Port to a 2D Heightmap complete

0.1-prestable
Adam Frisby 2007-04-07 16:19:49 +00:00
parent d28dd8f456
commit 30a5e028c5
3 changed files with 85 additions and 0 deletions

View File

@ -0,0 +1,83 @@
using System;
using System.Collections.Generic;
using System.Text;
namespace OpenSim.Terrain.BasicTerrain
{
static class Normalise
{
public static void normalise(float[,] map)
{
double max = findMax(map);
double min = findMin(map);
int w = map.GetLength(0);
int h = map.GetLength(1);
int x, y;
for (x = 0; x < w; x++)
{
for (y = 0; y < h; y++)
{
map[x, y] = (float)((map[x, y] - min) * (1.0 / (max - min)));
}
}
}
public static void normalise(float[,] map, double newmax)
{
double max = findMax(map);
double min = findMin(map);
int w = map.GetLength(0);
int h = map.GetLength(1);
int x, y;
for (x = 0; x < w; x++)
{
for (y = 0; y < h; y++)
{
map[x, y] = (float)((map[x, y] - min) * (1.0 / (max - min)) * newmax);
}
}
}
public static double findMax(float[,] map)
{
int x, y;
int w = map.GetLength(0);
int h = map.GetLength(1);
double max = double.MinValue;
for (x = 0; x < w; x++)
{
for (y = 0; y < h; y++)
{
if (map[x, y] > max)
max = map[x, y];
}
}
return max;
}
public static double findMin(float[,] map)
{
int x, y;
int w = map.GetLength(0);
int h = map.GetLength(1);
double min = double.MaxValue;
for (x = 0; x < w; x++)
{
for (y = 0; y < h; y++)
{
if (map[x, y] < min)
min = map[x, y];
}
}
return min;
}
}
}

View File

@ -34,6 +34,7 @@
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<Compile Include="Hills.cs" /> <Compile Include="Hills.cs" />
<Compile Include="Normalise.cs" />
<Compile Include="RaiseLower.cs" /> <Compile Include="RaiseLower.cs" />
<Compile Include="TerrainEngine.cs" /> <Compile Include="TerrainEngine.cs" />
<Compile Include="Properties\AssemblyInfo.cs" /> <Compile Include="Properties\AssemblyInfo.cs" />

View File

@ -67,6 +67,7 @@ namespace OpenSim.Terrain
lock (map) lock (map)
{ {
Hills.hillsSpheres(this.map, 1337, 200, 20, 40, true, true, false); Hills.hillsSpheres(this.map, 1337, 200, 20, 40, true, true, false);
Normalise.normalise(this.map,60);
} }
} }