# ODE: simulating a car.

## Recommended Posts

ehmdjii    238
hello, i need some help on simulating a car. am i right that i will need these things: a dWorld a dBody for the car( i apply forces there) a dBody for the terrain a dSpace for colldec. anything else? what are these dGeoms for? and how do i apply such a dGeom to the dBody and how do i all connect that to the dSpace? thanks!

##### Share on other sites
Gorax    202
The world holds all of your bodies. The space holds all of your geoms. Your bodies hold all of your joints. Your geoms can be mapped to bodies so you can put them at some position in space, with rotational values, etc. applied to them. All of the geoms are used in the collision detection, which you'll have to implement yourself.

While this does seem confusing at first, it's not after you get used to it. You might want to consider adding 4 wheels to your body, and attach them with joints, either that or you're going to have a lot of trouble pushing a box around on the ground, while trying to keep it reasonably realistic. ;)

I suggest you download the latest user guide from ODE's website, since it'll explain *everything* there is to know about ODE.

Here's a small piece of code that'll let you create a box:
dWorldID worldID = dWorldCreate();dSpaceID spaceID = dHashSpaceCreate(0);dBodyID bodyID = dBodyCreate(worldID);dGeomID geomID = dCreateBox(spaceID,lengthX,lengthY,lengthZ);dMass mass;dMassSetBox(&mass,density,lengthX,lengthY,lengthZ);dBodySetMass(bodyID,&mass);dGeomSetBody(geomID,bodyID);

You'll need to specify the lengths and the density, and you'll probably have your own world and space IDs elsewhere.

Practice makes perfect, and the same holds true for using ODE. Rather than jumping right into the 'creating a car' phase, you should try something *much* more simple, like creating a box that'll fall, then make another one under it that doesn't, and see if you can set up the collision detection so that they'll actually collide. After that, you can try adding joints, applying forces, etc. After you've done all of that, you'll be able to move onto doing more complex things, like creating a car, or a humanoid, or even implementing different object types, such as water, fixed objects that can't be moved at all, etc.

##### Share on other sites
coldacid    755
Even if you don't use OGRE, I'd suggest you look at OgreOde, a library for using ODE in OGRE applications. It has a class for vehicles which might give you a good idea at how to do this on your own.

##### Share on other sites
ehmdjii    238
thanks so far!

so my first goal is to drive a box on a plane:

//setup:	ODE_W = dWorldCreate();	ODE_CAR = dBodyCreate (ODE_W);	ODE_SPACE = dHashSpaceCreate(0);	ODE_GEOM_CAR = dCreateBox(ODE_SPACE,1,1,1);	ODE_GEOM_PLANE = dCreatePlane(ODE_SPACE,0,1,0,0);	dGeomSetBody(ODE_GEOM_CAR, ODE_CAR);	dGeomSetBody(ODE_GEOM_PLANE, 0);//in the game loop:	dWorldQuickStep(ODE_W, (dReal) at);	dContactGeom *contact;	dCollide(ODE_GEOM_CAR, ODE_GEOM_PLANE, 0, contact, sizeof(dContactGeom));

but it doesnt work, the box (car) simply does not collide with the plane, it just sinks down.

thanks!

##### Share on other sites
ehmdjii    238
ok, i am so far that the plane and the box can collide, but i cant find realistic parameters for the contact.surface

the box bounces off higher than it falls.

can anyone recommend useful flags and values for this surface?

thanks!