Improved camera logic to restore proper character orientation when loading a saved game.

pull/615/head
madsbuvi 4 years ago
parent 2172aa17f1
commit 6e5d9d39dd

@ -10,6 +10,7 @@
#include "../mwbase/environment.hpp" #include "../mwbase/environment.hpp"
#include "../mwbase/world.hpp" #include "../mwbase/world.hpp"
#include "../mwbase/windowmanager.hpp"
#include "../mwworld/player.hpp" #include "../mwworld/player.hpp"
#include "../mwworld/class.hpp" #include "../mwworld/class.hpp"
@ -66,21 +67,6 @@ namespace MWVR
} }
mShouldResetZ = false; 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; mShouldRecenter = false;
Log(Debug::Verbose) << "Recentered"; Log(Debug::Verbose) << "Recentered";
} }
@ -91,18 +77,18 @@ namespace MWVR
auto& player = world->getPlayer(); auto& player = world->getPlayer();
auto playerPtr = player.getPlayer(); auto playerPtr = player.getPlayer();
osg::Quat orientation;
getOrientation(orientation);
float yaw = 0.f; float yaw = 0.f;
float pitch = 0.f; float pitch = 0.f;
float roll = 0.f; float roll = 0.f;
getEulerAngles(mHeadPose.orientation, yaw, pitch, roll); getEulerAngles(orientation, yaw, pitch, roll);
yaw += mYawOffset;
if (!player.isDisabled() && mTrackingNode) if (!player.isDisabled() && mTrackingNode)
{ {
world->rotateObject(playerPtr, pitch, 0.f, yaw, MWBase::RotationFlag_none); world->rotateObject(playerPtr, pitch, 0.f, yaw, MWBase::RotationFlag_none);
world->rotateWorldObject(playerPtr, mHeadPose.orientation);
} }
} }
@ -136,8 +122,9 @@ namespace MWVR
} }
else else
{ {
if (mShouldTrackPlayerCharacter) if (mShouldTrackPlayerCharacter && !MWBase::Environment::get().getWindowManager()->isGuiMode())
applyTracking(); applyTracking();
Camera::updateCamera(cam); Camera::updateCamera(cam);
} }
} }
@ -214,6 +201,15 @@ namespace MWVR
{ {
Camera::rotateCameraToTrackingPtr(); Camera::rotateCameraToTrackingPtr();
setRoll(-mTrackingPtr.getRefData().getPosition().rot[1] - mDeferredRotation.y()); 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() osg::Quat VRCamera::stageRotation()
@ -225,7 +221,7 @@ namespace MWVR
{ {
mShouldRecenter = true; 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; mShouldResetZ |= resetZ;
} }
} }

Loading…
Cancel
Save