[PATCH] qbsp: Refactor some winding clip/split code

Each of ClipWinding, DivideWinding and SplitFace need to calculate on which
side of the split plane each winding point lies. Split this operation out into
a shared function.

Signed-off-by: Tyrann <tyrann@disenchant.net>
This commit is contained in:
Tyrann 2006-10-02 19:46:43 +09:30
parent fa7e4c9671
commit 118916b825
3 changed files with 31 additions and 51 deletions

View File

@ -83,23 +83,8 @@ SplitFace(face_t *in, plane_t *split, face_t **front, face_t **back)
if (in->w.numpoints < 0)
Message(msgError, errFreedFace);
counts[0] = counts[1] = counts[2] = 0;
// determine sides for each point
for (i = 0; i < in->w.numpoints; i++) {
dot = DotProduct(in->w.points[i], split->normal);
dot -= split->dist;
dists[i] = dot;
if (dot > ON_EPSILON)
sides[i] = SIDE_FRONT;
else if (dot < -ON_EPSILON)
sides[i] = SIDE_BACK;
else
sides[i] = SIDE_ON;
counts[sides[i]]++;
}
sides[i] = sides[0];
dists[i] = dists[0];
CalcSides(&in->w, split, sides, dists, counts);
// Plane doesn't split this face after all
if (!counts[SIDE_FRONT]) {

View File

@ -317,6 +317,10 @@ void DivideWinding(winding_t *in, plane_t *split, winding_t **front,
winding_t **back);
void MidpointWinding(winding_t *w, vec3_t v);
/* Helper function for ClipWinding and it's variants */
void CalcSides(const winding_t *in, const plane_t *split, int *sides,
vec_t *dists, int counts[3]);
//============================================================================

View File

@ -125,6 +125,30 @@ CheckWinding(winding_t *w)
}
void
CalcSides(const winding_t *in, const plane_t *split, int *sides, vec_t *dists,
int counts[3])
{
int i;
const vec_t *p;
counts[0] = counts[1] = counts[2] = 0;
p = in->points[0];
for (i = 0; i < in->numpoints; i++, p += 3) {
const vec_t dist = DotProduct(split->normal, p) - split->dist;
dists[i] = dist;
if (dist > ON_EPSILON)
sides[i] = SIDE_FRONT;
else if (dist < -ON_EPSILON)
sides[i] = SIDE_BACK;
else
sides[i] = SIDE_ON;
counts[sides[i]]++;
}
sides[i] = sides[0];
dists[i] = dists[0];
}
/*
==================
ClipWinding
@ -148,25 +172,7 @@ ClipWinding(winding_t *in, plane_t *split, bool keepon)
winding_t *neww;
int maxpts;
counts[0] = counts[1] = counts[2] = 0;
// determine sides for each point
for (i = 0; i < in->numpoints; i++) {
dot = DotProduct(in->points[i], split->normal);
dot -= split->dist;
dists[i] = dot;
if (dot > ON_EPSILON)
sides[i] = SIDE_FRONT;
else if (dot < -ON_EPSILON)
sides[i] = SIDE_BACK;
else
sides[i] = SIDE_ON;
counts[sides[i]]++;
}
sides[i] = sides[0];
dists[i] = dists[0];
CalcSides(in, split, sides, dists, counts);
if (keepon && !counts[SIDE_FRONT] && !counts[SIDE_BACK])
return in;
@ -254,22 +260,7 @@ DivideWinding(winding_t *in, plane_t *split, winding_t **front,
counts[0] = counts[1] = counts[2] = 0;
// determine sides for each point
for (i = 0; i < in->numpoints; i++) {
dot = DotProduct(in->points[i], split->normal);
dot -= split->dist;
dists[i] = dot;
if (dot > ON_EPSILON)
sides[i] = SIDE_FRONT;
else if (dot < -ON_EPSILON)
sides[i] = SIDE_BACK;
else {
sides[i] = SIDE_ON;
}
counts[sides[i]]++;
}
sides[i] = sides[0];
dists[i] = dists[0];
CalcSides(in, split, sides, dists, counts);
*front = *back = NULL;