keep camera upright in 1st person mode

actorid
Marc Zinnschlag 11 years ago
parent ae637d6abc
commit 4d3abeedcb

@ -11,7 +11,17 @@ bool CSVRender::Navigation1st::activate (Ogre::Camera *camera)
{
mCamera = camera;
mCamera->setFixedYawAxis (true);
return false;
Ogre::Radian pitch = mCamera->getOrientation().getPitch();
Ogre::Radian limit (Ogre::Math::PI/2-0.5);
if (pitch>limit)
mCamera->pitch (-(pitch-limit));
else if (pitch<-limit)
mCamera->pitch (pitch-limit);
return true;
}
bool CSVRender::Navigation1st::wheelMoved (int delta)
@ -29,7 +39,16 @@ bool CSVRender::Navigation1st::mouseMoved (const QPoint& delta, int mode)
mCamera->yaw (Ogre::Degree (getFactor (true) * delta.x()));
if (delta.y())
mCamera->pitch (Ogre::Degree (getFactor (true) * delta.y()));
{
Ogre::Radian oldPitch = mCamera->getOrientation().getPitch();
float deltaPitch = getFactor (true) * delta.y();
Ogre::Radian newPitch = oldPitch + Ogre::Degree (deltaPitch);
Ogre::Radian limit (Ogre::Math::PI/2-0.5);
if ((deltaPitch>0 && newPitch<limit) || (deltaPitch<0 && newPitch>-limit))
mCamera->pitch (Ogre::Degree (deltaPitch));
}
return true;
}

@ -102,7 +102,8 @@ namespace CSVRender
if ((mNavigation = navigation))
{
mNavigation->setFastModeFactor (mFast ? mFastFactor : 1);
mNavigation->activate (mCamera);
if (mNavigation->activate (mCamera))
mUpdate = true;
}
}

Loading…
Cancel
Save