do some renaming of variables to save my sanity

This commit is contained in:
Bill Currie 2006-12-24 06:34:12 +00:00 committed by Jeff Teunissen
parent 46a74c831a
commit 8dce95b4ba

View file

@ -49,7 +49,7 @@ static __attribute__ ((used)) const char rcsid[] =
/* LINE TESTING IN HULLS */ /* LINE TESTING IN HULLS */
typedef struct { typedef struct {
vec3_t backpt; vec3_t end;
int side; int side;
int num; int num;
mplane_t *plane; mplane_t *plane;
@ -91,19 +91,20 @@ calc_impact (trace_t *trace, const vec3_t start, const vec3_t end,
} }
qboolean qboolean
MOD_TraceLine (hull_t *hull, int num, const vec3_t start, const vec3_t end, MOD_TraceLine (hull_t *hull, int num,
const vec3_t start_point, const vec3_t end_point,
trace_t *trace) trace_t *trace)
{ {
vec_t front, back, offset, frac; vec_t start_dist, end_dist, offset, frac;
vec3_t frontpt, backpt, dist; vec3_t start, end, dist;
int side, empty, solid; int side, empty, solid;
tracestack_t *tstack; tracestack_t *tstack;
tracestack_t tracestack[256]; tracestack_t tracestack[256];
dclipnode_t *node; dclipnode_t *node;
mplane_t *plane, *split_plane; mplane_t *plane, *split_plane;
VectorCopy (start, frontpt); VectorCopy (start_point, start);
VectorCopy (end, backpt); VectorCopy (end_point, end);
tstack = tracestack; tstack = tracestack;
empty = 0; empty = 0;
@ -124,11 +125,11 @@ MOD_TraceLine (hull_t *hull, int num, const vec3_t start, const vec3_t end,
// DONE! // DONE!
trace->allsolid = solid & (num == CONTENTS_SOLID); trace->allsolid = solid & (num == CONTENTS_SOLID);
trace->startsolid = solid; trace->startsolid = solid;
calc_impact (trace, start, end, split_plane); calc_impact (trace, start_point, end_point, split_plane);
return false; return false;
} }
// pop up the stack for a back side // pop up the stack for a end_dist side
if (tstack-- == tracestack) { if (tstack-- == tracestack) {
trace->allsolid = solid & (num == CONTENTS_SOLID); trace->allsolid = solid & (num == CONTENTS_SOLID);
trace->startsolid = solid; trace->startsolid = solid;
@ -136,10 +137,10 @@ MOD_TraceLine (hull_t *hull, int num, const vec3_t start, const vec3_t end,
} }
// set the hit point for this plane // set the hit point for this plane
VectorCopy (backpt, frontpt); VectorCopy (end, start);
// go down the back side // go down the end_dist side
VectorCopy (tstack->backpt, backpt); VectorCopy (tstack->end, end);
side = tstack->side; side = tstack->side;
split_plane = tstack->plane; split_plane = tstack->plane;
@ -150,8 +151,8 @@ MOD_TraceLine (hull_t *hull, int num, const vec3_t start, const vec3_t end,
plane = hull->planes + node->planenum; plane = hull->planes + node->planenum;
offset = 0; offset = 0;
front = PlaneDiff (frontpt, plane); start_dist = PlaneDiff (start, plane);
back = PlaneDiff (backpt, plane); end_dist = PlaneDiff (end, plane);
if (trace->isbox) { if (trace->isbox) {
if (plane->type < 3) if (plane->type < 3)
offset = trace->extents[plane->type]; offset = trace->extents[plane->type];
@ -161,53 +162,57 @@ MOD_TraceLine (hull_t *hull, int num, const vec3_t start, const vec3_t end,
+ fabs (trace->extents[2] * plane->normal[2])); + fabs (trace->extents[2] * plane->normal[2]));
} }
// when offset is 0, the following is equivalent to: /* when offset is 0, the following is equivalent to:
// if (front >= 0 && back >= 0) ... if (start_dist >= 0 && end_dist >= 0) ...
// if (front < 0 && back < 0) ... if (start_dist < 0 && end_dist < 0) ...
// due to the order of operations due to the order of operations
// however, when (front == offset && back == offset) or however, when (start_dist == offset && end_dist == offset) or
// (front == -offset && back == -offset), the trace will go down (start_dist == -offset && end_dist == -offset), the trace will go
// the /correct/ side of the plane: ie, the side the box is actually down the /correct/ side of the plane: ie, the side the box is
// on actually on
if (front >= offset && back >= offset) { */
if (start_dist >= offset && end_dist >= offset) {
// entierly in front of the plane
num = node->children[0]; num = node->children[0];
continue; continue;
} }
if (front <= -offset && back <= -offset) { if (start_dist <= -offset && end_dist <= -offset) {
// entierly behind the plane
num = node->children[1]; num = node->children[1];
continue; continue;
} }
if (front >= offset || front <= -offset if (start_dist >= offset || start_dist <= -offset
|| back >= offset || back <= -offset) { || end_dist >= offset || end_dist <= -offset) {
// either: // either:
// back is guaranteed to be < offset or > -offset // end_dist is guaranteed to be < offset or > -offset
// or // or:
// front is guaranteed to be < offset or > -offset // start_dist is guaranteed to be < offset or > -offset
// so splitting is needed, on the offset plane closes to front // so splitting is needed, on the offset plane closest to
side = front < 0; // start
if (front < 0) { side = start_dist < 0;
frac = (front + offset) / (front - back); if (start_dist < 0) {
frac = (start_dist + offset) / (start_dist - end_dist);
} else { } else {
frac = (front - offset) / (front - back); frac = (start_dist - offset) / (start_dist - end_dist);
} }
frac = bound (0, frac, 1); frac = bound (0, frac, 1);
} else { } else {
// both: // both:
// front is guaranteed to be < offset and > -offset // start_dist is guaranteed to be < offset and > -offset
// and // and:
// back is guaranteed to be < offset and > -offset // end_dist is guaranteed to be < offset and > -offset
frac = 1; frac = 1;
side = front < back; side = start_dist < end_dist;
} }
tstack->num = num; tstack->num = num;
tstack->side = side; tstack->side = side;
tstack->plane = plane; tstack->plane = plane;
VectorCopy (backpt, tstack->backpt); VectorCopy (end, tstack->end);
tstack++; tstack++;
VectorSubtract (backpt, frontpt, dist); VectorSubtract (end, start, dist);
VectorMultAdd (frontpt, frac, dist, backpt); VectorMultAdd (start, frac, dist, end);
num = node->children[side]; num = node->children[side];
} }