aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Generators
diff options
context:
space:
mode:
authorAdam Frisby2007-07-21 22:25:42 +0000
committerAdam Frisby2007-07-21 22:25:42 +0000
commitf84937367f7180140bd17444d507977f9b7e3d2e (patch)
tree944f2824669e42b5df3b6655bd09999c89b50376 /OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Generators
parent* Renamed terrain functions to match OpenSim naming styles. (diff)
downloadopensim-SC-f84937367f7180140bd17444d507977f9b7e3d2e.zip
opensim-SC-f84937367f7180140bd17444d507977f9b7e3d2e.tar.gz
opensim-SC-f84937367f7180140bd17444d507977f9b7e3d2e.tar.bz2
opensim-SC-f84937367f7180140bd17444d507977f9b7e3d2e.tar.xz
* Deleted libTerrain-BSD.dll
* Added libTerrain to BasicTerrain directly as a subfolder
Diffstat (limited to 'OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Generators')
-rw-r--r--OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Generators/Cellular.cs1
-rw-r--r--OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Generators/Fracture.cs113
-rw-r--r--OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Generators/Gradient.cs67
-rw-r--r--OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Generators/HillPlanter.cs278
-rw-r--r--OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Generators/Midpoint.cs1
-rw-r--r--OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Generators/Mountain.cs1
-rw-r--r--OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Generators/Noise.cs57
-rw-r--r--OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Generators/Spiral.cs152
-rw-r--r--OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Generators/Voronoi.cs212
-rw-r--r--OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Generators/Worms.cs75
10 files changed, 957 insertions, 0 deletions
diff --git a/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Generators/Cellular.cs b/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Generators/Cellular.cs
new file mode 100644
index 0000000..0cec05d
--- /dev/null
+++ b/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Generators/Cellular.cs
@@ -0,0 +1 @@
/* Needs BSD rewrite */ \ No newline at end of file
diff --git a/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Generators/Fracture.cs b/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Generators/Fracture.cs
new file mode 100644
index 0000000..2a24ecf
--- /dev/null
+++ b/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Generators/Fracture.cs
@@ -0,0 +1,113 @@
1/*
2Redistribution and use in source and binary forms, with or without
3modification, are permitted provided that the following conditions are
4met:
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
19THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
21LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
22A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
23OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
24SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
25LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30*/
31
32using System;
33using System.Collections.Generic;
34using System.Text;
35
36namespace libTerrain
37{
38 partial class Channel
39 {
40 /// <summary>
41 /// Produces a set of coordinates defined by an edge point. Eg - 0 = 0,0. 256 = 0,256. 512 = 256,256
42 /// Assumes a 256^2 heightmap. This needs fixing for input values of w,h
43 /// </summary>
44 /// <param name="val"></param>
45 /// <param name="w"></param>
46 /// <param name="h"></param>
47 /// <returns></returns>
48 private int[] radialEdge256(int val)
49 {
50 // Four cases:
51 // 1. 000..255 return 0,val
52 // 2. 256..511 return val - 256,255
53 // 3. 512..767 return 255, val - 511
54 // 4. 768..1023 return val - 768,0
55
56 int[] ret = new int[2];
57
58 if (val < 256)
59 {
60 ret[0] = 0;
61 ret[1] = val;
62 return ret;
63 }
64 if (val < 512)
65 {
66 ret[0] = (val % 256);
67 ret[1] = 255;
68 return ret;
69 }
70 if (val < 768)
71 {
72 ret[0] = 255;
73 ret[1] = 255 - (val % 256);
74 return ret;
75 }
76 if (val < 1024)
77 {
78 ret[0] = 255 - (val % 256);
79 ret[1] = 255;
80 return ret;
81 }
82
83 throw new Exception("Out of bounds parameter (val)");
84 }
85 public void fracture(int number, double scalemin, double scalemax)
86 {
87 Random rand = new Random(seed);
88
89 for (int i = 0; i < number; i++)
90 {
91 int[] a, b;
92
93 a = radialEdge256(rand.Next(1023)); // TODO: Broken
94 b = radialEdge256(rand.Next(1023)); // TODO: Broken
95 double z = rand.NextDouble();
96
97 for (int x = 0; x < w; x++)
98 {
99 for (int y = 0; y < h; y++)
100 {
101 double miny = Tools.linearInterpolate(a[1], b[1], (double)x / (double)w);
102
103 if (y > miny)
104 {
105 map[x, y] += Tools.linearInterpolate(scalemin, scalemax, z);
106 }
107 }
108 }
109 }
110 normalise();
111 }
112 }
113} \ No newline at end of file
diff --git a/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Generators/Gradient.cs b/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Generators/Gradient.cs
new file mode 100644
index 0000000..8f45bf7
--- /dev/null
+++ b/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Generators/Gradient.cs
@@ -0,0 +1,67 @@
1/*
2Redistribution and use in source and binary forms, with or without
3modification, are permitted provided that the following conditions are
4met:
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
19THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
21LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
22A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
23OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
24SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
25LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30*/
31
32using System;
33using System.Collections.Generic;
34using System.Text;
35
36namespace libTerrain
37{
38 partial class Channel
39 {
40
41 public void gradientCube()
42 {
43 int x, y;
44 for (x = 0; x < w; x++)
45 {
46 for (y = 0; y < h; y++)
47 {
48 map[x, y] = x*y;
49 }
50 }
51 normalise();
52 }
53
54 public void gradientStripe()
55 {
56 int x, y;
57 for (x = 0; x < w; x++)
58 {
59 for (y = 0; y < h; y++)
60 {
61 map[x, y] = x;
62 }
63 }
64 normalise();
65 }
66 }
67} \ No newline at end of file
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/*
2Redistribution and use in source and binary forms, with or without
3modification, are permitted provided that the following conditions are
4met:
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
19THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
21LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
22A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
23OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
24SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
25LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30*/
31
32using System;
33using System.Collections.Generic;
34using System.Text;
35
36namespace 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}
diff --git a/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Generators/Midpoint.cs b/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Generators/Midpoint.cs
new file mode 100644
index 0000000..0cec05d
--- /dev/null
+++ b/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Generators/Midpoint.cs
@@ -0,0 +1 @@
/* Needs BSD rewrite */ \ No newline at end of file
diff --git a/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Generators/Mountain.cs b/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Generators/Mountain.cs
new file mode 100644
index 0000000..0cec05d
--- /dev/null
+++ b/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Generators/Mountain.cs
@@ -0,0 +1 @@
/* Needs BSD rewrite */ \ No newline at end of file
diff --git a/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Generators/Noise.cs b/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Generators/Noise.cs
new file mode 100644
index 0000000..7789d3e
--- /dev/null
+++ b/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Generators/Noise.cs
@@ -0,0 +1,57 @@
1/*
2Redistribution and use in source and binary forms, with or without
3modification, are permitted provided that the following conditions are
4met:
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
19THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
21LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
22A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
23OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
24SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
25LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30*/
31
32using System;
33using System.Collections.Generic;
34using System.Text;
35
36namespace libTerrain
37{
38 partial class Channel
39 {
40 /// <summary>
41 /// Fills a channel with 0..1 noise
42 /// </summary>
43 /// <remarks>3-Clause BSD Licensed</remarks>
44 public void noise()
45 {
46 Random rand = new Random(seed);
47 int x, y;
48 for (x = 0; x < w; x++)
49 {
50 for (y = 0; y < h; y++)
51 {
52 map[x, y] = rand.NextDouble();
53 }
54 }
55 }
56 }
57}
diff --git a/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Generators/Spiral.cs b/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Generators/Spiral.cs
new file mode 100644
index 0000000..ede4600
--- /dev/null
+++ b/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Generators/Spiral.cs
@@ -0,0 +1,152 @@
1/*
2Redistribution and use in source and binary forms, with or without
3modification, are permitted provided that the following conditions are
4met:
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
19THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
21LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
22A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
23OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
24SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
25LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30*/
31
32using System;
33using System.Collections.Generic;
34using System.Text;
35
36namespace libTerrain
37{
38 partial class Channel
39 {
40 private double[] coordinatesToPolar(int x, int y)
41 {
42
43 double theta = Math.Atan2(x - (w / 2), y - (h / 2));
44 double rx = (double)x - ((double)w / 2);
45 double ry = (double)y - ((double)h / 2);
46 double r = Math.Sqrt((rx * rx) + (ry * ry));
47
48 double[] coords = new double[2];
49 coords[0] = r;
50 coords[1] = theta;
51 return coords;
52 }
53
54 public int[] polarToCoordinates(double r, double theta) {
55 double nx;
56 double ny;
57
58 nx = (double)r * Math.Cos(theta);
59 ny = (double)r * Math.Sin(theta);
60
61 nx += w / 2;
62 ny += h / 2;
63
64 if (nx >= w)
65 nx = w - 1;
66
67 if (ny >= h)
68 ny = h - 1;
69
70 if (nx < 0)
71 nx = 0;
72
73 if (ny < 0)
74 ny = 0;
75
76 int[] coords = new int[2];
77 coords[0] = (int)nx;
78 coords[1] = (int)ny;
79 return coords;
80 }
81
82 public void Polar()
83 {
84 Channel n = this.copy();
85
86 int x, y;
87 for (x = 0; x < w; x++)
88 {
89 for (y = 0; y < h; y++)
90 {
91 double[] coords = coordinatesToPolar(x,y);
92
93 coords[0] += w / 2.0;
94 coords[1] += h / 2.0;
95
96 map[x, y] = n.map[(int)coords[0] % n.w, (int)coords[1] % n.h];
97 }
98 }
99 }
100
101 public void SpiralPlanter(int steps, double incAngle, double incRadius, double offsetRadius, double offsetAngle)
102 {
103 int i;
104 double r = offsetRadius;
105 double theta = offsetAngle;
106 for (i = 0; i < steps; i++)
107 {
108 r += incRadius;
109 theta += incAngle;
110
111 int[] coords = polarToCoordinates(r,theta);
112 raise(coords[0], coords[1], 20, 1);
113 }
114 }
115
116 public void SpiralCells(int steps, double incAngle, double incRadius, double offsetRadius, double offsetAngle, double[] c)
117 {
118 List<Point2D> points = new List<Point2D>();
119
120 int i;
121 double r = offsetRadius;
122 double theta = offsetAngle;
123 for (i = 0; i < steps; i++)
124 {
125 r += incRadius;
126 theta += incAngle;
127
128 int[] coords = polarToCoordinates(r, theta);
129 points.Add(new Point2D(coords[0],coords[1]));
130 }
131
132 voronoiDiagram(points, c);
133 }
134
135 public void Spiral(double wid, double hig, double offset)
136 {
137 int x, y, z;
138 z = 0;
139 for (x = 0; x < w; x++)
140 {
141 for (y = 0; y < h; y++)
142 {
143 z++;
144 double dx = Math.Abs((w / 2) - x);
145 double dy = Math.Abs((h / 2) - y);
146 map[x, y] += Math.Sin(dx / wid) + Math.Cos(dy / hig);
147 }
148 }
149 normalise();
150 }
151 }
152} \ No newline at end of file
diff --git a/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Generators/Voronoi.cs b/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Generators/Voronoi.cs
new file mode 100644
index 0000000..df21ecc
--- /dev/null
+++ b/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Generators/Voronoi.cs
@@ -0,0 +1,212 @@
1/*
2Redistribution and use in source and binary forms, with or without
3modification, are permitted provided that the following conditions are
4met:
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
19THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
21LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
22A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
23OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
24SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
25LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30*/
31
32using System;
33using System.Collections.Generic;
34using System.Text;
35
36namespace libTerrain
37{
38 partial class Channel
39 {
40 /// <summary>
41 /// Generates a Voronoi diagram (sort of a stained glass effect) which will fill the entire channel
42 /// </summary>
43 /// <remarks>3-Clause BSD Licensed</remarks>
44 /// <param name="pointsPerBlock">The number of generator points in each block</param>
45 /// <param name="blockSize">A multiple of the channel width and height which will have voronoi points generated in it.
46 /// <para>This is to ensure a more even distribution of the points than pure random allocation.</para></param>
47 /// <param name="c">The Voronoi diagram type. Usually an array with values consisting of [-1,1]. Experiment with the chain, you can have as many values as you like.</param>
48 public void voronoiDiagram(int pointsPerBlock, int blockSize, double[] c)
49 {
50 List<Point2D> points = new List<Point2D>();
51 Random generator = new Random(seed);
52
53 // Generate the emitter points
54 int x, y, i;
55 for (x = -blockSize; x < w + blockSize; x += blockSize)
56 {
57 for (y = -blockSize; y < h + blockSize; y += blockSize)
58 {
59 for (i = 0; i < pointsPerBlock; i++)
60 {
61 double pX = x + (generator.NextDouble() * (double)blockSize);
62 double pY = y + (generator.NextDouble() * (double)blockSize);
63
64 points.Add(new Point2D(pX, pY));
65 }
66 }
67 }
68
69 double[] distances = new double[points.Count];
70
71 // Calculate the distance each pixel is from an emitter
72 for (x = 0; x < w; x++)
73 {
74 for (y = 0; y < h; y++)
75 {
76 for (i = 0; i < points.Count; i++)
77 {
78 double dx, dy;
79 dx = Math.Abs((double)x - points[i].x);
80 dy = Math.Abs((double)y - points[i].y);
81
82 distances[i] = (dx * dx + dy * dy);
83 }
84
85 Array.Sort(distances);
86
87 double f = 0.0;
88
89 // Multiply the distances with their 'c' counterpart
90 // ordering the distances descending
91 for (i = 0; i < c.Length; i++)
92 {
93 if (i >= points.Count)
94 break;
95
96 f += c[i] * distances[i];
97 }
98
99 map[x, y] = f;
100 }
101 }
102
103 // Normalise the result
104 normalise();
105 }
106
107 public void voronoiDiagram(List<Point2D> points, double[] c)
108 {
109
110 Random generator = new Random(seed);
111 int x, y, i;
112 double[] distances = new double[points.Count];
113
114 // Calculate the distance each pixel is from an emitter
115 for (x = 0; x < w; x++)
116 {
117 for (y = 0; y < h; y++)
118 {
119 for (i = 0; i < points.Count; i++)
120 {
121 double dx, dy;
122 dx = Math.Abs((double)x - points[i].x);
123 dy = Math.Abs((double)y - points[i].y);
124
125 distances[i] = (dx * dx + dy * dy);
126 }
127
128 Array.Sort(distances);
129
130 double f = 0.0;
131
132 // Multiply the distances with their 'c' counterpart
133 // ordering the distances descending
134 for (i = 0; i < c.Length; i++)
135 {
136 if (i >= points.Count)
137 break;
138
139 f += c[i] * distances[i];
140 }
141
142 map[x, y] = f;
143 }
144 }
145
146 // Normalise the result
147 normalise();
148 }
149
150 public void voroflatDiagram(int pointsPerBlock, int blockSize)
151 {
152 List<Point2D> points = new List<Point2D>();
153 Random generator = new Random(seed);
154
155 // Generate the emitter points
156 int x, y, i;
157 for (x = -blockSize; x < w + blockSize; x += blockSize)
158 {
159 for (y = -blockSize; y < h + blockSize; y += blockSize)
160 {
161 for (i = 0; i < pointsPerBlock; i++)
162 {
163 double pX = x + (generator.NextDouble() * (double)blockSize);
164 double pY = y + (generator.NextDouble() * (double)blockSize);
165
166 points.Add(new Point2D(pX, pY));
167 }
168 }
169 }
170
171 double[] distances = new double[points.Count];
172
173 // Calculate the distance each pixel is from an emitter
174 for (x = 0; x < w; x++)
175 {
176 for (y = 0; y < h; y++)
177 {
178 for (i = 0; i < points.Count; i++)
179 {
180 double dx, dy;
181 dx = Math.Abs((double)x - points[i].x);
182 dy = Math.Abs((double)y - points[i].y);
183
184 distances[i] = (dx * dx + dy * dy);
185 }
186
187 //Array.Sort(distances);
188
189 double f = 0.0;
190
191 double min = double.MaxValue;
192 for (int j = 0; j < distances.Length;j++ )
193 {
194 if (distances[j] < min)
195 {
196 min = distances[j];
197 f = j;
198 }
199 }
200
201 // Multiply the distances with their 'c' counterpart
202 // ordering the distances descending
203
204 map[x, y] = f;
205 }
206 }
207
208 // Normalise the result
209 normalise();
210 }
211 }
212}
diff --git a/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Generators/Worms.cs b/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Generators/Worms.cs
new file mode 100644
index 0000000..a54c946
--- /dev/null
+++ b/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Generators/Worms.cs
@@ -0,0 +1,75 @@
1/*
2Redistribution and use in source and binary forms, with or without
3modification, are permitted provided that the following conditions are
4met:
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
19THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
21LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
22A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
23OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
24SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
25LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30*/
31
32using System;
33using System.Collections.Generic;
34using System.Text;
35
36namespace libTerrain
37{
38 partial class Channel
39 {
40 /// <summary>
41 /// Generates 'number' of worms which navigate randomly around the landscape creating terrain as they go.
42 /// </summary>
43 /// <param name="number">The number of worms which will traverse the map</param>
44 /// <param name="rounds">The number of steps each worm will traverse</param>
45 /// <param name="movement">The maximum distance each worm will move each step</param>
46 /// <param name="size">The size of the area around the worm modified</param>
47 /// <param name="centerspawn">Do worms start in the middle, or randomly?</param>
48 public void worms(int number, int rounds, double movement, double size, bool centerspawn)
49 {
50 Random random = new Random(seed);
51 int i, j;
52
53 for (i = 0; i < number; i++)
54 {
55 double rx, ry;
56 if (centerspawn)
57 {
58 rx = w / 2.0;
59 ry = h / 2.0;
60 }
61 else
62 {
63 rx = random.NextDouble() * (w - 1);
64 ry = random.NextDouble() * (h - 1);
65 }
66 for (j = 0; j < rounds; j++)
67 {
68 rx += (random.NextDouble() * movement) - (movement / 2.0);
69 ry += (random.NextDouble() * movement) - (movement / 2.0);
70 raise(rx, ry, size, 1.0);
71 }
72 }
73 }
74 }
75} \ No newline at end of file