aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/Environment/Modules/World/Terrain/PaintBrushes
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim/Region/Environment/Modules/World/Terrain/PaintBrushes')
-rw-r--r--OpenSim/Region/Environment/Modules/World/Terrain/PaintBrushes/ErodeSphere.cs318
-rw-r--r--OpenSim/Region/Environment/Modules/World/Terrain/PaintBrushes/FlattenSphere.cs101
-rw-r--r--OpenSim/Region/Environment/Modules/World/Terrain/PaintBrushes/LowerSphere.cs84
-rw-r--r--OpenSim/Region/Environment/Modules/World/Terrain/PaintBrushes/NoiseSphere.cs67
-rw-r--r--OpenSim/Region/Environment/Modules/World/Terrain/PaintBrushes/OlsenSphere.cs223
-rw-r--r--OpenSim/Region/Environment/Modules/World/Terrain/PaintBrushes/RaiseSphere.cs80
-rw-r--r--OpenSim/Region/Environment/Modules/World/Terrain/PaintBrushes/RevertSphere.cs80
-rw-r--r--OpenSim/Region/Environment/Modules/World/Terrain/PaintBrushes/SmoothSphere.cs100
-rw-r--r--OpenSim/Region/Environment/Modules/World/Terrain/PaintBrushes/WeatherSphere.cs211
9 files changed, 0 insertions, 1264 deletions
diff --git a/OpenSim/Region/Environment/Modules/World/Terrain/PaintBrushes/ErodeSphere.cs b/OpenSim/Region/Environment/Modules/World/Terrain/PaintBrushes/ErodeSphere.cs
deleted file mode 100644
index 4d694cc..0000000
--- a/OpenSim/Region/Environment/Modules/World/Terrain/PaintBrushes/ErodeSphere.cs
+++ /dev/null
@@ -1,318 +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
28using System;
29using OpenSim.Region.Framework.Interfaces;
30using OpenSim.Region.Framework.Scenes;
31
32namespace OpenSim.Region.Environment.Modules.World.Terrain.PaintBrushes
33{
34 /// <summary>
35 /// Hydraulic Erosion Brush
36 /// </summary>
37 public class ErodeSphere : ITerrainPaintableEffect
38 {
39 private const double rainHeight = 0.2;
40 private const int rounds = 10;
41 private const NeighbourSystem type = NeighbourSystem.Moore;
42 private const double waterSaturation = 0.30;
43
44 #region Supporting Functions
45
46 private static int[] Neighbours(NeighbourSystem neighbourType, int index)
47 {
48 int[] coord = new int[2];
49
50 index++;
51
52 switch (neighbourType)
53 {
54 case NeighbourSystem.Moore:
55 switch (index)
56 {
57 case 1:
58 coord[0] = -1;
59 coord[1] = -1;
60 break;
61
62 case 2:
63 coord[0] = -0;
64 coord[1] = -1;
65 break;
66
67 case 3:
68 coord[0] = +1;
69 coord[1] = -1;
70 break;
71
72 case 4:
73 coord[0] = -1;
74 coord[1] = -0;
75 break;
76
77 case 5:
78 coord[0] = -0;
79 coord[1] = -0;
80 break;
81
82 case 6:
83 coord[0] = +1;
84 coord[1] = -0;
85 break;
86
87 case 7:
88 coord[0] = -1;
89 coord[1] = +1;
90 break;
91
92 case 8:
93 coord[0] = -0;
94 coord[1] = +1;
95 break;
96
97 case 9:
98 coord[0] = +1;
99 coord[1] = +1;
100 break;
101
102 default:
103 break;
104 }
105 break;
106
107 case NeighbourSystem.VonNeumann:
108 switch (index)
109 {
110 case 1:
111 coord[0] = 0;
112 coord[1] = -1;
113 break;
114
115 case 2:
116 coord[0] = -1;
117 coord[1] = 0;
118 break;
119
120 case 3:
121 coord[0] = +1;
122 coord[1] = 0;
123 break;
124
125 case 4:
126 coord[0] = 0;
127 coord[1] = +1;
128 break;
129
130 case 5:
131 coord[0] = -0;
132 coord[1] = -0;
133 break;
134
135 default:
136 break;
137 }
138 break;
139 }
140
141 return coord;
142 }
143
144 private enum NeighbourSystem
145 {
146 Moore,
147 VonNeumann
148 } ;
149
150 #endregion
151
152 #region ITerrainPaintableEffect Members
153
154 public void PaintEffect(ITerrainChannel map, bool[,] mask, double rx, double ry, double rz, double strength, double duration)
155 {
156 strength = TerrainUtil.MetersToSphericalStrength(strength);
157
158 int x, y;
159 // Using one 'rain' round for this, so skipping a useless loop
160 // Will need to adapt back in for the Flood brush
161
162 ITerrainChannel water = new TerrainChannel(map.Width, map.Height);
163 ITerrainChannel sediment = new TerrainChannel(map.Width, map.Height);
164
165 // Fill with rain
166 for (x = 0; x < water.Width; x++)
167 for (y = 0; y < water.Height; y++)
168 water[x, y] = Math.Max(0.0, TerrainUtil.SphericalFactor(x, y, rx, ry, strength) * rainHeight * duration);
169
170 for (int i = 0; i < rounds; i++)
171 {
172 // Erode underlying terrain
173 for (x = 0; x < water.Width; x++)
174 {
175 for (y = 0; y < water.Height; y++)
176 {
177 if (mask[x,y])
178 {
179 const double solConst = (1.0 / rounds);
180 double sedDelta = water[x, y] * solConst;
181 map[x, y] -= sedDelta;
182 sediment[x, y] += sedDelta;
183 }
184 }
185 }
186
187 // Move water
188 for (x = 0; x < water.Width; x++)
189 {
190 for (y = 0; y < water.Height; y++)
191 {
192 if (water[x, y] <= 0)
193 continue;
194
195 // Step 1. Calculate average of neighbours
196
197 int neighbours = 0;
198 double altitudeTotal = 0.0;
199 double altitudeMe = map[x, y] + water[x, y];
200
201 const int NEIGHBOUR_ME = 4;
202 const int NEIGHBOUR_MAX = 9;
203
204 for (int j = 0; j < NEIGHBOUR_MAX; j++)
205 {
206 if (j != NEIGHBOUR_ME)
207 {
208 int[] coords = Neighbours(type, j);
209
210 coords[0] += x;
211 coords[1] += y;
212
213 if (coords[0] > map.Width - 1)
214 continue;
215 if (coords[1] > map.Height - 1)
216 continue;
217 if (coords[0] < 0)
218 continue;
219 if (coords[1] < 0)
220 continue;
221
222 // Calculate total height of this neighbour
223 double altitudeNeighbour = water[coords[0], coords[1]] + map[coords[0], coords[1]];
224
225 // If it's greater than me...
226 if (altitudeNeighbour - altitudeMe < 0)
227 {
228 // Add it to our calculations
229 neighbours++;
230 altitudeTotal += altitudeNeighbour;
231 }
232 }
233 }
234
235 if (neighbours == 0)
236 continue;
237
238 double altitudeAvg = altitudeTotal / neighbours;
239
240 // Step 2. Allocate water to neighbours.
241 for (int j = 0; j < NEIGHBOUR_MAX; j++)
242 {
243 if (j != NEIGHBOUR_ME)
244 {
245 int[] coords = Neighbours(type, j);
246
247 coords[0] += x;
248 coords[1] += y;
249
250 if (coords[0] > map.Width - 1)
251 continue;
252 if (coords[1] > map.Height - 1)
253 continue;
254 if (coords[0] < 0)
255 continue;
256 if (coords[1] < 0)
257 continue;
258
259 // Skip if we dont have water to begin with.
260 if (water[x, y] < 0)
261 continue;
262
263 // Calculate our delta average
264 double altitudeDelta = altitudeMe - altitudeAvg;
265
266 if (altitudeDelta < 0)
267 continue;
268
269 // Calculate how much water we can move
270 double waterMin = Math.Min(water[x, y], altitudeDelta);
271 double waterDelta = waterMin * ((water[coords[0], coords[1]] + map[coords[0], coords[1]])
272 / altitudeTotal);
273
274 double sedimentDelta = sediment[x, y] * (waterDelta / water[x, y]);
275
276 if (sedimentDelta > 0)
277 {
278 sediment[x, y] -= sedimentDelta;
279 sediment[coords[0], coords[1]] += sedimentDelta;
280 }
281 }
282 }
283 }
284 }
285
286 // Evaporate
287
288 for (x = 0; x < water.Width; x++)
289 {
290 for (y = 0; y < water.Height; y++)
291 {
292 water[x, y] *= 1.0 - (rainHeight / rounds);
293
294 double waterCapacity = waterSaturation * water[x, y];
295
296 double sedimentDeposit = sediment[x, y] - waterCapacity;
297 if (sedimentDeposit > 0)
298 {
299 if (mask[x,y])
300 {
301 sediment[x, y] -= sedimentDeposit;
302 map[x, y] += sedimentDeposit;
303 }
304 }
305 }
306 }
307 }
308
309 // Deposit any remainder (should be minimal)
310 for (x = 0; x < water.Width; x++)
311 for (y = 0; y < water.Height; y++)
312 if (mask[x,y] && sediment[x, y] > 0)
313 map[x, y] += sediment[x, y];
314 }
315
316 #endregion
317 }
318}
diff --git a/OpenSim/Region/Environment/Modules/World/Terrain/PaintBrushes/FlattenSphere.cs b/OpenSim/Region/Environment/Modules/World/Terrain/PaintBrushes/FlattenSphere.cs
deleted file mode 100644
index 91c030d..0000000
--- a/OpenSim/Region/Environment/Modules/World/Terrain/PaintBrushes/FlattenSphere.cs
+++ /dev/null
@@ -1,101 +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
28using System;
29using OpenSim.Region.Framework.Interfaces;
30using OpenSim.Region.Framework.Scenes;
31
32namespace OpenSim.Region.Environment.Modules.World.Terrain.PaintBrushes
33{
34 public class FlattenSphere : ITerrainPaintableEffect
35 {
36 #region ITerrainPaintableEffect Members
37
38 public void PaintEffect(ITerrainChannel map, bool[,] mask, double rx, double ry, double rz, double strength, double duration)
39 {
40 strength = TerrainUtil.MetersToSphericalStrength(strength);
41
42 int x, y;
43
44 if (rz < 0) {
45 double sum = 0.0;
46 double step2 = 0.0;
47 duration = 0.009; //MCP Should be read from ini file
48
49
50 // compute delta map
51 for (x = 0; x < map.Width; x++)
52 {
53 for (y = 0; y < map.Height; y++)
54 {
55 double z = TerrainUtil.SphericalFactor(x, y, rx, ry, strength);
56
57 if (z > 0) // add in non-zero amount
58 {
59 sum += map[x, y] * z;
60 step2 += z;
61 }
62 }
63 }
64 rz = sum / step2;
65 }
66
67
68 // blend in map
69 for (x = 0; x < map.Width; x++)
70 {
71 for (y = 0; y < map.Height; y++)
72 {
73 if (!mask[x,y])
74 continue;
75
76 double z = TerrainUtil.SphericalFactor(x, y, rx, ry, strength) * duration;
77
78 if (z > 0) // add in non-zero amount
79 {
80 if (z > 1.0)
81 z = 1.0;
82
83 map[x, y] = (map[x, y] * (1.0 - z)) + (rz * z);
84 }
85
86 double delta = rz - map[x, y];
87 if (Math.Abs(delta) > 0.1)
88 delta *= 0.25;
89
90 if (delta != 0) // add in non-zero amount
91 {
92 map[x, y] += delta;
93 }
94
95 }
96 }
97 }
98
99 #endregion
100 }
101}
diff --git a/OpenSim/Region/Environment/Modules/World/Terrain/PaintBrushes/LowerSphere.cs b/OpenSim/Region/Environment/Modules/World/Terrain/PaintBrushes/LowerSphere.cs
deleted file mode 100644
index d391e94..0000000
--- a/OpenSim/Region/Environment/Modules/World/Terrain/PaintBrushes/LowerSphere.cs
+++ /dev/null
@@ -1,84 +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
28using System;
29using OpenSim.Region.Framework.Interfaces;
30
31namespace OpenSim.Region.Environment.Modules.World.Terrain.PaintBrushes
32{
33 public class LowerSphere : ITerrainPaintableEffect
34 {
35 #region ITerrainPaintableEffect Members
36
37 public void PaintEffect(ITerrainChannel map, bool[,] mask, double rx, double ry, double rz, double strength, double duration)
38 {
39 int s = (int) (Math.Pow(2, strength) + 0.5);
40
41 int x;
42 int xFrom = (int)(rx-s+0.5);
43 int xTo = (int)(rx+s+0.5) + 1;
44 int yFrom = (int)(ry-s+0.5);
45 int yTo = (int)(ry+s+0.5) + 1;
46
47 if (xFrom < 0)
48 xFrom = 0;
49
50 if (yFrom < 0)
51 yFrom = 0;
52
53 if (xTo > map.Width)
54 xTo = map.Width;
55
56 if (yTo > map.Width)
57 yTo = map.Width;
58
59 for (x = xFrom; x < xTo; x++)
60 {
61 int y;
62 for (y = yFrom; y < yTo; y++)
63 {
64 if (!mask[x,y])
65 continue;
66
67 // Calculate a cos-sphere and add it to the heighmap
68 double r = Math.Sqrt((x-rx) * (x-rx) + ((y-ry) * (y-ry)));
69 double z = Math.Cos(r * Math.PI / (s * 2));
70 if (z > 0.0)
71 {
72 double newz = map[x, y] - z * duration;
73 if (newz < 0.0)
74 map[x, y] = 0.0;
75 else
76 map[x, y] = newz;
77 }
78 }
79 }
80
81 }
82 #endregion
83 }
84}
diff --git a/OpenSim/Region/Environment/Modules/World/Terrain/PaintBrushes/NoiseSphere.cs b/OpenSim/Region/Environment/Modules/World/Terrain/PaintBrushes/NoiseSphere.cs
deleted file mode 100644
index 32a6869..0000000
--- a/OpenSim/Region/Environment/Modules/World/Terrain/PaintBrushes/NoiseSphere.cs
+++ /dev/null
@@ -1,67 +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
28using System;
29using OpenSim.Framework;
30using OpenSim.Region.Framework.Interfaces;
31using OpenSim.Region.Framework.Scenes;
32
33namespace OpenSim.Region.Environment.Modules.World.Terrain.PaintBrushes
34{
35 public class NoiseSphere : ITerrainPaintableEffect
36 {
37 #region ITerrainPaintableEffect Members
38
39 public void PaintEffect(ITerrainChannel map, bool[,] mask, double rx, double ry, double rz, double strength, double duration)
40 {
41 strength = TerrainUtil.MetersToSphericalStrength(strength);
42
43 int x;
44 for (x = 0; x < map.Width; x++)
45 {
46 int y;
47 for (y = 0; y < map.Height; y++)
48 {
49 if (!mask[x,y])
50 continue;
51
52 // Calculate a sphere and add it to the heighmap
53 double z = strength;
54 z *= z;
55 z -= ((x - rx) * (x - rx)) + ((y - ry) * (y - ry));
56
57 double noise = TerrainUtil.PerlinNoise2D(x / (double) Constants.RegionSize, y / (double) Constants.RegionSize, 8, 1.0);
58
59 if (z > 0.0)
60 map[x, y] += noise * z * duration;
61 }
62 }
63 }
64
65 #endregion
66 }
67}
diff --git a/OpenSim/Region/Environment/Modules/World/Terrain/PaintBrushes/OlsenSphere.cs b/OpenSim/Region/Environment/Modules/World/Terrain/PaintBrushes/OlsenSphere.cs
deleted file mode 100644
index 86d01d3..0000000
--- a/OpenSim/Region/Environment/Modules/World/Terrain/PaintBrushes/OlsenSphere.cs
+++ /dev/null
@@ -1,223 +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
28using System;
29using OpenSim.Region.Framework.Interfaces;
30using OpenSim.Region.Framework.Scenes;
31
32namespace OpenSim.Region.Environment.Modules.World.Terrain.PaintBrushes
33{
34 /// <summary>
35 /// Speed-Optimised Hybrid Erosion Brush
36 ///
37 /// As per Jacob Olsen's Paper
38 /// http://www.oddlabs.com/download/terrain_generation.pdf
39 /// </summary>
40 public class OlsenSphere : ITerrainPaintableEffect
41 {
42 private const double nConst = 1024.0;
43 private const NeighbourSystem type = NeighbourSystem.Moore;
44
45 #region Supporting Functions
46
47 private static int[] Neighbours(NeighbourSystem neighbourType, int index)
48 {
49 int[] coord = new int[2];
50
51 index++;
52
53 switch (neighbourType)
54 {
55 case NeighbourSystem.Moore:
56 switch (index)
57 {
58 case 1:
59 coord[0] = -1;
60 coord[1] = -1;
61 break;
62
63 case 2:
64 coord[0] = -0;
65 coord[1] = -1;
66 break;
67
68 case 3:
69 coord[0] = +1;
70 coord[1] = -1;
71 break;
72
73 case 4:
74 coord[0] = -1;
75 coord[1] = -0;
76 break;
77
78 case 5:
79 coord[0] = -0;
80 coord[1] = -0;
81 break;
82
83 case 6:
84 coord[0] = +1;
85 coord[1] = -0;
86 break;
87
88 case 7:
89 coord[0] = -1;
90 coord[1] = +1;
91 break;
92
93 case 8:
94 coord[0] = -0;
95 coord[1] = +1;
96 break;
97
98 case 9:
99 coord[0] = +1;
100 coord[1] = +1;
101 break;
102
103 default:
104 break;
105 }
106 break;
107
108 case NeighbourSystem.VonNeumann:
109 switch (index)
110 {
111 case 1:
112 coord[0] = 0;
113 coord[1] = -1;
114 break;
115
116 case 2:
117 coord[0] = -1;
118 coord[1] = 0;
119 break;
120
121 case 3:
122 coord[0] = +1;
123 coord[1] = 0;
124 break;
125
126 case 4:
127 coord[0] = 0;
128 coord[1] = +1;
129 break;
130
131 case 5:
132 coord[0] = -0;
133 coord[1] = -0;
134 break;
135
136 default:
137 break;
138 }
139 break;
140 }
141
142 return coord;
143 }
144
145 private enum NeighbourSystem
146 {
147 Moore,
148 VonNeumann
149 } ;
150
151 #endregion
152
153 #region ITerrainPaintableEffect Members
154
155 public void PaintEffect(ITerrainChannel map, bool[,] mask, double rx, double ry, double rz, double strength, double duration)
156 {
157 strength = TerrainUtil.MetersToSphericalStrength(strength);
158
159 int x;
160
161 for (x = 0; x < map.Width; x++)
162 {
163 int y;
164 for (y = 0; y < map.Height; y++)
165 {
166 if (!mask[x,y])
167 continue;
168
169 double z = TerrainUtil.SphericalFactor(x, y, rx, ry, strength);
170
171 if (z > 0) // add in non-zero amount
172 {
173 const int NEIGHBOUR_ME = 4;
174 const int NEIGHBOUR_MAX = 9;
175
176 double max = Double.MinValue;
177 int loc = 0;
178
179
180 for (int j = 0; j < NEIGHBOUR_MAX; j++)
181 {
182 if (j != NEIGHBOUR_ME)
183 {
184 int[] coords = Neighbours(type, j);
185
186 coords[0] += x;
187 coords[1] += y;
188
189 if (coords[0] > map.Width - 1)
190 continue;
191 if (coords[1] > map.Height - 1)
192 continue;
193 if (coords[0] < 0)
194 continue;
195 if (coords[1] < 0)
196 continue;
197
198 double cellmax = map[x, y] - map[coords[0], coords[1]];
199 if (cellmax > max)
200 {
201 max = cellmax;
202 loc = j;
203 }
204 }
205 }
206
207 double T = nConst / ((map.Width + map.Height) / 2.0);
208 // Apply results
209 if (0 < max && max <= T)
210 {
211 int[] maxCoords = Neighbours(type, loc);
212 double heightDelta = 0.5 * max * z * duration;
213 map[x, y] -= heightDelta;
214 map[x + maxCoords[0], y + maxCoords[1]] += heightDelta;
215 }
216 }
217 }
218 }
219 }
220
221 #endregion
222 }
223}
diff --git a/OpenSim/Region/Environment/Modules/World/Terrain/PaintBrushes/RaiseSphere.cs b/OpenSim/Region/Environment/Modules/World/Terrain/PaintBrushes/RaiseSphere.cs
deleted file mode 100644
index a0ff262..0000000
--- a/OpenSim/Region/Environment/Modules/World/Terrain/PaintBrushes/RaiseSphere.cs
+++ /dev/null
@@ -1,80 +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
28using System;
29using OpenSim.Region.Framework.Interfaces;
30using OpenSim.Region.Framework.Scenes;
31
32namespace OpenSim.Region.Environment.Modules.World.Terrain.PaintBrushes
33{
34 public class RaiseSphere : ITerrainPaintableEffect
35 {
36 #region ITerrainPaintableEffect Members
37
38
39 public void PaintEffect(ITerrainChannel map, bool[,] mask, double rx, double ry, double rz, double strength, double duration)
40 {
41 int s = (int) (Math.Pow(2, strength) + 0.5);
42
43 int x;
44 int xFrom = (int)(rx-s+0.5);
45 int xTo = (int)(rx+s+0.5) + 1;
46 int yFrom = (int)(ry-s+0.5);
47 int yTo = (int)(ry+s+0.5) + 1;
48
49 if (xFrom < 0)
50 xFrom = 0;
51
52 if (yFrom < 0)
53 yFrom = 0;
54
55 if (xTo > map.Width)
56 xTo = map.Width;
57
58 if (yTo > map.Width)
59 yTo = map.Width;
60
61 for (x = xFrom; x < xTo; x++)
62 {
63 int y;
64 for (y = yFrom; y < yTo; y++)
65 {
66 if (!mask[x,y])
67 continue;
68
69 // Calculate a cos-sphere and add it to the heighmap
70 double r = Math.Sqrt((x-rx) * (x-rx) + ((y-ry) * (y-ry)));
71 double z = Math.Cos(r * Math.PI / (s * 2));
72 if (z > 0.0)
73 map[x, y] += z * duration;
74 }
75 }
76 }
77
78 #endregion
79 }
80}
diff --git a/OpenSim/Region/Environment/Modules/World/Terrain/PaintBrushes/RevertSphere.cs b/OpenSim/Region/Environment/Modules/World/Terrain/PaintBrushes/RevertSphere.cs
deleted file mode 100644
index af6d94d..0000000
--- a/OpenSim/Region/Environment/Modules/World/Terrain/PaintBrushes/RevertSphere.cs
+++ /dev/null
@@ -1,80 +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
28using System;
29using OpenSim.Region.Framework.Interfaces;
30using OpenSim.Region.Framework.Scenes;
31
32namespace OpenSim.Region.Environment.Modules.World.Terrain.PaintBrushes
33{
34 public class RevertSphere : ITerrainPaintableEffect
35 {
36 private readonly ITerrainChannel m_revertmap;
37
38 public RevertSphere(ITerrainChannel revertmap)
39 {
40 m_revertmap = revertmap;
41 }
42
43 #region ITerrainPaintableEffect Members
44
45 public void PaintEffect(ITerrainChannel map, bool[,] mask, double rx, double ry, double rz, double strength, double duration)
46 {
47 strength = TerrainUtil.MetersToSphericalStrength(strength);
48 duration = 0.03; //MCP Should be read from ini file
49
50 if (duration > 1.0)
51 duration = 1.0;
52 if (duration < 0)
53 return;
54
55 int x;
56 for (x = 0; x < map.Width; x++)
57 {
58 int y;
59 for (y = 0; y < map.Height; y++)
60 {
61 if (!mask[x,y])
62 continue;
63
64 // Calculate a sphere and add it to the heighmap
65 double z = strength;
66 z *= z;
67 z -= ((x - rx) * (x - rx)) + ((y - ry) * (y - ry));
68
69 if (z > 0.0)
70 {
71 z *= duration;
72 map[x, y] = (map[x, y] * (1.0 - z)) + (m_revertmap[x, y] * z);
73 }
74 }
75 }
76 }
77
78 #endregion
79 }
80}
diff --git a/OpenSim/Region/Environment/Modules/World/Terrain/PaintBrushes/SmoothSphere.cs b/OpenSim/Region/Environment/Modules/World/Terrain/PaintBrushes/SmoothSphere.cs
deleted file mode 100644
index fe270f7..0000000
--- a/OpenSim/Region/Environment/Modules/World/Terrain/PaintBrushes/SmoothSphere.cs
+++ /dev/null
@@ -1,100 +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
28using OpenSim.Region.Framework.Interfaces;
29using OpenSim.Region.Framework.Scenes;
30
31namespace OpenSim.Region.Environment.Modules.World.Terrain.PaintBrushes
32{
33 public class SmoothSphere : ITerrainPaintableEffect
34 {
35 #region ITerrainPaintableEffect Members
36
37 public void PaintEffect(ITerrainChannel map, bool[,] mask, double rx, double ry, double rz, double strength, double duration)
38 {
39 strength = TerrainUtil.MetersToSphericalStrength(strength);
40
41 int x, y;
42 double[,] tweak = new double[map.Width,map.Height];
43
44 double area = strength;
45 double step = strength / 4.0;
46 duration = 0.03; //MCP Should be read from ini file
47
48
49 // compute delta map
50 for (x = 0; x < map.Width; x++)
51 {
52 for (y = 0; y < map.Height; y++)
53 {
54 double z = TerrainUtil.SphericalFactor(x, y, rx, ry, strength);
55
56 if (z > 0) // add in non-zero amount
57 {
58 double average = 0.0;
59 int avgsteps = 0;
60
61 double n;
62 for (n = 0.0 - area; n < area; n += step)
63 {
64 double l;
65 for (l = 0.0 - area; l < area; l += step)
66 {
67 avgsteps++;
68 average += TerrainUtil.GetBilinearInterpolate(x + n, y + l, map);
69 }
70 }
71 tweak[x, y] = average / avgsteps;
72 }
73 }
74 }
75 // blend in map
76 for (x = 0; x < map.Width; x++)
77 {
78 for (y = 0; y < map.Height; y++)
79 {
80 if (!mask[x,y])
81 continue;
82
83 double z = TerrainUtil.SphericalFactor(x, y, rx, ry, strength);
84
85 if (z > 0) // add in non-zero amount
86 {
87 double da = z;
88 double a = (map[x, y] - tweak[x, y]) * da;
89 double newz = map[x, y] - (a * duration);
90
91 if (newz > 0.0)
92 map[x, y] = newz;
93 }
94 }
95 }
96 }
97
98 #endregion
99 }
100}
diff --git a/OpenSim/Region/Environment/Modules/World/Terrain/PaintBrushes/WeatherSphere.cs b/OpenSim/Region/Environment/Modules/World/Terrain/PaintBrushes/WeatherSphere.cs
deleted file mode 100644
index faba119..0000000
--- a/OpenSim/Region/Environment/Modules/World/Terrain/PaintBrushes/WeatherSphere.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
28using OpenSim.Region.Framework.Interfaces;
29using OpenSim.Region.Framework.Scenes;
30
31namespace OpenSim.Region.Environment.Modules.World.Terrain.PaintBrushes
32{
33 /// <summary>
34 /// Thermal Weathering Paint Brush
35 /// </summary>
36 public class WeatherSphere : ITerrainPaintableEffect
37 {
38 private const double talus = 0.2;
39 private const NeighbourSystem type = NeighbourSystem.Moore;
40
41 #region Supporting Functions
42
43 private static int[] Neighbours(NeighbourSystem neighbourType, int index)
44 {
45 int[] coord = new int[2];
46
47 index++;
48
49 switch (neighbourType)
50 {
51 case NeighbourSystem.Moore:
52 switch (index)
53 {
54 case 1:
55 coord[0] = -1;
56 coord[1] = -1;
57 break;
58
59 case 2:
60 coord[0] = -0;
61 coord[1] = -1;
62 break;
63
64 case 3:
65 coord[0] = +1;
66 coord[1] = -1;
67 break;
68
69 case 4:
70 coord[0] = -1;
71 coord[1] = -0;
72 break;
73
74 case 5:
75 coord[0] = -0;
76 coord[1] = -0;
77 break;
78
79 case 6:
80 coord[0] = +1;
81 coord[1] = -0;
82 break;
83
84 case 7:
85 coord[0] = -1;
86 coord[1] = +1;
87 break;
88
89 case 8:
90 coord[0] = -0;
91 coord[1] = +1;
92 break;
93
94 case 9:
95 coord[0] = +1;
96 coord[1] = +1;
97 break;
98
99 default:
100 break;
101 }
102 break;
103
104 case NeighbourSystem.VonNeumann:
105 switch (index)
106 {
107 case 1:
108 coord[0] = 0;
109 coord[1] = -1;
110 break;
111
112 case 2:
113 coord[0] = -1;
114 coord[1] = 0;
115 break;
116
117 case 3:
118 coord[0] = +1;
119 coord[1] = 0;
120 break;
121
122 case 4:
123 coord[0] = 0;
124 coord[1] = +1;
125 break;
126
127 case 5:
128 coord[0] = -0;
129 coord[1] = -0;
130 break;
131
132 default:
133 break;
134 }
135 break;
136 }
137
138 return coord;
139 }
140
141 private enum NeighbourSystem
142 {
143 Moore,
144 VonNeumann
145 } ;
146
147 #endregion
148
149 #region ITerrainPaintableEffect Members
150
151 public void PaintEffect(ITerrainChannel map, bool[,] mask, double rx, double ry, double rz, double strength, double duration)
152 {
153 strength = TerrainUtil.MetersToSphericalStrength(strength);
154
155 int x;
156
157 for (x = 0; x < map.Width; x++)
158 {
159 int y;
160 for (y = 0; y < map.Height; y++)
161 {
162 if (!mask[x,y])
163 continue;
164
165 double z = TerrainUtil.SphericalFactor(x, y, rx, ry, strength);
166
167 if (z > 0) // add in non-zero amount
168 {
169 const int NEIGHBOUR_ME = 4;
170 const int NEIGHBOUR_MAX = 9;
171
172 for (int j = 0; j < NEIGHBOUR_MAX; j++)
173 {
174 if (j != NEIGHBOUR_ME)
175 {
176 int[] coords = Neighbours(type, j);
177
178 coords[0] += x;
179 coords[1] += y;
180
181 if (coords[0] > map.Width - 1)
182 continue;
183 if (coords[1] > map.Height - 1)
184 continue;
185 if (coords[0] < 0)
186 continue;
187 if (coords[1] < 0)
188 continue;
189
190 double heightF = map[x, y];
191 double target = map[coords[0], coords[1]];
192
193 if (target > heightF + talus)
194 {
195 double calc = duration * ((target - heightF) - talus) * z;
196 heightF += calc;
197 target -= calc;
198 }
199
200 map[x, y] = heightF;
201 map[coords[0], coords[1]] = target;
202 }
203 }
204 }
205 }
206 }
207 }
208
209 #endregion
210 }
211}