From a7aeda9a3b78d8939745a07fb55c7adb0f5b38cd Mon Sep 17 00:00:00 2001 From: greye Date: Sun, 12 Aug 2012 18:35:35 +0400 Subject: [PATCH] initial vanity mode support --- apps/openmw/mwrender/player.cpp | 85 +++++++++++++++++++---- apps/openmw/mwrender/player.hpp | 12 +++- apps/openmw/mwrender/renderingmanager.cpp | 13 +++- 3 files changed, 90 insertions(+), 20 deletions(-) diff --git a/apps/openmw/mwrender/player.cpp b/apps/openmw/mwrender/player.cpp index a99d69945..53642d615 100644 --- a/apps/openmw/mwrender/player.cpp +++ b/apps/openmw/mwrender/player.cpp @@ -24,19 +24,29 @@ namespace MWRender pitchNode->attachObject(mCamera); } - bool Player::rotate(const Ogre::Vector3 &rot, bool adjust) + void Player::rotateImpl(Ogre::Vector3 &rot, bool adjust, float r) { - bool force = !mVanityMode && !mPreviewMode; - Ogre::Vector3 newRot = rot; + rotateCamera(rot, adjust); - rotateCamera(newRot, adjust); - - if (!force || !mFirstPersonView) { - moveCamera(400.f, 1600.f); + if (mVanityMode || mPreviewMode || !mFirstPersonView) { + moveCamera(r); } updateListener(); + } - return force; + bool Player::rotate(const Ogre::Vector3 &rot, bool adjust) + { + Ogre::Vector3 _rot = rot; + rotateImpl(_rot, adjust, 400.f); + + mUpdates = 0; + mTimeIdle = 0.f; + + if (mVanityMode) { + toggleVanityMode(); + } + + return !mVanityMode && !mPreviewMode; } void Player::rotateCamera(Ogre::Vector3 &rot, bool adjust) @@ -67,7 +77,7 @@ namespace MWRender } } - void Player::moveCamera(float rsq, float hsq) + void Player::moveCamera(float r) { /* Ogre::Quaternion orient = @@ -97,7 +107,7 @@ namespace MWRender Ogre::Ray ray(Ogre::Vector3(0, 0, 0), dir); - mCameraNode->setPosition(ray.getPoint(800.f)); + mCameraNode->setPosition(ray.getPoint(r)); } std::string Player::getHandle() const @@ -145,13 +155,20 @@ namespace MWRender void Player::update(float duration) { + if (!mVanityMode) { + ++mUpdates; + mTimeIdle += duration; + if (mTimeIdle > 30.f) { + toggleVanityMode(); + } + } if (mFirstPersonView && !mVanityMode) { return; } if (mVanityMode) { - /// \todo adjust rotation constantly - } else { - /// \todo move camera closer or change view mode if needed + Ogre::Vector3 rot(0.f, 0.f, 0.f); + rot.z = Ogre::Degree(3.f * duration).valueRadians(); + rotateImpl(rot, true, 300.f); } } @@ -161,14 +178,28 @@ namespace MWRender if (mFirstPersonView) { mCameraNode->setPosition(0.f, 0.f, 0.f); } else { - moveCamera(400.f, 1600.f); + moveCamera(400.f); } } void Player::toggleVanityMode() { - /// \todo move camera mVanityMode = !mVanityMode; + + float r = 400.f; + Ogre::Vector3 rot(0.f, 0.f, 0.f); + if (mVanityMode) { + mPitch = getPitchAngle(); + mYaw = getYawAngle(); + + rot.x = Ogre::Degree(-30.f).valueRadians(); + rot.z = 0; + r = 300.f; + } else { + rot.x = Ogre::Degree(mPitch).valueRadians(); + rot.z = Ogre::Degree(mYaw).valueRadians(); + } + rotateImpl(rot, false, r); } void Player::togglePreviewMode() @@ -176,4 +207,28 @@ namespace MWRender /// \todo move camera mPreviewMode = !mPreviewMode; } + + float Player::getPitchAngle() + { + Ogre::Quaternion orient + = mCamera->getParentSceneNode()->getOrientation(); + + float angle = + (2 * Ogre::Degree(Ogre::Math::ASin(orient.x)).valueDegrees()); + + return angle; + } + + float Player::getYawAngle() + { + Ogre::Quaternion orient + = mCameraNode->getOrientation(); + + float angle = + (2 * Ogre::Degree(Ogre::Math::ASin(orient.y)).valueDegrees()); + if (orient.w < 0) { + angle = -angle; + } + return -angle; + } } diff --git a/apps/openmw/mwrender/player.hpp b/apps/openmw/mwrender/player.hpp index 739b4cd8b..d4c0eab5d 100644 --- a/apps/openmw/mwrender/player.hpp +++ b/apps/openmw/mwrender/player.hpp @@ -3,9 +3,8 @@ #include - namespace Ogre -{ +{ class Vector3; class Camera; class SceneNode; @@ -30,15 +29,22 @@ namespace MWRender bool mVanityMode; bool mPreviewMode; + float mPitch, mYaw; + float mTimeIdle; + int mUpdates; float limitPitchAngle(float limitAbs, float shift = 0.f); /// Updates sound manager listener data void updateListener(); + void rotateImpl(Ogre::Vector3 &rot, bool adjust, float r); void rotateCamera(Ogre::Vector3 &rot, bool adjust); - void moveCamera(float r, float h); + void moveCamera(float r); + + float getYawAngle(); + float getPitchAngle(); public: diff --git a/apps/openmw/mwrender/renderingmanager.cpp b/apps/openmw/mwrender/renderingmanager.cpp index 91d83caf3..d5e28e439 100644 --- a/apps/openmw/mwrender/renderingmanager.cpp +++ b/apps/openmw/mwrender/renderingmanager.cpp @@ -309,7 +309,17 @@ void RenderingManager::update (float duration){ mRendering.update(duration); - mLocalMap->updatePlayer( mRendering.getCamera()->getRealPosition(), mRendering.getCamera()->getRealOrientation() ); + float *fpos = + MWBase::Environment::get() + .getWorld() + ->getPlayer() + .getPlayer() + .getRefData() + .getPosition() + .pos; + Ogre::Vector3 pos(fpos[0], fpos[1], fpos[2]); + + mLocalMap->updatePlayer(pos, mRendering.getCamera()->getRealOrientation() ); if (mWater) { Ogre::Vector3 cam = mRendering.getCamera()->getRealPosition(); @@ -323,7 +333,6 @@ void RenderingManager::update (float duration){ ); mWater->update(duration); } - mPlayer->update(duration); }