Trouble Moving First Person Camera

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:

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?

nickgravelyn

05-08-2006 00:35:36

I've been trying at this for a few days, but still can't figure out a way to do this. Any ideas?

abecam

05-08-2006 10:38:49

As far as I know, you shouldn't "set" the orientation during the simulation. setPositionOrientation is used at the initialisation of a body, and goes against Newton's calculations. Try to give a torque instead.
If it doesn't help, try different combination, and use the log. I had some strange problems too, so I use the log to see if my force-position-orientation are well as I think, and I trace the problem in this way, by removing/changing/moving some critical line to see what it changes.
Good luck! :)
(You should look for some past topics too, it seems that some other persons had already this problem, and got some complete answer from Walaber, I have read that recently)