From 0ae1d75daffd2713148cec52456bb6ce10dd6270 Mon Sep 17 00:00:00 2001 From: Lubos Date: Thu, 17 Nov 2022 10:22:01 +0100 Subject: [PATCH] OpenXR - Support camera adjust using joystick --- Common/VR/PPSSPPVR.cpp | 24 +++++++++++++++--------- Common/VR/PPSSPPVR.h | 3 ++- UI/NativeApp.cpp | 9 +++++++-- 3 files changed, 24 insertions(+), 12 deletions(-) diff --git a/Common/VR/PPSSPPVR.cpp b/Common/VR/PPSSPPVR.cpp index 92e00f898a..e35066dc14 100644 --- a/Common/VR/PPSSPPVR.cpp +++ b/Common/VR/PPSSPPVR.cpp @@ -36,6 +36,7 @@ enum VRMirroring { VR_MIRRORING_COUNT }; +static std::map pspAxis; static std::map pspKeys; static int vr3DGeometryCount = 0; @@ -325,7 +326,12 @@ void UpdateVRInput(bool(*NativeKey)(const KeyInput &key), bool(*NativeTouch)(con } } -bool UpdateVRSpecialKeys(const KeyInput &key) { +bool UpdateVRAxis(const AxisInput &axis) { + pspAxis[axis.axisId] = axis.value; + return !pspKeys[VIRTKEY_VR_CAMERA_ADJUST]; +} + +bool UpdateVRKeys(const KeyInput &key) { std::vector nativeKeys; if (KeyMap::KeyToPspButton(key.deviceId, key.keyCode, &nativeKeys)) { for (int& nativeKey : nativeKeys) { @@ -562,16 +568,16 @@ bool StartVRRender() { // Camera control if (pspKeys[VIRTKEY_VR_CAMERA_ADJUST]) { //left joystick controls height and side - if (pspKeys[CTRL_LEFT]) g_Config.fCameraSide -= 0.05f; - if (pspKeys[CTRL_RIGHT]) g_Config.fCameraSide += 0.05f; - if (pspKeys[CTRL_DOWN]) g_Config.fCameraHeight -= 0.05f; - if (pspKeys[CTRL_UP]) g_Config.fCameraHeight += 0.05f; + if (pspKeys[CTRL_LEFT] || (pspAxis[JOYSTICK_AXIS_X] < -0.5f)) g_Config.fCameraSide -= 0.05f; + if (pspKeys[CTRL_RIGHT] || (pspAxis[JOYSTICK_AXIS_X] > 0.5f)) g_Config.fCameraSide += 0.05f; + if (pspKeys[CTRL_DOWN] || (pspAxis[JOYSTICK_AXIS_Y] > 0.5f)) g_Config.fCameraHeight -= 0.05f; + if (pspKeys[CTRL_UP] || (pspAxis[JOYSTICK_AXIS_Y] < -0.5f)) g_Config.fCameraHeight += 0.05f; //right joystick controls distance and fov - if (pspKeys[VIRTKEY_AXIS_X_MIN]) g_Config.fFieldOfViewPercentage -= 1.0f; - if (pspKeys[VIRTKEY_AXIS_X_MAX]) g_Config.fFieldOfViewPercentage += 1.0f; - if (pspKeys[VIRTKEY_AXIS_Y_MIN]) g_Config.fCameraDistance -= 0.1f; - if (pspKeys[VIRTKEY_AXIS_Y_MAX]) g_Config.fCameraDistance += 0.1f; + if (pspKeys[VIRTKEY_AXIS_X_MIN] || (pspAxis[JOYSTICK_AXIS_Z] < -0.5f)) g_Config.fFieldOfViewPercentage -= 1.0f; + if (pspKeys[VIRTKEY_AXIS_X_MAX] || (pspAxis[JOYSTICK_AXIS_Z] > 0.5f)) g_Config.fFieldOfViewPercentage += 1.0f; + if (pspKeys[VIRTKEY_AXIS_Y_MIN] || (pspAxis[JOYSTICK_AXIS_RZ] > 0.5f)) g_Config.fCameraDistance -= 0.1f; + if (pspKeys[VIRTKEY_AXIS_Y_MAX] || (pspAxis[JOYSTICK_AXIS_RZ] < -0.5f)) g_Config.fCameraDistance += 0.1f; // Reset values if (pspKeys[VIRTKEY_VR_CAMERA_RESET]) { diff --git a/Common/VR/PPSSPPVR.h b/Common/VR/PPSSPPVR.h index c47fada705..f83f7e721e 100644 --- a/Common/VR/PPSSPPVR.h +++ b/Common/VR/PPSSPPVR.h @@ -23,7 +23,8 @@ void InitVROnAndroid(void* vm, void* activity, const char* system, int version, void EnterVR(bool firstStart, void* vulkanContext); void GetVRResolutionPerEye(int* width, int* height); void UpdateVRInput(bool(*NativeKey)(const KeyInput &key), bool(*NativeTouch)(const TouchInput &touch), bool haptics, float dp_xscale, float dp_yscale); -bool UpdateVRSpecialKeys(const KeyInput &key); +bool UpdateVRAxis(const AxisInput &axis); +bool UpdateVRKeys(const KeyInput &key); // VR games compatibility void PreprocessStepVR(void* step); diff --git a/UI/NativeApp.cpp b/UI/NativeApp.cpp index 2e8e202b8b..0bea47395a 100644 --- a/UI/NativeApp.cpp +++ b/UI/NativeApp.cpp @@ -1306,8 +1306,8 @@ bool NativeTouch(const TouchInput &touch) { } bool NativeKey(const KeyInput &key) { - // Special key VR actions - if (IsVREnabled() && !UpdateVRSpecialKeys(key)) { + // VR actions + if (IsVREnabled() && !UpdateVRKeys(key)) { return false; } @@ -1331,6 +1331,11 @@ bool NativeKey(const KeyInput &key) { } bool NativeAxis(const AxisInput &axis) { + // VR actions + if (IsVREnabled() && !UpdateVRAxis(axis)) { + return false; + } + if (!screenManager) { // Too early. return false;