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

+8 -1
View File
@@ -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 {
+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
+2
View File
@@ -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),
};
+2
View File
@@ -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;
+7
View File
@@ -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, "}"},
+10 -5
View File
@@ -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);
}
}