diff options
Diffstat (limited to 'OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Generators/HillPlanter.cs')
-rw-r--r-- | OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Generators/HillPlanter.cs | 566 |
1 files changed, 283 insertions, 283 deletions
diff --git a/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Generators/HillPlanter.cs b/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Generators/HillPlanter.cs index 5a697b1..aa18e40 100644 --- a/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Generators/HillPlanter.cs +++ b/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Generators/HillPlanter.cs | |||
@@ -1,283 +1,283 @@ | |||
1 | /* | 1 | /* |
2 | * Copyright (c) Contributors, http://www.openmetaverse.org/ | 2 | * Copyright (c) Contributors, http://www.openmetaverse.org/ |
3 | * See CONTRIBUTORS.TXT for a full list of copyright holders. | 3 | * See CONTRIBUTORS.TXT for a full list of copyright holders. |
4 | * | 4 | * |
5 | * Redistribution and use in source and binary forms, with or without | 5 | * Redistribution and use in source and binary forms, with or without |
6 | * modification, are permitted provided that the following conditions are met: | 6 | * modification, are permitted provided that the following conditions are met: |
7 | * * Redistributions of source code must retain the above copyright | 7 | * * Redistributions of source code must retain the above copyright |
8 | * notice, this list of conditions and the following disclaimer. | 8 | * notice, this list of conditions and the following disclaimer. |
9 | * * Redistributions in binary form must reproduce the above copyright | 9 | * * Redistributions in binary form must reproduce the above copyright |
10 | * notice, this list of conditions and the following disclaimer in the | 10 | * notice, this list of conditions and the following disclaimer in the |
11 | * documentation and/or other materials provided with the distribution. | 11 | * documentation and/or other materials provided with the distribution. |
12 | * * Neither the name of the OpenSim Project nor the | 12 | * * Neither the name of the OpenSim Project nor the |
13 | * names of its contributors may be used to endorse or promote products | 13 | * names of its contributors may be used to endorse or promote products |
14 | * derived from this software without specific prior written permission. | 14 | * derived from this software without specific prior written permission. |
15 | * | 15 | * |
16 | * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS AND ANY | 16 | * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS AND ANY |
17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | 17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | 18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
19 | * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY | 19 | * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY |
20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | 20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES |
21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | 21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; |
22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | 22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND |
23 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 23 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | 24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
26 | * | 26 | * |
27 | */ | 27 | */ |
28 | 28 | ||
29 | using System; | 29 | using System; |
30 | using System.Collections.Generic; | 30 | using System.Collections.Generic; |
31 | using System.Text; | 31 | using System.Text; |
32 | 32 | ||
33 | namespace libTerrain | 33 | namespace libTerrain |
34 | { | 34 | { |
35 | partial class Channel | 35 | partial class Channel |
36 | { | 36 | { |
37 | /// <summary> | 37 | /// <summary> |
38 | /// Generates a series of spheres which are then either max()'d or added together. Inspired by suggestion from jh. | 38 | /// Generates a series of spheres which are then either max()'d or added together. Inspired by suggestion from jh. |
39 | /// </summary> | 39 | /// </summary> |
40 | /// <remarks>3-Clause BSD Licensed</remarks> | 40 | /// <remarks>3-Clause BSD Licensed</remarks> |
41 | /// <param name="number">The number of hills to generate</param> | 41 | /// <param name="number">The number of hills to generate</param> |
42 | /// <param name="scale_min">The minimum size of each hill</param> | 42 | /// <param name="scale_min">The minimum size of each hill</param> |
43 | /// <param name="scale_range">The maximum size of each hill</param> | 43 | /// <param name="scale_range">The maximum size of each hill</param> |
44 | /// <param name="island">Whether to bias hills towards the center of the map</param> | 44 | /// <param name="island">Whether to bias hills towards the center of the map</param> |
45 | /// <param name="additive">Whether to add hills together or to pick the largest value</param> | 45 | /// <param name="additive">Whether to add hills together or to pick the largest value</param> |
46 | /// <param name="noisy">Generates hill-shaped noise instead of consistent hills</param> | 46 | /// <param name="noisy">Generates hill-shaped noise instead of consistent hills</param> |
47 | public void HillsSpheres(int number, double scale_min, double scale_range, bool island, bool additive, bool noisy) | 47 | public void HillsSpheres(int number, double scale_min, double scale_range, bool island, bool additive, bool noisy) |
48 | { | 48 | { |
49 | SetDiff(); | 49 | SetDiff(); |
50 | 50 | ||
51 | Random random = new Random(seed); | 51 | Random random = new Random(seed); |
52 | 52 | ||
53 | int x, y; | 53 | int x, y; |
54 | int i; | 54 | int i; |
55 | 55 | ||
56 | for (i = 0; i < number; i++) | 56 | for (i = 0; i < number; i++) |
57 | { | 57 | { |
58 | double rx = Math.Min(255.0, random.NextDouble() * w); | 58 | double rx = Math.Min(255.0, random.NextDouble() * w); |
59 | double ry = Math.Min(255.0, random.NextDouble() * h); | 59 | double ry = Math.Min(255.0, random.NextDouble() * h); |
60 | double rand = random.NextDouble(); | 60 | double rand = random.NextDouble(); |
61 | 61 | ||
62 | if (island) | 62 | if (island) |
63 | { | 63 | { |
64 | // Move everything towards the center | 64 | // Move everything towards the center |
65 | rx -= w / 2; | 65 | rx -= w / 2; |
66 | rx /= 2; | 66 | rx /= 2; |
67 | rx += w / 2; | 67 | rx += w / 2; |
68 | 68 | ||
69 | ry -= h / 2; | 69 | ry -= h / 2; |
70 | ry /= 2; | 70 | ry /= 2; |
71 | ry += h / 2; | 71 | ry += h / 2; |
72 | } | 72 | } |
73 | 73 | ||
74 | for (x = 0; x < w; x++) | 74 | for (x = 0; x < w; x++) |
75 | { | 75 | { |
76 | for (y = 0; y < h; y++) | 76 | for (y = 0; y < h; y++) |
77 | { | 77 | { |
78 | if (noisy) | 78 | if (noisy) |
79 | rand = random.NextDouble(); | 79 | rand = random.NextDouble(); |
80 | 80 | ||
81 | double z = (scale_min + (scale_range * rand)); | 81 | double z = (scale_min + (scale_range * rand)); |
82 | z *= z; | 82 | z *= z; |
83 | z -= ((x - rx) * (x - rx)) + ((y - ry) * (y - ry)); | 83 | z -= ((x - rx) * (x - rx)) + ((y - ry) * (y - ry)); |
84 | 84 | ||
85 | if (z < 0) | 85 | if (z < 0) |
86 | z = 0; | 86 | z = 0; |
87 | 87 | ||
88 | if (additive) | 88 | if (additive) |
89 | { | 89 | { |
90 | map[x, y] += z; | 90 | map[x, y] += z; |
91 | } | 91 | } |
92 | else | 92 | else |
93 | { | 93 | { |
94 | map[x, y] = Math.Max(map[x, y], z); | 94 | map[x, y] = Math.Max(map[x, y], z); |
95 | } | 95 | } |
96 | } | 96 | } |
97 | } | 97 | } |
98 | } | 98 | } |
99 | 99 | ||
100 | Normalise(); | 100 | Normalise(); |
101 | } | 101 | } |
102 | 102 | ||
103 | /// <summary> | 103 | /// <summary> |
104 | /// Generates a series of cones which are then either max()'d or added together. Inspired by suggestion from jh. | 104 | /// Generates a series of cones which are then either max()'d or added together. Inspired by suggestion from jh. |
105 | /// </summary> | 105 | /// </summary> |
106 | /// <remarks>3-Clause BSD Licensed</remarks> | 106 | /// <remarks>3-Clause BSD Licensed</remarks> |
107 | /// <param name="number">The number of hills to generate</param> | 107 | /// <param name="number">The number of hills to generate</param> |
108 | /// <param name="scale_min">The minimum size of each hill</param> | 108 | /// <param name="scale_min">The minimum size of each hill</param> |
109 | /// <param name="scale_range">The maximum size of each hill</param> | 109 | /// <param name="scale_range">The maximum size of each hill</param> |
110 | /// <param name="island">Whether to bias hills towards the center of the map</param> | 110 | /// <param name="island">Whether to bias hills towards the center of the map</param> |
111 | /// <param name="additive">Whether to add hills together or to pick the largest value</param> | 111 | /// <param name="additive">Whether to add hills together or to pick the largest value</param> |
112 | /// <param name="noisy">Generates hill-shaped noise instead of consistent hills</param> | 112 | /// <param name="noisy">Generates hill-shaped noise instead of consistent hills</param> |
113 | public void HillsCones(int number, double scale_min, double scale_range, bool island, bool additive, bool noisy) | 113 | public void HillsCones(int number, double scale_min, double scale_range, bool island, bool additive, bool noisy) |
114 | { | 114 | { |
115 | SetDiff(); | 115 | SetDiff(); |
116 | 116 | ||
117 | Random random = new Random(seed); | 117 | Random random = new Random(seed); |
118 | 118 | ||
119 | int x, y; | 119 | int x, y; |
120 | int i; | 120 | int i; |
121 | 121 | ||
122 | for (i = 0; i < number; i++) | 122 | for (i = 0; i < number; i++) |
123 | { | 123 | { |
124 | double rx = Math.Min(255.0, random.NextDouble() * w); | 124 | double rx = Math.Min(255.0, random.NextDouble() * w); |
125 | double ry = Math.Min(255.0, random.NextDouble() * h); | 125 | double ry = Math.Min(255.0, random.NextDouble() * h); |
126 | double rand = random.NextDouble(); | 126 | double rand = random.NextDouble(); |
127 | 127 | ||
128 | if (island) | 128 | if (island) |
129 | { | 129 | { |
130 | // Move everything towards the center | 130 | // Move everything towards the center |
131 | rx -= w / 2; | 131 | rx -= w / 2; |
132 | rx /= 2; | 132 | rx /= 2; |
133 | rx += w / 2; | 133 | rx += w / 2; |
134 | 134 | ||
135 | ry -= h / 2; | 135 | ry -= h / 2; |
136 | ry /= 2; | 136 | ry /= 2; |
137 | ry += h / 2; | 137 | ry += h / 2; |
138 | } | 138 | } |
139 | 139 | ||
140 | for (x = 0; x < w; x++) | 140 | for (x = 0; x < w; x++) |
141 | { | 141 | { |
142 | for (y = 0; y < h; y++) | 142 | for (y = 0; y < h; y++) |
143 | { | 143 | { |
144 | if (noisy) | 144 | if (noisy) |
145 | rand = random.NextDouble(); | 145 | rand = random.NextDouble(); |
146 | 146 | ||
147 | double z = (scale_min + (scale_range * rand)); | 147 | double z = (scale_min + (scale_range * rand)); |
148 | z -= Math.Sqrt(((x - rx) * (x - rx)) + ((y - ry) * (y - ry))); | 148 | z -= Math.Sqrt(((x - rx) * (x - rx)) + ((y - ry) * (y - ry))); |
149 | 149 | ||
150 | if (z < 0) | 150 | if (z < 0) |
151 | z = 0; | 151 | z = 0; |
152 | 152 | ||
153 | if (additive) | 153 | if (additive) |
154 | { | 154 | { |
155 | map[x, y] += z; | 155 | map[x, y] += z; |
156 | } | 156 | } |
157 | else | 157 | else |
158 | { | 158 | { |
159 | map[x, y] = Math.Max(map[x, y], z); | 159 | map[x, y] = Math.Max(map[x, y], z); |
160 | } | 160 | } |
161 | } | 161 | } |
162 | } | 162 | } |
163 | } | 163 | } |
164 | 164 | ||
165 | Normalise(); | 165 | Normalise(); |
166 | } | 166 | } |
167 | 167 | ||
168 | public void HillsBlocks(int number, double scale_min, double scale_range, bool island, bool additive, bool noisy) | 168 | public void HillsBlocks(int number, double scale_min, double scale_range, bool island, bool additive, bool noisy) |
169 | { | 169 | { |
170 | SetDiff(); | 170 | SetDiff(); |
171 | 171 | ||
172 | Random random = new Random(seed); | 172 | Random random = new Random(seed); |
173 | 173 | ||
174 | int x, y; | 174 | int x, y; |
175 | int i; | 175 | int i; |
176 | 176 | ||
177 | for (i = 0; i < number; i++) | 177 | for (i = 0; i < number; i++) |
178 | { | 178 | { |
179 | double rx = Math.Min(255.0, random.NextDouble() * w); | 179 | double rx = Math.Min(255.0, random.NextDouble() * w); |
180 | double ry = Math.Min(255.0, random.NextDouble() * h); | 180 | double ry = Math.Min(255.0, random.NextDouble() * h); |
181 | double rand = random.NextDouble(); | 181 | double rand = random.NextDouble(); |
182 | 182 | ||
183 | if (island) | 183 | if (island) |
184 | { | 184 | { |
185 | // Move everything towards the center | 185 | // Move everything towards the center |
186 | rx -= w / 2; | 186 | rx -= w / 2; |
187 | rx /= 2; | 187 | rx /= 2; |
188 | rx += w / 2; | 188 | rx += w / 2; |
189 | 189 | ||
190 | ry -= h / 2; | 190 | ry -= h / 2; |
191 | ry /= 2; | 191 | ry /= 2; |
192 | ry += h / 2; | 192 | ry += h / 2; |
193 | } | 193 | } |
194 | 194 | ||
195 | for (x = 0; x < w; x++) | 195 | for (x = 0; x < w; x++) |
196 | { | 196 | { |
197 | for (y = 0; y < h; y++) | 197 | for (y = 0; y < h; y++) |
198 | { | 198 | { |
199 | if (noisy) | 199 | if (noisy) |
200 | rand = random.NextDouble(); | 200 | rand = random.NextDouble(); |
201 | 201 | ||
202 | double z = (scale_min + (scale_range * rand)); | 202 | double z = (scale_min + (scale_range * rand)); |
203 | z -= Math.Abs(x-rx) + Math.Abs(y-ry); | 203 | z -= Math.Abs(x-rx) + Math.Abs(y-ry); |
204 | //z -= Math.Sqrt(((x - rx) * (x - rx)) + ((y - ry) * (y - ry))); | 204 | //z -= Math.Sqrt(((x - rx) * (x - rx)) + ((y - ry) * (y - ry))); |
205 | 205 | ||
206 | if (z < 0) | 206 | if (z < 0) |
207 | z = 0; | 207 | z = 0; |
208 | 208 | ||
209 | if (additive) | 209 | if (additive) |
210 | { | 210 | { |
211 | map[x, y] += z; | 211 | map[x, y] += z; |
212 | } | 212 | } |
213 | else | 213 | else |
214 | { | 214 | { |
215 | map[x, y] = Math.Max(map[x, y], z); | 215 | map[x, y] = Math.Max(map[x, y], z); |
216 | } | 216 | } |
217 | } | 217 | } |
218 | } | 218 | } |
219 | } | 219 | } |
220 | 220 | ||
221 | Normalise(); | 221 | Normalise(); |
222 | } | 222 | } |
223 | 223 | ||
224 | public void HillsSquared(int number, double scale_min, double scale_range, bool island, bool additive, bool noisy) | 224 | public void HillsSquared(int number, double scale_min, double scale_range, bool island, bool additive, bool noisy) |
225 | { | 225 | { |
226 | SetDiff(); | 226 | SetDiff(); |
227 | 227 | ||
228 | Random random = new Random(seed); | 228 | Random random = new Random(seed); |
229 | 229 | ||
230 | int x, y; | 230 | int x, y; |
231 | int i; | 231 | int i; |
232 | 232 | ||
233 | for (i = 0; i < number; i++) | 233 | for (i = 0; i < number; i++) |
234 | { | 234 | { |
235 | double rx = Math.Min(255.0, random.NextDouble() * w); | 235 | double rx = Math.Min(255.0, random.NextDouble() * w); |
236 | double ry = Math.Min(255.0, random.NextDouble() * h); | 236 | double ry = Math.Min(255.0, random.NextDouble() * h); |
237 | double rand = random.NextDouble(); | 237 | double rand = random.NextDouble(); |
238 | 238 | ||
239 | if (island) | 239 | if (island) |
240 | { | 240 | { |
241 | // Move everything towards the center | 241 | // Move everything towards the center |
242 | rx -= w / 2; | 242 | rx -= w / 2; |
243 | rx /= 2; | 243 | rx /= 2; |
244 | rx += w / 2; | 244 | rx += w / 2; |
245 | 245 | ||
246 | ry -= h / 2; | 246 | ry -= h / 2; |
247 | ry /= 2; | 247 | ry /= 2; |
248 | ry += h / 2; | 248 | ry += h / 2; |
249 | } | 249 | } |
250 | 250 | ||
251 | for (x = 0; x < w; x++) | 251 | for (x = 0; x < w; x++) |
252 | { | 252 | { |
253 | for (y = 0; y < h; y++) | 253 | for (y = 0; y < h; y++) |
254 | { | 254 | { |
255 | if (noisy) | 255 | if (noisy) |
256 | rand = random.NextDouble(); | 256 | rand = random.NextDouble(); |
257 | 257 | ||
258 | double z = (scale_min + (scale_range * rand)); | 258 | double z = (scale_min + (scale_range * rand)); |
259 | z *= z * z * z; | 259 | z *= z * z * z; |
260 | double dx = Math.Abs(x - rx); | 260 | double dx = Math.Abs(x - rx); |
261 | double dy = Math.Abs(y - ry); | 261 | double dy = Math.Abs(y - ry); |
262 | z -= (dx * dx * dx * dx) + (dy * dy * dy * dy); | 262 | z -= (dx * dx * dx * dx) + (dy * dy * dy * dy); |
263 | 263 | ||
264 | if (z < 0) | 264 | if (z < 0) |
265 | z = 0; | 265 | z = 0; |
266 | 266 | ||
267 | if (additive) | 267 | if (additive) |
268 | { | 268 | { |
269 | map[x, y] += z; | 269 | map[x, y] += z; |
270 | } | 270 | } |
271 | else | 271 | else |
272 | { | 272 | { |
273 | map[x, y] = Math.Max(map[x, y], z); | 273 | map[x, y] = Math.Max(map[x, y], z); |
274 | } | 274 | } |
275 | } | 275 | } |
276 | } | 276 | } |
277 | } | 277 | } |
278 | 278 | ||
279 | Normalise(); | 279 | Normalise(); |
280 | } | 280 | } |
281 | 281 | ||
282 | } | 282 | } |
283 | } | 283 | } |