diff --git a/apps/openmw/mwrender/player.cpp b/apps/openmw/mwrender/player.cpp index 8b27adbe3..f05ea80ce 100644 --- a/apps/openmw/mwrender/player.cpp +++ b/apps/openmw/mwrender/player.cpp @@ -27,10 +27,10 @@ namespace MWRender // we are only interested in X and Y rotation // Rotate around X axis - Ogre::Quaternion xr(Ogre::Degree(rot.x), Ogre::Vector3::UNIT_X); + Ogre::Quaternion xr(Ogre::Radian(rot.x), Ogre::Vector3::UNIT_X); // Rotate around Y axis - Ogre::Quaternion yr(Ogre::Degree(-rot.z), Ogre::Vector3::UNIT_Y); + Ogre::Quaternion yr(Ogre::Radian(-rot.z), Ogre::Vector3::UNIT_Y); pitchNode->setOrientation(xr); yawNode->setOrientation(yr); @@ -56,8 +56,8 @@ namespace MWRender Ogre::SceneNode *pitchNode = mCamera->getParentSceneNode(); Ogre::SceneNode *yawNode = pitchNode->getParentSceneNode(); - pitchNode->pitch(Ogre::Degree(rot.x)); - yawNode->yaw(Ogre::Degree(-rot.z)); + pitchNode->pitch(Ogre::Radian(rot.x)); + yawNode->yaw(Ogre::Radian(-rot.z)); controlFlip(); updateListener(); diff --git a/apps/openmw/mwrender/player.hpp b/apps/openmw/mwrender/player.hpp index e5361e64b..a19e72ab0 100644 --- a/apps/openmw/mwrender/player.hpp +++ b/apps/openmw/mwrender/player.hpp @@ -37,9 +37,11 @@ namespace MWRender Player (Ogre::Camera *camera, Ogre::SceneNode* mNode); /// Set where the player is looking at. Uses Morrowind (euler) angles + /// \param rot Rotation angles in radians /// \return true if player object needs to bo rotated physically bool setRotation(const Ogre::Vector3 &rot); + /// \param rot Rotation angles in radians /// \return true if player object needs to bo rotated physically bool adjustRotation(const Ogre::Vector3 &rot); diff --git a/apps/openmw/mwrender/renderingmanager.cpp b/apps/openmw/mwrender/renderingmanager.cpp index 8719557ca..7180fea66 100644 --- a/apps/openmw/mwrender/renderingmanager.cpp +++ b/apps/openmw/mwrender/renderingmanager.cpp @@ -254,27 +254,31 @@ RenderingManager::rotateObject( Ogre::Vector3 &rot, bool adjust) { - if (ptr.getRefData().getHandle() == "player") { + bool isPlayer = ptr.getRefData().getHandle() == "player"; + bool force = true; + + if (isPlayer) { if (adjust) { - return mPlayer->adjustRotation(rot); + force = mPlayer->adjustRotation(rot); } else { - return mPlayer->setRotation(rot); + force = mPlayer->setRotation(rot); } } MWWorld::Class::get(ptr).adjustRotation(ptr, rot.x, rot.y, rot.z); if (adjust) { + /// \note Stored and passed in radians float *f = ptr.getRefData().getPosition().rot; rot.x += f[0], rot.y += f[1], rot.z += f[2]; } + if (!isPlayer) { + Ogre::Quaternion xr(Ogre::Radian(rot.x), Ogre::Vector3::UNIT_X); + Ogre::Quaternion yr(Ogre::Radian(rot.y), Ogre::Vector3::UNIT_Y); + Ogre::Quaternion zr(Ogre::Radian(rot.z), Ogre::Vector3::UNIT_Z); - Ogre::Quaternion xr(Ogre::Degree(rot.x), Ogre::Vector3::UNIT_X); - Ogre::Quaternion yr(Ogre::Degree(rot.y), Ogre::Vector3::UNIT_Y); - Ogre::Quaternion zr(Ogre::Degree(rot.z), Ogre::Vector3::UNIT_Z); - - ptr.getRefData().getBaseNode()->setOrientation(xr * yr * zr); - - return true; + ptr.getRefData().getBaseNode()->setOrientation(xr * yr * zr); + } + return force; } void diff --git a/apps/openmw/mwrender/renderingmanager.hpp b/apps/openmw/mwrender/renderingmanager.hpp index c0558b714..ef6f18a75 100644 --- a/apps/openmw/mwrender/renderingmanager.hpp +++ b/apps/openmw/mwrender/renderingmanager.hpp @@ -87,6 +87,7 @@ class RenderingManager: private RenderingInterface, public Ogre::WindowEventList void scaleObject (const MWWorld::Ptr& ptr, const Ogre::Vector3& scale); /// Rotates object accordingly to its type + /// \param rot euler angles in radians /// \param adjust indicates should rotation be set or adjusted /// \return true if object needs to be rotated physically bool rotateObject (const MWWorld::Ptr& ptr, Ogre::Vector3 &rot, bool adjust = false); diff --git a/apps/openmw/mwworld/scene.cpp b/apps/openmw/mwworld/scene.cpp index 531546a57..e02e10188 100644 --- a/apps/openmw/mwworld/scene.cpp +++ b/apps/openmw/mwworld/scene.cpp @@ -150,7 +150,11 @@ namespace MWWorld if (adjustPlayerPos) { world->moveObject(player, pos.pos[0], pos.pos[1], pos.pos[2]); - world->rotateObject(player, pos.rot[0], pos.rot[1], pos.rot[2]); + + float x = Ogre::Radian(pos.rot[0]).valueDegrees(); + float y = Ogre::Radian(pos.rot[1]).valueDegrees(); + float z = Ogre::Radian(pos.rot[2]).valueDegrees(); + world->rotateObject(player, x, y, z); } MWMechanics::MechanicsManager *mechMgr = diff --git a/apps/openmw/mwworld/worldimp.cpp b/apps/openmw/mwworld/worldimp.cpp index cf2d21014..605858eaf 100644 --- a/apps/openmw/mwworld/worldimp.cpp +++ b/apps/openmw/mwworld/worldimp.cpp @@ -629,12 +629,14 @@ namespace MWWorld void World::rotateObject (const Ptr& ptr,float x,float y,float z, bool adjust) { - Ogre::Vector3 rot(x, y, z); + Ogre::Vector3 rot; + rot.x = Ogre::Degree(x).valueRadians(); + rot.y = Ogre::Degree(y).valueRadians(); + rot.z = Ogre::Degree(z).valueRadians(); + if (mRendering->rotateObject(ptr, rot, adjust)) { float *objRot = ptr.getRefData().getPosition().rot; - objRot[0] = Ogre::Degree(rot.x).valueRadians(); - objRot[1] = Ogre::Degree(rot.y).valueRadians(); - objRot[2] = Ogre::Degree(rot.z).valueRadians(); + objRot[0] = rot.x, objRot[1] = rot.y, objRot[2] = rot.z; mPhysics->rotateObject( ptr.getRefData().getHandle(), diff --git a/apps/openmw/mwworld/worldimp.hpp b/apps/openmw/mwworld/worldimp.hpp index 24645cb8e..c3b0ed898 100644 --- a/apps/openmw/mwworld/worldimp.hpp +++ b/apps/openmw/mwworld/worldimp.hpp @@ -210,6 +210,8 @@ namespace MWWorld virtual void scaleObject (const Ptr& ptr, float scale); + /// Rotates object, uses degrees + /// \param adjust indicates rotation should be set or adjusted virtual void rotateObject (const Ptr& ptr,float x,float y,float z, bool adjust = false); virtual void indexToPosition (int cellX, int cellY, float &x, float &y, bool centre = false)