From d121206f830cccc5a77a5c6b8a56a5f1105d9786 Mon Sep 17 00:00:00 2001 From: Petr Bartos Date: Sat, 8 Apr 2023 22:49:28 +0200 Subject: [PATCH] Tune touch gesture distance; Improve use interaction in 3rd person. --- .../Android/jni/OpenJK/code/game/g_active.cpp | 13 +++---- .../Android/jni/OpenJK/code/game/g_utils.cpp | 34 +++++++++++++------ .../jni/OpenJK/codeJK2/game/g_active.cpp | 13 +++---- .../jni/OpenJK/codeJK2/game/g_utils.cpp | 34 +++++++++++++------ 4 files changed, 62 insertions(+), 32 deletions(-) diff --git a/Projects/Android/jni/OpenJK/code/game/g_active.cpp b/Projects/Android/jni/OpenJK/code/game/g_active.cpp index a5990c7..c360ae4 100644 --- a/Projects/Android/jni/OpenJK/code/game/g_active.cpp +++ b/Projects/Android/jni/OpenJK/code/game/g_active.cpp @@ -1349,11 +1349,12 @@ void ClientImpacts( gentity_t *ent, pmove_t *pm ) { } - // Use triggers seems to have bigger "front" boundaries - // (with longer range player often reaches behind them - // not activating them at all) -const float TOUCH_DISTANCE = 1.0f; -const vec3_t TOUCH_RANGE = { 4, 4, 4 }; +// Use triggers seems to have bigger "front" boundaries allowing +// user to trigger them from distance while it is possible to reach +// through them when standing near. To ballance this, move hand +// origin a bit back +const float TOUCH_OFFSET = -10.0f; +const vec3_t TOUCH_RANGE = { 4, 4, 4 }; void G_TouchTriggersWithHand( bool offHand, gentity_t *ent, vec3_t src, vec3_t vf ) { vec3_t dest, mins, maxs; @@ -1364,7 +1365,7 @@ void G_TouchTriggersWithHand( bool offHand, gentity_t *ent, vec3_t src, vec3_t v memset (touched, qfalse, sizeof(touched) ); - VectorMA( src, TOUCH_DISTANCE, vf, dest ); + VectorMA( src, TOUCH_OFFSET, vf, dest ); VectorSubtract( dest, TOUCH_RANGE, mins ); VectorAdd( dest, TOUCH_RANGE, maxs ); diff --git a/Projects/Android/jni/OpenJK/code/game/g_utils.cpp b/Projects/Android/jni/OpenJK/code/game/g_utils.cpp index 908fa5c..81621d8 100644 --- a/Projects/Android/jni/OpenJK/code/game/g_utils.cpp +++ b/Projects/Android/jni/OpenJK/code/game/g_utils.cpp @@ -1669,12 +1669,15 @@ qboolean CanUseInfrontOf(gentity_t *ent) return qfalse; } + bool thirdPersonActive = gi.cvar("cg_thirdPerson", "0", CVAR_TEMP)->integer; + if (thirdPersonActive) { + VectorCopy(ent->currentOrigin, src); + AngleVectors(ent->currentAngles, vf, NULL, NULL); + } else { + VectorCopy( ent->client->renderInfo.eyePoint, src ); + AngleVectors( ent->client->ps.viewangles, vf, NULL, NULL ); + } - //FIXME: this does not match where the new accurate crosshair aims... - //cg.refdef.vieworg, basically - VectorCopy( ent->client->renderInfo.eyePoint, src ); - - AngleVectors( ent->client->ps.viewangles, vf, NULL, NULL ); //extend to find end of use trace VectorMA( src, USE_DISTANCE, vf, dest ); @@ -1757,7 +1760,10 @@ Try and use an entity in the world, directly ahead of us */ #define USE_DISTANCE_BUTTON 64.0f -#define USE_DISTANCE_GESTURE 16.0f +#define USE_DISTANCE_GESTURE 26.0f +// Move controller origin a bit back to prevent reach +// through usable entities when use gesture is active +#define USE_OFFSET -10.0f void TryUse_Internal( bool offHand, gentity_t *ent, vec3_t src, vec3_t vf ) { @@ -1769,7 +1775,9 @@ void TryUse_Internal( bool offHand, gentity_t *ent, vec3_t src, vec3_t vf ) bool thirdPersonActive = gi.cvar("cg_thirdPerson", "0", CVAR_TEMP)->integer; bool useGestureEnabled = gi.cvar("vr_gesture_triggered_use", "1", CVAR_ARCHIVE)->integer; // defined in VrCvars.h bool useGestureAllowed = useGestureEnabled && !thirdPersonActive; + float useOffset = useGestureAllowed ? USE_OFFSET : 0.0f; float useDistance = useGestureAllowed ? USE_DISTANCE_GESTURE : USE_DISTANCE_BUTTON; + VectorMA( src, useOffset, vf, src ); VectorMA( src, useDistance, vf, dest ); //Trace ahead to find a valid target @@ -1863,10 +1871,16 @@ void TryUse( gentity_t *ent ) { bool thirdPersonActive = gi.cvar("cg_thirdPerson", "0", CVAR_TEMP)->integer; vec3_t src, angles, vf; - if (ent->client->ps.clientNum == 0 && !thirdPersonActive) { - BG_CalculateVRWeaponPosition(src, angles); - AngleVectors( angles, vf, NULL, NULL ); - TryUse_Internal(false, ent, src, vf); + if (ent->client->ps.clientNum == 0) { + if (thirdPersonActive) { + VectorCopy(ent->currentOrigin, src); + AngleVectors(ent->currentAngles, vf, NULL, NULL); + TryUse_Internal(false, ent, src, vf); + } else { + BG_CalculateVRWeaponPosition(src, angles); + AngleVectors( angles, vf, NULL, NULL ); + TryUse_Internal(false, ent, src, vf); + } } else { VectorCopy(ent->client->renderInfo.eyePoint, src); AngleVectors(ent->client->ps.viewangles, vf, NULL, NULL); diff --git a/Projects/Android/jni/OpenJK/codeJK2/game/g_active.cpp b/Projects/Android/jni/OpenJK/codeJK2/game/g_active.cpp index 0d4cc47..c7e646d 100644 --- a/Projects/Android/jni/OpenJK/codeJK2/game/g_active.cpp +++ b/Projects/Android/jni/OpenJK/codeJK2/game/g_active.cpp @@ -819,11 +819,12 @@ void ClientImpacts( gentity_t *ent, pmove_t *pm ) { } - // Use triggers seems to have bigger "front" boundaries - // (with longer range player often reaches behind them - // not activating them at all) -const float TOUCH_DISTANCE = 1.0f; -const vec3_t TOUCH_RANGE = { 4, 4, 4 }; +// Use triggers seems to have bigger "front" boundaries allowing +// user to trigger them from distance while it is possible to reach +// through them when standing near. To ballance this, move hand +// origin a bit back +const float TOUCH_OFFSET = -10.0f; +const vec3_t TOUCH_RANGE = { 4, 4, 4 }; void G_TouchTriggersWithHand( bool offHand, gentity_t *ent, vec3_t src, vec3_t vf ) { vec3_t dest, mins, maxs; @@ -834,7 +835,7 @@ void G_TouchTriggersWithHand( bool offHand, gentity_t *ent, vec3_t src, vec3_t v memset (touched, qfalse, sizeof(touched) ); - VectorMA( src, TOUCH_DISTANCE, vf, dest ); + VectorMA( src, TOUCH_OFFSET, vf, dest ); VectorSubtract( dest, TOUCH_RANGE, mins ); VectorAdd( dest, TOUCH_RANGE, maxs ); diff --git a/Projects/Android/jni/OpenJK/codeJK2/game/g_utils.cpp b/Projects/Android/jni/OpenJK/codeJK2/game/g_utils.cpp index 20c3669..6a04a26 100644 --- a/Projects/Android/jni/OpenJK/codeJK2/game/g_utils.cpp +++ b/Projects/Android/jni/OpenJK/codeJK2/game/g_utils.cpp @@ -1442,12 +1442,15 @@ qboolean CanUseInfrontOf(gentity_t *ent) return qfalse; } + bool thirdPersonActive = gi.cvar("cg_thirdPerson", "0", CVAR_TEMP)->integer; + if (thirdPersonActive) { + VectorCopy(ent->currentOrigin, src); + AngleVectors(ent->currentAngles, vf, NULL, NULL); + } else { + VectorCopy( ent->client->renderInfo.eyePoint, src ); + AngleVectors( ent->client->ps.viewangles, vf, NULL, NULL ); + } - //FIXME: this does not match where the new accurate crosshair aims... - //cg.refdef.vieworg, basically - VectorCopy( ent->client->renderInfo.eyePoint, src ); - - AngleVectors( ent->client->ps.viewangles, vf, NULL, NULL ); //extend to find end of use trace VectorMA( src, USE_DISTANCE, vf, dest ); @@ -1523,7 +1526,10 @@ Try and use an entity in the world, directly ahead of us */ #define USE_DISTANCE_BUTTON 64.0f -#define USE_DISTANCE_GESTURE 16.0f +#define USE_DISTANCE_GESTURE 26.0f +// Move controller origin a bit back to prevent reach +// through usable entities when use gesture is active +#define USE_OFFSET -10.0f void TryUse_Internal( bool offHand, gentity_t *ent, vec3_t src, vec3_t vf ) { gentity_t *target; @@ -1534,7 +1540,9 @@ void TryUse_Internal( bool offHand, gentity_t *ent, vec3_t src, vec3_t vf ) { bool thirdPersonActive = gi.cvar("cg_thirdPerson", "0", CVAR_TEMP)->integer; bool useGestureEnabled = gi.cvar("vr_gesture_triggered_use", "1", CVAR_ARCHIVE)->integer; // defined in VrCvars.h bool useGestureAllowed = useGestureEnabled && !thirdPersonActive; + float useOffset = useGestureAllowed ? USE_OFFSET : 0.0f; float useDistance = useGestureAllowed ? USE_DISTANCE_GESTURE : USE_DISTANCE_BUTTON; + VectorMA( src, useOffset, vf, src ); VectorMA( src, useDistance, vf, dest ); //Trace ahead to find a valid target @@ -1609,10 +1617,16 @@ void TryUse( gentity_t *ent ) { bool thirdPersonActive = gi.cvar("cg_thirdPerson", "0", CVAR_TEMP)->integer; vec3_t src, angles, vf; - if (ent->client->ps.clientNum == 0 && !thirdPersonActive) { - BG_CalculateVRWeaponPosition(src, angles); - AngleVectors( angles, vf, NULL, NULL ); - TryUse_Internal(false, ent, src, vf); + if (ent->client->ps.clientNum == 0) { + if (thirdPersonActive) { + VectorCopy(ent->currentOrigin, src); + AngleVectors(ent->currentAngles, vf, NULL, NULL); + TryUse_Internal(false, ent, src, vf); + } else { + BG_CalculateVRWeaponPosition(src, angles); + AngleVectors( angles, vf, NULL, NULL ); + TryUse_Internal(false, ent, src, vf); + } } else { VectorCopy(ent->client->renderInfo.eyePoint, src); AngleVectors(ent->client->ps.viewangles, vf, NULL, NULL);