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/Hills.cs | |
parent | And now for some solution files... (diff) | |
download | opensim-SC_OLD-fb0dffbf13a79aabe9537f16b7bb151af62c75bf.zip opensim-SC_OLD-fb0dffbf13a79aabe9537f16b7bb151af62c75bf.tar.gz opensim-SC_OLD-fb0dffbf13a79aabe9537f16b7bb151af62c75bf.tar.bz2 opensim-SC_OLD-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 |
1 files changed, 72 insertions, 0 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 | } | ||