zass
10-09-2008 18:05:11
Hi,
I'm not usually one to post questions on forums, but I have searched everywhere and I'm sure I cant find an answer to my problem, although I'm sure there is some simple solution that I'm somehow missing.
I have created a character class which in theory creates and moves a character around the world. To do the movement the class has a forceCallback method which I assign to the character's body like so:
I have also tried it this way (but it shouldn't make a difference):
In the forceCallback method I want to add the force mMovementForce (which is a character instance variable) to the body. mMovementForce is calculated elsewhere based on input. So my forceCallback method looks something like this:
The problem is that mMovementForce doesnt have the right value, in fact it has very weird values like (1.07374e+008, 0, 2.10195e-044), however if I make the mMovementForce variable static and reference it like Character::mMovementForce then it works fine (but I need mMovementForce to not be static). So I'm thinking that the instanced mMovementForce isnt defined somehow for the forceCallback method and its just pulling some random undefined memory or something, but I cant for the life of me figure out why or how to fix it. I've been searching the forums for hours and I havent found a solution, although i've found other peoples code that does exactly this and apparently works, so I guess there must be some simple solution that I am missing.
Any help would be greatly appreciated.
I'm not usually one to post questions on forums, but I have searched everywhere and I'm sure I cant find an answer to my problem, although I'm sure there is some simple solution that I'm somehow missing.
I have created a character class which in theory creates and moves a character around the world. To do the movement the class has a forceCallback method which I assign to the character's body like so:
body->setCustomForceAndTorqueCallback<Character>(&Character::forceCallback, this);I have also tried it this way (but it shouldn't make a difference):
body->setCustomForceAndTorqueCallback(boost::bind(&Character::forceCallback, this, _1));In the forceCallback method I want to add the force mMovementForce (which is a character instance variable) to the body. mMovementForce is calculated elsewhere based on input. So my forceCallback method looks something like this:
void Character::forceCallback(OgreNewt::Body *bod)
{
Ogre::Real mass;
bod->getMassMatrix(mass, Ogre::Vector3());
bod->addForce(Ogre::Vector3::UNIT_Y * -98.1 * mass);
bod->addLocalForce(mMovementForce, Ogre::Vector3::ZERO);
mMovementForce = Ogre::Vector3::ZERO;
}The problem is that mMovementForce doesnt have the right value, in fact it has very weird values like (1.07374e+008, 0, 2.10195e-044), however if I make the mMovementForce variable static and reference it like Character::mMovementForce then it works fine (but I need mMovementForce to not be static). So I'm thinking that the instanced mMovementForce isnt defined somehow for the forceCallback method and its just pulling some random undefined memory or something, but I cant for the life of me figure out why or how to fix it. I've been searching the forums for hours and I havent found a solution, although i've found other peoples code that does exactly this and apparently works, so I guess there must be some simple solution that I am missing.
Any help would be greatly appreciated.