mirror of
https://git.code.sf.net/p/quake/quakeforge
synced 2025-01-31 05:00:35 +00:00
same with MAX_POINTS_ON_WINDING
This commit is contained in:
parent
ca91f7b727
commit
50d83a7c56
2 changed files with 20 additions and 74 deletions
|
@ -54,8 +54,6 @@ typedef struct
|
||||||
vec3_t points[8]; // variable sized
|
vec3_t points[8]; // variable sized
|
||||||
} winding_t;
|
} winding_t;
|
||||||
|
|
||||||
#define MAX_POINTS_ON_WINDING 64
|
|
||||||
|
|
||||||
winding_t *BaseWindingForPlane (plane_t *p);
|
winding_t *BaseWindingForPlane (plane_t *p);
|
||||||
void CheckWinding (winding_t *w);
|
void CheckWinding (winding_t *w);
|
||||||
winding_t *NewWinding (int points);
|
winding_t *NewWinding (int points);
|
||||||
|
@ -67,10 +65,6 @@ void DivideWinding (winding_t *in, plane_t *split, winding_t **front, winding_t
|
||||||
|
|
||||||
//============================================================================
|
//============================================================================
|
||||||
|
|
||||||
#define MAXEDGES 32
|
|
||||||
#define MAXPOINTS 28 // don't let a base face get past this
|
|
||||||
// because it can be split more later
|
|
||||||
|
|
||||||
typedef struct visfacet_s
|
typedef struct visfacet_s
|
||||||
{
|
{
|
||||||
struct visfacet_s *next;
|
struct visfacet_s *next;
|
||||||
|
|
|
@ -177,16 +177,19 @@ winding_t *
|
||||||
ClipWinding (winding_t *in, plane_t *split, qboolean keepon)
|
ClipWinding (winding_t *in, plane_t *split, qboolean keepon)
|
||||||
{
|
{
|
||||||
int maxpts, i, j;
|
int maxpts, i, j;
|
||||||
int sides[MAX_POINTS_ON_WINDING + 1];
|
int *sides;
|
||||||
int counts[3];
|
int counts[3];
|
||||||
vec_t dot;
|
vec_t dot;
|
||||||
vec_t dists[MAX_POINTS_ON_WINDING + 1];
|
vec_t *dists;
|
||||||
vec_t *p1, *p2;
|
vec_t *p1, *p2;
|
||||||
vec3_t mid;
|
vec3_t mid;
|
||||||
winding_t *neww;
|
winding_t *neww;
|
||||||
|
|
||||||
counts[0] = counts[1] = counts[2] = 0;
|
counts[0] = counts[1] = counts[2] = 0;
|
||||||
|
|
||||||
|
sides = alloca ((in->numpoints + 1) * sizeof (int));
|
||||||
|
dists = alloca ((in->numpoints + 1) * sizeof (vec_t));
|
||||||
|
|
||||||
// determine sides for each point
|
// determine sides for each point
|
||||||
for (i = 0; i < in->numpoints; i++) {
|
for (i = 0; i < in->numpoints; i++) {
|
||||||
dot = DotProduct (in->points[i], split->normal);
|
dot = DotProduct (in->points[i], split->normal);
|
||||||
|
@ -273,41 +276,30 @@ void
|
||||||
DivideWinding (winding_t *in, plane_t *split, winding_t **front,
|
DivideWinding (winding_t *in, plane_t *split, winding_t **front,
|
||||||
winding_t **back)
|
winding_t **back)
|
||||||
{
|
{
|
||||||
int maxpts, i, j;
|
int maxpts, i;
|
||||||
int sides[MAX_POINTS_ON_WINDING + 1];
|
|
||||||
int counts[3];
|
int counts[3];
|
||||||
|
plane_t plane;
|
||||||
vec_t dot;
|
vec_t dot;
|
||||||
vec_t dists[MAX_POINTS_ON_WINDING + 1];
|
winding_t *tmp;
|
||||||
vec_t *p1, *p2;
|
|
||||||
vec3_t mid;
|
|
||||||
winding_t *f, *b;
|
|
||||||
|
|
||||||
counts[0] = counts[1] = counts[2] = 0;
|
counts[0] = counts[1] = counts[2] = 0;
|
||||||
|
|
||||||
// determine sides for each point
|
// determine sides for each point
|
||||||
for (i = 0; i < in->numpoints; i++) {
|
for (i = 0; i < in->numpoints; i++) {
|
||||||
dot = DotProduct (in->points[i], split->normal);
|
dot = DotProduct (in->points[i], split->normal) - split->dist;
|
||||||
dot -= split->dist;
|
|
||||||
dists[i] = dot;
|
|
||||||
if (dot > ON_EPSILON)
|
if (dot > ON_EPSILON)
|
||||||
sides[i] = SIDE_FRONT;
|
counts[SIDE_FRONT]++;
|
||||||
else if (dot < -ON_EPSILON)
|
else if (dot < -ON_EPSILON)
|
||||||
sides[i] = SIDE_BACK;
|
counts[SIDE_BACK]++;
|
||||||
else {
|
|
||||||
sides[i] = SIDE_ON;
|
|
||||||
}
|
}
|
||||||
counts[sides[i]]++;
|
|
||||||
}
|
|
||||||
sides[i] = sides[0];
|
|
||||||
dists[i] = dists[0];
|
|
||||||
|
|
||||||
*front = *back = NULL;
|
*front = *back = NULL;
|
||||||
|
|
||||||
if (!counts[0]) {
|
if (!counts[SIDE_FRONT]) {
|
||||||
*back = in;
|
*back = in;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (!counts[1]) {
|
if (!counts[SIDE_BACK]) {
|
||||||
*front = in;
|
*front = in;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -315,54 +307,14 @@ DivideWinding (winding_t *in, plane_t *split, winding_t **front,
|
||||||
maxpts = in->numpoints + 4; // can't use counts[0]+2 because
|
maxpts = in->numpoints + 4; // can't use counts[0]+2 because
|
||||||
// of fp grouping errors
|
// of fp grouping errors
|
||||||
|
|
||||||
*front = f = NewWinding (maxpts);
|
tmp = CopyWinding (in);
|
||||||
*back = b = NewWinding (maxpts);
|
*front = ClipWinding (tmp, split, 0);
|
||||||
|
|
||||||
for (i = 0; i < in->numpoints; i++) {
|
plane.dist = -split->dist;
|
||||||
p1 = in->points[i];
|
VectorNegate (split->normal, plane.normal);
|
||||||
|
|
||||||
if (sides[i] == SIDE_ON) {
|
tmp = CopyWinding (in);
|
||||||
VectorCopy (p1, f->points[f->numpoints]);
|
*back = ClipWinding (tmp, &plane, 0);
|
||||||
f->numpoints++;
|
|
||||||
VectorCopy (p1, b->points[b->numpoints]);
|
|
||||||
b->numpoints++;
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (sides[i] == SIDE_FRONT) {
|
|
||||||
VectorCopy (p1, f->points[f->numpoints]);
|
|
||||||
f->numpoints++;
|
|
||||||
}
|
|
||||||
if (sides[i] == SIDE_BACK) {
|
|
||||||
VectorCopy (p1, b->points[b->numpoints]);
|
|
||||||
b->numpoints++;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (sides[i + 1] == SIDE_ON || sides[i + 1] == sides[i])
|
|
||||||
continue;
|
|
||||||
|
|
||||||
// generate a split point
|
|
||||||
p2 = in->points[(i + 1) % in->numpoints];
|
|
||||||
|
|
||||||
dot = dists[i] / (dists[i] - dists[i + 1]);
|
|
||||||
for (j = 0; j < 3; j++) { // avoid round off error when
|
|
||||||
// possible
|
|
||||||
if (split->normal[j] == 1)
|
|
||||||
mid[j] = split->dist;
|
|
||||||
else if (split->normal[j] == -1)
|
|
||||||
mid[j] = -split->dist;
|
|
||||||
else
|
|
||||||
mid[j] = p1[j] + dot * (p2[j] - p1[j]);
|
|
||||||
}
|
|
||||||
|
|
||||||
VectorCopy (mid, f->points[f->numpoints]);
|
|
||||||
f->numpoints++;
|
|
||||||
VectorCopy (mid, b->points[b->numpoints]);
|
|
||||||
b->numpoints++;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (f->numpoints > maxpts || b->numpoints > maxpts)
|
|
||||||
Sys_Error ("ClipWinding: points exceeded estimate");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
winding_t *
|
winding_t *
|
||||||
|
@ -371,7 +323,7 @@ NewWinding (int points)
|
||||||
int size;
|
int size;
|
||||||
winding_t *w;
|
winding_t *w;
|
||||||
|
|
||||||
if (points < 3 || points > MAX_POINTS_ON_WINDING)
|
if (points < 3)
|
||||||
Sys_Error ("NewWinding: %i points", points);
|
Sys_Error ("NewWinding: %i points", points);
|
||||||
|
|
||||||
c_activewindings++;
|
c_activewindings++;
|
||||||
|
|
Loading…
Reference in a new issue