[ODE] dGeomSetOffsetPosition

Geoff Carlton gcarlton at iinet.net.au
Tue Sep 12 19:00:04 MST 2006


Hi,
Selwakad just gave me an example bit of code here, and it contains what 
might be a common misconception.  It has three geoms offset at (0,0,0), 
(k,0,0) and (2k,0,0), and then calls the set mass function with a dMass 
structure that has a centre of mass of roughly (k,0,0).  This doesn't work!

I would suggest that the dBodySetMass structure should warn (or even 
assert) when passed a mass with a non-zero 'c' field, since that value 
is ignored by ODE.  We could add a new function that does this:

void dBodySetOffsetMass(dMass* mass, dBodyID body) {
  if (mass->c != (0,0,0)) {
    for each (geom in body) {
      dGeomSetOffset(dGeomGetOffset(geom) - mass->c)
    }
    dMassTranslate(mass, -mass->c)
  }
  dBodySetMass(mass)
}

I'm not sure how useful the above would be, but it may help in some 
situations.

Geoff

selwakad at comcast.net wrote:
>
> I don't have that code since i replaced it with this code which seems 
> to work a lot better, although sometimes the compound object sinks 
> through the ground or the program simple freezes.
>
> Anyways, here is the code, it is simple, nothing fancy:
>
> if (cmd == 'b')
>
> {
>
> dMass m2, m3, r;
>
> dMassSetZero(&m);
>
> dMassSetZero(&m2);
>
> dMassSetZero(&m3);
>
> dMassSetZero(&r);
>
> obj[i].geom[0] = dCreateSphere (space,sides[0]);
>
> obj[i].geom[1] = dCreateBox (space,sides[0],sides[0],sides[0]);
>
> obj[i].geom[2] = dCreateSphere (space,sides[0]);
>
> dMassSetSphere (&m2, DENSITY,sides[0]);
>
> dMassSetBox (&m,DENSITY,sides[0],sides[0],sides[0]);
>
> dMassSetSphere (&m3, DENSITY,sides[0]);
>
> dMassTranslate(&m, sides[0], 0.0, 0.0);
>
> dMassTranslate(&m3, 2*sides[0], 0.0, 0.0);
>
> dMassAdd(&r, &m);
>
> dMassAdd(&r, &m2);
>
> dMassAdd(&r, &m3);
>
> dBodySetMass (obj[i].body,&r);
>
> dGeomSetBody (obj[i].geom[0], obj[i].body);
>
> dGeomSetBody (obj[i].geom[1], obj[i].body);
>
> dGeomSetBody (obj[i].geom[2], obj[i].body);
>
> dGeomSetOffsetPosition(obj[i].geom[0], 0.0, 0.0, 0.0);
>
> dGeomSetOffsetPosition(obj[i].geom[1], sides[0], 0.0, 0.0);
>
> dGeomSetOffsetPosition(obj[i].geom[2], 2 * sides[0], 0.0, 0.0);
>
> return;
>
> }
>
>  
>
> Thanks.
>
> ------------------------------------------------------------------------
>
> No virus found in this incoming message.
> Checked by AVG Free Edition.
> Version: 7.1.405 / Virus Database: 268.12.3/446 - Release Date: 12/09/2006
>   


More information about the ODE mailing list