From d2b7cb5bb2f168f1a189b6cb4b43e3bdf1e5c914 Mon Sep 17 00:00:00 2001 From: Sebastian Wick Date: Mon, 29 Jul 2013 16:43:16 +0200 Subject: [PATCH 1/2] First/Third person transitions with mouse wheel --- apps/openmw/mwrender/camera.cpp | 29 ++++++++++++++++++----- apps/openmw/mwrender/camera.hpp | 8 +++++++ apps/openmw/mwrender/renderingmanager.cpp | 10 +++++++- 3 files changed, 40 insertions(+), 7 deletions(-) diff --git a/apps/openmw/mwrender/camera.cpp b/apps/openmw/mwrender/camera.cpp index 59b320b65e..7dd1c84d86 100644 --- a/apps/openmw/mwrender/camera.cpp +++ b/apps/openmw/mwrender/camera.cpp @@ -25,7 +25,9 @@ namespace MWRender mHeight(128.f), mCameraDistance(300.f), mDistanceAdjusted(false), - mAnimation(NULL) + mAnimation(NULL), + mNearest(30.f), + mFurthest(800.f) { mVanity.enabled = false; mVanity.allowed = true; @@ -232,16 +234,21 @@ namespace MWRender if(mFirstPersonView && !mPreviewMode && !mVanity.enabled) return; + mIsFurthest = false; + mIsNearest = false; + Ogre::Vector3 v(0.f, 0.f, dist); if (adjust) { v += mCamera->getPosition(); } - if (v.z > 800.f) { - v.z = 800.f; - } else if (v.z < 10.f) { + if (v.z >= mFurthest) { + v.z = mFurthest; + mIsFurthest = true; + } else if (!override && v.z < 10.f) { v.z = 10.f; - } else if (override && v.z < 50.f) { - v.z = 50.f; + } else if (override && v.z <= mNearest) { + v.z = mNearest; + mIsNearest = true; } mCamera->setPosition(v); @@ -320,4 +327,14 @@ namespace MWRender { return mPreviewMode || mVanity.enabled; } + + bool Camera::isNearest() + { + return mIsNearest; + } + + bool Camera::isFurthest() + { + return mIsFurthest; + } } diff --git a/apps/openmw/mwrender/camera.hpp b/apps/openmw/mwrender/camera.hpp index 2993bad052..cbfbd09197 100644 --- a/apps/openmw/mwrender/camera.hpp +++ b/apps/openmw/mwrender/camera.hpp @@ -33,6 +33,10 @@ namespace MWRender bool mFirstPersonView; bool mPreviewMode; bool mFreeLook; + float mNearest; + float mFurthest; + bool mIsNearest; + bool mIsFurthest; struct { bool enabled, allowed; @@ -99,6 +103,10 @@ namespace MWRender void togglePlayerLooking(bool enable); bool isVanityOrPreviewModeEnabled(); + + bool isNearest(); + + bool isFurthest(); }; } diff --git a/apps/openmw/mwrender/renderingmanager.cpp b/apps/openmw/mwrender/renderingmanager.cpp index 4a9de259f7..2f48a0ce91 100644 --- a/apps/openmw/mwrender/renderingmanager.cpp +++ b/apps/openmw/mwrender/renderingmanager.cpp @@ -903,7 +903,15 @@ void RenderingManager::setCameraDistance(float dist, bool adjust, bool override) { if(!mCamera->isVanityOrPreviewModeEnabled() && !mCamera->isFirstPerson()) { - mCamera->setCameraDistance(-dist / 120.f * 10, adjust, override); + if(mCamera->isNearest() && dist > 0.f) + mCamera->toggleViewMode(); + else + mCamera->setCameraDistance(-dist / 120.f * 10, adjust, override); + } + else if(mCamera->isFirstPerson() && dist < 0.f) + { + mCamera->toggleViewMode(); + mCamera->setCameraDistance(0.f, false, override); } } From 7c24c0a64efc6de3f91dee20221cadc8ddb4ba7b Mon Sep 17 00:00:00 2001 From: Sebastian Wick Date: Mon, 29 Jul 2013 16:45:35 +0200 Subject: [PATCH 2/2] fix uninitialized variables --- apps/openmw/mwrender/camera.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/apps/openmw/mwrender/camera.cpp b/apps/openmw/mwrender/camera.cpp index 7dd1c84d86..941b8fde7e 100644 --- a/apps/openmw/mwrender/camera.cpp +++ b/apps/openmw/mwrender/camera.cpp @@ -27,7 +27,9 @@ namespace MWRender mDistanceAdjusted(false), mAnimation(NULL), mNearest(30.f), - mFurthest(800.f) + mFurthest(800.f), + mIsNearest(false), + mIsFurthest(false) { mVanity.enabled = false; mVanity.allowed = true;