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.

This commit is contained in:
Ragnvald Maartmann-Moe IV 2002-06-26 22:20:12 +00:00
parent 26dce371d9
commit fd1ded5c4a
8 changed files with 99 additions and 59 deletions

View file

@ -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)? \

View file

@ -41,13 +41,15 @@
#define Q_MAXSHORT ((short)0x7fff)
#define Q_MAXINT ((int)0x7fffffff)
#define Q_MAXLONG ((int)0x7fffffff)
#define Q_MAXFLOAT ((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_MINFLOAT -3.40282346638528859811704183484516925440e38
#define Q_FLOAT_EPSILON 1.1754943508222875079687365372222456778186655567720875215087517062784172594547271728515625e-38
//============================================================================

View file

@ -41,6 +41,7 @@
#include <stdlib.h>
#ifndef max
# define max(a,b) ((a) > (b) ? (a) : (b))
#endif

View file

@ -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;

View file

@ -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];

View file

@ -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;

View file

@ -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
// 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_X/2 degrees
// 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,14 +317,21 @@ R_SetupGL (void)
float screenaspect;
int x, x2, y2, y, w, h;
R_SetFrustum ();
// set up viewpoint
qfglMatrixMode (GL_PROJECTION);
qfglLoadIdentity ();
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;
y2 = (vid.height - (r_refdef.vrect.y + r_refdef.vrect.height)) *
glheight / vid.height;
// fudge around because of frac screen scale
if (x > 0)
@ -346,15 +345,12 @@ R_SetupGL (void)
w = x2 - x;
h = y - y2;
if (envmap) {
x = y2 = 0;
w = h = 256;
}
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);

View file

@ -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.");