From fd1ded5c4a857836cb74aa371e6cee638fbe949a Mon Sep 17 00:00:00 2001 From: Ragnvald Maartmann-Moe IV Date: Wed, 26 Jun 2002 22:20:12 +0000 Subject: [PATCH] Add r_nearclip and r_particles_nearclip. Also put some limits on r_farclip. And fix id's insane max and min float, and some minor improvements in frustum setup in GL. --- include/QF/mathlib.h | 4 +- include/QF/qendian.h | 22 ++++---- include/compat.h | 1 + include/r_cvar.h | 2 + libs/util/mathlib.c | 6 +-- libs/video/renderer/gl/gl_dyn_part.c | 3 +- libs/video/renderer/gl/gl_rmain.c | 77 +++++++++++++--------------- libs/video/renderer/r_cvar.c | 43 +++++++++++++++- 8 files changed, 99 insertions(+), 59 deletions(-) diff --git a/include/QF/mathlib.h b/include/QF/mathlib.h index 300b68186..d6010aee9 100644 --- a/include/QF/mathlib.h +++ b/include/QF/mathlib.h @@ -112,8 +112,8 @@ int BoxOnPlaneSide (const vec3_t emins, const vec3_t emaxs, struct mplane_s *plane); float anglemod (float a); -void RotatePointAroundVector (vec3_t dst, const vec3_t dir, const vec3_t point, - float degrees ); +void RotatePointAroundVector (vec3_t dst, const vec3_t axis, + const vec3_t point, float degrees); #define BOX_ON_PLANE_SIDE(emins, emaxs, p) \ (((p)->type < 3)? \ diff --git a/include/QF/qendian.h b/include/QF/qendian.h index 0362f2b16..c92477792 100644 --- a/include/QF/qendian.h +++ b/include/QF/qendian.h @@ -37,17 +37,19 @@ # define NULL ((void *)0) #endif -#define Q_MAXCHAR ((char)0x7f) -#define Q_MAXSHORT ((short)0x7fff) -#define Q_MAXINT ((int)0x7fffffff) -#define Q_MAXLONG ((int)0x7fffffff) -#define Q_MAXFLOAT ((int)0x7fffffff) +#define Q_MAXCHAR ((char)0x7f) +#define Q_MAXSHORT ((short)0x7fff) +#define Q_MAXINT ((int)0x7fffffff) +#define Q_MAXLONG ((int)0x7fffffff) +#define Q_MAXFLOAT 3.40282346638528859811704183484516925440e38 -#define Q_MINCHAR ((char)0x80) -#define Q_MINSHORT ((short)0x8000) -#define Q_MININT ((int)0x80000000) -#define Q_MINLONG ((int)0x80000000) -#define Q_MINFLOAT ((int)0x7fffffff) +#define Q_MINCHAR ((char)0x80) +#define Q_MINSHORT ((short)0x8000) +#define Q_MININT ((int)0x80000000) +#define Q_MINLONG ((int)0x80000000) +#define Q_MINFLOAT -3.40282346638528859811704183484516925440e38 + +#define Q_FLOAT_EPSILON 1.1754943508222875079687365372222456778186655567720875215087517062784172594547271728515625e-38 //============================================================================ diff --git a/include/compat.h b/include/compat.h index 1b013a2dc..58652533a 100644 --- a/include/compat.h +++ b/include/compat.h @@ -41,6 +41,7 @@ #include + #ifndef max # define max(a,b) ((a) > (b) ? (a) : (b)) #endif diff --git a/include/r_cvar.h b/include/r_cvar.h index 86ec0bc91..8cff1c675 100644 --- a/include/r_cvar.h +++ b/include/r_cvar.h @@ -64,6 +64,7 @@ extern struct cvar_s *r_lightmap_components; extern struct cvar_s *r_maxedges; extern struct cvar_s *r_maxsurfs; extern struct cvar_s *r_mirroralpha; +extern struct cvar_s *r_nearclip; extern struct cvar_s *r_netgraph; extern struct cvar_s *r_netgraph_alpha; extern struct cvar_s *r_netgraph_box; @@ -73,6 +74,7 @@ extern struct cvar_s *r_numedges; extern struct cvar_s *r_numsurfs; extern struct cvar_s *r_particles; extern struct cvar_s *r_particles_max; +extern struct cvar_s *r_particles_nearclip; extern struct cvar_s *r_particles_style; extern struct cvar_s *r_reportedgeout; extern struct cvar_s *r_reportsurfout; diff --git a/libs/util/mathlib.c b/libs/util/mathlib.c index b8f645094..3c166ed23 100644 --- a/libs/util/mathlib.c +++ b/libs/util/mathlib.c @@ -112,7 +112,7 @@ VectorVectors(const vec3_t forward, vec3_t right, vec3_t up) } void -RotatePointAroundVector (vec3_t dst, const vec3_t dir, const vec3_t point, +RotatePointAroundVector (vec3_t dst, const vec3_t axis, const vec3_t point, float degrees) { float m[3][3]; @@ -123,9 +123,9 @@ RotatePointAroundVector (vec3_t dst, const vec3_t dir, const vec3_t point, int i; vec3_t vr, vup, vf; - VectorCopy (dir, vf); + VectorCopy (axis, vf); - PerpendicularVector (vr, dir); + PerpendicularVector (vr, axis); CrossProduct (vr, vf, vup); m[0][0] = vr[0]; diff --git a/libs/video/renderer/gl/gl_dyn_part.c b/libs/video/renderer/gl/gl_dyn_part.c index c7830cbe1..f2452dda4 100644 --- a/libs/video/renderer/gl/gl_dyn_part.c +++ b/libs/video/renderer/gl/gl_dyn_part.c @@ -1298,7 +1298,8 @@ R_DrawParticles (void) time30 = r_frametime * 30.0; time50 = r_frametime * 50.0; - minparticledist = DotProduct (r_refdef.vieworg, vpn) + 32.0; + minparticledist = DotProduct (r_refdef.vieworg, vpn) + + r_particles_nearclip->value; activeparticles = 0; vacount = 0; diff --git a/libs/video/renderer/gl/gl_rmain.c b/libs/video/renderer/gl/gl_rmain.c index 6cc3f6862..ec0d4120d 100644 --- a/libs/video/renderer/gl/gl_rmain.c +++ b/libs/video/renderer/gl/gl_rmain.c @@ -251,27 +251,19 @@ static void R_SetFrustum (void) { int i; - if (r_refdef.fov_x == 90) { - // front side is visible - VectorAdd (vpn, vright, frustum[0].normal); - VectorSubtract (vpn, vright, frustum[1].normal); - VectorAdd (vpn, vup, frustum[2].normal); - VectorSubtract (vpn, vup, frustum[3].normal); - } else { - // rotate VPN right by FOV_X/2 degrees - RotatePointAroundVector (frustum[0].normal, vup, vpn, - -(90 - r_refdef.fov_x / 2)); - // rotate VPN left by FOV_X/2 degrees - RotatePointAroundVector (frustum[1].normal, vup, vpn, - 90 - r_refdef.fov_x / 2); - // rotate VPN up by FOV_X/2 degrees - RotatePointAroundVector (frustum[2].normal, vright, vpn, - 90 - r_refdef.fov_y / 2); - // rotate VPN down by FOV_X/2 degrees - RotatePointAroundVector (frustum[3].normal, vright, vpn, - -(90 - r_refdef.fov_y / 2)); - } + // rotate VPN right by FOV_X/2 degrees + RotatePointAroundVector (frustum[0].normal, vup, vpn, + -(90 - r_refdef.fov_x / 2)); + // rotate VPN left by FOV_X/2 degrees + RotatePointAroundVector (frustum[1].normal, vup, vpn, + 90 - r_refdef.fov_x / 2); + // rotate VPN up by FOV_Y/2 degrees + RotatePointAroundVector (frustum[2].normal, vright, vpn, + 90 - r_refdef.fov_y / 2); + // rotate VPN down by FOV_Y/2 degrees + RotatePointAroundVector (frustum[3].normal, vright, vpn, + -(90 - r_refdef.fov_y / 2)); for (i = 0; i < 4; i++) { frustum[i].type = PLANE_ANYZ; @@ -314,7 +306,7 @@ MYgluPerspective (GLdouble fovy, GLdouble aspect, GLdouble zNear, GLdouble zFar) ymin = -ymax; xmin = ymin * aspect; - xmax = ymax * aspect; + xmax = -xmin; qfglFrustum (xmin, xmax, ymin, ymax, zNear, zFar); } @@ -325,36 +317,40 @@ R_SetupGL (void) float screenaspect; int x, x2, y2, y, w, h; + R_SetFrustum (); + // set up viewpoint qfglMatrixMode (GL_PROJECTION); qfglLoadIdentity (); - x = r_refdef.vrect.x * glwidth / vid.width; - x2 = (r_refdef.vrect.x + r_refdef.vrect.width) * glwidth / vid.width; - y = (vid.height - r_refdef.vrect.y) * glheight / vid.height; - y2 = (vid.height - (r_refdef.vrect.y + r_refdef.vrect.height)) * glheight - / vid.height; - - // fudge around because of frac screen scale - if (x > 0) - x--; - if (x2 < glwidth) - x2++; - if (y2 < 0) - y2--; - if (y < glheight) - y++; - - w = x2 - x; - h = y - y2; if (envmap) { x = y2 = 0; w = h = 256; + } else { + x = r_refdef.vrect.x * glwidth / vid.width; + x2 = (r_refdef.vrect.x + r_refdef.vrect.width) * glwidth / vid.width; + y = (vid.height - r_refdef.vrect.y) * glheight / vid.height; + y2 = (vid.height - (r_refdef.vrect.y + r_refdef.vrect.height)) * + glheight / vid.height; + + // fudge around because of frac screen scale + if (x > 0) + x--; + if (x2 < glwidth) + x2++; + if (y2 < 0) + y2--; + if (y < glheight) + y++; + + w = x2 - x; + h = y - y2; } qfglViewport (glx + x, gly + y2, w, h); screenaspect = (float) r_refdef.vrect.width / r_refdef.vrect.height; - MYgluPerspective (r_refdef.fov_y, screenaspect, 4, r_farclip->value); + MYgluPerspective (r_refdef.fov_y, screenaspect, r_nearclip->value, + r_farclip->value); if (mirror) { if (mirror_plane->normal[2]) @@ -405,7 +401,6 @@ R_RenderScene (void) r_time1 = Sys_DoubleTime (); R_SetupFrame (); - R_SetFrustum (); R_SetupGL (); R_MarkLeaves (); // done here so we know if we're in water R_PushDlights (vec3_origin); diff --git a/libs/video/renderer/r_cvar.c b/libs/video/renderer/r_cvar.c index 9afebf899..97165f727 100644 --- a/libs/video/renderer/r_cvar.c +++ b/libs/video/renderer/r_cvar.c @@ -38,7 +38,9 @@ static const char rcsid[] = #include "QF/cvar.h" #include "QF/model.h" +#include "QF/qendian.h" +#include "compat.h" #include "r_cvar.h" #include "r_dynamic.h" @@ -102,6 +104,7 @@ cvar_t *r_lightmap_components; cvar_t *r_maxedges; cvar_t *r_maxsurfs; cvar_t *r_mirroralpha; +cvar_t *r_nearclip; cvar_t *r_netgraph; cvar_t *r_netgraph_alpha; cvar_t *r_netgraph_box; @@ -112,6 +115,7 @@ cvar_t *r_numsurfs; cvar_t *r_particles; cvar_t *r_particles_style; cvar_t *r_particles_max; +cvar_t *r_particles_nearclip; cvar_t *r_reportedgeout; cvar_t *r_reportsurfout; cvar_t *r_shadows; @@ -162,6 +166,33 @@ r_lightmap_components_f (cvar_t *var) } } +static void +r_farclip_f (cvar_t *var) +{ + Cvar_SetValue (r_farclip, bound (8.0, var->value, Q_MAXFLOAT)); + if (r_particles_nearclip && r_nearclip) + Cvar_SetValue (r_particles_nearclip, + bound (r_nearclip->value, var->value, + r_farclip->value)); +} + +static void +r_nearclip_f (cvar_t *var) +{ + Cvar_SetValue (r_nearclip, bound (0.01, var->value, 4.0)); + if (r_particles_nearclip && r_farclip) + Cvar_SetValue (r_particles_nearclip, + bound (r_nearclip->value, var->value, + r_farclip->value)); +} + +static void +r_particles_nearclip_f (cvar_t *var) +{ + Cvar_SetValue (r_particles_nearclip, bound (r_nearclip->value, var->value, + r_farclip->value)); +} + void R_Init_Cvars (void) { @@ -286,8 +317,9 @@ R_Init_Cvars (void) "Set to 0 to disable lightmap changes"); r_explosionclip = Cvar_Get ("r_explosionclip", "0", CVAR_ARCHIVE, NULL, "Clip explosions."); - r_farclip = Cvar_Get ("r_farclip", "4096", CVAR_ARCHIVE, NULL, "Distance " - "of the far clipping plane from the player."); + r_farclip = Cvar_Get ("r_farclip", "4096", CVAR_ARCHIVE, r_farclip_f, + "Distance of the far clipping plane from the " + "player."); r_firecolor = Cvar_Get ("r_firecolor", "0.9 0.7 0.0", CVAR_ARCHIVE, NULL, "color of rocket and lava ball fires"); r_graphheight = Cvar_Get ("r_graphheight", "32", CVAR_NONE, NULL, @@ -302,6 +334,9 @@ R_Init_Cvars (void) r_maxsurfs = Cvar_Get ("r_maxsurfs", "0", CVAR_NONE, NULL, "Sets the maximum number of surfaces"); r_mirroralpha = Cvar_Get ("r_mirroralpha", "1", CVAR_NONE, NULL, "None"); + r_nearclip = Cvar_Get ("r_nearclip", "4", CVAR_ARCHIVE, r_nearclip_f, + "Distance of the near clipping plane from the " + "player."); r_netgraph = Cvar_Get ("r_netgraph", "0", CVAR_NONE, NULL, "Toggle the display of a graph showing network " "performance"); @@ -325,6 +360,10 @@ R_Init_Cvars (void) r_particles_max_f, "Maximum amount of " "particles to display. No maximum, minimum " "is 0."); + r_particles_nearclip = Cvar_Get ("r_particles_nearclip", "32", + CVAR_ARCHIVE, r_particles_nearclip_f, + "Distance of the particle near clipping " + "plane from the player."); r_particles_style = Cvar_Get ("r_particles_style", "1", CVAR_ARCHIVE, r_particles_style_f, "Sets particle style. " "0 for Id, 1 for QF.");