From 4d3abeedcbac1aaf583e16124cccf4df0618e26a Mon Sep 17 00:00:00 2001 From: Marc Zinnschlag Date: Fri, 28 Feb 2014 13:37:01 +0100 Subject: [PATCH] keep camera upright in 1st person mode --- apps/opencs/view/render/navigation1st.cpp | 23 +++++++++++++++++++++-- apps/opencs/view/render/scenewidget.cpp | 3 ++- 2 files changed, 23 insertions(+), 3 deletions(-) diff --git a/apps/opencs/view/render/navigation1st.cpp b/apps/opencs/view/render/navigation1st.cpp index b177c019b..b892d3e3e 100644 --- a/apps/opencs/view/render/navigation1st.cpp +++ b/apps/opencs/view/render/navigation1st.cpp @@ -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)) + mCamera->pitch (Ogre::Degree (deltaPitch)); + } return true; } diff --git a/apps/opencs/view/render/scenewidget.cpp b/apps/opencs/view/render/scenewidget.cpp index f864e1528..6f07c1b0d 100644 --- a/apps/opencs/view/render/scenewidget.cpp +++ b/apps/opencs/view/render/scenewidget.cpp @@ -102,7 +102,8 @@ namespace CSVRender if ((mNavigation = navigation)) { mNavigation->setFastModeFactor (mFast ? mFastFactor : 1); - mNavigation->activate (mCamera); + if (mNavigation->activate (mCamera)) + mUpdate = true; } }