Move the start point to the near side of the crossed plane.

I'm not sure the end point needs to be moved at all, but I'll leave it
alone for now. I have a couple of failing test cases that seem to be caused
by not handling moves where the box is always cut by the plane.
This commit is contained in:
Bill Currie 2011-11-12 20:42:44 +09:00
parent fa6390a46a
commit 8cc320b7ef
2 changed files with 53 additions and 8 deletions

View file

@ -145,6 +145,37 @@ hull_t hull_step1 = {
{0, 0, 0}, {0, 0, 0},
}; };
// 2
// eee|eee
// 0,32+--- 1
// eee|sss
// ---+--- 0
// ss0,0ss
mclipnode_t clipnodes_covered_step[] = {
{ 0, { 1, CONTENTS_SOLID}},
{ 1, { 3, 2}},
{ 2, {CONTENTS_SOLID, CONTENTS_EMPTY}},
{ 3, {CONTENTS_EMPTY, 4}},
{ 4, {CONTENTS_SOLID, CONTENTS_EMPTY}},
};
mplane_t planes_covered_step[] = {
{{0, 0, 1}, 0, 2, 0},
{{0, 0, 1}, 32, 2, 0},
{{1, 0, 0}, 0, 0, 0},
{{1, 0, 0}, -20, 0, 0},
{{0, 0, 1}, 40, 2, 0},
};
hull_t hull_covered_step = {
clipnodes_covered_step,
planes_covered_step,
0,
4,
{0, 0, 0},
{0, 0, 0},
};
typedef struct { typedef struct {
vec3_t extents; vec3_t extents;
} box_t; } box_t;
@ -217,6 +248,19 @@ test_t tests[] = {
// 136 is a corner case caused by back/front side issues and 0 // 136 is a corner case caused by back/front side issues and 0
{"Box, Step 1", &box, &hull_step1, {"Box, Step 1", &box, &hull_step1,
{ -16, 0, 8}, {16, 0, 137}, { 1, 0, 0, 1, 0}}, { -16, 0, 8}, {16, 0, 137}, { 1, 0, 0, 1, 0}},
{"Point, Covered Step", &point, &hull_covered_step,
{ -24, 0, 8}, {-24, 0, 72}, { 0.5, 0, 0, 1, 0}},
{"Box, Covered Step", &box, &hull_covered_step,
{ -32, 0, 8}, {-32, 0, 72}, { 0.375, 0, 0, 1, 0}},
{"Box, Covered Step", &box, &hull_covered_step,
{ -24, 0, 8}, {-24, 0, 72}, { 0.375, 0, 0, 1, 0}},
{"Box, Covered Step", &box, &hull_covered_step,
{ -24, 0, 8}, {8, 0, 72}, { 0.375, 0, 0, 1, 0}},
// {"Box, Covered Step", &box, &hull_covered_step,
// { -16, 0, 8}, {0, 0, 72}, { 1, 0, 0, 1, 0}},
{"Box, Covered Step", &box, &hull_covered_step,
{ -8, 0, 40}, {8, 0, 72}, { 1, 0, 0, 1, 0}},
}; };
#define num_tests (sizeof (tests) / sizeof (tests[0])) #define num_tests (sizeof (tests) / sizeof (tests[0]))

View file

@ -55,6 +55,7 @@ static __attribute__ ((used)) const char rcsid[] =
#endif #endif
typedef struct { typedef struct {
vec3_t start;
vec3_t end; vec3_t end;
int side; int side;
int num; int num;
@ -120,7 +121,7 @@ MOD_TraceLine (hull_t *hull, int num,
const vec3_t start_point, const vec3_t end_point, const vec3_t start_point, const vec3_t end_point,
trace_t *trace) trace_t *trace)
{ {
vec_t start_dist, end_dist, frac, offset; vec_t start_dist, end_dist, frac[2], offset;
vec3_t start, end, dist; vec3_t start, end, dist;
int side; int side;
qboolean seen_empty, seen_solid; qboolean seen_empty, seen_solid;
@ -177,7 +178,7 @@ MOD_TraceLine (hull_t *hull, int num,
} }
// set the hit point for this plane // set the hit point for this plane
VectorCopy (end, start); VectorCopy (end, tstack->start);
// go down the back side // go down the back side
VectorCopy (tstack->end, end); VectorCopy (tstack->end, end);
@ -208,11 +209,10 @@ MOD_TraceLine (hull_t *hull, int num,
// cross the plane // cross the plane
side = start_dist < 0; side = start_dist < 0;
if (side) frac[0] = (start_dist + offset) / (start_dist - end_dist);
frac = (start_dist - offset) / (start_dist - end_dist); frac[1] = (start_dist - offset) / (start_dist - end_dist);
else frac[0] = bound (0, frac[0], 1);
frac = (start_dist + offset) / (start_dist - end_dist); frac[1] = bound (0, frac[1], 1);
frac = bound (0, frac, 1);
tstack->num = num; tstack->num = num;
tstack->side = side; tstack->side = side;
@ -221,7 +221,8 @@ MOD_TraceLine (hull_t *hull, int num,
tstack++; tstack++;
VectorSubtract (end, start, dist); VectorSubtract (end, start, dist);
VectorMultAdd (start, frac, dist, end); VectorMultAdd (start, frac[side], dist, end);
VectorMultAdd (start, frac[side ^ 1], dist, tstack->start);
num = node->children[side]; num = node->children[side];
} }