diff options
author | Jeff Ames | 2008-05-01 14:31:30 +0000 |
---|---|---|
committer | Jeff Ames | 2008-05-01 14:31:30 +0000 |
commit | d51ce47b2d7635b17f3dd429158e8f59b78b83aa (patch) | |
tree | d3595bd5194199184059aa398b91a51dc6c799cf /OpenSim/Region/Environment/Modules/World/Terrain/PaintBrushes | |
parent | * Looks like I had the bamboo build right in the first place - it was just th... (diff) | |
download | opensim-SC_OLD-d51ce47b2d7635b17f3dd429158e8f59b78b83aa.zip opensim-SC_OLD-d51ce47b2d7635b17f3dd429158e8f59b78b83aa.tar.gz opensim-SC_OLD-d51ce47b2d7635b17f3dd429158e8f59b78b83aa.tar.bz2 opensim-SC_OLD-d51ce47b2d7635b17f3dd429158e8f59b78b83aa.tar.xz |
Update svn properties. Minor formatting cleanup.
Diffstat (limited to '')
9 files changed, 1208 insertions, 1208 deletions
diff --git a/OpenSim/Region/Environment/Modules/World/Terrain/PaintBrushes/ErodeSphere.cs b/OpenSim/Region/Environment/Modules/World/Terrain/PaintBrushes/ErodeSphere.cs index 29448aa..e036988 100644 --- a/OpenSim/Region/Environment/Modules/World/Terrain/PaintBrushes/ErodeSphere.cs +++ b/OpenSim/Region/Environment/Modules/World/Terrain/PaintBrushes/ErodeSphere.cs | |||
@@ -1,312 +1,312 @@ | |||
1 | /* | 1 | /* |
2 | * Copyright (c) Contributors, http://opensimulator.org/ | 2 | * Copyright (c) Contributors, http://opensimulator.org/ |
3 | * See CONTRIBUTORS.TXT for a full list of copyright holders. | 3 | * See CONTRIBUTORS.TXT for a full list of copyright holders. |
4 | * | 4 | * |
5 | * Redistribution and use in source and binary forms, with or without | 5 | * Redistribution and use in source and binary forms, with or without |
6 | * modification, are permitted provided that the following conditions are met: | 6 | * modification, are permitted provided that the following conditions are met: |
7 | * * Redistributions of source code must retain the above copyright | 7 | * * Redistributions of source code must retain the above copyright |
8 | * notice, this list of conditions and the following disclaimer. | 8 | * notice, this list of conditions and the following disclaimer. |
9 | * * Redistributions in binary form must reproduce the above copyright | 9 | * * Redistributions in binary form must reproduce the above copyright |
10 | * notice, this list of conditions and the following disclaimer in the | 10 | * notice, this list of conditions and the following disclaimer in the |
11 | * documentation and/or other materials provided with the distribution. | 11 | * documentation and/or other materials provided with the distribution. |
12 | * * Neither the name of the OpenSim Project nor the | 12 | * * Neither the name of the OpenSim Project nor the |
13 | * names of its contributors may be used to endorse or promote products | 13 | * names of its contributors may be used to endorse or promote products |
14 | * derived from this software without specific prior written permission. | 14 | * derived from this software without specific prior written permission. |
15 | * | 15 | * |
16 | * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY | 16 | * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY |
17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | 17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | 18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
19 | * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY | 19 | * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY |
20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | 20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES |
21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | 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 | 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 | 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 | 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. | 25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
26 | */ | 26 | */ |
27 | 27 | ||
28 | using System; | 28 | using System; |
29 | using OpenSim.Region.Environment.Interfaces; | 29 | using OpenSim.Region.Environment.Interfaces; |
30 | 30 | ||
31 | namespace OpenSim.Region.Environment.Modules.World.Terrain.PaintBrushes | 31 | namespace OpenSim.Region.Environment.Modules.World.Terrain.PaintBrushes |
32 | { | 32 | { |
33 | /// <summary> | 33 | /// <summary> |
34 | /// Hydraulic Erosion Brush | 34 | /// Hydraulic Erosion Brush |
35 | /// </summary> | 35 | /// </summary> |
36 | public class ErodeSphere : ITerrainPaintableEffect | 36 | public class ErodeSphere : ITerrainPaintableEffect |
37 | { | 37 | { |
38 | private double rainHeight = 0.2; | 38 | private double rainHeight = 0.2; |
39 | private int rounds = 10; | 39 | private int rounds = 10; |
40 | private NeighbourSystem type = NeighbourSystem.Moore; // Parameter | 40 | private NeighbourSystem type = NeighbourSystem.Moore; // Parameter |
41 | private double waterSaturation = 0.30; // Can carry 1% of water in height | 41 | private double waterSaturation = 0.30; // Can carry 1% of water in height |
42 | 42 | ||
43 | #region Supporting Functions | 43 | #region Supporting Functions |
44 | 44 | ||
45 | private int[] Neighbours(NeighbourSystem type, int index) | 45 | private int[] Neighbours(NeighbourSystem type, int index) |
46 | { | 46 | { |
47 | int[] coord = new int[2]; | 47 | int[] coord = new int[2]; |
48 | 48 | ||
49 | index++; | 49 | index++; |
50 | 50 | ||
51 | switch (type) | 51 | switch (type) |
52 | { | 52 | { |
53 | case NeighbourSystem.Moore: | 53 | case NeighbourSystem.Moore: |
54 | switch (index) | 54 | switch (index) |
55 | { | 55 | { |
56 | case 1: | 56 | case 1: |
57 | coord[0] = -1; | 57 | coord[0] = -1; |
58 | coord[1] = -1; | 58 | coord[1] = -1; |
59 | break; | 59 | break; |
60 | 60 | ||
61 | case 2: | 61 | case 2: |
62 | coord[0] = -0; | 62 | coord[0] = -0; |
63 | coord[1] = -1; | 63 | coord[1] = -1; |
64 | break; | 64 | break; |
65 | 65 | ||
66 | case 3: | 66 | case 3: |
67 | coord[0] = +1; | 67 | coord[0] = +1; |
68 | coord[1] = -1; | 68 | coord[1] = -1; |
69 | break; | 69 | break; |
70 | 70 | ||
71 | case 4: | 71 | case 4: |
72 | coord[0] = -1; | 72 | coord[0] = -1; |
73 | coord[1] = -0; | 73 | coord[1] = -0; |
74 | break; | 74 | break; |
75 | 75 | ||
76 | case 5: | 76 | case 5: |
77 | coord[0] = -0; | 77 | coord[0] = -0; |
78 | coord[1] = -0; | 78 | coord[1] = -0; |
79 | break; | 79 | break; |
80 | 80 | ||
81 | case 6: | 81 | case 6: |
82 | coord[0] = +1; | 82 | coord[0] = +1; |
83 | coord[1] = -0; | 83 | coord[1] = -0; |
84 | break; | 84 | break; |
85 | 85 | ||
86 | case 7: | 86 | case 7: |
87 | coord[0] = -1; | 87 | coord[0] = -1; |
88 | coord[1] = +1; | 88 | coord[1] = +1; |
89 | break; | 89 | break; |
90 | 90 | ||
91 | case 8: | 91 | case 8: |
92 | coord[0] = -0; | 92 | coord[0] = -0; |
93 | coord[1] = +1; | 93 | coord[1] = +1; |
94 | break; | 94 | break; |
95 | 95 | ||
96 | case 9: | 96 | case 9: |
97 | coord[0] = +1; | 97 | coord[0] = +1; |
98 | coord[1] = +1; | 98 | coord[1] = +1; |
99 | break; | 99 | break; |
100 | 100 | ||
101 | default: | 101 | default: |
102 | break; | 102 | break; |
103 | } | 103 | } |
104 | break; | 104 | break; |
105 | 105 | ||
106 | case NeighbourSystem.VonNeumann: | 106 | case NeighbourSystem.VonNeumann: |
107 | switch (index) | 107 | switch (index) |
108 | { | 108 | { |
109 | case 1: | 109 | case 1: |
110 | coord[0] = 0; | 110 | coord[0] = 0; |
111 | coord[1] = -1; | 111 | coord[1] = -1; |
112 | break; | 112 | break; |
113 | 113 | ||
114 | case 2: | 114 | case 2: |
115 | coord[0] = -1; | 115 | coord[0] = -1; |
116 | coord[1] = 0; | 116 | coord[1] = 0; |
117 | break; | 117 | break; |
118 | 118 | ||
119 | case 3: | 119 | case 3: |
120 | coord[0] = +1; | 120 | coord[0] = +1; |
121 | coord[1] = 0; | 121 | coord[1] = 0; |
122 | break; | 122 | break; |
123 | 123 | ||
124 | case 4: | 124 | case 4: |
125 | coord[0] = 0; | 125 | coord[0] = 0; |
126 | coord[1] = +1; | 126 | coord[1] = +1; |
127 | break; | 127 | break; |
128 | 128 | ||
129 | case 5: | 129 | case 5: |
130 | coord[0] = -0; | 130 | coord[0] = -0; |
131 | coord[1] = -0; | 131 | coord[1] = -0; |
132 | break; | 132 | break; |
133 | 133 | ||
134 | default: | 134 | default: |
135 | break; | 135 | break; |
136 | } | 136 | } |
137 | break; | 137 | break; |
138 | } | 138 | } |
139 | 139 | ||
140 | return coord; | 140 | return coord; |
141 | } | 141 | } |
142 | 142 | ||
143 | private enum NeighbourSystem | 143 | private enum NeighbourSystem |
144 | { | 144 | { |
145 | Moore, | 145 | Moore, |
146 | VonNeumann | 146 | VonNeumann |
147 | } ; | 147 | } ; |
148 | 148 | ||
149 | #endregion | 149 | #endregion |
150 | 150 | ||
151 | #region ITerrainPaintableEffect Members | 151 | #region ITerrainPaintableEffect Members |
152 | 152 | ||
153 | public void PaintEffect(ITerrainChannel map, double rx, double ry, double strength, double duration) | 153 | public void PaintEffect(ITerrainChannel map, double rx, double ry, double strength, double duration) |
154 | { | 154 | { |
155 | strength = TerrainUtil.MetersToSphericalStrength(strength); | 155 | strength = TerrainUtil.MetersToSphericalStrength(strength); |
156 | 156 | ||
157 | int x, y; | 157 | int x, y; |
158 | // Using one 'rain' round for this, so skipping a useless loop | 158 | // Using one 'rain' round for this, so skipping a useless loop |
159 | // Will need to adapt back in for the Flood brush | 159 | // Will need to adapt back in for the Flood brush |
160 | 160 | ||
161 | ITerrainChannel water = new TerrainChannel(map.Width, map.Height); | 161 | ITerrainChannel water = new TerrainChannel(map.Width, map.Height); |
162 | ITerrainChannel sediment = new TerrainChannel(map.Width, map.Height); | 162 | ITerrainChannel sediment = new TerrainChannel(map.Width, map.Height); |
163 | 163 | ||
164 | // Fill with rain | 164 | // Fill with rain |
165 | for (x = 0; x < water.Width; x++) | 165 | for (x = 0; x < water.Width; x++) |
166 | for (y = 0; y < water.Height; y++) | 166 | for (y = 0; y < water.Height; y++) |
167 | water[x, y] = Math.Max(0.0, TerrainUtil.SphericalFactor(x, y, rx, ry, strength) * rainHeight * duration); | 167 | water[x, y] = Math.Max(0.0, TerrainUtil.SphericalFactor(x, y, rx, ry, strength) * rainHeight * duration); |
168 | 168 | ||
169 | for (int i = 0; i < rounds; i++) | 169 | for (int i = 0; i < rounds; i++) |
170 | { | 170 | { |
171 | // Erode underlying terrain | 171 | // Erode underlying terrain |
172 | for (x = 0; x < water.Width; x++) | 172 | for (x = 0; x < water.Width; x++) |
173 | { | 173 | { |
174 | for (y = 0; y < water.Height; y++) | 174 | for (y = 0; y < water.Height; y++) |
175 | { | 175 | { |
176 | double solConst = (1.0 / rounds); | 176 | double solConst = (1.0 / rounds); |
177 | double sedDelta = water[x, y] * solConst; | 177 | double sedDelta = water[x, y] * solConst; |
178 | map[x, y] -= sedDelta; | 178 | map[x, y] -= sedDelta; |
179 | sediment[x, y] += sedDelta; | 179 | sediment[x, y] += sedDelta; |
180 | } | 180 | } |
181 | } | 181 | } |
182 | 182 | ||
183 | // Move water | 183 | // Move water |
184 | for (x = 0; x < water.Width; x++) | 184 | for (x = 0; x < water.Width; x++) |
185 | { | 185 | { |
186 | for (y = 0; y < water.Height; y++) | 186 | for (y = 0; y < water.Height; y++) |
187 | { | 187 | { |
188 | if (water[x, y] <= 0) | 188 | if (water[x, y] <= 0) |
189 | continue; | 189 | continue; |
190 | 190 | ||
191 | // Step 1. Calculate average of neighbours | 191 | // Step 1. Calculate average of neighbours |
192 | 192 | ||
193 | int neighbours = 0; | 193 | int neighbours = 0; |
194 | double altitudeTotal = 0.0; | 194 | double altitudeTotal = 0.0; |
195 | double altitudeMe = map[x, y] + water[x, y]; | 195 | double altitudeMe = map[x, y] + water[x, y]; |
196 | 196 | ||
197 | int NEIGHBOUR_ME = 4; | 197 | int NEIGHBOUR_ME = 4; |
198 | 198 | ||
199 | int NEIGHBOUR_MAX = type == NeighbourSystem.Moore ? 9 : 5; | 199 | int NEIGHBOUR_MAX = type == NeighbourSystem.Moore ? 9 : 5; |
200 | 200 | ||
201 | for (int j = 0; j < NEIGHBOUR_MAX; j++) | 201 | for (int j = 0; j < NEIGHBOUR_MAX; j++) |
202 | { | 202 | { |
203 | if (j != NEIGHBOUR_ME) | 203 | if (j != NEIGHBOUR_ME) |
204 | { | 204 | { |
205 | int[] coords = Neighbours(type, j); | 205 | int[] coords = Neighbours(type, j); |
206 | 206 | ||
207 | coords[0] += x; | 207 | coords[0] += x; |
208 | coords[1] += y; | 208 | coords[1] += y; |
209 | 209 | ||
210 | if (coords[0] > map.Width - 1) | 210 | if (coords[0] > map.Width - 1) |
211 | continue; | 211 | continue; |
212 | if (coords[1] > map.Height - 1) | 212 | if (coords[1] > map.Height - 1) |
213 | continue; | 213 | continue; |
214 | if (coords[0] < 0) | 214 | if (coords[0] < 0) |
215 | continue; | 215 | continue; |
216 | if (coords[1] < 0) | 216 | if (coords[1] < 0) |
217 | continue; | 217 | continue; |
218 | 218 | ||
219 | // Calculate total height of this neighbour | 219 | // Calculate total height of this neighbour |
220 | double altitudeNeighbour = water[coords[0], coords[1]] + map[coords[0], coords[1]]; | 220 | double altitudeNeighbour = water[coords[0], coords[1]] + map[coords[0], coords[1]]; |
221 | 221 | ||
222 | // If it's greater than me... | 222 | // If it's greater than me... |
223 | if (altitudeNeighbour - altitudeMe < 0) | 223 | if (altitudeNeighbour - altitudeMe < 0) |
224 | { | 224 | { |
225 | // Add it to our calculations | 225 | // Add it to our calculations |
226 | neighbours++; | 226 | neighbours++; |
227 | altitudeTotal += altitudeNeighbour; | 227 | altitudeTotal += altitudeNeighbour; |
228 | } | 228 | } |
229 | } | 229 | } |
230 | } | 230 | } |
231 | 231 | ||
232 | if (neighbours == 0) | 232 | if (neighbours == 0) |
233 | continue; | 233 | continue; |
234 | 234 | ||
235 | double altitudeAvg = altitudeTotal / neighbours; | 235 | double altitudeAvg = altitudeTotal / neighbours; |
236 | 236 | ||
237 | // Step 2. Allocate water to neighbours. | 237 | // Step 2. Allocate water to neighbours. |
238 | for (int j = 0; j < NEIGHBOUR_MAX; j++) | 238 | for (int j = 0; j < NEIGHBOUR_MAX; j++) |
239 | { | 239 | { |
240 | if (j != NEIGHBOUR_ME) | 240 | if (j != NEIGHBOUR_ME) |
241 | { | 241 | { |
242 | int[] coords = Neighbours(type, j); | 242 | int[] coords = Neighbours(type, j); |
243 | 243 | ||
244 | coords[0] += x; | 244 | coords[0] += x; |
245 | coords[1] += y; | 245 | coords[1] += y; |
246 | 246 | ||
247 | if (coords[0] > map.Width - 1) | 247 | if (coords[0] > map.Width - 1) |
248 | continue; | 248 | continue; |
249 | if (coords[1] > map.Height - 1) | 249 | if (coords[1] > map.Height - 1) |
250 | continue; | 250 | continue; |
251 | if (coords[0] < 0) | 251 | if (coords[0] < 0) |
252 | continue; | 252 | continue; |
253 | if (coords[1] < 0) | 253 | if (coords[1] < 0) |
254 | continue; | 254 | continue; |
255 | 255 | ||
256 | // Skip if we dont have water to begin with. | 256 | // Skip if we dont have water to begin with. |
257 | if (water[x, y] < 0) | 257 | if (water[x, y] < 0) |
258 | continue; | 258 | continue; |
259 | 259 | ||
260 | // Calculate our delta average | 260 | // Calculate our delta average |
261 | double altitudeDelta = altitudeMe - altitudeAvg; | 261 | double altitudeDelta = altitudeMe - altitudeAvg; |
262 | 262 | ||
263 | if (altitudeDelta < 0) | 263 | if (altitudeDelta < 0) |
264 | continue; | 264 | continue; |
265 | 265 | ||
266 | // Calculate how much water we can move | 266 | // Calculate how much water we can move |
267 | double waterMin = Math.Min(water[x, y], altitudeDelta); | 267 | double waterMin = Math.Min(water[x, y], altitudeDelta); |
268 | double waterDelta = waterMin * ((water[coords[0], coords[1]] + map[coords[0], coords[1]]) | 268 | double waterDelta = waterMin * ((water[coords[0], coords[1]] + map[coords[0], coords[1]]) |
269 | / altitudeTotal); | 269 | / altitudeTotal); |
270 | 270 | ||
271 | double sedimentDelta = sediment[x, y] * (waterDelta / water[x, y]); | 271 | double sedimentDelta = sediment[x, y] * (waterDelta / water[x, y]); |
272 | 272 | ||
273 | if (sedimentDelta > 0) | 273 | if (sedimentDelta > 0) |
274 | { | 274 | { |
275 | sediment[x, y] -= sedimentDelta; | 275 | sediment[x, y] -= sedimentDelta; |
276 | sediment[coords[0], coords[1]] += sedimentDelta; | 276 | sediment[coords[0], coords[1]] += sedimentDelta; |
277 | } | 277 | } |
278 | } | 278 | } |
279 | } | 279 | } |
280 | } | 280 | } |
281 | } | 281 | } |
282 | 282 | ||
283 | // Evaporate | 283 | // Evaporate |
284 | 284 | ||
285 | for (x = 0; x < water.Width; x++) | 285 | for (x = 0; x < water.Width; x++) |
286 | { | 286 | { |
287 | for (y = 0; y < water.Height; y++) | 287 | for (y = 0; y < water.Height; y++) |
288 | { | 288 | { |
289 | water[x, y] *= 1.0 - (rainHeight / rounds); | 289 | water[x, y] *= 1.0 - (rainHeight / rounds); |
290 | 290 | ||
291 | double waterCapacity = waterSaturation * water[x, y]; | 291 | double waterCapacity = waterSaturation * water[x, y]; |
292 | 292 | ||
293 | double sedimentDeposit = sediment[x, y] - waterCapacity; | 293 | double sedimentDeposit = sediment[x, y] - waterCapacity; |
294 | if (sedimentDeposit > 0) | 294 | if (sedimentDeposit > 0) |
295 | { | 295 | { |
296 | sediment[x, y] -= sedimentDeposit; | 296 | sediment[x, y] -= sedimentDeposit; |
297 | map[x, y] += sedimentDeposit; | 297 | map[x, y] += sedimentDeposit; |
298 | } | 298 | } |
299 | } | 299 | } |
300 | } | 300 | } |
301 | } | 301 | } |
302 | 302 | ||
303 | // Deposit any remainder (should be minimal) | 303 | // Deposit any remainder (should be minimal) |
304 | for (x = 0; x < water.Width; x++) | 304 | for (x = 0; x < water.Width; x++) |
305 | for (y = 0; y < water.Height; y++) | 305 | for (y = 0; y < water.Height; y++) |
306 | if (sediment[x, y] > 0) | 306 | if (sediment[x, y] > 0) |
307 | map[x, y] += sediment[x, y]; | 307 | map[x, y] += sediment[x, y]; |
308 | } | 308 | } |
309 | 309 | ||
310 | #endregion | 310 | #endregion |
311 | } | 311 | } |
312 | } \ No newline at end of file | 312 | } \ No newline at end of file |
diff --git a/OpenSim/Region/Environment/Modules/World/Terrain/PaintBrushes/FlattenSphere.cs b/OpenSim/Region/Environment/Modules/World/Terrain/PaintBrushes/FlattenSphere.cs index d4f3b9f..dee455f 100644 --- a/OpenSim/Region/Environment/Modules/World/Terrain/PaintBrushes/FlattenSphere.cs +++ b/OpenSim/Region/Environment/Modules/World/Terrain/PaintBrushes/FlattenSphere.cs | |||
@@ -1,94 +1,94 @@ | |||
1 | /* | 1 | /* |
2 | * Copyright (c) Contributors, http://opensimulator.org/ | 2 | * Copyright (c) Contributors, http://opensimulator.org/ |
3 | * See CONTRIBUTORS.TXT for a full list of copyright holders. | 3 | * See CONTRIBUTORS.TXT for a full list of copyright holders. |
4 | * | 4 | * |
5 | * Redistribution and use in source and binary forms, with or without | 5 | * Redistribution and use in source and binary forms, with or without |
6 | * modification, are permitted provided that the following conditions are met: | 6 | * modification, are permitted provided that the following conditions are met: |
7 | * * Redistributions of source code must retain the above copyright | 7 | * * Redistributions of source code must retain the above copyright |
8 | * notice, this list of conditions and the following disclaimer. | 8 | * notice, this list of conditions and the following disclaimer. |
9 | * * Redistributions in binary form must reproduce the above copyright | 9 | * * Redistributions in binary form must reproduce the above copyright |
10 | * notice, this list of conditions and the following disclaimer in the | 10 | * notice, this list of conditions and the following disclaimer in the |
11 | * documentation and/or other materials provided with the distribution. | 11 | * documentation and/or other materials provided with the distribution. |
12 | * * Neither the name of the OpenSim Project nor the | 12 | * * Neither the name of the OpenSim Project nor the |
13 | * names of its contributors may be used to endorse or promote products | 13 | * names of its contributors may be used to endorse or promote products |
14 | * derived from this software without specific prior written permission. | 14 | * derived from this software without specific prior written permission. |
15 | * | 15 | * |
16 | * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY | 16 | * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY |
17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | 17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | 18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
19 | * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY | 19 | * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY |
20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | 20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES |
21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | 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 | 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 | 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 | 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. | 25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
26 | */ | 26 | */ |
27 | 27 | ||
28 | using OpenSim.Region.Environment.Interfaces; | 28 | using OpenSim.Region.Environment.Interfaces; |
29 | 29 | ||
30 | namespace OpenSim.Region.Environment.Modules.World.Terrain.PaintBrushes | 30 | namespace OpenSim.Region.Environment.Modules.World.Terrain.PaintBrushes |
31 | { | 31 | { |
32 | public class FlattenSphere : ITerrainPaintableEffect | 32 | public class FlattenSphere : ITerrainPaintableEffect |
33 | { | 33 | { |
34 | 34 | ||
35 | #region ITerrainPaintableEffect Members | 35 | #region ITerrainPaintableEffect Members |
36 | 36 | ||
37 | public void PaintEffect(ITerrainChannel map, double rx, double ry, double strength, double duration) | 37 | public void PaintEffect(ITerrainChannel map, double rx, double ry, double strength, double duration) |
38 | { | 38 | { |
39 | strength = TerrainUtil.MetersToSphericalStrength(strength); | 39 | strength = TerrainUtil.MetersToSphericalStrength(strength); |
40 | 40 | ||
41 | int x, y; | 41 | int x, y; |
42 | double[,] tweak = new double[map.Width,map.Height]; | 42 | double[,] tweak = new double[map.Width,map.Height]; |
43 | 43 | ||
44 | double area = strength; | 44 | double area = strength; |
45 | double step = strength / 4.0; | 45 | double step = strength / 4.0; |
46 | 46 | ||
47 | double sum = 0.0; | 47 | double sum = 0.0; |
48 | double step2 = 0.0; | 48 | double step2 = 0.0; |
49 | double avg = 0.0; | 49 | double avg = 0.0; |
50 | 50 | ||
51 | // compute delta map | 51 | // compute delta map |
52 | for (x = 0; x < map.Width; x++) | 52 | for (x = 0; x < map.Width; x++) |
53 | { | 53 | { |
54 | for (y = 0; y < map.Height; y++) | 54 | for (y = 0; y < map.Height; y++) |
55 | { | 55 | { |
56 | double z = SphericalFactor(x, y, rx, ry, strength); | 56 | double z = SphericalFactor(x, y, rx, ry, strength); |
57 | 57 | ||
58 | if (z > 0) // add in non-zero amount | 58 | if (z > 0) // add in non-zero amount |
59 | { | 59 | { |
60 | sum += map[x, y] * z; | 60 | sum += map[x, y] * z; |
61 | step2 += z; | 61 | step2 += z; |
62 | } | 62 | } |
63 | } | 63 | } |
64 | } | 64 | } |
65 | 65 | ||
66 | avg = sum / step2; | 66 | avg = sum / step2; |
67 | 67 | ||
68 | // blend in map | 68 | // blend in map |
69 | for (x = 0; x < map.Width; x++) | 69 | for (x = 0; x < map.Width; x++) |
70 | { | 70 | { |
71 | for (y = 0; y < map.Height; y++) | 71 | for (y = 0; y < map.Height; y++) |
72 | { | 72 | { |
73 | double z = SphericalFactor(x, y, rx, ry, strength) * duration; | 73 | double z = SphericalFactor(x, y, rx, ry, strength) * duration; |
74 | 74 | ||
75 | if (z > 0) // add in non-zero amount | 75 | if (z > 0) // add in non-zero amount |
76 | { | 76 | { |
77 | if (z > 1.0) | 77 | if (z > 1.0) |
78 | z = 1.0; | 78 | z = 1.0; |
79 | 79 | ||
80 | map[x, y] = (map[x, y] * (1.0 - z)) + (avg * z); | 80 | map[x, y] = (map[x, y] * (1.0 - z)) + (avg * z); |
81 | } | 81 | } |
82 | } | 82 | } |
83 | } | 83 | } |
84 | } | 84 | } |
85 | 85 | ||
86 | #endregion | 86 | #endregion |
87 | 87 | ||
88 | private double SphericalFactor(double x, double y, double rx, double ry, double size) | 88 | private double SphericalFactor(double x, double y, double rx, double ry, double size) |
89 | { | 89 | { |
90 | double z = size * size - ((x - rx) * (x - rx) + (y - ry) * (y - ry)); | 90 | double z = size * size - ((x - rx) * (x - rx) + (y - ry) * (y - ry)); |
91 | return z; | 91 | return z; |
92 | } | 92 | } |
93 | } | 93 | } |
94 | } \ No newline at end of file | 94 | } \ No newline at end of file |
diff --git a/OpenSim/Region/Environment/Modules/World/Terrain/PaintBrushes/LowerSphere.cs b/OpenSim/Region/Environment/Modules/World/Terrain/PaintBrushes/LowerSphere.cs index 0b80407..092bd29 100644 --- a/OpenSim/Region/Environment/Modules/World/Terrain/PaintBrushes/LowerSphere.cs +++ b/OpenSim/Region/Environment/Modules/World/Terrain/PaintBrushes/LowerSphere.cs | |||
@@ -1,67 +1,67 @@ | |||
1 | /* | 1 | /* |
2 | * Copyright (c) Contributors, http://opensimulator.org/ | 2 | * Copyright (c) Contributors, http://opensimulator.org/ |
3 | * See CONTRIBUTORS.TXT for a full list of copyright holders. | 3 | * See CONTRIBUTORS.TXT for a full list of copyright holders. |
4 | * | 4 | * |
5 | * Redistribution and use in source and binary forms, with or without | 5 | * Redistribution and use in source and binary forms, with or without |
6 | * modification, are permitted provided that the following conditions are met: | 6 | * modification, are permitted provided that the following conditions are met: |
7 | * * Redistributions of source code must retain the above copyright | 7 | * * Redistributions of source code must retain the above copyright |
8 | * notice, this list of conditions and the following disclaimer. | 8 | * notice, this list of conditions and the following disclaimer. |
9 | * * Redistributions in binary form must reproduce the above copyright | 9 | * * Redistributions in binary form must reproduce the above copyright |
10 | * notice, this list of conditions and the following disclaimer in the | 10 | * notice, this list of conditions and the following disclaimer in the |
11 | * documentation and/or other materials provided with the distribution. | 11 | * documentation and/or other materials provided with the distribution. |
12 | * * Neither the name of the OpenSim Project nor the | 12 | * * Neither the name of the OpenSim Project nor the |
13 | * names of its contributors may be used to endorse or promote products | 13 | * names of its contributors may be used to endorse or promote products |
14 | * derived from this software without specific prior written permission. | 14 | * derived from this software without specific prior written permission. |
15 | * | 15 | * |
16 | * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY | 16 | * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY |
17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | 17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | 18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
19 | * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY | 19 | * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY |
20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | 20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES |
21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | 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 | 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 | 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 | 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. | 25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
26 | */ | 26 | */ |
27 | 27 | ||
28 | using System; | 28 | using System; |
29 | using OpenSim.Region.Environment.Interfaces; | 29 | using OpenSim.Region.Environment.Interfaces; |
30 | 30 | ||
31 | namespace OpenSim.Region.Environment.Modules.World.Terrain.PaintBrushes | 31 | namespace OpenSim.Region.Environment.Modules.World.Terrain.PaintBrushes |
32 | { | 32 | { |
33 | public class LowerSphere : ITerrainPaintableEffect | 33 | public class LowerSphere : ITerrainPaintableEffect |
34 | { | 34 | { |
35 | #region ITerrainPaintableEffect Members | 35 | #region ITerrainPaintableEffect Members |
36 | 36 | ||
37 | public void PaintEffect(ITerrainChannel map, double rx, double ry, double strength, double duration) | 37 | public void PaintEffect(ITerrainChannel map, double rx, double ry, double strength, double duration) |
38 | { | 38 | { |
39 | strength = TerrainUtil.MetersToSphericalStrength(strength); | 39 | strength = TerrainUtil.MetersToSphericalStrength(strength); |
40 | 40 | ||
41 | int x, y; | 41 | int x, y; |
42 | for (x = 0; x < map.Width; x++) | 42 | for (x = 0; x < map.Width; x++) |
43 | { | 43 | { |
44 | // Skip everything unlikely to be affected | 44 | // Skip everything unlikely to be affected |
45 | if (Math.Abs(x - rx) > strength * 1.1) | 45 | if (Math.Abs(x - rx) > strength * 1.1) |
46 | continue; | 46 | continue; |
47 | 47 | ||
48 | for (y = 0; y < map.Height; y++) | 48 | for (y = 0; y < map.Height; y++) |
49 | { | 49 | { |
50 | // Skip everything unlikely to be affected | 50 | // Skip everything unlikely to be affected |
51 | if (Math.Abs(y - ry) > strength * 1.1) | 51 | if (Math.Abs(y - ry) > strength * 1.1) |
52 | continue; | 52 | continue; |
53 | 53 | ||
54 | // Calculate a sphere and add it to the heighmap | 54 | // Calculate a sphere and add it to the heighmap |
55 | double z = strength; | 55 | double z = strength; |
56 | z *= z; | 56 | z *= z; |
57 | z -= ((x - rx) * (x - rx)) + ((y - ry) * (y - ry)); | 57 | z -= ((x - rx) * (x - rx)) + ((y - ry) * (y - ry)); |
58 | 58 | ||
59 | if (z > 0.0) | 59 | if (z > 0.0) |
60 | map[x, y] -= z * duration; | 60 | map[x, y] -= z * duration; |
61 | } | 61 | } |
62 | } | 62 | } |
63 | } | 63 | } |
64 | 64 | ||
65 | #endregion | 65 | #endregion |
66 | } | 66 | } |
67 | } \ No newline at end of file | 67 | } \ No newline at end of file |
diff --git a/OpenSim/Region/Environment/Modules/World/Terrain/PaintBrushes/NoiseSphere.cs b/OpenSim/Region/Environment/Modules/World/Terrain/PaintBrushes/NoiseSphere.cs index a188e9f..8ae583e 100644 --- a/OpenSim/Region/Environment/Modules/World/Terrain/PaintBrushes/NoiseSphere.cs +++ b/OpenSim/Region/Environment/Modules/World/Terrain/PaintBrushes/NoiseSphere.cs | |||
@@ -1,70 +1,70 @@ | |||
1 | /* | 1 | /* |
2 | * Copyright (c) Contributors, http://opensimulator.org/ | 2 | * Copyright (c) Contributors, http://opensimulator.org/ |
3 | * See CONTRIBUTORS.TXT for a full list of copyright holders. | 3 | * See CONTRIBUTORS.TXT for a full list of copyright holders. |
4 | * | 4 | * |
5 | * Redistribution and use in source and binary forms, with or without | 5 | * Redistribution and use in source and binary forms, with or without |
6 | * modification, are permitted provided that the following conditions are met: | 6 | * modification, are permitted provided that the following conditions are met: |
7 | * * Redistributions of source code must retain the above copyright | 7 | * * Redistributions of source code must retain the above copyright |
8 | * notice, this list of conditions and the following disclaimer. | 8 | * notice, this list of conditions and the following disclaimer. |
9 | * * Redistributions in binary form must reproduce the above copyright | 9 | * * Redistributions in binary form must reproduce the above copyright |
10 | * notice, this list of conditions and the following disclaimer in the | 10 | * notice, this list of conditions and the following disclaimer in the |
11 | * documentation and/or other materials provided with the distribution. | 11 | * documentation and/or other materials provided with the distribution. |
12 | * * Neither the name of the OpenSim Project nor the | 12 | * * Neither the name of the OpenSim Project nor the |
13 | * names of its contributors may be used to endorse or promote products | 13 | * names of its contributors may be used to endorse or promote products |
14 | * derived from this software without specific prior written permission. | 14 | * derived from this software without specific prior written permission. |
15 | * | 15 | * |
16 | * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY | 16 | * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY |
17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | 17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | 18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
19 | * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY | 19 | * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY |
20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | 20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES |
21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | 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 | 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 | 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 | 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. | 25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
26 | */ | 26 | */ |
27 | 27 | ||
28 | using System; | 28 | using System; |
29 | using OpenSim.Framework; | 29 | using OpenSim.Framework; |
30 | using OpenSim.Region.Environment.Interfaces; | 30 | using OpenSim.Region.Environment.Interfaces; |
31 | 31 | ||
32 | namespace OpenSim.Region.Environment.Modules.World.Terrain.PaintBrushes | 32 | namespace OpenSim.Region.Environment.Modules.World.Terrain.PaintBrushes |
33 | { | 33 | { |
34 | public class NoiseSphere : ITerrainPaintableEffect | 34 | public class NoiseSphere : ITerrainPaintableEffect |
35 | { | 35 | { |
36 | #region ITerrainPaintableEffect Members | 36 | #region ITerrainPaintableEffect Members |
37 | 37 | ||
38 | public void PaintEffect(ITerrainChannel map, double rx, double ry, double strength, double duration) | 38 | public void PaintEffect(ITerrainChannel map, double rx, double ry, double strength, double duration) |
39 | { | 39 | { |
40 | strength = TerrainUtil.MetersToSphericalStrength(strength); | 40 | strength = TerrainUtil.MetersToSphericalStrength(strength); |
41 | 41 | ||
42 | int x, y; | 42 | int x, y; |
43 | for (x = 0; x < map.Width; x++) | 43 | for (x = 0; x < map.Width; x++) |
44 | { | 44 | { |
45 | // Skip everything unlikely to be affected | 45 | // Skip everything unlikely to be affected |
46 | if (Math.Abs(x - rx) > strength * 1.1) | 46 | if (Math.Abs(x - rx) > strength * 1.1) |
47 | continue; | 47 | continue; |
48 | 48 | ||
49 | for (y = 0; y < map.Height; y++) | 49 | for (y = 0; y < map.Height; y++) |
50 | { | 50 | { |
51 | // Skip everything unlikely to be affected | 51 | // Skip everything unlikely to be affected |
52 | if (Math.Abs(y - ry) > strength * 1.1) | 52 | if (Math.Abs(y - ry) > strength * 1.1) |
53 | continue; | 53 | continue; |
54 | 54 | ||
55 | // Calculate a sphere and add it to the heighmap | 55 | // Calculate a sphere and add it to the heighmap |
56 | double z = strength; | 56 | double z = strength; |
57 | z *= z; | 57 | z *= z; |
58 | z -= ((x - rx) * (x - rx)) + ((y - ry) * (y - ry)); | 58 | z -= ((x - rx) * (x - rx)) + ((y - ry) * (y - ry)); |
59 | 59 | ||
60 | double noise = TerrainUtil.PerlinNoise2D((double) x / (double) Constants.RegionSize, (double) y / (double) Constants.RegionSize, 8, 1.0); | 60 | double noise = TerrainUtil.PerlinNoise2D((double) x / (double) Constants.RegionSize, (double) y / (double) Constants.RegionSize, 8, 1.0); |
61 | 61 | ||
62 | if (z > 0.0) | 62 | if (z > 0.0) |
63 | map[x, y] += noise * z * duration; | 63 | map[x, y] += noise * z * duration; |
64 | } | 64 | } |
65 | } | 65 | } |
66 | } | 66 | } |
67 | 67 | ||
68 | #endregion | 68 | #endregion |
69 | } | 69 | } |
70 | } \ No newline at end of file | 70 | } \ No newline at end of file |
diff --git a/OpenSim/Region/Environment/Modules/World/Terrain/PaintBrushes/OlsenSphere.cs b/OpenSim/Region/Environment/Modules/World/Terrain/PaintBrushes/OlsenSphere.cs index dc56cf1..ba01a01 100644 --- a/OpenSim/Region/Environment/Modules/World/Terrain/PaintBrushes/OlsenSphere.cs +++ b/OpenSim/Region/Environment/Modules/World/Terrain/PaintBrushes/OlsenSphere.cs | |||
@@ -1,225 +1,225 @@ | |||
1 | /* | 1 | /* |
2 | * Copyright (c) Contributors, http://opensimulator.org/ | 2 | * Copyright (c) Contributors, http://opensimulator.org/ |
3 | * See CONTRIBUTORS.TXT for a full list of copyright holders. | 3 | * See CONTRIBUTORS.TXT for a full list of copyright holders. |
4 | * | 4 | * |
5 | * Redistribution and use in source and binary forms, with or without | 5 | * Redistribution and use in source and binary forms, with or without |
6 | * modification, are permitted provided that the following conditions are met: | 6 | * modification, are permitted provided that the following conditions are met: |
7 | * * Redistributions of source code must retain the above copyright | 7 | * * Redistributions of source code must retain the above copyright |
8 | * notice, this list of conditions and the following disclaimer. | 8 | * notice, this list of conditions and the following disclaimer. |
9 | * * Redistributions in binary form must reproduce the above copyright | 9 | * * Redistributions in binary form must reproduce the above copyright |
10 | * notice, this list of conditions and the following disclaimer in the | 10 | * notice, this list of conditions and the following disclaimer in the |
11 | * documentation and/or other materials provided with the distribution. | 11 | * documentation and/or other materials provided with the distribution. |
12 | * * Neither the name of the OpenSim Project nor the | 12 | * * Neither the name of the OpenSim Project nor the |
13 | * names of its contributors may be used to endorse or promote products | 13 | * names of its contributors may be used to endorse or promote products |
14 | * derived from this software without specific prior written permission. | 14 | * derived from this software without specific prior written permission. |
15 | * | 15 | * |
16 | * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY | 16 | * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY |
17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | 17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | 18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
19 | * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY | 19 | * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY |
20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | 20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES |
21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | 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 | 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 | 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 | 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. | 25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
26 | */ | 26 | */ |
27 | 27 | ||
28 | using System; | 28 | using System; |
29 | using OpenSim.Region.Environment.Interfaces; | 29 | using OpenSim.Region.Environment.Interfaces; |
30 | 30 | ||
31 | namespace OpenSim.Region.Environment.Modules.World.Terrain.PaintBrushes | 31 | namespace OpenSim.Region.Environment.Modules.World.Terrain.PaintBrushes |
32 | { | 32 | { |
33 | /// <summary> | 33 | /// <summary> |
34 | /// Speed-Optimised Hybrid Erosion Brush | 34 | /// Speed-Optimised Hybrid Erosion Brush |
35 | /// | 35 | /// |
36 | /// As per Jacob Olsen's Paper | 36 | /// As per Jacob Olsen's Paper |
37 | /// http://www.oddlabs.com/download/terrain_generation.pdf | 37 | /// http://www.oddlabs.com/download/terrain_generation.pdf |
38 | /// </summary> | 38 | /// </summary> |
39 | public class OlsenSphere : ITerrainPaintableEffect | 39 | public class OlsenSphere : ITerrainPaintableEffect |
40 | { | 40 | { |
41 | private double nConst = 1024.0; | 41 | private double nConst = 1024.0; |
42 | private NeighbourSystem type = NeighbourSystem.Moore; // Parameter | 42 | private NeighbourSystem type = NeighbourSystem.Moore; // Parameter |
43 | 43 | ||
44 | #region Supporting Functions | 44 | #region Supporting Functions |
45 | 45 | ||
46 | private int[] Neighbours(NeighbourSystem type, int index) | 46 | private int[] Neighbours(NeighbourSystem type, int index) |
47 | { | 47 | { |
48 | int[] coord = new int[2]; | 48 | int[] coord = new int[2]; |
49 | 49 | ||
50 | index++; | 50 | index++; |
51 | 51 | ||
52 | switch (type) | 52 | switch (type) |
53 | { | 53 | { |
54 | case NeighbourSystem.Moore: | 54 | case NeighbourSystem.Moore: |
55 | switch (index) | 55 | switch (index) |
56 | { | 56 | { |
57 | case 1: | 57 | case 1: |
58 | coord[0] = -1; | 58 | coord[0] = -1; |
59 | coord[1] = -1; | 59 | coord[1] = -1; |
60 | break; | 60 | break; |
61 | 61 | ||
62 | case 2: | 62 | case 2: |
63 | coord[0] = -0; | 63 | coord[0] = -0; |
64 | coord[1] = -1; | 64 | coord[1] = -1; |
65 | break; | 65 | break; |
66 | 66 | ||
67 | case 3: | 67 | case 3: |
68 | coord[0] = +1; | 68 | coord[0] = +1; |
69 | coord[1] = -1; | 69 | coord[1] = -1; |
70 | break; | 70 | break; |
71 | 71 | ||
72 | case 4: | 72 | case 4: |
73 | coord[0] = -1; | 73 | coord[0] = -1; |
74 | coord[1] = -0; | 74 | coord[1] = -0; |
75 | break; | 75 | break; |
76 | 76 | ||
77 | case 5: | 77 | case 5: |
78 | coord[0] = -0; | 78 | coord[0] = -0; |
79 | coord[1] = -0; | 79 | coord[1] = -0; |
80 | break; | 80 | break; |
81 | 81 | ||
82 | case 6: | 82 | case 6: |
83 | coord[0] = +1; | 83 | coord[0] = +1; |
84 | coord[1] = -0; | 84 | coord[1] = -0; |
85 | break; | 85 | break; |
86 | 86 | ||
87 | case 7: | 87 | case 7: |
88 | coord[0] = -1; | 88 | coord[0] = -1; |
89 | coord[1] = +1; | 89 | coord[1] = +1; |
90 | break; | 90 | break; |
91 | 91 | ||
92 | case 8: | 92 | case 8: |
93 | coord[0] = -0; | 93 | coord[0] = -0; |
94 | coord[1] = +1; | 94 | coord[1] = +1; |
95 | break; | 95 | break; |
96 | 96 | ||
97 | case 9: | 97 | case 9: |
98 | coord[0] = +1; | 98 | coord[0] = +1; |
99 | coord[1] = +1; | 99 | coord[1] = +1; |
100 | break; | 100 | break; |
101 | 101 | ||
102 | default: | 102 | default: |
103 | break; | 103 | break; |
104 | } | 104 | } |
105 | break; | 105 | break; |
106 | 106 | ||
107 | case NeighbourSystem.VonNeumann: | 107 | case NeighbourSystem.VonNeumann: |
108 | switch (index) | 108 | switch (index) |
109 | { | 109 | { |
110 | case 1: | 110 | case 1: |
111 | coord[0] = 0; | 111 | coord[0] = 0; |
112 | coord[1] = -1; | 112 | coord[1] = -1; |
113 | break; | 113 | break; |
114 | 114 | ||
115 | case 2: | 115 | case 2: |
116 | coord[0] = -1; | 116 | coord[0] = -1; |
117 | coord[1] = 0; | 117 | coord[1] = 0; |
118 | break; | 118 | break; |
119 | 119 | ||
120 | case 3: | 120 | case 3: |
121 | coord[0] = +1; | 121 | coord[0] = +1; |
122 | coord[1] = 0; | 122 | coord[1] = 0; |
123 | break; | 123 | break; |
124 | 124 | ||
125 | case 4: | 125 | case 4: |
126 | coord[0] = 0; | 126 | coord[0] = 0; |
127 | coord[1] = +1; | 127 | coord[1] = +1; |
128 | break; | 128 | break; |
129 | 129 | ||
130 | case 5: | 130 | case 5: |
131 | coord[0] = -0; | 131 | coord[0] = -0; |
132 | coord[1] = -0; | 132 | coord[1] = -0; |
133 | break; | 133 | break; |
134 | 134 | ||
135 | default: | 135 | default: |
136 | break; | 136 | break; |
137 | } | 137 | } |
138 | break; | 138 | break; |
139 | } | 139 | } |
140 | 140 | ||
141 | return coord; | 141 | return coord; |
142 | } | 142 | } |
143 | 143 | ||
144 | private double SphericalFactor(double x, double y, double rx, double ry, double size) | 144 | private double SphericalFactor(double x, double y, double rx, double ry, double size) |
145 | { | 145 | { |
146 | double z = size * size - ((x - rx) * (x - rx) + (y - ry) * (y - ry)); | 146 | double z = size * size - ((x - rx) * (x - rx) + (y - ry) * (y - ry)); |
147 | return z; | 147 | return z; |
148 | } | 148 | } |
149 | 149 | ||
150 | private enum NeighbourSystem | 150 | private enum NeighbourSystem |
151 | { | 151 | { |
152 | Moore, | 152 | Moore, |
153 | VonNeumann | 153 | VonNeumann |
154 | } ; | 154 | } ; |
155 | 155 | ||
156 | #endregion | 156 | #endregion |
157 | 157 | ||
158 | #region ITerrainPaintableEffect Members | 158 | #region ITerrainPaintableEffect Members |
159 | 159 | ||
160 | public void PaintEffect(ITerrainChannel map, double rx, double ry, double strength, double duration) | 160 | public void PaintEffect(ITerrainChannel map, double rx, double ry, double strength, double duration) |
161 | { | 161 | { |
162 | strength = TerrainUtil.MetersToSphericalStrength(strength); | 162 | strength = TerrainUtil.MetersToSphericalStrength(strength); |
163 | 163 | ||
164 | int x, y; | 164 | int x, y; |
165 | 165 | ||
166 | for (x = 0; x < map.Width; x++) | 166 | for (x = 0; x < map.Width; x++) |
167 | { | 167 | { |
168 | for (y = 0; y < map.Height; y++) | 168 | for (y = 0; y < map.Height; y++) |
169 | { | 169 | { |
170 | double z = SphericalFactor(x, y, rx, ry, strength); | 170 | double z = SphericalFactor(x, y, rx, ry, strength); |
171 | 171 | ||
172 | if (z > 0) // add in non-zero amount | 172 | if (z > 0) // add in non-zero amount |
173 | { | 173 | { |
174 | int NEIGHBOUR_ME = 4; | 174 | int NEIGHBOUR_ME = 4; |
175 | int NEIGHBOUR_MAX = type == NeighbourSystem.Moore ? 9 : 5; | 175 | int NEIGHBOUR_MAX = type == NeighbourSystem.Moore ? 9 : 5; |
176 | 176 | ||
177 | double max = Double.MinValue; | 177 | double max = Double.MinValue; |
178 | int loc = 0; | 178 | int loc = 0; |
179 | double cellmax = 0; | 179 | double cellmax = 0; |
180 | 180 | ||
181 | 181 | ||
182 | for (int j = 0; j < NEIGHBOUR_MAX; j++) | 182 | for (int j = 0; j < NEIGHBOUR_MAX; j++) |
183 | { | 183 | { |
184 | if (j != NEIGHBOUR_ME) | 184 | if (j != NEIGHBOUR_ME) |
185 | { | 185 | { |
186 | int[] coords = Neighbours(type, j); | 186 | int[] coords = Neighbours(type, j); |
187 | 187 | ||
188 | coords[0] += x; | 188 | coords[0] += x; |
189 | coords[1] += y; | 189 | coords[1] += y; |
190 | 190 | ||
191 | if (coords[0] > map.Width - 1) | 191 | if (coords[0] > map.Width - 1) |
192 | continue; | 192 | continue; |
193 | if (coords[1] > map.Height - 1) | 193 | if (coords[1] > map.Height - 1) |
194 | continue; | 194 | continue; |
195 | if (coords[0] < 0) | 195 | if (coords[0] < 0) |
196 | continue; | 196 | continue; |
197 | if (coords[1] < 0) | 197 | if (coords[1] < 0) |
198 | continue; | 198 | continue; |
199 | 199 | ||
200 | cellmax = map[x, y] - map[coords[0], coords[1]]; | 200 | cellmax = map[x, y] - map[coords[0], coords[1]]; |
201 | if (cellmax > max) | 201 | if (cellmax > max) |
202 | { | 202 | { |
203 | max = cellmax; | 203 | max = cellmax; |
204 | loc = j; | 204 | loc = j; |
205 | } | 205 | } |
206 | } | 206 | } |
207 | } | 207 | } |
208 | 208 | ||
209 | double T = nConst / ((map.Width + map.Height) / 2); | 209 | double T = nConst / ((map.Width + map.Height) / 2); |
210 | // Apply results | 210 | // Apply results |
211 | if (0 < max && max <= T) | 211 | if (0 < max && max <= T) |
212 | { | 212 | { |
213 | int[] maxCoords = Neighbours(type, loc); | 213 | int[] maxCoords = Neighbours(type, loc); |
214 | double heightDelta = 0.5 * max * z * duration; | 214 | double heightDelta = 0.5 * max * z * duration; |
215 | map[x, y] -= heightDelta; | 215 | map[x, y] -= heightDelta; |
216 | map[x + maxCoords[0], y + maxCoords[1]] += heightDelta; | 216 | map[x + maxCoords[0], y + maxCoords[1]] += heightDelta; |
217 | } | 217 | } |
218 | } | 218 | } |
219 | } | 219 | } |
220 | } | 220 | } |
221 | } | 221 | } |
222 | 222 | ||
223 | #endregion | 223 | #endregion |
224 | } | 224 | } |
225 | } \ No newline at end of file | 225 | } \ No newline at end of file |
diff --git a/OpenSim/Region/Environment/Modules/World/Terrain/PaintBrushes/RaiseSphere.cs b/OpenSim/Region/Environment/Modules/World/Terrain/PaintBrushes/RaiseSphere.cs index cd5a22b..5d6f093 100644 --- a/OpenSim/Region/Environment/Modules/World/Terrain/PaintBrushes/RaiseSphere.cs +++ b/OpenSim/Region/Environment/Modules/World/Terrain/PaintBrushes/RaiseSphere.cs | |||
@@ -1,67 +1,67 @@ | |||
1 | /* | 1 | /* |
2 | * Copyright (c) Contributors, http://opensimulator.org/ | 2 | * Copyright (c) Contributors, http://opensimulator.org/ |
3 | * See CONTRIBUTORS.TXT for a full list of copyright holders. | 3 | * See CONTRIBUTORS.TXT for a full list of copyright holders. |
4 | * | 4 | * |
5 | * Redistribution and use in source and binary forms, with or without | 5 | * Redistribution and use in source and binary forms, with or without |
6 | * modification, are permitted provided that the following conditions are met: | 6 | * modification, are permitted provided that the following conditions are met: |
7 | * * Redistributions of source code must retain the above copyright | 7 | * * Redistributions of source code must retain the above copyright |
8 | * notice, this list of conditions and the following disclaimer. | 8 | * notice, this list of conditions and the following disclaimer. |
9 | * * Redistributions in binary form must reproduce the above copyright | 9 | * * Redistributions in binary form must reproduce the above copyright |
10 | * notice, this list of conditions and the following disclaimer in the | 10 | * notice, this list of conditions and the following disclaimer in the |
11 | * documentation and/or other materials provided with the distribution. | 11 | * documentation and/or other materials provided with the distribution. |
12 | * * Neither the name of the OpenSim Project nor the | 12 | * * Neither the name of the OpenSim Project nor the |
13 | * names of its contributors may be used to endorse or promote products | 13 | * names of its contributors may be used to endorse or promote products |
14 | * derived from this software without specific prior written permission. | 14 | * derived from this software without specific prior written permission. |
15 | * | 15 | * |
16 | * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY | 16 | * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY |
17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | 17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | 18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
19 | * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY | 19 | * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY |
20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | 20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES |
21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | 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 | 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 | 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 | 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. | 25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
26 | */ | 26 | */ |
27 | 27 | ||
28 | using System; | 28 | using System; |
29 | using OpenSim.Region.Environment.Interfaces; | 29 | using OpenSim.Region.Environment.Interfaces; |
30 | 30 | ||
31 | namespace OpenSim.Region.Environment.Modules.World.Terrain.PaintBrushes | 31 | namespace OpenSim.Region.Environment.Modules.World.Terrain.PaintBrushes |
32 | { | 32 | { |
33 | public class RaiseSphere : ITerrainPaintableEffect | 33 | public class RaiseSphere : ITerrainPaintableEffect |
34 | { | 34 | { |
35 | #region ITerrainPaintableEffect Members | 35 | #region ITerrainPaintableEffect Members |
36 | 36 | ||
37 | public void PaintEffect(ITerrainChannel map, double rx, double ry, double strength, double duration) | 37 | public void PaintEffect(ITerrainChannel map, double rx, double ry, double strength, double duration) |
38 | { | 38 | { |
39 | strength = TerrainUtil.MetersToSphericalStrength(strength); | 39 | strength = TerrainUtil.MetersToSphericalStrength(strength); |
40 | 40 | ||
41 | int x, y; | 41 | int x, y; |
42 | for (x = 0; x < map.Width; x++) | 42 | for (x = 0; x < map.Width; x++) |
43 | { | 43 | { |
44 | // Skip everything unlikely to be affected | 44 | // Skip everything unlikely to be affected |
45 | if (Math.Abs(x - rx) > strength * 1.1) | 45 | if (Math.Abs(x - rx) > strength * 1.1) |
46 | continue; | 46 | continue; |
47 | 47 | ||
48 | for (y = 0; y < map.Height; y++) | 48 | for (y = 0; y < map.Height; y++) |
49 | { | 49 | { |
50 | // Skip everything unlikely to be affected | 50 | // Skip everything unlikely to be affected |
51 | if (Math.Abs(y - ry) > strength * 1.1) | 51 | if (Math.Abs(y - ry) > strength * 1.1) |
52 | continue; | 52 | continue; |
53 | 53 | ||
54 | // Calculate a sphere and add it to the heighmap | 54 | // Calculate a sphere and add it to the heighmap |
55 | double z = strength; | 55 | double z = strength; |
56 | z *= z; | 56 | z *= z; |
57 | z -= ((x - rx) * (x - rx)) + ((y - ry) * (y - ry)); | 57 | z -= ((x - rx) * (x - rx)) + ((y - ry) * (y - ry)); |
58 | 58 | ||
59 | if (z > 0.0) | 59 | if (z > 0.0) |
60 | map[x, y] += z * duration; | 60 | map[x, y] += z * duration; |
61 | } | 61 | } |
62 | } | 62 | } |
63 | } | 63 | } |
64 | 64 | ||
65 | #endregion | 65 | #endregion |
66 | } | 66 | } |
67 | } \ No newline at end of file | 67 | } \ No newline at end of file |
diff --git a/OpenSim/Region/Environment/Modules/World/Terrain/PaintBrushes/RevertSphere.cs b/OpenSim/Region/Environment/Modules/World/Terrain/PaintBrushes/RevertSphere.cs index 5b92cb5..b47e041 100644 --- a/OpenSim/Region/Environment/Modules/World/Terrain/PaintBrushes/RevertSphere.cs +++ b/OpenSim/Region/Environment/Modules/World/Terrain/PaintBrushes/RevertSphere.cs | |||
@@ -1,82 +1,82 @@ | |||
1 | /* | 1 | /* |
2 | * Copyright (c) Contributors, http://opensimulator.org/ | 2 | * Copyright (c) Contributors, http://opensimulator.org/ |
3 | * See CONTRIBUTORS.TXT for a full list of copyright holders. | 3 | * See CONTRIBUTORS.TXT for a full list of copyright holders. |
4 | * | 4 | * |
5 | * Redistribution and use in source and binary forms, with or without | 5 | * Redistribution and use in source and binary forms, with or without |
6 | * modification, are permitted provided that the following conditions are met: | 6 | * modification, are permitted provided that the following conditions are met: |
7 | * * Redistributions of source code must retain the above copyright | 7 | * * Redistributions of source code must retain the above copyright |
8 | * notice, this list of conditions and the following disclaimer. | 8 | * notice, this list of conditions and the following disclaimer. |
9 | * * Redistributions in binary form must reproduce the above copyright | 9 | * * Redistributions in binary form must reproduce the above copyright |
10 | * notice, this list of conditions and the following disclaimer in the | 10 | * notice, this list of conditions and the following disclaimer in the |
11 | * documentation and/or other materials provided with the distribution. | 11 | * documentation and/or other materials provided with the distribution. |
12 | * * Neither the name of the OpenSim Project nor the | 12 | * * Neither the name of the OpenSim Project nor the |
13 | * names of its contributors may be used to endorse or promote products | 13 | * names of its contributors may be used to endorse or promote products |
14 | * derived from this software without specific prior written permission. | 14 | * derived from this software without specific prior written permission. |
15 | * | 15 | * |
16 | * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY | 16 | * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY |
17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | 17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | 18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
19 | * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY | 19 | * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY |
20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | 20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES |
21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | 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 | 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 | 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 | 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. | 25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
26 | */ | 26 | */ |
27 | 27 | ||
28 | using System; | 28 | using System; |
29 | using OpenSim.Region.Environment.Interfaces; | 29 | using OpenSim.Region.Environment.Interfaces; |
30 | 30 | ||
31 | namespace OpenSim.Region.Environment.Modules.World.Terrain.PaintBrushes | 31 | namespace OpenSim.Region.Environment.Modules.World.Terrain.PaintBrushes |
32 | { | 32 | { |
33 | public class RevertSphere : ITerrainPaintableEffect | 33 | public class RevertSphere : ITerrainPaintableEffect |
34 | { | 34 | { |
35 | private ITerrainChannel m_revertmap; | 35 | private ITerrainChannel m_revertmap; |
36 | 36 | ||
37 | public RevertSphere(ITerrainChannel revertmap) | 37 | public RevertSphere(ITerrainChannel revertmap) |
38 | { | 38 | { |
39 | m_revertmap = revertmap; | 39 | m_revertmap = revertmap; |
40 | } | 40 | } |
41 | 41 | ||
42 | #region ITerrainPaintableEffect Members | 42 | #region ITerrainPaintableEffect Members |
43 | 43 | ||
44 | public void PaintEffect(ITerrainChannel map, double rx, double ry, double strength, double duration) | 44 | public void PaintEffect(ITerrainChannel map, double rx, double ry, double strength, double duration) |
45 | { | 45 | { |
46 | strength = TerrainUtil.MetersToSphericalStrength(strength); | 46 | strength = TerrainUtil.MetersToSphericalStrength(strength); |
47 | 47 | ||
48 | if (duration > 1.0) | 48 | if (duration > 1.0) |
49 | duration = 1.0; | 49 | duration = 1.0; |
50 | if (duration < 0) | 50 | if (duration < 0) |
51 | return; | 51 | return; |
52 | 52 | ||
53 | int x, y; | 53 | int x, y; |
54 | for (x = 0; x < map.Width; x++) | 54 | for (x = 0; x < map.Width; x++) |
55 | { | 55 | { |
56 | // Skip everything unlikely to be affected | 56 | // Skip everything unlikely to be affected |
57 | if (Math.Abs(x - rx) > strength * 1.1) | 57 | if (Math.Abs(x - rx) > strength * 1.1) |
58 | continue; | 58 | continue; |
59 | 59 | ||
60 | for (y = 0; y < map.Height; y++) | 60 | for (y = 0; y < map.Height; y++) |
61 | { | 61 | { |
62 | // Skip everything unlikely to be affected | 62 | // Skip everything unlikely to be affected |
63 | if (Math.Abs(y - ry) > strength * 1.1) | 63 | if (Math.Abs(y - ry) > strength * 1.1) |
64 | continue; | 64 | continue; |
65 | 65 | ||
66 | // Calculate a sphere and add it to the heighmap | 66 | // Calculate a sphere and add it to the heighmap |
67 | double z = strength; | 67 | double z = strength; |
68 | z *= z; | 68 | z *= z; |
69 | z -= ((x - rx) * (x - rx)) + ((y - ry) * (y - ry)); | 69 | z -= ((x - rx) * (x - rx)) + ((y - ry) * (y - ry)); |
70 | 70 | ||
71 | if (z > 0.0) | 71 | if (z > 0.0) |
72 | { | 72 | { |
73 | z *= duration; | 73 | z *= duration; |
74 | map[x, y] += (map[x, y] * (1.0 - z)) + (m_revertmap[x, y] * z); | 74 | map[x, y] += (map[x, y] * (1.0 - z)) + (m_revertmap[x, y] * z); |
75 | } | 75 | } |
76 | } | 76 | } |
77 | } | 77 | } |
78 | } | 78 | } |
79 | 79 | ||
80 | #endregion | 80 | #endregion |
81 | } | 81 | } |
82 | } \ No newline at end of file | 82 | } \ No newline at end of file |
diff --git a/OpenSim/Region/Environment/Modules/World/Terrain/PaintBrushes/SmoothSphere.cs b/OpenSim/Region/Environment/Modules/World/Terrain/PaintBrushes/SmoothSphere.cs index 305a875..51d5f0e 100644 --- a/OpenSim/Region/Environment/Modules/World/Terrain/PaintBrushes/SmoothSphere.cs +++ b/OpenSim/Region/Environment/Modules/World/Terrain/PaintBrushes/SmoothSphere.cs | |||
@@ -1,93 +1,93 @@ | |||
1 | /* | 1 | /* |
2 | * Copyright (c) Contributors, http://opensimulator.org/ | 2 | * Copyright (c) Contributors, http://opensimulator.org/ |
3 | * See CONTRIBUTORS.TXT for a full list of copyright holders. | 3 | * See CONTRIBUTORS.TXT for a full list of copyright holders. |
4 | * | 4 | * |
5 | * Redistribution and use in source and binary forms, with or without | 5 | * Redistribution and use in source and binary forms, with or without |
6 | * modification, are permitted provided that the following conditions are met: | 6 | * modification, are permitted provided that the following conditions are met: |
7 | * * Redistributions of source code must retain the above copyright | 7 | * * Redistributions of source code must retain the above copyright |
8 | * notice, this list of conditions and the following disclaimer. | 8 | * notice, this list of conditions and the following disclaimer. |
9 | * * Redistributions in binary form must reproduce the above copyright | 9 | * * Redistributions in binary form must reproduce the above copyright |
10 | * notice, this list of conditions and the following disclaimer in the | 10 | * notice, this list of conditions and the following disclaimer in the |
11 | * documentation and/or other materials provided with the distribution. | 11 | * documentation and/or other materials provided with the distribution. |
12 | * * Neither the name of the OpenSim Project nor the | 12 | * * Neither the name of the OpenSim Project nor the |
13 | * names of its contributors may be used to endorse or promote products | 13 | * names of its contributors may be used to endorse or promote products |
14 | * derived from this software without specific prior written permission. | 14 | * derived from this software without specific prior written permission. |
15 | * | 15 | * |
16 | * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY | 16 | * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY |
17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | 17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | 18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
19 | * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY | 19 | * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY |
20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | 20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES |
21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | 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 | 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 | 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 | 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. | 25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
26 | */ | 26 | */ |
27 | 27 | ||
28 | using OpenSim.Region.Environment.Interfaces; | 28 | using OpenSim.Region.Environment.Interfaces; |
29 | 29 | ||
30 | namespace OpenSim.Region.Environment.Modules.World.Terrain.PaintBrushes | 30 | namespace OpenSim.Region.Environment.Modules.World.Terrain.PaintBrushes |
31 | { | 31 | { |
32 | public class SmoothSphere : ITerrainPaintableEffect | 32 | public class SmoothSphere : ITerrainPaintableEffect |
33 | { | 33 | { |
34 | #region ITerrainPaintableEffect Members | 34 | #region ITerrainPaintableEffect Members |
35 | 35 | ||
36 | public void PaintEffect(ITerrainChannel map, double rx, double ry, double strength, double duration) | 36 | public void PaintEffect(ITerrainChannel map, double rx, double ry, double strength, double duration) |
37 | { | 37 | { |
38 | strength = TerrainUtil.MetersToSphericalStrength(strength); | 38 | strength = TerrainUtil.MetersToSphericalStrength(strength); |
39 | 39 | ||
40 | int x, y; | 40 | int x, y; |
41 | double[,] tweak = new double[map.Width,map.Height]; | 41 | double[,] tweak = new double[map.Width,map.Height]; |
42 | 42 | ||
43 | double n, l; | 43 | double n, l; |
44 | double area = strength; | 44 | double area = strength; |
45 | double step = strength / 4.0; | 45 | double step = strength / 4.0; |
46 | 46 | ||
47 | // compute delta map | 47 | // compute delta map |
48 | for (x = 0; x < map.Width; x++) | 48 | for (x = 0; x < map.Width; x++) |
49 | { | 49 | { |
50 | for (y = 0; y < map.Height; y++) | 50 | for (y = 0; y < map.Height; y++) |
51 | { | 51 | { |
52 | double z = TerrainUtil.SphericalFactor(x, y, rx, ry, strength); | 52 | double z = TerrainUtil.SphericalFactor(x, y, rx, ry, strength); |
53 | 53 | ||
54 | if (z > 0) // add in non-zero amount | 54 | if (z > 0) // add in non-zero amount |
55 | { | 55 | { |
56 | double average = 0.0; | 56 | double average = 0.0; |
57 | int avgsteps = 0; | 57 | int avgsteps = 0; |
58 | 58 | ||
59 | for (n = 0.0 - area; n < area; n += step) | 59 | for (n = 0.0 - area; n < area; n += step) |
60 | { | 60 | { |
61 | for (l = 0.0 - area; l < area; l += step) | 61 | for (l = 0.0 - area; l < area; l += step) |
62 | { | 62 | { |
63 | avgsteps++; | 63 | avgsteps++; |
64 | average += TerrainUtil.GetBilinearInterpolate(x + n, y + l, map); | 64 | average += TerrainUtil.GetBilinearInterpolate(x + n, y + l, map); |
65 | } | 65 | } |
66 | } | 66 | } |
67 | tweak[x, y] = average / avgsteps; | 67 | tweak[x, y] = average / avgsteps; |
68 | } | 68 | } |
69 | } | 69 | } |
70 | } | 70 | } |
71 | // blend in map | 71 | // blend in map |
72 | for (x = 0; x < map.Width; x++) | 72 | for (x = 0; x < map.Width; x++) |
73 | { | 73 | { |
74 | for (y = 0; y < map.Height; y++) | 74 | for (y = 0; y < map.Height; y++) |
75 | { | 75 | { |
76 | double z = TerrainUtil.SphericalFactor(x, y, rx, ry, strength); | 76 | double z = TerrainUtil.SphericalFactor(x, y, rx, ry, strength); |
77 | 77 | ||
78 | if (z > 0) // add in non-zero amount | 78 | if (z > 0) // add in non-zero amount |
79 | { | 79 | { |
80 | double da = z; | 80 | double da = z; |
81 | double a = (map[x, y] - tweak[x, y]) * da; | 81 | double a = (map[x, y] - tweak[x, y]) * da; |
82 | double newz = map[x, y] - (a * duration); | 82 | double newz = map[x, y] - (a * duration); |
83 | 83 | ||
84 | if (newz > 0.0) | 84 | if (newz > 0.0) |
85 | map[x, y] = newz; | 85 | map[x, y] = newz; |
86 | } | 86 | } |
87 | } | 87 | } |
88 | } | 88 | } |
89 | } | 89 | } |
90 | 90 | ||
91 | #endregion | 91 | #endregion |
92 | } | 92 | } |
93 | } \ No newline at end of file | 93 | } \ No newline at end of file |
diff --git a/OpenSim/Region/Environment/Modules/World/Terrain/PaintBrushes/WeatherSphere.cs b/OpenSim/Region/Environment/Modules/World/Terrain/PaintBrushes/WeatherSphere.cs index 2d81054..b48beb8 100644 --- a/OpenSim/Region/Environment/Modules/World/Terrain/PaintBrushes/WeatherSphere.cs +++ b/OpenSim/Region/Environment/Modules/World/Terrain/PaintBrushes/WeatherSphere.cs | |||
@@ -1,207 +1,207 @@ | |||
1 | /* | 1 | /* |
2 | * Copyright (c) Contributors, http://opensimulator.org/ | 2 | * Copyright (c) Contributors, http://opensimulator.org/ |
3 | * See CONTRIBUTORS.TXT for a full list of copyright holders. | 3 | * See CONTRIBUTORS.TXT for a full list of copyright holders. |
4 | * | 4 | * |
5 | * Redistribution and use in source and binary forms, with or without | 5 | * Redistribution and use in source and binary forms, with or without |
6 | * modification, are permitted provided that the following conditions are met: | 6 | * modification, are permitted provided that the following conditions are met: |
7 | * * Redistributions of source code must retain the above copyright | 7 | * * Redistributions of source code must retain the above copyright |
8 | * notice, this list of conditions and the following disclaimer. | 8 | * notice, this list of conditions and the following disclaimer. |
9 | * * Redistributions in binary form must reproduce the above copyright | 9 | * * Redistributions in binary form must reproduce the above copyright |
10 | * notice, this list of conditions and the following disclaimer in the | 10 | * notice, this list of conditions and the following disclaimer in the |
11 | * documentation and/or other materials provided with the distribution. | 11 | * documentation and/or other materials provided with the distribution. |
12 | * * Neither the name of the OpenSim Project nor the | 12 | * * Neither the name of the OpenSim Project nor the |
13 | * names of its contributors may be used to endorse or promote products | 13 | * names of its contributors may be used to endorse or promote products |
14 | * derived from this software without specific prior written permission. | 14 | * derived from this software without specific prior written permission. |
15 | * | 15 | * |
16 | * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY | 16 | * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY |
17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | 17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | 18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
19 | * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY | 19 | * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY |
20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | 20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES |
21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | 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 | 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 | 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 | 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. | 25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
26 | */ | 26 | */ |
27 | 27 | ||
28 | using OpenSim.Region.Environment.Interfaces; | 28 | using OpenSim.Region.Environment.Interfaces; |
29 | 29 | ||
30 | namespace OpenSim.Region.Environment.Modules.World.Terrain.PaintBrushes | 30 | namespace OpenSim.Region.Environment.Modules.World.Terrain.PaintBrushes |
31 | { | 31 | { |
32 | /// <summary> | 32 | /// <summary> |
33 | /// Thermal Weathering Paint Brush | 33 | /// Thermal Weathering Paint Brush |
34 | /// </summary> | 34 | /// </summary> |
35 | public class WeatherSphere : ITerrainPaintableEffect | 35 | public class WeatherSphere : ITerrainPaintableEffect |
36 | { | 36 | { |
37 | private double talus = 0.2; // Number of meters max difference before stop eroding. Tweakage required. | 37 | private double talus = 0.2; // Number of meters max difference before stop eroding. Tweakage required. |
38 | private NeighbourSystem type = NeighbourSystem.Moore; // Parameter | 38 | private NeighbourSystem type = NeighbourSystem.Moore; // Parameter |
39 | 39 | ||
40 | #region Supporting Functions | 40 | #region Supporting Functions |
41 | 41 | ||
42 | private int[] Neighbours(NeighbourSystem type, int index) | 42 | private int[] Neighbours(NeighbourSystem type, int index) |
43 | { | 43 | { |
44 | int[] coord = new int[2]; | 44 | int[] coord = new int[2]; |
45 | 45 | ||
46 | index++; | 46 | index++; |
47 | 47 | ||
48 | switch (type) | 48 | switch (type) |
49 | { | 49 | { |
50 | case NeighbourSystem.Moore: | 50 | case NeighbourSystem.Moore: |
51 | switch (index) | 51 | switch (index) |
52 | { | 52 | { |
53 | case 1: | 53 | case 1: |
54 | coord[0] = -1; | 54 | coord[0] = -1; |
55 | coord[1] = -1; | 55 | coord[1] = -1; |
56 | break; | 56 | break; |
57 | 57 | ||
58 | case 2: | 58 | case 2: |
59 | coord[0] = -0; | 59 | coord[0] = -0; |
60 | coord[1] = -1; | 60 | coord[1] = -1; |
61 | break; | 61 | break; |
62 | 62 | ||
63 | case 3: | 63 | case 3: |
64 | coord[0] = +1; | 64 | coord[0] = +1; |
65 | coord[1] = -1; | 65 | coord[1] = -1; |
66 | break; | 66 | break; |
67 | 67 | ||
68 | case 4: | 68 | case 4: |
69 | coord[0] = -1; | 69 | coord[0] = -1; |
70 | coord[1] = -0; | 70 | coord[1] = -0; |
71 | break; | 71 | break; |
72 | 72 | ||
73 | case 5: | 73 | case 5: |
74 | coord[0] = -0; | 74 | coord[0] = -0; |
75 | coord[1] = -0; | 75 | coord[1] = -0; |
76 | break; | 76 | break; |
77 | 77 | ||
78 | case 6: | 78 | case 6: |
79 | coord[0] = +1; | 79 | coord[0] = +1; |
80 | coord[1] = -0; | 80 | coord[1] = -0; |
81 | break; | 81 | break; |
82 | 82 | ||
83 | case 7: | 83 | case 7: |
84 | coord[0] = -1; | 84 | coord[0] = -1; |
85 | coord[1] = +1; | 85 | coord[1] = +1; |
86 | break; | 86 | break; |
87 | 87 | ||
88 | case 8: | 88 | case 8: |
89 | coord[0] = -0; | 89 | coord[0] = -0; |
90 | coord[1] = +1; | 90 | coord[1] = +1; |
91 | break; | 91 | break; |
92 | 92 | ||
93 | case 9: | 93 | case 9: |
94 | coord[0] = +1; | 94 | coord[0] = +1; |
95 | coord[1] = +1; | 95 | coord[1] = +1; |
96 | break; | 96 | break; |
97 | 97 | ||
98 | default: | 98 | default: |
99 | break; | 99 | break; |
100 | } | 100 | } |
101 | break; | 101 | break; |
102 | 102 | ||
103 | case NeighbourSystem.VonNeumann: | 103 | case NeighbourSystem.VonNeumann: |
104 | switch (index) | 104 | switch (index) |
105 | { | 105 | { |
106 | case 1: | 106 | case 1: |
107 | coord[0] = 0; | 107 | coord[0] = 0; |
108 | coord[1] = -1; | 108 | coord[1] = -1; |
109 | break; | 109 | break; |
110 | 110 | ||
111 | case 2: | 111 | case 2: |
112 | coord[0] = -1; | 112 | coord[0] = -1; |
113 | coord[1] = 0; | 113 | coord[1] = 0; |
114 | break; | 114 | break; |
115 | 115 | ||
116 | case 3: | 116 | case 3: |
117 | coord[0] = +1; | 117 | coord[0] = +1; |
118 | coord[1] = 0; | 118 | coord[1] = 0; |
119 | break; | 119 | break; |
120 | 120 | ||
121 | case 4: | 121 | case 4: |
122 | coord[0] = 0; | 122 | coord[0] = 0; |
123 | coord[1] = +1; | 123 | coord[1] = +1; |
124 | break; | 124 | break; |
125 | 125 | ||
126 | case 5: | 126 | case 5: |
127 | coord[0] = -0; | 127 | coord[0] = -0; |
128 | coord[1] = -0; | 128 | coord[1] = -0; |
129 | break; | 129 | break; |
130 | 130 | ||
131 | default: | 131 | default: |
132 | break; | 132 | break; |
133 | } | 133 | } |
134 | break; | 134 | break; |
135 | } | 135 | } |
136 | 136 | ||
137 | return coord; | 137 | return coord; |
138 | } | 138 | } |
139 | 139 | ||
140 | private enum NeighbourSystem | 140 | private enum NeighbourSystem |
141 | { | 141 | { |
142 | Moore, | 142 | Moore, |
143 | VonNeumann | 143 | VonNeumann |
144 | } ; | 144 | } ; |
145 | 145 | ||
146 | #endregion | 146 | #endregion |
147 | 147 | ||
148 | #region ITerrainPaintableEffect Members | 148 | #region ITerrainPaintableEffect Members |
149 | 149 | ||
150 | public void PaintEffect(ITerrainChannel map, double rx, double ry, double strength, double duration) | 150 | public void PaintEffect(ITerrainChannel map, double rx, double ry, double strength, double duration) |
151 | { | 151 | { |
152 | strength = TerrainUtil.MetersToSphericalStrength(strength); | 152 | strength = TerrainUtil.MetersToSphericalStrength(strength); |
153 | 153 | ||
154 | int x, y; | 154 | int x, y; |
155 | 155 | ||
156 | for (x = 0; x < map.Width; x++) | 156 | for (x = 0; x < map.Width; x++) |
157 | { | 157 | { |
158 | for (y = 0; y < map.Height; y++) | 158 | for (y = 0; y < map.Height; y++) |
159 | { | 159 | { |
160 | double z = TerrainUtil.SphericalFactor(x, y, rx, ry, strength); | 160 | double z = TerrainUtil.SphericalFactor(x, y, rx, ry, strength); |
161 | 161 | ||
162 | if (z > 0) // add in non-zero amount | 162 | if (z > 0) // add in non-zero amount |
163 | { | 163 | { |
164 | int NEIGHBOUR_ME = 4; | 164 | int NEIGHBOUR_ME = 4; |
165 | 165 | ||
166 | int NEIGHBOUR_MAX = type == NeighbourSystem.Moore ? 9 : 5; | 166 | int NEIGHBOUR_MAX = type == NeighbourSystem.Moore ? 9 : 5; |
167 | 167 | ||
168 | for (int j = 0; j < NEIGHBOUR_MAX; j++) | 168 | for (int j = 0; j < NEIGHBOUR_MAX; j++) |
169 | { | 169 | { |
170 | if (j != NEIGHBOUR_ME) | 170 | if (j != NEIGHBOUR_ME) |
171 | { | 171 | { |
172 | int[] coords = Neighbours(type, j); | 172 | int[] coords = Neighbours(type, j); |
173 | 173 | ||
174 | coords[0] += x; | 174 | coords[0] += x; |
175 | coords[1] += y; | 175 | coords[1] += y; |
176 | 176 | ||
177 | if (coords[0] > map.Width - 1) | 177 | if (coords[0] > map.Width - 1) |
178 | continue; | 178 | continue; |
179 | if (coords[1] > map.Height - 1) | 179 | if (coords[1] > map.Height - 1) |
180 | continue; | 180 | continue; |
181 | if (coords[0] < 0) | 181 | if (coords[0] < 0) |
182 | continue; | 182 | continue; |
183 | if (coords[1] < 0) | 183 | if (coords[1] < 0) |
184 | continue; | 184 | continue; |
185 | 185 | ||
186 | double heightF = map[x, y]; | 186 | double heightF = map[x, y]; |
187 | double target = map[coords[0], coords[1]]; | 187 | double target = map[coords[0], coords[1]]; |
188 | 188 | ||
189 | if (target > heightF + talus) | 189 | if (target > heightF + talus) |
190 | { | 190 | { |
191 | double calc = duration * ((target - heightF) - talus) * z; | 191 | double calc = duration * ((target - heightF) - talus) * z; |
192 | heightF += calc; | 192 | heightF += calc; |
193 | target -= calc; | 193 | target -= calc; |
194 | } | 194 | } |
195 | 195 | ||
196 | map[x, y] = heightF; | 196 | map[x, y] = heightF; |
197 | map[coords[0], coords[1]] = target; | 197 | map[coords[0], coords[1]] = target; |
198 | } | 198 | } |
199 | } | 199 | } |
200 | } | 200 | } |
201 | } | 201 | } |
202 | } | 202 | } |
203 | } | 203 | } |
204 | 204 | ||
205 | #endregion | 205 | #endregion |
206 | } | 206 | } |
207 | } \ No newline at end of file | 207 | } \ No newline at end of file |