aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--OpenSim/Region/Terrain.BasicTerrain/TerrainEngine.cs4
-rw-r--r--OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Bitmap/Bitmap.cs77
-rw-r--r--OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Channel.cs66
-rw-r--r--OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Common.cs228
-rw-r--r--OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Editing/Flatten.cs102
-rw-r--r--OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Editing/Raise.cs142
-rw-r--r--OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/File.cs75
-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
-rw-r--r--OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Grid.cs264
-rw-r--r--OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Manipulators/AerobicErosion.cs170
-rw-r--r--OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Manipulators/HydraulicErosion.cs1
-rw-r--r--OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Manipulators/ThermalWeathering.cs113
-rw-r--r--OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Neighbours.cs144
-rw-r--r--OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Operators.cs221
-rw-r--r--OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Tools/Point2D.cs49
-rw-r--r--OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Tools/Tools.cs60
25 files changed, 2671 insertions, 2 deletions
diff --git a/OpenSim/Region/Terrain.BasicTerrain/TerrainEngine.cs b/OpenSim/Region/Terrain.BasicTerrain/TerrainEngine.cs
index f965c41..7eb90a8 100644
--- a/OpenSim/Region/Terrain.BasicTerrain/TerrainEngine.cs
+++ b/OpenSim/Region/Terrain.BasicTerrain/TerrainEngine.cs
@@ -111,11 +111,11 @@ namespace OpenSim.Region.Terrain
111 { 111 {
112 if ((heightmap.get(x, y) > revertmap.get(x, y) + maxRaise)) 112 if ((heightmap.get(x, y) > revertmap.get(x, y) + maxRaise))
113 { 113 {
114 heightmap.map[x, y] = revertmap(x, y) + maxRaise; 114 heightmap.map[x, y] = revertmap.get(x, y) + maxRaise;
115 } 115 }
116 if ((heightmap.get(x, y) > revertmap.get(x, y) - minLower)) 116 if ((heightmap.get(x, y) > revertmap.get(x, y) - minLower))
117 { 117 {
118 heightmap.map[x, y] = revertmap(x, y) - minLower; 118 heightmap.map[x, y] = revertmap.get(x, y) - minLower;
119 } 119 }
120 } 120 }
121 } 121 }
diff --git a/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Bitmap/Bitmap.cs b/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Bitmap/Bitmap.cs
new file mode 100644
index 0000000..923da47
--- /dev/null
+++ b/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Bitmap/Bitmap.cs
@@ -0,0 +1,77 @@
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;
35using System.Drawing;
36
37namespace libTerrain
38{
39 class Raster
40 {
41 int w;
42 int h;
43 Bitmap bmp;
44
45 public Raster(int width, int height)
46 {
47 w = width;
48 h = height;
49 bmp = new Bitmap(width, height, System.Drawing.Imaging.PixelFormat.Format24bppRgb);
50 }
51
52 public Channel toChannel()
53 {
54 Channel chan = new Channel(bmp.Width, bmp.Height);
55
56 int x, y;
57 for (x = 0; x < bmp.Width; x++)
58 {
59 for (y = 0; y < bmp.Height; y++)
60 {
61 Color val = bmp.GetPixel(x, y);
62 chan.map[x, y] = (((double)val.R + (double)val.G + (double)val.B) / 3.0) / 255.0;
63 }
64 }
65
66 return chan;
67 }
68
69 public void drawText(string txt, string font, double size)
70 {
71 Graphics gd = Graphics.FromImage(bmp);
72 //gd.DrawString(txt,
73
74
75 }
76 }
77}
diff --git a/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Channel.cs b/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Channel.cs
new file mode 100644
index 0000000..9849ef2
--- /dev/null
+++ b/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Channel.cs
@@ -0,0 +1,66 @@
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
36
37/* Channel
38 * A channel is a single heightmap array
39 * */
40
41namespace libTerrain
42{
43 partial class Channel
44 {
45 public double[,] map;
46 public int w;
47 public int h;
48
49 public int seed = 1338; // One better than 1337
50
51 public Channel()
52 {
53 w = 256;
54 h = 256;
55 map = new double[w, h];
56 }
57
58 public Channel(int width, int height)
59 {
60 w = width;
61 h = height;
62 map = new double[w, h];
63 }
64
65 }
66}
diff --git a/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Common.cs b/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Common.cs
new file mode 100644
index 0000000..438359c
--- /dev/null
+++ b/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Common.cs
@@ -0,0 +1,228 @@
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
32
33using System;
34using System.Collections.Generic;
35using System.Text;
36
37namespace libTerrain
38{
39 public partial class Channel
40 {
41 public int getWidth()
42 {
43 return w;
44 }
45 public int getHeight()
46 {
47 return h;
48 }
49
50 public Channel copy()
51 {
52 Channel x = new Channel(w, h);
53 x.map = (double[,])this.map.Clone();
54 return x;
55 }
56
57 public void set(int x, int y, double val)
58 {
59 if (x >= w)
60 throw new Exception("Bounds error while setting pixel (width)");
61 if (y >= h)
62 throw new Exception("Bounds error while setting pixel (height)");
63 if (x < 0)
64 throw new Exception("Bounds error while setting pixel (width)");
65 if (y < 0)
66 throw new Exception("Bounds error while setting pixel (height)");
67
68 map[x, y] = val;
69 }
70
71 public void setClip(int x, int y, double val)
72 {
73 if (x >= w)
74 throw new Exception("Bounds error while setting pixel (width)");
75 if (y >= h)
76 throw new Exception("Bounds error while setting pixel (height)");
77 if (x < 0)
78 throw new Exception("Bounds error while setting pixel (width)");
79 if (y < 0)
80 throw new Exception("Bounds error while setting pixel (height)");
81
82 if (val > 1.0)
83 val = 1.0;
84 if (val < 0.0)
85 val = 0.0;
86
87 map[x, y] = val;
88 }
89
90 private double getBilinearInterpolate(double x, double y)
91 {
92 if (x > w - 2.0)
93 x = w - 2.0;
94 if (y > h - 2.0)
95 y = h - 2.0;
96 if (x < 0.0)
97 x = 0.0;
98 if (y < 0.0)
99 y = 0.0;
100
101 int STEP_SIZE = 1;
102 double h00 = get((int)x, (int)y);
103 double h10 = get((int)x + STEP_SIZE, (int)y);
104 double h01 = get((int)x, (int)y + STEP_SIZE);
105 double h11 = get((int)x + STEP_SIZE, (int)y + STEP_SIZE);
106 double h1 = h00;
107 double h2 = h10;
108 double h3 = h01;
109 double h4 = h11;
110 double a00 = h1;
111 double a10 = h2 - h1;
112 double a01 = h3 - h1;
113 double a11 = h1 - h2 - h3 + h4;
114 double partialx = x - (int)x;
115 double partialz = y - (int)y;
116 double hi = a00 + (a10 * partialx) + (a01 * partialz) + (a11 * partialx * partialz);
117 return hi;
118 }
119
120 public double get(int x, int y)
121 {
122 if (x >= w)
123 x = w - 1;
124 if (y >= h)
125 y = h - 1;
126 if (x < 0)
127 x = 0;
128 if (y < 0)
129 y = 0;
130 return map[x, y];
131 }
132
133 public void setWrap(int x, int y, double val)
134 {
135 map[x % w, y % h] = val;
136 }
137
138 public void setWrapClip(int x, int y, double val)
139 {
140 if (val > 1.0)
141 val = 1.0;
142 if (val < 0.0)
143 val = 0.0;
144
145 map[x % w, y % h] = val;
146 }
147
148 public void fill(double val)
149 {
150 int x, y;
151 for (x = 0; x < w; x++)
152 {
153 for (y = 0; y < h; y++)
154 {
155 map[x, y] = val;
156 }
157 }
158 }
159
160 public void fill(double min, double max, double val)
161 {
162 int x, y;
163 for (x = 0; x < w; x++)
164 {
165 for (y = 0; y < h; y++)
166 {
167 if (map[x, y] >= min && map[x, y] <= max)
168 map[x, y] = val;
169 }
170 }
171 }
172
173 public double findMax()
174 {
175 int x, y;
176 double max = double.MinValue;
177
178 for (x = 0; x < w; x++)
179 {
180 for (y = 0; y < h; y++)
181 {
182 if (map[x, y] > max)
183 max = map[x, y];
184 }
185 }
186
187 return max;
188 }
189
190 public double findMin()
191 {
192 int x, y;
193 double min = double.MaxValue;
194
195 for (x = 0; x < w; x++)
196 {
197 for (y = 0; y < h; y++)
198 {
199 if (map[x, y] < min)
200 min = map[x, y];
201 }
202 }
203
204 return min;
205 }
206
207 public double sum()
208 {
209 int x, y;
210 double sum = 0.0;
211
212 for (x = 0; x < w; x++)
213 {
214 for (y = 0; y < h; y++)
215 {
216 sum += map[x, y];
217 }
218 }
219
220 return sum;
221 }
222
223 public double avg()
224 {
225 return sum() / (w * h);
226 }
227 }
228}
diff --git a/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Editing/Flatten.cs b/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Editing/Flatten.cs
new file mode 100644
index 0000000..5e5254d
--- /dev/null
+++ b/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Editing/Flatten.cs
@@ -0,0 +1,102 @@
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
32
33using System;
34using System.Collections.Generic;
35using System.Text;
36
37namespace libTerrain
38{
39 partial class Channel
40 {
41 /// <summary>
42 /// Flattens the area underneath rx,ry by moving it to the average of the area. Uses a spherical mask provided by the raise() function.
43 /// </summary>
44 /// <param name="rx">The X coordinate of the terrain mask</param>
45 /// <param name="ry">The Y coordinate of the terrain mask</param>
46 /// <param name="size">The size of the terrain mask</param>
47 /// <param name="amount">The scale of the terrain mask</param>
48 public void flatten(double rx, double ry, double size, double amount)
49 {
50 // Generate the mask
51 Channel temp = new Channel(w, h);
52 temp.fill(0);
53 temp.raise(rx, ry, size, amount);
54 temp.normalise();
55 double total_mod = temp.sum();
56
57 // Establish the average height under the area
58 Channel newmap = new Channel(w, h);
59 newmap.map = (double[,])map.Clone();
60
61 newmap *= temp;
62
63 double total_terrain = newmap.sum();
64 double avg_height = total_terrain / total_mod;
65
66 // Create a flat terrain using the average height
67 Channel flat = new Channel(w, h);
68 flat.fill(avg_height);
69
70 // Blend the current terrain with the average height terrain
71 // using the "raised" empty terrain as a mask
72 blend(flat, temp);
73
74 }
75
76 public void flatten(Channel mask, double amount)
77 {
78 // Generate the mask
79 Channel temp = mask * amount;
80 temp.clip(0, 1); // Cut off out-of-bounds values
81
82 double total_mod = temp.sum();
83
84 // Establish the average height under the area
85 Channel map = new Channel(w, h);
86 map.map = (double[,])this.map.Clone();
87
88 map *= temp;
89
90 double total_terrain = map.sum();
91 double avg_height = total_terrain / total_mod;
92
93 // Create a flat terrain using the average height
94 Channel flat = new Channel(w, h);
95 flat.fill(avg_height);
96
97 // Blend the current terrain with the average height terrain
98 // using the "raised" empty terrain as a mask
99 blend(flat, temp);
100 }
101 }
102} \ No newline at end of file
diff --git a/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Editing/Raise.cs b/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Editing/Raise.cs
new file mode 100644
index 0000000..21d2645
--- /dev/null
+++ b/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Editing/Raise.cs
@@ -0,0 +1,142 @@
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
32
33using System;
34using System.Collections.Generic;
35using System.Text;
36
37namespace libTerrain
38{
39 partial class Channel
40 {
41 /// <summary>
42 /// Raises land around the selection
43 /// </summary>
44 /// <param name="rx">The center the X coordinate of where you wish to raise the land</param>
45 /// <param name="ry">The center the Y coordinate of where you wish to raise the land</param>
46 /// <param name="size">The radius of the dimple</param>
47 /// <param name="amount">How much impact to add to the terrain (0..2 usually)</param>
48 public void raise(double rx, double ry, double size, double amount)
49 {
50 raiseSphere(rx, ry, size, amount);
51 }
52
53 /// <summary>
54 /// Raises land in a sphere around the selection
55 /// </summary>
56 /// <param name="rx">The center the X coordinate of where you wish to raise the land</param>
57 /// <param name="ry">The center the Y coordinate of where you wish to raise the land</param>
58 /// <param name="size">The radius of the sphere dimple</param>
59 /// <param name="amount">How much impact to add to the terrain (0..2 usually)</param>
60 public void raiseSphere(double rx, double ry, double size, double amount)
61 {
62 int x, y;
63 for (x = 0; x < w; x++)
64 {
65 for (y = 0; y < h; y++)
66 {
67 double z = size;
68 z *= z;
69 z -= ((x - rx) * (x - rx)) + ((y - ry) * (y - ry));
70
71 if (z < 0)
72 z = 0;
73
74 map[x, y] += z * amount;
75 }
76 }
77 }
78
79 /// <summary>
80 /// Raises land in a cone around the selection
81 /// </summary>
82 /// <param name="rx">The center the X coordinate of where you wish to raise the land</param>
83 /// <param name="ry">The center the Y coordinate of where you wish to raise the land</param>
84 /// <param name="size">The radius of the cone</param>
85 /// <param name="amount">How much impact to add to the terrain (0..2 usually)</param>
86 public void raiseCone(double rx, double ry, double size, double amount)
87 {
88 int x, y;
89 for (x = 0; x < w; x++)
90 {
91 for (y = 0; y < h; y++)
92 {
93 double z = size;
94 z -= Math.Sqrt(((x - rx) * (x - rx)) + ((y - ry) * (y - ry)));
95
96 if (z < 0)
97 z = 0;
98
99 map[x, y] += z * amount;
100 }
101 }
102 }
103
104 /// <summary>
105 /// Lowers land in a sphere around the selection
106 /// </summary>
107 /// <param name="rx">The center the X coordinate of where you wish to lower the land</param>
108 /// <param name="ry">The center the Y coordinate of where you wish to lower the land</param>
109 /// <param name="size">The radius of the sphere dimple</param>
110 /// <param name="amount">How much impact to remove from the terrain (0..2 usually)</param>
111 public void lower(double rx, double ry, double size, double amount)
112 {
113 lowerSphere(rx, ry, size, amount);
114 }
115
116 /// <summary>
117 /// Lowers land in a sphere around the selection
118 /// </summary>
119 /// <param name="rx">The center the X coordinate of where you wish to lower the land</param>
120 /// <param name="ry">The center the Y coordinate of where you wish to lower the land</param>
121 /// <param name="size">The radius of the sphere dimple</param>
122 /// <param name="amount">How much impact to remove from the terrain (0..2 usually)</param>
123 public void lowerSphere(double rx, double ry, double size, double amount)
124 {
125 int x, y;
126 for (x = 0; x < w; x++)
127 {
128 for (y = 0; y < h; y++)
129 {
130 double z = size;
131 z *= z;
132 z -= ((x - rx) * (x - rx)) + ((y - ry) * (y - ry));
133
134 if (z < 0)
135 z = 0;
136
137 map[x, y] -= z * amount;
138 }
139 }
140 }
141 }
142} \ No newline at end of file
diff --git a/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/File.cs b/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/File.cs
new file mode 100644
index 0000000..4163a5f
--- /dev/null
+++ b/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/File.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;
35using System.Drawing;
36
37namespace libTerrain
38{
39 partial class Channel
40 {
41 public Channel loadImage(string filename)
42 {
43 Bitmap bit = new Bitmap(filename);
44 Channel chan = new Channel(bit.Width, bit.Height);
45
46 int x, y;
47 for (x = 0; x < bit.Width; x++)
48 {
49 for (y = 0; y < bit.Height; y++)
50 {
51 Color val = bit.GetPixel(x, y);
52 chan.map[x, y] = (((double)val.R + (double)val.G + (double)val.B) / 3.0) / 255.0;
53 }
54 }
55
56 return chan;
57 }
58
59 public void saveImage(string filename)
60 {
61 Bitmap bit = new Bitmap(w, h, System.Drawing.Imaging.PixelFormat.Format24bppRgb);
62 int x, y;
63 for (x = 0; x < w; x++)
64 {
65 for (y = 0; y < h; y++)
66 {
67 int val = Math.Min(255, (int)(map[x,y] * 255));
68 Color col = Color.FromArgb(val,val,val);
69 bit.SetPixel(x, y, col);
70 }
71 }
72 bit.Save(filename);
73 }
74 }
75}
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
diff --git a/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Grid.cs b/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Grid.cs
new file mode 100644
index 0000000..41d20f6
--- /dev/null
+++ b/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Grid.cs
@@ -0,0 +1,264 @@
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 public Channel normalise()
41 {
42 double max = findMax();
43 double min = findMin();
44
45 int x, y;
46
47 for (x = 0; x < w; x++)
48 {
49 for (y = 0; y < h; y++)
50 {
51 map[x, y] = (map[x, y] - min) * (1.0 / (max - min));
52 }
53 }
54
55 return this;
56 }
57
58 public Channel normalise(double minv, double maxv)
59 {
60 double max = findMax();
61 double min = findMin();
62
63 int x, y;
64
65 for (x = 0; x < w; x++)
66 {
67 for (y = 0; y < h; y++)
68 {
69 double val = (map[x, y] - min) * (1.0 / max - min);
70 val *= maxv - minv;
71 val += minv;
72
73 map[x, y] = val;
74 }
75 }
76
77 return this;
78 }
79
80 public Channel clip()
81 {
82 int x, y;
83
84 for (x = 0; x < w; x++)
85 {
86 for (y = 0; y < h; y++)
87 {
88 setClip(x, y, map[x, y]);
89 }
90 }
91
92 return this;
93 }
94
95 public Channel clip(double min, double max)
96 {
97 int x, y;
98 for (x = 0; x < w; x++)
99 {
100 for (y = 0; y < h; y++)
101 {
102 double val = map[x, y];
103 if (val > max) val = max;
104 if (val < min) val = min;
105 map[x, y] = val;
106 }
107 }
108 return this;
109 }
110
111 public Channel crop(int x1, int y1, int x2, int y2)
112 {
113 int width = x1 - x2 + 1;
114 int height = y1 - y2 + 1;
115 Channel chan = new Channel(width, height);
116
117 int x, y;
118 int nx, ny;
119
120 nx = 0;
121 for (x = x1; x < x2; x++)
122 {
123 ny = 0;
124 for (y = y1; y < y2; y++)
125 {
126 chan.map[nx, ny] = map[x, y];
127
128 ny++;
129 }
130 nx++;
131 }
132
133 return this;
134 }
135
136 public Channel addClip(Channel other)
137 {
138 int x, y;
139 for (x = 0; x < w; x++)
140 {
141 for (y = 0; y < h; y++)
142 {
143 map[x, y] = other.map[x, y];
144 if (map[x, y] > 1)
145 map[x, y] = 1;
146 if (map[x, y] < 0)
147 map[x, y] = 0;
148 }
149 }
150 return this;
151 }
152
153 public void smooth(double amount)
154 {
155 double area = amount;
156 double step = amount / 4.0;
157
158 double[,] manipulate = new double[w, h];
159 int x, y;
160 double n, l;
161 for (x = 0; x < w; x++)
162 {
163 for (y = 0; y < h; y++)
164 {
165 double average = 0.0;
166 int avgsteps = 0;
167
168 for (n = 0.0 - area; n < area; n += step)
169 {
170 for (l = 0.0 - area; l < area; l += step)
171 {
172 avgsteps++;
173 average += getBilinearInterpolate(x + n, y + l);
174 }
175 }
176
177 manipulate[x, y] = average / avgsteps;
178 }
179 }
180 map = manipulate;
181 }
182
183 public void pertubation(double amount)
184 {
185 // Simple pertubation filter
186 double[,] manipulated = new double[w, h];
187 Random generator = new Random(seed); // Seeds FTW!
188 //double amount = 8.0;
189
190 int x, y;
191 for (x = 0; x < w; x++)
192 {
193 for (y = 0; y < h; y++)
194 {
195 double offset_x = (double)x + (generator.NextDouble() * amount) - (amount / 2.0);
196 double offset_y = (double)y + (generator.NextDouble() * amount) - (amount / 2.0);
197 double p = getBilinearInterpolate(offset_x, offset_y);
198 manipulated[x, y] = p;
199 }
200 }
201 map = manipulated;
202 }
203
204 public void pertubationMask(Channel mask)
205 {
206 // Simple pertubation filter
207 double[,] manipulated = new double[w, h];
208 Random generator = new Random(seed); // Seeds FTW!
209 //double amount = 8.0;
210
211 double amount;
212
213 int x, y;
214 for (x = 0; x < w; x++)
215 {
216 for (y = 0; y < h; y++)
217 {
218 amount = mask.map[x, y];
219 double offset_x = (double)x + (generator.NextDouble() * amount) - (amount / 2.0);
220 double offset_y = (double)y + (generator.NextDouble() * amount) - (amount / 2.0);
221
222 if (offset_x > w)
223 offset_x = w - 1;
224 if (offset_y > h)
225 offset_y = h - 1;
226 if (offset_y < 0)
227 offset_y = 0;
228 if (offset_x < 0)
229 offset_x = 0;
230
231 double p = getBilinearInterpolate(offset_x, offset_y);
232 manipulated[x, y] = p;
233 }
234 }
235 map = manipulated;
236 }
237
238 public Channel blend(Channel other, double amount)
239 {
240 int x, y;
241 for (x = 0; x < w; x++)
242 {
243 for (y = 0; y < h; y++)
244 {
245 map[x, y] = Tools.linearInterpolate(map[x,y],other.map[x,y],amount);
246 }
247 }
248 return this;
249 }
250
251 public Channel blend(Channel other, Channel amount)
252 {
253 int x, y;
254 for (x = 0; x < w; x++)
255 {
256 for (y = 0; y < h; y++)
257 {
258 map[x, y] = Tools.linearInterpolate(map[x, y], other.map[x, y], amount.map[x,y]);
259 }
260 }
261 return this;
262 }
263 }
264}
diff --git a/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Manipulators/AerobicErosion.cs b/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Manipulators/AerobicErosion.cs
new file mode 100644
index 0000000..ebeabe9
--- /dev/null
+++ b/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Manipulators/AerobicErosion.cs
@@ -0,0 +1,170 @@
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 // Ideas for Aerobic erosion
41 //
42 // Unlike thermal (gravity) and hydraulic (water suspension)
43 // aerobic erosion should displace mass by moving sediment
44 // in "hops". The length of the hop being dictated by the
45 // presence of sharp cliffs and wind speed.
46
47 // The ability to pickup sediment is defined by the total
48 // surface area, such that:
49 // 0 0 0
50 // 0 1 0
51 // 0 0 0
52 // Would be the best possible value for sediment to be
53 // picked up (total difference = 8) and flatter land
54 // will erode less quickly.
55
56 // Suspended particles assist the erosion process by hitting
57 // the surface and chiselling additional particles off faster
58 // than alone.
59
60 // Particles are deposited when one of two conditions is met
61 // First:
62 // When particles hit a wall - such that the
63 // wind direction points at a difference >= the
64 // deposition mininum talus.
65 // Second:
66 // When wind speed is lowered to below the minimum
67 // required for transit. An idea for this is to
68 // use the navier-stokes algorithms for simulating
69 // pressure across the terrain.
70
71 /// <summary>
72 /// An experimental erosion algorithm developed by Adam. Moves sediment by factoring the surface area of each height point.
73 /// </summary>
74 /// <param name="windspeed">0..1 The speed of the wind</param>
75 /// <param name="pickup_talus_minimum">The minimum angle at which rock is eroded 0..1 (recommended: <= 0.30)</param>
76 /// <param name="drop_talus_minimum">The minimum angle at which rock is dropped 0..1 (recommended: >= 0.00)</param>
77 /// <param name="carry">The percentage of rock which can be picked up to pickup 0..1</param>
78 /// <param name="rounds">The number of erosion rounds (recommended: 25+)</param>
79 /// <param name="lowest">Drop sediment at the lowest point?</param>
80 public void AerobicErosion(double windspeed, double pickup_talus_minimum, double drop_talus_minimum, double carry, int rounds, bool lowest)
81 {
82 Channel wind = new Channel(w, h) ;
83 Channel sediment = new Channel(w, h);
84 int x, y, i, j;
85
86 wind = this.copy();
87 wind.normalise(); // Cheap wind calculations
88 wind *= windspeed;
89 wind.pertubation(30); // Can do better later
90
91 for (i = 0; i < rounds; i++)
92 {
93 // Convert some rocks to sand
94 for (x = 1; x < w - 1; x++)
95 {
96 for (y = 1; y < h - 1; y++)
97 {
98 double me = get(x, y);
99 double surfacearea = 0.3; // Everything will erode even if it's flat. Just slower.
100
101 for (j = 0; j < 9; j++)
102 {
103 int[] coords = neighbours(NEIGHBOURS.NEIGHBOUR_MOORE, j);
104 double target = get(x + coords[0], y + coords[1]);
105
106 surfacearea += Math.Abs(target - me);
107 }
108
109 double amount = surfacearea * wind.map[x, y] * carry;
110
111 if (amount < 0)
112 amount = 0;
113
114 if (surfacearea > pickup_talus_minimum)
115 {
116 this.map[x, y] -= amount;
117 sediment.map[x, y] += amount;
118 }
119 }
120 }
121 sediment.pertubation(10); // Sediment is blown around a bit
122 sediment.seed++;
123 wind.pertubation(15); // So is the wind
124 wind.seed++;
125
126 // Convert some sand to rock
127 for (x = 1; x < w - 1; x++)
128 {
129 for (y = 1; y < h - 1; y++)
130 {
131 double me = get(x, y);
132 double surfacearea = 0.01; // Flat land does not get deposition
133 double min = double.MaxValue;
134 int[] minside = new int[2];
135
136 for (j = 0; j < 9; j++)
137 {
138 int[] coords = neighbours(NEIGHBOURS.NEIGHBOUR_MOORE, j);
139 double target = get(x + coords[0], y + coords[1]);
140
141 surfacearea += Math.Abs(target - me);
142
143 if (target < min && lowest)
144 {
145 minside = (int[])coords.Clone();
146 min = target;
147 }
148 }
149
150 double amount = surfacearea * (1.0 - wind.map[x, y]) * carry;
151
152 if (amount < 0)
153 amount = 0;
154
155 if (surfacearea > drop_talus_minimum)
156 {
157 this.map[x + minside[0], y + minside[1]] += amount;
158 sediment.map[x, y] -= amount;
159 }
160 }
161 }
162
163 }
164
165 Channel myself = this;
166 myself += sediment;
167 myself.normalise();
168 }
169 }
170} \ No newline at end of file
diff --git a/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Manipulators/HydraulicErosion.cs b/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Manipulators/HydraulicErosion.cs
new file mode 100644
index 0000000..0cec05d
--- /dev/null
+++ b/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Manipulators/HydraulicErosion.cs
@@ -0,0 +1 @@
/* Needs BSD rewrite */ \ No newline at end of file
diff --git a/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Manipulators/ThermalWeathering.cs b/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Manipulators/ThermalWeathering.cs
new file mode 100644
index 0000000..0cae56d
--- /dev/null
+++ b/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Manipulators/ThermalWeathering.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 /// A thermal weathering implementation based on Musgrave's original 1989 algorithm. This is Adam's custom implementation which may differ slightly from the original.
42 /// </summary>
43 /// <param name="talus">The rock angle (represented as a dy/dx ratio) at which point it will be succeptible to breakage</param>
44 /// <param name="rounds">The number of erosion rounds</param>
45 /// <param name="c">The amount of rock to carry each round</param>
46 public Channel thermalWeathering(double talus, int rounds, double c)
47 {
48 double[,] lastFrame;
49 double[,] thisFrame;
50
51 lastFrame = (double[,])map.Clone();
52 thisFrame = (double[,])map.Clone();
53
54 NEIGHBOURS type = NEIGHBOURS.NEIGHBOUR_MOORE; // Using moore neighbourhood (twice as computationally expensive)
55 int NEIGHBOUR_ME = 4; // I am always 4 in both systems.
56
57 int NEIGHBOUR_MAX = type == NEIGHBOURS.NEIGHBOUR_MOORE ? 9 : 5;
58
59 int frames = rounds; // Number of thermal erosion iterations to run
60 int i, j;
61 int x, y;
62
63 for (i = 0; i < frames; i++)
64 {
65 for (x = 0; x < w; x++)
66 {
67 for (y = 0; y < h; y++)
68 {
69 for (j = 0; j < NEIGHBOUR_MAX; j++)
70 {
71 if (j != NEIGHBOUR_ME)
72 {
73 int[] coords = neighbours(type, j);
74
75 coords[0] += x;
76 coords[1] += y;
77
78 if (coords[0] > w - 1)
79 coords[0] = w - 1;
80 if (coords[1] > h - 1)
81 coords[1] = h - 1;
82 if (coords[0] < 0)
83 coords[0] = 0;
84 if (coords[1] < 0)
85 coords[1] = 0;
86
87 double heightF = thisFrame[x, y];
88 double target = thisFrame[coords[0], coords[1]];
89
90 if (target > heightF + talus)
91 {
92 double calc = c * ((target - heightF) - talus);
93 heightF += calc;
94 target -= calc;
95 }
96
97 thisFrame[x, y] = heightF;
98 thisFrame[coords[0], coords[1]] = target;
99
100 }
101 }
102 }
103 }
104 lastFrame = (double[,])thisFrame.Clone();
105 }
106
107 map = thisFrame;
108
109 normalise(); // Just to guaruntee a smooth 0..1 value
110 return this;
111 }
112 }
113}
diff --git a/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Neighbours.cs b/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Neighbours.cs
new file mode 100644
index 0000000..f2b4aed
--- /dev/null
+++ b/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Neighbours.cs
@@ -0,0 +1,144 @@
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 enum NEIGHBOURS
41 {
42 NEIGHBOUR_MOORE,
43 NEIGHBOUR_VONNEUMANN
44 };
45
46 private int[] neighbours(NEIGHBOURS type, int index)
47 {
48 int[] coord = new int[2];
49
50 index++;
51
52 switch (type)
53 {
54 case NEIGHBOURS.NEIGHBOUR_MOORE:
55 switch (index)
56 {
57 case 1:
58 coord[0] = -1;
59 coord[1] = -1;
60 break;
61
62 case 2:
63 coord[0] = -0;
64 coord[1] = -1;
65 break;
66
67 case 3:
68 coord[0] = +1;
69 coord[1] = -1;
70 break;
71
72 case 4:
73 coord[0] = -1;
74 coord[1] = -0;
75 break;
76
77 case 5:
78 coord[0] = -0;
79 coord[1] = -0;
80 break;
81
82 case 6:
83 coord[0] = +1;
84 coord[1] = -0;
85 break;
86
87 case 7:
88 coord[0] = -1;
89 coord[1] = +1;
90 break;
91
92 case 8:
93 coord[0] = -0;
94 coord[1] = +1;
95 break;
96
97 case 9:
98 coord[0] = +1;
99 coord[1] = +1;
100 break;
101
102 default:
103 break;
104 }
105 break;
106
107 case NEIGHBOURS.NEIGHBOUR_VONNEUMANN:
108 switch (index)
109 {
110 case 1:
111 coord[0] = 0;
112 coord[1] = -1;
113 break;
114
115 case 2:
116 coord[0] = -1;
117 coord[1] = 0;
118 break;
119
120 case 3:
121 coord[0] = +1;
122 coord[1] = 0;
123 break;
124
125 case 4:
126 coord[0] = 0;
127 coord[1] = +1;
128 break;
129
130 case 5:
131 coord[0] = -0;
132 coord[1] = -0;
133 break;
134
135 default:
136 break;
137 }
138 break;
139 }
140
141 return coord;
142 }
143 }
144}
diff --git a/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Operators.cs b/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Operators.cs
new file mode 100644
index 0000000..81db690
--- /dev/null
+++ b/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Operators.cs
@@ -0,0 +1,221 @@
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 /* Operator combination of channel datatypes */
41
42 public static Channel operator +(Channel A, Channel B)
43 {
44 if (A.h != B.h)
45 throw new Exception("Cannot add heightmaps, of different height.");
46 if (A.w != B.w)
47 throw new Exception("Cannot add heightmaps, of different width.");
48
49 int x, y;
50
51 for (x = 0; x < A.w; x++)
52 {
53 for (y = 0; y < A.h; y++)
54 {
55 A.map[x, y] += B.map[x, y];
56 }
57 }
58
59 return A;
60 }
61
62 public static Channel operator *(Channel A, Channel B)
63 {
64 if (A.h != B.h)
65 throw new Exception("Cannot multiply heightmaps, of different height.");
66 if (A.w != B.w)
67 throw new Exception("Cannot multiply heightmaps, of different width.");
68
69 int x, y;
70
71 for (x = 0; x < A.w; x++)
72 {
73 for (y = 0; y < A.h; y++)
74 {
75 A.map[x, y] *= B.map[x, y];
76 }
77 }
78
79 return A;
80 }
81
82 public static Channel operator -(Channel A, Channel B)
83 {
84 if (A.h != B.h)
85 throw new Exception("Cannot subtract heightmaps, of different height.");
86 if (A.w != B.w)
87 throw new Exception("Cannot subtract heightmaps, of different width.");
88
89 int x, y;
90
91 for (x = 0; x < A.w; x++)
92 {
93 for (y = 0; y < A.h; y++)
94 {
95 A.map[x, y] -= B.map[x, y];
96 }
97 }
98
99 return A;
100 }
101
102 public static Channel operator /(Channel A, Channel B)
103 {
104 if (A.h != B.h)
105 throw new Exception("Cannot divide heightmaps, of different height.");
106 if (A.w != B.w)
107 throw new Exception("Cannot divide heightmaps, of different width.");
108
109 int x, y;
110
111 for (x = 0; x < A.w; x++)
112 {
113 for (y = 0; y < A.h; y++)
114 {
115 A.map[x, y] /= B.map[x, y];
116 }
117 }
118
119 return A;
120 }
121
122 public static Channel operator ^(Channel A, Channel B)
123 {
124 if (A.h != B.h)
125 throw new Exception("Cannot divide heightmaps, of different height.");
126 if (A.w != B.w)
127 throw new Exception("Cannot divide heightmaps, of different width.");
128
129 int x, y;
130
131 for (x = 0; x < A.w; x++)
132 {
133 for (y = 0; y < A.h; y++)
134 {
135 A.map[x, y] = Math.Pow(A.map[x,y],B.map[x, y]);
136 }
137 }
138
139 return A;
140 }
141
142
143 /* Operator combination of channel and double datatypes */
144
145 public static Channel operator +(Channel A, double B)
146 {
147 int x, y;
148
149 for (x = 0; x < A.w; x++)
150 {
151 for (y = 0; y < A.h; y++)
152 {
153 A.map[x, y] += B;
154 }
155 }
156
157 return A;
158 }
159
160 public static Channel operator -(Channel A, double B)
161 {
162 int x, y;
163
164 for (x = 0; x < A.w; x++)
165 {
166 for (y = 0; y < A.h; y++)
167 {
168 A.map[x, y] -= B;
169 }
170 }
171
172 return A;
173 }
174
175 public static Channel operator *(Channel A, double B)
176 {
177 int x, y;
178
179 for (x = 0; x < A.w; x++)
180 {
181 for (y = 0; y < A.h; y++)
182 {
183 A.map[x, y] *= B;
184 }
185 }
186
187 return A;
188 }
189
190 public static Channel operator /(Channel A, double B)
191 {
192 int x, y;
193
194 for (x = 0; x < A.w; x++)
195 {
196 for (y = 0; y < A.h; y++)
197 {
198 A.map[x, y] /= B;
199 }
200 }
201
202 return A;
203 }
204
205 public static Channel operator ^(Channel A, double B)
206 {
207 int x, y;
208
209 for (x = 0; x < A.w; x++)
210 {
211 for (y = 0; y < A.h; y++)
212 {
213 A.map[x, y] = Math.Pow(A.map[x,y],B);
214 }
215 }
216
217 return A;
218 }
219
220 }
221}
diff --git a/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Tools/Point2D.cs b/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Tools/Point2D.cs
new file mode 100644
index 0000000..69c1148
--- /dev/null
+++ b/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Tools/Point2D.cs
@@ -0,0 +1,49 @@
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 public class Point2D
39 {
40 public double x;
41 public double y;
42
43 public Point2D(double X, double Y)
44 {
45 x = X;
46 y = Y;
47 }
48 }
49}
diff --git a/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Tools/Tools.cs b/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Tools/Tools.cs
new file mode 100644
index 0000000..3f7ab68
--- /dev/null
+++ b/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Tools/Tools.cs
@@ -0,0 +1,60 @@
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 class Tools
39 {
40 public static double linearInterpolate(double a, double b, double amount)
41 {
42 return a + ((b - a) * amount);
43 }
44 public static double exponentialInterpolate(double a, double b, double amount)
45 {
46 a = Math.Pow(a, amount);
47 b = Math.Pow(b - a, 1.0 - amount);
48 return a+b;
49 }
50 public static int powerOf2Log2(int n) {
51 for (int i = 0; i < 31; i++) {
52 if ((n & 1) == 1) {
53 return i;
54 }
55 n >>= 1;
56 }
57 return 0;
58 }
59 }
60}