From 66dffef936e084b5f3f94b43198f69ab9d5b60aa Mon Sep 17 00:00:00 2001 From: Bill Currie Date: Wed, 7 Dec 2011 15:31:33 +0900 Subject: [PATCH] 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). --- libs/models/test/testclip.c | 7 +++++-- libs/models/trace.c | 20 ++++++++++++++------ 2 files changed, 19 insertions(+), 8 deletions(-) diff --git a/libs/models/test/testclip.c b/libs/models/test/testclip.c index 4b560c2f8..d7d4db31d 100644 --- a/libs/models/test/testclip.c +++ b/libs/models/test/testclip.c @@ -44,8 +44,9 @@ typedef struct { } expect; } test_t; -box_t point = { {0, 0, 0} }; -box_t box = { {8, 8, 8} }; +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])) diff --git a/libs/models/trace.c b/libs/models/trace.c index a3e66dc21..398dc9857 100644 --- a/libs/models/trace.c +++ b/libs/models/trace.c @@ -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; - lstate.split_plane = plane; - f = box_portal_dist (hull, portal, &lstate); 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) + && l->test_count != test_count) { f = trace_to_leaf (hull, l, trace, state, 0); - if (f > 0) { + } else { + lstate.split_plane = plane; + f = box_portal_dist (hull, portal, &lstate); + } + if (f >= 0) { clipped = true; if (f < frac) frac = f;