diff options
author | Adam Frisby | 2007-04-06 18:48:23 +0000 |
---|---|---|
committer | Adam Frisby | 2007-04-06 18:48:23 +0000 |
commit | fb0dffbf13a79aabe9537f16b7bb151af62c75bf (patch) | |
tree | 28a8d468e5499a7af1e33eec7bbdeb9e82ae8732 /OpenSim.Terrain.BasicTerrain | |
parent | And now for some solution files... (diff) | |
download | opensim-SC-fb0dffbf13a79aabe9537f16b7bb151af62c75bf.zip opensim-SC-fb0dffbf13a79aabe9537f16b7bb151af62c75bf.tar.gz opensim-SC-fb0dffbf13a79aabe9537f16b7bb151af62c75bf.tar.bz2 opensim-SC-fb0dffbf13a79aabe9537f16b7bb151af62c75bf.tar.xz |
**BREAKING CHANGE** Changing the way terrain is stored and used internally.
Diffstat (limited to '')
-rw-r--r-- | OpenSim.Terrain.BasicTerrain/Hills.cs | 72 | ||||
-rw-r--r-- | OpenSim.Terrain.BasicTerrain/OpenSim.Terrain.BasicTerrain.csproj | 4 | ||||
-rw-r--r-- | OpenSim.Terrain.BasicTerrain/RaiseLower.cs | 91 | ||||
-rw-r--r-- | OpenSim.Terrain.BasicTerrain/TerrainEngine.cs | 64 | ||||
-rw-r--r-- | OpenSim.Terrain.BasicTerrain/TerrainManager.cs | 11 | ||||
-rw-r--r-- | OpenSim.Terrain.BasicTerrain/bin/Debug/OpenSim.Terrain.BasicTerrain.dll | bin | 0 -> 16384 bytes | |||
-rw-r--r-- | OpenSim.Terrain.BasicTerrain/bin/Debug/OpenSim.Terrain.BasicTerrain.pdb | bin | 0 -> 19968 bytes | |||
-rw-r--r-- | OpenSim.Terrain.BasicTerrain/obj/Debug/OpenSim.Terrain.BasicTerrain.dll | bin | 0 -> 16384 bytes | |||
-rw-r--r-- | OpenSim.Terrain.BasicTerrain/obj/Debug/OpenSim.Terrain.BasicTerrain.pdb | bin | 0 -> 19968 bytes | |||
-rw-r--r-- | OpenSim.Terrain.BasicTerrain/obj/OpenSim.Terrain.BasicTerrain.csproj.FileList.txt | 5 |
10 files changed, 235 insertions, 12 deletions
diff --git a/OpenSim.Terrain.BasicTerrain/Hills.cs b/OpenSim.Terrain.BasicTerrain/Hills.cs new file mode 100644 index 0000000..40543a9 --- /dev/null +++ b/OpenSim.Terrain.BasicTerrain/Hills.cs | |||
@@ -0,0 +1,72 @@ | |||
1 | using System; | ||
2 | using System.Collections.Generic; | ||
3 | using System.Text; | ||
4 | |||
5 | namespace OpenSim.Terrain.BasicTerrain | ||
6 | { | ||
7 | static class Hills | ||
8 | { | ||
9 | /// <summary> | ||
10 | /// Generates a series of spheres which are then either max()'d or added together. Inspired by suggestion from jh. | ||
11 | /// </summary> | ||
12 | /// <remarks>3-Clause BSD Licensed</remarks> | ||
13 | /// <param name="number">The number of hills to generate</param> | ||
14 | /// <param name="scale_min">The minimum size of each hill</param> | ||
15 | /// <param name="scale_range">The maximum size of each hill</param> | ||
16 | /// <param name="island">Whether to bias hills towards the center of the map</param> | ||
17 | /// <param name="additive">Whether to add hills together or to pick the largest value</param> | ||
18 | /// <param name="noisy">Generates hill-shaped noise instead of consistent hills</param> | ||
19 | public static void hillsSpheres(float[,] map,int seed, int number, double scale_min, double scale_range, bool island, bool additive, bool noisy) | ||
20 | { | ||
21 | Random random = new Random(seed); | ||
22 | int w = map.GetLength(0); | ||
23 | int h = map.GetLength(1); | ||
24 | int x, y; | ||
25 | int i; | ||
26 | |||
27 | for (i = 0; i < number; i++) | ||
28 | { | ||
29 | double rx = Math.Min(255.0, random.NextDouble() * w); | ||
30 | double ry = Math.Min(255.0, random.NextDouble() * h); | ||
31 | double rand = random.NextDouble(); | ||
32 | |||
33 | if (island) | ||
34 | { | ||
35 | // Move everything towards the center | ||
36 | rx -= w / 2; | ||
37 | rx /= 2; | ||
38 | rx += w / 2; | ||
39 | |||
40 | ry -= h / 2; | ||
41 | ry /= 2; | ||
42 | ry += h / 2; | ||
43 | } | ||
44 | |||
45 | for (x = 0; x < w; x++) | ||
46 | { | ||
47 | for (y = 0; y < h; y++) | ||
48 | { | ||
49 | if (noisy) | ||
50 | rand = random.NextDouble(); | ||
51 | |||
52 | double z = (scale_min + (scale_range * rand)); | ||
53 | z *= z; | ||
54 | z -= ((x - rx) * (x - rx)) + ((y - ry) * (y - ry)); | ||
55 | |||
56 | if (z < 0) | ||
57 | z = 0; | ||
58 | |||
59 | if (additive) | ||
60 | { | ||
61 | map[x, y] += (float)z; | ||
62 | } | ||
63 | else | ||
64 | { | ||
65 | map[x, y] = (float)Math.Max(map[x, y], z); | ||
66 | } | ||
67 | } | ||
68 | } | ||
69 | } | ||
70 | } | ||
71 | } | ||
72 | } | ||
diff --git a/OpenSim.Terrain.BasicTerrain/OpenSim.Terrain.BasicTerrain.csproj b/OpenSim.Terrain.BasicTerrain/OpenSim.Terrain.BasicTerrain.csproj index 4da1ede..2103902 100644 --- a/OpenSim.Terrain.BasicTerrain/OpenSim.Terrain.BasicTerrain.csproj +++ b/OpenSim.Terrain.BasicTerrain/OpenSim.Terrain.BasicTerrain.csproj | |||
@@ -33,7 +33,9 @@ | |||
33 | <Reference Include="System.Xml" /> | 33 | <Reference Include="System.Xml" /> |
34 | </ItemGroup> | 34 | </ItemGroup> |
35 | <ItemGroup> | 35 | <ItemGroup> |
36 | <Compile Include="TerrainManager.cs" /> | 36 | <Compile Include="Hills.cs" /> |
37 | <Compile Include="RaiseLower.cs" /> | ||
38 | <Compile Include="TerrainEngine.cs" /> | ||
37 | <Compile Include="Properties\AssemblyInfo.cs" /> | 39 | <Compile Include="Properties\AssemblyInfo.cs" /> |
38 | </ItemGroup> | 40 | </ItemGroup> |
39 | <Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" /> | 41 | <Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" /> |
diff --git a/OpenSim.Terrain.BasicTerrain/RaiseLower.cs b/OpenSim.Terrain.BasicTerrain/RaiseLower.cs new file mode 100644 index 0000000..384bcc0 --- /dev/null +++ b/OpenSim.Terrain.BasicTerrain/RaiseLower.cs | |||
@@ -0,0 +1,91 @@ | |||
1 | using System; | ||
2 | using System.Collections.Generic; | ||
3 | using System.Text; | ||
4 | |||
5 | namespace OpenSim.Terrain.BasicTerrain | ||
6 | { | ||
7 | static class RaiseLower | ||
8 | { | ||
9 | /// <summary> | ||
10 | /// Raises land around the selection | ||
11 | /// </summary> | ||
12 | /// <param name="rx">The center the X coordinate of where you wish to raise the land</param> | ||
13 | /// <param name="ry">The center the Y coordinate of where you wish to raise the land</param> | ||
14 | /// <param name="size">The radius of the dimple</param> | ||
15 | /// <param name="amount">How much impact to add to the terrain (0..2 usually)</param> | ||
16 | public static void raise(float[,] map, double rx, double ry, double size, double amount) | ||
17 | { | ||
18 | raiseSphere(map, rx, ry, size, amount); | ||
19 | } | ||
20 | |||
21 | /// <summary> | ||
22 | /// Raises land in a sphere around the selection | ||
23 | /// </summary> | ||
24 | /// <param name="rx">The center the X coordinate of where you wish to raise the land</param> | ||
25 | /// <param name="ry">The center the Y coordinate of where you wish to raise the land</param> | ||
26 | /// <param name="size">The radius of the sphere dimple</param> | ||
27 | /// <param name="amount">How much impact to add to the terrain (0..2 usually)</param> | ||
28 | public static void raiseSphere(float[,] map, double rx, double ry, double size, double amount) | ||
29 | { | ||
30 | int x, y; | ||
31 | int w = map.GetLength(0); | ||
32 | int h = map.GetLength(1); | ||
33 | |||
34 | for (x = 0; x < w; x++) | ||
35 | { | ||
36 | for (y = 0; y < h; y++) | ||
37 | { | ||
38 | double z = size; | ||
39 | z *= z; | ||
40 | z -= ((x - rx) * (x - rx)) + ((y - ry) * (y - ry)); | ||
41 | |||
42 | if (z < 0) | ||
43 | z = 0; | ||
44 | |||
45 | map[x, y] += (float)(z * amount); | ||
46 | } | ||
47 | } | ||
48 | } | ||
49 | |||
50 | /// <summary> | ||
51 | /// Lowers land in a sphere around the selection | ||
52 | /// </summary> | ||
53 | /// <param name="rx">The center the X coordinate of where you wish to lower the land</param> | ||
54 | /// <param name="ry">The center the Y coordinate of where you wish to lower the land</param> | ||
55 | /// <param name="size">The radius of the sphere dimple</param> | ||
56 | /// <param name="amount">How much impact to remove from the terrain (0..2 usually)</param> | ||
57 | public static void lower(float[,] map, double rx, double ry, double size, double amount) | ||
58 | { | ||
59 | lowerSphere(map, rx, ry, size, amount); | ||
60 | } | ||
61 | |||
62 | /// <summary> | ||
63 | /// Lowers land in a sphere around the selection | ||
64 | /// </summary> | ||
65 | /// <param name="rx">The center the X coordinate of where you wish to lower the land</param> | ||
66 | /// <param name="ry">The center the Y coordinate of where you wish to lower the land</param> | ||
67 | /// <param name="size">The radius of the sphere dimple</param> | ||
68 | /// <param name="amount">How much impact to remove from the terrain (0..2 usually)</param> | ||
69 | public static void lowerSphere(float[,] map, double rx, double ry, double size, double amount) | ||
70 | { | ||
71 | int x, y; | ||
72 | int w = map.GetLength(0); | ||
73 | int h = map.GetLength(1); | ||
74 | |||
75 | for (x = 0; x < w; x++) | ||
76 | { | ||
77 | for (y = 0; y < h; y++) | ||
78 | { | ||
79 | double z = size; | ||
80 | z *= z; | ||
81 | z -= ((x - rx) * (x - rx)) + ((y - ry) * (y - ry)); | ||
82 | |||
83 | if (z < 0) | ||
84 | z = 0; | ||
85 | |||
86 | map[x, y] -= (float)(z * amount); | ||
87 | } | ||
88 | } | ||
89 | } | ||
90 | } | ||
91 | } | ||
diff --git a/OpenSim.Terrain.BasicTerrain/TerrainEngine.cs b/OpenSim.Terrain.BasicTerrain/TerrainEngine.cs new file mode 100644 index 0000000..f805d18 --- /dev/null +++ b/OpenSim.Terrain.BasicTerrain/TerrainEngine.cs | |||
@@ -0,0 +1,64 @@ | |||
1 | using System; | ||
2 | using System.Collections.Generic; | ||
3 | using System.Text; | ||
4 | using OpenSim.Terrain.BasicTerrain; | ||
5 | |||
6 | namespace OpenSim.Terrain | ||
7 | { | ||
8 | public class TerrainEngine | ||
9 | { | ||
10 | public float[,] map; | ||
11 | public float[,] water; | ||
12 | int w, h; | ||
13 | |||
14 | public TerrainEngine() | ||
15 | { | ||
16 | w = 256; | ||
17 | h = 256; | ||
18 | map = new float[w, h]; | ||
19 | water = new float[w, h]; | ||
20 | |||
21 | } | ||
22 | |||
23 | /// <summary> | ||
24 | /// Swaps the references between the height and water buffers to allow you to edit the water heightmap. Remember to swap back when you are done. | ||
25 | /// </summary> | ||
26 | public void swapWaterBuffer() | ||
27 | { | ||
28 | float[,] temp = map; | ||
29 | map = water; | ||
30 | water = temp; | ||
31 | } | ||
32 | |||
33 | /// <summary> | ||
34 | /// Raises land in a sphere around the specified coordinates | ||
35 | /// </summary> | ||
36 | /// <param name="rx">Center of the sphere on the X axis</param> | ||
37 | /// <param name="ry">Center of the sphere on the Y axis</param> | ||
38 | /// <param name="size">The radius of the sphere</param> | ||
39 | /// <param name="amount">Scale the height of the sphere by this amount (recommended 0..2)</param> | ||
40 | public void raise(double rx, double ry, double size, double amount) | ||
41 | { | ||
42 | lock (map) | ||
43 | { | ||
44 | RaiseLower.raiseSphere(this.map, rx, ry, size, amount); | ||
45 | } | ||
46 | } | ||
47 | public void lower(double rx, double ry, double size, double amount) | ||
48 | { | ||
49 | lock (map) | ||
50 | { | ||
51 | RaiseLower.lowerSphere(this.map, rx, ry, size, amount); | ||
52 | } | ||
53 | } | ||
54 | |||
55 | public void hills() | ||
56 | { | ||
57 | lock (map) | ||
58 | { | ||
59 | Hills.hillsSpheres(this.map, 1337, 200, 20, 40, true, true, false); | ||
60 | } | ||
61 | } | ||
62 | |||
63 | } | ||
64 | } | ||
diff --git a/OpenSim.Terrain.BasicTerrain/TerrainManager.cs b/OpenSim.Terrain.BasicTerrain/TerrainManager.cs deleted file mode 100644 index 65880eb..0000000 --- a/OpenSim.Terrain.BasicTerrain/TerrainManager.cs +++ /dev/null | |||
@@ -1,11 +0,0 @@ | |||
1 | using System; | ||
2 | using System.Collections.Generic; | ||
3 | using System.Text; | ||
4 | |||
5 | namespace OpenSim.Terrain | ||
6 | { | ||
7 | public class TerrainManager | ||
8 | { | ||
9 | |||
10 | } | ||
11 | } | ||
diff --git a/OpenSim.Terrain.BasicTerrain/bin/Debug/OpenSim.Terrain.BasicTerrain.dll b/OpenSim.Terrain.BasicTerrain/bin/Debug/OpenSim.Terrain.BasicTerrain.dll new file mode 100644 index 0000000..0cfa595 --- /dev/null +++ b/OpenSim.Terrain.BasicTerrain/bin/Debug/OpenSim.Terrain.BasicTerrain.dll | |||
Binary files differ | |||
diff --git a/OpenSim.Terrain.BasicTerrain/bin/Debug/OpenSim.Terrain.BasicTerrain.pdb b/OpenSim.Terrain.BasicTerrain/bin/Debug/OpenSim.Terrain.BasicTerrain.pdb new file mode 100644 index 0000000..ce440c6 --- /dev/null +++ b/OpenSim.Terrain.BasicTerrain/bin/Debug/OpenSim.Terrain.BasicTerrain.pdb | |||
Binary files differ | |||
diff --git a/OpenSim.Terrain.BasicTerrain/obj/Debug/OpenSim.Terrain.BasicTerrain.dll b/OpenSim.Terrain.BasicTerrain/obj/Debug/OpenSim.Terrain.BasicTerrain.dll new file mode 100644 index 0000000..0cfa595 --- /dev/null +++ b/OpenSim.Terrain.BasicTerrain/obj/Debug/OpenSim.Terrain.BasicTerrain.dll | |||
Binary files differ | |||
diff --git a/OpenSim.Terrain.BasicTerrain/obj/Debug/OpenSim.Terrain.BasicTerrain.pdb b/OpenSim.Terrain.BasicTerrain/obj/Debug/OpenSim.Terrain.BasicTerrain.pdb new file mode 100644 index 0000000..ce440c6 --- /dev/null +++ b/OpenSim.Terrain.BasicTerrain/obj/Debug/OpenSim.Terrain.BasicTerrain.pdb | |||
Binary files differ | |||
diff --git a/OpenSim.Terrain.BasicTerrain/obj/OpenSim.Terrain.BasicTerrain.csproj.FileList.txt b/OpenSim.Terrain.BasicTerrain/obj/OpenSim.Terrain.BasicTerrain.csproj.FileList.txt new file mode 100644 index 0000000..4728b51 --- /dev/null +++ b/OpenSim.Terrain.BasicTerrain/obj/OpenSim.Terrain.BasicTerrain.csproj.FileList.txt | |||
@@ -0,0 +1,5 @@ | |||
1 | bin\Debug\OpenSim.Terrain.BasicTerrain.dll | ||
2 | bin\Debug\OpenSim.Terrain.BasicTerrain.pdb | ||
3 | obj\Debug\ResolveAssemblyReference.cache | ||
4 | obj\Debug\OpenSim.Terrain.BasicTerrain.dll | ||
5 | obj\Debug\OpenSim.Terrain.BasicTerrain.pdb | ||