Add some snug-fit tests and fix the uncovered bugs.

The tests involve the box fitting into a hole with zero slop (this would be
impossible with point clipping).
This commit is contained in:
Bill Currie 2011-11-28 19:07:00 +09:00
parent 985667ecba
commit 50b08c98fa
2 changed files with 68 additions and 7 deletions

View file

@ -265,6 +265,39 @@ hull_t hull_ramp = {
{0, 0, 0},
};
// 2 1
// ss|sss|ss
// ss+-3-+ss 8
// ss|eee|ss
// ss+-4-+ss -8
// ss|sss|ss
// -8 8
// looking at plane 0: back of 0 is empty, front of 0 has above hole
mclipnode_t clipnodes_hole[] = {
{ 0, { 1, CONTENTS_EMPTY}},
{ 1, {CONTENTS_SOLID, 2}},
{ 2, { 3, CONTENTS_SOLID}},
{ 3, {CONTENTS_SOLID, 4}},
{ 4, {CONTENTS_EMPTY, CONTENTS_SOLID}},
};
plane_t planes_hole[] = {
{{ 0, 1, 0}, 0, 1, 0},
{{ 1, 0, 0}, 8, 0, 0},
{{ 1, 0, 0}, -8, 0, 0},
{{ 0, 0, 1}, 8, 2, 0},
{{ 0, 0, 1}, -8, 2, 0},
};
hull_t hull_hole = {
clipnodes_hole,
planes_hole,
0,
4,
{0, 0, 0},
{0, 0, 0},
};
typedef struct {
vec3_t extents;
@ -378,6 +411,27 @@ test_t tests[] = {
{-16, 0, 5}, {16, 0, 5}, { 0.25, 0, 0, 1, 0, 3}},
{"Box, Simple Wedge", &box, &hull_simple_wedge,
{-16, 0, 12}, {16, 0, 4}, { 0.5, 0, 0, 1, 0, 3}},
{"Box, Hole. slide in", &box, &hull_hole,
{ 0, -16, 0}, { 0, 16, 0}, { 1, 0, 0, 1, 0, 13}},
{"Box, Hole. slide out", &box, &hull_hole,
{ 0, 16, 0}, { 0, -16, 0}, { 1, 0, 0, 1, 0, 13}},
{"Box, Hole. tight", &box, &hull_hole,
{ 0, 16, 0}, { 0, 16, 16}, { 0, 0, 0, 1, 0, 13}},
{"Box, Hole. tight", &box, &hull_hole,
{ 0, 16, 0}, { 0, 16, -16}, { 0, 0, 0, 1, 0, 13}},
{"Box, Hole. tight", &box, &hull_hole,
{ 0, 16, 0}, { 16, 16, 0}, { 0, 0, 0, 1, 0, 13}},
{"Box, Hole. tight", &box, &hull_hole,
{ 0, 16, 0}, {-16, 16, 0}, { 0, 0, 0, 1, 0, 13}},
{"Box, Hole. edge", &box, &hull_hole,
{ 0, -16, 1}, { 0, 16, 1}, { 0.25, 0, 0, 1, 0, 13}},
{"Box, Hole. edge", &box, &hull_hole,
{ 0, -16, -1}, { 0, 16, -1}, { 0.25, 0, 0, 1, 0, 13}},
{"Box, Hole. edge", &box, &hull_hole,
{ 1, -16, 0}, { 1, 16, 0}, { 0.25, 0, 0, 1, 0, 13}},
{"Box, Hole. edge", &box, &hull_hole,
{-1, -16, 0}, { -1, 16, 0}, { 0.25, 0, 0, 1, 0, 13}},
};
#define num_tests (sizeof (tests) / sizeof (tests[0]))

View file

@ -97,7 +97,6 @@ check_in_leaf (hull_t *hull, trace_t *trace, clipleaf_t *leaf, plane_t *plane,
{
clipport_t *portal;
int side;
int miss = 0;
int i;
int planenum;
plane_t cutplane;
@ -107,12 +106,17 @@ check_in_leaf (hull_t *hull, trace_t *trace, clipleaf_t *leaf, plane_t *plane,
planenum = plane - hull->planes;
cutplane.type = 3; // generic plane
v_n = DotProduct (vel, plane->normal);
if (!v_n) {
//FIXME is this correct? The assumption is that if we got to a leaf
//travelliing parallel to its plane, then we have to be in the leaf
return 1;
}
for (portal = leaf->portals; portal; portal = portal->next[side]) {
side = portal->leafs[1] == leaf;
if (portal->planenum != planenum)
continue;
for (i = 0; !miss && i < portal->winding->numpoints; i++) {
for (i = 0; i < portal->winding->numpoints; i++) {
point = portal->winding->points[i];
edge = portal->edges->points[i];
// so long as the plane distance and offset are calculated using
@ -122,12 +126,15 @@ check_in_leaf (hull_t *hull, trace_t *trace, clipleaf_t *leaf, plane_t *plane,
cutplane.dist = DotProduct (cutplane.normal, point);
dist = PlaneDiff (org, &cutplane);
offset = calc_offset (trace, &cutplane);
if (v_n >= 0)
miss = dist >= offset;
else
miss = dist <= -offset;
if (v_n > 0) {
if (dist >= offset)
break;
} else {
if (dist <= -offset)
break;
}
if (!miss)
}
if (i == portal->winding->numpoints)
return 1;
}
return 0;