protected Region GetRegion( AxisAlignedBox bounds, bool autoCreate )
{
if ( bounds == null )
return null;
// Get the region which has the largest overlapping volume
Vector3 min = bounds.Minimum;
Vector3 max = bounds.Maximum;
// Get the min and max region indexes
ushort minx, miny, minz;
ushort maxx, maxy, maxz;
GetRegionIndexes( min, out minx, out miny, out minz );
GetRegionIndexes( max, out maxx, out maxy, out maxz );
float maxVolume = 0.0f;
ushort finalx = 0;
ushort finaly = 0;
ushort finalz = 0;
for ( ushort x = minx; x <= maxx; ++x )
{
for ( ushort y = miny; y <= maxy; ++y )
{
for ( ushort z = minz; z <= maxz; ++z )
{
float vol = GetVolumeIntersection( bounds, x, y, z );
if ( vol > maxVolume )
{
maxVolume = vol;
finalx = x;
finaly = y;
finalz = z;
}
}
}
}
Debug.Assert( maxVolume > 0.0f, "Static geometry: Problem determining closest volume match!" );
return GetRegion( finalx, finaly, finalz, autoCreate );
}