From e8e3c211a490fbf0400725adb1d2523d62e7c447 Mon Sep 17 00:00:00 2001 From: emoose Date: Mon, 5 Nov 2012 19:48:07 +0000 Subject: [PATCH] Changed: MWRender::player: make camera rotation functions public; world: fix/clean scaleObject and rotateObject; rendering: add scaleObject code, fix rotateObject so it stores correct rotation --- apps/openmw/mwrender/player.hpp | 20 +++++------ apps/openmw/mwrender/renderingmanager.cpp | 43 +++++++++++++---------- apps/openmw/mwworld/worldimp.cpp | 27 +++++++------- 3 files changed, 47 insertions(+), 43 deletions(-) diff --git a/apps/openmw/mwrender/player.hpp b/apps/openmw/mwrender/player.hpp index b4d8983e4..29a68ca69 100644 --- a/apps/openmw/mwrender/player.hpp +++ b/apps/openmw/mwrender/player.hpp @@ -48,16 +48,6 @@ namespace MWRender /// Updates sound manager listener data void updateListener(); - void rotateCamera(const Ogre::Vector3 &rot, bool adjust); - - float getYaw(); - void setYaw(float angle); - - float getPitch(); - void setPitch(float angle); - - void compensateYaw(float diff); - void setLowHeight(bool low = true); public: @@ -69,7 +59,17 @@ namespace MWRender /// \param rot Rotation angles in radians /// \return true if player object needs to bo rotated physically bool rotate(const Ogre::Vector3 &rot, bool adjust); + + void rotateCamera(const Ogre::Vector3 &rot, bool adjust); + + float getYaw(); + void setYaw(float angle); + float getPitch(); + void setPitch(float angle); + + void compensateYaw(float diff); + std::string getHandle() const; /// Attach camera to object diff --git a/apps/openmw/mwrender/renderingmanager.cpp b/apps/openmw/mwrender/renderingmanager.cpp index bcc3a311d..2daf99087 100644 --- a/apps/openmw/mwrender/renderingmanager.cpp +++ b/apps/openmw/mwrender/renderingmanager.cpp @@ -258,39 +258,44 @@ void RenderingManager::moveObject (const MWWorld::Ptr& ptr, const Ogre::Vector3& setPosition (position); } -void RenderingManager::scaleObject (const MWWorld::Ptr& ptr, const Ogre::Vector3& scale){ - +void RenderingManager::scaleObject (const MWWorld::Ptr& ptr, const Ogre::Vector3& scale) +{ + ptr.getRefData().getBaseNode()->setScale(scale); } -bool -RenderingManager::rotateObject( - const MWWorld::Ptr &ptr, - Ogre::Vector3 &rot, - bool adjust) +bool RenderingManager::rotateObject( const MWWorld::Ptr &ptr, Ogre::Vector3 &rot, bool adjust) { bool isActive = ptr.getRefData().getBaseNode() != 0; bool isPlayer = isActive && ptr.getRefData().getHandle() == "player"; bool force = true; - if (isPlayer) { + if (isPlayer) force = mPlayer->rotate(rot, adjust); - } + 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 && isActive) { + if (!isPlayer && isActive) + { 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); - - ptr.getRefData().getBaseNode()->setOrientation(xr * yr * zr); + Ogre::Quaternion newo = adjust ? (xr * yr * zr) * ptr.getRefData().getBaseNode()->getOrientation() : xr * yr * zr; + rot.x = newo.x; + rot.y = newo.y; + rot.z = newo.z; + ptr.getRefData().getBaseNode()->setOrientation(newo); + } + else if(isPlayer) + { + rot.x = mPlayer->getPitch(); + rot.z = mPlayer->getYaw(); + } + else 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]; } - return force; } diff --git a/apps/openmw/mwworld/worldimp.cpp b/apps/openmw/mwworld/worldimp.cpp index 81fe14ba8..58d2a9eac 100644 --- a/apps/openmw/mwworld/worldimp.cpp +++ b/apps/openmw/mwworld/worldimp.cpp @@ -657,17 +657,16 @@ namespace MWWorld void World::moveObject (const Ptr& ptr, float x, float y, float z) { moveObjectImp(ptr, x, y, z); - - } void World::scaleObject (const Ptr& ptr, float scale) { MWWorld::Class::get(ptr).adjustScale(ptr,scale); - ptr.getCellRef().mScale = scale; - //scale = scale/ptr.getRefData().getBaseNode()->getScale().x; - ptr.getRefData().getBaseNode()->setScale(scale,scale,scale); + + if(ptr.getRefData().getBaseNode() == 0) + return; + mRendering->scaleObject(ptr, Vector3(scale,scale,scale)); mPhysics->scaleObject(ptr); } @@ -678,16 +677,16 @@ namespace MWWorld 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] = rot.x, objRot[1] = rot.y, objRot[2] = rot.z; - - - if (ptr.getRefData().getBaseNode() != 0) { - mPhysics->rotateObject(ptr); - } - } + float *objRot = ptr.getRefData().getPosition().rot; + if(ptr.getRefData().getBaseNode() == 0 || !mRendering->rotateObject(ptr, rot, adjust)) + { + objRot[0] = (adjust ? objRot[0] + rot.x : rot.x), objRot[1] = (adjust ? objRot[1] + rot.y : rot.y), objRot[2] = (adjust ? objRot[2] + rot.z : rot.z); + return; + } + // do this after rendering rotated the object so it gets changed by Class->adjustRotation + objRot[0] = rot.x, objRot[1] = rot.y, objRot[2] = rot.z; + mPhysics->rotateObject(ptr); } void World::safePlaceObject(const MWWorld::Ptr& ptr,MWWorld::CellStore &Cell,ESM::Position pos)