public static void FixHeight(float[,] heights)
{
// fix X-axis
for (int z = 0; z < 5; z++)
{
// left side
float before = heights[0, z];
heights[0, z] = (float)Math.Round(heights[0, z]);
if (heights[0, z] < 0)
heights[0, z] = 0;
if (heights[0, z] > 1)
heights[0, z] = 1;
float diff = before - heights[0, z];
for (int x = 1; x < 5; x++)
{
heights[x, z] = heights[x, z] - diff * (float)(4 - x) / 4f;
}
// right side
before = heights[4, z];
heights[4, z] = (float)Math.Round(heights[4, z]);
if (heights[4, z] < 0)
heights[4, z] = 0;
if (heights[4, z] > 1)
heights[4, z] = 1;
diff = before - heights[4, z];
for (int x = 0; x < 4; x++)
{
heights[x, z] = heights[x, z] - diff * (float)x / 4f;
}
}
// fix z-axis
for (int x = 0; x < 5; x++)
{
// left side
float before = heights[x, 0];
heights[x, 0] = (float)Math.Round(heights[x, 0]);
if (heights[x, 0] < 0)
heights[x, 0] = 0;
if (heights[x, 0] > 1)
heights[x, 0] = 1;
float diff = before - heights[x, 0];
for (int z = 1; z < 5; z++)
{
heights[x, z] = heights[x, z] - diff * (float)(4 - z) / 4f;
}
// right side
before = heights[x, 4];
heights[x, 4] = (float)Math.Round(heights[x, 4]);
if (heights[x, 4] < 0)
heights[x, 4] = 0;
if (heights[x, 4] > 1)
heights[x, 4] = 1;
diff = before - heights[x, 4];
for (int z = 0; z < 4; z++)
{
heights[x, z] = heights[x, z] - diff * (float)z / 4f;
}
}
}