From 6695f0bc0db441f3aeaf42a0e301c0e88ba596b4 Mon Sep 17 00:00:00 2001 From: Simon Date: Wed, 9 Nov 2022 21:28:18 +0000 Subject: [PATCH] Finished implementation of disruptor scope --- .../Android/jni/JKVR/JKVR_SurfaceView.cpp | 13 +++- Projects/Android/jni/JKVR/VrClientInfo.h | 8 --- Projects/Android/jni/JKVR/VrInput.h | 7 +-- Projects/Android/jni/JKVR/VrInputCommon.cpp | 25 -------- Projects/Android/jni/JKVR/VrInputDefault.cpp | 60 +++++++++---------- .../jni/OpenJK/code/cgame/cg_drawtools.cpp | 6 +- .../OpenJK/codeJK2/cgame/cg_consolecmds.cpp | 2 + .../jni/OpenJK/codeJK2/cgame/cg_drawtools.cpp | 6 +- .../jni/OpenJK/codeJK2/cgame/cg_weapons.cpp | 16 ++++- 9 files changed, 62 insertions(+), 81 deletions(-) diff --git a/Projects/Android/jni/JKVR/JKVR_SurfaceView.cpp b/Projects/Android/jni/JKVR/JKVR_SurfaceView.cpp index b07cc7b..be33b87 100644 --- a/Projects/Android/jni/JKVR/JKVR_SurfaceView.cpp +++ b/Projects/Android/jni/JKVR/JKVR_SurfaceView.cpp @@ -1751,8 +1751,17 @@ void JKVR_submitFrame() layer.Textures[eye].SwapChainIndex = frameBuffer->TextureSwapChainIndex; ovrMatrix4f projectionMatrix; - projectionMatrix = ovrMatrix4f_CreateProjectionFov(vr.fov, vr.fov, - 0.0f, 0.0f, 0.1f, 0.0f); + + if (vr.cgzoommode) + { + projectionMatrix = ovrMatrix4f_CreateProjectionFov(vr.fov / 1.4, vr.fov / 1.4, + 0.0f, 0.0f, 0.1f, 0.0f); + } + else + { + projectionMatrix = ovrMatrix4f_CreateProjectionFov(vr.fov, vr.fov, + 0.0f, 0.0f, 0.1f, 0.0f); + } layer.Textures[eye].TexCoordsFromTanAngles = ovrMatrix4f_TanAngleMatrixFromProjection(&projectionMatrix); diff --git a/Projects/Android/jni/JKVR/VrClientInfo.h b/Projects/Android/jni/JKVR/VrClientInfo.h index e4e9381..5e5f7d1 100644 --- a/Projects/Android/jni/JKVR/VrClientInfo.h +++ b/Projects/Android/jni/JKVR/VrClientInfo.h @@ -47,14 +47,6 @@ typedef struct { int item_selector = 0; // 1 - weapons/gadgets/saber stance, 2 - Force powers - //Lots of scope weapon stuff - bool scopeengaged; // Scope has been engaged on a scoped weapon - bool scopedweapon; // Weapon scope is available - bool scopedetached; // Scope has been detached from weapon - bool detachablescope; // Scope can be detached from weapon - - bool hasbinoculars; - bool velocitytriggered; float primaryswingvelocity; bool primaryVelocityTriggeredAttack; diff --git a/Projects/Android/jni/JKVR/VrInput.h b/Projects/Android/jni/JKVR/VrInput.h index cd0dd50..399a8a7 100644 --- a/Projects/Android/jni/JKVR/VrInput.h +++ b/Projects/Android/jni/JKVR/VrInput.h @@ -4,11 +4,7 @@ #include "VrCommon.h" -#define STABILISATION_DISTANCE 0.25 -#define SCOPE_ENGAGE_DISTANCE 0.25 -#define VSTOCK_ENGAGE_DISTANCE 0.25 -#define BINOCULAR_ENGAGE_DISTANCE 0.25 -#define VELOCITY_TRIGGER 1.0 +#define STABILISATION_DISTANCE 0.28 extern ovrInputStateTrackedRemote leftTrackedRemoteState_old; extern ovrInputStateTrackedRemote leftTrackedRemoteState_new; @@ -42,6 +38,5 @@ void HandleInput_WeaponAlign( ovrInputStateTrackedRemote *pDominantTrackedRemote void CalculateShoulderPosition(); -void updateScopeAngles(); #endif //vrinput_h \ No newline at end of file diff --git a/Projects/Android/jni/JKVR/VrInputCommon.cpp b/Projects/Android/jni/JKVR/VrInputCommon.cpp index 168ea8f..d92e6fd 100644 --- a/Projects/Android/jni/JKVR/VrInputCommon.cpp +++ b/Projects/Android/jni/JKVR/VrInputCommon.cpp @@ -176,31 +176,6 @@ void acquireTrackedRemotesData(ovrMobile *Ovr, double displayTime) {//The amount } } - -//YAW: Left increase, Right decrease -void updateScopeAngles() -{ - //Bit of a hack, but use weapon orientation / position for view when scope is engaged - static vec3_t currentScopeAngles; - static vec3_t lastScopeAngles; - if (vr.scopeengaged) - { - VectorSet(currentScopeAngles, vr.weaponangles[PITCH], vr.weaponangles[YAW], vr.hmdorientation[ROLL]); - - //Set "view" Angles - VectorCopy(currentScopeAngles, vr.hmdorientation); - - //Orientation - VectorSubtract(lastScopeAngles, currentScopeAngles, vr.hmdorientation_delta); - - //Keep this for our records - VectorCopy(currentScopeAngles, lastScopeAngles); - } else { - VectorSet(currentScopeAngles, vr.weaponangles[PITCH], vr.weaponangles[YAW], vr.hmdorientation[ROLL]); - VectorCopy(currentScopeAngles, lastScopeAngles); - } -} - void PortableMouseAbs(float x,float y); float clamp(float _min, float _val, float _max) { diff --git a/Projects/Android/jni/JKVR/VrInputDefault.cpp b/Projects/Android/jni/JKVR/VrInputDefault.cpp index 6f1b968..d765b5d 100644 --- a/Projects/Android/jni/JKVR/VrInputDefault.cpp +++ b/Projects/Android/jni/JKVR/VrInputDefault.cpp @@ -242,12 +242,11 @@ void HandleInput_Default( ovrInputStateGamepad *pFootTrackingNew, ovrInputStateG if (vr.weapon_stabilised && VectorLength(vr.weaponoffset) < 0.24f && vr.cgzoommode == 0) { - sendButtonAction("+altattack", true); + sendButtonAction("disruptorscope", true); } else if ((VectorLength(vr.weaponoffset) >= 0.24f || !vr.weapon_stabilised) && vr.cgzoommode == 2) { sendButtonActionSimple("exitzoom"); } - //We don't need to send the -altattack as the block below in the next frame will send it for us } if (vr.cgzoommode > 0) @@ -289,28 +288,6 @@ void HandleInput_Default( ovrInputStateGamepad *pFootTrackingNew, ovrInputStateG } } - //Engage scope / virtual stock if conditions are right - bool scopeready = vr.weapon_stabilised && (distanceToHMD < SCOPE_ENGAGE_DISTANCE); - static bool lastScopeReady = qfalse; - if (scopeready != lastScopeReady) { - if (vr.scopedweapon && !vr.scopedetached) { - if (!vr.scopeengaged && scopeready) { - ALOGV("**WEAPON EVENT** trigger scope mode"); - sendButtonActionSimple("weapalt"); - } else if (vr.scopeengaged && !scopeready) { - ALOGV("**WEAPON EVENT** disable scope mode"); - sendButtonActionSimple("weapalt"); - } - lastScopeReady = scopeready; - } - } - - //Engage scope / virtual stock (iron sight lock) if conditions are right - static bool scopeEngaged = qfalse; - if (scopeEngaged != vr.scopeengaged) { - scopeEngaged = vr.scopeengaged; - } - //dominant hand stuff first { //Record recent weapon position for trajectory based stuff @@ -403,7 +380,7 @@ void HandleInput_Default( ovrInputStateGamepad *pFootTrackingNew, ovrInputStateG } if (vr.weapon_stabilised) { - if (vr.scopeengaged || vr_virtual_stock->integer == 1) { + if (vr_virtual_stock->integer == 1) { //offset to the appropriate eye a little bit vec2_t xy; rotateAboutOrigin(Cvar_VariableValue("cg_stereoSeparation") / 2.0f, 0.0f, @@ -418,7 +395,26 @@ void HandleInput_Default( ovrInputStateGamepad *pFootTrackingNew, ovrInputStateG VectorSet(vr.weaponangles, -degrees(atanf(y / zxDist)), -degrees(atan2f(x, -z)), 0); } - } else { + } + else if (vr.cgzoommode == 2) + { + float x = + pOff->HeadPose.Pose.Position.x - vr.hmdposition[0]; + float y = + pOff->HeadPose.Pose.Position.y - (vr.hmdposition[1] - 0.1f); + float z = + pOff->HeadPose.Pose.Position.z - vr.hmdposition[2]; + float zxDist = length(x, z); + + if (zxDist != 0.0f && z != 0.0f) { + VectorSet(vr.weaponangles, -degrees(atanf(y / zxDist)), + -degrees(atan2f(x, -z)), vr.weaponangles[ROLL] / + 2.0f); //Dampen roll on stabilised weapon + vr.weaponposition[1] += 0.1; + } + } + else + { float x = pOff->HeadPose.Pose.Position.x - pWeapon->HeadPose.Pose.Position.x; float y = @@ -583,9 +579,9 @@ void HandleInput_Default( ovrInputStateGamepad *pFootTrackingNew, ovrInputStateG //B Button if ((primaryButtonsNew & primaryButton2) != (primaryButtonsOld & primaryButton2)) { - if (vr.cgzoommode == 1 || vr.cgzoommode == 3) + if (vr.cgzoommode) { - sendButtonActionSimple("invuse"); + sendButtonActionSimple("exitzoom"); } else if (cl.frame.ps.weapon == WP_SABER && vr.velocitytriggered) { @@ -676,9 +672,9 @@ void HandleInput_Default( ovrInputStateGamepad *pFootTrackingNew, ovrInputStateG //Move a lot slower if scope is engaged remote_movementSideways = - v[0] * (vr.scopeengaged ? 0.3f : 1.0f) * vr_movement_multiplier->value; + v[0] * vr_movement_multiplier->value; remote_movementForward = - v[1] * (vr.scopeengaged ? 0.3f : 1.0f) * vr_movement_multiplier->value; + v[1] * vr_movement_multiplier->value; ALOGV(" remote_movementSideways: %f, remote_movementForward: %f", remote_movementSideways, remote_movementForward); @@ -714,7 +710,7 @@ void HandleInput_Default( ovrInputStateGamepad *pFootTrackingNew, ovrInputStateG (!vr.third_person && vr_turn_mode->integer == 1); static int increaseSnap = true; - if (!vr.item_selector && !vr.scopeengaged) { + if (!vr.item_selector) { if (usingSnapTurn) { if (primaryJoystickX > 0.7f) { if (increaseSnap) { @@ -793,8 +789,6 @@ void HandleInput_Default( ovrInputStateGamepad *pFootTrackingNew, ovrInputStateG } } } - - updateScopeAngles(); } diff --git a/Projects/Android/jni/OpenJK/code/cgame/cg_drawtools.cpp b/Projects/Android/jni/OpenJK/code/cgame/cg_drawtools.cpp index 7238da4..042034c 100644 --- a/Projects/Android/jni/OpenJK/code/cgame/cg_drawtools.cpp +++ b/Projects/Android/jni/OpenJK/code/cgame/cg_drawtools.cpp @@ -28,10 +28,10 @@ along with this program; if not, see . void CG_AdjustFrom640( float *x, float *y, float *w, float *h ) { - if (cg.drawingHUD && !vr->cin_camera && !vr->using_screen_layer && !vr->scopeengaged) + if (cg.drawingHUD && !vr->cin_camera && !vr->using_screen_layer) { - float screenXScale = 1.0f / (cg.drawingHUD == CG_HUD_SCALED ? 2.5f : 1.2f); - float screenYScale = 1.0f / (cg.drawingHUD == CG_HUD_SCALED ? 2.5f : 1.2f); + float screenXScale = 1.0f / (cg.drawingHUD == CG_HUD_SCALED ? 2.5f : 1.0f); + float screenYScale = 1.0f / (cg.drawingHUD == CG_HUD_SCALED ? 2.5f : 1.0f); float xoffset = cg.drawingHUD == CG_HUD_SCALED ? -20 : 0; if (cg.refdef.stereoView == STEREO_LEFT) { diff --git a/Projects/Android/jni/OpenJK/codeJK2/cgame/cg_consolecmds.cpp b/Projects/Android/jni/OpenJK/codeJK2/cgame/cg_consolecmds.cpp index f266920..2f38dd4 100644 --- a/Projects/Android/jni/OpenJK/codeJK2/cgame/cg_consolecmds.cpp +++ b/Projects/Android/jni/OpenJK/codeJK2/cgame/cg_consolecmds.cpp @@ -208,6 +208,7 @@ void CG_ItemSelectorNext_f( void ); void CG_ItemSelectorPrev_f( void ); void CG_ToggleSaber_f( void ); void CG_ExitZoom_f( void ); +void CG_DisruptorScope_f( void ); /* This array MUST be sorted correctly by alphabetical name field */ static consoleCommand_t commands[] = { @@ -251,6 +252,7 @@ static consoleCommand_t commands[] = { { "itemselectorprev", CG_ItemSelectorPrev_f }, { "togglesaber", CG_ToggleSaber_f }, { "exitzoom", CG_ExitZoom_f }, + { "disruptorscope", CG_DisruptorScope_f }, }; static const size_t numCommands = ARRAY_LEN( commands ); diff --git a/Projects/Android/jni/OpenJK/codeJK2/cgame/cg_drawtools.cpp b/Projects/Android/jni/OpenJK/codeJK2/cgame/cg_drawtools.cpp index e03a669..bea1c32 100644 --- a/Projects/Android/jni/OpenJK/codeJK2/cgame/cg_drawtools.cpp +++ b/Projects/Android/jni/OpenJK/codeJK2/cgame/cg_drawtools.cpp @@ -27,10 +27,10 @@ along with this program; if not, see . void CG_AdjustFrom640( float *x, float *y, float *w, float *h ) { - if (cg.drawingHUD && !vr->cin_camera && !vr->using_screen_layer && !vr->scopeengaged) + if (cg.drawingHUD && !vr->cin_camera && !vr->using_screen_layer) { - float screenXScale = 1.0f / (cg.drawingHUD == CG_HUD_SCALED ? 2.5f : 1.2f); - float screenYScale = 1.0f / (cg.drawingHUD == CG_HUD_SCALED ? 2.5f : 1.2f); + float screenXScale = 1.0f / (cg.drawingHUD == CG_HUD_SCALED ? 2.5f : 1.0f); + float screenYScale = 1.0f / (cg.drawingHUD == CG_HUD_SCALED ? 2.5f : 1.0f); float xoffset = cg.drawingHUD == CG_HUD_SCALED ? -20 : 0; if (cg.refdef.stereoView == STEREO_LEFT) { diff --git a/Projects/Android/jni/OpenJK/codeJK2/cgame/cg_weapons.cpp b/Projects/Android/jni/OpenJK/codeJK2/cgame/cg_weapons.cpp index 8ba94dd..a5b1343 100644 --- a/Projects/Android/jni/OpenJK/codeJK2/cgame/cg_weapons.cpp +++ b/Projects/Android/jni/OpenJK/codeJK2/cgame/cg_weapons.cpp @@ -2651,9 +2651,11 @@ void CG_Weapon_f( void ) void Cmd_UseInventory_f(gentity_t *ent); +extern float cg_zoomFov; //from cg_view.cpp + void CG_ExitZoom_f( ) { - if ( cg.zoomMode == 2 ) + if ( cg.zoomMode ) { G_SoundOnEnt( pm->gent, CHAN_AUTO, "sound/weapons/disruptor/zoomend.wav" ); // already zooming, so must be wanting to turn it off @@ -2663,6 +2665,18 @@ void CG_ExitZoom_f( ) } } +void CG_DisruptorScope_f( ) +{ + if ( cg.zoomMode == 0 || cg.zoomMode == 3 ) + { + G_SoundOnEnt( pm->gent, CHAN_AUTO, "sound/weapons/disruptor/zoomstart.wav" ); + // not already zooming, so do it now + cg.zoomMode = 2; + cg.zoomLocked = qfalse; + cg_zoomFov = 80.0f;//(cg.overrides.active&CG_OVERRIDE_FOV) ? cg.overrides.fov : cg_fov.value; + } +} + void CG_ToggleSaber_f( ) { player->client->ps.saberActive = (qboolean)!player->client->ps.saberActive;