more tests, more progress. just need to fix a regression that popped up while fixing the new test (18)

This commit is contained in:
Bill Currie 2009-03-22 00:31:44 +00:00 committed by Jeff Teunissen
parent dd27143f62
commit a26cd68ea9
2 changed files with 116 additions and 17 deletions

View file

@ -154,6 +154,66 @@ hull_t hull3 = {
{0, 0, 0}, {0, 0, 0},
}; };
dclipnode_t clipnodes4[] = {
{0, {1, 25}}, // 0
{1, {-1, 2}}, // 1
{2, {3, 11}}, // 2
{3, {4, -1}}, // 3
{4, {5, 8}}, // 4
{5, {-1, 6}}, // 5
{6, {-1, 7}}, // 6
{7, {-1, -2}}, // 7
{5, {-1, 9}}, // 8
{8, {10, -1}}, // 9
{7, {-1, -2}}, // 10
{9, {12, 17}}, // 11
{4, {13, 15}}, // 12
{6, {-1, 14}}, // 13
{7, {-1, -2}}, // 14
{7, {-1, 16}}, // 15
{8, {-2, -1}}, // 16
{10, {-1, 18}}, // 17
{4, {19, 22}}, // 18
{11, {20, -1}}, // 19
{6, {-1, 21}}, // 20
{7, {-1, -2}}, // 21
{11, {23, -1}}, // 22
{7, {-1, 24}}, // 23
{8, {-2, -1}}, // 24
{11, {26, -1}}, // 25
{5, {-1, 27}}, // 26
{12, {28, -1}}, // 27
{13, {-1, 29}}, // 28
{14, {-2, -1}}, // 29
};
mplane_t planes4[] = {
{{0, 1, 0}, 832, 1, 0, {0, 0}}, // 0
{{0, 1, 0}, 1216, 1, 0, {0, 0}}, // 1
{{1, 0, 0}, 608, 0, 0, {0, 0}}, // 2
{{1, 0, 0}, 624, 0, 0, {0, 0}}, // 3
{{0, 0, 1}, -40, 2, 0, {0, 0}}, // 4
{{1, 0, 0}, 672, 0, 0, {0, 0}}, // 5
{{0, 0, 1}, -24, 2, 0, {0, 0}}, // 6
{{0, -0.242536, 0.970142}, -256.118, 5, 0, {0, 0}}, // 7
{{-0, -0.242536, 0.970142}, -271.64, 5, 0, {0, 0}}, // 8
{{1, 0, 0}, 480, 0, 0, {0, 0}}, // 9
{{1, 0, 0}, 464, 0, 0, {0, 0}}, // 10
{{1, 0, 0}, 416, 0, 0, {0, 0}}, // 11
{{0, 1, 0}, 768, 1, 0, {0, 0}}, // 12
{{0, 0, 1}, -64, 2, 0, {0, 0}}, // 13
{{0, 0, 1}, -80, 2, 0, {0, 0}}, // 14
};
hull_t hull4 = {
clipnodes4,
planes4,
0,
6,
{0, 0, 0},
{0, 0, 0},
};
typedef struct { typedef struct {
const char *desc; const char *desc;
hull_t *hull; hull_t *hull;
@ -216,6 +276,9 @@ test_t tests[] = {
&hull3, {480, -208.873, 77}, {468, -208.873, 75}, {0.5, 0, 0, 1, 0}}, &hull3, {480, -208.873, 77}, {468, -208.873, 75}, {0.5, 0, 0, 1, 0}},
{"diagonal drop onto top of ramp: hull3", {"diagonal drop onto top of ramp: hull3",
&hull3, {480, -208.873, 77}, {468, -207.977, 75}, {0.5, 0, 0, 1, 0}}, &hull3, {480, -208.873, 77}, {468, -207.977, 75}, {0.5, 0, 0, 1, 0}},
{"drop onto thin bridge",
&hull4, {544, 1080, 5}, {544, 1080, 3}, {0.5, 0, 0, 1, 0}},
}; };
const int num_tests = sizeof (tests) / sizeof (tests[0]); const int num_tests = sizeof (tests) / sizeof (tests[0]);

View file

@ -96,6 +96,7 @@ typedef struct {
qboolean isbox; qboolean isbox;
hull_t hull; hull_t hull;
tp_t split; tp_t split;
tp_t straddle;
tp_t impact; tp_t impact;
float fraction; float fraction;
int flags; int flags;
@ -116,6 +117,21 @@ restore_split (tl_t *tl, tp_t *s)
tl->split = *s; tl->split = *s;
} }
static inline void
set_straddle (tl_t *tl, mplane_t *plane, int side, tp_t *s)
{
if (s)
*s = tl->straddle;
tl->straddle.plane = plane;
tl->straddle.side = side;
}
static inline void
restore_straddle (tl_t *tl, tp_t *s)
{
tl->straddle = *s;
}
static inline void static inline void
set_impact (tl_t *tl, mplane_t *plane, int side) set_impact (tl_t *tl, mplane_t *plane, int side)
{ {
@ -242,7 +258,7 @@ validate_impact (tp_t *split, tl_t *tl)
} while (0) } while (0)
static int static int
validate_solid (const vec3_t p, tp_t *wall, tp_t *split, tl_t *tl) validate_solid (const vec3_t p, tp_t *wall, tp_t *straddle, tl_t *tl)
{ {
static const vec3_t edges[][2] = { static const vec3_t edges[][2] = {
{{ 1, -1, 1}, { 1, 1, 1}}, {{ 1, -1, 1}, { 1, 1, 1}},
@ -270,9 +286,26 @@ validate_solid (const vec3_t p, tp_t *wall, tp_t *split, tl_t *tl)
int type = wall->plane->type; int type = wall->plane->type;
int i; int i;
if (!split->plane) if (!straddle->plane)
return 1; return 1;
for (i = 0; i < 4; i++) {
set_point (p, edges[i + 4][0], tl->extents, p1);
t1 = PlaneDiff (p1, wall->plane);
if ((t1 < 0) == wall->side) {
t = PlaneDiff (p1, straddle->plane);
if ((t < 0) == straddle->side)
return 1;
}
set_point (p, edges[i + 4][1], tl->extents, p2);
t2 = PlaneDiff (p2, wall->plane);
if ((t2 < 0) == wall->side) {
t = PlaneDiff (p2, straddle->plane);
if ((t < 0) == straddle->side)
return 1;
}
}
if (type >= 3) { if (type >= 3) {
// don't trust multi-axial types // don't trust multi-axial types
if (!wall->plane->normal[0]) if (!wall->plane->normal[0])
@ -303,20 +336,20 @@ validate_solid (const vec3_t p, tp_t *wall, tp_t *split, tl_t *tl)
VectorSubtract (p2, p1, dist); VectorSubtract (p2, p1, dist);
VectorMultAdd (p1, frac, dist, point); VectorMultAdd (p1, frac, dist, point);
t = PlaneDiff (point, split->plane); t = PlaneDiff (point, straddle->plane);
side = t < 0; side = t < 0;
if (side == split->side) if (!t || side == straddle->side)
return 1; return 1;
} }
#if 0 #if 0
Sys_Printf ("\nsolid: (%g %g %g) (%g %g %g) %d %d\n", Sys_Printf ("\nsolid: (%g %g %g) (%g %g %g) %d %d\n",
point[0], point[1], point[2], point[0], point[1], point[2],
offs[0], offs[1], offs[2], offs[0], offs[1], offs[2],
side, split->side); side, straddle->side);
print_tp (*wall); print_tp (*wall);
print_tp (*split); print_tp (*straddle);
#endif #endif
return 0; return 0;
} }
@ -359,23 +392,25 @@ traceline (int num, float p1f, float p2f, const vec3_t p1, const vec3_t p2,
// if (t1 == t2) { // if (t1 == t2) {
if (t1 >= -offset && t1 < offset && t2 >= -offset && t2 < offset) { if (t1 >= -offset && t1 < offset && t2 >= -offset && t2 < offset) {
set_split (tl, plane, 0, &split); tp_t straddle;
set_straddle (tl, plane, 0, &straddle);
c1 = c2 = traceline (node->children[0], p1f, p2f, p1, p2, tl); c1 = c2 = traceline (node->children[0], p1f, p2f, p1, p2, tl);
if (c1 == CONTENTS_SOLID) { if (c1 == CONTENTS_SOLID) {
if (!validate_solid (p1, &tl->split, &split, tl)) if (!validate_solid (p1, &tl->straddle, &straddle, tl))
c1 = CONTENTS_EMPTY; c1 = CONTENTS_EMPTY;
} else { } else {
if (tl->impact.plane) if (tl->impact.plane)
validate_impact (&tl->split, tl); validate_impact (&tl->straddle, tl);
} }
if (c1 != CONTENTS_SOLID) { if (c1 != CONTENTS_SOLID) {
set_split (tl, plane, 1, 0); set_straddle (tl, plane, 1, 0);
c2 = traceline (node->children[1], p1f, p2f, p1, p2, tl); c2 = traceline (node->children[1], p1f, p2f, p1, p2, tl);
if (c2 == CONTENTS_SOLID && !validate_solid (p1, &tl->split, if (c2 == CONTENTS_SOLID && !validate_solid (p1, &tl->straddle,
&split, tl)) &straddle, tl))
c2 = CONTENTS_EMPTY; c2 = CONTENTS_EMPTY;
} }
restore_split (tl, &split); restore_straddle (tl, &straddle);
if (c1 == CONTENTS_SOLID || c2 == CONTENTS_SOLID) { if (c1 == CONTENTS_SOLID || c2 == CONTENTS_SOLID) {
if (!p1f) { if (!p1f) {
tl->flags &= 3; tl->flags &= 3;
@ -396,12 +431,12 @@ traceline (int num, float p1f, float p2f, const vec3_t p1, const vec3_t p2,
} else { } else {
if (t1 < t2) { if (t1 < t2) {
side = 1; side = 1;
frac = (t1 + offset) / (t1 - t2);
frac2 = (t1 - offset) / (t1 - t2);
} else /*if (t1 > t2)*/ {
side = 0;
frac = (t1 - offset) / (t1 - t2); frac = (t1 - offset) / (t1 - t2);
frac2 = (t1 + offset) / (t1 - t2); frac2 = (t1 + offset) / (t1 - t2);
} else /*if (t1 > t2)*/ {
side = 0;
frac = (t1 + offset) / (t1 - t2);
frac2 = (t1 - offset) / (t1 - t2);
} }
frac = bound (0, frac, 1); frac = bound (0, frac, 1);
@ -450,6 +485,7 @@ MOD_TraceLine (hull_t *hull, int num,
tl.hull = *hull; tl.hull = *hull;
tl.fraction = 1; tl.fraction = 1;
set_split (&tl, 0, 0, 0); set_split (&tl, 0, 0, 0);
set_straddle (&tl, 0, 0, 0);
set_impact (&tl, 0, 0); set_impact (&tl, 0, 0);
tl.flags = 1; tl.flags = 1;
tl.isbox = trace->isbox; tl.isbox = trace->isbox;