use the vector/plane macros to clean up the code a bit

This commit is contained in:
Bill Currie 2006-12-24 03:01:15 +00:00 committed by Jeff Teunissen
parent 33f08b6a43
commit a483f8670d

View file

@ -60,23 +60,15 @@ calc_impact (trace_t *trace, const vec3_t start, const vec3_t end,
mplane_t *plane) mplane_t *plane)
{ {
vec_t t1, t2, frac; vec_t t1, t2, frac;
int i, side; vec3_t dist;
if (plane->type < 3) { t1 = PlaneDiff (start, plane);
t1 = start[plane->type] - plane->dist; t2 = PlaneDiff (end, plane);
t2 = end[plane->type] - plane->dist;
} else {
t1 = DotProduct (plane->normal, start) - plane->dist;
t2 = DotProduct (plane->normal, end) - plane->dist;
}
side = t1 < 0; if (t1 < 0) {
if (side) {
frac = (t1 + DIST_EPSILON) / (t1 - t2); frac = (t1 + DIST_EPSILON) / (t1 - t2);
// invert plane paramterers // invert plane paramterers
trace->plane.normal[0] = -plane->normal[0]; VectorNegate (plane->normal, trace->plane.normal);
trace->plane.normal[1] = -plane->normal[1];
trace->plane.normal[2] = -plane->normal[2];
trace->plane.dist = -plane->dist; trace->plane.dist = -plane->dist;
} else { } else {
frac = (t1 - DIST_EPSILON) / (t1 - t2); frac = (t1 - DIST_EPSILON) / (t1 - t2);
@ -85,8 +77,8 @@ calc_impact (trace_t *trace, const vec3_t start, const vec3_t end,
} }
frac = bound (0, frac, 1); frac = bound (0, frac, 1);
trace->fraction = frac; trace->fraction = frac;
for (i = 0; i < 3; i++) VectorSubtract (end, start, dist);
trace->endpos[i] = start[i] + frac * (end[i] - start[i]); VectorMultAdd (start, frac, dist, trace->endpos);
} }
qboolean qboolean
@ -94,7 +86,7 @@ MOD_TraceLine (hull_t *hull, int num, const vec3_t start, const vec3_t end,
trace_t *trace) trace_t *trace)
{ {
vec_t front, back; vec_t front, back;
vec3_t frontpt, backpt; vec3_t frontpt, backpt, dist;
int side, empty, solid; int side, empty, solid;
tracestack_t *tstack; tracestack_t *tstack;
tracestack_t tracestack[256]; tracestack_t tracestack[256];
@ -148,13 +140,8 @@ MOD_TraceLine (hull_t *hull, int num, const vec3_t start, const vec3_t end,
node = hull->clipnodes + num; node = hull->clipnodes + num;
plane = hull->planes + node->planenum; plane = hull->planes + node->planenum;
if (plane->type < 3) { front = PlaneDiff (frontpt, plane);
front = frontpt[plane->type] - plane->dist; back = PlaneDiff (backpt, plane);
back = backpt[plane->type] - plane->dist;
} else {
front = DotProduct (plane->normal, frontpt) - plane->dist;
back = DotProduct (plane->normal, backpt) - plane->dist;
}
if (front >= 0 && back >= 0) { if (front >= 0 && back >= 0) {
num = node->children[0]; num = node->children[0];
@ -177,9 +164,8 @@ MOD_TraceLine (hull_t *hull, int num, const vec3_t start, const vec3_t end,
tstack++; tstack++;
backpt[0] = frontpt[0] + front * (backpt[0] - frontpt[0]); VectorSubtract (backpt, frontpt, dist);
backpt[1] = frontpt[1] + front * (backpt[1] - frontpt[1]); VectorMultAdd (frontpt, frac, dist, backpt);
backpt[2] = frontpt[2] + front * (backpt[2] - frontpt[2]);
num = node->children[side]; num = node->children[side];
} }