mirror of
https://github.com/hrydgard/ppsspp.git
synced 2024-11-26 23:10:38 +00:00
OpenXR - Support head rotations in 2D
This commit is contained in:
parent
51a29fb4bf
commit
c368a213ac
@ -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:
|
||||
|
@ -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,
|
||||
|
@ -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 {
|
||||
|
@ -103,6 +103,7 @@ static std::vector<ButtonMapping> 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) {
|
||||
|
@ -465,3 +465,7 @@ void* VR_BindFramebuffer(engine_t *engine) {
|
||||
XrView VR_GetView(int eye) {
|
||||
return projections[eye];
|
||||
}
|
||||
|
||||
XrVector3f VR_GetHMDAngles() {
|
||||
return hmdorientation;
|
||||
}
|
||||
|
@ -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();
|
||||
|
@ -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, "{"},
|
||||
|
Loading…
Reference in New Issue
Block a user