Get trace_to_leaf working a little better.

I think the recursion decision needs a little more work, but this gets the
current tests working (though there's still a failure due to fp math).
This commit is contained in:
Bill Currie 2011-12-07 15:31:33 +09:00
parent ccbc69a7f5
commit 66dffef936
2 changed files with 19 additions and 8 deletions

View file

@ -46,6 +46,7 @@ typedef struct {
box_t point = { { 0, 0, 0} };
box_t box = { { 8, 8, 8} };
box_t bigbox = { { 8, 8, 24} };
box_t player = { {16, 16, 28} };
test_t tests[] = {
@ -195,6 +196,8 @@ test_t tests[] = {
{ 54, 0, -16}, { 54, 0, 56}, { 0.5, 0, 1, 1, 0, 14}},
{"Box, cave", &box, &hull_cave,
{ 54, 0, 12}, { 54, 0, 28}, { 0.5, 0, 0, 1, 0, 14}},
{"Big Box, cave. start solid", &bigbox, &hull_cave,
{ 54, 0, 0}, { 54, 0, 8}, { 0.5, 0, 1, 1, 0, 14}},
};
#define num_tests (sizeof (tests) / sizeof (tests[0]))

View file

@ -667,10 +667,10 @@ trace_to_leaf (const hull_t *hull, clipleaf_t *leaf,
const trace_t *trace, const trace_state_t *state, vec3_t stop)
{
clipport_t *portal;
plane_t *plane;
int side;
vec_t frac = 1;
plane_t *plane;
vec_t f;
vec_t t1, t2, offset, f;
qboolean clipped = false;
clipleaf_t *l;
trace_state_t lstate = *state;
@ -684,13 +684,21 @@ trace_to_leaf (const hull_t *hull, clipleaf_t *leaf,
if (!trace_hits_portal (hull, trace, portal,
state->start_point, state->dist))
continue;
l = portal->leafs[side^1];
if (l->test_count == test_count)
continue;
t1 = PlaneDiff (state->start_point, plane);
t2 = PlaneDiff (state->end_point, plane);
offset = calc_offset (trace, plane);
f = (t1 + (t1 < 0 ? offset : -offset)) / (t1 - t2);
if (f < 0 && l->contents != CONTENTS_SOLID
&& l->test_count != test_count) {
f = trace_to_leaf (hull, l, trace, state, 0);
} else {
lstate.split_plane = plane;
f = box_portal_dist (hull, portal, &lstate);
l = portal->leafs[side^1];
if (f < 0 && l->contents != CONTENTS_SOLID
&& l->test_count != test_count)
f = trace_to_leaf (hull, l, trace, state, 0);
if (f > 0) {
}
if (f >= 0) {
clipped = true;
if (f < frac)
frac = f;