From 6394ea27e88730001349160cd9a94be71dc8a131 Mon Sep 17 00:00:00 2001 From: Shpoike Date: Wed, 26 Jul 2023 11:18:06 +0100 Subject: [PATCH] Fix chasecam to deal with the viewmodel change... Also attempt to push it away from walls in a not-so-much-of-a-wallhack kind of way. --- Quake/chase.c | 31 ++++++++++++++++++++----------- Quake/cl_main.c | 2 +- Quake/client.h | 2 +- Quake/gl_rmain.c | 1 - Quake/gl_rmisc.c | 1 - Quake/gl_sky.c | 1 - Quake/glquake.h | 3 +++ Quake/pr_ext.c | 6 +----- 8 files changed, 26 insertions(+), 21 deletions(-) diff --git a/Quake/chase.c b/Quake/chase.c index ee2aee43..54c89c27 100644 --- a/Quake/chase.c +++ b/Quake/chase.c @@ -48,14 +48,25 @@ TraceLine TODO: impact on bmodels, monsters ============== */ -void TraceLine (vec3_t start, vec3_t end, vec3_t impact) +void TraceLine (vec3_t start, vec3_t end, float pushoff, vec3_t impact) { trace_t trace; memset (&trace, 0, sizeof(trace)); + trace.fraction = 1; + trace.allsolid = true; + VectorCopy (end, trace.endpos); SV_RecursiveHullCheck (cl.worldmodel->hulls, start, end, &trace, CONTENTMASK_ANYSOLID); VectorCopy (trace.endpos, impact); + + if (pushoff && trace.fraction < 1) //push away from the impact plane by the distance specified, so our camera's near clip plane does not intersect the wall. + { + vec3_t dir; + VectorSubtract(start, end, dir); + pushoff = pushoff / DotProduct(dir, trace.plane.normal); //distance needs to be bigger if the trace is co-planar to the surface + VectorMA(impact, pushoff, dir, impact); + } } /* @@ -91,28 +102,26 @@ void Chase_UpdateForDrawing (void) // calc ideal camera location before checking for walls for (i=0 ; i<3 ; i++) - ideal[i] = cl.viewent.origin[i] + ideal[i] = r_refdef.vieworg[i] - forward[i]*chase_back.value + right[i]*chase_right.value; //+ up[i]*chase_up.value; - ideal[2] = cl.viewent.origin[2] + chase_up.value; + ideal[2] = r_refdef.vieworg[2] + chase_up.value; // make sure camera is not in or behind a wall - TraceLine(r_refdef.vieworg, ideal, temp); - if (VectorLength(temp) != 0) - VectorCopy(temp, ideal); + TraceLine(r_refdef.vieworg, ideal, NEARCLIP, ideal); + + // find the spot the player is looking at + VectorMA (r_refdef.vieworg, 1<<20, forward, temp); + TraceLine (r_refdef.vieworg, temp, 0, crosshair); // place camera VectorCopy (ideal, r_refdef.vieworg); - // find the spot the player is looking at - VectorMA (cl.viewent.origin, 1<<20, forward, temp); - TraceLine (cl.viewent.origin, temp, crosshair); - // calculate camera angles to look at the same spot VectorSubtract (crosshair, r_refdef.vieworg, temp); VectorAngles (temp, NULL, r_refdef.viewangles); - if (r_refdef.viewangles[PITCH] == 90 || r_refdef.viewangles[PITCH] == -90) + if (r_refdef.viewangles[PITCH] >= 89.9 || r_refdef.viewangles[PITCH] <= -89.9) r_refdef.viewangles[YAW] = cl.viewangles[YAW]; } diff --git a/Quake/cl_main.c b/Quake/cl_main.c index 3bc44a71..b2058d94 100644 --- a/Quake/cl_main.c +++ b/Quake/cl_main.c @@ -1389,7 +1389,7 @@ void CL_Tracepos_f (void) return; VectorMA(r_refdef.vieworg, 8192.0, vpn, v); - TraceLine(r_refdef.vieworg, v, w); + TraceLine(r_refdef.vieworg, v, 0, w); if (VectorLength(w) == 0) Con_Printf ("Tracepos: trace didn't hit anything\n"); diff --git a/Quake/client.h b/Quake/client.h index 8e480e68..e2e1dae3 100644 --- a/Quake/client.h +++ b/Quake/client.h @@ -471,7 +471,7 @@ float CL_TraceLine (vec3_t start, vec3_t end, vec3_t impact, vec3_t normal, int extern cvar_t chase_active; void Chase_Init (void); -void TraceLine (vec3_t start, vec3_t end, vec3_t impact); +void TraceLine (vec3_t start, vec3_t end, float pushoff, vec3_t impact); void Chase_UpdateForClient (void); //johnfitz void Chase_UpdateForDrawing (void); //johnfitz diff --git a/Quake/gl_rmain.c b/Quake/gl_rmain.c index bd5ae112..7b1fe92e 100644 --- a/Quake/gl_rmain.c +++ b/Quake/gl_rmain.c @@ -453,7 +453,6 @@ void R_SetFrustum (float fovx, float fovy) GL_SetFrustum -- johnfitz -- written to replace MYgluPerspective ============= */ -#define NEARCLIP 4 float frustum_skew = 0.0; //used by r_stereo /*void GL_SetFrustum(float fovx, float fovy) { diff --git a/Quake/gl_rmisc.c b/Quake/gl_rmisc.c index 962723c3..a172f465 100644 --- a/Quake/gl_rmisc.c +++ b/Quake/gl_rmisc.c @@ -31,7 +31,6 @@ extern cvar_t r_clearcolor; extern cvar_t r_drawflat; extern cvar_t r_flatlightstyles; extern cvar_t gl_fullbrights; -extern cvar_t gl_farclip; extern cvar_t gl_overbright; extern cvar_t gl_overbright_models; extern cvar_t r_waterwarp; diff --git a/Quake/gl_sky.c b/Quake/gl_sky.c index 12737163..0363ec5d 100644 --- a/Quake/gl_sky.c +++ b/Quake/gl_sky.c @@ -46,7 +46,6 @@ char skybox_name[1024]; //name of current skybox, or "" if no skybox gltexture_t *skybox_textures[6]; gltexture_t *solidskytexture, *alphaskytexture; -extern cvar_t gl_farclip; cvar_t r_fastsky = {"r_fastsky", "0", CVAR_NONE}; cvar_t r_sky_quality = {"r_sky_quality", "12", CVAR_NONE}; cvar_t r_skyalpha = {"r_skyalpha", "1", CVAR_NONE}; diff --git a/Quake/glquake.h b/Quake/glquake.h index 15ad3c85..f93c1644 100644 --- a/Quake/glquake.h +++ b/Quake/glquake.h @@ -154,6 +154,9 @@ extern refdef_t r_refdef; extern mleaf_t *r_viewleaf, *r_oldviewleaf; extern int d_lightstylevalue[MAX_LIGHTSTYLES]; // 8.8 fraction of base light value +extern cvar_t gl_farclip; +#define NEARCLIP 4 + extern cvar_t r_norefresh; extern cvar_t r_drawentities; extern cvar_t r_drawworld; diff --git a/Quake/pr_ext.c b/Quake/pr_ext.c index fa616abb..d6c0599f 100644 --- a/Quake/pr_ext.c +++ b/Quake/pr_ext.c @@ -6945,14 +6945,10 @@ static void PF_cl_getproperty(void) G_FLOAT(OFS_RETURN+0) = viewprops.drawcrosshair; break; case VF_MINDIST: - #define NEARCLIP 4 G_FLOAT(OFS_RETURN+0) = NEARCLIP; break; case VF_MAXDIST: //maxdist - { - extern cvar_t gl_farclip; - G_FLOAT(OFS_RETURN+0) = gl_farclip.value; - } + G_FLOAT(OFS_RETURN+0) = gl_farclip.value; break; case VF_CL_VIEWANGLES: //viewangles hack