[ODE] newbie problem

Ian McMeans imcmeans at telus.net
Tue Mar 30 23:35:25 MST 2004


Hi, I'm trying to do a simple car simulation. Right now I'm not even worried
about collision detection, I'm just trying to get some joints interacting
and drawn on the screen. I wrote some simple code to draw each dBody as a
cube, and I know ODE is at least running (because I can watch my car fall -
there's no ground yet, so it falls forever).

However, my problem is that if I attach the wheels (which are not at origin)
to the car (which happens to be at origin when the game starts) using a
joint, then the position of the wheel changes to origin.

Here is my code - I'm omitting the part where x,y, and z are computed, for
brevity:
Car::Car(dWorldID world) : wheelOffset(0.3, -0.1, 0.5)
{
dMass bodyMass, wheelMass;
dMassSetBoxTotal(&bodyMass, 1000, 2 * wheelOffset.X(), 2 * wheelOffset.Y(),
2 * wheelOffset.Z());
dMassSetCylinderTotal(&wheelMass, 100, 1, 0.2, 0.1);

body = dBodyCreate(world);
dBodySetMass(body, &bodyMass);
dBodySetPosition(body, 0, 0, 0); // car initially at origin
shocksJointGroup = dJointGroupCreate(0);

for (int wheel = 0; wheel < 4; wheel++)
{
    wheels[wheel] = dBodyCreate(world);
    dBodySetMass(wheels[wheel], &wheelMass);

    dBodySetPosition(wheels[wheel], x, y, z); // we have the wheel right on
the hinge2 anchor
    shocks[wheel] = dJointCreateBall(world, 0);

    dJointSetBallAnchor(shocks[wheel], x, y, z);
    dJointAttach(shocks[wheel], body, wheels[wheel]);  // THIS LINE
}
}

If I comment out the line I marked "THIS LINE", then the wheels are drawn in
the position I expect. What's going wrong? Are one of these functions
expecting coordinates relative to (a) the joint, (b) the car, (c) the wheel,
and I'm supplying coordinates relative to something else?

Thanks in advance!
Ian.



More information about the ODE mailing list