unify WindingExtendBounds logic

This commit is contained in:
Garux 2021-03-05 06:15:48 +03:00
parent 902fb46938
commit bee749118f
8 changed files with 14 additions and 29 deletions

View File

@ -151,13 +151,11 @@ float WindingArea( const winding_t *w ){
return total;
}
MinMax WindingBounds( const winding_t *w ){
MinMax minmax;
for ( int i = 0 ; i < w->numpoints ; i++ )
void WindingExtendBounds( const winding_t *w, MinMax& minmax ){
for ( int i = 0 ; i < w->numpoints ; ++i )
{
minmax.extend( w->p[i] );
}
return minmax;
}
/*

View File

@ -60,7 +60,7 @@ Plane3f WindingPlane( const winding_t *w );
void RemoveColinearPoints( winding_t *w );
EPlaneSide WindingOnPlaneSide( const winding_t *w, const Plane3f& plane );
void FreeWinding( winding_t *w );
MinMax WindingBounds( const winding_t *w );
void WindingExtendBounds( const winding_t *w, MinMax& minmax );
void AddWindingToConvexHull( winding_t *w, winding_t **hull, const Vector3& normal );

View File

@ -179,11 +179,9 @@ bool BoundBrush( brush_t *brush ){
for ( int i = 0; i < brush->numsides; i++ )
{
const winding_t *w = brush->sides[ i ].winding;
if ( w == NULL ) {
continue;
if ( w != NULL ) {
WindingExtendBounds( w, brush->minmax );
}
for ( int j = 0; j < w->numpoints; j++ )
brush->minmax.extend( w->p[ j ] );
}
return brush->minmax.valid() && c_worldMinmax.surrounds( brush->minmax );
@ -291,7 +289,6 @@ bool FixWinding( winding_t *w ){
bool valid = true;
int i, j, k;
Vector3 vec;
float dist;
/* dummy check */
@ -311,8 +308,7 @@ bool FixWinding( winding_t *w ){
j = ( i + 1 ) % w->numpoints;
/* degenerate edge? */
dist = vector3_length( w->p[ i ] - w->p[ j ] );
if ( dist < DEGENERATE_EPSILON ) {
if ( vector3_length( w->p[ i ] - w->p[ j ] ) < DEGENERATE_EPSILON ) {
valid = false;
//Sys_FPrintf( SYS_WRN | SYS_VRBflag, "WARNING: Degenerate winding edge found, fixing...\n" );

View File

@ -872,12 +872,12 @@ int ConvertBSPMain( int argc, char **argv ){
else if ( striEqual( argv[ i ], "-ne" ) ) {
normalEpsilon = atof( argv[ i + 1 ] );
i++;
Sys_Printf( "Normal epsilon set to %f\n", normalEpsilon );
Sys_Printf( "Normal epsilon set to %lf\n", normalEpsilon );
}
else if ( striEqual( argv[ i ], "-de" ) ) {
distanceEpsilon = atof( argv[ i + 1 ] );
i++;
Sys_Printf( "Distance epsilon set to %f\n", distanceEpsilon );
Sys_Printf( "Distance epsilon set to %lf\n", distanceEpsilon );
}
else if ( striEqual( argv[ i ], "-shaderasbitmap" ) || striEqual( argv[ i ], "-shadersasbitmap" ) ) {
shadersAsBitmap = true;

View File

@ -365,25 +365,20 @@ void BuildFaceTree_r( node_t *node, face_t *list ){
tree_t *FaceBSP( face_t *list ) {
tree_t *tree;
face_t *face;
int i;
int count;
Sys_FPrintf( SYS_VRB, "--- FaceBSP ---\n" );
tree = AllocTree();
count = 0;
int count = 0;
for ( face = list; face != NULL; face = face->next )
{
WindingExtendBounds( face->w, tree->minmax );
count++;
for ( i = 0; i < face->w->numpoints; i++ )
{
tree->minmax.extend( face->w->p[ i ] );
}
}
Sys_FPrintf( SYS_VRB, "%9d faces\n", count );
for ( i = 0; i < nummapplanes; i++ )
for ( int i = 0; i < nummapplanes; i++ )
{
mapplanes[ i ].counter = 0;
}

View File

@ -587,7 +587,7 @@ static void RadSubdivideDiffuseLight( int lightmapNum, bspDrawSurface_t *ds, raw
splash_w = AllocWinding( rw->numVerts );
splash_w->numpoints = rw->numVerts;
for ( i = 0; i < rw->numVerts; i++ )
splash_w->p[ i ] = normal * si->backsplashDistance + rw->verts[rw->numVerts - 1 - i].xyz;
splash_w->p[ i ] = rw->verts[rw->numVerts - 1 - i].xyz + normal * si->backsplashDistance;
splash->w = splash_w;
splash->origin = normal * si->backsplashDistance + light->origin;

View File

@ -456,15 +456,13 @@ void SplitNodePortals( node_t *node ){
void CalcNodeBounds( node_t *node ){
portal_t *p;
int s;
int i;
// calc mins/maxs for both leafs and nodes
node->minmax.clear();
for ( p = node->portals ; p ; p = p->next[s] )
{
s = ( p->nodes[1] == node );
for ( i = 0 ; i < p->winding->numpoints ; i++ )
node->minmax.extend( p->winding->p[i] );
WindingExtendBounds( p->winding, node->minmax );
}
}

View File

@ -1212,7 +1212,6 @@ static void AddSurfaceFlare( mapDrawSurface_t *ds, const Vector3& entityOrigin )
*/
static void SubdivideFace_r( entity_t *e, brush_t *brush, side_t *side, winding_t *w, int fogNum, float subdivisions ){
int i;
int axis;
MinMax bounds;
const float epsilon = 0.1;
@ -1230,8 +1229,7 @@ static void SubdivideFace_r( entity_t *e, brush_t *brush, side_t *side, winding_
}
/* determine surface bounds */
for ( i = 0; i < w->numpoints; i++ )
bounds.extend( w->p[ i ] );
WindingExtendBounds( w, bounds );
/* split the face */
for ( axis = 0; axis < 3; axis++ )