[ODE] dGeomSetOffsetPosition
Jon Watte (ODE)
hplus-ode at mindcontrol.org
Wed Sep 13 09:10:58 MST 2006
The problem with this proposal is that any geoms that are added after
the mass is set will not be translated.
The real solution would be to implement the offset center of gravity,
and apply that in all the appropriate calculations (or, rather,
pre-apply it when setting the body pos, and counter-apply it when
someone asks for the pos). Doing that might actually not be too bloody,
but more than zero work.
Cheers,
/ h+
Geoff Carlton wrote:
> 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
>>
>>
> _______________________________________________
> ODE mailing list
> ODE at q12.org
> http://q12.org/mailman/listinfo/ode
>
>
>
More information about the ODE
mailing list