@MuadDib's Multi-hand-use-gesture

This commit is contained in:
Simon 2023-03-05 08:48:31 +00:00
parent a4b8ffc635
commit b00d5053dd
23 changed files with 401 additions and 122 deletions

View file

@ -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

View file

@ -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;
}
}

View file

@ -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);

View file

@ -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

View file

@ -142,6 +142,7 @@ typedef struct {
int touchents[MAXTOUCH];
int useEvent;
int altUseEvent;
vec3_t mins, maxs; // bounding box size

View file

@ -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 ; i<num ; i++ ) {
hit = touch[i];
if ( !( hit->contents & 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 );

View file

@ -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

View file

@ -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)
{

View file

@ -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<saberInfo_t>;
#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

View file

@ -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

View file

@ -143,6 +143,7 @@ typedef struct {
int touchents[MAXTOUCH];
int useEvent;
int altUseEvent;
vec3_t mins, maxs; // bounding box size

View file

@ -41,7 +41,10 @@ along with this program; if not, see <http://www.gnu.org/licenses/>.
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 ; i<num ; i++ ) {
hit = touch[i];
if ( !( hit->contents & 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 );

View file

@ -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;
}

View file

@ -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)
{

View file

@ -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
{

View file

@ -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

View file

@ -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

View file

@ -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"

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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