[HELP, PLEASE!] adding collision to my custom car

unclepauly

08-09-2006 15:09:43

hello

i have been trying to improve on demo 5, the simple vehicle demo, by replacing the box with an actual car. i have got some 3ds max cars and exported everything to Ogre - it's an Audi TT, and it looks awesome.

but i am struggling to add the physics. in my test app, i have a cone, a cylinder, and my car. they all start the same height above the surface, and when the app starts, they all should drop to the floor. the cone and the cylinder do, but my car stays in the air. i think this is something to do with the collision object i am attaching, and/or the inertia or mass settings.

the car is actually made up of loads of meshes, eah one represnting a part of the car. so there is the body, the interior, the grill, the lights etc. however i can reproduce my problem with only one mesh, for example the body.

so here is my code:




body = mSceneMgr->createEntity( "carentity", "AudiTT_body.mesh" );
carnode->attachObject(body);
carnode->setScale( size );
// rigid body.
OgreNewt::Collision* col = new OgreNewt::CollisionPrimitives::TreeCollision(m_World, carnode, false);
bod = new OgreNewt::Body( m_World, col );
bod->attachToNode(carnode);
// initial position
bod->setPositionOrientation( Ogre::Vector3(10,10,13),Ogre::Quaternion::IDENTITY );
delete col;
mass = 100.0;
inertia = OgreNewt::MomentOfInertia::CalcBoxSolid( mass, size );
bod->setMassMatrix( mass, inertia );
bod->setStandardForceCallback();



in demo5, the 'car' has a collision object of type CollisionPrimitives::Box. I figured this would only work for boxes, so i changed it to a TreeCollision for my car. Is this correct?

also, i calculate the interia above by using CalcBoxSolid. I'm guessing this is wrong, but i am not sure what to replace it with.

Appreciate any help, and thanks.

unclepauly

08-09-2006 15:37:02

actually if i change the collision object back to being a box, then the car falls as expected. so i am guessing a TreeCollision object causes the node to be static?

i would still like to know if there is a better way, or is the box the right method after all? i would have thought for other shapes like my car, there would be something else...

unclepauly

08-09-2006 16:32:21

ok, more playing around, and if i press F3 i can see the collision object on the screen. so i have found out that i can make the box a nice size around my car in the x and z direction, but i cannot increase the height of the object, or the car raises up in the air - the more i increase the height of the collision object, the more the car raises. so by using a box collision object, i can only really attach a collision to the bottom couple of centimeters of the car!

so it looks like a box collision object is not the way forward, and it seems like a tree collision is not right either.

so please can someone tell me which correct type of collision object i should be using, and how to properly attach a it to my car?

thank you!

unclepauly

09-09-2006 10:26:45

is anyone there..?

surely someone knows the answer ;)

Bekas

09-09-2006 11:07:03

TreeCollision is only used for static objects like walls.

If you want precise collisions you should use ConvexHull which "is the smallest possible convex shape that fully encloses all points supplied". You pass a SceneNode, gets the first object and calculates the hull.

But I think the box is a good compromize between accuracy and performance for a car. Play around with the parameters you pass (mass etc.) I'm not sure why box is not working properly.

unclepauly

09-09-2006 13:02:20

hi and thanks for replying!

you say:


If you want precise collisions you should use ConvexHull which "is the smallest possible convex shape that fully encloses all points supplied". You pass a SceneNode, gets the first object and calculates the hull.


where did you get this information from? could you point me to some documentation regarding convexhull so i can research this? or maybe a code sample? it's new to me.

the box collision does not work because as you change the height of the box collision, it raises the car node in the air so it is not touching the ground. i do not think this is a fault, i think this is by design, unless i am mistaken.

thanks again.

unclepauly

09-09-2006 13:37:07

seems like using ConvexHull is easier than i thought - just pass in m_world and the scene node and ogrenewt does everything for you.

so problem sovled, thanks Bekas...

Bekas

09-09-2006 13:53:48

where did you get this information from? could you point me to some documentation regarding convexhull so i can research this? or maybe a code sample?
From the OgreNewt source code. See this page for information on how to get it.