Sign in to follow this  

Open Dynamics Engine Non-Static Callback

This topic is 4718 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I recently started using the Open Dynamics Engine (ODE) along with OGRE3D and I am currently in the process of testing out what I can do and learning the basics of both engines. I have put together a set of objects on the screen and I am trying to check to see whether the camera has collided with them and if it has, move the camera back to the position it was before it collided (I am sure there is a better solution than this but since I am only in the learning stages, I am not worried about optimization, framerates, or anything else related to the user experience other than program crashes). The code technically works perfectly however, I had to do several things that I am afriad will prevent me from actually creating a full project later when I am ready to. My problem is related to the function, dSpaceCollide which is defined as: void dSpaceCollide (dSpaceID space, void *data, dNearCallback *callback);. The function I am using as the callback is defined as: void nearCallback(void *data, dGeomID o1, dGeomID o2);. If I pass nearCallback to dSpaceCollide as the callback function and nearCallback is not declared static void, I get the error: OgreFPSFrameListener.cpp(31) : error C2276: '&' : illegal operation on bound member function expression. The function dSpaceCollide is called in my code as follows: dSpaceCollide(spaceID, 0, &nearCallback); In the nearCallback function, I set a boolean variable so that the rest of the program knows if the camera is colliding with any objects in the scene or not. The problem is that since nearCallback has to be static to avoid the C2267 error, that makes me also need to define the boolean variable as static. If I declare the boolean variable as static, I get the linker error LNK2001. The solution I chose is to make the static boolean variable in the global space (in the .cpp file but outside any class) and make nearCallback static. Since I know that global static variables only exist in the scope of the file they are declared in, I can't use them outside that file which might cause some problems if when I write a bigger application with more files. Even if I am wrong about static variables being only available in the scope of the file, I might need to have several cameras or I might at a later time, need more than one collision variable per class so I would need the variable in the file. I want to be able to have the variable inside the class and I would also like to have nearCallback not be static. I know that this might not be possible but does anyone have any suggestions on how to fix the code so that my boolean variable can be inside the class? Thank you in advance for your time and suggestions.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
The easy way to reference member functions is to use a static function to wrap around the member function. You use this static function for the callback and the function only does this:

this->nonStaticCallbackFunction(...);

You can use the void* in the function call to pass the this-pointer.

Share this post


Link to post
Share on other sites

This topic is 4718 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this