Strange movement of the camera!!

majc

31-08-2006 23:21:11

Im doing a fps camera but when i push forward or backwards the cam moves a little strange some times i push forward and move backwards.
Why is that?
Yaw and pitch work well alone without the arrow keys.
But when i use newt bodys pitch dont work.

This is the input function that i call in framestarted:


void cPlayer::Input(const FrameEvent &evt)
{
mCamera->getParentSceneNode()->detachObject( mCamera );
DarkFuture->mCamNode = mSceneMgr->getSceneNode( "CamNode" );
mSceneMgr->getSceneNode( "PitchNode1" )->attachObject( mCamera );



Vector3 transVector = Vector3::ZERO;


Vector3 trans, strafe, vec;
Quaternion quat;

quat = DarkFuture->mCamNode->getOrientation();

vec = Vector3(0.0,0.0,-2);
trans = quat * vec;

vec = Vector3(2,0.0,0.0);
strafe = quat * vec;

bool up_enable;

up_enable = true;


if (mInputDevice->isKeyDown(Ogre::KC_UP) || mInputDevice->isKeyDown(Ogre::KC_W))
{
DarkFuture->cam_body->setVelocity( (trans * 6.0) );
}

if (mInputDevice->isKeyDown(Ogre::KC_DOWN) || mInputDevice->isKeyDown(Ogre::KC_S))
{
DarkFuture->cam_body->unFreeze();
DarkFuture->cam_body->setVelocity( (trans * -1 * 6.0) );
}

if (mInputDevice->isKeyDown(Ogre::KC_LEFT) || mInputDevice->isKeyDown(Ogre::KC_A))
{
DarkFuture->cam_body->unFreeze();
DarkFuture->cam_body->setVelocity( (strafe * -1 * 6.0) );
}

if (mInputDevice->isKeyDown(Ogre::KC_RIGHT) || mInputDevice->isKeyDown(Ogre::KC_D))
{
DarkFuture->cam_body->unFreeze();
DarkFuture->cam_body->setVelocity( (strafe * 6.0) );
}

if (mInputDevice->isKeyDown(Ogre::KC_PGDOWN))
{
Ogre::Vector3 dir(0,-1,0);
DarkFuture->cam_body->setVelocity( (dir * 6.0) );
}

if (mInputDevice->isKeyDown(Ogre::KC_PGUP))
{
Ogre::Vector3 dir(0,1,0);
DarkFuture->cam_body->setVelocity( (dir * 6.0) );
}

DarkFuture->cam_body->setOmega(Ogre::Vector3::ZERO );<- added this line to stop spinning.

DarkFuture->mCamNode->yaw( Degree(-mRotate * mInputDevice->getMouseRelativeX()) );
DarkFuture->mCamNode->getChild(0)->pitch( Degree(-mRotate * mInputDevice->getMouseRelativeY()) );
}



This is the function that creates the cam body and attach it:



void DF::createCamBody()
{
col = new OgreNewt::CollisionPrimitives::Ellipsoid( m_World, Ogre::Vector3(1,1,1) );
cam_body = new OgreNewt::Body( m_World, col );
delete col;

Ogre::Real mass = 70.0;
Ogre::Vector3 inertia = OgreNewt::MomentOfInertia::CalcEllipsoidSolid( mass,Ogre::Vector3(1,1,1));
cam_body->setMassMatrix( mass, inertia );
Vector3 posi = mCamNode->getPosition();
cam_body->setPositionOrientation(posi, mCamNode->getOrientation());
cam_body->addForce(Vector3(0,-9.8,0));
cam_body->setStandardForceCallback();
cam_body->setAutoFreeze(0);
cam_body->attachToNode(mCamNode);
new OgreNewt::BasicJoints::UpVector( m_World, cam_body, Ogre::Vector3::UNIT_Y );
}


Thanks in advance!