Merge pull request #16310 from lvonasek/feature_openxr_motion

OpenXR - Map controller gestures
This commit is contained in:
Henrik Rydgård authored and GitHub committed 2022-11-05 18:18:57 +01:00
commit 10c6232b9b
6 files changed
+82 -6

No files matched your search

+53
View File
@@ -78,6 +78,7 @@ static std::vector<ButtonMapping> 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