From e123731955fda53e6bf029f886e76d504aeaf4cb Mon Sep 17 00:00:00 2001 From: Grant Bagwell Date: Sat, 13 Jan 2024 20:12:27 +0100 Subject: [PATCH] Added Trigger Release Band Cvars + Fixed Vive Controls Added Cvars for engaging Grip by level. Defaults Below: vr_engage_trigger 0.7 vr_release_trigger 0.7 vr_engage_trigger_index 0.7 (Index Only) vr_release_trigger_index 0.05 (Index Only) Vive Controls Left Trackpad press (whilst roughly in the middle) - Crouch Left menu Button - Pause Trackpad Right Press - DataPad Right Menu Button - 1st / 3rd person Right Trackpad Press Up = Alt Fire / Switch Off Saber Right Trackpad Press Down = Jump Right Trackpad Press Center = Use / Interact --- .../Android/jni/OpenJK/JKXR/OpenXrInput.cpp | 96 +++++++++++++++---- Projects/Android/jni/OpenJK/JKXR/VrCvars.h | 4 + .../Android/jni/OpenJK/JKXR/VrInputCommon.cpp | 4 + .../OpenJK/JKXR/windows/JKXR_SurfaceView.cpp | 4 + 4 files changed, 87 insertions(+), 21 deletions(-) diff --git a/Projects/Android/jni/OpenJK/JKXR/OpenXrInput.cpp b/Projects/Android/jni/OpenJK/JKXR/OpenXrInput.cpp index 0eb37fa..9e8db58 100644 --- a/Projects/Android/jni/OpenJK/JKXR/OpenXrInput.cpp +++ b/Projects/Android/jni/OpenJK/JKXR/OpenXrInput.cpp @@ -802,15 +802,24 @@ void TBXR_UpdateControllers( ) trackpadPosition = GetActionStateVector2(trackPadAction, SIDE_LEFT).currentState; if (GetActionStateBoolean(trackPadClickAction, SIDE_LEFT).currentState) { - if (trackpadPosition.x >= -0.2 && trackpadPosition.x <= 0.2) + if (trackpadPosition.x >= -0.3 && trackpadPosition.x <= 0.3) { - if (trackpadPosition.y >= 0.2) + //Always the in center for crouch + //Crouch + leftTrackedRemoteState_new.Buttons |= xrButton_LThumb; + leftTrackedRemoteState_new.Buttons |= xrButton_Joystick; + } + else + { + if (trackpadPosition.x <= -0.3) //Left { - leftTrackedRemoteState_new.Buttons |= xrButton_Y; + //Ingame Menu - dont need this on Vive + //leftTrackedRemoteState_new.Buttons |= xrButton_X; } - else if (trackpadPosition.y <= -0.2) + else if(trackpadPosition.x >= 0.3) //Right { - leftTrackedRemoteState_new.Buttons |= xrButton_X; + //DataPad + leftTrackedRemoteState_new.Buttons |= xrButton_Y; } } } @@ -821,31 +830,48 @@ void TBXR_UpdateControllers( ) if (GetActionStateBoolean(XTouchAction, SIDE_LEFT).currentState) leftTrackedRemoteState_new.Touches |= xrButton_X; if (GetActionStateBoolean(YAction, SIDE_LEFT).currentState) leftTrackedRemoteState_new.Buttons |= xrButton_Y; if (GetActionStateBoolean(YTouchAction, SIDE_LEFT).currentState) leftTrackedRemoteState_new.Touches |= xrButton_Y; + if (GetActionStateBoolean(thumbstickClickAction, SIDE_LEFT).currentState) leftTrackedRemoteState_new.Buttons |= xrButton_LThumb; + if (GetActionStateBoolean(thumbstickClickAction, SIDE_LEFT).currentState) leftTrackedRemoteState_new.Buttons |= xrButton_Joystick; + if (GetActionStateBoolean(thumbstickTouchAction, SIDE_LEFT).currentState) leftTrackedRemoteState_new.Touches |= xrButton_LThumb; + if (GetActionStateBoolean(thumbstickTouchAction, SIDE_LEFT).currentState) leftTrackedRemoteState_new.Touches |= xrButton_Joystick; } + //Defaults engage/disable at the same level + float enableLevel = vr_engage_trigger->value; + float disableLevel = vr_release_trigger->value; //INDEX we'll need to add force check so its not boolean if (gAppState.controllersPresent == VIVE_CONTROLLERS) { leftTrackedRemoteState_new.GripTrigger = GetActionStateBoolean(squeezeClickAction, SIDE_LEFT).currentState; + enableLevel = 1.0f; + disableLevel = 1.0f; } else if (gAppState.controllersPresent == INDEX_CONTROLLERS) { leftTrackedRemoteState_new.GripTrigger = GetActionStateFloat(squeezeForceAction, SIDE_LEFT).currentState; + // Use different release level for the Index Knuckles + enableLevel = vr_engage_trigger_index->value; + disableLevel = vr_release_trigger_index->value; } else { leftTrackedRemoteState_new.GripTrigger = GetActionStateFloat(squeezeAction, SIDE_LEFT).currentState; } - if (leftTrackedRemoteState_new.GripTrigger > 0.7f) + + static int leftGripEngaged = false; + if (leftTrackedRemoteState_new.GripTrigger >= enableLevel && !leftGripEngaged) + { + leftGripEngaged = true; + } + else if (leftTrackedRemoteState_new.GripTrigger < disableLevel && leftGripEngaged) + { + leftGripEngaged = false; + } + if (leftGripEngaged) { leftTrackedRemoteState_new.Buttons |= xrButton_GripTrigger; } - if (GetActionStateBoolean(thumbstickClickAction, SIDE_LEFT).currentState) leftTrackedRemoteState_new.Buttons |= xrButton_LThumb; - if (GetActionStateBoolean(thumbstickClickAction, SIDE_LEFT).currentState) leftTrackedRemoteState_new.Buttons |= xrButton_Joystick; - if (GetActionStateBoolean(thumbstickTouchAction, SIDE_LEFT).currentState) leftTrackedRemoteState_new.Touches |= xrButton_LThumb; - if (GetActionStateBoolean(thumbstickTouchAction, SIDE_LEFT).currentState) leftTrackedRemoteState_new.Touches |= xrButton_Joystick; - leftTrackedRemoteState_new.IndexTrigger = GetActionStateFloat(triggerAction, SIDE_LEFT).currentState; if (leftTrackedRemoteState_new.IndexTrigger > 0.5f) leftTrackedRemoteState_new.Buttons |= xrButton_Trigger; if (GetActionStateBoolean(triggerTouchAction, SIDE_LEFT).currentState) leftTrackedRemoteState_new.Touches |= xrButton_Trigger; @@ -867,15 +893,25 @@ void TBXR_UpdateControllers( ) { if (trackpadPosition.x >= -0.2 && trackpadPosition.x <= 0.2) { - if (trackpadPosition.y >= 0.2) + if (trackpadPosition.y >= 0.3) { //Menu button on Vive instead rightTrackedRemoteState_new.Buttons |= xrButton_B; } - else if (trackpadPosition.y <= -0.2) + else if (trackpadPosition.y <= -0.3) { rightTrackedRemoteState_new.Buttons |= xrButton_A; } + else + { + rightTrackedRemoteState_new.Buttons |= xrButton_Joystick; + rightTrackedRemoteState_new.Buttons |= xrButton_RThumb; + } + } + else + { + rightTrackedRemoteState_new.Buttons |= xrButton_Joystick; + rightTrackedRemoteState_new.Buttons |= xrButton_RThumb; } } if (GetActionStateBoolean(backAction, SIDE_RIGHT).currentState) @@ -888,29 +924,47 @@ void TBXR_UpdateControllers( ) if (GetActionStateBoolean(AAction, SIDE_RIGHT).currentState) rightTrackedRemoteState_new.Buttons |= xrButton_A; if (GetActionStateBoolean(ATouchAction, SIDE_RIGHT).currentState) rightTrackedRemoteState_new.Touches |= xrButton_A; if (GetActionStateBoolean(BAction, SIDE_RIGHT).currentState) rightTrackedRemoteState_new.Buttons |= xrButton_B; - if (GetActionStateBoolean(BTouchAction, SIDE_RIGHT).currentState) rightTrackedRemoteState_new.Touches |= xrButton_B; + if (GetActionStateBoolean(BTouchAction, SIDE_RIGHT).currentState) rightTrackedRemoteState_new.Touches |= xrButton_B; if (GetActionStateBoolean(backAction, SIDE_RIGHT).currentState) rightTrackedRemoteState_new.Buttons |= xrButton_Enter; + if (GetActionStateBoolean(thumbstickClickAction, SIDE_RIGHT).currentState) rightTrackedRemoteState_new.Buttons |= xrButton_RThumb; + if (GetActionStateBoolean(thumbstickClickAction, SIDE_RIGHT).currentState) rightTrackedRemoteState_new.Buttons |= xrButton_Joystick; + if (GetActionStateBoolean(thumbstickTouchAction, SIDE_RIGHT).currentState) rightTrackedRemoteState_new.Touches |= xrButton_RThumb; + if (GetActionStateBoolean(thumbstickTouchAction, SIDE_RIGHT).currentState) rightTrackedRemoteState_new.Touches |= xrButton_Joystick; } + + //INDEX we'll need to add force check so its not boolean + //Defaults engage/disable at the same level if (gAppState.controllersPresent == VIVE_CONTROLLERS) { - rightTrackedRemoteState_new.GripTrigger = GetActionStateBoolean(squeezeClickAction, SIDE_RIGHT).currentState; + rightTrackedRemoteState_new.GripTrigger = GetActionStateBoolean(squeezeClickAction, SIDE_RIGHT).currentState; } else if (gAppState.controllersPresent == INDEX_CONTROLLERS) { - rightTrackedRemoteState_new.GripTrigger = GetActionStateFloat(squeezeForceAction, SIDE_RIGHT).currentState; + rightTrackedRemoteState_new.GripTrigger = GetActionStateFloat(squeezeForceAction, SIDE_RIGHT).currentState; } else { rightTrackedRemoteState_new.GripTrigger = GetActionStateFloat(squeezeAction, SIDE_RIGHT).currentState; } - if (rightTrackedRemoteState_new.GripTrigger > 0.7f) rightTrackedRemoteState_new.Buttons |= xrButton_GripTrigger; - if (GetActionStateBoolean(thumbstickClickAction, SIDE_RIGHT).currentState) rightTrackedRemoteState_new.Buttons |= xrButton_RThumb; - if (GetActionStateBoolean(thumbstickClickAction, SIDE_RIGHT).currentState) rightTrackedRemoteState_new.Buttons |= xrButton_Joystick; - if (GetActionStateBoolean(thumbstickTouchAction, SIDE_RIGHT).currentState) rightTrackedRemoteState_new.Touches |= xrButton_RThumb; - if (GetActionStateBoolean(thumbstickTouchAction, SIDE_RIGHT).currentState) rightTrackedRemoteState_new.Touches |= xrButton_Joystick; + static int rightGripEngaged = false; + if (rightTrackedRemoteState_new.GripTrigger >= enableLevel && !rightGripEngaged) + { + rightGripEngaged = true; + } + else if (rightTrackedRemoteState_new.GripTrigger < disableLevel && rightGripEngaged) + { + rightGripEngaged = false; + } + + if (rightGripEngaged) + { + rightTrackedRemoteState_new.Buttons |= xrButton_GripTrigger; + } + + rightTrackedRemoteState_new.IndexTrigger = GetActionStateFloat(triggerAction, SIDE_RIGHT).currentState; if (rightTrackedRemoteState_new.IndexTrigger > 0.5f) rightTrackedRemoteState_new.Buttons |= xrButton_Trigger; if (GetActionStateBoolean(triggerTouchAction, SIDE_RIGHT).currentState) rightTrackedRemoteState_new.Touches |= xrButton_Trigger; diff --git a/Projects/Android/jni/OpenJK/JKXR/VrCvars.h b/Projects/Android/jni/OpenJK/JKXR/VrCvars.h index c0eab5d..0899b35 100644 --- a/Projects/Android/jni/OpenJK/JKXR/VrCvars.h +++ b/Projects/Android/jni/OpenJK/JKXR/VrCvars.h @@ -35,3 +35,7 @@ extern cvar_t *vr_use_gesture_boundary; extern cvar_t *vr_align_weapons; // Only used for development extern cvar_t *vr_refresh; extern cvar_t *vr_super_sampling; +extern cvar_t *vr_engage_trigger; +extern cvar_t *vr_release_trigger; +extern cvar_t *vr_engage_trigger_index; +extern cvar_t *vr_release_trigger_index; diff --git a/Projects/Android/jni/OpenJK/JKXR/VrInputCommon.cpp b/Projects/Android/jni/OpenJK/JKXR/VrInputCommon.cpp index 7a085c9..b90d651 100644 --- a/Projects/Android/jni/OpenJK/JKXR/VrInputCommon.cpp +++ b/Projects/Android/jni/OpenJK/JKXR/VrInputCommon.cpp @@ -48,6 +48,10 @@ cvar_t *vr_use_gesture_boundary; cvar_t *vr_align_weapons; cvar_t *vr_refresh; cvar_t *vr_super_sampling; +cvar_t *vr_engage_trigger; +cvar_t *vr_release_trigger; +cvar_t *vr_engage_trigger_index; +cvar_t *vr_release_trigger_index; ovrInputStateTrackedRemote leftTrackedRemoteState_old; ovrInputStateTrackedRemote leftTrackedRemoteState_new; diff --git a/Projects/Android/jni/OpenJK/JKXR/windows/JKXR_SurfaceView.cpp b/Projects/Android/jni/OpenJK/JKXR/windows/JKXR_SurfaceView.cpp index 60f9e89..76648b8 100644 --- a/Projects/Android/jni/OpenJK/JKXR/windows/JKXR_SurfaceView.cpp +++ b/Projects/Android/jni/OpenJK/JKXR/windows/JKXR_SurfaceView.cpp @@ -281,6 +281,10 @@ void VR_Init() vr_use_gesture_boundary = Cvar_Get ("vr_use_gesture_boundary", "0.35", CVAR_ARCHIVE); vr_align_weapons = Cvar_Get ("vr_align_weapons", "0", CVAR_ARCHIVE); vr_refresh = Cvar_Get ("vr_refresh", "72", CVAR_ARCHIVE); + vr_engage_trigger = Cvar_Get("vr_engage_trigger", "0.7", CVAR_ARCHIVE); + vr_release_trigger = Cvar_Get("vr_release_trigger", "0.7", CVAR_ARCHIVE); + vr_engage_trigger_index = Cvar_Get("vr_engage_trigger_index", "0.7", CVAR_ARCHIVE); + vr_release_trigger_index = Cvar_Get("vr_release_trigger_index", "0.05", CVAR_ARCHIVE); cvar_t *expanded_menu_enabled = Cvar_Get ("expanded_menu_enabled", "0", CVAR_ARCHIVE); if (FS_FileExists("expanded_menu.pk3") || FS_BaseFileExists("expanded_menu.pk3")) {