From 7d1b50d6f98072ba70600b6939045701fa4d7558 Mon Sep 17 00:00:00 2001 From: Lubos Date: Sat, 28 Jan 2023 18:36:29 +0100 Subject: [PATCH] OpenXR - Combine game and VR camera rotation --- Common/VR/PPSSPPVR.cpp | 35 ++++++++++++++++++----------------- Core/Config.cpp | 2 +- UI/GameSettingsScreen.cpp | 2 +- 3 files changed, 20 insertions(+), 19 deletions(-) diff --git a/Common/VR/PPSSPPVR.cpp b/Common/VR/PPSSPPVR.cpp index b0719c4d34..a22680d1a3 100644 --- a/Common/VR/PPSSPPVR.cpp +++ b/Common/VR/PPSSPPVR.cpp @@ -106,6 +106,7 @@ static bool controllerMotion[2][5] = {}; static bool hmdMotion[4] = {}; static float hmdMotionLast[2] = {}; static float hmdMotionDiff[2] = {}; +static float hmdMotionDiffLast[2] = {}; static int mouseController = 1; static bool mousePressed = false; @@ -327,14 +328,16 @@ void UpdateVRInput(bool haptics, float dp_xscale, float dp_yscale) { while (deltaYaw < -180) deltaYaw += 360; hmdMotionLast[0] = pitch; hmdMotionLast[1] = yaw; - hmdMotionDiff[0] += deltaPitch * g_Config.fHeadRotationScale; - hmdMotionDiff[1] += deltaYaw * g_Config.fHeadRotationScale; + hmdMotionDiffLast[0] = hmdMotionDiff[0]; + hmdMotionDiffLast[1] = hmdMotionDiff[1]; + hmdMotionDiff[0] += deltaPitch; + hmdMotionDiff[1] += deltaYaw; pitch = hmdMotionDiff[0]; yaw = hmdMotionDiff[1]; } bool activate; - float limit = isVR ? 1 : 20; + float limit = isVR ? g_Config.fHeadRotationScale : 20; keyInput.deviceId = DEVICE_ID_XR_HMD; // vertical rotations @@ -670,22 +673,20 @@ bool StartVRRender() { invView = XrPosef_Inverse(invView); } - // disable specific rotations if requested - switch (g_Config.iHeadRotation) { - case 1: //horizontal - my = 0; - break; - case 2: //horizontal+vertical - mx = 0; - my = 0; - break; - } + // decompose rotation + XrVector3f rotation = XrQuaternionf_ToEulerAngles(invView.orientation); + float mPitch = mx * ToRadians(rotation.x); + float mYaw = my * ToRadians(rotation.y); + float mRoll = mz * ToRadians(rotation.z); + + // use in-game camera interpolated rotation + if (g_Config.iHeadRotation >= 2) mPitch = -mx * ToRadians(hmdMotionDiffLast[0]); // vertical + if (g_Config.iHeadRotation >= 1) mYaw = -my * ToRadians(hmdMotionDiffLast[1]); // horizontal // create updated quaternion - XrVector3f rotation = XrQuaternionf_ToEulerAngles(invView.orientation); - XrQuaternionf pitch = XrQuaternionf_CreateFromVectorAngle({1, 0, 0}, mx * ToRadians(rotation.x)); - XrQuaternionf yaw = XrQuaternionf_CreateFromVectorAngle({0, 1, 0}, my * ToRadians(rotation.y)); - XrQuaternionf roll = XrQuaternionf_CreateFromVectorAngle({0, 0, 1}, mz * ToRadians(rotation.z)); + XrQuaternionf pitch = XrQuaternionf_CreateFromVectorAngle({1, 0, 0}, mPitch); + XrQuaternionf yaw = XrQuaternionf_CreateFromVectorAngle({0, 1, 0}, mYaw); + XrQuaternionf roll = XrQuaternionf_CreateFromVectorAngle({0, 0, 1}, mRoll); invView.orientation = XrQuaternionf_Multiply(roll, XrQuaternionf_Multiply(pitch, yaw)); float M[16]; diff --git a/Core/Config.cpp b/Core/Config.cpp index dff6e44b2c..17b5c36b25 100644 --- a/Core/Config.cpp +++ b/Core/Config.cpp @@ -1197,7 +1197,7 @@ static ConfigSetting vrSettings[] = { ConfigSetting("VRFieldOfView", &g_Config.fFieldOfViewPercentage, 100.0f), ConfigSetting("VRHeadUpDisplayScale", &g_Config.fHeadUpDisplayScale, 0.3f), ConfigSetting("VRMotionLength", &g_Config.fMotionLength, 0.5f), - ConfigSetting("VRHeadRotationScale", &g_Config.fHeadRotationScale, 0.5f), + ConfigSetting("VRHeadRotationScale", &g_Config.fHeadRotationScale, 5.0f), ConfigSetting("VRHeadRotation", &g_Config.iHeadRotation, 0), ConfigSetting(false), diff --git a/UI/GameSettingsScreen.cpp b/UI/GameSettingsScreen.cpp index 0829ca7a50..897d84ad3e 100644 --- a/UI/GameSettingsScreen.cpp +++ b/UI/GameSettingsScreen.cpp @@ -1087,7 +1087,7 @@ void GameSettingsScreen::CreateViews() { vrSettings->Add(new ItemHeader(vr->T("Experts only"))); static const char *vrHeadRotations[] = { vr->T("Disabled"), vr->T("Horizontal only"), vr->T("Horizontal and vertical") }; vrSettings->Add(new PopupMultiChoice(&g_Config.iHeadRotation, vr->T("Map HMD rotations on keys instead of VR camera"), vrHeadRotations, 0, ARRAY_SIZE(vrHeadRotations), vr->GetName(), screenManager())); - PopupSliderChoiceFloat *vrHeadRotationScale = vrSettings->Add(new PopupSliderChoiceFloat(&g_Config.fHeadRotationScale, 0.3f, 1.0f, vr->T("Scale HMD rotations affects game camera"), 0.1f, screenManager(), "")); + PopupSliderChoiceFloat *vrHeadRotationScale = vrSettings->Add(new PopupSliderChoiceFloat(&g_Config.fHeadRotationScale, 0.1f, 10.0f, vr->T("Game camera rotation step per frame"), 0.1f, screenManager(), "°")); vrHeadRotationScale->SetEnabledFunc([&] { return g_Config.iHeadRotation > 0; }); vrSettings->Add(new CheckBox(&g_Config.bEnableMotions, vr->T("Map controller movements to keys"))); PopupSliderChoiceFloat *vrMotions = vrSettings->Add(new PopupSliderChoiceFloat(&g_Config.fMotionLength, 0.3f, 1.0f, vr->T("Motion needed to generate action"), 0.1f, screenManager(), vr->T("m")));