From 217a6fa2b79c6d3f5687050fe34f0e10f48815b4 Mon Sep 17 00:00:00 2001 From: Simon Date: Fri, 11 Mar 2022 00:02:23 +0000 Subject: [PATCH] Weapon Wheel prevent cursor overshooting added ability to colourise the beam in code --- .../app/src/main/cpp/code/cgame/cg_local.h | 2 +- android/app/src/main/cpp/code/cgame/cg_view.c | 16 +++++++- .../app/src/main/cpp/code/cgame/cg_weapons.c | 41 ++++++++++++++----- 3 files changed, 46 insertions(+), 13 deletions(-) diff --git a/android/app/src/main/cpp/code/cgame/cg_local.h b/android/app/src/main/cpp/code/cgame/cg_local.h index fe6b001f..c526a7d9 100644 --- a/android/app/src/main/cpp/code/cgame/cg_local.h +++ b/android/app/src/main/cpp/code/cgame/cg_local.h @@ -1414,7 +1414,7 @@ void CG_AddViewWeapon (playerState_t *ps); void CG_DrawHolsteredWeapons( void ); void CG_AddPlayerWeapon( refEntity_t *parent, playerState_t *ps, centity_t *cent, int team ); void CG_DrawWeaponSelect( void ); -void CG_LaserSight( vec3_t start, vec3_t end ); +void CG_LaserSight( vec3_t start, vec3_t end, byte colour[4] ); void CG_OutOfAmmoChange( void ); // should this be in pmove? diff --git a/android/app/src/main/cpp/code/cgame/cg_view.c b/android/app/src/main/cpp/code/cgame/cg_view.c index 36c70201..86e340ac 100644 --- a/android/app/src/main/cpp/code/cgame/cg_view.c +++ b/android/app/src/main/cpp/code/cgame/cg_view.c @@ -751,7 +751,13 @@ static int CG_CalcViewValues( stereoFrame_t stereoView ) { if (cg_debugWeaponAiming.integer) { - CG_LaserSight(weaponorigin, trace.endpos); + byte colour[4]; + colour[0] = 0xff; + colour[1] = 0x00; + colour[2] = 0x00; + colour[3] = 0x40; + + CG_LaserSight(weaponorigin, trace.endpos, colour); } { @@ -776,7 +782,13 @@ static int CG_CalcViewValues( stereoFrame_t stereoView ) { if (cg_debugWeaponAiming.integer) { - CG_LaserSight(cg.refdef.vieworg, trace2.endpos); + byte colour[4]; + colour[0] = 0x00; + colour[1] = 0xff; + colour[2] = 0x00; + colour[3] = 0x40; + + CG_LaserSight(cg.refdef.vieworg, trace2.endpos, colour); } //convert to real-world angles - should be very close to real weapon angles diff --git a/android/app/src/main/cpp/code/cgame/cg_weapons.c b/android/app/src/main/cpp/code/cgame/cg_weapons.c index 47a33928..431516ac 100644 --- a/android/app/src/main/cpp/code/cgame/cg_weapons.c +++ b/android/app/src/main/cpp/code/cgame/cg_weapons.c @@ -504,7 +504,7 @@ static void CG_NailgunEjectBrass( centity_t *cent ) { CG_LaserSight ========================== */ -void CG_LaserSight( vec3_t start, vec3_t end ) { +void CG_LaserSight( vec3_t start, vec3_t end, byte colour[4] ) { refEntity_t re; memset( &re, 0, sizeof( re ) ); @@ -519,10 +519,10 @@ void CG_LaserSight( vec3_t start, vec3_t end ) { AxisClear( re.axis ); - re.shaderRGBA[0] = 0xff; - re.shaderRGBA[1] = 0x00; - re.shaderRGBA[2] = 0x00; - re.shaderRGBA[3] = 0x40; + re.shaderRGBA[0] = colour[0]; + re.shaderRGBA[1] = colour[1]; + re.shaderRGBA[2] = colour[2]; + re.shaderRGBA[3] = colour[3]; trap_R_AddRefEntityToScene(&re); } @@ -1729,7 +1729,14 @@ void CG_AddViewWeapon( playerState_t *ps ) { trace_t trace; CG_Trace(&trace, hand.origin, NULL, NULL, end, cg.predictedPlayerState.clientNum, MASK_SOLID); - CG_LaserSight(hand.origin, trace.endpos); + + byte colour[4]; + colour[0] = 0xff; + colour[1] = 0x00; + colour[2] = 0x00; + colour[3] = 0x40; + + CG_LaserSight(hand.origin, trace.endpos, colour); } //Scale / Move gun etc @@ -2033,6 +2040,11 @@ void CG_HolsterSelect_f( void ) cg.weaponHolsterSelection = WP_NONE; } +static float length(float x, float y) +{ + return sqrtf(powf(x, 2.0f) + powf(y, 2.0f)); +} + void CG_DrawHolsteredWeapons( void ) { if (cg.weaponHolsterTime == 0) @@ -2048,7 +2060,7 @@ void CG_DrawHolsteredWeapons( void ) float SCALE = 0.04f; const float DIST = 5.0f; const float SEP = 360.0f / (WP_NUM_WEAPONS - 1); // Exclude grappling hook - float frac = (cg.time - cg.weaponHolsterTime) / (50 * DIST); + float frac = (cg.time - cg.weaponHolsterTime) / (25 * DIST); if (frac > 1.0f) frac = 1.0f; vec3_t controllerOrigin, controllerAngles, controllerOffset, selectorOrigin; @@ -2063,10 +2075,19 @@ void CG_DrawHolsteredWeapons( void ) VectorMA(holsterOrigin, (DIST*frac), holsterForward, holsterOrigin); VectorCopy(holsterOrigin, selectorOrigin); - VectorMA(selectorOrigin, DIST * ((holsterAngles[YAW] - controllerAngles[YAW]) / 22.5f), holsterRight, selectorOrigin); - VectorMA(selectorOrigin, DIST * ((holsterAngles[PITCH] - controllerAngles[PITCH]) / 22.5f), holsterUp, selectorOrigin); + float x = ((holsterAngles[YAW] - controllerAngles[YAW]) / 22.5f); + float y = ((holsterAngles[PITCH] - controllerAngles[PITCH]) / 22.5f); + float len = length(x, y); + if (len > 1.0f) + { + x *= (1.0f / len); + y *= (1.0f / len); + } - { + VectorMA(selectorOrigin, DIST * x, holsterRight, selectorOrigin); + VectorMA(selectorOrigin, DIST * y, holsterUp, selectorOrigin); + + { refEntity_t blob; memset( &blob, 0, sizeof( blob ) ); VectorCopy( selectorOrigin, blob.origin );