still disabled since it's still broken, but progress has been made. Fortunately, some of the breakage shows up as a regression in the testcases.

This commit is contained in:
Bill Currie 2009-03-19 03:16:24 +00:00 committed by Jeff Teunissen
parent e2355aa357
commit 3be88c3e1d
2 changed files with 165 additions and 38 deletions

View file

@ -1,6 +1,6 @@
#include "world.h"
dclipnode_t clipnodes[] = {
dclipnode_t clipnodes1[] = {
{ 0, { 1, -2}},
{ 1, {-2, 2}},
{ 2, {-2, 3}},
@ -17,7 +17,7 @@ dclipnode_t clipnodes[] = {
{ 13, {-1, -2}},
};
mplane_t planes[] = {
mplane_t planes1[] = {
{{0, 1, 0}, -96, 1, 0}, // 0 wall at right
{{0, 1, 0}, 96, 1, 0}, // 1 wall at left (with ditch)
{{1, 0, 0}, 128, 0, 0}, // 2 wall at front (with shelves)
@ -34,16 +34,76 @@ mplane_t planes[] = {
{{0, 0, 1}, 8, 2, 0}, // 13 main floor
};
hull_t hull = {
clipnodes,
planes,
hull_t hull1 = {
clipnodes1,
planes1,
0,
13,
{0, 0, 0},
{0, 0, 0},
};
static void do_trace (vec3_t start, vec3_t end)
dclipnode_t clipnodes2[] = {
{0, {1, 12}}, // 0
{1, {-1, 2}}, // 1
{2, {3, 6}}, // 2
{3, {-1, 4}}, // 3
{4, {5, -1}}, // 4
{5, {-1, -2}}, // 5
{6, {7, 9}}, // 6
{7, {-1, 8}}, // 7
{4, {-2, -1}}, // 8
{8, {10, -1}}, // 9
{5, {-1, 11}}, // 10
{4, {-2, -1}}, // 11
{9, {13, 25}}, // 12
{2, {-1, 14}}, // 13
{6, {15, 19}}, // 14
{10, {-1, 16}}, // 15
{11, {17, 18}}, // 16
{7, {-1, -2}}, // 17
{4, {-2, -1}}, // 18
{11, {20, 23}}, // 19
{12, {-1, 21}}, // 20
{8, {22, -1}}, // 21
{5, {-1, -2}}, // 22
{8, {24, -1}}, // 23
{4, {-2, -1}}, // 24
{3, {-1, 26}}, // 25
{8, {27, -1}}, // 26
{11, {28, -1}}, // 27
{12, {-1, 29}}, // 28
{13, {-2, -1}}, // 29
};
mplane_t planes2[] = {
{{1, 0, 0}, 912, 0, 0, {0, 0}}, // 0 0
{{1, 0, 0}, 1168, 0, 0, {0, 0}}, // 1 1
{{0, 1, 0}, 2112, 1, 0, {0, 0}}, // 2 2 13
{{0, 1, 0}, 2128, 1, 0, {0, 0}}, // 3 3 25
{{0.229038, 0, 0.973417}, 18.3218, 5, 0, {0, 0}}, // 4 4 8 11 18 24
{{0.229038, -0, 0.973417}, 57.2585, 5, 0, {0, 0}}, // 5 5 10 22
{{0, 1, 0}, 1984, 1, 0, {0, 0}}, // 6 6 14
{{0.229039, -0, 0.973417}, 33.8978, 5, 0, {0, 0}}, // 7 7 17
{{0, 1, 0}, 1968, 1, 0, {0, 0}}, // 8 9 21 23 26
{{1, 0, 0}, 736, 0, 0, {0, 0}}, // 9 12
{{0, 0, 1}, -176, 2, 0, {0, 0}}, // 10 15
{{0, 0, 1}, -192, 2, 0, {0, 0}}, // 11 16 19 27
{{0, 0, 1}, -152, 2, 0, {0, 0}}, // 12 20 28
{{1, 0, 0}, 720, 0, 0, {0, 0}}, // 13 29
};
hull_t hull2 = {
clipnodes2,
planes2,
0,
6,
{0, 0, 0},
{0, 0, 0},
};
static void
do_trace (hull_t *hull, vec3_t start, vec3_t end)
{
trace_t trace;
@ -56,18 +116,20 @@ static void do_trace (vec3_t start, vec3_t end)
trace.extents[1] = 16;
trace.extents[2] = 28;
trace.isbox = true;
MOD_TraceLine (&hull, 0, start, end, &trace);
VectorCopy (end, trace.endpos);
MOD_TraceLine (hull, 0, start, end, &trace);
printf ("(%g %g %g) (%g %g %g) -> %3g %d %d %d %d\n",
start[0], start[1], start[2],
end[0], end[1], end[2], trace.fraction,
trace.endpos[0], trace.endpos[1], trace.endpos[2], trace.fraction,
trace.allsolid, trace.startsolid, trace.inopen, trace.inwater);
}
int main (int argc, char **argv)
int
main (int argc, char **argv)
{
vec3_t start, end;
#if 1
int i;
#if 1
puts ("\nexpect 0.496094, 1 (0 0 1 0), (0 0 1 0)");
for (i = 0; i < 2; i++) {
start[0] = 0;
@ -75,7 +137,7 @@ int main (int argc, char **argv)
start[2] = 40;
VectorCopy (start, end);
end[2] -= 8;
do_trace (start, end);
do_trace (&hull1, start, end);
}
puts ("\nexpect 0.496094, 1 (0 0 1 0), (0 0 1 0)");
@ -85,39 +147,50 @@ int main (int argc, char **argv)
start[2] = 35 + i;
VectorCopy (start, end);
end[1] -= 8;
do_trace (start, end);
do_trace (&hull1, start, end);
}
puts ("\nexpect 0.484375, 1 (0 0 1 0), (1 1 0 0)");
for (i = 0; i < 2; i++) {
start[0] = 47 + i;
start[1] = -80;
start[1] = -32;
start[2] = 36;
VectorCopy (start, end);
end[0] += 2;
do_trace (start, end);
do_trace (&hull1, start, end);
}
puts ("\nexpect 0.496094, 1 (0 0 1 0), (0 0 1 0)");
for (i = 0; i < 2; i++) {
start[0] = 44;
start[1] = -80;
start[1] = -32;
start[2] = 59 + i;
VectorCopy (start, end);
end[0] += 8;
do_trace (start, end);
do_trace (&hull1, start, end);
}
puts ("\nexpect 1, 0.499023 (0 1 1 0), (0 1 1 0)");
for (i = 0; i < 2; i++) {
start[0] = 47 + i;
start[1] = -80;
start[1] = -32;
start[2] = 76;
VectorCopy (start, end);
end[2] -= 32;
do_trace (start, end);
do_trace (&hull1, start, end);
}
#endif
puts ("\nexpect 1, 0.499023 (0 1 1 0), (0 1 1 0)");
// for (i = 0; i < 30; i++) {
i = 5;
start[0] = 891 + i;
start[1] = 2048;
start[2] = -144;
VectorCopy (start, end);
end[2] -= 8;
do_trace (&hull2, start, end);
// }
#if 1
puts ("\nexpect 0 (0 0 1 0)");
start[0] = 96;
start[1] = -47.9612;
@ -125,8 +198,8 @@ int main (int argc, char **argv)
end[0] = 96;
end[1] = -47.1025;
end[2] = 55.8737 + 4;
do_trace (start, end);
#endif
do_trace (&hull1, start, end);
puts ("\nexpect 0 (0 0 1 0)");
start[0] = 94.8916;
start[1] = -34.8506;
@ -134,6 +207,7 @@ int main (int argc, char **argv)
end[0] = 94.8146;
end[1] = -28.5696;
end[2] = 55.5683 + 4;
do_trace (start, end);
do_trace (&hull1, start, end);
#endif
return 0;
}

View file

@ -48,6 +48,8 @@ static __attribute__ ((used)) const char rcsid[] =
#include "world.h"
/* LINE TESTING IN HULLS */
//#undef DIST_EPSILON
//#define DIST_EPSILON 0
static inline void
calc_impact (trace_t *trace, const vec3_t start, const vec3_t end,
@ -92,10 +94,31 @@ typedef struct {
hull_t hull;
mplane_t *plane;
mplane_t *impact;
int impactside;
float fraction;
int flags;
} tl_t;
static inline vec_t
sgn (vec_t v)
{
return v < 0 ? -1 : (v > 0 ? 1 : -1);
}
static inline vec_t
select_point (mplane_t *split, int side, int axis, tl_t *tl)
{
vec_t s = sgn (tl->impact->normal[axis]);
if (!tl->impactside)
s = -s;
if (!s) {
s = sgn (split->normal[axis]);
if (!side)
s = -s;
}
return tl->extents[axis] * s;
}
static inline void
check_contents (int num, tl_t *tl)
{
@ -129,12 +152,16 @@ static void
impact (tl_t *tl)
{
float t1, t2, offset, frac;
int side = 0;
t1 = PlaneDiff (tl->start, tl->plane);
t2 = PlaneDiff (tl->end, tl->plane);
offset = calc_offset (tl, tl->plane);
if (t1 < t2) {
side = -1;
frac = (t1 + offset) / (t1 - t2);
} else if (t1 > t2) {
side = 0;
frac = (t1 - offset) / (t1 - t2);
} else {
frac = 0;
@ -143,6 +170,25 @@ impact (tl_t *tl)
if (frac >= 0) {
tl->fraction = frac;
tl->impact = tl->plane;
tl->impactside = side;
}
}
static void
validate_impact (mplane_t *split, int side, tl_t *tl)
{
vec3_t dist, point;
int pside;
VectorSubtract (tl->end, tl->start, dist);
VectorMultAdd (tl->start, tl->fraction, dist, point);
point[0] += select_point (split, !side, 0, tl);
point[1] += select_point (split, !side, 1, tl);
point[2] += select_point (split, !side, 2, tl);
pside = PlaneDiff (point, split) < 0;
if (pside != side) {
tl->fraction = 1;
tl->impact = 0;
}
}
@ -157,28 +203,35 @@ traceline (int num, float p1f, float p2f, const vec3_t p1, const vec3_t p2,
vec3_t mid;
int c1, c2;
while (num >= 0) {
node = tl->hull.clipnodes + num;
plane = tl->hull.planes + node->planenum;
// Skip past nodes that don't intersect with the line.
do {
// Sys_Printf ("%d\n", num);
while (num >= 0) {
node = tl->hull.clipnodes + num;
plane = tl->hull.planes + node->planenum;
t1 = PlaneDiff (p1, plane);
t2 = PlaneDiff (p2, plane);
offset = calc_offset (tl, plane);
t1 = PlaneDiff (p1, plane);
t2 = PlaneDiff (p2, plane);
offset = calc_offset (tl, plane);
if (t1 >= offset && t2 >= offset) {
num = node->children[0];
} else if (t1 < -offset && t2 < -offset) {
num = node->children[1];
} else {
break;
if (t1 >= offset && t2 >= offset) {
num = node->children[0];
} else if (t1 < -offset && t2 < -offset) {
num = node->children[1];
} else {
break;
}
// Sys_Printf ("%d\n", num);
}
}
if (num < 0)
return num;
if (num < 0)
return num;
} while (0);
// if (t1 == t2) {
if (t1 >= -offset && t1 < offset && t2 >= -offset && t2 < offset) {
c1 = c2 = traceline (node->children[0], p1f, p2f, p1, p2, tl);
if (tl->impact)
validate_impact (plane, 0, tl);
if (c1 != CONTENTS_SOLID)
c2 = traceline (node->children[1], p1f, p2f, p1, p2, tl);
if (c1 == CONTENTS_SOLID || c2 == CONTENTS_SOLID) {
@ -203,7 +256,7 @@ traceline (int num, float p1f, float p2f, const vec3_t p1, const vec3_t p2,
side = 1;
frac = (t1 - offset) / (t1 - t2);
frac2 = (t1 + offset) / (t1 - t2);
} else if (t1 > t2) {
} else /*if (t1 > t2)*/ {
side = 0;
frac = (t1 + offset) / (t1 - t2);
frac2 = (t1 - offset) / (t1 - t2);