[ODE] ODE: Center of gravity problem & fast step

Troy Chard troy.chard at shaw.ca
Tue Jul 8 12:05:02 2003


At 08:10 AM 7/8/03 -0400, you wrote:


>Troy Chard wrote:
> >
> > I noticed in the docs for ODE that there's a bug involving the center of
> > gravity being fixed at 0,0,0
> > with respect to the position of the body.
>
>This isn't a bug, it's a feature.  Check out the transform geom.
>
>- Martin

Hi Martin,

Thanks for the reply.  It took me some time to figure out how i could use this.
I just wrote a proposed solution to one of the cs guys. I thought you might 
find it
interesting.  Also.... perhaps you may know of a more elegant approach than my
bumbling below:

-------------8<----------------

Proposed solution to center of gravity problem:

In iRigidBody::AttachColliderBox, a GeomTransform is created.

It encapsulates a geom E, it can be treated itself as a geom T (although T
is just the transform applied to E).   You probably already know this.

Ok suppose you made a sprite model of a 1x1x1 box located with it's center at
3,3,3.  So the vertices are all set at like 2.5 3.5 values.  0,0,0 is the 
sprite origin.

So AttachColliderMesh works perfectly... it transforms E to 3,3,3 creating 
a collider
flawlessly aligned to the sprite.  T is left at 0,0,0, which coincides with 
the sprite origin.
This works.  T is center of gravity and it's moved around in world 
according to physics
forces.  Whereever T is, the body is. These 2 positions are joined in the 
call to
dGeomSetBody (id, bodyID);

Wherever T is, the body is... wherever the body is, that's where the sprite 
is drawn...
well almost... T,body and sprite will share the same point, but the sprite 
is offset by 3.
This is ok because E is offset the same amount... if E collides with 
something, a new
T is calculated using ODE physics, and the sprite is drawn using T as it's 
origin.

Ok... so the only way to alter the center of gravity is by moving T (i 
suspect that moving the
body will also move T but I should check this).  Nothing else will alter 
the center of gravity.

But, nothing says we have to render the meshobj at T.
So one possible solution is:
Inside AttachColliderBox, store the csOrthoTransform as a member of 
iRigidBody instead
of applying it to E.
(Better yet might be to invert it and store the inverted form).
Leave both T and E alone... at the 0,0,0 origin.  The body will also be 
located at T.
Now we have a centered center of gravity and a centered collider, but the 
sprite is way out
at 3,3,3... so our visual is misaligned... to correct this... whenever the 
mesh is to be drawn
or moved or transformed to keep it in synch with the physics model we 
offset the mesh
by the inverted transform that was supplied in AttachColliderMesh.

This will move the sprite from 3,3,3 back to 0,0,0 and into alignment with 
the collider E.  This
should achieve the illusion of a sprite with a corrected center of gravity.

So finally... to allow for an offset center of gravity... well... I'm not 
sure what ODE does with
the center of gravity stored in dBodySetMass (bodyID, m) when we call 
SetProperties, but
if we store it with the rigidbody:

1.Offset T (or the body) in world by center of gravity using something to 
move it in worldspace.
eg if CenterGravity is set to (0,-5,0), call something like
dBodySetPosition   (dBodyID, 0, -5, 0);
2. Then alter the transform to E (I'm hoping we've got access to that 
somewhere - I need to check
ODE API) such that the collider E is now located at (0,5,0).  This only 
needs to be done once
to set this new center of gravity... although it could be a nasty to do this
dynamically (eg horse leaning left) it should work fine for one time 
settings like setting up a
bowling ball pin or something like that with an offset center of gravity).

3. Whenever drawing sprite, do the same as above... transforming it using 
the inverse
transform, but as well, translate it by the inverse center of gravity argument.
This would put box at 3,3,3 back to 0,0,0 and then to 0,5,0 which would 
still appear as
0,0,0 with T and body invisibly lurking at 0,-5,0.

-------------8<----------------

Troy