1
0
Fork 1
mirror of https://github.com/TES3MP/openmw-tes3mp.git synced 2025-02-15 17:09:46 +00:00

Recenter view upon cell change.

This commit is contained in:
Mads Buvik Sandvei 2020-06-09 18:16:46 +02:00
parent 7f3930c312
commit 8ba341172d
3 changed files with 32 additions and 2 deletions

View file

@ -959,6 +959,11 @@ private:
mXRInput->applyHaptics(OpenXRInput::RIGHT_HAND, intensity);
}
void OpenXRInputManager::requestRecenter()
{
mShouldRecenter = true;
}
OpenXRInputManager::OpenXRInputManager(
SDL_Window* window,
osg::ref_ptr<osgViewer::Viewer> viewer,
@ -1212,7 +1217,7 @@ private:
case OpenXRInput::A_Recenter:
xrGUIManager->updateTracking();
if(!MWBase::Environment::get().getWindowManager()->isGuiMode())
mShouldRecenter = true;
requestRecenter();
break;
case MWInput::A_Use:
if (mActivationIndication || MWBase::Environment::get().getWindowManager()->isGuiMode())
@ -1256,10 +1261,20 @@ private:
if (mShouldRecenter)
{
mHeadOffset = osg::Vec3(0, 0, 0);
// Move position of head to center of character
// Z should not be affected
mHeadOffset = osg::Vec3(0, 0, 0);
mHeadOffset.z() = mHeadPose.position.z();
// Adjust orientation to zero yaw
float yaw = 0.f;
float pitch = 0.f;
float roll = 0.f;
getEulerAngles(mHeadPose.orientation, yaw, pitch, roll);
mYaw = -yaw;
mShouldRecenter = false;
Log(Debug::Verbose) << "Recentered (" << mYaw << ")";
}
else
{

View file

@ -53,6 +53,8 @@ namespace MWVR
void applyHapticsLeftHand(float intensity) override;
void applyHapticsRightHand(float intensity) override;
void requestRecenter();
std::unique_ptr<OpenXRInput> mXRInput;
std::unique_ptr<RealisticCombat::StateMachine> mRealisticCombat;
Pose mHeadPose{};

View file

@ -76,6 +76,7 @@
#ifdef USE_OPENXR
#include "../mwvr/vrenvironment.hpp"
#include "../mwvr/vranimation.hpp"
#include "../mwvr/openxrinputmanager.hpp"
#endif
namespace
@ -1066,6 +1067,12 @@ namespace MWWorld
removeContainerScripts(getPlayerPtr());
mWorldScene->changeToInteriorCell(cellName, position, adjustPlayerPos, changeEvent);
addContainerScripts(getPlayerPtr(), getPlayerPtr().getCell());
#ifdef USE_OPENXR
auto* xrInput = MWVR::Environment::get().getInputManager();
if (xrInput)
xrInput->requestRecenter();
#endif
}
void World::changeToExteriorCell (const ESM::Position& position, bool adjustPlayerPos, bool changeEvent)
@ -1081,6 +1088,12 @@ namespace MWWorld
removeContainerScripts(getPlayerPtr());
mWorldScene->changeToExteriorCell(position, adjustPlayerPos, changeEvent);
addContainerScripts(getPlayerPtr(), getPlayerPtr().getCell());
#ifdef USE_OPENXR
auto* xrInput = MWVR::Environment::get().getInputManager();
if (xrInput)
xrInput->requestRecenter();
#endif
}
void World::changeToCell (const ESM::CellId& cellId, const ESM::Position& position, bool adjustPlayerPos, bool changeEvent)