[ODE] Dumb question
Nate W
coding at natew.com
Mon Jul 22 01:13:01 2002
On Mon, 22 Jul 2002, Henry wrote:
> Any body had any luck setting the nearcallback to point to a c++ class
> member. eg
>
> dSpaceCollide ( space, 0, &myclass::nearCallback);
>
> Care to share how you did it?
Your average member function has an implicit parameter which becomes the
"this" pointer. ODE doesn't know how to pass that implicit parameter, so
you have to give dSpaceCollide a plain-C function or a static member
function. You can the use that static member function to call your
regular member function, like this:
class World
{
...
bool Step ();
// This static member is just a wrapper
static void CollisionCallback (void *pData, dGeomID o1, dGeomID o2);
// This is where the collision handling will really happen
void CollisionCallback (dGeomID o1, dGeomID o2);
// Gotta have this
dSpaceID m_SpaceID;
...
};
bool World::Step ()
{
...
// pass the this pointer for the 'data' parameter
dSpaceCollide (m_SpaceID, this, CollisionCallback);
...
}
void World::CollisionCallback (void *pData, dGeomID o1, dGeomID o2)
{
World* pThis = (World*) pData;
if (pThis)
pThis->CollisionCallback (o1, o2);
}
void World::CollisionCallback (dGeomID o1, dGeomID o2)
{
// put all of your collision-handling stuff here
}
--
Nate Waddoups
Redmond WA USA
http://www.natew.com