AFAIK, this can't be done in ODE. Bodies don't accept masses that are
not centered at the origin. The only purpose for the center information
in the mass structure is so you can add a bunch of them, and (before
putting it on the body) center it before sending it to the body. Then
you offset the geoms accordingly to how much the mass was translated.
Pseudo-code:
-- 8< -- 8< -- cut here -- 8< -- 8< --
create a zero mass, Mt
for each geom to be added at position Pi:
create a mass Mi for this geom
dMassTranslate(&Mi, Pi[0], Pi[1], Pi[2]);
dMassAdd(&Mt, &Mi);
c = Mt.c //this is a vector
// Center the mass:
dMassTranslate(&Mt, -c[0], -c[1], -c[2]);
dBodySetMass(body, &Mt);
for each geom (again):
Gi = dCreate...(...);
dGeomSetBody(body, Gi);
dGeomSetOffsetPosition(Gi,
Pi[0] - c[0], Pi[1] - c[1], Pi[2] - c[2]);
-- >8 -- >8 -- cut here -- >8 -- >8 --
That is, after accumulating the masses you'll know how by much you have
to translate everything, both the mass, and the geom offsets: "-c".
For your particular case, the first loop would end up with Mt centered
at (0,10,0), thus c = (0,10,0). So your geom offset, (0,10,0) would be
canceled by adding "-c" in the last line.
This limitation is more of a design decision. I believe some important
equations would have to be updated to handle non-centered masses
(probably to just "center" them for calculations, then move them back),
and you would gain almost nothing (would shorten the above code in just
2 lines).
--
Daniel K. O.
"The only way to succeed is to build success yourself"
The center of gravity is always the center of the body. However, that's
not really a big problem, because the body has no physical extent. Thus,
put the body where you want the physical center of gravity, and then put
the geom/geoms relative to that location where you want them.
For example, for a car with very low center of gravity, you might want
the COG at 0,0.01,0. With 0.2 meters of clearance, and a 0.5 meter tall
body, you would want the center of your collision geom box to be at
0,0.45,0. You implement this by placing the body at 0,0.01,0, and
placing the geom at 0,0.44,0 offset of the body.
Sincerely,
jw