aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim.Terrain.BasicTerrain
diff options
context:
space:
mode:
authorAdam Frisby2007-04-07 16:19:49 +0000
committerAdam Frisby2007-04-07 16:19:49 +0000
commit30a5e028c5f8bfbd488046879334688fe3cab10e (patch)
tree8d7de63a58d563868295dca907905b03f9d62789 /OpenSim.Terrain.BasicTerrain
parentI am a freaking idiot. (diff)
downloadopensim-SC-30a5e028c5f8bfbd488046879334688fe3cab10e.zip
opensim-SC-30a5e028c5f8bfbd488046879334688fe3cab10e.tar.gz
opensim-SC-30a5e028c5f8bfbd488046879334688fe3cab10e.tar.bz2
opensim-SC-30a5e028c5f8bfbd488046879334688fe3cab10e.tar.xz
Port to a 2D Heightmap complete
Diffstat (limited to 'OpenSim.Terrain.BasicTerrain')
-rw-r--r--OpenSim.Terrain.BasicTerrain/Normalise.cs83
-rw-r--r--OpenSim.Terrain.BasicTerrain/OpenSim.Terrain.BasicTerrain.csproj1
-rw-r--r--OpenSim.Terrain.BasicTerrain/TerrainEngine.cs1
3 files changed, 85 insertions, 0 deletions
diff --git a/OpenSim.Terrain.BasicTerrain/Normalise.cs b/OpenSim.Terrain.BasicTerrain/Normalise.cs
new file mode 100644
index 0000000..507795b
--- /dev/null
+++ b/OpenSim.Terrain.BasicTerrain/Normalise.cs
@@ -0,0 +1,83 @@
1using System;
2using System.Collections.Generic;
3using System.Text;
4
5namespace OpenSim.Terrain.BasicTerrain
6{
7 static class Normalise
8 {
9 public static void normalise(float[,] map)
10 {
11 double max = findMax(map);
12 double min = findMin(map);
13 int w = map.GetLength(0);
14 int h = map.GetLength(1);
15
16 int x, y;
17
18 for (x = 0; x < w; x++)
19 {
20 for (y = 0; y < h; y++)
21 {
22 map[x, y] = (float)((map[x, y] - min) * (1.0 / (max - min)));
23 }
24 }
25 }
26
27 public static void normalise(float[,] map, double newmax)
28 {
29 double max = findMax(map);
30 double min = findMin(map);
31 int w = map.GetLength(0);
32 int h = map.GetLength(1);
33
34 int x, y;
35
36 for (x = 0; x < w; x++)
37 {
38 for (y = 0; y < h; y++)
39 {
40 map[x, y] = (float)((map[x, y] - min) * (1.0 / (max - min)) * newmax);
41 }
42 }
43 }
44
45 public static double findMax(float[,] map)
46 {
47 int x, y;
48 int w = map.GetLength(0);
49 int h = map.GetLength(1);
50 double max = double.MinValue;
51
52 for (x = 0; x < w; x++)
53 {
54 for (y = 0; y < h; y++)
55 {
56 if (map[x, y] > max)
57 max = map[x, y];
58 }
59 }
60
61 return max;
62 }
63
64 public static double findMin(float[,] map)
65 {
66 int x, y;
67 int w = map.GetLength(0);
68 int h = map.GetLength(1);
69 double min = double.MaxValue;
70
71 for (x = 0; x < w; x++)
72 {
73 for (y = 0; y < h; y++)
74 {
75 if (map[x, y] < min)
76 min = map[x, y];
77 }
78 }
79
80 return min;
81 }
82 }
83}
diff --git a/OpenSim.Terrain.BasicTerrain/OpenSim.Terrain.BasicTerrain.csproj b/OpenSim.Terrain.BasicTerrain/OpenSim.Terrain.BasicTerrain.csproj
index 2103902..328f69d 100644
--- a/OpenSim.Terrain.BasicTerrain/OpenSim.Terrain.BasicTerrain.csproj
+++ b/OpenSim.Terrain.BasicTerrain/OpenSim.Terrain.BasicTerrain.csproj
@@ -34,6 +34,7 @@
34 </ItemGroup> 34 </ItemGroup>
35 <ItemGroup> 35 <ItemGroup>
36 <Compile Include="Hills.cs" /> 36 <Compile Include="Hills.cs" />
37 <Compile Include="Normalise.cs" />
37 <Compile Include="RaiseLower.cs" /> 38 <Compile Include="RaiseLower.cs" />
38 <Compile Include="TerrainEngine.cs" /> 39 <Compile Include="TerrainEngine.cs" />
39 <Compile Include="Properties\AssemblyInfo.cs" /> 40 <Compile Include="Properties\AssemblyInfo.cs" />
diff --git a/OpenSim.Terrain.BasicTerrain/TerrainEngine.cs b/OpenSim.Terrain.BasicTerrain/TerrainEngine.cs
index 60b49ae..de0ab50 100644
--- a/OpenSim.Terrain.BasicTerrain/TerrainEngine.cs
+++ b/OpenSim.Terrain.BasicTerrain/TerrainEngine.cs
@@ -67,6 +67,7 @@ namespace OpenSim.Terrain
67 lock (map) 67 lock (map)
68 { 68 {
69 Hills.hillsSpheres(this.map, 1337, 200, 20, 40, true, true, false); 69 Hills.hillsSpheres(this.map, 1337, 200, 20, 40, true, true, false);
70 Normalise.normalise(this.map,60);
70 } 71 }
71 } 72 }
72 73