From 2fd6438c0e515ca29995dbef5a07987b916f4adf Mon Sep 17 00:00:00 2001 From: Lubos Date: Thu, 20 Oct 2022 21:23:27 +0200 Subject: [PATCH] OpenXR - Camera distance adjust added --- Common/VR/PPSSPPVR.cpp | 1 + Common/VR/VRRenderer.cpp | 8 ++++++++ Common/VR/VRRenderer.h | 2 +- Core/Config.cpp | 1 + Core/Config.h | 1 + UI/GameSettingsScreen.cpp | 1 + 6 files changed, 13 insertions(+), 1 deletion(-) diff --git a/Common/VR/PPSSPPVR.cpp b/Common/VR/PPSSPPVR.cpp index 41101cdd9a..edb88a3400 100644 --- a/Common/VR/PPSSPPVR.cpp +++ b/Common/VR/PPSSPPVR.cpp @@ -319,6 +319,7 @@ bool StartVRRender() { // Set customizations VR_SetConfig(VR_CONFIG_6DOF_ENABLED, g_Config.bEnable6DoF); + VR_SetConfig(VR_CONFIG_CAMERA_DISTANCE, g_Config.iCameraDistance); VR_SetConfig(VR_CONFIG_CANVAS_DISTANCE, g_Config.iCanvasDistance); VR_SetConfig(VR_CONFIG_FOV_SCALE, g_Config.iFieldOfViewPercentage); VR_SetConfig(VR_CONFIG_MIRROR_UPDATED, false); diff --git a/Common/VR/VRRenderer.cpp b/Common/VR/VRRenderer.cpp index d4b35c596d..5a8084941b 100644 --- a/Common/VR/VRRenderer.cpp +++ b/Common/VR/VRRenderer.cpp @@ -338,6 +338,14 @@ bool VR_InitFrame( engine_t* engine ) { vrMatrix[matrix].M[1][3] -= hmdposition.y * (vrConfig[VR_CONFIG_MIRROR_AXIS_Y] ? -1.0f : 1.0f) * scale; vrMatrix[matrix].M[2][3] -= hmdposition.z * (vrConfig[VR_CONFIG_MIRROR_AXIS_Z] ? -1.0f : 1.0f) * scale; } + if (abs(vrConfig[VR_CONFIG_CAMERA_DISTANCE]) > 0) { + XrVector3f forward = {0.0f, 0.0f, (float)vrConfig[VR_CONFIG_CAMERA_DISTANCE] * scale}; + forward = XrQuaternionf_Rotate(invView.orientation, forward); + forward = XrVector3f_ScalarMultiply(forward, vrConfig[VR_CONFIG_MIRROR_AXIS_Z] ? -1.0f : 1.0f); + vrMatrix[matrix].M[0][3] += forward.x; + vrMatrix[matrix].M[1][3] += forward.y; + vrMatrix[matrix].M[2][3] += forward.z; + } if (vrConfig[VR_CONFIG_6DOF_PRECISE] && (matrix == VR_VIEW_MATRIX_RIGHT_EYE)) { float dx = fabs(invViewTransform[1].position.x - invViewTransform[0].position.x); float dy = fabs(invViewTransform[1].position.y - invViewTransform[0].position.y); diff --git a/Common/VR/VRRenderer.h b/Common/VR/VRRenderer.h index 16f70d9411..1c93f98752 100644 --- a/Common/VR/VRRenderer.h +++ b/Common/VR/VRRenderer.h @@ -7,7 +7,7 @@ enum VRConfig { //switching between 2D and 3D VR_CONFIG_MODE, VR_CONFIG_3D_GEOMETRY_COUNT, VR_CONFIG_FORCE_2D, //camera setup - VR_CONFIG_FOV_SCALE, VR_CONFIG_CANVAS_DISTANCE, + VR_CONFIG_FOV_SCALE, VR_CONFIG_CAMERA_DISTANCE, VR_CONFIG_CANVAS_DISTANCE, //6DoF VR_CONFIG_6DOF_ENABLED, VR_CONFIG_6DOF_SCALE, VR_CONFIG_6DOF_PRECISE, VR_CONFIG_MIRROR_UPDATED, VR_CONFIG_MIRROR_AXIS_X, VR_CONFIG_MIRROR_AXIS_Y, VR_CONFIG_MIRROR_AXIS_Z, diff --git a/Core/Config.cpp b/Core/Config.cpp index 650e1812fa..1e44ed482b 100644 --- a/Core/Config.cpp +++ b/Core/Config.cpp @@ -1206,6 +1206,7 @@ static ConfigSetting vrSettings[] = { ConfigSetting("VREnable", &g_Config.bEnableVR, true), ConfigSetting("VREnable6DoF", &g_Config.bEnable6DoF, true), ConfigSetting("VREnableStereo", &g_Config.bEnableStereo, false), + ConfigSetting("VRCameraDistance", &g_Config.iCameraDistance, 0), ConfigSetting("VRCanvasDistance", &g_Config.iCanvasDistance, 6), ConfigSetting("VRFieldOfView", &g_Config.iFieldOfViewPercentage, 100), diff --git a/Core/Config.h b/Core/Config.h index 10748583a9..497e8266bd 100644 --- a/Core/Config.h +++ b/Core/Config.h @@ -457,6 +457,7 @@ public: bool bEnableVR; bool bEnable6DoF; bool bEnableStereo; + int iCameraDistance; int iCanvasDistance; int iFieldOfViewPercentage; diff --git a/UI/GameSettingsScreen.cpp b/UI/GameSettingsScreen.cpp index a02190445a..158fc547d0 100644 --- a/UI/GameSettingsScreen.cpp +++ b/UI/GameSettingsScreen.cpp @@ -1130,6 +1130,7 @@ void GameSettingsScreen::CreateViews() { vrStereo->SetEnabledPtr(&g_Config.bEnableVR); vrSettings->Add(new ItemHeader(vr->T("VR camera"))); + vrSettings->Add(new PopupSliderChoice(&g_Config.iCameraDistance, -10, 10, vr->T("Camera distance adjust", "Camera distance adjust"), 1, screenManager(), "")); vrSettings->Add(new PopupSliderChoice(&g_Config.iCanvasDistance, 1, 10, vr->T("Distance to 2D menus and scenes", "Distance to 2D menus and scenes"), 1, screenManager(), "")); vrSettings->Add(new PopupSliderChoice(&g_Config.iFieldOfViewPercentage, 100, 200, vr->T("Field of view scale", "Headset's field of view scale"), 10, screenManager(), vr->T("% of native FoV"))); }