[ODE] nearcallback pointer help

Arturo Colorado Garín acolorado at telefonica.net
Sun Nov 5 16:32:50 MST 2006

> Hello,
> I've created a Physics class, here is the .h file.
> ----------------------------------------------------------------------------------
> Here is my question:
> I want to pass the nearcallback function into the dSpaceCollide();
> However, I can't cast it into a pointer because it's not a static member. 
> If I
> make it a static member it can't access the World and Space variables,
> because they are not static either.


You can't, you need to pass a global function to dSpaceCollide(). However 
you can do this if you want to have your callback as a class member:

First, remove the 'data' parameter of your method Physics::nearCallback. 
Then, implement in your .cpp a global function (not a member of your class) 
similar to this:

void CB_nearCallback(void *data, dGeomID geom1, dGeomID geom2)
    ASSERT( data != NULL );

    // Let the Physics::nearCallback method do all the work
    data->nearCallback(geom1, geom2);

Then, your call to dSpaceCollide should look something like this:

    // Collide geoms
    dSpaceCollide( pPhysicsObject->GetOdeSpace(), pPhysicsObject, 

This way, when CB_nearCallback is called it will receive the pointer to your 
Physics object (pPhysicsObject), which is then used to call the method 

Hope this helps,


More information about the ODE mailing list