From 0cf5dec5bb6ac6f3d1760a2cb641c7ecf87bbdc8 Mon Sep 17 00:00:00 2001 From: Bill Currie Date: Sat, 12 Nov 2011 21:30:45 +0900 Subject: [PATCH] Fix the covered step tests. However, there is still a problem with moves where the box is always cut by the plane: both sides need to be tested (done), but when the first side checked allows longer motion than the second, but still collides, only the first side is checked. The shorter motion is required. --- libs/models/test/testclip.c | 71 ++++++++++++++++++++++++++++++++++--- libs/models/trace.c | 17 ++++++--- 2 files changed, 79 insertions(+), 9 deletions(-) diff --git a/libs/models/test/testclip.c b/libs/models/test/testclip.c index ea07463cc..3cab3011c 100644 --- a/libs/models/test/testclip.c +++ b/libs/models/test/testclip.c @@ -145,10 +145,66 @@ hull_t hull_step1 = { {0, 0, 0}, }; -// 2 +// 0 // eee|eee // 0,32+--- 1 // eee|sss +// ---+sss 2 +// ss0,0ss +mclipnode_t clipnodes_step2[] = { + { 0, { 1, 2}}, + { 1, {CONTENTS_EMPTY, CONTENTS_SOLID}}, + { 2, {CONTENTS_EMPTY, CONTENTS_SOLID}}, +}; + +mplane_t planes_step2[] = { + {{1, 0, 0}, 0, 0, 0}, + {{0, 0, 1}, 32, 2, 0}, + {{0, 0, 1}, 0, 2, 0}, +}; + +hull_t hull_step2 = { + clipnodes_step2, + planes_step2, + 0, + 2, + {0, 0, 0}, + {0, 0, 0}, +}; + +// 0 +// eee|eee +// 2---+0,32 +// sss|eee +// sss+--- 1 +// ss0,0ss +mclipnode_t clipnodes_step3[] = { + { 0, { 1, 2}}, + { 1, {CONTENTS_EMPTY, CONTENTS_SOLID}}, + { 2, {CONTENTS_EMPTY, CONTENTS_SOLID}}, +}; + +mplane_t planes_step3[] = { + {{1, 0, 0}, 0, 0, 0}, + {{0, 0, 1}, 0, 2, 0}, + {{0, 0, 1}, 32, 2, 0}, +}; + +hull_t hull_step3 = { + clipnodes_step3, + planes_step3, + 0, + 2, + {0, 0, 0}, + {0, 0, 0}, +}; + +// 3 2 +// s|e|eee +// 4-+e|-20,40 +// e|e|eee +// 0,32+--- 1 +// eee|sss // ---+--- 0 // ss0,0ss mclipnode_t clipnodes_covered_step[] = { @@ -256,11 +312,18 @@ test_t tests[] = { {"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}}, + { -25, 0, 8}, {7, 0, 72}, { 0.375, 0, 0, 1, 0}}, + {"Box, Covered Step", &box, &hull_covered_step, + { -8, 0, 40}, {-16, 0, 40}, { 0.5, 0, 0, 1, 0}}, + {"Box, Covered Step", &box, &hull_covered_step, + { -17, 0, 8}, {-1, 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}}, + + {"Box, Step 2", &box, &hull_step2, + { 0, 0, 64}, {0, 0, 0}, { 0.375, 0, 0, 1, 0}}, + {"Box, Step 3", &box, &hull_step3, + { 0, 0, 64}, {0, 0, 0}, { 0.375, 0, 0, 1, 0}}, }; #define num_tests (sizeof (tests) / sizeof (tests[0])) diff --git a/libs/models/trace.c b/libs/models/trace.c index 6fcb20eaf..16e7e5944 100644 --- a/libs/models/trace.c +++ b/libs/models/trace.c @@ -208,11 +208,18 @@ MOD_TraceLine (hull_t *hull, int num, // cross the plane - side = start_dist < 0; - frac[0] = (start_dist + offset) / (start_dist - end_dist); - frac[1] = (start_dist - offset) / (start_dist - end_dist); - frac[0] = bound (0, frac[0], 1); - frac[1] = bound (0, frac[1], 1); + if (start_dist < offset && end_dist < offset + && start_dist >= -offset && end_dist >= end_dist) { + side = 0; + frac[0] = 1; + frac[1] = 0; + } else { + side = start_dist < offset; + frac[0] = (start_dist + offset) / (start_dist - end_dist); + frac[1] = (start_dist - offset) / (start_dist - end_dist); + frac[0] = bound (0, frac[0], 1); + frac[1] = bound (0, frac[1], 1); + } tstack->num = num; tstack->side = side;