From 85f642e9e7d45155ee37b4e9bb54b7642d1508fa Mon Sep 17 00:00:00 2001 From: Simon Date: Wed, 16 Nov 2022 22:34:41 +0000 Subject: [PATCH] Use primary hand direction/location as trigger for buttons --- Projects/Android/jni/JKVR/VrInputDefault.cpp | 5 +++- .../jni/OpenJK/codeJK2/game/g_trigger.cpp | 12 +++++++- .../jni/OpenJK/codeJK2/game/g_utils.cpp | 29 ++++++++++++------- 3 files changed, 34 insertions(+), 12 deletions(-) diff --git a/Projects/Android/jni/JKVR/VrInputDefault.cpp b/Projects/Android/jni/JKVR/VrInputDefault.cpp index 8999249..5748b95 100644 --- a/Projects/Android/jni/JKVR/VrInputDefault.cpp +++ b/Projects/Android/jni/JKVR/VrInputDefault.cpp @@ -414,6 +414,9 @@ void HandleInput_Default( ovrInputStateGamepad *pFootTrackingNew, ovrInputStateG VectorSet(vr.weaponangles, -degrees(atanf(y / zxDist)), -degrees(atan2f(x, -z)), vr.weaponangles[ROLL] / 2.0f); //Dampen roll on stabilised weapon + + VectorCopy(vr.hmdposition, vr.weaponposition); + VectorClear(vr.weaponoffset); vr.weaponposition[1] += 0.1; } } @@ -585,7 +588,7 @@ void HandleInput_Default( ovrInputStateGamepad *pFootTrackingNew, ovrInputStateG if ((primaryButtonsNew & primaryButton2) != (primaryButtonsOld & primaryButton2)) { if (vr.cgzoommode) { - sendButtonActionSimple("exitzoom"); + sendButtonActionSimple("exitscope"); } else if (cl.frame.ps.weapon == WP_SABER && vr.velocitytriggered) { diff --git a/Projects/Android/jni/OpenJK/codeJK2/game/g_trigger.cpp b/Projects/Android/jni/OpenJK/codeJK2/game/g_trigger.cpp index 6e6e7ac..4528c2e 100644 --- a/Projects/Android/jni/OpenJK/codeJK2/game/g_trigger.cpp +++ b/Projects/Android/jni/OpenJK/codeJK2/game/g_trigger.cpp @@ -25,6 +25,7 @@ along with this program; if not, see . #include "g_functions.h" #include "b_local.h" #include "anims.h" +#include "bg_local.h" #define ENTDIST_PLAYER 1 #define ENTDIST_NPC 2 @@ -228,7 +229,16 @@ void Touch_Multi( gentity_t *self, gentity_t *other, trace_t *trace ) if ( other->client ) { - AngleVectors( other->client->ps.viewangles, forward, NULL, NULL ); + if (other->client->ps.clientNum == 0) + { + vec3_t origin, angles; + BG_CalculateVRWeaponPosition(origin, angles); + AngleVectors( angles, forward, NULL, NULL ); + } + else + { + AngleVectors( other->client->ps.viewangles, forward, NULL, NULL ); + } } else { diff --git a/Projects/Android/jni/OpenJK/codeJK2/game/g_utils.cpp b/Projects/Android/jni/OpenJK/codeJK2/game/g_utils.cpp index 95a70c6..5f7d87b 100644 --- a/Projects/Android/jni/OpenJK/codeJK2/game/g_utils.cpp +++ b/Projects/Android/jni/OpenJK/codeJK2/game/g_utils.cpp @@ -230,6 +230,8 @@ void G_PlayEffect( const char *name, const int modelIndex, const int boltIndex, extern void cgi_S_StartSound( vec3_t origin, int entityNum, int entchannel, sfxHandle_t sfx ); #include "../cgame/cg_media.h" //access to cgs +#include "bg_local.h" + extern void CG_TryPlayCustomSound( vec3_t origin, int entityNum, soundChannel_t channel, const char *soundName, int customSoundSet ); //NOTE: Do NOT Try to use this before the cgame DLL is valid, it will NOT work! void G_SoundOnEnt (gentity_t *ent, soundChannel_t channel, const char *soundPath) @@ -1267,22 +1269,29 @@ Try and use an entity in the world, directly ahead of us #define USE_DISTANCE 64.0f -void TryUse( gentity_t *ent ) -{ - gentity_t *target; - trace_t trace; - vec3_t src, dest, vf; +void TryUse( gentity_t *ent ) { + 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 ); + 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 - VectorCopy( ent->client->renderInfo.eyePoint, src ); + if (ent->client->ps.clientNum == 0) { + vec3_t angles; + 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 + } - 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 );