Problem with collision detection and how to react.

Bajter

29-06-2008 21:22:20

Hello,
I wanted to ask, about maybe not really specific problem, but I need an answer, which I couldn't find when searching the forums and internet :)
The problem is about famous NxOgre (well, why do I write in here? How did I get it? - its famous :D ) So, here I go:

I got two bodies, from which one is a ball, and the second is a 'bouncer'
In the program I want to release the ball (which I already handled with addforce on keypress :) ) - and... When it hits the bouncer, I want the ball to bounce from it.
The default physics aren't working with the problem, they dont let the ball bump from the bouncer, its rather like the ball jumps from the bouncer, or throws bouncer faaar away(with a funny spin movement :D - dealt with it by adjusting the masses)
I tried callbacks and triggers, but had many problems with it, so I'm asking - how to? (I need to detect the collision of ball with bouncer [sphere with cube/convex] and then apply a force that will change the direction - so do *(-1) to some directions of the vector)
Hope you will be able to respond, thanks in advance,
B.!
Edit :: Currently I've noticed, that maybe NxMaterial.h from PhysX could be useful *checking out* - still waiting for response.
Edit :: Found out, that I can actually do thing like this

NxOgre::Material *mMaterial= new NxOgre::Material("Ball",mScene);
mMaterial->setAll(0.9f,0.5f,0.5f);
mScene->createMaterial("Ball");
mBall = mScene->createBody("Ball;Ball.mesh", new NxOgre::Sphere(30), Vector3(0,5000,0), "mass: 1, material: Ball");

But it seems that it doesn't change anything. (material settings I mean) - but I feel that's the correct way of doing things. Any advice? :)
// and sorry for my English :D

Bajter

01-07-2008 11:34:18

// Sorry for doublepost, but this doesnt fit for an edit.

I havent knew that there is thing like 'material' in NxOgre, so I couldnt use it before, now, when I know it - it's not working as I would like to.
In debugger it doesnt show as material attached to the body I want it attached to (so Ball.mesh)
Anyone know how to help in this problem?


NxOgre::Material* mMaterial = mScene->createMaterial("bouncy");
mMaterial->setAll(1,0.5,0.5);
mBall = mScene->createBody("Ball;Ball.mesh", new NxOgre::Sphere(30, "material: bouncy"), Vector3(300,100,100), "mass: 1");

Laiquendir

01-07-2008 21:40:23

Hello, I have really similar problem to that Bajter described, could someone respond to his question, so we can fight against the difficulties? http://online.freeware.info.pl/games.html Please :)

nord

01-07-2008 23:21:00

Very sorry I dont have an answer. But my question is very simple and some kind of related to collision so I did not want to pollute the forum.

How can I see a body's collision boundries?

There is this function in ogre : mSceneMgr->showBoundingBoxes(true);
but it has nothing to do with the physics am I right?

it just shows some kind of smallest possible axis alligned bounding box for a mesh.

I need something to see the collision box for a body in run time so that I can tweak it according to the model mesh and have more realistic collisions. Thanks.

Laiquendir

01-07-2008 23:26:12

You can try RemoteDebugger. It have option which shows body boundaries.

Use:
mWorld->getPhysXDriver()->createDebuggerConnection("localhost");

Bajter

01-07-2008 23:27:40

Nord, when you enter (PHYSX_DIR)\Bin\win32 - you can see a RemoteDebugger there, run it, and your own application, then turn on the option "show boundaries" (or similar to this, Im sure it's in there :) )
// turning the option is in the debugger, which should show you the same things that are shown in the app.

nord

01-07-2008 23:48:13

thank you very much I have used it to observe the collision boxes. Better than nothing but I still cannot see the collision boxes along with the visual meshes on the SAME screen =).

PS: my wheels are inside the collision box of my car, is it a problem? tyre cylinders are half embedded into the cube collision box of my car. It still accelerates though.

Bajter

01-07-2008 23:52:50

Personally I think it could cause problems, but im not a specialist in either nxogre nor physx (thats why I wrote the first post here).
Im glad that I could help :)
And Laiquendir! Thank's for writing here! :)
ATM. I still don't have any idea what can cause problems with material to body attachment, it seems that every body in the scene have material: 0, even though I told them to have material: Ball (which index is 1) and material: Bouncer (which index is 2)
// Hope those details can help in resolving the problem, which seems to be a common one, and without a solve. *desperately calls for help* :)

Gohla

02-07-2008 09:35:54

new NxOgre::Sphere(30, "material: bouncy")
doesn't work because:
//if (Set("material", parameter, mMaterial)) continue;
//if (Set("material-index", parameter, mMaterial)) continue;

that piece of code is commented out.

I think you need to create a ShapeParams object, and set the mMaterial variable to the material (never done this before but should work :P).
NxOgre::ShapeParams shapeParams;
shapeParams.setToDefault();
shapeParams.mMaterial = ...

Bajter

02-07-2008 13:10:54

Looks that this isn't working too :(
Anyway, will it work if I'll put those two lines out of comment, and recompile the source?
If not - what's another way? Maybe Betajaen could help us? ( I feel like im doomed :P )

Laiquendir

02-07-2008 23:43:30

Thanks Gohla :) Now materials are working.

Bajter you must write:

NxOgre::ShapeParams shapeParams;
shapeParams.setToDefault();
shapeParams.mMaterial = (Material ID)


Try shapeParamss.mMaterial = 1 :)

Bajter

03-07-2008 05:50:33

Laiquendir, firstly - thanks, and secondly - you missed a ";" after Material ID bracket :)
I only used the code in wrong way, Gohla, my fault - sorry.
Instead of material ID I was writing the (0.7f,0.2f,0.2f) part :)
Now I can even do thing like this! :D
NxOgre::ShapeParams shapeParams;
shapeParams.mMaterial = (2);
mLevel = mScene->createBody("Level;Pong_Map1.mesh",new NxOgre::Convex(Resources::ResourceSystem::getSingleton()->getMesh("Pong_Map1.mesh.nxs"),shapeParams),Vector3(0,0,0),"static: yes");
mBouncer = mScene->createBody("Bumper1;Bumper.mesh", new NxOgre::Cube(Vector3(50,50,271),shapeParams), Vector3(0,50,-500), "mass: 1000");
mBouncer2= mScene->createBody("Bumper2;Bumper.mesh", new NxOgre::Cube(Vector3(50,50,271),shapeParams), Vector3(0,50, 500), "mass: 1000");
shapeParams.mMaterial = (1);
mBall = mScene->createBody("Ball;Ball.mesh", new NxOgre::Sphere(30, shapeParams), Vector3(300,100,100), "mass: 1");


And its working :)
Great thanks Gohla, and once again, sorry for using the code in wrong way, I was a bit sleepy in that moment, maybe thats why ;) Nevermind it :D