aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/Environment/Modules
diff options
context:
space:
mode:
authorJeff Ames2008-03-09 15:08:03 +0000
committerJeff Ames2008-03-09 15:08:03 +0000
commit7981c4575058aef220cba059b0e77885ad933a90 (patch)
tree716dfacbf458d7a95a8fb8fa5d8d68ac4ebfee6f /OpenSim/Region/Environment/Modules
parent* New terrainmodule paint brush "Olsen Erosion" (diff)
downloadopensim-SC_OLD-7981c4575058aef220cba059b0e77885ad933a90.zip
opensim-SC_OLD-7981c4575058aef220cba059b0e77885ad933a90.tar.gz
opensim-SC_OLD-7981c4575058aef220cba059b0e77885ad933a90.tar.bz2
opensim-SC_OLD-7981c4575058aef220cba059b0e77885ad933a90.tar.xz
Update svn properties.
Diffstat (limited to 'OpenSim/Region/Environment/Modules')
-rw-r--r--OpenSim/Region/Environment/Modules/Terrain/PaintBrushes/OlsenSphere.cs446
1 files changed, 223 insertions, 223 deletions
diff --git a/OpenSim/Region/Environment/Modules/Terrain/PaintBrushes/OlsenSphere.cs b/OpenSim/Region/Environment/Modules/Terrain/PaintBrushes/OlsenSphere.cs
index 171b710..937309b 100644
--- a/OpenSim/Region/Environment/Modules/Terrain/PaintBrushes/OlsenSphere.cs
+++ b/OpenSim/Region/Environment/Modules/Terrain/PaintBrushes/OlsenSphere.cs
@@ -1,223 +1,223 @@
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*/
28using OpenSim.Region.Environment.Interfaces; 28using OpenSim.Region.Environment.Interfaces;
29using System; 29using System;
30 30
31namespace OpenSim.Region.Environment.Modules.Terrain.PaintBrushes 31namespace OpenSim.Region.Environment.Modules.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 NeighbourSystem type = NeighbourSystem.Moore; // Parameter 41 NeighbourSystem type = NeighbourSystem.Moore; // Parameter
42 42
43 double nConst = 256.0; 43 double nConst = 256.0;
44 44
45 #region Supporting Functions 45 #region Supporting Functions
46 private enum NeighbourSystem 46 private enum NeighbourSystem
47 { 47 {
48 Moore, 48 Moore,
49 VonNeumann 49 VonNeumann
50 } ; 50 } ;
51 51
52 private int[] Neighbours(NeighbourSystem type, int index) 52 private int[] Neighbours(NeighbourSystem type, int index)
53 { 53 {
54 int[] coord = new int[2]; 54 int[] coord = new int[2];
55 55
56 index++; 56 index++;
57 57
58 switch (type) 58 switch (type)
59 { 59 {
60 case NeighbourSystem.Moore: 60 case NeighbourSystem.Moore:
61 switch (index) 61 switch (index)
62 { 62 {
63 case 1: 63 case 1:
64 coord[0] = -1; 64 coord[0] = -1;
65 coord[1] = -1; 65 coord[1] = -1;
66 break; 66 break;
67 67
68 case 2: 68 case 2:
69 coord[0] = -0; 69 coord[0] = -0;
70 coord[1] = -1; 70 coord[1] = -1;
71 break; 71 break;
72 72
73 case 3: 73 case 3:
74 coord[0] = +1; 74 coord[0] = +1;
75 coord[1] = -1; 75 coord[1] = -1;
76 break; 76 break;
77 77
78 case 4: 78 case 4:
79 coord[0] = -1; 79 coord[0] = -1;
80 coord[1] = -0; 80 coord[1] = -0;
81 break; 81 break;
82 82
83 case 5: 83 case 5:
84 coord[0] = -0; 84 coord[0] = -0;
85 coord[1] = -0; 85 coord[1] = -0;
86 break; 86 break;
87 87
88 case 6: 88 case 6:
89 coord[0] = +1; 89 coord[0] = +1;
90 coord[1] = -0; 90 coord[1] = -0;
91 break; 91 break;
92 92
93 case 7: 93 case 7:
94 coord[0] = -1; 94 coord[0] = -1;
95 coord[1] = +1; 95 coord[1] = +1;
96 break; 96 break;
97 97
98 case 8: 98 case 8:
99 coord[0] = -0; 99 coord[0] = -0;
100 coord[1] = +1; 100 coord[1] = +1;
101 break; 101 break;
102 102
103 case 9: 103 case 9:
104 coord[0] = +1; 104 coord[0] = +1;
105 coord[1] = +1; 105 coord[1] = +1;
106 break; 106 break;
107 107
108 default: 108 default:
109 break; 109 break;
110 } 110 }
111 break; 111 break;
112 112
113 case NeighbourSystem.VonNeumann: 113 case NeighbourSystem.VonNeumann:
114 switch (index) 114 switch (index)
115 { 115 {
116 case 1: 116 case 1:
117 coord[0] = 0; 117 coord[0] = 0;
118 coord[1] = -1; 118 coord[1] = -1;
119 break; 119 break;
120 120
121 case 2: 121 case 2:
122 coord[0] = -1; 122 coord[0] = -1;
123 coord[1] = 0; 123 coord[1] = 0;
124 break; 124 break;
125 125
126 case 3: 126 case 3:
127 coord[0] = +1; 127 coord[0] = +1;
128 coord[1] = 0; 128 coord[1] = 0;
129 break; 129 break;
130 130
131 case 4: 131 case 4:
132 coord[0] = 0; 132 coord[0] = 0;
133 coord[1] = +1; 133 coord[1] = +1;
134 break; 134 break;
135 135
136 case 5: 136 case 5:
137 coord[0] = -0; 137 coord[0] = -0;
138 coord[1] = -0; 138 coord[1] = -0;
139 break; 139 break;
140 140
141 default: 141 default:
142 break; 142 break;
143 } 143 }
144 break; 144 break;
145 } 145 }
146 146
147 return coord; 147 return coord;
148 } 148 }
149 149
150 private double SphericalFactor(double x, double y, double rx, double ry, double size) 150 private double SphericalFactor(double x, double y, double rx, double ry, double size)
151 { 151 {
152 double z = size * size - ((x - rx) * (x - rx) + (y - ry) * (y - ry)); 152 double z = size * size - ((x - rx) * (x - rx) + (y - ry) * (y - ry));
153 return z; 153 return z;
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 int x, y; 162 int x, y;
163 163
164 for (x = 0; x < map.Width; x++) 164 for (x = 0; x < map.Width; x++)
165 { 165 {
166 for (y = 0; y < map.Height; y++) 166 for (y = 0; y < map.Height; y++)
167 { 167 {
168 double z = SphericalFactor(x, y, rx, ry, strength); 168 double z = SphericalFactor(x, y, rx, ry, strength);
169 169
170 if (z > 0) // add in non-zero amount 170 if (z > 0) // add in non-zero amount
171 { 171 {
172 int NEIGHBOUR_ME = 4; 172 int NEIGHBOUR_ME = 4;
173 int NEIGHBOUR_MAX = type == NeighbourSystem.Moore ? 9 : 5; 173 int NEIGHBOUR_MAX = type == NeighbourSystem.Moore ? 9 : 5;
174 174
175 double max = Double.MinValue; 175 double max = Double.MinValue;
176 int loc = 0; 176 int loc = 0;
177 double cellmax = 0; 177 double cellmax = 0;
178 178
179 179
180 for (int j = 0; j < NEIGHBOUR_MAX; j++) 180 for (int j = 0; j < NEIGHBOUR_MAX; j++)
181 { 181 {
182 if (j != NEIGHBOUR_ME) 182 if (j != NEIGHBOUR_ME)
183 { 183 {
184 int[] coords = Neighbours(type, j); 184 int[] coords = Neighbours(type, j);
185 185
186 coords[0] += x; 186 coords[0] += x;
187 coords[1] += y; 187 coords[1] += y;
188 188
189 if (coords[0] > map.Width - 1) 189 if (coords[0] > map.Width - 1)
190 continue; 190 continue;
191 if (coords[1] > map.Height - 1) 191 if (coords[1] > map.Height - 1)
192 continue; 192 continue;
193 if (coords[0] < 0) 193 if (coords[0] < 0)
194 continue; 194 continue;
195 if (coords[1] < 0) 195 if (coords[1] < 0)
196 continue; 196 continue;
197 197
198 cellmax = map[x, y] - map[coords[0], coords[1]]; 198 cellmax = map[x, y] - map[coords[0], coords[1]];
199 if (cellmax > max) 199 if (cellmax > max)
200 { 200 {
201 max = cellmax; 201 max = cellmax;
202 loc = j; 202 loc = j;
203 } 203 }
204 } 204 }
205 } 205 }
206 206
207 double T = nConst / ((map.Width + map.Height) / 2); 207 double T = nConst / ((map.Width + map.Height) / 2);
208 // Apply results 208 // Apply results
209 if (0 < max && max <= T) 209 if (0 < max && max <= T)
210 { 210 {
211 int[] maxCoords = Neighbours(type, loc); 211 int[] maxCoords = Neighbours(type, loc);
212 double heightDelta = 0.5 * max * z * duration; 212 double heightDelta = 0.5 * max * z * duration;
213 map[x, y] -= heightDelta; 213 map[x, y] -= heightDelta;
214 map[x + maxCoords[0], y + maxCoords[1]] += heightDelta; 214 map[x + maxCoords[0], y + maxCoords[1]] += heightDelta;
215 } 215 }
216 } 216 }
217 } 217 }
218 } 218 }
219 } 219 }
220 220
221 #endregion 221 #endregion
222 } 222 }
223} 223}