Clean up FindSeparators a little bit.

This was testing an idea I had to remove the plane flips. It seems to have
been good for the initial plane orientation, but was a slight slowdown for
the pass-portal test. However, this makes the code a little easier to work
with for my idea on improving the algorithm itself.
This commit is contained in:
Bill Currie 2013-03-17 10:16:47 +09:00
parent 5dba419233
commit 1d262f7dea

View file

@ -112,6 +112,16 @@ free_separators (threaddata_t *thread, sep_t *sep_list)
} }
} }
static inline int
test_zero (float d)
{
if (d < -ON_EPSILON)
return -1;
else if (d > ON_EPSILON)
return 1;
return 0;
}
/* /*
Find the planes separating source from pass. The planes form a double Find the planes separating source from pass. The planes form a double
pyramid with source as the base (ie, source's edges will all be in one pyramid with source as the base (ie, source's edges will all be in one
@ -131,7 +141,7 @@ FindSeparators (threaddata_t *thread, winding_t *source, const plane_t src_pl,
float d; float d;
int i, j, k, l; int i, j, k, l;
int count; int count;
qboolean fliptest; int fliptest;
plane_t plane; plane_t plane;
vec3_t v1, v2; vec3_t v1, v2;
vec_t length; vec_t length;
@ -147,16 +157,12 @@ FindSeparators (threaddata_t *thread, winding_t *source, const plane_t src_pl,
// source on the back side // source on the back side
for (j = 0; j < pass->numpoints; j++) { for (j = 0; j < pass->numpoints; j++) {
d = DotProduct (pass->points[j], src_pl.normal) - src_pl.dist; d = DotProduct (pass->points[j], src_pl.normal) - src_pl.dist;
if (d < -ON_EPSILON) if ((fliptest = test_zero (d)) == 0)
fliptest = true;
else if (d > ON_EPSILON)
fliptest = false;
else
continue; // The point lies in the source plane continue; // The point lies in the source plane
VectorSubtract (pass->points[j], source->points[i], v2); VectorSubtract (pass->points[j], source->points[i], v2);
if (fliptest) { if (fliptest < 0) {
//CrossProduct (v2, v1, plane.normal); //CrossProduct (v2, v1, plane.normal);
plane.normal[0] = v2[1] * v1[2] - v2[2] * v1[1]; plane.normal[0] = v2[1] * v1[2] - v2[2] * v1[1];
plane.normal[1] = v2[2] * v1[0] - v2[0] * v1[2]; plane.normal[1] = v2[2] * v1[0] - v2[0] * v1[2];
@ -179,12 +185,6 @@ FindSeparators (threaddata_t *thread, winding_t *source, const plane_t src_pl,
plane.dist = DotProduct (pass->points[j], plane.normal); plane.dist = DotProduct (pass->points[j], plane.normal);
// flip the normal if the source portal is backwards
//if (fliptest) {
// VectorNegate (plane.normal, plane.normal);
// plane.dist = -plane.dist;
//}
// if all of the pass portal points are now on the positive side, // if all of the pass portal points are now on the positive side,
// this is the seperating plane // this is the seperating plane
count = 0; count = 0;