nickgravelyn
16-06-2007 08:22:56
I sort of figured out how to implement physics based camera control, however I'm having a bit of trouble. Here's my callback for the camera:
void CubismApp::cameraBodyCallback(OgreNewt::Body* bod)
{
//apply a simple gravity force.
Ogre::Real mass;
Ogre::Vector3 inertia;
bod->getMassMatrix(mass, inertia);
bod->addForce(Vector3(0,-9.8,0) * mass);
//Force = ((desiredVelocity- currentVelocity) / TimeStep) * mass
if (mTranslateVector != Vector3::ZERO)
{
Vector3 moveForce = mCameraYawNode->getOrientation() * mTranslateVector;
moveForce.normalise();
bod->addForce((((moveForce * mMoveSpeed) - bod->getVelocity()) / mWorld->getTimeStep()) * mass);
}
//stop the camera from rotating
bod->setOmega(Vector3::ZERO);
}
Everything works like it should... to an extent. If I am moving at all (i.e. mTranslateVector != Vector3::ZERO), I cease to fall. Is there any way I can still have gravity affect me even if I am adding in my own forces? I figured that, being adds, it would work, but it doesn't. Any help is greatly appreciated.
void CubismApp::cameraBodyCallback(OgreNewt::Body* bod)
{
//apply a simple gravity force.
Ogre::Real mass;
Ogre::Vector3 inertia;
bod->getMassMatrix(mass, inertia);
bod->addForce(Vector3(0,-9.8,0) * mass);
//Force = ((desiredVelocity- currentVelocity) / TimeStep) * mass
if (mTranslateVector != Vector3::ZERO)
{
Vector3 moveForce = mCameraYawNode->getOrientation() * mTranslateVector;
moveForce.normalise();
bod->addForce((((moveForce * mMoveSpeed) - bod->getVelocity()) / mWorld->getTimeStep()) * mass);
}
//stop the camera from rotating
bod->setOmega(Vector3::ZERO);
}
Everything works like it should... to an extent. If I am moving at all (i.e. mTranslateVector != Vector3::ZERO), I cease to fall. Is there any way I can still have gravity affect me even if I am adding in my own forces? I figured that, being adds, it would work, but it doesn't. Any help is greatly appreciated.