diff options
author | Adam Frisby | 2008-04-23 10:55:04 +0000 |
---|---|---|
committer | Adam Frisby | 2008-04-23 10:55:04 +0000 |
commit | 7c897043bab19bf748ac3078a05a74969c409fa7 (patch) | |
tree | f3f89972edbdebd9678025e754734f6aeb8b2952 /OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel | |
parent | * Get rid of missing texture notification drop messages for now - obscuring t... (diff) | |
download | opensim-SC_OLD-7c897043bab19bf748ac3078a05a74969c409fa7.zip opensim-SC_OLD-7c897043bab19bf748ac3078a05a74969c409fa7.tar.gz opensim-SC_OLD-7c897043bab19bf748ac3078a05a74969c409fa7.tar.bz2 opensim-SC_OLD-7c897043bab19bf748ac3078a05a74969c409fa7.tar.xz |
* Removing old libTerrainBSD and associated Plugin & Project.
* Updated prebuild.xml accordingly.
Diffstat (limited to 'OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel')
22 files changed, 0 insertions, 3325 deletions
diff --git a/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Channel.cs b/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Channel.cs deleted file mode 100644 index b19a788..0000000 --- a/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Channel.cs +++ /dev/null | |||
@@ -1,59 +0,0 @@ | |||
1 | /* | ||
2 | * Copyright (c) Contributors, http://opensimulator.org/ | ||
3 | * See CONTRIBUTORS.TXT for a full list of copyright holders. | ||
4 | * | ||
5 | * Redistribution and use in source and binary forms, with or without | ||
6 | * modification, are permitted provided that the following conditions are met: | ||
7 | * * Redistributions of source code must retain the above copyright | ||
8 | * notice, this list of conditions and the following disclaimer. | ||
9 | * * Redistributions in binary form must reproduce the above copyright | ||
10 | * notice, this list of conditions and the following disclaimer in the | ||
11 | * documentation and/or other materials provided with the distribution. | ||
12 | * * Neither the name of the OpenSim Project nor the | ||
13 | * names of its contributors may be used to endorse or promote products | ||
14 | * derived from this software without specific prior written permission. | ||
15 | * | ||
16 | * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY | ||
17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
19 | * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY | ||
20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | ||
23 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
26 | */ | ||
27 | |||
28 | /* Channel | ||
29 | * A channel is a single heightmap array | ||
30 | * */ | ||
31 | |||
32 | namespace libTerrain | ||
33 | { | ||
34 | partial class Channel | ||
35 | { | ||
36 | public double[,] map; | ||
37 | public int[,] diff; | ||
38 | public int w; | ||
39 | public int h; | ||
40 | |||
41 | public int seed = 1338; // One better than 1337 | ||
42 | |||
43 | public Channel() | ||
44 | { | ||
45 | w = 256; | ||
46 | h = 256; | ||
47 | map = new double[w,h]; | ||
48 | diff = new int[(int) (w/16),(int) (h/16)]; | ||
49 | } | ||
50 | |||
51 | public Channel(int width, int height) | ||
52 | { | ||
53 | w = width; | ||
54 | h = height; | ||
55 | map = new double[w,h]; | ||
56 | diff = new int[(int) (w/16),(int) (h/16)]; | ||
57 | } | ||
58 | } | ||
59 | } | ||
diff --git a/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Common.cs b/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Common.cs deleted file mode 100644 index 0c71ed8..0000000 --- a/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Common.cs +++ /dev/null | |||
@@ -1,281 +0,0 @@ | |||
1 | /* | ||
2 | * Copyright (c) Contributors, http://opensimulator.org/ | ||
3 | * See CONTRIBUTORS.TXT for a full list of copyright holders. | ||
4 | * | ||
5 | * Redistribution and use in source and binary forms, with or without | ||
6 | * modification, are permitted provided that the following conditions are met: | ||
7 | * * Redistributions of source code must retain the above copyright | ||
8 | * notice, this list of conditions and the following disclaimer. | ||
9 | * * Redistributions in binary form must reproduce the above copyright | ||
10 | * notice, this list of conditions and the following disclaimer in the | ||
11 | * documentation and/or other materials provided with the distribution. | ||
12 | * * Neither the name of the OpenSim Project nor the | ||
13 | * names of its contributors may be used to endorse or promote products | ||
14 | * derived from this software without specific prior written permission. | ||
15 | * | ||
16 | * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY | ||
17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
19 | * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY | ||
20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | ||
23 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
26 | */ | ||
27 | |||
28 | using System; | ||
29 | |||
30 | namespace libTerrain | ||
31 | { | ||
32 | public partial class Channel | ||
33 | { | ||
34 | public int GetWidth() | ||
35 | { | ||
36 | return w; | ||
37 | } | ||
38 | |||
39 | public int GetHeight() | ||
40 | { | ||
41 | return h; | ||
42 | } | ||
43 | |||
44 | public Channel Copy() | ||
45 | { | ||
46 | Channel x = new Channel(w, h); | ||
47 | x.map = (double[,]) map.Clone(); | ||
48 | return x; | ||
49 | } | ||
50 | |||
51 | public void SetDiff() | ||
52 | { | ||
53 | SetDiff(1); | ||
54 | } | ||
55 | |||
56 | public void SetDiff(int val) | ||
57 | { | ||
58 | for (int x = 0; x < w/16; x++) | ||
59 | { | ||
60 | for (int y = 0; y < h/16; y++) | ||
61 | { | ||
62 | diff[x, y] = val; | ||
63 | } | ||
64 | } | ||
65 | } | ||
66 | |||
67 | public void SetDiff(int x, int y) | ||
68 | { | ||
69 | diff[x/16, y/16]++; | ||
70 | } | ||
71 | |||
72 | public void Set(int x, int y, double val) | ||
73 | { | ||
74 | if (x >= w) | ||
75 | throw new Exception("Bounds error while setting pixel (width)"); | ||
76 | if (y >= h) | ||
77 | throw new Exception("Bounds error while setting pixel (height)"); | ||
78 | if (x < 0) | ||
79 | throw new Exception("Bounds error while setting pixel (width)"); | ||
80 | if (y < 0) | ||
81 | throw new Exception("Bounds error while setting pixel (height)"); | ||
82 | |||
83 | if (map[x, y] != val) | ||
84 | { | ||
85 | SetDiff(x, y); | ||
86 | |||
87 | map[x, y] = val; | ||
88 | } | ||
89 | } | ||
90 | |||
91 | public void SetClip(int x, int y, double val) | ||
92 | { | ||
93 | SetDiff(x, y); | ||
94 | |||
95 | if (x >= w) | ||
96 | throw new Exception("Bounds error while setting pixel (width)"); | ||
97 | if (y >= h) | ||
98 | throw new Exception("Bounds error while setting pixel (height)"); | ||
99 | if (x < 0) | ||
100 | throw new Exception("Bounds error while setting pixel (width)"); | ||
101 | if (y < 0) | ||
102 | throw new Exception("Bounds error while setting pixel (height)"); | ||
103 | |||
104 | if (val > 1.0) | ||
105 | val = 1.0; | ||
106 | if (val < 0.0) | ||
107 | val = 0.0; | ||
108 | |||
109 | map[x, y] = val; | ||
110 | } | ||
111 | |||
112 | private double GetBilinearInterpolate(double x, double y) | ||
113 | { | ||
114 | if (x > w - 2.0) | ||
115 | x = w - 2.0; | ||
116 | if (y > h - 2.0) | ||
117 | y = h - 2.0; | ||
118 | if (x < 0.0) | ||
119 | x = 0.0; | ||
120 | if (y < 0.0) | ||
121 | y = 0.0; | ||
122 | |||
123 | int stepSize = 1; | ||
124 | double h00 = Get((int) x, (int) y); | ||
125 | double h10 = Get((int) x + stepSize, (int) y); | ||
126 | double h01 = Get((int) x, (int) y + stepSize); | ||
127 | double h11 = Get((int) x + stepSize, (int) y + stepSize); | ||
128 | double h1 = h00; | ||
129 | double h2 = h10; | ||
130 | double h3 = h01; | ||
131 | double h4 = h11; | ||
132 | double a00 = h1; | ||
133 | double a10 = h2 - h1; | ||
134 | double a01 = h3 - h1; | ||
135 | double a11 = h1 - h2 - h3 + h4; | ||
136 | double partialx = x - (int) x; | ||
137 | double partialz = y - (int) y; | ||
138 | double hi = a00 + (a10*partialx) + (a01*partialz) + (a11*partialx*partialz); | ||
139 | return hi; | ||
140 | } | ||
141 | |||
142 | public double Get(int x, int y) | ||
143 | { | ||
144 | try | ||
145 | { | ||
146 | return map[x, y]; | ||
147 | } | ||
148 | catch (IndexOutOfRangeException) | ||
149 | { | ||
150 | if (x >= w) | ||
151 | x = w - 1; | ||
152 | if (y >= h) | ||
153 | y = h - 1; | ||
154 | if (x < 0) | ||
155 | x = 0; | ||
156 | if (y < 0) | ||
157 | y = 0; | ||
158 | return map[x, y]; | ||
159 | } | ||
160 | } | ||
161 | |||
162 | public void SetWrap(int x, int y, double val) | ||
163 | { | ||
164 | SetDiff(x, y); | ||
165 | |||
166 | map[x%w, y%h] = val; | ||
167 | } | ||
168 | |||
169 | public void SetWrapClip(int x, int y, double val) | ||
170 | { | ||
171 | SetDiff(x, y); | ||
172 | |||
173 | if (val > 1.0) | ||
174 | val = 1.0; | ||
175 | if (val < 0.0) | ||
176 | val = 0.0; | ||
177 | |||
178 | map[x%w, y%h] = val; | ||
179 | } | ||
180 | |||
181 | public void Fill(double val) | ||
182 | { | ||
183 | SetDiff(); | ||
184 | |||
185 | int x, y; | ||
186 | for (x = 0; x < w; x++) | ||
187 | { | ||
188 | for (y = 0; y < h; y++) | ||
189 | { | ||
190 | map[x, y] = val; | ||
191 | } | ||
192 | } | ||
193 | } | ||
194 | |||
195 | public void Fill(double min, double max, double val) | ||
196 | { | ||
197 | SetDiff(); | ||
198 | |||
199 | int x, y; | ||
200 | for (x = 0; x < w; x++) | ||
201 | { | ||
202 | for (y = 0; y < h; y++) | ||
203 | { | ||
204 | if (map[x, y] >= min && map[x, y] <= max) | ||
205 | map[x, y] = val; | ||
206 | } | ||
207 | } | ||
208 | } | ||
209 | |||
210 | public double FindMax() | ||
211 | { | ||
212 | int x, y; | ||
213 | double max = double.MinValue; | ||
214 | |||
215 | for (x = 0; x < w; x++) | ||
216 | { | ||
217 | for (y = 0; y < h; y++) | ||
218 | { | ||
219 | if (map[x, y] > max) | ||
220 | max = map[x, y]; | ||
221 | } | ||
222 | } | ||
223 | |||
224 | return max; | ||
225 | } | ||
226 | |||
227 | public double FindMin() | ||
228 | { | ||
229 | int x, y; | ||
230 | double min = double.MaxValue; | ||
231 | |||
232 | for (x = 0; x < w; x++) | ||
233 | { | ||
234 | for (y = 0; y < h; y++) | ||
235 | { | ||
236 | if (map[x, y] < min) | ||
237 | min = map[x, y]; | ||
238 | } | ||
239 | } | ||
240 | |||
241 | return min; | ||
242 | } | ||
243 | |||
244 | public double Sum() | ||
245 | { | ||
246 | int x, y; | ||
247 | double sum = 0.0; | ||
248 | |||
249 | for (x = 0; x < w; x++) | ||
250 | { | ||
251 | for (y = 0; y < h; y++) | ||
252 | { | ||
253 | sum += map[x, y]; | ||
254 | } | ||
255 | } | ||
256 | |||
257 | return sum; | ||
258 | } | ||
259 | |||
260 | public double Avg() | ||
261 | { | ||
262 | return Sum()/(w*h); | ||
263 | } | ||
264 | |||
265 | public bool ContainsNaN() | ||
266 | { | ||
267 | int x, y; | ||
268 | for (x = 0; x < w; x++) | ||
269 | { | ||
270 | for (y = 0; y < h; y++) | ||
271 | { | ||
272 | double elm = map[x, y]; | ||
273 | |||
274 | if (Double.IsNaN(elm)) | ||
275 | return true; | ||
276 | } | ||
277 | } | ||
278 | return false; | ||
279 | } | ||
280 | } | ||
281 | } | ||
diff --git a/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Editing/Flatten.cs b/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Editing/Flatten.cs deleted file mode 100644 index 7162758..0000000 --- a/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Editing/Flatten.cs +++ /dev/null | |||
@@ -1,141 +0,0 @@ | |||
1 | /* | ||
2 | * Copyright (c) Contributors, http://opensimulator.org/ | ||
3 | * See CONTRIBUTORS.TXT for a full list of copyright holders. | ||
4 | * | ||
5 | * Redistribution and use in source and binary forms, with or without | ||
6 | * modification, are permitted provided that the following conditions are met: | ||
7 | * * Redistributions of source code must retain the above copyright | ||
8 | * notice, this list of conditions and the following disclaimer. | ||
9 | * * Redistributions in binary form must reproduce the above copyright | ||
10 | * notice, this list of conditions and the following disclaimer in the | ||
11 | * documentation and/or other materials provided with the distribution. | ||
12 | * * Neither the name of the OpenSim Project nor the | ||
13 | * names of its contributors may be used to endorse or promote products | ||
14 | * derived from this software without specific prior written permission. | ||
15 | * | ||
16 | * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY | ||
17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
19 | * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY | ||
20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | ||
23 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
26 | */ | ||
27 | |||
28 | namespace libTerrain | ||
29 | { | ||
30 | partial class Channel | ||
31 | { | ||
32 | /// <summary> | ||
33 | /// Flattens the area underneath rx,ry by moving it to the average of the area. Uses a spherical mask provided by the raise() function. | ||
34 | /// </summary> | ||
35 | /// <param name="rx">The X coordinate of the terrain mask</param> | ||
36 | /// <param name="ry">The Y coordinate of the terrain mask</param> | ||
37 | /// <param name="size">The size of the terrain mask</param> | ||
38 | /// <param name="amount">The scale of the terrain mask</param> | ||
39 | public void Flatten(double rx, double ry, double size, double amount) | ||
40 | { | ||
41 | FlattenSlow(rx, ry, size, amount); | ||
42 | } | ||
43 | |||
44 | private void FlattenSlow(double rx, double ry, double size, double amount) | ||
45 | { | ||
46 | // Generate the mask | ||
47 | Channel temp = new Channel(w, h); | ||
48 | temp.Fill(0); | ||
49 | temp.Raise(rx, ry, size, amount); | ||
50 | temp.Normalise(); | ||
51 | double total_mod = temp.Sum(); | ||
52 | |||
53 | // Establish the average height under the area | ||
54 | Channel newmap = new Channel(w, h); | ||
55 | newmap.map = (double[,]) map.Clone(); | ||
56 | |||
57 | newmap *= temp; | ||
58 | |||
59 | double total_terrain = newmap.Sum(); | ||
60 | double avg_height = total_terrain/total_mod; | ||
61 | |||
62 | // Create a flat terrain using the average height | ||
63 | Channel flat = new Channel(w, h); | ||
64 | flat.Fill(avg_height); | ||
65 | |||
66 | // Blend the current terrain with the average height terrain | ||
67 | // using the "raised" empty terrain as a mask | ||
68 | Blend(flat, temp); | ||
69 | } | ||
70 | |||
71 | // TODO: unused | ||
72 | // private void FlattenFast(double rx, double ry, double size, double amount) | ||
73 | // { | ||
74 | // int x, y; | ||
75 | // double avg = 0; | ||
76 | // double div = 0; | ||
77 | |||
78 | // int minX = Math.Max(0, (int) (rx - (size + 1))); | ||
79 | // int maxX = Math.Min(w, (int) (rx + (size + 1))); | ||
80 | // int minY = Math.Max(0, (int) (ry - (size + 1))); | ||
81 | // int maxY = Math.Min(h, (int) (ry + (size + 1))); | ||
82 | |||
83 | // for (x = minX; x < maxX; x++) | ||
84 | // { | ||
85 | // for (y = minY; y < maxY; y++) | ||
86 | // { | ||
87 | // double z = size; | ||
88 | // z *= z; | ||
89 | // z -= ((x - rx)*(x - rx)) + ((y - ry)*(y - ry)); | ||
90 | |||
91 | // if (z < 0) | ||
92 | // z = 0; | ||
93 | |||
94 | // avg += z*amount; | ||
95 | // div += z; | ||
96 | // } | ||
97 | // } | ||
98 | |||
99 | // double height = avg/div; | ||
100 | |||
101 | // for (x = minX; x < maxX; x++) | ||
102 | // { | ||
103 | // for (y = minY; y < maxY; y++) | ||
104 | // { | ||
105 | // double z = size; | ||
106 | // z *= z; | ||
107 | // z -= ((x - rx)*(x - rx)) + ((y - ry)*(y - ry)); | ||
108 | |||
109 | // if (z > 0.0) | ||
110 | // Set(x, y, Tools.LinearInterpolate(map[x, y], height, z)); | ||
111 | // } | ||
112 | // } | ||
113 | // } | ||
114 | |||
115 | public void Flatten(Channel mask, double amount) | ||
116 | { | ||
117 | // Generate the mask | ||
118 | Channel temp = mask*amount; | ||
119 | temp.Clip(0, 1); // Cut off out-of-bounds values | ||
120 | |||
121 | double total_mod = temp.Sum(); | ||
122 | |||
123 | // Establish the average height under the area | ||
124 | Channel map = new Channel(w, h); | ||
125 | map.map = (double[,]) this.map.Clone(); | ||
126 | |||
127 | map *= temp; | ||
128 | |||
129 | double total_terrain = map.Sum(); | ||
130 | double avg_height = total_terrain/total_mod; | ||
131 | |||
132 | // Create a flat terrain using the average height | ||
133 | Channel flat = new Channel(w, h); | ||
134 | flat.Fill(avg_height); | ||
135 | |||
136 | // Blend the current terrain with the average height terrain | ||
137 | // using the "raised" empty terrain as a mask | ||
138 | Blend(flat, temp); | ||
139 | } | ||
140 | } | ||
141 | } | ||
diff --git a/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Editing/Raise.cs b/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Editing/Raise.cs deleted file mode 100644 index 465005a..0000000 --- a/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Editing/Raise.cs +++ /dev/null | |||
@@ -1,191 +0,0 @@ | |||
1 | /* | ||
2 | * Copyright (c) Contributors, http://opensimulator.org/ | ||
3 | * See CONTRIBUTORS.TXT for a full list of copyright holders. | ||
4 | * | ||
5 | * Redistribution and use in source and binary forms, with or without | ||
6 | * modification, are permitted provided that the following conditions are met: | ||
7 | * * Redistributions of source code must retain the above copyright | ||
8 | * notice, this list of conditions and the following disclaimer. | ||
9 | * * Redistributions in binary form must reproduce the above copyright | ||
10 | * notice, this list of conditions and the following disclaimer in the | ||
11 | * documentation and/or other materials provided with the distribution. | ||
12 | * * Neither the name of the OpenSim Project nor the | ||
13 | * names of its contributors may be used to endorse or promote products | ||
14 | * derived from this software without specific prior written permission. | ||
15 | * | ||
16 | * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY | ||
17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
19 | * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY | ||
20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | ||
23 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
26 | */ | ||
27 | |||
28 | using System; | ||
29 | |||
30 | namespace libTerrain | ||
31 | { | ||
32 | partial class Channel | ||
33 | { | ||
34 | /// <summary> | ||
35 | /// Raises land around the selection | ||
36 | /// </summary> | ||
37 | /// <param name="rx">The center the X coordinate of where you wish to raise the land</param> | ||
38 | /// <param name="ry">The center the Y coordinate of where you wish to raise the land</param> | ||
39 | /// <param name="size">The radius of the dimple</param> | ||
40 | /// <param name="amount">How much impact to add to the terrain (0..2 usually)</param> | ||
41 | public void Raise(double rx, double ry, double size, double amount) | ||
42 | { | ||
43 | RaiseSphere(rx, ry, size, amount); | ||
44 | } | ||
45 | |||
46 | /// <summary> | ||
47 | /// Raises land in a sphere around the selection | ||
48 | /// </summary> | ||
49 | /// <param name="rx">The center the X coordinate of where you wish to raise the land</param> | ||
50 | /// <param name="ry">The center the Y coordinate of where you wish to raise the land</param> | ||
51 | /// <param name="size">The radius of the sphere dimple</param> | ||
52 | /// <param name="amount">How much impact to add to the terrain (0..2 usually)</param> | ||
53 | public void RaiseSphere(double rx, double ry, double size, double amount) | ||
54 | { | ||
55 | int x, y; | ||
56 | for (x = 0; x < w; x++) | ||
57 | { | ||
58 | for (y = 0; y < h; y++) | ||
59 | { | ||
60 | double z = size; | ||
61 | z *= z; | ||
62 | z -= ((x - rx)*(x - rx)) + ((y - ry)*(y - ry)); | ||
63 | |||
64 | if (z > 0.0) | ||
65 | Set(x, y, map[x, y] + (z * amount)); | ||
66 | } | ||
67 | } | ||
68 | } | ||
69 | |||
70 | /// <summary> | ||
71 | /// Raises land in a cone around the selection | ||
72 | /// </summary> | ||
73 | /// <param name="rx">The center the X coordinate of where you wish to raise the land</param> | ||
74 | /// <param name="ry">The center the Y coordinate of where you wish to raise the land</param> | ||
75 | /// <param name="size">The radius of the cone</param> | ||
76 | /// <param name="amount">How much impact to add to the terrain (0..2 usually)</param> | ||
77 | public void RaiseCone(double rx, double ry, double size, double amount) | ||
78 | { | ||
79 | int x, y; | ||
80 | for (x = 0; x < w; x++) | ||
81 | { | ||
82 | for (y = 0; y < h; y++) | ||
83 | { | ||
84 | double z = size; | ||
85 | z -= Math.Sqrt(((x - rx)*(x - rx)) + ((y - ry)*(y - ry))); | ||
86 | |||
87 | if (z > 0.0) | ||
88 | Set(x, y, map[x, y] + (z * amount)); | ||
89 | } | ||
90 | } | ||
91 | } | ||
92 | |||
93 | /// <summary> | ||
94 | /// Lowers land in a sphere around the selection | ||
95 | /// </summary> | ||
96 | /// <param name="rx">The center the X coordinate of where you wish to lower the land</param> | ||
97 | /// <param name="ry">The center the Y coordinate of where you wish to lower the land</param> | ||
98 | /// <param name="size">The radius of the sphere dimple</param> | ||
99 | /// <param name="amount">How much impact to remove from the terrain (0..2 usually)</param> | ||
100 | public void Lower(double rx, double ry, double size, double amount) | ||
101 | { | ||
102 | LowerSphere(rx, ry, size, amount); | ||
103 | } | ||
104 | |||
105 | /// <summary> | ||
106 | /// Lowers land in a sphere around the selection | ||
107 | /// </summary> | ||
108 | /// <param name="rx">The center the X coordinate of where you wish to lower the land</param> | ||
109 | /// <param name="ry">The center the Y coordinate of where you wish to lower the land</param> | ||
110 | /// <param name="size">The radius of the sphere dimple</param> | ||
111 | /// <param name="amount">How much impact to remove from the terrain (0..2 usually)</param> | ||
112 | public void LowerSphere(double rx, double ry, double size, double amount) | ||
113 | { | ||
114 | int x, y; | ||
115 | for (x = 0; x < w; x++) | ||
116 | { | ||
117 | for (y = 0; y < h; y++) | ||
118 | { | ||
119 | double z = size; | ||
120 | z *= z; | ||
121 | z -= ((x - rx)*(x - rx)) + ((y - ry)*(y - ry)); | ||
122 | |||
123 | if (z > 0.0) | ||
124 | Set(x, y, map[x, y] - (z * amount)); | ||
125 | } | ||
126 | } | ||
127 | } | ||
128 | |||
129 | public double SphericalFactor(double x, double y, double rx, double ry, double size) | ||
130 | { | ||
131 | double z = size * size - ((x - rx) * (x - rx) + (y - ry) * (y - ry)); | ||
132 | return z; | ||
133 | } | ||
134 | |||
135 | public void SmoothRegion(double rx, double ry, double size, double amount) | ||
136 | { | ||
137 | int x, y; | ||
138 | double[,] tweak = new double[w, h]; | ||
139 | |||
140 | double n, l; | ||
141 | double area = size; | ||
142 | double step = size / 4.0; | ||
143 | |||
144 | // compute delta map | ||
145 | for (x = 0; x < w; x++) | ||
146 | { | ||
147 | for (y = 0; y < h; y++) | ||
148 | { | ||
149 | double z = SphericalFactor(x, y, rx, ry, size); | ||
150 | |||
151 | if (z > 0) // add in non-zero amount | ||
152 | { | ||
153 | double average = 0.0; | ||
154 | int avgsteps = 0; | ||
155 | |||
156 | for (n = 0.0 - area; n < area; n += step) | ||
157 | { | ||
158 | for (l = 0.0 - area; l < area; l += step) | ||
159 | { | ||
160 | avgsteps++; | ||
161 | average += GetBilinearInterpolate(x + n, y + l); | ||
162 | } | ||
163 | } | ||
164 | tweak[x, y] = average / avgsteps; | ||
165 | //if (x == rx && y == ry) | ||
166 | // Console.WriteLine("tweak[ " + x + " , " + y + " ] = " + tweak[x, y]); | ||
167 | } | ||
168 | } | ||
169 | } | ||
170 | // blend in map | ||
171 | for (x = 0; x < w; x++) | ||
172 | { | ||
173 | for (y = 0; y < h; y++) | ||
174 | { | ||
175 | double z = SphericalFactor(x, y, rx, ry, size); | ||
176 | |||
177 | if (z > 0) // add in non-zero amount | ||
178 | { | ||
179 | double da = z * amount; | ||
180 | double a = (map[x, y] - tweak[x, y]) * da; | ||
181 | double newz = map[x, y] - a; | ||
182 | //if (rx == x || ry == y) | ||
183 | // Console.WriteLine("map[ " + x + " , " + y + " ] = " + map[x, y] + " tweak, a , da, z, size, amount = " + tweak[x, y] + " " + a + " " + da + " " + z + " " + size + " " + amount); | ||
184 | if (newz > 0.0) | ||
185 | Set(x, y, newz); | ||
186 | } | ||
187 | } | ||
188 | } | ||
189 | } | ||
190 | } | ||
191 | } | ||
diff --git a/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/File.cs b/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/File.cs deleted file mode 100644 index 84eca54..0000000 --- a/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/File.cs +++ /dev/null | |||
@@ -1,75 +0,0 @@ | |||
1 | /* | ||
2 | * Copyright (c) Contributors, http://opensimulator.org/ | ||
3 | * See CONTRIBUTORS.TXT for a full list of copyright holders. | ||
4 | * | ||
5 | * Redistribution and use in source and binary forms, with or without | ||
6 | * modification, are permitted provided that the following conditions are met: | ||
7 | * * Redistributions of source code must retain the above copyright | ||
8 | * notice, this list of conditions and the following disclaimer. | ||
9 | * * Redistributions in binary form must reproduce the above copyright | ||
10 | * notice, this list of conditions and the following disclaimer in the | ||
11 | * documentation and/or other materials provided with the distribution. | ||
12 | * * Neither the name of the OpenSim Project nor the | ||
13 | * names of its contributors may be used to endorse or promote products | ||
14 | * derived from this software without specific prior written permission. | ||
15 | * | ||
16 | * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY | ||
17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
19 | * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY | ||
20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | ||
23 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
26 | */ | ||
27 | |||
28 | using System; | ||
29 | using System.Drawing; | ||
30 | using System.Drawing.Imaging; | ||
31 | |||
32 | namespace libTerrain | ||
33 | { | ||
34 | partial class Channel | ||
35 | { | ||
36 | public Channel LoadImage(string filename) | ||
37 | { | ||
38 | SetDiff(); | ||
39 | |||
40 | Bitmap bit = new Bitmap(filename); | ||
41 | Channel chan = new Channel(bit.Width, bit.Height); | ||
42 | |||
43 | int x, y; | ||
44 | for (x = 0; x < bit.Width; x++) | ||
45 | { | ||
46 | for (y = 0; y < bit.Height; y++) | ||
47 | { | ||
48 | Color val = bit.GetPixel(x, y); | ||
49 | chan.map[x, y] = (((double) val.R + (double) val.G + (double) val.B)/3.0)/255.0; | ||
50 | } | ||
51 | } | ||
52 | |||
53 | return chan; | ||
54 | } | ||
55 | |||
56 | public void SaveImage(string filename) | ||
57 | { | ||
58 | Channel outmap = Copy(); | ||
59 | outmap.Normalise(); | ||
60 | |||
61 | Bitmap bit = new Bitmap(w, h, 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) (outmap.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 deleted file mode 100644 index 06e7e3c..0000000 --- a/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Generators/Cellular.cs +++ /dev/null | |||
@@ -1,28 +0,0 @@ | |||
1 | /* | ||
2 | * Copyright (c) Contributors, http://opensimulator.org/ | ||
3 | * See CONTRIBUTORS.TXT for a full list of copyright holders. | ||
4 | * | ||
5 | * Redistribution and use in source and binary forms, with or without | ||
6 | * modification, are permitted provided that the following conditions are met: | ||
7 | * * Redistributions of source code must retain the above copyright | ||
8 | * notice, this list of conditions and the following disclaimer. | ||
9 | * * Redistributions in binary form must reproduce the above copyright | ||
10 | * notice, this list of conditions and the following disclaimer in the | ||
11 | * documentation and/or other materials provided with the distribution. | ||
12 | * * Neither the name of the OpenSim Project nor the | ||
13 | * names of its contributors may be used to endorse or promote products | ||
14 | * derived from this software without specific prior written permission. | ||
15 | * | ||
16 | * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY | ||
17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
19 | * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY | ||
20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | ||
23 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
26 | */ | ||
27 | |||
28 | /* TODO: Needs BSD rewrite */ | ||
diff --git a/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Generators/Fracture.cs b/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Generators/Fracture.cs deleted file mode 100644 index 3e1c34c..0000000 --- a/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Generators/Fracture.cs +++ /dev/null | |||
@@ -1,142 +0,0 @@ | |||
1 | /* | ||
2 | * Copyright (c) Contributors, http://opensimulator.org/ | ||
3 | * See CONTRIBUTORS.TXT for a full list of copyright holders. | ||
4 | * | ||
5 | * Redistribution and use in source and binary forms, with or without | ||
6 | * modification, are permitted provided that the following conditions are met: | ||
7 | * * Redistributions of source code must retain the above copyright | ||
8 | * notice, this list of conditions and the following disclaimer. | ||
9 | * * Redistributions in binary form must reproduce the above copyright | ||
10 | * notice, this list of conditions and the following disclaimer in the | ||
11 | * documentation and/or other materials provided with the distribution. | ||
12 | * * Neither the name of the OpenSim Project nor the | ||
13 | * names of its contributors may be used to endorse or promote products | ||
14 | * derived from this software without specific prior written permission. | ||
15 | * | ||
16 | * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY | ||
17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
19 | * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY | ||
20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | ||
23 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
26 | */ | ||
27 | |||
28 | using System; | ||
29 | |||
30 | namespace libTerrain | ||
31 | { | ||
32 | partial class Channel | ||
33 | { | ||
34 | /// <summary> | ||
35 | /// Produces a set of coordinates defined by an edge point. Eg - 0 = 0,0. 256 = 0,256. 512 = 256,256 | ||
36 | /// Assumes a 256^2 heightmap. This needs fixing for input values of w,h | ||
37 | /// </summary> | ||
38 | /// <param name="val"></param> | ||
39 | /// <param name="w"></param> | ||
40 | /// <param name="h"></param> | ||
41 | /// <returns></returns> | ||
42 | private int[] RadialEdge256(int val) | ||
43 | { | ||
44 | // Four cases: | ||
45 | // 1. 000..255 return 0,val | ||
46 | // 2. 256..511 return val - 256,255 | ||
47 | // 3. 512..767 return 255, val - 511 | ||
48 | // 4. 768..1023 return val - 768,0 | ||
49 | |||
50 | int[] ret = new int[2]; | ||
51 | |||
52 | if (val < 256) | ||
53 | { | ||
54 | ret[0] = 0; | ||
55 | ret[1] = val; | ||
56 | return ret; | ||
57 | } | ||
58 | if (val < 512) | ||
59 | { | ||
60 | ret[0] = (val%256); | ||
61 | ret[1] = 255; | ||
62 | return ret; | ||
63 | } | ||
64 | if (val < 768) | ||
65 | { | ||
66 | ret[0] = 255; | ||
67 | ret[1] = 255 - (val%256); | ||
68 | return ret; | ||
69 | } | ||
70 | if (val < 1024) | ||
71 | { | ||
72 | ret[0] = 255 - (val%256); | ||
73 | ret[1] = 255; | ||
74 | return ret; | ||
75 | } | ||
76 | |||
77 | throw new Exception("Out of bounds parameter (val)"); | ||
78 | } | ||
79 | |||
80 | public void Fracture(int number, double scalemin, double scalemax) | ||
81 | { | ||
82 | SetDiff(); | ||
83 | |||
84 | Random rand = new Random(seed); | ||
85 | |||
86 | for (int i = 0; i < number; i++) | ||
87 | { | ||
88 | int[] a, b; | ||
89 | |||
90 | a = RadialEdge256(rand.Next(1023)); // TODO: Broken | ||
91 | b = RadialEdge256(rand.Next(1023)); // TODO: Broken | ||
92 | double z = rand.NextDouble(); | ||
93 | double u = rand.NextDouble(); | ||
94 | double v = rand.NextDouble(); | ||
95 | |||
96 | for (int x = 0; x < w; x++) | ||
97 | { | ||
98 | for (int y = 0; y < h; y++) | ||
99 | { | ||
100 | double miny = Tools.LinearInterpolate(a[1], b[1], (double) x/(double) w); | ||
101 | |||
102 | if (v >= 0.5) | ||
103 | { | ||
104 | if (u >= 0.5) | ||
105 | { | ||
106 | if (y > miny) | ||
107 | { | ||
108 | map[x, y] += Tools.LinearInterpolate(scalemin, scalemax, z); | ||
109 | } | ||
110 | } | ||
111 | else | ||
112 | { | ||
113 | if (y < miny) | ||
114 | { | ||
115 | map[x, y] += Tools.LinearInterpolate(scalemin, scalemax, z); | ||
116 | } | ||
117 | } | ||
118 | } | ||
119 | else | ||
120 | { | ||
121 | if (u >= 0.5) | ||
122 | { | ||
123 | if (x > miny) | ||
124 | { | ||
125 | map[x, y] += Tools.LinearInterpolate(scalemin, scalemax, z); | ||
126 | } | ||
127 | } | ||
128 | else | ||
129 | { | ||
130 | if (x < miny) | ||
131 | { | ||
132 | map[x, y] += Tools.LinearInterpolate(scalemin, scalemax, z); | ||
133 | } | ||
134 | } | ||
135 | } | ||
136 | } | ||
137 | } | ||
138 | } | ||
139 | Normalise(); | ||
140 | } | ||
141 | } | ||
142 | } | ||
diff --git a/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Generators/Gradient.cs b/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Generators/Gradient.cs deleted file mode 100644 index afe0877..0000000 --- a/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Generators/Gradient.cs +++ /dev/null | |||
@@ -1,60 +0,0 @@ | |||
1 | /* | ||
2 | * Copyright (c) Contributors, http://opensimulator.org/ | ||
3 | * See CONTRIBUTORS.TXT for a full list of copyright holders. | ||
4 | * | ||
5 | * Redistribution and use in source and binary forms, with or without | ||
6 | * modification, are permitted provided that the following conditions are met: | ||
7 | * * Redistributions of source code must retain the above copyright | ||
8 | * notice, this list of conditions and the following disclaimer. | ||
9 | * * Redistributions in binary form must reproduce the above copyright | ||
10 | * notice, this list of conditions and the following disclaimer in the | ||
11 | * documentation and/or other materials provided with the distribution. | ||
12 | * * Neither the name of the OpenSim Project nor the | ||
13 | * names of its contributors may be used to endorse or promote products | ||
14 | * derived from this software without specific prior written permission. | ||
15 | * | ||
16 | * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY | ||
17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
19 | * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY | ||
20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | ||
23 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
26 | */ | ||
27 | |||
28 | namespace libTerrain | ||
29 | { | ||
30 | partial class Channel | ||
31 | { | ||
32 | public void GradientCube() | ||
33 | { | ||
34 | SetDiff(); | ||
35 | |||
36 | int x, y; | ||
37 | for (x = 0; x < w; x++) | ||
38 | { | ||
39 | for (y = 0; y < h; y++) | ||
40 | { | ||
41 | map[x, y] = x*y; | ||
42 | } | ||
43 | } | ||
44 | Normalise(); | ||
45 | } | ||
46 | |||
47 | public void GradientStripe() | ||
48 | { | ||
49 | int x, y; | ||
50 | for (x = 0; x < w; x++) | ||
51 | { | ||
52 | for (y = 0; y < h; y++) | ||
53 | { | ||
54 | map[x, y] = x; | ||
55 | } | ||
56 | } | ||
57 | Normalise(); | ||
58 | } | ||
59 | } | ||
60 | } | ||
diff --git a/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Generators/HillPlanter.cs b/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Generators/HillPlanter.cs deleted file mode 100644 index 82b0cfd..0000000 --- a/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Generators/HillPlanter.cs +++ /dev/null | |||
@@ -1,281 +0,0 @@ | |||
1 | /* | ||
2 | * Copyright (c) Contributors, http://opensimulator.org/ | ||
3 | * See CONTRIBUTORS.TXT for a full list of copyright holders. | ||
4 | * | ||
5 | * Redistribution and use in source and binary forms, with or without | ||
6 | * modification, are permitted provided that the following conditions are met: | ||
7 | * * Redistributions of source code must retain the above copyright | ||
8 | * notice, this list of conditions and the following disclaimer. | ||
9 | * * Redistributions in binary form must reproduce the above copyright | ||
10 | * notice, this list of conditions and the following disclaimer in the | ||
11 | * documentation and/or other materials provided with the distribution. | ||
12 | * * Neither the name of the OpenSim Project nor the | ||
13 | * names of its contributors may be used to endorse or promote products | ||
14 | * derived from this software without specific prior written permission. | ||
15 | * | ||
16 | * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY | ||
17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
19 | * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY | ||
20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | ||
23 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
26 | */ | ||
27 | |||
28 | using System; | ||
29 | |||
30 | namespace libTerrain | ||
31 | { | ||
32 | partial class Channel | ||
33 | { | ||
34 | /// <summary> | ||
35 | /// Generates a series of spheres which are then either max()'d or added together. Inspired by suggestion from jh. | ||
36 | /// </summary> | ||
37 | /// <remarks>3-Clause BSD Licensed</remarks> | ||
38 | /// <param name="number">The number of hills to generate</param> | ||
39 | /// <param name="scale_min">The minimum size of each hill</param> | ||
40 | /// <param name="scale_range">The maximum size of each hill</param> | ||
41 | /// <param name="island">Whether to bias hills towards the center of the map</param> | ||
42 | /// <param name="additive">Whether to add hills together or to pick the largest value</param> | ||
43 | /// <param name="noisy">Generates hill-shaped noise instead of consistent hills</param> | ||
44 | public void HillsSpheres(int number, double scale_min, double scale_range, bool island, bool additive, | ||
45 | bool noisy) | ||
46 | { | ||
47 | SetDiff(); | ||
48 | |||
49 | Random random = new Random(seed); | ||
50 | |||
51 | int x, y; | ||
52 | int i; | ||
53 | |||
54 | for (i = 0; i < number; i++) | ||
55 | { | ||
56 | double rx = Math.Min(255.0, random.NextDouble()*w); | ||
57 | double ry = Math.Min(255.0, random.NextDouble()*h); | ||
58 | double rand = random.NextDouble(); | ||
59 | |||
60 | if (island) | ||
61 | { | ||
62 | // Move everything towards the center | ||
63 | rx -= w/2; | ||
64 | rx /= 2; | ||
65 | rx += w/2; | ||
66 | |||
67 | ry -= h/2; | ||
68 | ry /= 2; | ||
69 | ry += h/2; | ||
70 | } | ||
71 | |||
72 | for (x = 0; x < w; x++) | ||
73 | { | ||
74 | for (y = 0; y < h; y++) | ||
75 | { | ||
76 | if (noisy) | ||
77 | rand = random.NextDouble(); | ||
78 | |||
79 | double z = (scale_min + (scale_range*rand)); | ||
80 | z *= z; | ||
81 | z -= ((x - rx)*(x - rx)) + ((y - ry)*(y - ry)); | ||
82 | |||
83 | if (z < 0) | ||
84 | z = 0; | ||
85 | |||
86 | if (additive) | ||
87 | { | ||
88 | map[x, y] += z; | ||
89 | } | ||
90 | else | ||
91 | { | ||
92 | map[x, y] = Math.Max(map[x, y], z); | ||
93 | } | ||
94 | } | ||
95 | } | ||
96 | } | ||
97 | |||
98 | Normalise(); | ||
99 | } | ||
100 | |||
101 | /// <summary> | ||
102 | /// Generates a series of cones which are then either max()'d or added together. Inspired by suggestion from jh. | ||
103 | /// </summary> | ||
104 | /// <remarks>3-Clause BSD Licensed</remarks> | ||
105 | /// <param name="number">The number of hills to generate</param> | ||
106 | /// <param name="scale_min">The minimum size of each hill</param> | ||
107 | /// <param name="scale_range">The maximum size of each hill</param> | ||
108 | /// <param name="island">Whether to bias hills towards the center of the map</param> | ||
109 | /// <param name="additive">Whether to add hills together or to pick the largest value</param> | ||
110 | /// <param name="noisy">Generates hill-shaped noise instead of consistent hills</param> | ||
111 | public void HillsCones(int number, double scale_min, double scale_range, bool island, bool additive, bool noisy) | ||
112 | { | ||
113 | SetDiff(); | ||
114 | |||
115 | Random random = new Random(seed); | ||
116 | |||
117 | int x, y; | ||
118 | int i; | ||
119 | |||
120 | for (i = 0; i < number; i++) | ||
121 | { | ||
122 | double rx = Math.Min(255.0, random.NextDouble()*w); | ||
123 | double ry = Math.Min(255.0, random.NextDouble()*h); | ||
124 | double rand = random.NextDouble(); | ||
125 | |||
126 | if (island) | ||
127 | { | ||
128 | // Move everything towards the center | ||
129 | rx -= w/2; | ||
130 | rx /= 2; | ||
131 | rx += w/2; | ||
132 | |||
133 | ry -= h/2; | ||
134 | ry /= 2; | ||
135 | ry += h/2; | ||
136 | } | ||
137 | |||
138 | for (x = 0; x < w; x++) | ||
139 | { | ||
140 | for (y = 0; y < h; y++) | ||
141 | { | ||
142 | if (noisy) | ||
143 | rand = random.NextDouble(); | ||
144 | |||
145 | double z = (scale_min + (scale_range*rand)); | ||
146 | z -= Math.Sqrt(((x - rx)*(x - rx)) + ((y - ry)*(y - ry))); | ||
147 | |||
148 | if (z < 0) | ||
149 | z = 0; | ||
150 | |||
151 | if (additive) | ||
152 | { | ||
153 | map[x, y] += z; | ||
154 | } | ||
155 | else | ||
156 | { | ||
157 | map[x, y] = Math.Max(map[x, y], z); | ||
158 | } | ||
159 | } | ||
160 | } | ||
161 | } | ||
162 | |||
163 | Normalise(); | ||
164 | } | ||
165 | |||
166 | public void HillsBlocks(int number, double scale_min, double scale_range, bool island, bool additive, bool noisy) | ||
167 | { | ||
168 | SetDiff(); | ||
169 | |||
170 | Random random = new Random(seed); | ||
171 | |||
172 | int x, y; | ||
173 | int i; | ||
174 | |||
175 | for (i = 0; i < number; i++) | ||
176 | { | ||
177 | double rx = Math.Min(255.0, random.NextDouble()*w); | ||
178 | double ry = Math.Min(255.0, random.NextDouble()*h); | ||
179 | double rand = random.NextDouble(); | ||
180 | |||
181 | if (island) | ||
182 | { | ||
183 | // Move everything towards the center | ||
184 | rx -= w/2; | ||
185 | rx /= 2; | ||
186 | rx += w/2; | ||
187 | |||
188 | ry -= h/2; | ||
189 | ry /= 2; | ||
190 | ry += h/2; | ||
191 | } | ||
192 | |||
193 | for (x = 0; x < w; x++) | ||
194 | { | ||
195 | for (y = 0; y < h; y++) | ||
196 | { | ||
197 | if (noisy) | ||
198 | rand = random.NextDouble(); | ||
199 | |||
200 | double z = (scale_min + (scale_range*rand)); | ||
201 | z -= Math.Abs(x - rx) + Math.Abs(y - ry); | ||
202 | //z -= Math.Sqrt(((x - rx) * (x - rx)) + ((y - ry) * (y - ry))); | ||
203 | |||
204 | if (z < 0) | ||
205 | z = 0; | ||
206 | |||
207 | if (additive) | ||
208 | { | ||
209 | map[x, y] += z; | ||
210 | } | ||
211 | else | ||
212 | { | ||
213 | map[x, y] = Math.Max(map[x, y], z); | ||
214 | } | ||
215 | } | ||
216 | } | ||
217 | } | ||
218 | |||
219 | Normalise(); | ||
220 | } | ||
221 | |||
222 | public void HillsSquared(int number, double scale_min, double scale_range, bool island, bool additive, | ||
223 | bool noisy) | ||
224 | { | ||
225 | SetDiff(); | ||
226 | |||
227 | Random random = new Random(seed); | ||
228 | |||
229 | int x, y; | ||
230 | int i; | ||
231 | |||
232 | for (i = 0; i < number; i++) | ||
233 | { | ||
234 | double rx = Math.Min(255.0, random.NextDouble()*w); | ||
235 | double ry = Math.Min(255.0, random.NextDouble()*h); | ||
236 | double rand = random.NextDouble(); | ||
237 | |||
238 | if (island) | ||
239 | { | ||
240 | // Move everything towards the center | ||
241 | rx -= w/2; | ||
242 | rx /= 2; | ||
243 | rx += w/2; | ||
244 | |||
245 | ry -= h/2; | ||
246 | ry /= 2; | ||
247 | ry += h/2; | ||
248 | } | ||
249 | |||
250 | for (x = 0; x < w; x++) | ||
251 | { | ||
252 | for (y = 0; y < h; y++) | ||
253 | { | ||
254 | if (noisy) | ||
255 | rand = random.NextDouble(); | ||
256 | |||
257 | double z = (scale_min + (scale_range*rand)); | ||
258 | z *= z*z*z; | ||
259 | double dx = Math.Abs(x - rx); | ||
260 | double dy = Math.Abs(y - ry); | ||
261 | z -= (dx*dx*dx*dx) + (dy*dy*dy*dy); | ||
262 | |||
263 | if (z < 0) | ||
264 | z = 0; | ||
265 | |||
266 | if (additive) | ||
267 | { | ||
268 | map[x, y] += z; | ||
269 | } | ||
270 | else | ||
271 | { | ||
272 | map[x, y] = Math.Max(map[x, y], z); | ||
273 | } | ||
274 | } | ||
275 | } | ||
276 | } | ||
277 | |||
278 | Normalise(); | ||
279 | } | ||
280 | } | ||
281 | } | ||
diff --git a/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Generators/Midpoint.cs b/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Generators/Midpoint.cs deleted file mode 100644 index 06e7e3c..0000000 --- a/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Generators/Midpoint.cs +++ /dev/null | |||
@@ -1,28 +0,0 @@ | |||
1 | /* | ||
2 | * Copyright (c) Contributors, http://opensimulator.org/ | ||
3 | * See CONTRIBUTORS.TXT for a full list of copyright holders. | ||
4 | * | ||
5 | * Redistribution and use in source and binary forms, with or without | ||
6 | * modification, are permitted provided that the following conditions are met: | ||
7 | * * Redistributions of source code must retain the above copyright | ||
8 | * notice, this list of conditions and the following disclaimer. | ||
9 | * * Redistributions in binary form must reproduce the above copyright | ||
10 | * notice, this list of conditions and the following disclaimer in the | ||
11 | * documentation and/or other materials provided with the distribution. | ||
12 | * * Neither the name of the OpenSim Project nor the | ||
13 | * names of its contributors may be used to endorse or promote products | ||
14 | * derived from this software without specific prior written permission. | ||
15 | * | ||
16 | * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY | ||
17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
19 | * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY | ||
20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | ||
23 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
26 | */ | ||
27 | |||
28 | /* TODO: Needs BSD rewrite */ | ||
diff --git a/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Generators/Mountain.cs b/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Generators/Mountain.cs deleted file mode 100644 index 06e7e3c..0000000 --- a/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Generators/Mountain.cs +++ /dev/null | |||
@@ -1,28 +0,0 @@ | |||
1 | /* | ||
2 | * Copyright (c) Contributors, http://opensimulator.org/ | ||
3 | * See CONTRIBUTORS.TXT for a full list of copyright holders. | ||
4 | * | ||
5 | * Redistribution and use in source and binary forms, with or without | ||
6 | * modification, are permitted provided that the following conditions are met: | ||
7 | * * Redistributions of source code must retain the above copyright | ||
8 | * notice, this list of conditions and the following disclaimer. | ||
9 | * * Redistributions in binary form must reproduce the above copyright | ||
10 | * notice, this list of conditions and the following disclaimer in the | ||
11 | * documentation and/or other materials provided with the distribution. | ||
12 | * * Neither the name of the OpenSim Project nor the | ||
13 | * names of its contributors may be used to endorse or promote products | ||
14 | * derived from this software without specific prior written permission. | ||
15 | * | ||
16 | * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY | ||
17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
19 | * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY | ||
20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | ||
23 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
26 | */ | ||
27 | |||
28 | /* TODO: Needs BSD rewrite */ | ||
diff --git a/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Generators/Noise.cs b/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Generators/Noise.cs deleted file mode 100644 index 10e8160..0000000 --- a/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Generators/Noise.cs +++ /dev/null | |||
@@ -1,53 +0,0 @@ | |||
1 | /* | ||
2 | * Copyright (c) Contributors, http://opensimulator.org/ | ||
3 | * See CONTRIBUTORS.TXT for a full list of copyright holders. | ||
4 | * | ||
5 | * Redistribution and use in source and binary forms, with or without | ||
6 | * modification, are permitted provided that the following conditions are met: | ||
7 | * * Redistributions of source code must retain the above copyright | ||
8 | * notice, this list of conditions and the following disclaimer. | ||
9 | * * Redistributions in binary form must reproduce the above copyright | ||
10 | * notice, this list of conditions and the following disclaimer in the | ||
11 | * documentation and/or other materials provided with the distribution. | ||
12 | * * Neither the name of the OpenSim Project nor the | ||
13 | * names of its contributors may be used to endorse or promote products | ||
14 | * derived from this software without specific prior written permission. | ||
15 | * | ||
16 | * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY | ||
17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
19 | * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY | ||
20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | ||
23 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
26 | */ | ||
27 | |||
28 | using System; | ||
29 | |||
30 | namespace libTerrain | ||
31 | { | ||
32 | partial class Channel | ||
33 | { | ||
34 | /// <summary> | ||
35 | /// Fills a channel with 0..1 noise | ||
36 | /// </summary> | ||
37 | /// <remarks>3-Clause BSD Licensed</remarks> | ||
38 | public void Noise() | ||
39 | { | ||
40 | SetDiff(); | ||
41 | |||
42 | Random rand = new Random(seed); | ||
43 | int x, y; | ||
44 | for (x = 0; x < w; x++) | ||
45 | { | ||
46 | for (y = 0; y < h; y++) | ||
47 | { | ||
48 | map[x, y] = rand.NextDouble(); | ||
49 | } | ||
50 | } | ||
51 | } | ||
52 | } | ||
53 | } | ||
diff --git a/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Generators/Spiral.cs b/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Generators/Spiral.cs deleted file mode 100644 index a516d8d..0000000 --- a/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Generators/Spiral.cs +++ /dev/null | |||
@@ -1,156 +0,0 @@ | |||
1 | /* | ||
2 | * Copyright (c) Contributors, http://opensimulator.org/ | ||
3 | * See CONTRIBUTORS.TXT for a full list of copyright holders. | ||
4 | * | ||
5 | * Redistribution and use in source and binary forms, with or without | ||
6 | * modification, are permitted provided that the following conditions are met: | ||
7 | * * Redistributions of source code must retain the above copyright | ||
8 | * notice, this list of conditions and the following disclaimer. | ||
9 | * * Redistributions in binary form must reproduce the above copyright | ||
10 | * notice, this list of conditions and the following disclaimer in the | ||
11 | * documentation and/or other materials provided with the distribution. | ||
12 | * * Neither the name of the OpenSim Project nor the | ||
13 | * names of its contributors may be used to endorse or promote products | ||
14 | * derived from this software without specific prior written permission. | ||
15 | * | ||
16 | * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY | ||
17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
19 | * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY | ||
20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | ||
23 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
26 | */ | ||
27 | |||
28 | using System; | ||
29 | using System.Collections.Generic; | ||
30 | |||
31 | namespace libTerrain | ||
32 | { | ||
33 | partial class Channel | ||
34 | { | ||
35 | private double[] CoordinatesToPolar(int x, int y) | ||
36 | { | ||
37 | double theta = Math.Atan2(x - (w/2), y - (h/2)); | ||
38 | double rx = (double) x - ((double) w/2); | ||
39 | double ry = (double) y - ((double) h/2); | ||
40 | double r = Math.Sqrt((rx*rx) + (ry*ry)); | ||
41 | |||
42 | double[] coords = new double[2]; | ||
43 | coords[0] = r; | ||
44 | coords[1] = theta; | ||
45 | return coords; | ||
46 | } | ||
47 | |||
48 | public int[] PolarToCoordinates(double r, double theta) | ||
49 | { | ||
50 | double nx; | ||
51 | double ny; | ||
52 | |||
53 | nx = (double) r*Math.Cos(theta); | ||
54 | ny = (double) r*Math.Sin(theta); | ||
55 | |||
56 | nx += w/2; | ||
57 | ny += h/2; | ||
58 | |||
59 | if (nx >= w) | ||
60 | nx = w - 1; | ||
61 | |||
62 | if (ny >= h) | ||
63 | ny = h - 1; | ||
64 | |||
65 | if (nx < 0) | ||
66 | nx = 0; | ||
67 | |||
68 | if (ny < 0) | ||
69 | ny = 0; | ||
70 | |||
71 | int[] coords = new int[2]; | ||
72 | coords[0] = (int) nx; | ||
73 | coords[1] = (int) ny; | ||
74 | return coords; | ||
75 | } | ||
76 | |||
77 | public void Polar() | ||
78 | { | ||
79 | SetDiff(); | ||
80 | |||
81 | Channel n = Copy(); | ||
82 | |||
83 | int x, y; | ||
84 | for (x = 0; x < w; x++) | ||
85 | { | ||
86 | for (y = 0; y < h; y++) | ||
87 | { | ||
88 | double[] coords = CoordinatesToPolar(x, y); | ||
89 | |||
90 | coords[0] += w/2.0; | ||
91 | coords[1] += h/2.0; | ||
92 | |||
93 | map[x, y] = n.map[(int) coords[0]%n.w, (int) coords[1]%n.h]; | ||
94 | } | ||
95 | } | ||
96 | } | ||
97 | |||
98 | public void SpiralPlanter(int steps, double incAngle, double incRadius, double offsetRadius, double offsetAngle) | ||
99 | { | ||
100 | SetDiff(); | ||
101 | |||
102 | int i; | ||
103 | double r = offsetRadius; | ||
104 | double theta = offsetAngle; | ||
105 | for (i = 0; i < steps; i++) | ||
106 | { | ||
107 | r += incRadius; | ||
108 | theta += incAngle; | ||
109 | |||
110 | int[] coords = PolarToCoordinates(r, theta); | ||
111 | Raise(coords[0], coords[1], 20, 1); | ||
112 | } | ||
113 | } | ||
114 | |||
115 | public void SpiralCells(int steps, double incAngle, double incRadius, double offsetRadius, double offsetAngle, | ||
116 | double[] c) | ||
117 | { | ||
118 | SetDiff(); | ||
119 | |||
120 | List<Point2D> points = new List<Point2D>(); | ||
121 | |||
122 | int i; | ||
123 | double r = offsetRadius; | ||
124 | double theta = offsetAngle; | ||
125 | for (i = 0; i < steps; i++) | ||
126 | { | ||
127 | r += incRadius; | ||
128 | theta += incAngle; | ||
129 | |||
130 | int[] coords = PolarToCoordinates(r, theta); | ||
131 | points.Add(new Point2D(coords[0], coords[1])); | ||
132 | } | ||
133 | |||
134 | VoronoiDiagram(points, c); | ||
135 | } | ||
136 | |||
137 | public void Spiral(double wid, double hig, double offset) | ||
138 | { | ||
139 | SetDiff(); | ||
140 | |||
141 | int x, y, z; | ||
142 | z = 0; | ||
143 | for (x = 0; x < w; x++) | ||
144 | { | ||
145 | for (y = 0; y < h; y++) | ||
146 | { | ||
147 | z++; | ||
148 | double dx = Math.Abs((w/2) - x); | ||
149 | double dy = Math.Abs((h/2) - y); | ||
150 | map[x, y] += Math.Sin(dx/wid) + Math.Cos(dy/hig); | ||
151 | } | ||
152 | } | ||
153 | Normalise(); | ||
154 | } | ||
155 | } | ||
156 | } | ||
diff --git a/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Generators/Voronoi.cs b/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Generators/Voronoi.cs deleted file mode 100644 index a4966a4..0000000 --- a/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Generators/Voronoi.cs +++ /dev/null | |||
@@ -1,211 +0,0 @@ | |||
1 | /* | ||
2 | * Copyright (c) Contributors, http://opensimulator.org/ | ||
3 | * See CONTRIBUTORS.TXT for a full list of copyright holders. | ||
4 | * | ||
5 | * Redistribution and use in source and binary forms, with or without | ||
6 | * modification, are permitted provided that the following conditions are met: | ||
7 | * * Redistributions of source code must retain the above copyright | ||
8 | * notice, this list of conditions and the following disclaimer. | ||
9 | * * Redistributions in binary form must reproduce the above copyright | ||
10 | * notice, this list of conditions and the following disclaimer in the | ||
11 | * documentation and/or other materials provided with the distribution. | ||
12 | * * Neither the name of the OpenSim Project nor the | ||
13 | * names of its contributors may be used to endorse or promote products | ||
14 | * derived from this software without specific prior written permission. | ||
15 | * | ||
16 | * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY | ||
17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
19 | * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY | ||
20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | ||
23 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
26 | */ | ||
27 | |||
28 | using System; | ||
29 | using System.Collections.Generic; | ||
30 | |||
31 | namespace libTerrain | ||
32 | { | ||
33 | partial class Channel | ||
34 | { | ||
35 | /// <summary> | ||
36 | /// Generates a Voronoi diagram (sort of a stained glass effect) which will fill the entire channel | ||
37 | /// </summary> | ||
38 | /// <remarks>3-Clause BSD Licensed</remarks> | ||
39 | /// <param name="pointsPerBlock">The number of generator points in each block</param> | ||
40 | /// <param name="blockSize">A multiple of the channel width and height which will have voronoi points generated in it. | ||
41 | /// <para>This is to ensure a more even distribution of the points than pure random allocation.</para></param> | ||
42 | /// <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> | ||
43 | public void VoronoiDiagram(int pointsPerBlock, int blockSize, double[] c) | ||
44 | { | ||
45 | SetDiff(); | ||
46 | |||
47 | List<Point2D> points = new List<Point2D>(); | ||
48 | Random generator = new Random(seed); | ||
49 | |||
50 | // Generate the emitter points | ||
51 | int x, y, i; | ||
52 | for (x = -blockSize; x < w + blockSize; x += blockSize) | ||
53 | { | ||
54 | for (y = -blockSize; y < h + blockSize; y += blockSize) | ||
55 | { | ||
56 | for (i = 0; i < pointsPerBlock; i++) | ||
57 | { | ||
58 | double pX = x + (generator.NextDouble()*(double) blockSize); | ||
59 | double pY = y + (generator.NextDouble()*(double) blockSize); | ||
60 | |||
61 | points.Add(new Point2D(pX, pY)); | ||
62 | } | ||
63 | } | ||
64 | } | ||
65 | |||
66 | double[] distances = new double[points.Count]; | ||
67 | |||
68 | // Calculate the distance each pixel is from an emitter | ||
69 | for (x = 0; x < w; x++) | ||
70 | { | ||
71 | for (y = 0; y < h; y++) | ||
72 | { | ||
73 | for (i = 0; i < points.Count; i++) | ||
74 | { | ||
75 | double dx, dy; | ||
76 | dx = Math.Abs((double) x - points[i].x); | ||
77 | dy = Math.Abs((double) y - points[i].y); | ||
78 | |||
79 | distances[i] = (dx*dx + dy*dy); | ||
80 | } | ||
81 | |||
82 | Array.Sort(distances); | ||
83 | |||
84 | double f = 0.0; | ||
85 | |||
86 | // Multiply the distances with their 'c' counterpart | ||
87 | // ordering the distances descending | ||
88 | for (i = 0; i < c.Length; i++) | ||
89 | { | ||
90 | if (i >= points.Count) | ||
91 | break; | ||
92 | |||
93 | f += c[i]*distances[i]; | ||
94 | } | ||
95 | |||
96 | map[x, y] = f; | ||
97 | } | ||
98 | } | ||
99 | |||
100 | // Normalise the result | ||
101 | Normalise(); | ||
102 | } | ||
103 | |||
104 | public void VoronoiDiagram(List<Point2D> points, double[] c) | ||
105 | { | ||
106 | SetDiff(); | ||
107 | |||
108 | int x, y, i; | ||
109 | double[] distances = new double[points.Count]; | ||
110 | |||
111 | // Calculate the distance each pixel is from an emitter | ||
112 | for (x = 0; x < w; x++) | ||
113 | { | ||
114 | for (y = 0; y < h; y++) | ||
115 | { | ||
116 | for (i = 0; i < points.Count; i++) | ||
117 | { | ||
118 | double dx, dy; | ||
119 | dx = Math.Abs((double) x - points[i].x); | ||
120 | dy = Math.Abs((double) y - points[i].y); | ||
121 | |||
122 | distances[i] = (dx*dx + dy*dy); | ||
123 | } | ||
124 | |||
125 | Array.Sort(distances); | ||
126 | |||
127 | double f = 0.0; | ||
128 | |||
129 | // Multiply the distances with their 'c' counterpart | ||
130 | // ordering the distances descending | ||
131 | for (i = 0; i < c.Length; i++) | ||
132 | { | ||
133 | if (i >= points.Count) | ||
134 | break; | ||
135 | |||
136 | f += c[i]*distances[i]; | ||
137 | } | ||
138 | |||
139 | map[x, y] = f; | ||
140 | } | ||
141 | } | ||
142 | |||
143 | // Normalise the result | ||
144 | Normalise(); | ||
145 | } | ||
146 | |||
147 | public void VoroflatDiagram(int pointsPerBlock, int blockSize) | ||
148 | { | ||
149 | SetDiff(); | ||
150 | |||
151 | List<Point2D> points = new List<Point2D>(); | ||
152 | Random generator = new Random(seed); | ||
153 | |||
154 | // Generate the emitter points | ||
155 | int x, y, i; | ||
156 | for (x = -blockSize; x < w + blockSize; x += blockSize) | ||
157 | { | ||
158 | for (y = -blockSize; y < h + blockSize; y += blockSize) | ||
159 | { | ||
160 | for (i = 0; i < pointsPerBlock; i++) | ||
161 | { | ||
162 | double pX = x + (generator.NextDouble()*(double) blockSize); | ||
163 | double pY = y + (generator.NextDouble()*(double) blockSize); | ||
164 | |||
165 | points.Add(new Point2D(pX, pY)); | ||
166 | } | ||
167 | } | ||
168 | } | ||
169 | |||
170 | double[] distances = new double[points.Count]; | ||
171 | |||
172 | // Calculate the distance each pixel is from an emitter | ||
173 | for (x = 0; x < w; x++) | ||
174 | { | ||
175 | for (y = 0; y < h; y++) | ||
176 | { | ||
177 | for (i = 0; i < points.Count; i++) | ||
178 | { | ||
179 | double dx, dy; | ||
180 | dx = Math.Abs((double) x - points[i].x); | ||
181 | dy = Math.Abs((double) y - points[i].y); | ||
182 | |||
183 | distances[i] = (dx*dx + dy*dy); | ||
184 | } | ||
185 | |||
186 | //Array.Sort(distances); | ||
187 | |||
188 | double f = 0.0; | ||
189 | |||
190 | double min = double.MaxValue; | ||
191 | for (int j = 0; j < distances.Length; j++) | ||
192 | { | ||
193 | if (distances[j] < min) | ||
194 | { | ||
195 | min = distances[j]; | ||
196 | f = j; | ||
197 | } | ||
198 | } | ||
199 | |||
200 | // Multiply the distances with their 'c' counterpart | ||
201 | // ordering the distances descending | ||
202 | |||
203 | map[x, y] = f; | ||
204 | } | ||
205 | } | ||
206 | |||
207 | // Normalise the result | ||
208 | Normalise(); | ||
209 | } | ||
210 | } | ||
211 | } | ||
diff --git a/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Generators/Worms.cs b/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Generators/Worms.cs deleted file mode 100644 index d9f0990..0000000 --- a/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Generators/Worms.cs +++ /dev/null | |||
@@ -1,71 +0,0 @@ | |||
1 | /* | ||
2 | * Copyright (c) Contributors, http://opensimulator.org/ | ||
3 | * See CONTRIBUTORS.TXT for a full list of copyright holders. | ||
4 | * | ||
5 | * Redistribution and use in source and binary forms, with or without | ||
6 | * modification, are permitted provided that the following conditions are met: | ||
7 | * * Redistributions of source code must retain the above copyright | ||
8 | * notice, this list of conditions and the following disclaimer. | ||
9 | * * Redistributions in binary form must reproduce the above copyright | ||
10 | * notice, this list of conditions and the following disclaimer in the | ||
11 | * documentation and/or other materials provided with the distribution. | ||
12 | * * Neither the name of the OpenSim Project nor the | ||
13 | * names of its contributors may be used to endorse or promote products | ||
14 | * derived from this software without specific prior written permission. | ||
15 | * | ||
16 | * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY | ||
17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
19 | * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY | ||
20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | ||
23 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
26 | */ | ||
27 | |||
28 | using System; | ||
29 | |||
30 | namespace libTerrain | ||
31 | { | ||
32 | partial class Channel | ||
33 | { | ||
34 | /// <summary> | ||
35 | /// Generates 'number' of worms which navigate randomly around the landscape creating terrain as they go. | ||
36 | /// </summary> | ||
37 | /// <param name="number">The number of worms which will traverse the map</param> | ||
38 | /// <param name="rounds">The number of steps each worm will traverse</param> | ||
39 | /// <param name="movement">The maximum distance each worm will move each step</param> | ||
40 | /// <param name="size">The size of the area around the worm modified</param> | ||
41 | /// <param name="centerspawn">Do worms start in the middle, or randomly?</param> | ||
42 | public void Worms(int number, int rounds, double movement, double size, bool centerspawn) | ||
43 | { | ||
44 | SetDiff(); | ||
45 | |||
46 | Random random = new Random(seed); | ||
47 | int i, j; | ||
48 | |||
49 | for (i = 0; i < number; i++) | ||
50 | { | ||
51 | double rx, ry; | ||
52 | if (centerspawn) | ||
53 | { | ||
54 | rx = w/2.0; | ||
55 | ry = h/2.0; | ||
56 | } | ||
57 | else | ||
58 | { | ||
59 | rx = random.NextDouble()*(w - 1); | ||
60 | ry = random.NextDouble()*(h - 1); | ||
61 | } | ||
62 | for (j = 0; j < rounds; j++) | ||
63 | { | ||
64 | rx += (random.NextDouble()*movement) - (movement/2.0); | ||
65 | ry += (random.NextDouble()*movement) - (movement/2.0); | ||
66 | Raise(rx, ry, size, 1.0); | ||
67 | } | ||
68 | } | ||
69 | } | ||
70 | } | ||
71 | } | ||
diff --git a/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Grid.cs b/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Grid.cs deleted file mode 100644 index a3e24a2..0000000 --- a/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Grid.cs +++ /dev/null | |||
@@ -1,376 +0,0 @@ | |||
1 | /* | ||
2 | * Copyright (c) Contributors, http://opensimulator.org/ | ||
3 | * See CONTRIBUTORS.TXT for a full list of copyright holders. | ||
4 | * | ||
5 | * Redistribution and use in source and binary forms, with or without | ||
6 | * modification, are permitted provided that the following conditions are met: | ||
7 | * * Redistributions of source code must retain the above copyright | ||
8 | * notice, this list of conditions and the following disclaimer. | ||
9 | * * Redistributions in binary form must reproduce the above copyright | ||
10 | * notice, this list of conditions and the following disclaimer in the | ||
11 | * documentation and/or other materials provided with the distribution. | ||
12 | * * Neither the name of the OpenSim Project nor the | ||
13 | * names of its contributors may be used to endorse or promote products | ||
14 | * derived from this software without specific prior written permission. | ||
15 | * | ||
16 | * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY | ||
17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
19 | * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY | ||
20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | ||
23 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
26 | */ | ||
27 | |||
28 | using System; | ||
29 | |||
30 | namespace libTerrain | ||
31 | { | ||
32 | partial class Channel | ||
33 | { | ||
34 | public Channel Normalise() | ||
35 | { | ||
36 | SetDiff(); | ||
37 | |||
38 | double max = FindMax(); | ||
39 | double min = FindMin(); | ||
40 | |||
41 | int x, y; | ||
42 | |||
43 | if (max != min) | ||
44 | { | ||
45 | for (x = 0; x < w; x++) | ||
46 | { | ||
47 | for (y = 0; y < h; y++) | ||
48 | { | ||
49 | map[x, y] = (map[x, y] - min)*(1.0/(max - min)); | ||
50 | } | ||
51 | } | ||
52 | } | ||
53 | else | ||
54 | { | ||
55 | Fill(0.5); | ||
56 | } | ||
57 | |||
58 | return this; | ||
59 | } | ||
60 | |||
61 | public Channel Normalise(double minv, double maxv) | ||
62 | { | ||
63 | SetDiff(); | ||
64 | |||
65 | if (minv == maxv) | ||
66 | { | ||
67 | Fill(minv); | ||
68 | return this; | ||
69 | } | ||
70 | |||
71 | double max = FindMax(); | ||
72 | double min = FindMin(); | ||
73 | |||
74 | int x, y; | ||
75 | |||
76 | for (x = 0; x < w; x++) | ||
77 | { | ||
78 | for (y = 0; y < h; y++) | ||
79 | { | ||
80 | if (min != max) | ||
81 | { | ||
82 | double val = (map[x, y] - min)*(1.0/(max - min)); | ||
83 | val *= maxv - minv; | ||
84 | val += minv; | ||
85 | |||
86 | map[x, y] = val; | ||
87 | } | ||
88 | else | ||
89 | { | ||
90 | map[x, y] = 0.5; | ||
91 | } | ||
92 | } | ||
93 | } | ||
94 | |||
95 | return this; | ||
96 | } | ||
97 | |||
98 | public Channel Elevate(double meters) | ||
99 | { | ||
100 | SetDiff(); | ||
101 | |||
102 | int x, y; | ||
103 | |||
104 | for (x = 0; x < w; x++) | ||
105 | { | ||
106 | for (y = 0; y < h; y++) | ||
107 | { | ||
108 | map[x, y] += meters; | ||
109 | } | ||
110 | } | ||
111 | |||
112 | return this; | ||
113 | } | ||
114 | |||
115 | |||
116 | public Channel Clip() | ||
117 | { | ||
118 | int x, y; | ||
119 | |||
120 | for (x = 0; x < w; x++) | ||
121 | { | ||
122 | for (y = 0; y < h; y++) | ||
123 | { | ||
124 | SetClip(x, y, map[x, y]); | ||
125 | } | ||
126 | } | ||
127 | |||
128 | return this; | ||
129 | } | ||
130 | |||
131 | public Channel Clip(double min, double max) | ||
132 | { | ||
133 | int x, y; | ||
134 | for (x = 0; x < w; x++) | ||
135 | { | ||
136 | for (y = 0; y < h; y++) | ||
137 | { | ||
138 | double val = map[x, y]; | ||
139 | if (val > max) val = max; | ||
140 | if (val < min) val = min; | ||
141 | |||
142 | Set(x, y, val); | ||
143 | } | ||
144 | } | ||
145 | return this; | ||
146 | } | ||
147 | |||
148 | public Channel Crop(int x1, int y1, int x2, int y2) | ||
149 | { | ||
150 | int width = x1 - x2 + 1; | ||
151 | int height = y1 - y2 + 1; | ||
152 | Channel chan = new Channel(width, height); | ||
153 | |||
154 | int x, y; | ||
155 | int nx, ny; | ||
156 | |||
157 | nx = 0; | ||
158 | for (x = x1; x < x2; x++) | ||
159 | { | ||
160 | ny = 0; | ||
161 | for (y = y1; y < y2; y++) | ||
162 | { | ||
163 | chan.map[nx, ny] = map[x, y]; | ||
164 | |||
165 | ny++; | ||
166 | } | ||
167 | nx++; | ||
168 | } | ||
169 | |||
170 | return this; | ||
171 | } | ||
172 | |||
173 | public Channel AddClip(Channel other) | ||
174 | { | ||
175 | SetDiff(); | ||
176 | |||
177 | int x, y; | ||
178 | for (x = 0; x < w; x++) | ||
179 | { | ||
180 | for (y = 0; y < h; y++) | ||
181 | { | ||
182 | map[x, y] = other.map[x, y]; | ||
183 | if (map[x, y] > 1) | ||
184 | map[x, y] = 1; | ||
185 | if (map[x, y] < 0) | ||
186 | map[x, y] = 0; | ||
187 | } | ||
188 | } | ||
189 | return this; | ||
190 | } | ||
191 | |||
192 | public void Smooth(double amount) | ||
193 | { | ||
194 | SetDiff(); | ||
195 | |||
196 | double area = amount; | ||
197 | double step = amount/4.0; | ||
198 | |||
199 | double[,] manipulate = new double[w,h]; | ||
200 | int x, y; | ||
201 | double n, l; | ||
202 | for (x = 0; x < w; x++) | ||
203 | { | ||
204 | for (y = 0; y < h; y++) | ||
205 | { | ||
206 | double average = 0.0; | ||
207 | int avgsteps = 0; | ||
208 | |||
209 | for (n = 0.0 - area; n < area; n += step) | ||
210 | { | ||
211 | for (l = 0.0 - area; l < area; l += step) | ||
212 | { | ||
213 | avgsteps++; | ||
214 | average += GetBilinearInterpolate(x + n, y + l); | ||
215 | } | ||
216 | } | ||
217 | |||
218 | manipulate[x, y] = average/avgsteps; | ||
219 | } | ||
220 | } | ||
221 | map = manipulate; | ||
222 | } | ||
223 | |||
224 | public void Pertubation(double amount) | ||
225 | { | ||
226 | SetDiff(); | ||
227 | |||
228 | // Simple pertubation filter | ||
229 | double[,] manipulated = new double[w,h]; | ||
230 | Random generator = new Random(seed); // Seeds FTW! | ||
231 | //double amount = 8.0; | ||
232 | |||
233 | int x, y; | ||
234 | for (x = 0; x < w; x++) | ||
235 | { | ||
236 | for (y = 0; y < h; y++) | ||
237 | { | ||
238 | double offset_x = (double) x + (generator.NextDouble()*amount) - (amount/2.0); | ||
239 | double offset_y = (double) y + (generator.NextDouble()*amount) - (amount/2.0); | ||
240 | double p = GetBilinearInterpolate(offset_x, offset_y); | ||
241 | manipulated[x, y] = p; | ||
242 | } | ||
243 | } | ||
244 | map = manipulated; | ||
245 | } | ||
246 | |||
247 | public void PertubationMask(Channel mask) | ||
248 | { | ||
249 | // Simple pertubation filter | ||
250 | double[,] manipulated = new double[w,h]; | ||
251 | Random generator = new Random(seed); // Seeds FTW! | ||
252 | //double amount = 8.0; | ||
253 | |||
254 | double amount; | ||
255 | |||
256 | int x, y; | ||
257 | for (x = 0; x < w; x++) | ||
258 | { | ||
259 | for (y = 0; y < h; y++) | ||
260 | { | ||
261 | amount = mask.map[x, y]; | ||
262 | double offset_x = (double) x + (generator.NextDouble()*amount) - (amount/2.0); | ||
263 | double offset_y = (double) y + (generator.NextDouble()*amount) - (amount/2.0); | ||
264 | |||
265 | if (offset_x > w) | ||
266 | offset_x = w - 1; | ||
267 | if (offset_y > h) | ||
268 | offset_y = h - 1; | ||
269 | if (offset_y < 0) | ||
270 | offset_y = 0; | ||
271 | if (offset_x < 0) | ||
272 | offset_x = 0; | ||
273 | |||
274 | double p = GetBilinearInterpolate(offset_x, offset_y); | ||
275 | manipulated[x, y] = p; | ||
276 | SetDiff(x, y); | ||
277 | } | ||
278 | } | ||
279 | map = manipulated; | ||
280 | } | ||
281 | |||
282 | public void Distort(Channel mask, double str) | ||
283 | { | ||
284 | // Simple pertubation filter | ||
285 | double[,] manipulated = new double[w,h]; | ||
286 | |||
287 | double amount; | ||
288 | |||
289 | int x, y; | ||
290 | for (x = 0; x < w; x++) | ||
291 | { | ||
292 | for (y = 0; y < h; y++) | ||
293 | { | ||
294 | amount = mask.map[x, y]; | ||
295 | double offset_x = (double) x + (amount*str) - (0.5*str); | ||
296 | double offset_y = (double) y + (amount*str) - (0.5*str); | ||
297 | |||
298 | if (offset_x > w) | ||
299 | offset_x = w - 1; | ||
300 | if (offset_y > h) | ||
301 | offset_y = h - 1; | ||
302 | if (offset_y < 0) | ||
303 | offset_y = 0; | ||
304 | if (offset_x < 0) | ||
305 | offset_x = 0; | ||
306 | |||
307 | double p = GetBilinearInterpolate(offset_x, offset_y); | ||
308 | manipulated[x, y] = p; | ||
309 | SetDiff(x, y); | ||
310 | } | ||
311 | } | ||
312 | map = manipulated; | ||
313 | } | ||
314 | |||
315 | public void Distort(Channel mask, Channel mask2, double str) | ||
316 | { | ||
317 | // Simple pertubation filter | ||
318 | double[,] manipulated = new double[w,h]; | ||
319 | |||
320 | double amountX; | ||
321 | double amountY; | ||
322 | |||
323 | int x, y; | ||
324 | for (x = 0; x < w; x++) | ||
325 | { | ||
326 | for (y = 0; y < h; y++) | ||
327 | { | ||
328 | amountX = mask.map[x, y]; | ||
329 | amountY = mask2.map[x, y]; | ||
330 | double offset_x = (double) x + (amountX*str) - (0.5*str); | ||
331 | double offset_y = (double) y + (amountY*str) - (0.5*str); | ||
332 | |||
333 | if (offset_x > w) | ||
334 | offset_x = w - 1; | ||
335 | if (offset_y > h) | ||
336 | offset_y = h - 1; | ||
337 | if (offset_y < 0) | ||
338 | offset_y = 0; | ||
339 | if (offset_x < 0) | ||
340 | offset_x = 0; | ||
341 | |||
342 | double p = GetBilinearInterpolate(offset_x, offset_y); | ||
343 | manipulated[x, y] = p; | ||
344 | SetDiff(x, y); | ||
345 | } | ||
346 | } | ||
347 | map = manipulated; | ||
348 | } | ||
349 | |||
350 | public Channel Blend(Channel other, double amount) | ||
351 | { | ||
352 | int x, y; | ||
353 | for (x = 0; x < w; x++) | ||
354 | { | ||
355 | for (y = 0; y < h; y++) | ||
356 | { | ||
357 | Set(x, y, Tools.LinearInterpolate(map[x, y], other.map[x, y], amount)); | ||
358 | } | ||
359 | } | ||
360 | return this; | ||
361 | } | ||
362 | |||
363 | public Channel Blend(Channel other, Channel amount) | ||
364 | { | ||
365 | int x, y; | ||
366 | for (x = 0; x < w; x++) | ||
367 | { | ||
368 | for (y = 0; y < h; y++) | ||
369 | { | ||
370 | Set(x, y, Tools.LinearInterpolate(map[x, y], other.map[x, y], amount.map[x, y])); | ||
371 | } | ||
372 | } | ||
373 | return this; | ||
374 | } | ||
375 | } | ||
376 | } | ||
diff --git a/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Manipulators/AerobicErosion.cs b/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Manipulators/AerobicErosion.cs deleted file mode 100644 index 6a846cd..0000000 --- a/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Manipulators/AerobicErosion.cs +++ /dev/null | |||
@@ -1,211 +0,0 @@ | |||
1 | /* | ||
2 | * Copyright (c) Contributors, http://opensimulator.org/ | ||
3 | * See CONTRIBUTORS.TXT for a full list of copyright holders. | ||
4 | * | ||
5 | * Redistribution and use in source and binary forms, with or without | ||
6 | * modification, are permitted provided that the following conditions are met: | ||
7 | * * Redistributions of source code must retain the above copyright | ||
8 | * notice, this list of conditions and the following disclaimer. | ||
9 | * * Redistributions in binary form must reproduce the above copyright | ||
10 | * notice, this list of conditions and the following disclaimer in the | ||
11 | * documentation and/or other materials provided with the distribution. | ||
12 | * * Neither the name of the OpenSim Project nor the | ||
13 | * names of its contributors may be used to endorse or promote products | ||
14 | * derived from this software without specific prior written permission. | ||
15 | * | ||
16 | * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY | ||
17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
19 | * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY | ||
20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | ||
23 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
26 | */ | ||
27 | |||
28 | using System; | ||
29 | |||
30 | namespace libTerrain | ||
31 | { | ||
32 | partial class Channel | ||
33 | { | ||
34 | // Ideas for Aerobic erosion | ||
35 | // | ||
36 | // Unlike thermal (gravity) and hydraulic (water suspension) | ||
37 | // aerobic erosion should displace mass by moving sediment | ||
38 | // in "hops". The length of the hop being dictated by the | ||
39 | // presence of sharp cliffs and wind speed. | ||
40 | |||
41 | // The ability to pickup sediment is defined by the total | ||
42 | // surface area, such that: | ||
43 | // 0 0 0 | ||
44 | // 0 1 0 | ||
45 | // 0 0 0 | ||
46 | // Would be the best possible value for sediment to be | ||
47 | // picked up (total difference = 8) and flatter land | ||
48 | // will erode less quickly. | ||
49 | |||
50 | // Suspended particles assist the erosion process by hitting | ||
51 | // the surface and chiselling additional particles off faster | ||
52 | // than alone. | ||
53 | |||
54 | // Particles are deposited when one of two conditions is met | ||
55 | // First: | ||
56 | // When particles hit a wall - such that the | ||
57 | // wind direction points at a difference >= the | ||
58 | // deposition mininum talus. | ||
59 | // Second: | ||
60 | // When wind speed is lowered to below the minimum | ||
61 | // required for transit. An idea for this is to | ||
62 | // use the navier-stokes algorithms for simulating | ||
63 | // pressure across the terrain. | ||
64 | |||
65 | /// <summary> | ||
66 | /// An experimental erosion algorithm developed by Adam. Moves sediment by factoring the surface area of each height point. | ||
67 | /// </summary> | ||
68 | /// <param name="windspeed">0..1 The speed of the wind</param> | ||
69 | /// <param name="pickup_talus_minimum">The minimum angle at which rock is eroded 0..1 (recommended: <= 0.30)</param> | ||
70 | /// <param name="drop_talus_minimum">The minimum angle at which rock is dropped 0..1 (recommended: >= 0.00)</param> | ||
71 | /// <param name="carry">The percentage of rock which can be picked up to pickup 0..1</param> | ||
72 | /// <param name="rounds">The number of erosion rounds (recommended: 25+)</param> | ||
73 | /// <param name="lowest">Drop sediment at the lowest point?</param> | ||
74 | public void AerobicErosion(double windspeed, double pickupTalusMinimum, double dropTalusMinimum, double carry, | ||
75 | int rounds, bool lowest, bool usingFluidDynamics) | ||
76 | { | ||
77 | bool debugImages = false; | ||
78 | |||
79 | Channel wind = new Channel(w, h); | ||
80 | Channel sediment = new Channel(w, h); | ||
81 | int x, y, i, j; | ||
82 | |||
83 | Normalise(); | ||
84 | |||
85 | wind = Copy(); | ||
86 | wind.Noise(); | ||
87 | |||
88 | if (debugImages) | ||
89 | wind.SaveImage("testimg/wind_start.png"); | ||
90 | |||
91 | if (usingFluidDynamics) | ||
92 | { | ||
93 | wind.navierStokes(20, 0.1, 0.0, 0.0); | ||
94 | } | ||
95 | else | ||
96 | { | ||
97 | wind.Pertubation(30); | ||
98 | } | ||
99 | |||
100 | if (debugImages) | ||
101 | wind.SaveImage("testimg/wind_begin.png"); | ||
102 | |||
103 | for (i = 0; i < rounds; i++) | ||
104 | { | ||
105 | // Convert some rocks to sand | ||
106 | for (x = 1; x < w - 1; x++) | ||
107 | { | ||
108 | for (y = 1; y < h - 1; y++) | ||
109 | { | ||
110 | double me = Get(x, y); | ||
111 | double surfacearea = 0.3; // Everything will erode even if it's flat. Just slower. | ||
112 | |||
113 | for (j = 0; j < 9; j++) | ||
114 | { | ||
115 | int[] coords = Neighbours(NeighbourSystem.Moore, j); | ||
116 | double target = Get(x + coords[0], y + coords[1]); | ||
117 | |||
118 | surfacearea += Math.Abs(target - me); | ||
119 | } | ||
120 | |||
121 | double amount = surfacearea*wind.map[x, y]*carry; | ||
122 | |||
123 | if (amount < 0) | ||
124 | amount = 0; | ||
125 | |||
126 | if (surfacearea > pickupTalusMinimum) | ||
127 | { | ||
128 | Set(x, y, map[x, y] - amount); | ||
129 | sediment.map[x, y] += amount; | ||
130 | } | ||
131 | } | ||
132 | } | ||
133 | |||
134 | if (usingFluidDynamics) | ||
135 | { | ||
136 | sediment.navierStokes(7, 0.1, 0.0, 0.1); | ||
137 | |||
138 | Channel noiseChan = new Channel(w, h); | ||
139 | noiseChan.Noise(); | ||
140 | wind.Blend(noiseChan, 0.01); | ||
141 | |||
142 | wind.navierStokes(10, 0.1, 0.01, 0.01); | ||
143 | |||
144 | sediment.Distort(wind, windspeed); | ||
145 | } | ||
146 | else | ||
147 | { | ||
148 | wind.Pertubation(15); // Can do better later | ||
149 | wind.seed++; | ||
150 | sediment.Pertubation(10); // Sediment is blown around a bit | ||
151 | sediment.seed++; | ||
152 | } | ||
153 | |||
154 | if (debugImages) | ||
155 | wind.SaveImage("testimg/wind_" + i.ToString() + ".png"); | ||
156 | |||
157 | // Convert some sand to rock | ||
158 | for (x = 1; x < w - 1; x++) | ||
159 | { | ||
160 | for (y = 1; y < h - 1; y++) | ||
161 | { | ||
162 | double me = Get(x, y); | ||
163 | double surfacearea = 0.01; // Flat land does not get deposition | ||
164 | double min = double.MaxValue; | ||
165 | int[] minside = new int[2]; | ||
166 | |||
167 | for (j = 0; j < 9; j++) | ||
168 | { | ||
169 | int[] coords = Neighbours(NeighbourSystem.Moore, j); | ||
170 | double target = Get(x + coords[0], y + coords[1]); | ||
171 | |||
172 | surfacearea += Math.Abs(target - me); | ||
173 | |||
174 | if (target < min && lowest) | ||
175 | { | ||
176 | minside = (int[]) coords.Clone(); | ||
177 | min = target; | ||
178 | } | ||
179 | } | ||
180 | |||
181 | double amount = surfacearea*(1.0 - wind.map[x, y])*carry; | ||
182 | |||
183 | if (amount < 0) | ||
184 | amount = 0; | ||
185 | |||
186 | if (surfacearea > dropTalusMinimum) | ||
187 | { | ||
188 | Set(x + minside[0], y + minside[1], map[x + minside[0], y + minside[1]] + amount); | ||
189 | sediment.map[x, y] -= amount; | ||
190 | } | ||
191 | } | ||
192 | } | ||
193 | |||
194 | if (debugImages) | ||
195 | sediment.SaveImage("testimg/sediment_" + i.ToString() + ".png"); | ||
196 | |||
197 | wind.Normalise(); | ||
198 | wind *= windspeed; | ||
199 | |||
200 | Normalise(); | ||
201 | } | ||
202 | |||
203 | Channel myself = this; | ||
204 | myself += sediment; | ||
205 | myself.Normalise(); | ||
206 | |||
207 | if (debugImages) | ||
208 | SaveImage("testimg/output.png"); | ||
209 | } | ||
210 | } | ||
211 | } | ||
diff --git a/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Manipulators/HydraulicErosion.cs b/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Manipulators/HydraulicErosion.cs deleted file mode 100644 index 608e0e3..0000000 --- a/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Manipulators/HydraulicErosion.cs +++ /dev/null | |||
@@ -1,144 +0,0 @@ | |||
1 | /* | ||
2 | * Copyright (c) Contributors, http://opensimulator.org/ | ||
3 | * See CONTRIBUTORS.TXT for a full list of copyright holders. | ||
4 | * | ||
5 | * Redistribution and use in source and binary forms, with or without | ||
6 | * modification, are permitted provided that the following conditions are met: | ||
7 | * * Redistributions of source code must retain the above copyright | ||
8 | * notice, this list of conditions and the following disclaimer. | ||
9 | * * Redistributions in binary form must reproduce the above copyright | ||
10 | * notice, this list of conditions and the following disclaimer in the | ||
11 | * documentation and/or other materials provided with the distribution. | ||
12 | * * Neither the name of the OpenSim Project nor the | ||
13 | * names of its contributors may be used to endorse or promote products | ||
14 | * derived from this software without specific prior written permission. | ||
15 | * | ||
16 | * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY | ||
17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
19 | * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY | ||
20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | ||
23 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
26 | */ | ||
27 | |||
28 | using System; | ||
29 | |||
30 | namespace libTerrain | ||
31 | { | ||
32 | partial class Channel | ||
33 | { | ||
34 | public void HydraulicErosion(Channel rain, double evaporation, double solubility, int frequency, int rounds) | ||
35 | { | ||
36 | SetDiff(); | ||
37 | |||
38 | Channel water = new Channel(w, h); | ||
39 | Channel sediment = new Channel(w, h); | ||
40 | Channel terrain = this; | ||
41 | Channel waterFlow = new Channel(w, h); | ||
42 | |||
43 | NeighbourSystem type = NeighbourSystem.Moore; | ||
44 | int NEIGHBOUR_ME = 4; | ||
45 | |||
46 | int NEIGHBOUR_MAX = type == NeighbourSystem.Moore ? 9 : 5; | ||
47 | |||
48 | for (int i = 0; i < rounds; i++) | ||
49 | { | ||
50 | water += rain; | ||
51 | |||
52 | sediment = terrain*water; | ||
53 | terrain -= sediment; | ||
54 | |||
55 | for (int x = 1; x < w - 1; x++) | ||
56 | { | ||
57 | for (int y = 1; y < h - 1; y++) | ||
58 | { | ||
59 | double[] heights = new double[NEIGHBOUR_MAX]; | ||
60 | double[] diffs = new double[NEIGHBOUR_MAX]; | ||
61 | |||
62 | double heightCenter = map[x, y]; | ||
63 | |||
64 | for (int j = 0; j < NEIGHBOUR_MAX; j++) | ||
65 | { | ||
66 | if (j != NEIGHBOUR_ME) | ||
67 | { | ||
68 | int[] coords = Neighbours(type, j); | ||
69 | coords[0] += x; | ||
70 | coords[1] += y; | ||
71 | |||
72 | heights[j] = map[coords[0], coords[1]] + water.map[coords[0], coords[1]] + | ||
73 | sediment.map[coords[0], coords[1]]; | ||
74 | diffs[j] = heightCenter - heights[j]; | ||
75 | } | ||
76 | } | ||
77 | |||
78 | double totalHeight = 0; | ||
79 | double totalHeightDiff = 0; | ||
80 | int totalCellsCounted = 1; | ||
81 | |||
82 | for (int j = 0; j < NEIGHBOUR_MAX; j++) | ||
83 | { | ||
84 | if (j != NEIGHBOUR_ME) | ||
85 | { | ||
86 | if (diffs[j] > 0) | ||
87 | { | ||
88 | totalHeight += heights[j]; | ||
89 | totalHeightDiff += diffs[j]; | ||
90 | totalCellsCounted++; | ||
91 | } | ||
92 | } | ||
93 | } | ||
94 | |||
95 | if (totalCellsCounted == 1) | ||
96 | continue; | ||
97 | |||
98 | double averageHeight = totalHeight/totalCellsCounted; | ||
99 | double waterAmount = Math.Min(water.map[x, y], heightCenter - averageHeight); | ||
100 | |||
101 | // TODO: Check this. | ||
102 | waterFlow.map[x, y] += waterFlow.map[x, y] - waterAmount; | ||
103 | |||
104 | double totalInverseDiff = waterAmount/totalHeightDiff; | ||
105 | |||
106 | for (int j = 0; j < NEIGHBOUR_MAX; j++) | ||
107 | { | ||
108 | if (j != NEIGHBOUR_ME) | ||
109 | { | ||
110 | int[] coords = Neighbours(type, j); | ||
111 | coords[0] += x; | ||
112 | coords[1] += y; | ||
113 | |||
114 | if (diffs[j] > 0) | ||
115 | { | ||
116 | waterFlow.SetWrap(coords[0], coords[1], | ||
117 | waterFlow.map[coords[0], coords[1]] + diffs[j]*totalInverseDiff); | ||
118 | } | ||
119 | } | ||
120 | } | ||
121 | } | ||
122 | } | ||
123 | |||
124 | water += waterFlow; | ||
125 | waterFlow.Fill(0); | ||
126 | |||
127 | water *= evaporation; | ||
128 | |||
129 | for (int x = 0; x < w; x++) | ||
130 | { | ||
131 | for (int y = 0; y < h; y++) | ||
132 | { | ||
133 | double deposition = sediment.map[x, y] - water.map[x, y]*solubility; | ||
134 | if (deposition > 0) | ||
135 | { | ||
136 | sediment.map[x, y] -= deposition; | ||
137 | terrain.map[x, y] += deposition; | ||
138 | } | ||
139 | } | ||
140 | } | ||
141 | } | ||
142 | } | ||
143 | } | ||
144 | } | ||
diff --git a/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Manipulators/NavierStokes.cs b/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Manipulators/NavierStokes.cs deleted file mode 100644 index 8f12637..0000000 --- a/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Manipulators/NavierStokes.cs +++ /dev/null | |||
@@ -1,307 +0,0 @@ | |||
1 | /* | ||
2 | * Copyright (c) Contributors, http://opensimulator.org/ | ||
3 | * See CONTRIBUTORS.TXT for a full list of copyright holders. | ||
4 | * | ||
5 | * Redistribution and use in source and binary forms, with or without | ||
6 | * modification, are permitted provided that the following conditions are met: | ||
7 | * * Redistributions of source code must retain the above copyright | ||
8 | * notice, this list of conditions and the following disclaimer. | ||
9 | * * Redistributions in binary form must reproduce the above copyright | ||
10 | * notice, this list of conditions and the following disclaimer in the | ||
11 | * documentation and/or other materials provided with the distribution. | ||
12 | * * Neither the name of the OpenSim Project nor the | ||
13 | * names of its contributors may be used to endorse or promote products | ||
14 | * derived from this software without specific prior written permission. | ||
15 | * | ||
16 | * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY | ||
17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
19 | * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY | ||
20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | ||
23 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
26 | */ | ||
27 | |||
28 | namespace libTerrain | ||
29 | { | ||
30 | partial class Channel | ||
31 | { | ||
32 | // Navier Stokes Algorithms ported from | ||
33 | // "Real-Time Fluid Dynamics for Games" by Jos Stam. | ||
34 | // presented at GDC 2003. | ||
35 | |||
36 | // Poorly ported from C++. (I gave up making it properly native somewhere after nsSetBnd) | ||
37 | |||
38 | private static int nsIX(int i, int j, int N) | ||
39 | { | ||
40 | return ((i) + (N + 2)*(j)); | ||
41 | } | ||
42 | |||
43 | // TODO: unused | ||
44 | // private static void nsSwap(ref double x0, ref double x) | ||
45 | // { | ||
46 | // double tmp = x0; | ||
47 | // x0 = x; | ||
48 | // x = tmp; | ||
49 | // } | ||
50 | |||
51 | private static void nsSwap(ref double[] x0, ref double[] x) | ||
52 | { | ||
53 | double[] tmp = x0; | ||
54 | x0 = x; | ||
55 | x = tmp; | ||
56 | } | ||
57 | |||
58 | private void nsAddSource(int N, ref double[] x, ref double[] s, double dt) | ||
59 | { | ||
60 | int i; | ||
61 | int size = (N + 2)*(N + 2); | ||
62 | for (i = 0; i < size; i++) | ||
63 | { | ||
64 | x[i] += dt*s[i]; | ||
65 | } | ||
66 | } | ||
67 | |||
68 | private void nsSetBnd(int N, int b, ref double[] x) | ||
69 | { | ||
70 | int i; | ||
71 | for (i = 0; i <= N; i++) | ||
72 | { | ||
73 | x[nsIX(0, i, N)] = b == 1 ? -x[nsIX(1, i, N)] : x[nsIX(1, i, N)]; | ||
74 | x[nsIX(0, N + 1, N)] = b == 1 ? -x[nsIX(N, i, N)] : x[nsIX(N, i, N)]; | ||
75 | x[nsIX(i, 0, N)] = b == 2 ? -x[nsIX(i, 1, N)] : x[nsIX(i, 1, N)]; | ||
76 | x[nsIX(i, N + 1, N)] = b == 2 ? -x[nsIX(i, N, N)] : x[nsIX(i, N, N)]; | ||
77 | } | ||
78 | x[nsIX(0, 0, N)] = 0.5f*(x[nsIX(1, 0, N)] + x[nsIX(0, 1, N)]); | ||
79 | x[nsIX(0, N + 1, N)] = 0.5f*(x[nsIX(1, N + 1, N)] + x[nsIX(0, N, N)]); | ||
80 | x[nsIX(N + 1, 0, N)] = 0.5f*(x[nsIX(N, 0, N)] + x[nsIX(N + 1, 1, N)]); | ||
81 | x[nsIX(N + 1, N + 1, N)] = 0.5f*(x[nsIX(N, N + 1, N)] + x[nsIX(N + 1, N, N)]); | ||
82 | } | ||
83 | |||
84 | private void nsLinSolve(int N, int b, ref double[] x, ref double[] x0, double a, double c) | ||
85 | { | ||
86 | int i, j; | ||
87 | for (i = 1; i <= N; i++) | ||
88 | { | ||
89 | for (j = 1; j <= N; j++) | ||
90 | { | ||
91 | x[nsIX(i, j, N)] = (x0[nsIX(i, j, N)] + a* | ||
92 | (x[nsIX(i - 1, j, N)] + | ||
93 | x[nsIX(i + 1, j, N)] + | ||
94 | x[nsIX(i, j - 1, N)] + x[nsIX(i, j + 1, N)]) | ||
95 | )/c; | ||
96 | } | ||
97 | } | ||
98 | |||
99 | nsSetBnd(N, b, ref x); | ||
100 | } | ||
101 | |||
102 | private void nsDiffuse(int N, int b, ref double[] x, ref double[] x0, double diff, double dt) | ||
103 | { | ||
104 | double a = dt*diff*N*N; | ||
105 | nsLinSolve(N, b, ref x, ref x0, a, 1 + 4*a); | ||
106 | } | ||
107 | |||
108 | private void nsAdvect(int N, int b, ref double[] d, ref double[] d0, ref double[] u, ref double[] v, double dt) | ||
109 | { | ||
110 | int i, j, i0, j0, i1, j1; | ||
111 | double x, y, s0, t0, s1, t1, dt0; | ||
112 | |||
113 | dt0 = dt*N; | ||
114 | |||
115 | for (i = 1; i <= N; i++) | ||
116 | { | ||
117 | for (j = 1; j <= N; j++) | ||
118 | { | ||
119 | x = i - dt0*u[nsIX(i, j, N)]; | ||
120 | y = j - dt0*v[nsIX(i, j, N)]; | ||
121 | |||
122 | if (x < 0.5) | ||
123 | x = 0.5; | ||
124 | if (x > N + 0.5) | ||
125 | x = N + 0.5; | ||
126 | i0 = (int) x; | ||
127 | i1 = i0 + 1; | ||
128 | |||
129 | if (y < 0.5) | ||
130 | y = 0.5; | ||
131 | if (y > N + 0.5) | ||
132 | y = N + 0.5; | ||
133 | j0 = (int) y; | ||
134 | j1 = j0 + 1; | ||
135 | |||
136 | s1 = x - i0; | ||
137 | s0 = 1 - s1; | ||
138 | t1 = y - j0; | ||
139 | t0 = 1 - t1; | ||
140 | |||
141 | d[nsIX(i, j, N)] = s0*(t0*d0[nsIX(i0, j0, N)] + t1*d0[nsIX(i0, j1, N)]) + | ||
142 | s1*(t0*d0[nsIX(i1, j0, N)] + t1*d0[nsIX(i1, j1, N)]); | ||
143 | } | ||
144 | } | ||
145 | |||
146 | nsSetBnd(N, b, ref d); | ||
147 | } | ||
148 | |||
149 | public void nsProject(int N, ref double[] u, ref double[] v, ref double[] p, ref double[] div) | ||
150 | { | ||
151 | int i, j; | ||
152 | |||
153 | for (i = 1; i <= N; i++) | ||
154 | { | ||
155 | for (j = 1; j <= N; j++) | ||
156 | { | ||
157 | div[nsIX(i, j, N)] = -0.5* | ||
158 | (u[nsIX(i + 1, j, N)] - u[nsIX(i - 1, j, N)] + v[nsIX(i, j + 1, N)] - | ||
159 | v[nsIX(i, j - 1, N)])/N; | ||
160 | p[nsIX(i, j, N)] = 0; | ||
161 | } | ||
162 | } | ||
163 | |||
164 | nsSetBnd(N, 0, ref div); | ||
165 | nsSetBnd(N, 0, ref p); | ||
166 | |||
167 | nsLinSolve(N, 0, ref p, ref div, 1, 4); | ||
168 | |||
169 | for (i = 1; i <= N; i++) | ||
170 | { | ||
171 | for (j = 1; j <= N; j++) | ||
172 | { | ||
173 | u[nsIX(i, j, N)] -= 0.5*N*(p[nsIX(i + 1, j, N)] - p[nsIX(i - 1, j, N)]); | ||
174 | v[nsIX(i, j, N)] -= 0.5*N*(p[nsIX(i, j + 1, N)] - p[nsIX(i, j - 1, N)]); | ||
175 | } | ||
176 | } | ||
177 | |||
178 | nsSetBnd(N, 1, ref u); | ||
179 | nsSetBnd(N, 2, ref v); | ||
180 | } | ||
181 | |||
182 | private void nsDensStep(int N, ref double[] x, ref double[] x0, ref double[] u, ref double[] v, double diff, | ||
183 | double dt) | ||
184 | { | ||
185 | nsAddSource(N, ref x, ref x0, dt); | ||
186 | nsSwap(ref x0, ref x); | ||
187 | nsDiffuse(N, 0, ref x, ref x0, diff, dt); | ||
188 | nsSwap(ref x0, ref x); | ||
189 | nsAdvect(N, 0, ref x, ref x0, ref u, ref v, dt); | ||
190 | } | ||
191 | |||
192 | private void nsVelStep(int N, ref double[] u, ref double[] v, ref double[] u0, ref double[] v0, double visc, | ||
193 | double dt) | ||
194 | { | ||
195 | nsAddSource(N, ref u, ref u0, dt); | ||
196 | nsAddSource(N, ref v, ref v0, dt); | ||
197 | nsSwap(ref u0, ref u); | ||
198 | nsDiffuse(N, 1, ref u, ref u0, visc, dt); | ||
199 | nsSwap(ref v0, ref v); | ||
200 | nsDiffuse(N, 2, ref v, ref v0, visc, dt); | ||
201 | nsProject(N, ref u, ref v, ref u0, ref v0); | ||
202 | nsSwap(ref u0, ref u); | ||
203 | nsSwap(ref v0, ref v); | ||
204 | nsAdvect(N, 1, ref u, ref u0, ref u0, ref v0, dt); | ||
205 | nsAdvect(N, 2, ref v, ref v0, ref u0, ref v0, dt); | ||
206 | nsProject(N, ref u, ref v, ref u0, ref v0); | ||
207 | } | ||
208 | |||
209 | private void nsBufferToDoubles(ref double[] dens, int N, ref double[,] doubles) | ||
210 | { | ||
211 | int i; | ||
212 | int j; | ||
213 | |||
214 | for (i = 1; i <= N; i++) | ||
215 | { | ||
216 | for (j = 1; j <= N; j++) | ||
217 | { | ||
218 | doubles[i - 1, j - 1] = dens[nsIX(i, j, N)]; | ||
219 | } | ||
220 | } | ||
221 | } | ||
222 | |||
223 | private void nsDoublesToBuffer(double[,] doubles, int N, ref double[] dens) | ||
224 | { | ||
225 | int i; | ||
226 | int j; | ||
227 | |||
228 | for (i = 1; i <= N; i++) | ||
229 | { | ||
230 | for (j = 1; j <= N; j++) | ||
231 | { | ||
232 | dens[nsIX(i, j, N)] = doubles[i - 1, j - 1]; | ||
233 | } | ||
234 | } | ||
235 | } | ||
236 | |||
237 | private void nsSimulate(int N, int rounds, double dt, double diff, double visc) | ||
238 | { | ||
239 | int size = (N*2)*(N*2); | ||
240 | |||
241 | double[] u = new double[size]; // Force, X axis | ||
242 | double[] v = new double[size]; // Force, Y axis | ||
243 | double[] u_prev = new double[size]; | ||
244 | double[] v_prev = new double[size]; | ||
245 | double[] dens = new double[size]; | ||
246 | double[] dens_prev = new double[size]; | ||
247 | |||
248 | nsDoublesToBuffer(map, N, ref dens); | ||
249 | nsDoublesToBuffer(map, N, ref dens_prev); | ||
250 | |||
251 | for (int i = 0; i < rounds; i++) | ||
252 | { | ||
253 | u_prev = u; | ||
254 | v_prev = v; | ||
255 | dens_prev = dens; | ||
256 | |||
257 | nsVelStep(N, ref u, ref v, ref u_prev, ref v_prev, visc, dt); | ||
258 | nsDensStep(N, ref dens, ref dens_prev, ref u, ref v, diff, dt); | ||
259 | } | ||
260 | |||
261 | nsBufferToDoubles(ref dens, N, ref map); | ||
262 | } | ||
263 | |||
264 | /// <summary> | ||
265 | /// Performs computational fluid dynamics on a channel | ||
266 | /// </summary> | ||
267 | /// <param name="rounds">The number of steps to perform (Recommended: 20)</param> | ||
268 | /// <param name="dt">Delta Time - The time between steps (Recommended: 0.1)</param> | ||
269 | /// <param name="diff">Fluid diffusion rate (Recommended: 0.0)</param> | ||
270 | /// <param name="visc">Fluid viscosity (Recommended: 0.0)</param> | ||
271 | public void navierStokes(int rounds, double dt, double diff, double visc) | ||
272 | { | ||
273 | nsSimulate(h, rounds, dt, diff, visc); | ||
274 | } | ||
275 | |||
276 | public void navierStokes(int rounds, double dt, double diff, double visc, ref double[,] uret, ref double[,] vret) | ||
277 | { | ||
278 | int N = h; | ||
279 | |||
280 | int size = (N*2)*(N*2); | ||
281 | |||
282 | double[] u = new double[size]; // Force, X axis | ||
283 | double[] v = new double[size]; // Force, Y axis | ||
284 | double[] u_prev = new double[size]; | ||
285 | double[] v_prev = new double[size]; | ||
286 | double[] dens = new double[size]; | ||
287 | double[] dens_prev = new double[size]; | ||
288 | |||
289 | nsDoublesToBuffer(map, N, ref dens); | ||
290 | nsDoublesToBuffer(map, N, ref dens_prev); | ||
291 | |||
292 | for (int i = 0; i < rounds; i++) | ||
293 | { | ||
294 | u_prev = u; | ||
295 | v_prev = v; | ||
296 | dens_prev = dens; | ||
297 | |||
298 | nsVelStep(N, ref u, ref v, ref u_prev, ref v_prev, visc, dt); | ||
299 | nsDensStep(N, ref dens, ref dens_prev, ref u, ref v, diff, dt); | ||
300 | } | ||
301 | |||
302 | nsBufferToDoubles(ref u, N, ref uret); | ||
303 | nsBufferToDoubles(ref v, N, ref vret); | ||
304 | nsBufferToDoubles(ref dens, N, ref map); | ||
305 | } | ||
306 | } | ||
307 | } | ||
diff --git a/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Manipulators/ThermalWeathering.cs b/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Manipulators/ThermalWeathering.cs deleted file mode 100644 index 532c2d6..0000000 --- a/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Manipulators/ThermalWeathering.cs +++ /dev/null | |||
@@ -1,107 +0,0 @@ | |||
1 | /* | ||
2 | * Copyright (c) Contributors, http://opensimulator.org/ | ||
3 | * See CONTRIBUTORS.TXT for a full list of copyright holders. | ||
4 | * | ||
5 | * Redistribution and use in source and binary forms, with or without | ||
6 | * modification, are permitted provided that the following conditions are met: | ||
7 | * * Redistributions of source code must retain the above copyright | ||
8 | * notice, this list of conditions and the following disclaimer. | ||
9 | * * Redistributions in binary form must reproduce the above copyright | ||
10 | * notice, this list of conditions and the following disclaimer in the | ||
11 | * documentation and/or other materials provided with the distribution. | ||
12 | * * Neither the name of the OpenSim Project nor the | ||
13 | * names of its contributors may be used to endorse or promote products | ||
14 | * derived from this software without specific prior written permission. | ||
15 | * | ||
16 | * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY | ||
17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
19 | * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY | ||
20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | ||
23 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
26 | */ | ||
27 | |||
28 | namespace libTerrain | ||
29 | { | ||
30 | partial class Channel | ||
31 | { | ||
32 | /// <summary> | ||
33 | /// A thermal weathering implementation based on Musgrave's original 1989 algorithm. This is Adam's custom implementation which may differ slightly from the original. | ||
34 | /// </summary> | ||
35 | /// <param name="talus">The rock angle (represented as a dy/dx ratio) at which point it will be succeptible to breakage</param> | ||
36 | /// <param name="rounds">The number of erosion rounds</param> | ||
37 | /// <param name="c">The amount of rock to carry each round</param> | ||
38 | public Channel ThermalWeathering(double talus, int rounds, double c) | ||
39 | { | ||
40 | SetDiff(); | ||
41 | |||
42 | double[,] lastFrame; | ||
43 | double[,] thisFrame; | ||
44 | |||
45 | lastFrame = (double[,]) map.Clone(); | ||
46 | thisFrame = (double[,]) map.Clone(); | ||
47 | |||
48 | NeighbourSystem type = NeighbourSystem.Moore; | ||
49 | // Using moore neighbourhood (twice as computationally expensive) | ||
50 | int NEIGHBOUR_ME = 4; // I am always 4 in both systems. | ||
51 | |||
52 | int NEIGHBOUR_MAX = type == NeighbourSystem.Moore ? 9 : 5; | ||
53 | |||
54 | int frames = rounds; // Number of thermal erosion iterations to run | ||
55 | int i, j; | ||
56 | int x, y; | ||
57 | |||
58 | for (i = 0; i < frames; i++) | ||
59 | { | ||
60 | for (x = 0; x < w; x++) | ||
61 | { | ||
62 | for (y = 0; y < h; y++) | ||
63 | { | ||
64 | for (j = 0; j < NEIGHBOUR_MAX; j++) | ||
65 | { | ||
66 | if (j != NEIGHBOUR_ME) | ||
67 | { | ||
68 | int[] coords = Neighbours(type, j); | ||
69 | |||
70 | coords[0] += x; | ||
71 | coords[1] += y; | ||
72 | |||
73 | if (coords[0] > w - 1) | ||
74 | coords[0] = w - 1; | ||
75 | if (coords[1] > h - 1) | ||
76 | coords[1] = h - 1; | ||
77 | if (coords[0] < 0) | ||
78 | coords[0] = 0; | ||
79 | if (coords[1] < 0) | ||
80 | coords[1] = 0; | ||
81 | |||
82 | double heightF = thisFrame[x, y]; | ||
83 | double target = thisFrame[coords[0], coords[1]]; | ||
84 | |||
85 | if (target > heightF + talus) | ||
86 | { | ||
87 | double calc = c*((target - heightF) - talus); | ||
88 | heightF += calc; | ||
89 | target -= calc; | ||
90 | } | ||
91 | |||
92 | thisFrame[x, y] = heightF; | ||
93 | thisFrame[coords[0], coords[1]] = target; | ||
94 | } | ||
95 | } | ||
96 | } | ||
97 | } | ||
98 | lastFrame = (double[,]) thisFrame.Clone(); | ||
99 | } | ||
100 | |||
101 | map = thisFrame; | ||
102 | |||
103 | Normalise(); // Just to guaruntee a smooth 0..1 value | ||
104 | return this; | ||
105 | } | ||
106 | } | ||
107 | } | ||
diff --git a/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Neighbours.cs b/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Neighbours.cs deleted file mode 100644 index d1027a3..0000000 --- a/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Neighbours.cs +++ /dev/null | |||
@@ -1,136 +0,0 @@ | |||
1 | /* | ||
2 | * Copyright (c) Contributors, http://opensimulator.org/ | ||
3 | * See CONTRIBUTORS.TXT for a full list of copyright holders. | ||
4 | * | ||
5 | * Redistribution and use in source and binary forms, with or without | ||
6 | * modification, are permitted provided that the following conditions are met: | ||
7 | * * Redistributions of source code must retain the above copyright | ||
8 | * notice, this list of conditions and the following disclaimer. | ||
9 | * * Redistributions in binary form must reproduce the above copyright | ||
10 | * notice, this list of conditions and the following disclaimer in the | ||
11 | * documentation and/or other materials provided with the distribution. | ||
12 | * * Neither the name of the OpenSim Project nor the | ||
13 | * names of its contributors may be used to endorse or promote products | ||
14 | * derived from this software without specific prior written permission. | ||
15 | * | ||
16 | * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY | ||
17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
19 | * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY | ||
20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | ||
23 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
26 | */ | ||
27 | |||
28 | namespace libTerrain | ||
29 | { | ||
30 | partial class Channel | ||
31 | { | ||
32 | private enum NeighbourSystem | ||
33 | { | ||
34 | Moore, | ||
35 | VonNeumann | ||
36 | } ; | ||
37 | |||
38 | private int[] Neighbours(NeighbourSystem type, int index) | ||
39 | { | ||
40 | int[] coord = new int[2]; | ||
41 | |||
42 | index++; | ||
43 | |||
44 | switch (type) | ||
45 | { | ||
46 | case NeighbourSystem.Moore: | ||
47 | switch (index) | ||
48 | { | ||
49 | case 1: | ||
50 | coord[0] = -1; | ||
51 | coord[1] = -1; | ||
52 | break; | ||
53 | |||
54 | case 2: | ||
55 | coord[0] = -0; | ||
56 | coord[1] = -1; | ||
57 | break; | ||
58 | |||
59 | case 3: | ||
60 | coord[0] = +1; | ||
61 | coord[1] = -1; | ||
62 | break; | ||
63 | |||
64 | case 4: | ||
65 | coord[0] = -1; | ||
66 | coord[1] = -0; | ||
67 | break; | ||
68 | |||
69 | case 5: | ||
70 | coord[0] = -0; | ||
71 | coord[1] = -0; | ||
72 | break; | ||
73 | |||
74 | case 6: | ||
75 | coord[0] = +1; | ||
76 | coord[1] = -0; | ||
77 | break; | ||
78 | |||
79 | case 7: | ||
80 | coord[0] = -1; | ||
81 | coord[1] = +1; | ||
82 | break; | ||
83 | |||
84 | case 8: | ||
85 | coord[0] = -0; | ||
86 | coord[1] = +1; | ||
87 | break; | ||
88 | |||
89 | case 9: | ||
90 | coord[0] = +1; | ||
91 | coord[1] = +1; | ||
92 | break; | ||
93 | |||
94 | default: | ||
95 | break; | ||
96 | } | ||
97 | break; | ||
98 | |||
99 | case NeighbourSystem.VonNeumann: | ||
100 | switch (index) | ||
101 | { | ||
102 | case 1: | ||
103 | coord[0] = 0; | ||
104 | coord[1] = -1; | ||
105 | break; | ||
106 | |||
107 | case 2: | ||
108 | coord[0] = -1; | ||
109 | coord[1] = 0; | ||
110 | break; | ||
111 | |||
112 | case 3: | ||
113 | coord[0] = +1; | ||
114 | coord[1] = 0; | ||
115 | break; | ||
116 | |||
117 | case 4: | ||
118 | coord[0] = 0; | ||
119 | coord[1] = +1; | ||
120 | break; | ||
121 | |||
122 | case 5: | ||
123 | coord[0] = -0; | ||
124 | coord[1] = -0; | ||
125 | break; | ||
126 | |||
127 | default: | ||
128 | break; | ||
129 | } | ||
130 | break; | ||
131 | } | ||
132 | |||
133 | return coord; | ||
134 | } | ||
135 | } | ||
136 | } | ||
diff --git a/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Operators.cs b/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Operators.cs deleted file mode 100644 index 6e1386d..0000000 --- a/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Operators.cs +++ /dev/null | |||
@@ -1,239 +0,0 @@ | |||
1 | /* | ||
2 | * Copyright (c) Contributors, http://opensimulator.org/ | ||
3 | * See CONTRIBUTORS.TXT for a full list of copyright holders. | ||
4 | * | ||
5 | * Redistribution and use in source and binary forms, with or without | ||
6 | * modification, are permitted provided that the following conditions are met: | ||
7 | * * Redistributions of source code must retain the above copyright | ||
8 | * notice, this list of conditions and the following disclaimer. | ||
9 | * * Redistributions in binary form must reproduce the above copyright | ||
10 | * notice, this list of conditions and the following disclaimer in the | ||
11 | * documentation and/or other materials provided with the distribution. | ||
12 | * * Neither the name of the OpenSim Project nor the | ||
13 | * names of its contributors may be used to endorse or promote products | ||
14 | * derived from this software without specific prior written permission. | ||
15 | * | ||
16 | * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY | ||
17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
19 | * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY | ||
20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | ||
23 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
26 | */ | ||
27 | |||
28 | using System; | ||
29 | |||
30 | namespace libTerrain | ||
31 | { | ||
32 | partial class Channel | ||
33 | { | ||
34 | /* Operator combination of channel datatypes */ | ||
35 | |||
36 | public static Channel operator +(Channel A, Channel B) | ||
37 | { | ||
38 | if (A.h != B.h) | ||
39 | throw new Exception("Cannot add heightmaps, of different height."); | ||
40 | if (A.w != B.w) | ||
41 | throw new Exception("Cannot add heightmaps, of different width."); | ||
42 | |||
43 | int x, y; | ||
44 | |||
45 | for (x = 0; x < A.w; x++) | ||
46 | { | ||
47 | for (y = 0; y < A.h; y++) | ||
48 | { | ||
49 | if (B.map[x, y] != 0) | ||
50 | A.SetDiff(x, y); | ||
51 | |||
52 | A.map[x, y] += B.map[x, y]; | ||
53 | } | ||
54 | } | ||
55 | |||
56 | return A; | ||
57 | } | ||
58 | |||
59 | public static Channel operator *(Channel A, Channel B) | ||
60 | { | ||
61 | if (A.h != B.h) | ||
62 | throw new Exception("Cannot multiply heightmaps, of different height."); | ||
63 | if (A.w != B.w) | ||
64 | throw new Exception("Cannot multiply heightmaps, of different width."); | ||
65 | |||
66 | int x, y; | ||
67 | |||
68 | for (x = 0; x < A.w; x++) | ||
69 | { | ||
70 | for (y = 0; y < A.h; y++) | ||
71 | { | ||
72 | A.map[x, y] *= B.map[x, y]; | ||
73 | } | ||
74 | } | ||
75 | |||
76 | A.SetDiff(); | ||
77 | |||
78 | return A; | ||
79 | } | ||
80 | |||
81 | public static Channel operator -(Channel A, Channel B) | ||
82 | { | ||
83 | if (A.h != B.h) | ||
84 | throw new Exception("Cannot subtract heightmaps, of different height."); | ||
85 | if (A.w != B.w) | ||
86 | throw new Exception("Cannot subtract heightmaps, of different width."); | ||
87 | |||
88 | int x, y; | ||
89 | |||
90 | for (x = 0; x < A.w; x++) | ||
91 | { | ||
92 | for (y = 0; y < A.h; y++) | ||
93 | { | ||
94 | if (B.map[x, y] != 0) | ||
95 | A.SetDiff(x, y); | ||
96 | A.map[x, y] -= B.map[x, y]; | ||
97 | } | ||
98 | } | ||
99 | |||
100 | return A; | ||
101 | } | ||
102 | |||
103 | public static Channel operator /(Channel A, Channel B) | ||
104 | { | ||
105 | if (A.h != B.h) | ||
106 | throw new Exception("Cannot divide heightmaps, of different height."); | ||
107 | if (A.w != B.w) | ||
108 | throw new Exception("Cannot divide heightmaps, of different width."); | ||
109 | |||
110 | int x, y; | ||
111 | |||
112 | for (x = 0; x < A.w; x++) | ||
113 | { | ||
114 | for (y = 0; y < A.h; y++) | ||
115 | { | ||
116 | A.map[x, y] /= B.map[x, y]; | ||
117 | } | ||
118 | } | ||
119 | |||
120 | A.SetDiff(); | ||
121 | |||
122 | return A; | ||
123 | } | ||
124 | |||
125 | public static Channel operator ^(Channel A, Channel B) | ||
126 | { | ||
127 | if (A.h != B.h) | ||
128 | throw new Exception("Cannot divide heightmaps, of different height."); | ||
129 | if (A.w != B.w) | ||
130 | throw new Exception("Cannot divide heightmaps, of different width."); | ||
131 | |||
132 | int x, y; | ||
133 | |||
134 | for (x = 0; x < A.w; x++) | ||
135 | { | ||
136 | for (y = 0; y < A.h; y++) | ||
137 | { | ||
138 | A.map[x, y] = Math.Pow(A.map[x, y], B.map[x, y]); | ||
139 | } | ||
140 | } | ||
141 | |||
142 | A.SetDiff(); | ||
143 | |||
144 | return A; | ||
145 | } | ||
146 | |||
147 | |||
148 | /* Operator combination of channel and double datatypes */ | ||
149 | |||
150 | public static Channel operator +(Channel A, double B) | ||
151 | { | ||
152 | int x, y; | ||
153 | |||
154 | for (x = 0; x < A.w; x++) | ||
155 | { | ||
156 | for (y = 0; y < A.h; y++) | ||
157 | { | ||
158 | A.map[x, y] += B; | ||
159 | } | ||
160 | } | ||
161 | |||
162 | if (B != 0) | ||
163 | A.SetDiff(); | ||
164 | |||
165 | return A; | ||
166 | } | ||
167 | |||
168 | public static Channel operator -(Channel A, double B) | ||
169 | { | ||
170 | int x, y; | ||
171 | |||
172 | for (x = 0; x < A.w; x++) | ||
173 | { | ||
174 | for (y = 0; y < A.h; y++) | ||
175 | { | ||
176 | A.map[x, y] -= B; | ||
177 | } | ||
178 | } | ||
179 | |||
180 | if (B != 0) | ||
181 | A.SetDiff(); | ||
182 | |||
183 | return A; | ||
184 | } | ||
185 | |||
186 | public static Channel operator *(Channel A, double B) | ||
187 | { | ||
188 | int x, y; | ||
189 | |||
190 | for (x = 0; x < A.w; x++) | ||
191 | { | ||
192 | for (y = 0; y < A.h; y++) | ||
193 | { | ||
194 | A.map[x, y] *= B; | ||
195 | } | ||
196 | } | ||
197 | |||
198 | if (B != 1) | ||
199 | A.SetDiff(); | ||
200 | |||
201 | return A; | ||
202 | } | ||
203 | |||
204 | public static Channel operator /(Channel A, double B) | ||
205 | { | ||
206 | int x, y; | ||
207 | |||
208 | for (x = 0; x < A.w; x++) | ||
209 | { | ||
210 | for (y = 0; y < A.h; y++) | ||
211 | { | ||
212 | A.map[x, y] /= B; | ||
213 | } | ||
214 | } | ||
215 | |||
216 | if (B != 1) | ||
217 | A.SetDiff(); | ||
218 | |||
219 | return A; | ||
220 | } | ||
221 | |||
222 | public static Channel operator ^(Channel A, double B) | ||
223 | { | ||
224 | int x, y; | ||
225 | |||
226 | for (x = 0; x < A.w; x++) | ||
227 | { | ||
228 | for (y = 0; y < A.h; y++) | ||
229 | { | ||
230 | A.map[x, y] = Math.Pow(A.map[x, y], B); | ||
231 | } | ||
232 | } | ||
233 | |||
234 | A.SetDiff(); | ||
235 | |||
236 | return A; | ||
237 | } | ||
238 | } | ||
239 | } | ||