Advertisement

Open Dynamics Engine Non-Static Callback

Started by January 16, 2005 01:00 PM
1 comment, last by Magefire2000 20 years, 1 month ago
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.
Thank you for your quick reply. I used a static_cast to convert the data parameter into the class which solved my problem. Thank you again for your help.

This topic is closed to new replies.

Advertisement