[ODE] Two Dimensions?

John john at blippygames.com
Thu Aug 4 15:32:13 MST 2005


> What is the most effective way to restrict motion of objects in ODE to 
> two dimensions?

Do not simply discard a position axis (say, the 'z' axis). You'll wonder 
why your 2D objects seem to overlap -- they are not overlapping, they 
have different z values. Also, you might be tempted to simply set the 
z-component of all added forces to zero and hope that objects never 
decide to leave the XY plane. Again, that doesn't work.

Here's my code to do this. Call it on each tick. It's a hack, but seems 
to work:

void
_ode_body_limit_axes (dBodyID id, dReal x, dReal y, dReal z)
{
     const dReal * r;

     if ((r = dBodyGetForce (id)))
         dBodySetForce(id, r[0]*x, r[1]*y, r[2]*z);

     if ((r = dBodyGetTorque (id)))
         dBodySetTorque (id, r[0]*x, r[1]*y, r[2]*z);

     if ((r = dBodyGetPosition (id)))
         dBodySetPosition (id, r[0]*x, r[1]*y, r[2]*z);

     if ((r = dBodyGetLinearVel (id)))
         dBodySetLinearVel (id, r[0]*x, r[1]*y, r[2]*z);

     // rotation?
     //r = dBodyGetAngularVel (id);
     //dBodySetAngularVel (id, r[0]*(1-x), r[1]*(1-y), r[2]*(1-z));
}



More information about the ODE mailing list