mirror of
https://git.code.sf.net/p/quake/quakeforge
synced 2025-02-16 17:01:53 +00:00
still disabled, but put the box tracing code in the shared code
This commit is contained in:
parent
45d467d748
commit
7624f2eb87
2 changed files with 53 additions and 184 deletions
|
@ -59,19 +59,28 @@ static inline void
|
|||
calc_impact (trace_t *trace, const vec3_t start, const vec3_t end,
|
||||
mplane_t *plane)
|
||||
{
|
||||
vec_t t1, t2, frac;
|
||||
vec_t t1, t2, frac, offset;
|
||||
vec3_t dist;
|
||||
|
||||
t1 = PlaneDiff (start, plane);
|
||||
t2 = PlaneDiff (end, plane);
|
||||
offset = 0;
|
||||
if (trace->isbox) {
|
||||
if (plane->type < 3)
|
||||
offset = trace->extents[plane->type];
|
||||
else
|
||||
offset = (fabs (trace->extents[0] * plane->normal[0])
|
||||
+ fabs (trace->extents[1] * plane->normal[1])
|
||||
+ fabs (trace->extents[2] * plane->normal[2]));
|
||||
}
|
||||
|
||||
if (t1 < 0) {
|
||||
frac = (t1 + DIST_EPSILON) / (t1 - t2);
|
||||
frac = (t1 + offset + DIST_EPSILON) / (t1 - t2);
|
||||
// invert plane paramterers
|
||||
VectorNegate (plane->normal, trace->plane.normal);
|
||||
trace->plane.dist = -plane->dist;
|
||||
} else {
|
||||
frac = (t1 - DIST_EPSILON) / (t1 - t2);
|
||||
frac = (t1 - offset - DIST_EPSILON) / (t1 - t2);
|
||||
VectorCopy (plane->normal, trace->plane.normal);
|
||||
trace->plane.dist = plane->dist;
|
||||
}
|
||||
|
@ -85,7 +94,7 @@ qboolean
|
|||
MOD_TraceLine (hull_t *hull, int num, const vec3_t start, const vec3_t end,
|
||||
trace_t *trace)
|
||||
{
|
||||
vec_t front, back, frac;
|
||||
vec_t front, back, offset, frac;
|
||||
vec3_t frontpt, backpt, dist;
|
||||
int side, empty, solid;
|
||||
tracestack_t *tstack;
|
||||
|
@ -140,28 +149,61 @@ MOD_TraceLine (hull_t *hull, int num, const vec3_t start, const vec3_t end,
|
|||
node = hull->clipnodes + num;
|
||||
plane = hull->planes + node->planenum;
|
||||
|
||||
offset = 0;
|
||||
front = PlaneDiff (frontpt, plane);
|
||||
back = PlaneDiff (backpt, plane);
|
||||
if (trace->isbox) {
|
||||
if (plane->type < 3)
|
||||
offset = trace->extents[plane->type];
|
||||
else
|
||||
offset = (fabs (trace->extents[0] * plane->normal[0])
|
||||
+ fabs (trace->extents[1] * plane->normal[1])
|
||||
+ fabs (trace->extents[2] * plane->normal[2]));
|
||||
}
|
||||
|
||||
// when offset is 0, the following is equivalent to:
|
||||
// if (front >= 0 && back >= 0) ...
|
||||
// if (front < 0 && back < 0) ...
|
||||
// due to the order of operations
|
||||
// however, when (front == offset && back == offset) or
|
||||
// (front == -offset && back == -offset), the trace will go down
|
||||
// the /correct/ side of the plane: ie, the side the box is actually
|
||||
// on
|
||||
if (front >= 0 && back >= 0) {
|
||||
num = node->children[0];
|
||||
continue;
|
||||
}
|
||||
|
||||
if (front < 0 && back < 0) {
|
||||
num = node->children[1];
|
||||
continue;
|
||||
}
|
||||
|
||||
side = front < 0;
|
||||
|
||||
frac = front / (front - back);
|
||||
if (front >= offset || front <= -offset
|
||||
|| back >= offset || back <= -offset) {
|
||||
// either:
|
||||
// back is guaranteed to be < offset or > -offset
|
||||
// or
|
||||
// front is guaranteed to be < offset or > -offset
|
||||
// so splitting is needed, on the offset plane closes to front
|
||||
side = front < 0;
|
||||
if (front < 0) {
|
||||
frac = (front + offset) / (front - back);
|
||||
} else {
|
||||
frac = (front - offset) / (front - back);
|
||||
}
|
||||
frac = bound (0, frac, 1);
|
||||
} else {
|
||||
// both:
|
||||
// front is guaranteed to be < offset and > -offset
|
||||
// and
|
||||
// back is guaranteed to be < offset and > -offset
|
||||
frac = 1;
|
||||
side = front < back;
|
||||
}
|
||||
|
||||
tstack->num = num;
|
||||
tstack->side = side;
|
||||
tstack->plane = plane;
|
||||
VectorCopy (backpt, tstack->backpt);
|
||||
|
||||
tstack++;
|
||||
|
||||
VectorSubtract (backpt, frontpt, dist);
|
||||
|
|
|
@ -500,179 +500,6 @@ SV_TestEntityPosition (edict_t *ent)
|
|||
return NULL;
|
||||
}
|
||||
|
||||
/* LINE TESTING IN HULLS */
|
||||
|
||||
// 1/32 epsilon to keep floating point happy
|
||||
#define DIST_EPSILON (0.03125)
|
||||
|
||||
typedef struct {
|
||||
vec3_t backpt;
|
||||
int side;
|
||||
int num;
|
||||
mplane_t *plane;
|
||||
} tracestack_t;
|
||||
|
||||
static inline void
|
||||
calc_impact (trace_t *trace, const vec3_t start, const vec3_t end,
|
||||
const mplane_t *plane)
|
||||
{
|
||||
vec_t t1, t2, frac, offset;
|
||||
vec3_t dist;
|
||||
|
||||
t1 = PlaneDiff (start, plane);
|
||||
t2 = PlaneDiff (end, plane);
|
||||
offset = 0;
|
||||
if (trace->isbox) {
|
||||
if (plane->type < 3)
|
||||
offset = trace->extents[plane->type];
|
||||
else
|
||||
offset = (fabs (trace->extents[0] * plane->normal[0])
|
||||
+ fabs (trace->extents[1] * plane->normal[1])
|
||||
+ fabs (trace->extents[2] * plane->normal[2]));
|
||||
}
|
||||
|
||||
if (t1 < 0) {
|
||||
frac = (t1 + DIST_EPSILON) / (t1 - t2);
|
||||
// invert plane parameters;
|
||||
VectorNegate (plane->normal, trace->plane.normal);
|
||||
trace->plane.dist = -plane->dist;
|
||||
} else {
|
||||
frac = (t1 - DIST_EPSILON) / (t1 - t2);
|
||||
VectorCopy (plane->normal, trace->plane.normal);
|
||||
trace->plane.dist = plane->dist;
|
||||
}
|
||||
frac = bound (0, frac, 1);
|
||||
trace->fraction = frac;
|
||||
VectorSubtract (end, start, dist);
|
||||
VectorMultAdd (start, frac, dist, trace->endpos);
|
||||
}
|
||||
|
||||
|
||||
static qboolean
|
||||
SV_RecursiveHullCheck (hull_t *hull, int num,
|
||||
const vec3_t start, const vec3_t end, trace_t *trace)
|
||||
{
|
||||
vec_t front, back, offset, frac, idist;
|
||||
vec3_t frontpt, backpt, dist;
|
||||
int side, empty, solid;
|
||||
tracestack_t *tstack;
|
||||
tracestack_t tracestack[256];
|
||||
dclipnode_t *node;
|
||||
mplane_t *plane, *split_plane;
|
||||
|
||||
VectorCopy (start, frontpt);
|
||||
VectorCopy (end, backpt);
|
||||
|
||||
tstack = tracestack;
|
||||
empty = 0;
|
||||
solid = 0;
|
||||
split_plane = 0;
|
||||
|
||||
while (1) {
|
||||
while (num < 0) {
|
||||
if (!solid && num != CONTENTS_SOLID) {
|
||||
empty = 1;
|
||||
if (num == CONTENTS_EMPTY)
|
||||
trace->inopen = true;
|
||||
else
|
||||
trace->inwater = true;
|
||||
} else if (!empty && num == CONTENTS_SOLID) {
|
||||
solid = 1;
|
||||
} else if (empty || solid) {
|
||||
// DONE!
|
||||
// trace->allsolid = solid & (num == CONTENTS_SOLID);
|
||||
trace->allsolid = false;
|
||||
trace->startsolid = solid;
|
||||
calc_impact (trace, start, end, split_plane);
|
||||
return false;
|
||||
}
|
||||
|
||||
// pop up the sta ck for a back side
|
||||
if (tstack-- == tracestack) {
|
||||
trace->allsolid = solid & (num == CONTENTS_SOLID);
|
||||
trace->startsolid = solid;
|
||||
return true;
|
||||
}
|
||||
|
||||
// set the hit point for this plane
|
||||
VectorCopy (backpt, frontpt);
|
||||
|
||||
// go doun the back side
|
||||
VectorCopy (tstack->backpt, backpt);
|
||||
side = tstack->side;
|
||||
split_plane = tstack->plane;
|
||||
|
||||
num = hull->clipnodes[tstack->num].children[side ^ 1];
|
||||
}
|
||||
|
||||
node = hull->clipnodes + num;
|
||||
plane = hull->planes + node->planenum;
|
||||
|
||||
offset = 0;
|
||||
front = PlaneDiff (frontpt, plane);
|
||||
back = PlaneDiff (backpt, plane);
|
||||
if (trace->isbox) {
|
||||
if (plane->type < 3)
|
||||
offset = trace->extents[plane->type];
|
||||
else
|
||||
offset = (fabs (trace->extents[0] * plane->normal[0])
|
||||
+ fabs (trace->extents[1] * plane->normal[1])
|
||||
+ fabs (trace->extents[2] * plane->normal[2]));
|
||||
}
|
||||
|
||||
// when offset is 0, the following is equivalent to:
|
||||
// if (front >= 0 && back >= 0) ...
|
||||
// if (front < 0 && back < 0) ...
|
||||
// due to the order of operations
|
||||
// however, when (front == offset && back == offset) or
|
||||
// (front == -offset && back == -offset), the trace will go down
|
||||
// the /correct/ side of the plane: ie, the side the box is actually
|
||||
// on
|
||||
if (front >= offset && back >= offset) {
|
||||
num = node->children[0];
|
||||
continue;
|
||||
}
|
||||
if (front <= -offset && back <= -offset) {
|
||||
num = node->children[1];
|
||||
continue;
|
||||
}
|
||||
if (front >= offset || front <= -offset
|
||||
|| back >= offset || back <= -offset) {
|
||||
// either:
|
||||
// back is guaranteed to be < offset or > -offset
|
||||
// or
|
||||
// front is guaranteed to be < offset or > -offset
|
||||
// so splitting is needed, on the offset plane closes to front
|
||||
side = front < back;
|
||||
idist = 1.0 / (front - back);
|
||||
if (front < 0) {
|
||||
frac = (front + offset) * idist;
|
||||
} else {
|
||||
frac = (front - offset) * idist;
|
||||
}
|
||||
frac = bound (0, frac, 1);
|
||||
} else {
|
||||
// both:
|
||||
// front is guaranteed to be < offset and > -offset
|
||||
// and
|
||||
// back is guaranteed to be < offset and > -offset
|
||||
frac = 1;
|
||||
side = front < back;
|
||||
}
|
||||
|
||||
tstack->num = num;
|
||||
tstack->side = side;
|
||||
tstack->plane = plane;
|
||||
VectorCopy (backpt, tstack->backpt);
|
||||
tstack++;
|
||||
|
||||
VectorSubtract (backpt, frontpt, dist);
|
||||
VectorMultAdd (frontpt, frac, dist, backpt);
|
||||
|
||||
num = node->children[side];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
SV_ClipMoveToEntity
|
||||
|
@ -704,7 +531,7 @@ SV_ClipMoveToEntity (edict_t *touched, edict_t *mover, const vec3_t start,
|
|||
VectorSubtract (end, offset, end_l);
|
||||
|
||||
// trace a line through the apropriate clipping hull
|
||||
SV_RecursiveHullCheck (hull, hull->firstclipnode, start_l, end_l, &trace);
|
||||
MOD_TraceLine (hull, hull->firstclipnode, start_l, end_l, &trace);
|
||||
|
||||
// fix trace up by the offset
|
||||
if (trace.fraction != 1)
|
||||
|
|
Loading…
Reference in a new issue