use MinMax functions instead of raw math
This commit is contained in:
parent
f9a424b6c8
commit
39f5a2d060
|
|
@ -819,6 +819,7 @@ winding_t *ChopWinding( winding_t *in, const Plane3f& plane ){
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
inline const MinMax c_worldMinmax( Vector3().set( MIN_WORLD_COORD ), Vector3().set( MAX_WORLD_COORD ) );
|
||||||
/*
|
/*
|
||||||
=================
|
=================
|
||||||
CheckWinding
|
CheckWinding
|
||||||
|
|
@ -827,7 +828,7 @@ winding_t *ChopWinding( winding_t *in, const Plane3f& plane ){
|
||||||
*/
|
*/
|
||||||
void CheckWinding( winding_t *w ){
|
void CheckWinding( winding_t *w ){
|
||||||
int i, j;
|
int i, j;
|
||||||
float d, edgedist;
|
float edgedist;
|
||||||
Vector3 dir, edgenormal;
|
Vector3 dir, edgenormal;
|
||||||
float area;
|
float area;
|
||||||
|
|
||||||
|
|
@ -846,16 +847,14 @@ void CheckWinding( winding_t *w ){
|
||||||
{
|
{
|
||||||
const Vector3& p1 = w->p[i];
|
const Vector3& p1 = w->p[i];
|
||||||
|
|
||||||
for ( j = 0 ; j < 3 ; j++ )
|
if ( !c_worldMinmax.test( p1 ) ) {
|
||||||
if ( p1[j] > MAX_WORLD_COORD || p1[j] < MIN_WORLD_COORD ) {
|
Error( "CheckFace: MAX_WORLD_COORD exceeded: ( %f %f %f )", p1[0], p1[1], p1[2] );
|
||||||
Error( "CheckFace: MAX_WORLD_COORD exceeded: %f",p1[j] );
|
}
|
||||||
}
|
|
||||||
|
|
||||||
j = ( i + 1 == w->numpoints )? 0 : i + 1;
|
j = ( i + 1 == w->numpoints )? 0 : i + 1;
|
||||||
|
|
||||||
// check the point is on the face plane
|
// check the point is on the face plane
|
||||||
d = plane3_distance_to_point( faceplane, p1 );
|
if ( fabs( plane3_distance_to_point( faceplane, p1 ) ) > ON_EPSILON ) {
|
||||||
if ( d < -ON_EPSILON || d > ON_EPSILON ) {
|
|
||||||
Error( "CheckWinding: point off plane" );
|
Error( "CheckWinding: point off plane" );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -876,8 +875,7 @@ void CheckWinding( winding_t *w ){
|
||||||
if ( j == i ) {
|
if ( j == i ) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
d = vector3_dot( w->p[j], edgenormal );
|
if ( vector3_dot( w->p[j], edgenormal ) > edgedist ) {
|
||||||
if ( d > edgedist ) {
|
|
||||||
Error( "CheckWinding: non-convex" );
|
Error( "CheckWinding: non-convex" );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -57,6 +57,7 @@ struct MinMax___
|
||||||
extend( other.mins );
|
extend( other.mins );
|
||||||
extend( other.maxs );
|
extend( other.maxs );
|
||||||
}
|
}
|
||||||
|
// true, if point is within the bounds
|
||||||
template<typename U>
|
template<typename U>
|
||||||
bool test( const BasicVector3<U>& point ) const {
|
bool test( const BasicVector3<U>& point ) const {
|
||||||
return point.x() >= mins.x() && point.y() >= mins.y() && point.z() >= mins.z()
|
return point.x() >= mins.x() && point.y() >= mins.y() && point.z() >= mins.z()
|
||||||
|
|
@ -68,6 +69,12 @@ struct MinMax___
|
||||||
return other.maxs.x() >= mins.x() && other.maxs.y() >= mins.y() && other.maxs.z() >= mins.z()
|
return other.maxs.x() >= mins.x() && other.maxs.y() >= mins.y() && other.maxs.z() >= mins.z()
|
||||||
&& other.mins.x() <= maxs.x() && other.mins.y() <= maxs.y() && other.mins.z() <= maxs.z();
|
&& other.mins.x() <= maxs.x() && other.mins.y() <= maxs.y() && other.mins.z() <= maxs.z();
|
||||||
}
|
}
|
||||||
|
// true, if other is completely enclosed by this
|
||||||
|
template<typename U>
|
||||||
|
bool surrounds( const MinMax___<U>& other ) const {
|
||||||
|
return other.mins.x() >= mins.x() && other.mins.y() >= mins.y() && other.mins.z() >= mins.z()
|
||||||
|
&& other.maxs.x() <= maxs.x() && other.maxs.y() <= maxs.y() && other.maxs.z() <= maxs.z();
|
||||||
|
}
|
||||||
BasicVector3<T> origin() const {
|
BasicVector3<T> origin() const {
|
||||||
return ( mins + maxs ) * 0.5;
|
return ( mins + maxs ) * 0.5;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -175,29 +175,18 @@ brush_t *CopyBrush( const brush_t *brush ){
|
||||||
*/
|
*/
|
||||||
|
|
||||||
bool BoundBrush( brush_t *brush ){
|
bool BoundBrush( brush_t *brush ){
|
||||||
int i, j;
|
|
||||||
winding_t *w;
|
|
||||||
|
|
||||||
|
|
||||||
brush->minmax.clear();
|
brush->minmax.clear();
|
||||||
for ( i = 0; i < brush->numsides; i++ )
|
for ( int i = 0; i < brush->numsides; i++ )
|
||||||
{
|
{
|
||||||
w = brush->sides[ i ].winding;
|
const winding_t *w = brush->sides[ i ].winding;
|
||||||
if ( w == NULL ) {
|
if ( w == NULL ) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
for ( j = 0; j < w->numpoints; j++ )
|
for ( int j = 0; j < w->numpoints; j++ )
|
||||||
brush->minmax.extend( w->p[ j ] );
|
brush->minmax.extend( w->p[ j ] );
|
||||||
}
|
}
|
||||||
|
|
||||||
for ( i = 0; i < 3; i++ )
|
return brush->minmax.valid() && c_worldMinmax.surrounds( brush->minmax );
|
||||||
{
|
|
||||||
if ( brush->minmax.mins[ i ] < MIN_WORLD_COORD || brush->minmax.maxs[ i ] > MAX_WORLD_COORD || brush->minmax.mins[i] >= brush->minmax.maxs[ i ] ) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -823,15 +812,9 @@ bool WindingIsTiny( winding_t *w ){
|
||||||
================
|
================
|
||||||
*/
|
*/
|
||||||
bool WindingIsHuge( winding_t *w ){
|
bool WindingIsHuge( winding_t *w ){
|
||||||
int i, j;
|
for ( int i = 0; i < w->numpoints; i++ )
|
||||||
|
if ( !c_worldMinmax.test( w->p[i] ) )
|
||||||
for ( i = 0 ; i < w->numpoints ; i++ )
|
return true;
|
||||||
{
|
|
||||||
for ( j = 0 ; j < 3 ; j++ )
|
|
||||||
if ( w->p[i][j] <= MIN_WORLD_COORD || w->p[i][j] >= MAX_WORLD_COORD ) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -478,10 +478,8 @@ void CalcNodeBounds( node_t *node ){
|
||||||
==================
|
==================
|
||||||
*/
|
*/
|
||||||
void MakeTreePortals_r( node_t *node ){
|
void MakeTreePortals_r( node_t *node ){
|
||||||
int i;
|
|
||||||
|
|
||||||
CalcNodeBounds( node );
|
CalcNodeBounds( node );
|
||||||
if ( node->minmax.mins[0] >= node->minmax.maxs[0] ) {
|
if ( !node->minmax.valid() ) {
|
||||||
Sys_Warning( "node without a volume\n"
|
Sys_Warning( "node without a volume\n"
|
||||||
"node has %d tiny portals\n"
|
"node has %d tiny portals\n"
|
||||||
"node reference point %1.2f %1.2f %1.2f\n",
|
"node reference point %1.2f %1.2f %1.2f\n",
|
||||||
|
|
@ -491,14 +489,9 @@ void MakeTreePortals_r( node_t *node ){
|
||||||
node->referencepoint[2] );
|
node->referencepoint[2] );
|
||||||
}
|
}
|
||||||
|
|
||||||
for ( i = 0 ; i < 3 ; i++ )
|
if ( !c_worldMinmax.surrounds( node->minmax ) ) {
|
||||||
{
|
if ( node->portals && node->portals->winding ) {
|
||||||
if ( node->minmax.mins[i] < MIN_WORLD_COORD || node->minmax.maxs[i] > MAX_WORLD_COORD ) {
|
xml_Winding( "WARNING: Node With Unbounded Volume", node->portals->winding->p, node->portals->winding->numpoints, false );
|
||||||
if ( node->portals && node->portals->winding ) {
|
|
||||||
xml_Winding( "WARNING: Node With Unbounded Volume", node->portals->winding->p, node->portals->winding->numpoints, false );
|
|
||||||
}
|
|
||||||
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if ( node->planenum == PLANENUM_LEAF ) {
|
if ( node->planenum == PLANENUM_LEAF ) {
|
||||||
|
|
|
||||||
|
|
@ -2128,6 +2128,8 @@ Q_EXTERN int allocatedmapplanes Q_ASSIGN( 0 );
|
||||||
Q_EXTERN int numMapPatches;
|
Q_EXTERN int numMapPatches;
|
||||||
Q_EXTERN MinMax g_mapMinmax;
|
Q_EXTERN MinMax g_mapMinmax;
|
||||||
|
|
||||||
|
inline const MinMax c_worldMinmax( Vector3().set( MIN_WORLD_COORD ), Vector3().set( MAX_WORLD_COORD ) );
|
||||||
|
|
||||||
Q_EXTERN int defaultFogNum Q_ASSIGN( -1 ); /* ydnar: cleaner fog handling */
|
Q_EXTERN int defaultFogNum Q_ASSIGN( -1 ); /* ydnar: cleaner fog handling */
|
||||||
Q_EXTERN int numMapFogs Q_ASSIGN( 0 );
|
Q_EXTERN int numMapFogs Q_ASSIGN( 0 );
|
||||||
Q_EXTERN fog_t mapFogs[ MAX_MAP_FOGS ];
|
Q_EXTERN fog_t mapFogs[ MAX_MAP_FOGS ];
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user