aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--OpenSim/Region/Environment/Modules/Terrain/PaintBrushes/WeatherSphere.cs243
1 files changed, 243 insertions, 0 deletions
diff --git a/OpenSim/Region/Environment/Modules/Terrain/PaintBrushes/WeatherSphere.cs b/OpenSim/Region/Environment/Modules/Terrain/PaintBrushes/WeatherSphere.cs
new file mode 100644
index 0000000..17207f8
--- /dev/null
+++ b/OpenSim/Region/Environment/Modules/Terrain/PaintBrushes/WeatherSphere.cs
@@ -0,0 +1,243 @@
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.Environment.Interfaces;
29
30namespace OpenSim.Region.Environment.Modules.Terrain.PaintBrushes
31{
32 /// <summary>
33 /// Thermal Weathering Paint Brush
34 /// </summary>
35 public class WeatherSphere : ITerrainPaintableEffect
36 {
37 NeighbourSystem type = NeighbourSystem.Moore; // Parameter
38 double talus = 0.2; // Number of meters max difference before stop eroding. Tweakage required.
39
40 #region Supporting Functions
41 private enum NeighbourSystem
42 {
43 Moore,
44 VonNeumann
45 } ;
46
47 private int[] Neighbours(NeighbourSystem type, int index)
48 {
49 int[] coord = new int[2];
50
51 index++;
52
53 switch (type)
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 double SphericalFactor(double x, double y, double rx, double ry, double size)
146 {
147 double z = size * size - ((x - rx) * (x - rx) + (y - ry) * (y - ry));
148 return z;
149 }
150
151 private double GetBilinearInterpolate(double x, double y, ITerrainChannel map)
152 {
153 int w = map.Width;
154 int h = map.Height;
155
156 if (x > w - 2.0)
157 x = w - 2.0;
158 if (y > h - 2.0)
159 y = h - 2.0;
160 if (x < 0.0)
161 x = 0.0;
162 if (y < 0.0)
163 y = 0.0;
164
165 int stepSize = 1;
166 double h00 = map[(int)x, (int)y];
167 double h10 = map[(int)x + stepSize, (int)y];
168 double h01 = map[(int)x, (int)y + stepSize];
169 double h11 = map[(int)x + stepSize, (int)y + stepSize];
170 double h1 = h00;
171 double h2 = h10;
172 double h3 = h01;
173 double h4 = h11;
174 double a00 = h1;
175 double a10 = h2 - h1;
176 double a01 = h3 - h1;
177 double a11 = h1 - h2 - h3 + h4;
178 double partialx = x - (int)x;
179 double partialz = y - (int)y;
180 double hi = a00 + (a10 * partialx) + (a01 * partialz) + (a11 * partialx * partialz);
181 return hi;
182 }
183
184 #endregion
185
186 #region ITerrainPaintableEffect Members
187
188 public void PaintEffect(ITerrainChannel map, double rx, double ry, double strength, double duration)
189 {
190 int x, y;
191
192 for (x = 0; x < map.Width; x++)
193 {
194 for (y = 0; y < map.Height; y++)
195 {
196 double z = SphericalFactor(x, y, rx, ry, strength);
197
198 if (z > 0) // add in non-zero amount
199 {
200 int NEIGHBOUR_ME = 4;
201
202 int NEIGHBOUR_MAX = type == NeighbourSystem.Moore ? 9 : 5;
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 coords[0] = map.Width - 1;
215 if (coords[1] > map.Height - 1)
216 coords[1] = map.Height - 1;
217 if (coords[0] < 0)
218 coords[0] = 0;
219 if (coords[1] < 0)
220 coords[1] = 0;
221
222 double heightF = map[x, y];
223 double target = map[coords[0], coords[1]];
224
225 if (target > heightF + talus)
226 {
227 double calc = duration * ((target - heightF) - talus) * z;
228 heightF += calc;
229 target -= calc;
230 }
231
232 map[x, y] = heightF;
233 map[coords[0], coords[1]] = target;
234 }
235 }
236 }
237 }
238 }
239 }
240
241 #endregion
242 }
243}