I need to create dynamically a number of meshes within nodes and newton body, how can I set a different instance of callback to each newton body?
Acid_Gambit
09-04-2007 20:06:16
I need to create dynamically a number of meshes within nodes and newton body, how can I set a different instance of callback to each newton body?
Isn't it possible to set the same callback to each newton body and check for specific user data that identifies the bodies within the method itself?
what kind of user data?
I want to use the same callback function, but for each body, the force will have a different values.
its like I wanna use the same class and the different object. but I dont know how it could works with the callback being a method of a class. and setup the callback through an object. I mean setting an object instead of a method, could work very well, but I dont know if its possible.
Tubez
09-04-2007 21:42:32
Here's how I do it:
In your callback you are passed a body parameter. Use that as an index in a lookup table or something. Get your params. Use them.
well, I dunno if it works, cuz the number of bodies is dinamically,
there is no predetermination
However, I should try it, do u have an example?
walaber
10-04-2007 06:28:30
if you have a base class for all of your bodies, you can do this:
imagine you have a class like this:
class MyBody
{
public:
Mybody( OgreNewt::Body* body, Ogre::Vector3 position );
~MyBody();
// set the force for this body!
void setForce( Ogre::Vector3 force ) { mForce = force; }
private:
// callback function
void myForceCallback( OgreNewt::Body* me );
Ogre::Vector3 mForce;
};
in the constructor, you would set the callback for the body like this:
mBody->setCustomForceAndTorqueCallback< MyBody >( &MyBody::myForceCallback, this );
then, make the callback something like this:
void MyBody::myForceCallback( OgreNewt::Body* me )
{
// this is a member function, so use the member variable that was set elsewhere in the program!
mBody->addForce( mForce );
}
this is a simplistic example, but as you can see, you can make the callback a member function of the class, and then access any member variables of the class in the callback, allowing a different force on every different instance of this class.
please note that this was all written quickly, and there may be typos, or errors in function names, but it should help you get the idea.
*great*
thanks walaber,
it really helped me to get the idea =)