public void CalculateMinLevelDist2( float C )
{
// level 1 has no delta
minLevelDistSqr[ 0 ] = 0;
for ( int level = 1; level < numMipMaps; level++ )
{
minLevelDistSqr[ level ] = 0;
int step = 1 << level;
for ( int j = 0; j < size - step; j += step )
{
for ( int i = 0; i < size - step; i += step )
{
//check each height inbetween the steps.
float h1 = GetVertex( i, j, 1 );
float h2 = GetVertex( i + step, j, 1 );
float h3 = GetVertex( i + step, j + step, 1 );
float h4 = GetVertex( i, j + step, 1 );
for ( int z = 1; z < step; z++ )
{
for ( int x = 1; x < step; x++ )
{
float zpct = z / step;
float xpct = x / step;
//interpolated height
float top = h3 * ( 1.0f - xpct ) + xpct * h4;
float bottom = h1 * ( 1.0f - xpct ) + xpct * h2;
float interp_h = top * ( 1.0f - zpct ) + zpct * bottom;
float actual_h = GetVertex( i + x, j + z, 1 );
float delta = Utility.Abs( interp_h - actual_h );
float D2 = delta * delta * C * C;
if ( minLevelDistSqr[ level ] < D2 )
minLevelDistSqr[ level ] = D2;
}
}
}
}
}
//make sure the levels are increasing...
for ( int i = 1; i < numMipMaps; i++ )
{
if ( minLevelDistSqr[ i ] < minLevelDistSqr[ i - 1 ] )
minLevelDistSqr[ i ] = minLevelDistSqr[ i - 1 ] + 1;
}
}