[ODE] Re: Translating a mass does not produce desired results

Andrzej Zacharewicz zachar at techland.pl
Tue May 25 09:01:07 MST 2004


Hi

I had similar problem with car mass translation.
I have found that gravity applied in step and stepfast functions ignore mass
translation.

I don't know this is best and correct solution, but enough for me.
In step and stepfast - gravity is applied to center of body - not center of
mass!
Change that to AddForceAtPos with pos = center of mass defined in body.mass

You may do this that: (step.cpp & stepfast.cpp)
(find world->gravity string and replace FOR loop)
-----------------------------------------------------
for (i=0; i<nb; i++)
{
    if ((body[i]->flags & dxBodyNoGravity) == 0)
    {
        dVector3 massTranslation;
        dBodyVectorToWorld(body[i], body[i]->mass.c[0], body[i]->mass.c[1],
body[i]->mass.c[2], massTranslation);
        dBodyAddForceAtPos(body[i],
                                            body[i]->mass.mass *
world->gravity[0],
                                            body[i]->mass.mass *
world->gravity[1],
                                            body[i]->mass.mass *
world->gravity[2],
                                            body[i]->pos[0] +
massTranslation[0],
                                            body[i]->pos[1] +
massTranslation[1],
                                            body[i]->pos[2] +
massTranslation[2]);
    }
}

-----------------------------------------------------


Regards
Andrzej Zacharewicz
Techland
zachar at techland.pl

>
> Hi,
>
> I have a function that creates a cylinder and in it I do the following:
>
>    dMass m;
>    dMassSetCappedCylinderTotal(&m,1.0,3,radius,length);
>    dMassTranslate(&m, 0.15, 0, 0);
>
>    Object* obj = newObject();
>    obj->body = dBodyCreate(world);
>    dBodySetMass (obj->body,&m);
>
> However, despite the fact that the mass has been translated to the
> "side" of the cylinder it does not roll.  Can anyone explain why this
> is so?



More information about the ODE mailing list