From 76f2b49ee07e11f0716f1d83ad089a0104d03390 Mon Sep 17 00:00:00 2001 From: Simon Date: Wed, 2 Mar 2022 23:26:57 +0000 Subject: [PATCH] Made spectator / follow mode use similar view to death cam --- android/app/src/main/cpp/code/cgame/cg_draw.c | 15 ++-- .../app/src/main/cpp/code/cgame/cg_local.h | 4 +- android/app/src/main/cpp/code/cgame/cg_view.c | 69 ++++++++++++------- .../app/src/main/cpp/code/cgame/cg_weapons.c | 9 +++ .../src/main/cpp/code/renderergl2/tr_init.c | 4 +- .../src/main/cpp/code/renderergl2/tr_local.h | 2 +- .../src/main/cpp/code/renderergl2/tr_sky.c | 2 +- .../app/src/main/cpp/code/vr/vr_renderer.c | 2 +- 8 files changed, 72 insertions(+), 35 deletions(-) diff --git a/android/app/src/main/cpp/code/cgame/cg_draw.c b/android/app/src/main/cpp/code/cgame/cg_draw.c index b614756d..3cf4aedc 100644 --- a/android/app/src/main/cpp/code/cgame/cg_draw.c +++ b/android/app/src/main/cpp/code/cgame/cg_draw.c @@ -2725,10 +2725,17 @@ void CG_DrawActive( stereoFrame_t stereoView ) { vec3_t baseOrg; VectorCopy( cg.refdef.vieworg, baseOrg ); - float worldscale = trap_Cvar_VariableValue("vr_worldscale") * - (( cg.snap->ps.stats[STAT_HEALTH] <= 0 ) && - ( cg.snap->ps.pm_type != PM_INTERMISSION ) ? DEATH_WORLDSCALE_MULTIPLIER : 1.0f); - + float worldscale = trap_Cvar_VariableValue("vr_worldscale"); + if (cg.snap->ps.pm_type == PM_SPECTATOR || + (cg.snap->ps.pm_flags & PMF_FOLLOW)) + { + worldscale *= SPECTATOR_WORLDSCALE_MULTIPLIER; + } + else if (( cg.snap->ps.stats[STAT_HEALTH] <= 0 ) && + ( cg.snap->ps.pm_type != PM_INTERMISSION )) + { + worldscale *= DEATH_WORLDSCALE_MULTIPLIER; + } float ipd = trap_Cvar_VariableValue("r_stereoSeparation") / 1000.0f; float separation = worldscale * (ipd / 2) * (stereoView == STEREO_LEFT ? -1.0f : 1.0f); 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 517f321d..879c168a 100644 --- a/android/app/src/main/cpp/code/cgame/cg_local.h +++ b/android/app/src/main/cpp/code/cgame/cg_local.h @@ -77,7 +77,8 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA #define NUM_CROSSHAIRS 10 //multiplying size you go to when dead looking down on the match -#define DEATH_WORLDSCALE_MULTIPLIER 40 +#define DEATH_WORLDSCALE_MULTIPLIER 40 +#define SPECTATOR_WORLDSCALE_MULTIPLIER 10 #define PLAYER_HEIGHT 48 @@ -631,7 +632,6 @@ typedef struct { float v_dmg_time; float v_dmg_pitch; float v_dmg_roll; - vec3_t v_death_origin; // temp working variables for player view float bobfracsin; 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 811a5902..38bb362a 100644 --- a/android/app/src/main/cpp/code/cgame/cg_view.c +++ b/android/app/src/main/cpp/code/cgame/cg_view.c @@ -220,21 +220,32 @@ static void CG_CalcVrect (void) { /* =============== -CG_OffsetDeathView +CG_OffsetVRThirdPersonView =============== */ -static void CG_OffsetDeathView( void ) { +static void CG_OffsetVRThirdPersonView( void ) { + float scale = 1.0f; - vec3_t position_delta; - VectorNegate(vr->hmdposition_delta, position_delta); - CG_ConvertFromVR(position_delta, NULL, position_delta); - position_delta[2] = 0; - VectorScale(position_delta, (DEATH_WORLDSCALE_MULTIPLIER / 2), position_delta); + if (cg.predictedPlayerState.pm_type == PM_SPECTATOR || + (cg.predictedPlayerState.pm_flags & PMF_FOLLOW)) + { + scale *= SPECTATOR_WORLDSCALE_MULTIPLIER; + } + else if (( cg.predictedPlayerState.stats[STAT_HEALTH] <= 0 ) && + ( cg.predictedPlayerState.pm_type != PM_INTERMISSION )) + { + scale *= DEATH_WORLDSCALE_MULTIPLIER; + } - VectorAdd(cg.v_death_origin, position_delta, cg.v_death_origin); - VectorCopy(cg.v_death_origin, cg.refdef.vieworg); - cg.refdef.vieworg[2] += DEATH_WORLDSCALE_MULTIPLIER * cg.predictedPlayerState.viewheight; + { + vec3_t position; + VectorCopy(vr->hmdposition, position); + CG_ConvertFromVR(position, NULL, position); + position[2] = 0; + VectorScale(position, scale, position); + VectorAdd(cg.refdef.vieworg, position, cg.refdef.vieworg); + } } /* @@ -255,8 +266,6 @@ static void CG_OffsetThirdPersonView( void ) { float focusDist; float forwardScale, sideScale; - VectorCopy(cg.refdef.vieworg, cg.v_death_origin); - cg.refdef.vieworg[2] += cg.predictedPlayerState.viewheight; VectorCopy( cg.refdefViewAngles, focusAngles ); @@ -348,8 +357,6 @@ static void CG_OffsetFirstPersonView( void ) { origin = cg.refdef.vieworg; angles = cg.refdefViewAngles; - VectorCopy(cg.refdef.vieworg, cg.v_death_origin); - float hitRollCoeff = trap_Cvar_VariableValue("vr_rollWhenHit"); // add angles based on damage kick @@ -638,8 +645,9 @@ static int CG_CalcViewValues( stereoFrame_t stereoView ) { //HACK!! - should change this to a renderer function call //Indicate to renderer whether we are in deathcam mode, We don't want sky in death cam mode - trap_Cvar_Set( "vr_deathCam", ((ps->stats[STAT_HEALTH] <= 0) && - ( ps->pm_type != PM_INTERMISSION )) ? "1" : "0" ); + trap_Cvar_Set( "vr_noSkybox", (((ps->stats[STAT_HEALTH] <= 0) && + ( ps->pm_type != PM_INTERMISSION )) || ps->pm_type == PM_SPECTATOR || + (ps->pm_flags & PMF_FOLLOW)) ? "1" : "0" ); // intermission view static float hmdYaw = 0; @@ -694,9 +702,11 @@ static int CG_CalcViewValues( stereoFrame_t stereoView ) { } } - if (cg.snap->ps.stats[STAT_HEALTH] <= 0) { - //If dead, view the map from above - CG_OffsetDeathView(); + if (cg.snap->ps.stats[STAT_HEALTH] <= 0 || + ps->pm_type == PM_SPECTATOR || + ps->pm_flags & PMF_FOLLOW) { + //If dead, or spectating, view the map from above + CG_OffsetVRThirdPersonView(); } else if ( cg.renderingThirdPerson ) { // back away from character CG_OffsetThirdPersonView(); @@ -705,7 +715,7 @@ static int CG_CalcViewValues( stereoFrame_t stereoView ) { CG_OffsetFirstPersonView(); } - if (stereoView == STEREO_LEFT) + if (!cgs.localServer && stereoView == STEREO_LEFT) { VectorCopy(vr->calculated_weaponangles, vr->last_calculated_weaponangles); @@ -769,7 +779,17 @@ static int CG_CalcViewValues( stereoFrame_t stereoView ) { VectorCopy(cg.refdefViewAngles, angles); angles[ROLL] = vr->hmdorientation[ROLL]; AnglesToAxis( angles, cg.refdef.viewaxis ); - } else { + } + else if (ps->pm_flags & PMF_FOLLOW) + { + //If we're following someone, + vec3_t angles; + VectorCopy(vr->hmdorientation, angles); + angles[YAW] = vr->clientviewangles[YAW]; + AnglesToAxis(angles, cg.refdef.viewaxis); + } + else + { //We are connected to a multiplayer server, so make the appropriate adjustment to the view //angles as we send orientation to the server that includes the weapon angles vec3_t angles; @@ -783,7 +803,7 @@ static int CG_CalcViewValues( stereoFrame_t stereoView ) { vec3_t angles; angles[ROLL] = vr->hmdorientation[ROLL]; angles[PITCH] = vr->weaponangles[PITCH]; - angles[YAW] = (cg.refdefViewAngles[YAW] - vr->hmdorientation[YAW]) + vr->last_calculated_weaponangles[YAW]; + angles[YAW] = (cg.refdefViewAngles[YAW] - vr->hmdorientation[YAW]) + vr->weaponangles[YAW]; AnglesToAxis(angles, cg.refdef.viewaxis); } else { AnglesToAxis(cg.refdefViewAngles, cg.refdef.viewaxis); @@ -906,8 +926,9 @@ void CG_DrawActiveFrame( int serverTime, stereoFrame_t stereoView, qboolean demo CG_PredictPlayerState(); // decide on third person view - cg.renderingThirdPerson = cg.snap->ps.persistant[PERS_TEAM] != TEAM_SPECTATOR - && cg_thirdPerson.integer; + cg.renderingThirdPerson = cg.predictedPlayerState.pm_type == PM_SPECTATOR || + cg.predictedPlayerState.pm_flags & PMF_FOLLOW || + cg_thirdPerson.integer; // build cg.refdef inwater = CG_CalcViewValues( stereoView ); 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 15ff2865..7b24539d 100644 --- a/android/app/src/main/cpp/code/cgame/cg_weapons.c +++ b/android/app/src/main/cpp/code/cgame/cg_weapons.c @@ -255,8 +255,17 @@ void CG_ConvertFromVR(vec3_t in, vec3_t offset, vec3_t out) } } +static void CG_CalculateWeaponPosition( vec3_t origin, vec3_t angles ); + void CG_CalculateVRWeaponPosition( vec3_t origin, vec3_t angles ) { + if (cg.predictedPlayerState.pm_type == PM_SPECTATOR || + cg.predictedPlayerState.pm_flags & PMF_FOLLOW) + { + CG_CalculateWeaponPosition(origin, angles); + return; + } + float worldscale = trap_Cvar_VariableValue("vr_worldscale"); if (!cgs.localServer) diff --git a/android/app/src/main/cpp/code/renderergl2/tr_init.c b/android/app/src/main/cpp/code/renderergl2/tr_init.c index cc04851d..3f9144c5 100644 --- a/android/app/src/main/cpp/code/renderergl2/tr_init.c +++ b/android/app/src/main/cpp/code/renderergl2/tr_init.c @@ -74,7 +74,7 @@ cvar_t *r_measureOverdraw; cvar_t *r_inGameVideo; cvar_t *r_fastsky; -cvar_t *vr_deathCam; +cvar_t *vr_noSkybox; cvar_t *r_drawSun; cvar_t *r_dynamiclight; cvar_t *r_dlightBacks; @@ -1312,7 +1312,7 @@ void R_Register( void ) r_useFlush = ri.Cvar_Get( "r_useFlush", "1", CVAR_ARCHIVE ); r_ignoreGLErrors = ri.Cvar_Get( "r_ignoreGLErrors", "1", CVAR_ARCHIVE ); r_fastsky = ri.Cvar_Get( "r_fastsky", "0", CVAR_ARCHIVE ); - vr_deathCam = ri.Cvar_Get( "vr_deathCam", "0", CVAR_TEMP ); + vr_noSkybox = ri.Cvar_Get( "vr_noSkybox", "0", CVAR_TEMP ); r_inGameVideo = ri.Cvar_Get( "r_inGameVideo", "1", CVAR_ARCHIVE ); r_drawSun = ri.Cvar_Get( "r_drawSun", "0", CVAR_ARCHIVE ); r_dynamiclight = ri.Cvar_Get( "r_dynamiclight", "0", CVAR_ARCHIVE ); diff --git a/android/app/src/main/cpp/code/renderergl2/tr_local.h b/android/app/src/main/cpp/code/renderergl2/tr_local.h index 6f280395..29c988d9 100644 --- a/android/app/src/main/cpp/code/renderergl2/tr_local.h +++ b/android/app/src/main/cpp/code/renderergl2/tr_local.h @@ -1701,7 +1701,7 @@ extern cvar_t *r_lodscale; extern cvar_t *r_inGameVideo; // controls whether in game video should be draw extern cvar_t *r_fastsky; // controls whether sky should be cleared or drawn -extern cvar_t *vr_deathCam; // +extern cvar_t *vr_noSkybox; // extern cvar_t *r_drawSun; // controls drawing of sun quad extern cvar_t *r_dynamiclight; // dynamic lights enabled/disabled extern cvar_t *r_dlightBacks; // dlight non-facing surfaces for continuity diff --git a/android/app/src/main/cpp/code/renderergl2/tr_sky.c b/android/app/src/main/cpp/code/renderergl2/tr_sky.c index 17638192..b1deb58d 100644 --- a/android/app/src/main/cpp/code/renderergl2/tr_sky.c +++ b/android/app/src/main/cpp/code/renderergl2/tr_sky.c @@ -843,7 +843,7 @@ Other things could be stuck in here, like birds in the sky, etc ================ */ void RB_StageIteratorSky( void ) { - if ( r_fastsky->integer || vr_deathCam->integer ) { + if ( r_fastsky->integer || vr_noSkybox->integer ) { return; } diff --git a/android/app/src/main/cpp/code/vr/vr_renderer.c b/android/app/src/main/cpp/code/vr/vr_renderer.c index 7b3511cd..95973596 100644 --- a/android/app/src/main/cpp/code/vr/vr_renderer.c +++ b/android/app/src/main/cpp/code/vr/vr_renderer.c @@ -214,7 +214,7 @@ void VR_ClearFrameBuffer( GLuint frameBuffer, int width, int height) glEnable( GL_SCISSOR_TEST ); glViewport( 0, 0, width, height ); - if (Cvar_VariableIntegerValue("vr_deathCam")) + if (Cvar_VariableIntegerValue("vr_noSkybox")) { //Blood red.. ish glClearColor( 0.12f, 0.0f, 0.05f, 1.0f );