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 d3463fb810..5007672b01 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}; @@ -218,6 +219,58 @@ void UpdateVRInput(bool(*NativeKey)(const KeyInput &key), bool(*NativeTouch)(con } } + //motion control + if (g_Config.bEnableMotions) { + for (int j = 0; j < 2; j++) { + bool activate; + 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); + 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/Config.cpp b/Core/Config.cpp index 03a5bb26ee..b8d1408144 100644 --- a/Core/Config.cpp +++ b/Core/Config.cpp @@ -1208,12 +1208,14 @@ 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("VRbForce72Hz", &g_Config.bForce72Hz, true), ConfigSetting("VRCameraDistance", &g_Config.fCameraDistance, 0.0f), ConfigSetting("VRCameraHeight", &g_Config.fCameraHeight, 0.0f), 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 4e15c3bb4b..1de62adf27 100644 --- a/Core/Config.h +++ b/Core/Config.h @@ -463,12 +463,14 @@ public: bool bEnableVR; bool bEnable6DoF; bool bEnableStereo; + bool bEnableMotions; bool bForce72Hz; float fCameraDistance; float fCameraHeight; float fCameraSide; float fCanvasDistance; float fFieldOfViewPercentage; + float fMotionLength; // Debugger int iDisasmWindowX; 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, "}"}, diff --git a/UI/GameSettingsScreen.cpp b/UI/GameSettingsScreen.cpp index b6c3e06a8e..e46311870b 100644 --- a/UI/GameSettingsScreen.cpp +++ b/UI/GameSettingsScreen.cpp @@ -1165,11 +1165,16 @@ void GameSettingsScreen::CreateViews() { vrSettings->Add(new CheckBox(&g_Config.bForce72Hz, vr->T("Force 72Hz update"))); 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.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"), 0.1f, screenManager(), vr->T("m"))); + vrMotions->SetEnabledPtr(&g_Config.bEnableMotions); } }