From 355ca649c2ca5cfd3d82b7ff0d904c532ef87e81 Mon Sep 17 00:00:00 2001 From: greye Date: Sat, 11 Aug 2012 14:54:33 +0400 Subject: [PATCH] camera flip control rewritten --- apps/openmw/mwrender/player.cpp | 40 +++++++++++++++++++-------------- apps/openmw/mwrender/player.hpp | 2 +- 2 files changed, 24 insertions(+), 18 deletions(-) diff --git a/apps/openmw/mwrender/player.cpp b/apps/openmw/mwrender/player.cpp index f05ea80ce..94a3f71c8 100644 --- a/apps/openmw/mwrender/player.cpp +++ b/apps/openmw/mwrender/player.cpp @@ -27,7 +27,13 @@ namespace MWRender // we are only interested in X and Y rotation // Rotate around X axis - Ogre::Quaternion xr(Ogre::Radian(rot.x), Ogre::Vector3::UNIT_X); + Ogre::Radian radx(rot.x); + if (radx.valueDegrees() > 89.5f) { + radx = Ogre::Degree(89.5f); + } else if (radx.valueDegrees() < -89.5f) { + radx = Ogre::Degree(-89.5f); + } + Ogre::Quaternion xr(radx, Ogre::Vector3::UNIT_X); // Rotate around Y axis Ogre::Quaternion yr(Ogre::Radian(-rot.z), Ogre::Vector3::UNIT_Y); @@ -35,7 +41,6 @@ namespace MWRender pitchNode->setOrientation(xr); yawNode->setOrientation(yr); - controlFlip(); updateListener(); return !mVanityModeEnabled; @@ -56,35 +61,36 @@ namespace MWRender Ogre::SceneNode *pitchNode = mCamera->getParentSceneNode(); Ogre::SceneNode *yawNode = pitchNode->getParentSceneNode(); - pitchNode->pitch(Ogre::Radian(rot.x)); + float f = controlFlip(Ogre::Radian(rot.x).valueDegrees()); + if (f != 0.0) { + pitchNode->pitch(Ogre::Degree(f)); + } yawNode->yaw(Ogre::Radian(-rot.z)); - controlFlip(); updateListener(); return !mVanityModeEnabled; } - void Player::controlFlip() + float Player::controlFlip(float shift) { Ogre::SceneNode *pitchNode = mCamera->getParentSceneNode(); Ogre::Quaternion orient = pitchNode->getOrientation(); float pitchAngle = - (2 * Ogre::Degree(Ogre::Math::ACos(orient.w)).valueDegrees()); + (2 * Ogre::Degree(Ogre::Math::ASin(orient.x)).valueDegrees()); - // Limit the pitch between -90 degress and +90 degrees, Quake3-style. - if (pitchAngle > 90.0f) - { - Ogre::Real sqrt = Ogre::Math::Sqrt(0.5f); - if (orient.x > 0) { - // Set orientation to 90 degrees on X-axis. - pitchNode->setOrientation(Ogre::Quaternion(sqrt, sqrt, 0, 0)); - } else if (orient.x < 0) { - // Sets orientation to -90 degrees on X-axis. - pitchNode->setOrientation(Ogre::Quaternion(sqrt, -sqrt, 0, 0)); - } + if (pitchAngle + shift < 89.5f && pitchAngle + shift > -89.5f) { + return shift; } + if (pitchAngle > 0) { + float f = 89.5f - pitchAngle - shift; + return (f > 0.f) ? f : 0.f; + } else if (pitchAngle < 0) { + float f = -89.5 - pitchAngle - shift; + return (f < 0.f) ? f : 0.f; + } + return 0.f; } void Player::updateListener() diff --git a/apps/openmw/mwrender/player.hpp b/apps/openmw/mwrender/player.hpp index a19e72ab0..981ecfe0b 100644 --- a/apps/openmw/mwrender/player.hpp +++ b/apps/openmw/mwrender/player.hpp @@ -27,7 +27,7 @@ namespace MWRender bool mFirstPersonView; bool mVanityModeEnabled; - void controlFlip(); + float controlFlip(float shift = 0.f); /// Updates sound manager listener data void updateListener();