diff --git a/Common/Input/InputState.cpp b/Common/Input/InputState.cpp index 06f31807ec..743da0f454 100644 --- a/Common/Input/InputState.cpp +++ b/Common/Input/InputState.cpp @@ -23,6 +23,7 @@ const char *GetDeviceName(int deviceId) { case DEVICE_ID_XINPUT_3: return "x360_4"; case DEVICE_ID_ACCELEROMETER: return "accelerometer"; case DEVICE_ID_MOUSE: return "mouse"; + case DEVICE_ID_XR_HMD: return "xr_hmd"; case DEVICE_ID_XR_CONTROLLER_LEFT: return "xr_l"; case DEVICE_ID_XR_CONTROLLER_RIGHT: return "xr_r"; default: diff --git a/Common/Input/InputState.h b/Common/Input/InputState.h index f5d43e209d..cc27b8dfe8 100644 --- a/Common/Input/InputState.h +++ b/Common/Input/InputState.h @@ -31,6 +31,7 @@ enum { DEVICE_ID_XINPUT_2 = 22, DEVICE_ID_XINPUT_3 = 23, DEVICE_ID_ACCELEROMETER = 30, + DEVICE_ID_XR_HMD = 39, DEVICE_ID_XR_CONTROLLER_LEFT = 40, DEVICE_ID_XR_CONTROLLER_RIGHT = 41, DEVICE_ID_TOUCH = 42, diff --git a/Common/Input/KeyCodes.h b/Common/Input/KeyCodes.h index 15f42c07c1..6e90381159 100644 --- a/Common/Input/KeyCodes.h +++ b/Common/Input/KeyCodes.h @@ -263,12 +263,18 @@ typedef enum _keycode_t { NKCODE_EXT_MOUSEWHEEL_UP = 1008, NKCODE_EXT_MOUSEWHEEL_DOWN = 1009, - // Virtual reality controller motion + // Virtual reality 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, + + // Virtual reality rotation + NKCODE_EXT_ROTATION_UP = 1111, + NKCODE_EXT_ROTATION_DOWN = 1112, + NKCODE_EXT_ROTATION_LEFT = 1113, + NKCODE_EXT_ROTATION_RIGHT = 1114, } keycode_t; enum AndroidJoystickAxis { diff --git a/Common/VR/PPSSPPVR.cpp b/Common/VR/PPSSPPVR.cpp index 30f93ba1fa..5d8d26e734 100644 --- a/Common/VR/PPSSPPVR.cpp +++ b/Common/VR/PPSSPPVR.cpp @@ -103,6 +103,7 @@ static std::vector controllerMapping[2] = { rightControllerMapping }; static bool controllerMotion[2][5] = {}; +static bool hmdMotion[4] = {}; static int mouseController = 1; static bool mousePressed = false; @@ -309,6 +310,47 @@ void UpdateVRInput(bool haptics, float dp_xscale, float dp_yscale) { } } + // Head control in non-VR mode + if (g_Config.iHeadRotation && IsFlatVRScene()) { + float pitch = -VR_GetHMDAngles().x; + float yaw = -VR_GetHMDAngles().y; + + bool activate; + float limit = 20; + keyInput.deviceId = DEVICE_ID_XR_HMD; + + // vertical rotations + if (g_Config.iHeadRotation == 2) { + //up + activate = pitch > limit; + keyInput.flags = activate ? KEY_DOWN : KEY_UP; + keyInput.keyCode = NKCODE_EXT_ROTATION_UP; + if (hmdMotion[0] != activate) NativeKey(keyInput); + hmdMotion[0] = activate; + + //down + activate = pitch < -limit; + keyInput.flags = activate ? KEY_DOWN : KEY_UP; + keyInput.keyCode = NKCODE_EXT_ROTATION_DOWN; + if (hmdMotion[1] != activate) NativeKey(keyInput); + hmdMotion[1] = activate; + } + + //left + activate = yaw < -limit; + keyInput.flags = activate ? KEY_DOWN : KEY_UP; + keyInput.keyCode = NKCODE_EXT_ROTATION_LEFT; + if (hmdMotion[2] != activate) NativeKey(keyInput); + hmdMotion[2] = activate; + + //right + activate = yaw > limit; + keyInput.flags = activate ? KEY_DOWN : KEY_UP; + keyInput.keyCode = NKCODE_EXT_ROTATION_RIGHT; + if (hmdMotion[3] != activate) NativeKey(keyInput); + hmdMotion[3] = activate; + } + // Camera adjust if (pspKeys[VIRTKEY_VR_CAMERA_ADJUST]) { for (auto& device : pspAxis) { diff --git a/Common/VR/VRRenderer.cpp b/Common/VR/VRRenderer.cpp index 5de7cb4055..7db2073244 100644 --- a/Common/VR/VRRenderer.cpp +++ b/Common/VR/VRRenderer.cpp @@ -465,3 +465,7 @@ void* VR_BindFramebuffer(engine_t *engine) { XrView VR_GetView(int eye) { return projections[eye]; } + +XrVector3f VR_GetHMDAngles() { + return hmdorientation; +} diff --git a/Common/VR/VRRenderer.h b/Common/VR/VRRenderer.h index 78de6a5ccf..8ed7869656 100644 --- a/Common/VR/VRRenderer.h +++ b/Common/VR/VRRenderer.h @@ -48,3 +48,4 @@ void VR_SetConfigFloat( VRConfigFloat config, float value ); void* VR_BindFramebuffer(engine_t *engine); XrView VR_GetView(int eye); +XrVector3f VR_GetHMDAngles(); diff --git a/Core/KeyMap.cpp b/Core/KeyMap.cpp index a853b69dfa..6b072fadb3 100644 --- a/Core/KeyMap.cpp +++ b/Core/KeyMap.cpp @@ -310,6 +310,10 @@ static const KeyMap_IntStrPair key_names[] = { {NKCODE_EXT_MOTION_LEFT, "MotionLeft"}, {NKCODE_EXT_MOTION_RIGHT, "MotionRight"}, {NKCODE_EXT_MOTION_FORWARD, "MotionFwd"}, + {NKCODE_EXT_ROTATION_UP, "RotationUp"}, + {NKCODE_EXT_ROTATION_DOWN, "RotationDown"}, + {NKCODE_EXT_ROTATION_LEFT, "RotationLeft"}, + {NKCODE_EXT_ROTATION_RIGHT, "RotationRight"}, {NKCODE_START_QUESTION, "¿"}, {NKCODE_LEFTBRACE, "{"},