mirror of
https://git.code.sf.net/p/quake/quakeforge
synced 2024-11-22 20:41:20 +00:00
various impovements from Vic via hqbsp (lordhavoc)
This commit is contained in:
parent
6ec1cfe389
commit
3764497143
5 changed files with 72 additions and 46 deletions
|
@ -35,16 +35,11 @@ PointInLeaf (node_t *node, vec3_t point)
|
|||
{
|
||||
vec_t d;
|
||||
|
||||
if (node->contents)
|
||||
while (!node->contents) {
|
||||
d = DotProduct (planes[node->planenum].normal, point);
|
||||
node = node->children[d <= planes[node->planenum].dist];
|
||||
}
|
||||
return node;
|
||||
|
||||
d = DotProduct (planes[node->planenum].normal, point)
|
||||
- planes[node->planenum].dist;
|
||||
|
||||
if (d > 0)
|
||||
return PointInLeaf (node->children[0], point);
|
||||
|
||||
return PointInLeaf (node->children[1], point);
|
||||
}
|
||||
|
||||
static void
|
||||
|
|
|
@ -83,6 +83,39 @@ RemovePortalFromNode (portal_t *portal, node_t *l)
|
|||
}
|
||||
}
|
||||
|
||||
static void
|
||||
CalcNodeBounds (node_t *node)
|
||||
{
|
||||
int i, j;
|
||||
portal_t *p;
|
||||
winding_t *w;
|
||||
int side;
|
||||
|
||||
for (i=0 ; i<3 ; i++) {
|
||||
node->mins[i] = BOGUS_RANGE;
|
||||
node->maxs[i] = -BOGUS_RANGE;
|
||||
}
|
||||
|
||||
for (p = node->portals ; p ; p = p->next[side]) {
|
||||
if (p->nodes[0] == node)
|
||||
side = 0;
|
||||
else if (p->nodes[1] == node)
|
||||
side = 1;
|
||||
else
|
||||
Sys_Error ("CalcNodeBounds: mislinked portal");
|
||||
|
||||
w = p->winding;
|
||||
for (i = 0; i < w->numpoints; i++) {
|
||||
for (j=0 ; j<3 ; j++) {
|
||||
if (w->points[i][j] < node->mins[j])
|
||||
node->mins[j] = w->points[i][j];
|
||||
if (w->points[i][j] > node->maxs[j])
|
||||
node->maxs[j] = w->points[i][j];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
MakeHeadnodePortals
|
||||
|
||||
|
@ -172,6 +205,8 @@ CutNodePortals_r (node_t *node)
|
|||
|
||||
// CheckLeafPortalConsistancy (node);
|
||||
|
||||
CalcNodeBounds (node);
|
||||
|
||||
// seperate the portals on node into it's children
|
||||
if (node->contents)
|
||||
return; // at a leaf, no more dividing
|
||||
|
@ -186,9 +221,6 @@ CutNodePortals_r (node_t *node)
|
|||
|
||||
// create the new portal by taking the full plane winding for the cutting
|
||||
// plane and clipping it by all of the planes from the other portals
|
||||
new_portal = AllocPortal ();
|
||||
new_portal->planenum = node->planenum;
|
||||
|
||||
w = BaseWindingForPlane (&planes[node->planenum]);
|
||||
side = 0;
|
||||
for (p = node->portals; p; p = p->next[side]) {
|
||||
|
@ -211,6 +243,9 @@ CutNodePortals_r (node_t *node)
|
|||
|
||||
if (w) {
|
||||
// if the plane was not clipped on all sides, there was an error
|
||||
new_portal = AllocPortal ();
|
||||
new_portal->planenum = node->planenum;
|
||||
|
||||
new_portal->winding = w;
|
||||
AddPortalToNodes (new_portal, f, b);
|
||||
}
|
||||
|
|
|
@ -472,22 +472,6 @@ DividePlane (surface_t *in, plane_t *split, surface_t **front,
|
|||
CalcSurfaceInfo (in);
|
||||
}
|
||||
|
||||
static void
|
||||
DivideNodeBounds (node_t *node, plane_t *split)
|
||||
{
|
||||
VectorCopy (node->mins, node->children[0]->mins);
|
||||
VectorCopy (node->mins, node->children[1]->mins);
|
||||
VectorCopy (node->maxs, node->children[0]->maxs);
|
||||
VectorCopy (node->maxs, node->children[1]->maxs);
|
||||
|
||||
// OPTIMIZE: sloping cuts can give a better bbox than this...
|
||||
if (split->type > 2)
|
||||
return;
|
||||
|
||||
node->children[0]->mins[split->type] =
|
||||
node->children[1]->maxs[split->type] = split->dist;
|
||||
}
|
||||
|
||||
/*
|
||||
LinkConvexFaces
|
||||
|
||||
|
@ -618,8 +602,6 @@ PartitionSurfaces (surface_t *surfaces, node_t *node)
|
|||
|
||||
splitplane = &planes[split->planenum];
|
||||
|
||||
DivideNodeBounds (node, splitplane);
|
||||
|
||||
// multiple surfaces, so split all the polysurfaces into front and back
|
||||
// lists
|
||||
frontlist = NULL;
|
||||
|
|
|
@ -50,6 +50,7 @@ typedef struct wedge_s {
|
|||
int numwedges, numwverts;
|
||||
int tjuncs;
|
||||
int tjuncfaces;
|
||||
int degenerdges;
|
||||
|
||||
#define MAXWVERTS 0x20000
|
||||
#define MAXWEDGES 0x10000
|
||||
|
@ -99,34 +100,38 @@ HashVec (vec3_t vec)
|
|||
return h;
|
||||
}
|
||||
|
||||
static void
|
||||
static qboolean
|
||||
CanonicalVector (vec3_t vec)
|
||||
{
|
||||
_VectorNormalize (vec);
|
||||
vec_t len = _VectorNormalize (vec);
|
||||
|
||||
if (len < EQUAL_EPSILON)
|
||||
return false;
|
||||
|
||||
if (vec[0] > EQUAL_EPSILON)
|
||||
return;
|
||||
return true;
|
||||
else if (vec[0] < -EQUAL_EPSILON) {
|
||||
VectorNegate (vec, vec);
|
||||
return;
|
||||
return true;
|
||||
} else
|
||||
vec[0] = 0;
|
||||
|
||||
if (vec[1] > EQUAL_EPSILON)
|
||||
return;
|
||||
return true;
|
||||
else if (vec[1] < -EQUAL_EPSILON) {
|
||||
VectorNegate (vec, vec);
|
||||
return;
|
||||
return true;
|
||||
} else
|
||||
vec[1] = 0;
|
||||
|
||||
if (vec[2] > EQUAL_EPSILON)
|
||||
return;
|
||||
return true;
|
||||
else if (vec[2] < -EQUAL_EPSILON) {
|
||||
VectorNegate (vec, vec);
|
||||
return;
|
||||
return true;
|
||||
} else
|
||||
vec[2] = 0;
|
||||
Sys_Error ("CanonicalVector: degenerate");
|
||||
return false;
|
||||
}
|
||||
|
||||
static wedge_t *
|
||||
|
@ -138,7 +143,11 @@ FindEdge (vec3_t p1, vec3_t p2, vec_t *t1, vec_t *t2)
|
|||
wedge_t *w;
|
||||
|
||||
VectorSubtract (p2, p1, dir);
|
||||
CanonicalVector (dir);
|
||||
|
||||
if (!CanonicalVector (dir)) {
|
||||
degenerdges++;
|
||||
return 0;
|
||||
}
|
||||
|
||||
*t1 = DotProduct (p1, dir);
|
||||
*t2 = DotProduct (p2, dir);
|
||||
|
@ -228,10 +237,11 @@ AddEdge (vec3_t p1, vec3_t p2)
|
|||
wedge_t *w;
|
||||
vec_t t1, t2;
|
||||
|
||||
w = FindEdge (p1, p2, &t1, &t2);
|
||||
if ((w = FindEdge (p1, p2, &t1, &t2))) {
|
||||
AddVert (w, t1);
|
||||
AddVert (w, t2);
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
AddFaceEdges (face_t *f)
|
||||
|
@ -259,7 +269,8 @@ FixFaceEdges (face_t *f)
|
|||
for (i = 0; i < fp->numpoints; i++) {
|
||||
j = (i + 1) % fp->numpoints;
|
||||
|
||||
w = FindEdge (fp->points[i], fp->points[j], &t1, &t2);
|
||||
if (!(w = FindEdge (fp->points[i], fp->points[j], &t1, &t2)))
|
||||
continue;
|
||||
|
||||
for (v = w->head.next; v->t < t1 + T_EPSILON; v = v->next) {
|
||||
}
|
||||
|
@ -356,9 +367,11 @@ tjunc (node_t *headnode)
|
|||
|
||||
// add extra vertexes on edges where needed
|
||||
tjuncs = tjuncfaces = 0;
|
||||
degenerdges = 0;
|
||||
|
||||
tjunc_fix_r (headnode);
|
||||
|
||||
qprintf ("%i degenerate edges\n", degenerdges);
|
||||
qprintf ("%i edges added by tjunctions\n", tjuncs);
|
||||
qprintf ("%i faces added by tjunctions\n", tjuncfaces);
|
||||
}
|
||||
|
|
|
@ -473,6 +473,7 @@ BeginBSPFile (void)
|
|||
|
||||
// leaf 0 is common solid with no faces
|
||||
leaf.contents = CONTENTS_SOLID;
|
||||
leaf.visofs = -1;
|
||||
BSP_AddLeaf (bsp, &leaf);
|
||||
|
||||
firstface = 0;
|
||||
|
|
Loading…
Reference in a new issue