From 6a714b3398016b70927384f48dcc63bc7d146521 Mon Sep 17 00:00:00 2001 From: Simon Date: Sat, 13 Jan 2024 10:52:23 +0000 Subject: [PATCH] Couple of movement fixes - Make 3rd person movement adhere to a compass direction so that special moves can be executed - Reduced speed of smooth turn as it was too fast on lowest setting --- Projects/Android/jni/OpenJK/JKXR/VrCvars.h | 1 + .../Android/jni/OpenJK/JKXR/VrInputCommon.cpp | 1 + .../jni/OpenJK/JKXR/VrInputDefault.cpp | 20 +++++++++++++++---- .../OpenJK/JKXR/android/JKXR_SurfaceView.cpp | 1 + .../OpenJK/JKXR/windows/JKXR_SurfaceView.cpp | 1 + 5 files changed, 20 insertions(+), 4 deletions(-) diff --git a/Projects/Android/jni/OpenJK/JKXR/VrCvars.h b/Projects/Android/jni/OpenJK/JKXR/VrCvars.h index 8ba5be8..c0eab5d 100644 --- a/Projects/Android/jni/OpenJK/JKXR/VrCvars.h +++ b/Projects/Android/jni/OpenJK/JKXR/VrCvars.h @@ -2,6 +2,7 @@ extern cvar_t *vr_turn_mode; extern cvar_t *vr_turn_angle; extern cvar_t *vr_positional_factor; extern cvar_t *vr_walkdirection; +extern cvar_t *vr_3rdperson_digital_direction; extern cvar_t *vr_weapon_pitchadjust; extern cvar_t *vr_saber_pitchadjust; extern cvar_t *vr_control_scheme; diff --git a/Projects/Android/jni/OpenJK/JKXR/VrInputCommon.cpp b/Projects/Android/jni/OpenJK/JKXR/VrInputCommon.cpp index bf0e09f..7a085c9 100644 --- a/Projects/Android/jni/OpenJK/JKXR/VrInputCommon.cpp +++ b/Projects/Android/jni/OpenJK/JKXR/VrInputCommon.cpp @@ -15,6 +15,7 @@ cvar_t *vr_turn_mode; cvar_t *vr_turn_angle; cvar_t *vr_positional_factor; cvar_t *vr_walkdirection; +cvar_t *vr_3rdperson_digital_direction; cvar_t *vr_weapon_pitchadjust; cvar_t *vr_saber_pitchadjust; cvar_t *vr_control_scheme; diff --git a/Projects/Android/jni/OpenJK/JKXR/VrInputDefault.cpp b/Projects/Android/jni/OpenJK/JKXR/VrInputDefault.cpp index bfb2e19..ef99326 100644 --- a/Projects/Android/jni/OpenJK/JKXR/VrInputDefault.cpp +++ b/Projects/Android/jni/OpenJK/JKXR/VrInputDefault.cpp @@ -39,6 +39,8 @@ void HandleInput_Default( ovrInputStateTrackedRemote *pDominantTrackedRemoteNew, vr.right_handed = vr_control_scheme->value < 10 || vr_control_scheme->value == 99; // Always right-handed for weapon calibration + bool thirdPersonActive = !!((int) Cvar_VariableValue("cg_thirdPerson")); + static bool dominantGripPushed = false; //Need this for the touch screen @@ -808,7 +810,7 @@ void HandleInput_Default( ovrInputStateTrackedRemote *pDominantTrackedRemoteNew, vr.offhandoffset[1] = pOff->Pose.position.y - vr.hmdposition[1]; vr.offhandoffset[2] = pOff->Pose.position.z - vr.hmdposition[2]; - if (vr_walkdirection->value == 0) { + if (vr_walkdirection->value == 0 && !thirdPersonActive) { controllerYawHeading = vr.offhandangles[ANGLES_ADJUSTED][YAW] - vr.hmdorientation[YAW]; } else { controllerYawHeading = 0.0f; @@ -954,6 +956,17 @@ void HandleInput_Default( ovrInputStateTrackedRemote *pDominantTrackedRemoteNew, vec2_t v; rotateAboutOrigin(x, y, controllerYawHeading, v); + // If in third person, use digital input (North, North-East, East, South-East etc) + // for movement as it allows execution of player special moves correctly in JKA + if (thirdPersonActive && vr_3rdperson_digital_direction->integer) + { + float angle = RAD2DEG(atan2f(v[1], v[0])) + 22.5; + int segment = angle / 45.0f; + angle = segment * 45.0f; + v[0] = nlf * cosf(DEG2RAD(angle)); + v[1] = nlf * sinf(DEG2RAD(angle)); + } + float move_speed_multiplier = 1.0f; switch (vr.move_speed) { @@ -968,7 +981,7 @@ void HandleInput_Default( ovrInputStateTrackedRemote *pDominantTrackedRemoteNew, break; } - if (vr_always_run->integer) + if (vr_always_run->integer || vr_3rdperson_digital_direction->integer) { move_speed_multiplier = 1.0f; } @@ -1072,7 +1085,7 @@ void HandleInput_Default( ovrInputStateTrackedRemote *pDominantTrackedRemoteNew, if (!usingSnapTurn && fabs(primaryJoystickX) > 0.1f) //smooth turn { - vr.snapTurn -= ((vr_turn_angle->value / 10.0f) * + vr.snapTurn -= ((vr_turn_angle->value / 25.0f) * primaryJoystickX); if (vr.snapTurn > 180.0f) { vr.snapTurn -= 360.f; @@ -1158,7 +1171,6 @@ void HandleInput_Default( ovrInputStateTrackedRemote *pDominantTrackedRemoteNew, // Process "use" gesture if (vr_gesture_triggered_use->integer) { - bool thirdPersonActive = !!((int) Cvar_VariableValue("cg_thirdPerson")); bool gestureUseAllowed = !vr.weapon_stabilised && !vr.cin_camera && !vr.misc_camera && !vr.remote_turret && !vr.emplaced_gun && !vr.in_vehicle && !thirdPersonActive; // Off-hand gesture float distanceToBody = sqrt(vr.offhandoffset[0]*vr.offhandoffset[0] + vr.offhandoffset[2]*vr.offhandoffset[2]); diff --git a/Projects/Android/jni/OpenJK/JKXR/android/JKXR_SurfaceView.cpp b/Projects/Android/jni/OpenJK/JKXR/android/JKXR_SurfaceView.cpp index 4d6f27b..393fa51 100644 --- a/Projects/Android/jni/OpenJK/JKXR/android/JKXR_SurfaceView.cpp +++ b/Projects/Android/jni/OpenJK/JKXR/android/JKXR_SurfaceView.cpp @@ -328,6 +328,7 @@ void VR_Init() vr_turn_angle = Cvar_Get( "vr_turn_angle", "45", CVAR_ARCHIVE); vr_positional_factor = Cvar_Get( "vr_positional_factor", "12", CVAR_ARCHIVE); vr_walkdirection = Cvar_Get( "vr_walkdirection", "1", CVAR_ARCHIVE); + vr_3rdperson_digital_direction = Cvar_Get( "vr_3rdperson_digital_direction", "1", CVAR_ARCHIVE); vr_weapon_pitchadjust = Cvar_Get( "vr_weapon_pitchadjust", "-20.0", CVAR_ARCHIVE); vr_saber_pitchadjust = Cvar_Get( "vr_saber_pitchadjust", "-13.36", CVAR_ARCHIVE); vr_virtual_stock = Cvar_Get( "vr_virtual_stock", "0", CVAR_ARCHIVE); diff --git a/Projects/Android/jni/OpenJK/JKXR/windows/JKXR_SurfaceView.cpp b/Projects/Android/jni/OpenJK/JKXR/windows/JKXR_SurfaceView.cpp index f835129..60f9e89 100644 --- a/Projects/Android/jni/OpenJK/JKXR/windows/JKXR_SurfaceView.cpp +++ b/Projects/Android/jni/OpenJK/JKXR/windows/JKXR_SurfaceView.cpp @@ -246,6 +246,7 @@ void VR_Init() vr_turn_angle = Cvar_Get( "vr_turn_angle", "45", CVAR_ARCHIVE); vr_positional_factor = Cvar_Get( "vr_positional_factor", "12", CVAR_ARCHIVE); vr_walkdirection = Cvar_Get( "vr_walkdirection", "1", CVAR_ARCHIVE); + vr_3rdperson_digital_direction = Cvar_Get( "vr_3rdperson_digital_direction", "1", CVAR_ARCHIVE); vr_weapon_pitchadjust = Cvar_Get( "vr_weapon_pitchadjust", "-20.0", CVAR_ARCHIVE); vr_saber_pitchadjust = Cvar_Get( "vr_saber_pitchadjust", "-13.36", CVAR_ARCHIVE); vr_virtual_stock = Cvar_Get( "vr_virtual_stock", "0", CVAR_ARCHIVE);