nickgravelyn
30-07-2006 07:12:04
I'm attempting my first camera with OgreNewt and it's proving a bit challenging. I think I've figured out a good method for rotating the body and applying forces, but it doesn't appear that my body moves the exact direction it's facing. When I move the mouse left and right, I simply use the setPositionOrientation() method with the new orientation and reusing the current position. Here's how that works:
Then in my force callback, I create my force like this:
Is there a problem with this? The orientation from the body should only have a yaw to it because I never rotate it any other way (I'm actually creating an Ogre::Quaternion with my current yaw angle and UNIT_Y for the vector). The body always faces directly with the camera, but the movement appears off sometimes. Any ideas?
Ogre::Degree pitch = Ogre::Degree( -mInput->getMouseRelativeY() * mLookSensitivity );
if ( mInvertedLook )
pitch *= -1;
mCameraYaw += Ogre::Degree( -mInput->getMouseRelativeX() * mLookSensitivity );
if ( mCameraPitch + pitch < Ogre::Degree( -CAMERA_LIMIT ) )
{
pitch = Ogre::Degree( -CAMERA_LIMIT ) + mCameraPitch;
mCameraPitch = -CAMERA_LIMIT;
}
else if ( mCameraPitch + pitch > Ogre::Degree( CAMERA_LIMIT ) )
{
pitch = Ogre::Degree( CAMERA_LIMIT ) - mCameraPitch;
mCameraPitch = CAMERA_LIMIT;
}
else
mCameraPitch += pitch;
Ogre::Quaternion yawQuat( mCameraYaw, Ogre::Vector3::UNIT_Y );
Ogre::Quaternion pitchQuat( mCameraPitch, Ogre::Vector3::UNIT_X );
mCamPitchNode->setOrientation( pitchQuat );
Ogre::Vector3 pos;
Ogre::Quaternion orient;
mPlayerBody->getPositionOrientation( pos, orient );
mPlayerBody->setPositionOrientation( pos, yawQuat );
Then in my force callback, I create my force like this:
Ogre::Vector3 force = Ogre::Vector3::ZERO;
if ( mForward && !mBackward )
force.z = -1;
else if ( mBackward && !mForward)
force.z = 1;
if ( mLeft && !mRight )
force.x = -1;
else if ( mRight && !mLeft )
force.x = 1;
force.normalise();
force *= mMoveSpeed * mNewtonWorld->getTimeStep();
Ogre::Vector3 pos;
Ogre::Quaternion orient;
pBody->getPositionOrientation( pos, orient );
pBody->addForce( orient * force );
pBody->setOmega( Ogre::Vector3::ZERO ); //prevent our camera from spinning
Is there a problem with this? The orientation from the body should only have a yaw to it because I never rotate it any other way (I'm actually creating an Ogre::Quaternion with my current yaw angle and UNIT_Y for the vector). The body always faces directly with the camera, but the movement appears off sometimes. Any ideas?