diff --git a/Projects/Android/jni/JKXR/VrClientInfo.h b/Projects/Android/jni/JKXR/VrClientInfo.h index f0f59b0..ad8dfcc 100644 --- a/Projects/Android/jni/JKXR/VrClientInfo.h +++ b/Projects/Android/jni/JKXR/VrClientInfo.h @@ -8,6 +8,9 @@ #define ANGLES_SABER 2 #define ANGLES_COUNT 3 +#define USE_GESTURE_OFF_HAND 1 +#define USE_GESTURE_WEAPON_HAND 2 + typedef struct { bool cin_camera; // cinematic camera taken over @@ -87,7 +90,7 @@ typedef struct { float maxHeight; float curHeight; - bool useGestureActive; + int useGestureState; ////////////////////////////////////// // Test stuff for weapon alignment diff --git a/Projects/Android/jni/JKXR/VrInputDefault.cpp b/Projects/Android/jni/JKXR/VrInputDefault.cpp index 42eeee0..fc13fa8 100644 --- a/Projects/Android/jni/JKXR/VrInputDefault.cpp +++ b/Projects/Android/jni/JKXR/VrInputDefault.cpp @@ -826,28 +826,42 @@ void HandleInput_Default( ovrInputStateTrackedRemote *pDominantTrackedRemoteNew, // Process "use" gesture if (vr_gesture_triggered_use->integer) { - float distanceToBody; - if (vr_gesture_triggered_use->integer == 1) { - // Gesture with off-hand - distanceToBody = sqrt(vr.offhandoffset[0]*vr.offhandoffset[0] + vr.offhandoffset[2]*vr.offhandoffset[2]); + 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]); + if (gestureUseAllowed && (distanceToBody > vr_use_gesture_boundary->value)) { + if (!(vr.useGestureState & USE_GESTURE_OFF_HAND)) { + sendButtonAction("+altuse", true); + } + vr.useGestureState |= USE_GESTURE_OFF_HAND; } else { - // Gesture with dominant-hand - distanceToBody = sqrt(vr.weaponoffset[0]*vr.weaponoffset[0] + vr.weaponoffset[2]*vr.weaponoffset[2]); + if (vr.useGestureState & USE_GESTURE_OFF_HAND) { + sendButtonAction("+altuse", false); + } + vr.useGestureState &= ~USE_GESTURE_OFF_HAND; } - - bool gestureUseAllowed = !vr.weapon_stabilised && !vr.cin_camera && !vr.misc_camera && !vr.remote_turret && !vr.emplaced_gun && !vr.in_vehicle; - if (gestureUseAllowed && distanceToBody > vr_use_gesture_boundary->value) { - if (!vr.useGestureActive) { - vr.useGestureActive = true; + // Weapon-hand gesture + distanceToBody = sqrt(vr.weaponoffset[0]*vr.weaponoffset[0] + vr.weaponoffset[2]*vr.weaponoffset[2]); + if (gestureUseAllowed && (distanceToBody > vr_use_gesture_boundary->value)) { + if (!(vr.useGestureState & USE_GESTURE_WEAPON_HAND)) { sendButtonAction("+use", true); } - } else if (vr.useGestureActive) { - vr.useGestureActive = false; + vr.useGestureState |= USE_GESTURE_WEAPON_HAND; + } else { + if (vr.useGestureState & USE_GESTURE_WEAPON_HAND) { + sendButtonAction("+use", false); + } + vr.useGestureState &= ~USE_GESTURE_WEAPON_HAND; + } + } else { + if (vr.useGestureState & USE_GESTURE_OFF_HAND) { + sendButtonAction("+altuse", false); + } + if (vr.useGestureState & USE_GESTURE_WEAPON_HAND) { sendButtonAction("+use", false); } - } else if (vr.useGestureActive) { - vr.useGestureActive = false; - sendButtonAction("+use", false); + vr.useGestureState = 0; } } diff --git a/Projects/Android/jni/OpenJK/code/client/cl_input.cpp b/Projects/Android/jni/OpenJK/code/client/cl_input.cpp index 7c3a176..f1f9d7b 100644 --- a/Projects/Android/jni/OpenJK/code/client/cl_input.cpp +++ b/Projects/Android/jni/OpenJK/code/client/cl_input.cpp @@ -1015,6 +1015,8 @@ void CL_InitInput( void ) { Cmd_AddCommand ("+block", IN_Button8Down);//manual blocking Cmd_AddCommand ("-block", IN_Button8Up); #endif + Cmd_AddCommand ("+altuse", IN_Button9Down); //use object with other hand + Cmd_AddCommand ("-altuse", IN_Button9Up); Cmd_AddCommand ("+button0", IN_Button0Down); Cmd_AddCommand ("-button0", IN_Button0Up); diff --git a/Projects/Android/jni/OpenJK/code/game/bg_pmove.cpp b/Projects/Android/jni/OpenJK/code/game/bg_pmove.cpp index 8b0fd91..10c0577 100644 --- a/Projects/Android/jni/OpenJK/code/game/bg_pmove.cpp +++ b/Projects/Android/jni/OpenJK/code/game/bg_pmove.cpp @@ -664,7 +664,7 @@ static void PM_Friction( void ) { } } /* - else if ( pm->cmd.buttons & BUTTON_USE ) + else if ( pm->cmd.buttons & ( BUTTON_USE | BUTTON_ALT_USE ) ) {//If the use key is pressed. slow the player more quickly if ( pm->gent->client->NPC_class != CLASS_VEHICLE ) // if not in a vehicle... {//in a vehicle, use key makes you turbo-boost @@ -9706,6 +9706,32 @@ void PM_Use( void ) pm->ps->useTime = USE_DELAY; } +void PM_AltUse( void ) +{ + if ( pm->ps->altUseTime > 0 ) + { + pm->ps->altUseTime -= pml.msec; + if ( pm->ps->altUseTime < 0 ) + { + pm->ps->altUseTime = 0; + } + } + + if ( pm->ps->altUseTime > 0 ) { + return; + } + + if ( ! (pm->cmd.buttons & BUTTON_ALT_USE ) ) + { + pm->altUseEvent = 0; + pm->ps->altUseTime = 0; + return; + } + + pm->altUseEvent = EV_USE; + pm->ps->altUseTime = USE_DELAY; +} + extern saberMoveName_t PM_AttackForEnemyPos( qboolean allowFB, qboolean allowStabDown ); saberMoveName_t PM_NPCSaberAttackFromQuad( int quad ) { @@ -15065,6 +15091,7 @@ void Pmove( pmove_t *pmove ) { // Use PM_Use(); + PM_AltUse(); } // Calculate the resulting speed of the last pmove diff --git a/Projects/Android/jni/OpenJK/code/game/bg_public.h b/Projects/Android/jni/OpenJK/code/game/bg_public.h index 16a6c3b..250ae1f 100644 --- a/Projects/Android/jni/OpenJK/code/game/bg_public.h +++ b/Projects/Android/jni/OpenJK/code/game/bg_public.h @@ -142,6 +142,7 @@ typedef struct { int touchents[MAXTOUCH]; int useEvent; + int altUseEvent; vec3_t mins, maxs; // bounding box size diff --git a/Projects/Android/jni/OpenJK/code/game/g_active.cpp b/Projects/Android/jni/OpenJK/code/game/g_active.cpp index 9805ce9..b8dd960 100644 --- a/Projects/Android/jni/OpenJK/code/game/g_active.cpp +++ b/Projects/Android/jni/OpenJK/code/game/g_active.cpp @@ -41,7 +41,10 @@ extern void VehicleExplosionDelay( gentity_t *self ); extern qboolean Q3_TaskIDPending( gentity_t *ent, taskID_t taskType ); extern void G_MaintainFormations(gentity_t *self); extern void BG_CalculateOffsetAngles( gentity_t *ent, usercmd_t *ucmd );//in bg_pangles.cpp +extern void BG_CalculateVRWeaponPosition( vec3_t origin, vec3_t angles );//in bg_pmisc.cpp +extern void BG_CalculateVROffHandPosition( vec3_t origin, vec3_t angles );//in bg_pmisc.cpp extern void TryUse( gentity_t *ent ); +extern void TryAltUse( gentity_t *ent ); extern void ChangeWeapon( gentity_t *ent, int newWeapon ); extern void ScoreBoardReset(void); extern void WP_SaberReflectCheck( gentity_t *self, usercmd_t *ucmd ); @@ -1345,6 +1348,51 @@ 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 }; + +void G_TouchTriggersWithHand( gentity_t *ent, vec3_t src, vec3_t vf ) { + vec3_t dest, mins, maxs; + gentity_t *touch[MAX_GENTITIES], *hit; + qboolean touched[MAX_GENTITIES]; + int i, num; + trace_t trace; + + memset (touched, qfalse, sizeof(touched) ); + + VectorMA( src, TOUCH_DISTANCE, vf, dest ); + VectorSubtract( dest, TOUCH_RANGE, mins ); + VectorAdd( dest, TOUCH_RANGE, maxs ); + + num = gi.EntitiesInBox( mins, maxs, touch, MAX_GENTITIES ); + + for ( i=0 ; icontents & CONTENTS_TRIGGER ) ) { + // Entity is not trigger + continue; + } + if ( touched[i] == qtrue ) { + // Already touched this move + continue; + } + if ( !( hit->spawnflags & 4 ) ) { + // Non-BUTTON entities were already processed + continue; + } + + touched[i] = qtrue; + memset( &trace, 0, sizeof(trace) ); + if ( hit->e_TouchFunc != touchF_NULL ) { + GEntity_TouchFunc(hit, ent, &trace); + } + } +} + /* ============ G_TouchTriggersLerped @@ -1397,6 +1445,10 @@ void G_TouchTriggersLerped( gentity_t *ent ) { } memset (touched, qfalse, sizeof(touched) ); + bool thirdPersonActive = gi.cvar("cg_thirdPerson", "0", CVAR_TEMP)->integer; + bool useGestureEnabled = gi.cvar("vr_gesture_triggered_use", "0", CVAR_ARCHIVE)->integer; // defined in VrCvars.h + bool useGestureAllowed = useGestureEnabled && !thirdPersonActive; + for ( curDist = 0; !done && ent->maxs[1]>0; curDist += (float)ent->maxs[1]/2.0f ) { if ( curDist >= dist ) @@ -1451,6 +1503,12 @@ void G_TouchTriggersLerped( gentity_t *ent ) { } } + if (ent->client && ent->client->ps.clientNum == 0 && hit->spawnflags & 4 && useGestureAllowed) { + // Entity is BUTTON touched by player with enabled use gestures. Skip it as we want to touch + // buttons by hands and not by body in this case + continue; + } + touched[i] = qtrue; memset( &trace, 0, sizeof(trace) ); @@ -1467,6 +1525,22 @@ void G_TouchTriggersLerped( gentity_t *ent ) { */ } } + + // In case of player entity with use gesture enabled, trace additional entities for each players hand based on active use action. + if ( ent->client && ent->client->ps.clientNum == 0 && ent->client->ps.stats[STAT_HEALTH] > 0 && useGestureAllowed) { + if( ent->client->usercmd.buttons & BUTTON_USE ) { + vec3_t src, angles, vf; + BG_CalculateVRWeaponPosition(src, angles); + AngleVectors( angles, vf, NULL, NULL ); + G_TouchTriggersWithHand( ent, src, vf ); + } + if( ent->client->usercmd.buttons & BUTTON_ALT_USE ) { + vec3_t src, angles, vf; + BG_CalculateVROffHandPosition(src, angles); + AngleVectors( angles, vf, NULL, NULL ); + G_TouchTriggersWithHand( ent, src, vf ); + } + } } /* @@ -5458,6 +5532,10 @@ extern cvar_t *g_skippingcin; //TODO: Use TryUse( ent ); } + if ( pm.altUseEvent ) + { + TryAltUse( ent ); + } // link entity now, after any personal teleporters have been used gi.linkentity( ent ); diff --git a/Projects/Android/jni/OpenJK/code/game/g_trigger.cpp b/Projects/Android/jni/OpenJK/code/game/g_trigger.cpp index 925bf32..8b40d49 100644 --- a/Projects/Android/jni/OpenJK/code/game/g_trigger.cpp +++ b/Projects/Android/jni/OpenJK/code/game/g_trigger.cpp @@ -248,26 +248,27 @@ void Touch_Multi( gentity_t *self, gentity_t *other, trace_t *trace ) return; } - if( !( other->client->usercmd.buttons & BUTTON_USE ) ) + if( !( other->client->usercmd.buttons & ( BUTTON_USE | BUTTON_ALT_USE ) ) ) {//not pressing use button return; } } - if ( self->spawnflags & 2 ) - {//FACING + bool thirdPersonActive = gi.cvar("cg_thirdPerson", "0", CVAR_TEMP)->integer; + bool useGestureEnabled = gi.cvar("vr_gesture_triggered_use", "0", CVAR_ARCHIVE)->integer; // defined in VrCvars.h + bool useGestureAllowed = useGestureEnabled && !thirdPersonActive; + if ( (self->spawnflags & 2) && ( !( self->spawnflags & 4 ) || ( ( self->spawnflags & 4) && !useGestureAllowed ) ) ) + { // FACING and... ...is not USE_BUTTON or... ...is USE_BUTTON but use gestures are not active + // In case of buttons activated by use gesture, we do not need to check if we are facing them as we are touching them by hand. vec3_t forward; if ( other->client ) { - if (other->client->ps.clientNum == 0) + if ( (other->client->ps.clientNum == 0) && (self->spawnflags & 4) ) { + // In case of USE_BUTTON, check facing by controller and not by head vec3_t origin, angles; - if (vr->useGestureActive && gi.cvar("vr_gesture_triggered_use", "2", CVAR_ARCHIVE)->integer == 1) { // defined in VrCvars.h - BG_CalculateVROffHandPosition(origin, angles); - } else { - BG_CalculateVRWeaponPosition(origin, angles); - } + BG_CalculateVRWeaponPosition(origin, angles); AngleVectors( angles, forward, NULL, NULL ); } else diff --git a/Projects/Android/jni/OpenJK/code/game/g_utils.cpp b/Projects/Android/jni/OpenJK/code/game/g_utils.cpp index b7f7ddb..122c867 100644 --- a/Projects/Android/jni/OpenJK/code/game/g_utils.cpp +++ b/Projects/Android/jni/OpenJK/code/game/g_utils.cpp @@ -1674,7 +1674,9 @@ qboolean CanUseInfrontOf(gentity_t *ent) //cg.refdef.vieworg, basically if (ent->client->ps.clientNum == 0) { vec3_t angles; - if (vr->useGestureActive && gi.cvar("vr_gesture_triggered_use", "2", CVAR_ARCHIVE)->integer == 1) { // defined in VrCvars.h + // TODO Not sure with this, function CanUseInfrontOf seems to be used only to + // show "usable hint" which i guess will be better based on gaze direction + if (vr->useGestureState & USE_GESTURE_OFF_HAND) { BG_CalculateVROffHandPosition(src, angles); } else { BG_CalculateVRWeaponPosition(src, angles); @@ -1768,37 +1770,21 @@ Try and use an entity in the world, directly ahead of us ============== */ +#define USE_DISTANCE_BUTTON 64.0f +#define USE_DISTANCE_GESTURE 16.0f -void TryUse( gentity_t *ent ) +void TryUse_Internal( gentity_t *ent, vec3_t src, vec3_t vf ) { gentity_t *target; trace_t trace; - vec3_t src, dest, vf; + vec3_t dest; - if (ent->s.number == 0 && g_npcdebug->integer == 1) - { - DebugTraceForNPC(ent); - } - - if ( ent->s.number == 0 && ent->client->NPC_class == CLASS_ATST ) - {//a player trying to get out of his ATST - GEntity_UseFunc( ent->activator, ent, ent ); - return; - } - - // TODO: turo-boost. -/* if ( ent->client->ps.vehicleIndex != VEHICLE_NONE ) - {//in a vehicle, use key makes you turbo-boost - return; - }*/ - - //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 );//ent->client->renderInfo.eyeAngles was cg.refdef.viewangles, basically //extend to find end of use trace - VectorMA( src, USE_DISTANCE, vf, dest ); + bool thirdPersonActive = gi.cvar("cg_thirdPerson", "0", CVAR_TEMP)->integer; + bool useGestureEnabled = gi.cvar("vr_gesture_triggered_use", "0", CVAR_ARCHIVE)->integer; // defined in VrCvars.h + bool useGestureAllowed = useGestureEnabled && !thirdPersonActive; + float useDistance = useGestureAllowed ? USE_DISTANCE_GESTURE : USE_DISTANCE_BUTTON; + VectorMA( src, useDistance, vf, dest ); //Trace ahead to find a valid target gi.trace( &trace, src, vec3_origin, vec3_origin, dest, ent->s.number, MASK_OPAQUE|CONTENTS_SOLID|CONTENTS_TERRAIN|CONTENTS_BODY|CONTENTS_ITEM|CONTENTS_CORPSE , G2_NOCOLLIDE, 10); @@ -1857,6 +1843,66 @@ void TryUse( gentity_t *ent ) */ } +void TryUse( gentity_t *ent ) { + if (ent->s.number == 0 && g_npcdebug->integer == 1) + { + DebugTraceForNPC(ent); + } + + if ( ent->s.number == 0 && ent->client->NPC_class == CLASS_ATST ) + {//a player trying to get out of his ATST + GEntity_UseFunc( ent->activator, ent, ent ); + return; + } + + // TODO: turo-boost. +/* if ( ent->client->ps.vehicleIndex != VEHICLE_NONE ) + {//in a vehicle, use key makes you turbo-boost + return; + }*/ + + vec3_t src, angles, vf; + if (ent->client->ps.clientNum == 0) { + BG_CalculateVRWeaponPosition(src, angles); + AngleVectors( angles, vf, NULL, NULL ); + TryUse_Internal(ent, src, vf); + } else { + VectorCopy(ent->client->renderInfo.eyePoint, src); + AngleVectors(ent->client->ps.viewangles, vf, NULL, NULL); + TryUse_Internal(ent, src, vf); + } +} + +void TryAltUse( gentity_t *ent ) { + if (ent->s.number == 0 && g_npcdebug->integer == 1) + { + DebugTraceForNPC(ent); + } + + if ( ent->s.number == 0 && ent->client->NPC_class == CLASS_ATST ) + {//a player trying to get out of his ATST + GEntity_UseFunc( ent->activator, ent, ent ); + return; + } + + // TODO: turo-boost. +/* if ( ent->client->ps.vehicleIndex != VEHICLE_NONE ) + {//in a vehicle, use key makes you turbo-boost + return; + }*/ + + vec3_t src, angles, vf; + if (ent->client->ps.clientNum == 0) { + BG_CalculateVROffHandPosition(src, angles); + AngleVectors( angles, vf, NULL, NULL ); + TryUse_Internal(ent, src, vf); + } else { + VectorCopy(ent->client->renderInfo.eyePoint, src); + AngleVectors(ent->client->ps.viewangles, vf, NULL, NULL); + TryUse_Internal(ent, src, vf); + } +} + extern int killPlayerTimer; void G_ChangeMap (const char *mapname, const char *spawntarget, qboolean hub) { diff --git a/Projects/Android/jni/OpenJK/code/qcommon/q_shared.h b/Projects/Android/jni/OpenJK/code/qcommon/q_shared.h index 5008b99..88c77c6 100644 --- a/Projects/Android/jni/OpenJK/code/qcommon/q_shared.h +++ b/Projects/Android/jni/OpenJK/code/qcommon/q_shared.h @@ -1668,6 +1668,7 @@ public: //int vehicleExplodeTime; //when it will go BOOM! int useTime; //not sent + int altUseTime; //not sent int lastShotTime;//last time you shot your weapon int ping; // server to game info for scoreboard int lastOnGround; //last time you were on the ground @@ -2265,6 +2266,8 @@ using playerState_t = PlayerStateBase; #define BUTTON_FORCE_FOCUS 256 // any key whatsoever +#define BUTTON_ALT_USE 512 + #define MOVE_RUN 120 // if forwardmove or rightmove are >= MOVE_RUN, // then BUTTON_WALKING should be set diff --git a/Projects/Android/jni/OpenJK/codeJK2/game/bg_pmove.cpp b/Projects/Android/jni/OpenJK/codeJK2/game/bg_pmove.cpp index 09f9859..38f9950 100644 --- a/Projects/Android/jni/OpenJK/codeJK2/game/bg_pmove.cpp +++ b/Projects/Android/jni/OpenJK/codeJK2/game/bg_pmove.cpp @@ -294,7 +294,7 @@ static void PM_Friction( void ) { if ( !(pm->ps->pm_flags & PMF_TIME_KNOCKBACK) && !(pm->ps->pm_flags & PMF_TIME_NOFRICTION) ) { //If the use key is pressed. slow the player more quickly - if ( pm->cmd.buttons & BUTTON_USE ) + if ( pm->cmd.buttons & ( BUTTON_USE | BUTTON_ALT_USE ) ) friction *= pm_frictionModifier; control = speed < pm_stopspeed ? pm_stopspeed : speed; @@ -5996,6 +5996,32 @@ void PM_Use( void ) pm->ps->useTime = USE_DELAY; } +void PM_AltUse( void ) +{ + if ( pm->ps->altUseTime > 0 ) + { + pm->ps->altUseTime -= pml.msec; + if ( pm->ps->altUseTime < 0 ) + { + pm->ps->altUseTime = 0; + } + } + + if ( pm->ps->altUseTime > 0 ) { + return; + } + + if ( ! (pm->cmd.buttons & BUTTON_ALT_USE ) ) + { + pm->altUseEvent = 0; + pm->ps->altUseTime = 0; + return; + } + + pm->altUseEvent = EV_USE; + pm->ps->altUseTime = USE_DELAY; +} + extern int PM_AttackForEnemyPos( qboolean allowFB ); int PM_NPCSaberAttackFromQuad( int quad ) { @@ -9028,6 +9054,7 @@ void Pmove( pmove_t *pmove ) { // Use PM_Use(); + PM_AltUse(); } // TEMPTEMPTEMPTEMPTEMPTEMPTEMPTEMPTEMPTEMPTEMPTEMPTEMPTEMPTEMP diff --git a/Projects/Android/jni/OpenJK/codeJK2/game/bg_public.h b/Projects/Android/jni/OpenJK/codeJK2/game/bg_public.h index 3a23d2f..03fbbf6 100644 --- a/Projects/Android/jni/OpenJK/codeJK2/game/bg_public.h +++ b/Projects/Android/jni/OpenJK/codeJK2/game/bg_public.h @@ -143,6 +143,7 @@ typedef struct { int touchents[MAXTOUCH]; int useEvent; + int altUseEvent; vec3_t mins, maxs; // bounding box size diff --git a/Projects/Android/jni/OpenJK/codeJK2/game/g_active.cpp b/Projects/Android/jni/OpenJK/codeJK2/game/g_active.cpp index 8479bb6..dec9b58 100644 --- a/Projects/Android/jni/OpenJK/codeJK2/game/g_active.cpp +++ b/Projects/Android/jni/OpenJK/codeJK2/game/g_active.cpp @@ -41,7 +41,10 @@ along with this program; if not, see . extern qboolean Q3_TaskIDPending( gentity_t *ent, taskID_t taskType ); extern void G_MaintainFormations(gentity_t *self); extern void BG_CalculateOffsetAngles( gentity_t *ent, usercmd_t *ucmd );//in bg_pangles.cpp +extern void BG_CalculateVRWeaponPosition( vec3_t origin, vec3_t angles );//in bg_pmisc.cpp +extern void BG_CalculateVROffHandPosition( vec3_t origin, vec3_t angles );//in bg_pmisc.cpp extern void TryUse( gentity_t *ent ); +extern void TryAltUse( gentity_t *ent ); extern void ChangeWeapon( gentity_t *ent, int newWeapon ); extern void ScoreBoardReset(void); extern void WP_SaberReflectCheck( gentity_t *self, usercmd_t *ucmd ); @@ -816,6 +819,51 @@ 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 }; + +void G_TouchTriggersWithHand( gentity_t *ent, vec3_t src, vec3_t vf ) { + vec3_t dest, mins, maxs; + gentity_t *touch[MAX_GENTITIES], *hit; + qboolean touched[MAX_GENTITIES]; + int i, num; + trace_t trace; + + memset (touched, qfalse, sizeof(touched) ); + + VectorMA( src, TOUCH_DISTANCE, vf, dest ); + VectorSubtract( dest, TOUCH_RANGE, mins ); + VectorAdd( dest, TOUCH_RANGE, maxs ); + + num = gi.EntitiesInBox( mins, maxs, touch, MAX_GENTITIES ); + + for ( i=0 ; icontents & CONTENTS_TRIGGER ) ) { + // Entity is not trigger + continue; + } + if ( touched[i] == qtrue ) { + // Already touched this move + continue; + } + if ( !( hit->spawnflags & 4 ) ) { + // Non-BUTTON entities were already processed + continue; + } + + touched[i] = qtrue; + memset( &trace, 0, sizeof(trace) ); + if ( hit->e_TouchFunc != touchF_NULL ) { + GEntity_TouchFunc(hit, ent, &trace); + } + } +} + /* ============ G_TouchTriggersLerped @@ -860,6 +908,10 @@ void G_TouchTriggersLerped( gentity_t *ent ) { memset (touched, qfalse, sizeof(touched) ); + bool thirdPersonActive = gi.cvar("cg_thirdPerson", "0", CVAR_TEMP)->integer; + bool useGestureEnabled = gi.cvar("vr_gesture_triggered_use", "0", CVAR_ARCHIVE)->integer; // defined in VrCvars.h + bool useGestureAllowed = useGestureEnabled && !thirdPersonActive; + for ( curDist = 0; !done && ent->maxs[1]>0; curDist += (float)ent->maxs[1]/2.0f ) { if ( curDist >= dist ) @@ -914,6 +966,12 @@ void G_TouchTriggersLerped( gentity_t *ent ) { } } + if (ent->client && ent->client->ps.clientNum == 0 && hit->spawnflags & 4 && useGestureAllowed) { + // Entity is BUTTON touched by player with enabled use gestures. Skip it as we want to touch + // buttons by hands and not by body in this case + continue; + } + touched[i] = qtrue; memset( &trace, 0, sizeof(trace) ); @@ -930,6 +988,22 @@ void G_TouchTriggersLerped( gentity_t *ent ) { */ } } + + // In case of player entity with use gesture enabled, trace additional entities for each players hand based on active use action. + if ( ent->client && ent->client->ps.clientNum == 0 && ent->client->ps.stats[STAT_HEALTH] > 0 && useGestureAllowed) { + if( ent->client->usercmd.buttons & BUTTON_USE ) { + vec3_t src, angles, vf; + BG_CalculateVRWeaponPosition(src, angles); + AngleVectors( angles, vf, NULL, NULL ); + G_TouchTriggersWithHand( ent, src, vf ); + } + if( ent->client->usercmd.buttons & BUTTON_ALT_USE ) { + vec3_t src, angles, vf; + BG_CalculateVROffHandPosition(src, angles); + AngleVectors( angles, vf, NULL, NULL ); + G_TouchTriggersWithHand( ent, src, vf ); + } + } } /* @@ -2854,6 +2928,10 @@ extern cvar_t *g_skippingcin; //TODO: Use TryUse( ent ); } + if ( pm.altUseEvent ) + { + TryAltUse( ent ); + } // link entity now, after any personal teleporters have been used gi.linkentity( ent ); diff --git a/Projects/Android/jni/OpenJK/codeJK2/game/g_trigger.cpp b/Projects/Android/jni/OpenJK/codeJK2/game/g_trigger.cpp index e977fff..f53720a 100644 --- a/Projects/Android/jni/OpenJK/codeJK2/game/g_trigger.cpp +++ b/Projects/Android/jni/OpenJK/codeJK2/game/g_trigger.cpp @@ -224,20 +224,21 @@ void Touch_Multi( gentity_t *self, gentity_t *other, trace_t *trace ) } } - if ( self->spawnflags & 2 ) - {//FACING + bool thirdPersonActive = gi.cvar("cg_thirdPerson", "0", CVAR_TEMP)->integer; + bool useGestureEnabled = gi.cvar("vr_gesture_triggered_use", "0", CVAR_ARCHIVE)->integer; // defined in VrCvars.h + bool useGestureAllowed = useGestureEnabled && !thirdPersonActive; + if ( (self->spawnflags & 2) && ( !( self->spawnflags & 4 ) || ( ( self->spawnflags & 4) && !useGestureAllowed ) ) ) + { // FACING and... ...is not USE_BUTTON or... ...is USE_BUTTON but use gestures are not active + // In case of buttons activated by use gesture, we do not need to check if we are facing them as we are touching them by hand. vec3_t forward; if ( other->client ) { - if (other->client->ps.clientNum == 0) + if ( (other->client->ps.clientNum == 0) && (self->spawnflags & 4) ) { + // In case of USE_BUTTON, check facing by controller and not by head vec3_t origin, angles; - if (vr->useGestureActive && gi.cvar("vr_gesture_triggered_use", "2", CVAR_ARCHIVE)->integer == 1) { // defined in VrCvars.h - BG_CalculateVROffHandPosition(origin, angles); - } else { - BG_CalculateVRWeaponPosition(origin, angles); - } + BG_CalculateVRWeaponPosition(origin, angles); AngleVectors( angles, forward, NULL, NULL ); } else @@ -263,7 +264,7 @@ void Touch_Multi( gentity_t *self, gentity_t *other, trace_t *trace ) return; } - if( !( other->client->usercmd.buttons & BUTTON_USE ) ) + if( !( other->client->usercmd.buttons & ( BUTTON_USE | BUTTON_ALT_USE ) ) ) {//not pressing use button return; } diff --git a/Projects/Android/jni/OpenJK/codeJK2/game/g_utils.cpp b/Projects/Android/jni/OpenJK/codeJK2/game/g_utils.cpp index 5fcf2b6..bb9fe14 100644 --- a/Projects/Android/jni/OpenJK/codeJK2/game/g_utils.cpp +++ b/Projects/Android/jni/OpenJK/codeJK2/game/g_utils.cpp @@ -1268,37 +1268,20 @@ Try and use an entity in the world, directly ahead of us ============== */ -#define USE_DISTANCE 64.0f +#define USE_DISTANCE_BUTTON 64.0f +#define USE_DISTANCE_GESTURE 16.0f -void TryUse( gentity_t *ent ) { +void TryUse_Internal( gentity_t *ent, vec3_t src, vec3_t vf ) { gentity_t *target; trace_t trace; - vec3_t src, dest, vf; - - if (ent->s.number == 0 && - ent->client->NPC_class == CLASS_ATST) {//a player trying to get out of his ATST - GEntity_UseFunc(ent->activator, ent, ent); - return; - } - //FIXME: this does not match where the new accurate crosshair aims... - //cg.refdef.vieworg, basically - if (ent->client->ps.clientNum == 0) { - vec3_t angles; - if (vr->useGestureActive && gi.cvar("vr_gesture_triggered_use", "2", CVAR_ARCHIVE)->integer == 1) { // defined in VrCvars.h - BG_CalculateVROffHandPosition(src, angles); - } else { - BG_CalculateVRWeaponPosition(src, angles); - } - AngleVectors(angles, vf, NULL, NULL); - } else { - VectorCopy(ent->client->renderInfo.eyePoint, src); - - AngleVectors(ent->client->ps.viewangles, vf, NULL, - NULL);//ent->client->renderInfo.eyeAngles was cg.refdef.viewangles, basically - } + vec3_t dest; //extend to find end of use trace - VectorMA( src, USE_DISTANCE, vf, dest ); + bool thirdPersonActive = gi.cvar("cg_thirdPerson", "0", CVAR_TEMP)->integer; + bool useGestureEnabled = gi.cvar("vr_gesture_triggered_use", "0", CVAR_ARCHIVE)->integer; // defined in VrCvars.h + bool useGestureAllowed = useGestureEnabled && !thirdPersonActive; + float useDistance = useGestureAllowed ? USE_DISTANCE_GESTURE : USE_DISTANCE_BUTTON; + VectorMA( src, useDistance, vf, dest ); //Trace ahead to find a valid target gi.trace( &trace, src, vec3_origin, vec3_origin, dest, ent->s.number, MASK_OPAQUE|CONTENTS_SOLID|CONTENTS_BODY|CONTENTS_ITEM|CONTENTS_CORPSE, G2_NOCOLLIDE, 0 ); @@ -1349,6 +1332,44 @@ void TryUse( gentity_t *ent ) { */ } +void TryUse( gentity_t *ent ) { + if (ent->s.number == 0 && + ent->client->NPC_class == CLASS_ATST) {//a player trying to get out of his ATST + GEntity_UseFunc(ent->activator, ent, ent); + return; + } + + vec3_t src, angles, vf; + if (ent->client->ps.clientNum == 0) { + BG_CalculateVRWeaponPosition(src, angles); + AngleVectors( angles, vf, NULL, NULL ); + TryUse_Internal(ent, src, vf); + } else { + VectorCopy(ent->client->renderInfo.eyePoint, src); + AngleVectors(ent->client->ps.viewangles, vf, NULL, NULL); + TryUse_Internal(ent, src, vf); + } +} + +void TryAltUse( gentity_t *ent ) { + if (ent->s.number == 0 && + ent->client->NPC_class == CLASS_ATST) {//a player trying to get out of his ATST + GEntity_UseFunc(ent->activator, ent, ent); + return; + } + + vec3_t src, angles, vf; + if (ent->client->ps.clientNum == 0) { + BG_CalculateVROffHandPosition(src, angles); + AngleVectors( angles, vf, NULL, NULL ); + TryUse_Internal(ent, src, vf); + } else { + VectorCopy(ent->client->renderInfo.eyePoint, src); + AngleVectors(ent->client->ps.viewangles, vf, NULL, NULL); + TryUse_Internal(ent, src, vf); + } +} + extern int killPlayerTimer; void G_ChangeMap (const char *mapname, const char *spawntarget, qboolean hub) { diff --git a/z_vr_assets/strip/menus_vr.sp b/z_vr_assets/strip/menus_vr.sp index 3e6f683..ec30377 100644 --- a/z_vr_assets/strip/menus_vr.sp +++ b/z_vr_assets/strip/menus_vr.sp @@ -652,7 +652,7 @@ INDEX 128 INDEX 129 { REFERENCE GESTURE_TRIGGERED_USE_DESC - TEXT_LANGUAGE1 "Toggles triggering of use/action by gesture." + TEXT_LANGUAGE1 "Toggles triggering of use/action by gesture (not active in 3rd person)." } INDEX 130 { diff --git a/z_vr_assets/ui/controls.menu b/z_vr_assets/ui/controls.menu index a4572d2..e7a16b9 100644 --- a/z_vr_assets/ui/controls.menu +++ b/z_vr_assets/ui/controls.menu @@ -1384,15 +1384,9 @@ { name none group commoncontrols - type ITEM_TYPE_MULTI + type ITEM_TYPE_YESNO text @MENUS_VR_GESTURE_TRIGGERED_USE_ITEM cvar "vr_gesture_triggered_use" - cvarFloatList - { - @MENUS0_NO 0 - @MENUS_VR_GESTURE_TRIGGERED_USE_OFF_HAND 1 - @MENUS_VR_GESTURE_TRIGGERED_USE_DOMINANT_HAND 2 - } rect 305 331 300 20 textalign ITEM_ALIGN_RIGHT textalignx 151 diff --git a/z_vr_assets/ui/ingamecontrols.menu b/z_vr_assets/ui/ingamecontrols.menu index 297f08d..8be1dba 100644 --- a/z_vr_assets/ui/ingamecontrols.menu +++ b/z_vr_assets/ui/ingamecontrols.menu @@ -1383,15 +1383,9 @@ { name none group commoncontrols - type ITEM_TYPE_MULTI + type ITEM_TYPE_YESNO text @MENUS_VR_GESTURE_TRIGGERED_USE_ITEM cvar "vr_gesture_triggered_use" - cvarFloatList - { - @MENUS0_NO 0 - @MENUS_VR_GESTURE_TRIGGERED_USE_OFF_HAND 1 - @MENUS_VR_GESTURE_TRIGGERED_USE_DOMINANT_HAND 2 - } rect 305 331 300 20 textalign ITEM_ALIGN_RIGHT textalignx 151 diff --git a/z_vr_assets_jka/strings/english/menus_vr.str b/z_vr_assets_jka/strings/english/menus_vr.str index 871ca9e..d98fafa 100644 --- a/z_vr_assets_jka/strings/english/menus_vr.str +++ b/z_vr_assets_jka/strings/english/menus_vr.str @@ -404,7 +404,7 @@ REFERENCE GESTURE_TRIGGERED_USE_ITEM LANG_ENGLISH "Gesture Triggered Use:" REFERENCE GESTURE_TRIGGERED_USE_DESC -LANG_ENGLISH "Toggles triggering of use/action by gesture." +LANG_ENGLISH "Toggles triggering of use/action by gesture (not active in 3rd person)." REFERENCE GESTURE_TRIGGERED_USE_OFF_HAND LANG_ENGLISH "Off-Hand" diff --git a/z_vr_assets_jka/strings/french/menus_vr.str b/z_vr_assets_jka/strings/french/menus_vr.str index 482897c..5bbf820 100644 --- a/z_vr_assets_jka/strings/french/menus_vr.str +++ b/z_vr_assets_jka/strings/french/menus_vr.str @@ -534,7 +534,7 @@ LANG_ENGLISH "Gesture Triggered Use:" LANG_FRENCH "#same" REFERENCE GESTURE_TRIGGERED_USE_DESC -LANG_ENGLISH "Toggles triggering of use/action by gesture." +LANG_ENGLISH "Toggles triggering of use/action by gesture (not active in 3rd person)." LANG_FRENCH "#same" REFERENCE GESTURE_TRIGGERED_USE_OFF_HAND diff --git a/z_vr_assets_jka/strings/german/menus_vr.str b/z_vr_assets_jka/strings/german/menus_vr.str index 9f22b2c..2539890 100644 --- a/z_vr_assets_jka/strings/german/menus_vr.str +++ b/z_vr_assets_jka/strings/german/menus_vr.str @@ -534,7 +534,7 @@ LANG_ENGLISH "Gesture Triggered Use:" LANG_GERMAN "#same" REFERENCE GESTURE_TRIGGERED_USE_DESC -LANG_ENGLISH "Toggles triggering of use/action by gesture." +LANG_ENGLISH "Toggles triggering of use/action by gesture (not active in 3rd person)." LANG_GERMAN "#same" REFERENCE GESTURE_TRIGGERED_USE_OFF_HAND diff --git a/z_vr_assets_jka/strings/spanish/menus_vr.str b/z_vr_assets_jka/strings/spanish/menus_vr.str index 43fd2cb..5ce09c3 100644 --- a/z_vr_assets_jka/strings/spanish/menus_vr.str +++ b/z_vr_assets_jka/strings/spanish/menus_vr.str @@ -534,7 +534,7 @@ LANG_ENGLISH "Gesture Triggered Use:" LANG_SPANISH "#same" REFERENCE GESTURE_TRIGGERED_USE_DESC -LANG_ENGLISH "Toggles triggering of use/action by gesture." +LANG_ENGLISH "Toggles triggering of use/action by gesture (not active in 3rd person)." LANG_SPANISH "#same" REFERENCE GESTURE_TRIGGERED_USE_OFF_HAND diff --git a/z_vr_assets_jka/ui/controls.menu b/z_vr_assets_jka/ui/controls.menu index 4938633..eb0b662 100644 --- a/z_vr_assets_jka/ui/controls.menu +++ b/z_vr_assets_jka/ui/controls.menu @@ -893,15 +893,9 @@ { name none group commoncontrols - type ITEM_TYPE_MULTI + type ITEM_TYPE_YESNO text @MENUS_VR_GESTURE_TRIGGERED_USE_ITEM cvar "vr_gesture_triggered_use" - cvarFloatList - { - @MENUS_NO 0 - @MENUS_VR_GESTURE_TRIGGERED_USE_OFF_HAND 1 - @MENUS_VR_GESTURE_TRIGGERED_USE_DOMINANT_HAND 2 - } rect 260 340 340 14 textalign ITEM_ALIGN_RIGHT textalignx 174 diff --git a/z_vr_assets_jka/ui/ingamecontrols.menu b/z_vr_assets_jka/ui/ingamecontrols.menu index 00556f9..4e3419b 100644 --- a/z_vr_assets_jka/ui/ingamecontrols.menu +++ b/z_vr_assets_jka/ui/ingamecontrols.menu @@ -1087,15 +1087,9 @@ { name none group commoncontrols - type ITEM_TYPE_MULTI + type ITEM_TYPE_YESNO text @MENUS_VR_GESTURE_TRIGGERED_USE_ITEM cvar "vr_gesture_triggered_use" - cvarFloatList - { - @MENUS_NO 0 - @MENUS_VR_GESTURE_TRIGGERED_USE_OFF_HAND 1 - @MENUS_VR_GESTURE_TRIGGERED_USE_DOMINANT_HAND 2 - } rect 260 340 340 14 textalign ITEM_ALIGN_RIGHT textalignx 174