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