From b740bfbcfb67a724f84893c34eba74a1c09a7e07 Mon Sep 17 00:00:00 2001 From: Lubos Date: Mon, 31 Oct 2022 11:59:07 +0100 Subject: [PATCH 1/5] OpenXR - Map controller motions on keys --- Common/Input/KeyCodes.h | 9 +++++++- Common/VR/PPSSPPVR.cpp | 51 +++++++++++++++++++++++++++++++++++++++++ Core/KeyMap.cpp | 7 ++++++ 3 files changed, 66 insertions(+), 1 deletion(-) diff --git a/Common/Input/KeyCodes.h b/Common/Input/KeyCodes.h index f00dbe8091..15f42c07c1 100644 --- a/Common/Input/KeyCodes.h +++ b/Common/Input/KeyCodes.h @@ -261,7 +261,14 @@ typedef enum _keycode_t { NKCODE_EXT_MOUSEBUTTON_4 = 1006, NKCODE_EXT_MOUSEBUTTON_5 = 1007, NKCODE_EXT_MOUSEWHEEL_UP = 1008, - NKCODE_EXT_MOUSEWHEEL_DOWN = 1009 + NKCODE_EXT_MOUSEWHEEL_DOWN = 1009, + + // Virtual reality controller motion + NKCODE_EXT_MOTION_UP = 1101, + NKCODE_EXT_MOTION_DOWN = 1102, + NKCODE_EXT_MOTION_LEFT = 1103, + NKCODE_EXT_MOTION_RIGHT = 1104, + NKCODE_EXT_MOTION_FORWARD = 1105, } keycode_t; enum AndroidJoystickAxis { diff --git a/Common/VR/PPSSPPVR.cpp b/Common/VR/PPSSPPVR.cpp index 0c496d55e0..8c3ae30169 100644 --- a/Common/VR/PPSSPPVR.cpp +++ b/Common/VR/PPSSPPVR.cpp @@ -78,6 +78,7 @@ static std::vector controllerMapping[2] = { leftControllerMapping, rightControllerMapping }; +static bool controllerMotion[2][5]; static int mouseController = -1; static bool mousePressed[] = {false, false}; @@ -203,6 +204,56 @@ void UpdateVRInput(bool(*NativeKey)(const KeyInput &key), bool(*NativeTouch)(con } } + //motion control + bool activate; + for (int j = 0; j < 2; j++) { + float limit = 0.5f; //length of needed movement in meters + XrVector3f axis = {0, 1, 0}; + float center = ToRadians((float)VR_GetConfig(VR_CONFIG_MENU_YAW)); + XrQuaternionf orientation = XrQuaternionf_CreateFromVectorAngle(axis, center); + XrVector3f position = XrQuaternionf_Rotate(orientation, IN_VRGetPose(j).position); + + //up + activate = position.y > limit; + keyInput.flags = activate ? KEY_DOWN : KEY_UP; + keyInput.keyCode = NKCODE_EXT_MOTION_UP; + keyInput.deviceId = controllerIds[j]; + if (controllerMotion[j][0] != activate) NativeKey(keyInput); + controllerMotion[j][0] = activate; + + //down + activate = position.y < -limit * 1.5f; + keyInput.flags = activate ? KEY_DOWN : KEY_UP; + keyInput.keyCode = NKCODE_EXT_MOTION_DOWN; + keyInput.deviceId = controllerIds[j]; + if (controllerMotion[j][1] != activate) NativeKey(keyInput); + controllerMotion[j][1] = activate; + + //left + activate = position.x < -limit * (j == 0 ? 1.0f : 0.25f); + keyInput.flags = activate ? KEY_DOWN : KEY_UP; + keyInput.keyCode = NKCODE_EXT_MOTION_LEFT; + keyInput.deviceId = controllerIds[j]; + if (controllerMotion[j][2] != activate) NativeKey(keyInput); + controllerMotion[j][2] = activate; + + //right + activate = position.x > limit * (j == 1 ? 1.0f : 0.25f); + keyInput.flags = activate ? KEY_DOWN : KEY_UP; + keyInput.keyCode = NKCODE_EXT_MOTION_RIGHT; + keyInput.deviceId = controllerIds[j]; + if (controllerMotion[j][3] != activate) NativeKey(keyInput); + controllerMotion[j][3] = activate; + + //forward + activate = position.z < -limit; + keyInput.flags = activate ? KEY_DOWN : KEY_UP; + keyInput.keyCode = NKCODE_EXT_MOTION_FORWARD; + keyInput.deviceId = controllerIds[j]; + if (controllerMotion[j][4] != activate) NativeKey(keyInput); + controllerMotion[j][4] = activate; + } + //mouse cursor if (mouseController >= 0) { //get position on screen diff --git a/Core/KeyMap.cpp b/Core/KeyMap.cpp index 30b005d86f..0be4dd7182 100644 --- a/Core/KeyMap.cpp +++ b/Core/KeyMap.cpp @@ -304,6 +304,13 @@ static const KeyMap_IntStrPair key_names[] = { {NKCODE_EXT_MOUSEWHEEL_UP, "MWheelU"}, {NKCODE_EXT_MOUSEWHEEL_DOWN, "MWheelD"}, + + {NKCODE_EXT_MOTION_UP, "MotionUp"}, + {NKCODE_EXT_MOTION_DOWN, "MotionDown"}, + {NKCODE_EXT_MOTION_LEFT, "MotionLeft"}, + {NKCODE_EXT_MOTION_RIGHT, "MotionRight"}, + {NKCODE_EXT_MOTION_FORWARD, "MotionFwd"}, + {NKCODE_START_QUESTION, "¿"}, {NKCODE_LEFTBRACE, "{"}, {NKCODE_RIGHTBRACE, "}"}, From 0101c464a5f3090fd21a2cdde5eefd56ccf5c585 Mon Sep 17 00:00:00 2001 From: Lubos Date: Mon, 31 Oct 2022 12:17:30 +0100 Subject: [PATCH 2/5] OpenXR - Option to disable controller mapping --- Common/VR/PPSSPPVR.cpp | 86 ++++++++++++++++++++------------------- Core/Config.cpp | 1 + Core/Config.h | 1 + UI/GameSettingsScreen.cpp | 2 + 4 files changed, 48 insertions(+), 42 deletions(-) diff --git a/Common/VR/PPSSPPVR.cpp b/Common/VR/PPSSPPVR.cpp index 8c3ae30169..4c85590107 100644 --- a/Common/VR/PPSSPPVR.cpp +++ b/Common/VR/PPSSPPVR.cpp @@ -205,53 +205,55 @@ void UpdateVRInput(bool(*NativeKey)(const KeyInput &key), bool(*NativeTouch)(con } //motion control - bool activate; - for (int j = 0; j < 2; j++) { - float limit = 0.5f; //length of needed movement in meters - XrVector3f axis = {0, 1, 0}; - float center = ToRadians((float)VR_GetConfig(VR_CONFIG_MENU_YAW)); - XrQuaternionf orientation = XrQuaternionf_CreateFromVectorAngle(axis, center); - XrVector3f position = XrQuaternionf_Rotate(orientation, IN_VRGetPose(j).position); + if (g_Config.bEnableMotions) { + for (int j = 0; j < 2; j++) { + bool activate; + float limit = 0.5f; //length of needed movement in meters + XrVector3f axis = {0, 1, 0}; + float center = ToRadians((float)VR_GetConfig(VR_CONFIG_MENU_YAW)); + XrQuaternionf orientation = XrQuaternionf_CreateFromVectorAngle(axis, center); + XrVector3f position = XrQuaternionf_Rotate(orientation, IN_VRGetPose(j).position); - //up - activate = position.y > limit; - keyInput.flags = activate ? KEY_DOWN : KEY_UP; - keyInput.keyCode = NKCODE_EXT_MOTION_UP; - keyInput.deviceId = controllerIds[j]; - if (controllerMotion[j][0] != activate) NativeKey(keyInput); - controllerMotion[j][0] = activate; + //up + activate = position.y > limit; + keyInput.flags = activate ? KEY_DOWN : KEY_UP; + keyInput.keyCode = NKCODE_EXT_MOTION_UP; + keyInput.deviceId = controllerIds[j]; + if (controllerMotion[j][0] != activate) NativeKey(keyInput); + controllerMotion[j][0] = activate; - //down - activate = position.y < -limit * 1.5f; - keyInput.flags = activate ? KEY_DOWN : KEY_UP; - keyInput.keyCode = NKCODE_EXT_MOTION_DOWN; - keyInput.deviceId = controllerIds[j]; - if (controllerMotion[j][1] != activate) NativeKey(keyInput); - controllerMotion[j][1] = activate; + //down + activate = position.y < -limit * 1.5f; + keyInput.flags = activate ? KEY_DOWN : KEY_UP; + keyInput.keyCode = NKCODE_EXT_MOTION_DOWN; + keyInput.deviceId = controllerIds[j]; + if (controllerMotion[j][1] != activate) NativeKey(keyInput); + controllerMotion[j][1] = activate; - //left - activate = position.x < -limit * (j == 0 ? 1.0f : 0.25f); - keyInput.flags = activate ? KEY_DOWN : KEY_UP; - keyInput.keyCode = NKCODE_EXT_MOTION_LEFT; - keyInput.deviceId = controllerIds[j]; - if (controllerMotion[j][2] != activate) NativeKey(keyInput); - controllerMotion[j][2] = activate; + //left + activate = position.x < -limit * (j == 0 ? 1.0f : 0.25f); + keyInput.flags = activate ? KEY_DOWN : KEY_UP; + keyInput.keyCode = NKCODE_EXT_MOTION_LEFT; + keyInput.deviceId = controllerIds[j]; + if (controllerMotion[j][2] != activate) NativeKey(keyInput); + controllerMotion[j][2] = activate; - //right - activate = position.x > limit * (j == 1 ? 1.0f : 0.25f); - keyInput.flags = activate ? KEY_DOWN : KEY_UP; - keyInput.keyCode = NKCODE_EXT_MOTION_RIGHT; - keyInput.deviceId = controllerIds[j]; - if (controllerMotion[j][3] != activate) NativeKey(keyInput); - controllerMotion[j][3] = activate; + //right + activate = position.x > limit * (j == 1 ? 1.0f : 0.25f); + keyInput.flags = activate ? KEY_DOWN : KEY_UP; + keyInput.keyCode = NKCODE_EXT_MOTION_RIGHT; + keyInput.deviceId = controllerIds[j]; + if (controllerMotion[j][3] != activate) NativeKey(keyInput); + controllerMotion[j][3] = activate; - //forward - activate = position.z < -limit; - keyInput.flags = activate ? KEY_DOWN : KEY_UP; - keyInput.keyCode = NKCODE_EXT_MOTION_FORWARD; - keyInput.deviceId = controllerIds[j]; - if (controllerMotion[j][4] != activate) NativeKey(keyInput); - controllerMotion[j][4] = activate; + //forward + activate = position.z < -limit; + keyInput.flags = activate ? KEY_DOWN : KEY_UP; + keyInput.keyCode = NKCODE_EXT_MOTION_FORWARD; + keyInput.deviceId = controllerIds[j]; + if (controllerMotion[j][4] != activate) NativeKey(keyInput); + controllerMotion[j][4] = activate; + } } //mouse cursor diff --git a/Core/Config.cpp b/Core/Config.cpp index f62a4baaae..94f96d15ad 100644 --- a/Core/Config.cpp +++ b/Core/Config.cpp @@ -1208,6 +1208,7 @@ static ConfigSetting vrSettings[] = { ConfigSetting("VREnable", &g_Config.bEnableVR, true), ConfigSetting("VREnable6DoF", &g_Config.bEnable6DoF, true), ConfigSetting("VREnableStereo", &g_Config.bEnableStereo, false), + ConfigSetting("VREnableMotions", &g_Config.bEnableMotions, true), ConfigSetting("VRCameraDistance", &g_Config.fCameraDistance, 0.0f), ConfigSetting("VRCameraHeight", &g_Config.fCameraHeight, 0.0f), ConfigSetting("VRCameraSide", &g_Config.fCameraSide, 0.0f), diff --git a/Core/Config.h b/Core/Config.h index a494cf4c61..3415cc55e0 100644 --- a/Core/Config.h +++ b/Core/Config.h @@ -463,6 +463,7 @@ public: bool bEnableVR; bool bEnable6DoF; bool bEnableStereo; + bool bEnableMotions; float fCameraDistance; float fCameraHeight; float fCameraSide; diff --git a/UI/GameSettingsScreen.cpp b/UI/GameSettingsScreen.cpp index 6b68d9c866..a7044d946f 100644 --- a/UI/GameSettingsScreen.cpp +++ b/UI/GameSettingsScreen.cpp @@ -1163,6 +1163,8 @@ void GameSettingsScreen::CreateViews() { vr6DoF->SetEnabledPtr(&g_Config.bEnableVR); CheckBox *vrStereo = vrSettings->Add(new CheckBox(&g_Config.bEnableStereo, vr->T("Stereoscopic vision (Experimental)"))); vrStereo->SetEnabledPtr(&g_Config.bEnableVR); + CheckBox *vrMotions = vrSettings->Add(new CheckBox(&g_Config.bEnableMotions, vr->T("Map controller movements to keys"))); + vrMotions->SetEnabledPtr(&g_Config.bEnableVR); vrSettings->Add(new ItemHeader(vr->T("VR camera"))); vrSettings->Add(new PopupSliderChoiceFloat(&g_Config.fCameraDistance, -10.0f, 10.0f, vr->T("Camera distance adjust", "Camera distance adjust"), 1.0f, screenManager(), "")); From 3c87e7117707e45f7f8c892a9f02c17ae7e9a83d Mon Sep 17 00:00:00 2001 From: Lubos Date: Mon, 31 Oct 2022 13:19:06 +0100 Subject: [PATCH 3/5] OpenXR - Let users set the movement length --- Common/VR/PPSSPPVR.cpp | 2 +- Core/Config.cpp | 1 + Core/Config.h | 1 + UI/GameSettingsScreen.cpp | 9 ++++++--- 4 files changed, 9 insertions(+), 4 deletions(-) diff --git a/Common/VR/PPSSPPVR.cpp b/Common/VR/PPSSPPVR.cpp index 4c85590107..a3b2506f88 100644 --- a/Common/VR/PPSSPPVR.cpp +++ b/Common/VR/PPSSPPVR.cpp @@ -208,7 +208,7 @@ void UpdateVRInput(bool(*NativeKey)(const KeyInput &key), bool(*NativeTouch)(con if (g_Config.bEnableMotions) { for (int j = 0; j < 2; j++) { bool activate; - float limit = 0.5f; //length of needed movement in meters + float limit = g_Config.fMotionLength; //length of needed movement in meters XrVector3f axis = {0, 1, 0}; float center = ToRadians((float)VR_GetConfig(VR_CONFIG_MENU_YAW)); XrQuaternionf orientation = XrQuaternionf_CreateFromVectorAngle(axis, center); diff --git a/Core/Config.cpp b/Core/Config.cpp index 94f96d15ad..e3aa3a5707 100644 --- a/Core/Config.cpp +++ b/Core/Config.cpp @@ -1214,6 +1214,7 @@ static ConfigSetting vrSettings[] = { ConfigSetting("VRCameraSide", &g_Config.fCameraSide, 0.0f), ConfigSetting("VRCanvasDistance", &g_Config.fCanvasDistance, 6.0f), ConfigSetting("VRFieldOfView", &g_Config.fFieldOfViewPercentage, 100.0f), + ConfigSetting("VRMotionLength", &g_Config.fMotionLength, 0.5f), ConfigSetting(false), }; diff --git a/Core/Config.h b/Core/Config.h index 3415cc55e0..4f212646d3 100644 --- a/Core/Config.h +++ b/Core/Config.h @@ -469,6 +469,7 @@ public: float fCameraSide; float fCanvasDistance; float fFieldOfViewPercentage; + float fMotionLength; // Debugger int iDisasmWindowX; diff --git a/UI/GameSettingsScreen.cpp b/UI/GameSettingsScreen.cpp index a7044d946f..7fed6c3c18 100644 --- a/UI/GameSettingsScreen.cpp +++ b/UI/GameSettingsScreen.cpp @@ -1163,15 +1163,18 @@ void GameSettingsScreen::CreateViews() { vr6DoF->SetEnabledPtr(&g_Config.bEnableVR); CheckBox *vrStereo = vrSettings->Add(new CheckBox(&g_Config.bEnableStereo, vr->T("Stereoscopic vision (Experimental)"))); vrStereo->SetEnabledPtr(&g_Config.bEnableVR); - CheckBox *vrMotions = vrSettings->Add(new CheckBox(&g_Config.bEnableMotions, vr->T("Map controller movements to keys"))); - vrMotions->SetEnabledPtr(&g_Config.bEnableVR); vrSettings->Add(new ItemHeader(vr->T("VR camera"))); vrSettings->Add(new PopupSliderChoiceFloat(&g_Config.fCameraDistance, -10.0f, 10.0f, vr->T("Camera distance adjust", "Camera distance adjust"), 1.0f, screenManager(), "")); vrSettings->Add(new PopupSliderChoiceFloat(&g_Config.fCameraHeight, -10.0f, 10.0f, vr->T("Camera height adjust", "Camera height adjust"), 1.0f, screenManager(), "")); vrSettings->Add(new PopupSliderChoiceFloat(&g_Config.fCameraSide, -10.0f, 10.0f, vr->T("Camera side adjust", "Camera side adjust"), 1.0f, screenManager(), "")); vrSettings->Add(new PopupSliderChoiceFloat(&g_Config.fCanvasDistance, 1.0f, 10.0f, vr->T("Distance to 2D menus and scenes", "Distance to 2D menus and scenes"), 1.0f, screenManager(), "")); - vrSettings->Add(new PopupSliderChoiceFloat(&g_Config.fFieldOfViewPercentage, 100.0f, 200.0f, vr->T("Field of view scale", "Headset's field of view scale"), 10.0f, screenManager(), vr->T("% of native FoV"))); + vrSettings->Add(new PopupSliderChoiceFloat(&g_Config.fFieldOfViewPercentage, 100.0f, 200.0f, vr->T("Field of view scale", "Field of view scale"), 10.0f, screenManager(), vr->T("% of native FoV"))); + + vrSettings->Add(new ItemHeader(vr->T("VR controllers"))); + 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", "Motion needed to generate action"), 0.1f, screenManager(), vr->T("m"))); + vrMotions->SetEnabledPtr(&g_Config.bEnableMotions); } } From 823bfae5eaaa074f83830ef0374316bf25e56fb5 Mon Sep 17 00:00:00 2001 From: Lubos Date: Mon, 31 Oct 2022 15:00:09 +0100 Subject: [PATCH 4/5] Memory initialization fixed --- Common/VR/PPSSPPVR.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Common/VR/PPSSPPVR.cpp b/Common/VR/PPSSPPVR.cpp index a3b2506f88..4dc3974761 100644 --- a/Common/VR/PPSSPPVR.cpp +++ b/Common/VR/PPSSPPVR.cpp @@ -78,7 +78,7 @@ static std::vector controllerMapping[2] = { leftControllerMapping, rightControllerMapping }; -static bool controllerMotion[2][5]; +static bool controllerMotion[2][5] = {}; static int mouseController = -1; static bool mousePressed[] = {false, false}; From 67af5baf3ead3b7201c3b1c49bd93d342a466809 Mon Sep 17 00:00:00 2001 From: Lubos Date: Tue, 1 Nov 2022 10:08:43 +0100 Subject: [PATCH 5/5] OpenXR - Settings code cleanup --- UI/GameSettingsScreen.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/UI/GameSettingsScreen.cpp b/UI/GameSettingsScreen.cpp index 7fed6c3c18..a3195adfc5 100644 --- a/UI/GameSettingsScreen.cpp +++ b/UI/GameSettingsScreen.cpp @@ -1165,15 +1165,15 @@ void GameSettingsScreen::CreateViews() { vrStereo->SetEnabledPtr(&g_Config.bEnableVR); vrSettings->Add(new ItemHeader(vr->T("VR camera"))); - vrSettings->Add(new PopupSliderChoiceFloat(&g_Config.fCameraDistance, -10.0f, 10.0f, vr->T("Camera distance adjust", "Camera distance adjust"), 1.0f, screenManager(), "")); - vrSettings->Add(new PopupSliderChoiceFloat(&g_Config.fCameraHeight, -10.0f, 10.0f, vr->T("Camera height adjust", "Camera height adjust"), 1.0f, screenManager(), "")); - vrSettings->Add(new PopupSliderChoiceFloat(&g_Config.fCameraSide, -10.0f, 10.0f, vr->T("Camera side adjust", "Camera side adjust"), 1.0f, screenManager(), "")); - vrSettings->Add(new PopupSliderChoiceFloat(&g_Config.fCanvasDistance, 1.0f, 10.0f, vr->T("Distance to 2D menus and scenes", "Distance to 2D menus and scenes"), 1.0f, screenManager(), "")); - vrSettings->Add(new PopupSliderChoiceFloat(&g_Config.fFieldOfViewPercentage, 100.0f, 200.0f, vr->T("Field of view scale", "Field of view scale"), 10.0f, screenManager(), vr->T("% of native FoV"))); + vrSettings->Add(new PopupSliderChoiceFloat(&g_Config.fCameraDistance, -10.0f, 10.0f, vr->T("Camera distance adjust"), 1.0f, screenManager(), "")); + vrSettings->Add(new PopupSliderChoiceFloat(&g_Config.fCameraHeight, -10.0f, 10.0f, vr->T("Camera height adjust"), 1.0f, screenManager(), "")); + vrSettings->Add(new PopupSliderChoiceFloat(&g_Config.fCameraSide, -10.0f, 10.0f, vr->T("Camera side adjust"), 1.0f, screenManager(), "")); + vrSettings->Add(new PopupSliderChoiceFloat(&g_Config.fCanvasDistance, 1.0f, 10.0f, vr->T("Distance to 2D menus and scenes"), 1.0f, screenManager(), "")); + vrSettings->Add(new PopupSliderChoiceFloat(&g_Config.fFieldOfViewPercentage, 100.0f, 200.0f, vr->T("Field of view scale"), 10.0f, screenManager(), vr->T("% of native FoV"))); vrSettings->Add(new ItemHeader(vr->T("VR controllers"))); 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", "Motion needed to generate action"), 0.1f, screenManager(), vr->T("m"))); + 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"))); vrMotions->SetEnabledPtr(&g_Config.bEnableMotions); } }