[ODE] Re: Copying/Cloning Composite Objects
john rieffel
jrieffel at gmail.com
Tue Aug 16 12:33:56 MST 2005
Hi Again,
I've tried to copy objects by copying their their bodies and all of
their geoms, but I'm obviously doing something incorrectly, because I
get a nasty error during collision detection of the copied object.
To simplify things, my world only ever contains either Box geoms or
dGeomTransforms which contain boxes. Here are my copy methods. The
"MyObject" struct is the same as those in the dropstuff demo:
//copy an object so that it can be reused as a module
MyObject ODEWorld::copyObject(MyObject inobj)
{
MyObject newobj;
memset (&newobj,0,sizeof(MyObject));
newobj.rc = inobj.rc;
newobj.gc = inobj.gc;
newobj.bc = inobj.bc;
//create it
newobj.body = dBodyCreate(world);
for (int i = 0; i < GPB; i++)
{
if (inobj.geom[i] != NULL)
{
newobj.geom[i] = copyGeom(inobj.geom[i]);
dGeomSetBody(newobj.geom[i],newobj.body);
}
}
dMass fromMass;
dBodyGetMass(inobj.body,&fromMass);
dMass newmass;
dMassSetZero(&newmass);
dMassAdd(&newmass,&fromMass);
dBodySetMass(newobj.body,&newmass);
const dReal *inpos = dBodyGetPosition (inobj.body);
const dReal *r2 = dBodyGetRotation(inobj.body);
dBodySetPosition(newobj.body,inpos[0],inpos[1],inpos[2]);
dBodySetRotation(newobj.body,r2);
return newobj;
}
//given a geom, copy it
// we only care about dGeomTransforms and dBoxGeoms.
dGeomID ODEWorld::copyGeom(dGeomID ingeom)
{
dGeomID copiedGeom;
if (dGeomGetClass(ingeom) == dGeomTransformClass)
{
copiedGeom = dCreateGeomTransform(space);
dGeomTransformSetCleanup (copiedGeom,1);
dGeomID subGeom = copyGeom(dGeomTransformGetGeom(ingeom));
dGeomTransformSetGeom (copiedGeom, subGeom);
}
else if (dGeomGetClass(ingeom) == dBoxClass)
{
dReal *sides;
dGeomBoxGetLengths(ingeom, sides);
copiedGeom = dCreateBox(space,sides[0],sides[1],sides[2]);
}
else
{
printf("ODEWorld::copyGeom - I don't know how to copy geom class
%d\n",dGeomGetClass(ingeom));
}
const dReal *inpos = dGeomGetPosition (ingeom);
dGeomSetPosition(copiedGeom,inpos[0],inpos[1],inpos[2]);
const dReal *r2 = dGeomGetRotation(ingeom);
dGeomSetRotation(copiedGeom,r2);
return copiedGeom;
}
and here is the error I'm getting:
Program received signal EXC_BAD_ACCESS, Could not access memory.
Reason: KERN_INVALID_ADDRESS at address: 0x3fb95818
0x00028850 in dxGeomTransform::computeAABB () at ODEWorld.cc:2845
2845 }
(gdb) where
#0 0x00028850 in dxGeomTransform::computeAABB () at ODEWorld.cc:2845
#1 0x000296b4 in dxHashSpace::cleanGeoms () at ODEWorld.cc:2845
#2 0x0002976c in dxHashSpace::collide () at ODEWorld.cc:2845
#3 0x0001f4dc in ODEWorld::run_interactive (this=0x1e2000) at ODEWorld.cc:1435
Any pointers would be greatly appreciated.
jr
On 8/4/05, john rieffel <jrieffel at gmail.com> wrote:
> Hi Folks,
>
> I'm getting back into ODE after a brief sabbatical from hacking.
> Here's my question:
>
> I've learned (thanks to matt hancher) how to create a single composite
> object given a set of individual bodies, by using a dGeomTransform.
> Now that I've created such a composite, I can place it in the world
> and watch it behave, which is quite satisfying.
>
> Now I'd like to be able to "clone" said composite object. For
> instance, say that I've encapsulated a bunch of fobs into a "widget"
> object, and now I'd like to place 10 geometrically identical such
> widgets throughout the world - what's the best way to do this?
>
> Are there any utility functions or obvious shortcuts for how to make
> copies of such a dGeomTransform? Or, do I have to hand-write a
> function which, given a target dGeomTransform, creates a new body in
> the world (corresponding to the clone), copy the object's mass and
> then copy each of the geoms to the clone, etc etc etc?
>
> Now that I've listed it all out it doesn't seem that bad after all,
> but I get the impression that someone else must have come across this
> problem (and solved it elegantly) - so I'd rather not repeat someone
> else's work.
>
> Thanks,
> John Rieffel
>
More information about the ODE
mailing list