aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region
diff options
context:
space:
mode:
authorAdam Frisby2008-03-09 15:00:52 +0000
committerAdam Frisby2008-03-09 15:00:52 +0000
commitb46b152954ae87c6b7192aea416bfb0ab66837cf (patch)
tree6ae9a4f6b605fdf1b2bd6e6b9f738d32f2ae38c3 /OpenSim/Region
parent* Added a hack-ish routine to add the State column to the primshapes table if... (diff)
downloadopensim-SC_OLD-b46b152954ae87c6b7192aea416bfb0ab66837cf.zip
opensim-SC_OLD-b46b152954ae87c6b7192aea416bfb0ab66837cf.tar.gz
opensim-SC_OLD-b46b152954ae87c6b7192aea416bfb0ab66837cf.tar.bz2
opensim-SC_OLD-b46b152954ae87c6b7192aea416bfb0ab66837cf.tar.xz
* New terrainmodule paint brush "Olsen Erosion"
* Implements the Optimised Erosion routine defined by Jacob Olsen in the paper 'Procedural Terrain Generation' (http://www.oddlabs.com/download/terrain_generation.pdf) * Replaces the 'flatten' brush when 'newbrushes' is enabled.
Diffstat (limited to 'OpenSim/Region')
-rw-r--r--OpenSim/Region/Environment/Modules/Terrain/PaintBrushes/OlsenSphere.cs223
-rw-r--r--OpenSim/Region/Environment/Modules/Terrain/TerrainModule.cs1
2 files changed, 224 insertions, 0 deletions
diff --git a/OpenSim/Region/Environment/Modules/Terrain/PaintBrushes/OlsenSphere.cs b/OpenSim/Region/Environment/Modules/Terrain/PaintBrushes/OlsenSphere.cs
new file mode 100644
index 0000000..171b710
--- /dev/null
+++ b/OpenSim/Region/Environment/Modules/Terrain/PaintBrushes/OlsenSphere.cs
@@ -0,0 +1,223 @@
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;
29using System;
30
31namespace OpenSim.Region.Environment.Modules.Terrain.PaintBrushes
32{
33 /// <summary>
34 /// Speed-Optimised Hybrid Erosion Brush
35 ///
36 /// As per Jacob Olsen's Paper
37 /// http://www.oddlabs.com/download/terrain_generation.pdf
38 /// </summary>
39 public class OlsenSphere : ITerrainPaintableEffect
40 {
41 NeighbourSystem type = NeighbourSystem.Moore; // Parameter
42
43 double nConst = 256.0;
44
45 #region Supporting Functions
46 private enum NeighbourSystem
47 {
48 Moore,
49 VonNeumann
50 } ;
51
52 private int[] Neighbours(NeighbourSystem type, int index)
53 {
54 int[] coord = new int[2];
55
56 index++;
57
58 switch (type)
59 {
60 case NeighbourSystem.Moore:
61 switch (index)
62 {
63 case 1:
64 coord[0] = -1;
65 coord[1] = -1;
66 break;
67
68 case 2:
69 coord[0] = -0;
70 coord[1] = -1;
71 break;
72
73 case 3:
74 coord[0] = +1;
75 coord[1] = -1;
76 break;
77
78 case 4:
79 coord[0] = -1;
80 coord[1] = -0;
81 break;
82
83 case 5:
84 coord[0] = -0;
85 coord[1] = -0;
86 break;
87
88 case 6:
89 coord[0] = +1;
90 coord[1] = -0;
91 break;
92
93 case 7:
94 coord[0] = -1;
95 coord[1] = +1;
96 break;
97
98 case 8:
99 coord[0] = -0;
100 coord[1] = +1;
101 break;
102
103 case 9:
104 coord[0] = +1;
105 coord[1] = +1;
106 break;
107
108 default:
109 break;
110 }
111 break;
112
113 case NeighbourSystem.VonNeumann:
114 switch (index)
115 {
116 case 1:
117 coord[0] = 0;
118 coord[1] = -1;
119 break;
120
121 case 2:
122 coord[0] = -1;
123 coord[1] = 0;
124 break;
125
126 case 3:
127 coord[0] = +1;
128 coord[1] = 0;
129 break;
130
131 case 4:
132 coord[0] = 0;
133 coord[1] = +1;
134 break;
135
136 case 5:
137 coord[0] = -0;
138 coord[1] = -0;
139 break;
140
141 default:
142 break;
143 }
144 break;
145 }
146
147 return coord;
148 }
149
150 private double SphericalFactor(double x, double y, double rx, double ry, double size)
151 {
152 double z = size * size - ((x - rx) * (x - rx) + (y - ry) * (y - ry));
153 return z;
154 }
155
156 #endregion
157
158 #region ITerrainPaintableEffect Members
159
160 public void PaintEffect(ITerrainChannel map, double rx, double ry, double strength, double duration)
161 {
162 int x, y;
163
164 for (x = 0; x < map.Width; x++)
165 {
166 for (y = 0; y < map.Height; y++)
167 {
168 double z = SphericalFactor(x, y, rx, ry, strength);
169
170 if (z > 0) // add in non-zero amount
171 {
172 int NEIGHBOUR_ME = 4;
173 int NEIGHBOUR_MAX = type == NeighbourSystem.Moore ? 9 : 5;
174
175 double max = Double.MinValue;
176 int loc = 0;
177 double cellmax = 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 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);
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/Terrain/TerrainModule.cs b/OpenSim/Region/Environment/Modules/Terrain/TerrainModule.cs
index ca07443..ac50b2b 100644
--- a/OpenSim/Region/Environment/Modules/Terrain/TerrainModule.cs
+++ b/OpenSim/Region/Environment/Modules/Terrain/TerrainModule.cs
@@ -336,6 +336,7 @@ namespace OpenSim.Region.Environment.Modules.Terrain
336 if (Boolean.Parse(param)) 336 if (Boolean.Parse(param))
337 { 337 {
338 m_painteffects[StandardTerrainEffects.Revert] = new PaintBrushes.WeatherSphere(); 338 m_painteffects[StandardTerrainEffects.Revert] = new PaintBrushes.WeatherSphere();
339 m_painteffects[StandardTerrainEffects.Flatten] = new PaintBrushes.OlsenSphere();
339 } 340 }
340 else 341 else
341 { 342 {