From 6e5d9d39dd9ea7c03b676ff6546aad63d15fbd95 Mon Sep 17 00:00:00 2001 From: madsbuvi Date: Mon, 26 Apr 2021 20:56:28 +0200 Subject: [PATCH] Improved camera logic to restore proper character orientation when loading a saved game. --- apps/openmw/mwvr/vrcamera.cpp | 38 ++++++++++++++++------------------- 1 file changed, 17 insertions(+), 21 deletions(-) diff --git a/apps/openmw/mwvr/vrcamera.cpp b/apps/openmw/mwvr/vrcamera.cpp index 750de4c2f..dd72a716b 100644 --- a/apps/openmw/mwvr/vrcamera.cpp +++ b/apps/openmw/mwvr/vrcamera.cpp @@ -10,6 +10,7 @@ #include "../mwbase/environment.hpp" #include "../mwbase/world.hpp" +#include "../mwbase/windowmanager.hpp" #include "../mwworld/player.hpp" #include "../mwworld/class.hpp" @@ -66,21 +67,6 @@ namespace MWVR } mShouldResetZ = false; } - - // When the cell changes, the game rotates the character appropriately. - // To respect this, reset yaw offset to make our yaw match the character. - MWBase::World* world = MWBase::Environment::get().getWorld(); - if (world) - { - auto& player = world->getPlayer(); - auto playerPtr = player.getPlayer(); - const auto& data = playerPtr.getRefData(); - float yaw = 0.f; - float pitch = 0.f; - float roll = 0.f; - getEulerAngles(mHeadPose.orientation, yaw, pitch, roll); - mYawOffset = data.getPosition().rot[2] - yaw; - } mShouldRecenter = false; Log(Debug::Verbose) << "Recentered"; } @@ -91,18 +77,18 @@ namespace MWVR auto& player = world->getPlayer(); auto playerPtr = player.getPlayer(); + + osg::Quat orientation; + getOrientation(orientation); float yaw = 0.f; float pitch = 0.f; float roll = 0.f; - getEulerAngles(mHeadPose.orientation, yaw, pitch, roll); - - yaw += mYawOffset; + getEulerAngles(orientation, yaw, pitch, roll); if (!player.isDisabled() && mTrackingNode) { world->rotateObject(playerPtr, pitch, 0.f, yaw, MWBase::RotationFlag_none); - world->rotateWorldObject(playerPtr, mHeadPose.orientation); } } @@ -136,8 +122,9 @@ namespace MWVR } else { - if (mShouldTrackPlayerCharacter) + if (mShouldTrackPlayerCharacter && !MWBase::Environment::get().getWindowManager()->isGuiMode()) applyTracking(); + Camera::updateCamera(cam); } } @@ -214,6 +201,15 @@ namespace MWVR { Camera::rotateCameraToTrackingPtr(); setRoll(-mTrackingPtr.getRefData().getPosition().rot[1] - mDeferredRotation.y()); + + // When the cell changes, openmw rotates the character. + // To make sure the player faces the same direction regardless of current orientation, + // compute the offset from character orientation to player orientation and reset yaw offset to this. + float yaw = 0.f; + float pitch = 0.f; + float roll = 0.f; + getEulerAngles(mHeadPose.orientation, yaw, pitch, roll); + mYawOffset = -mYaw - yaw; } osg::Quat VRCamera::stageRotation() @@ -225,7 +221,7 @@ namespace MWVR { mShouldRecenter = true; - // Use OR so we don't a pending reset of Z. + // Use OR so we don't negate a pending requests. mShouldResetZ |= resetZ; } }