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/OlsenSphere.cs | |
parent | * Looks like I had the bamboo build right in the first place - it was just th... (diff) | |
download | opensim-SC-d51ce47b2d7635b17f3dd429158e8f59b78b83aa.zip opensim-SC-d51ce47b2d7635b17f3dd429158e8f59b78b83aa.tar.gz opensim-SC-d51ce47b2d7635b17f3dd429158e8f59b78b83aa.tar.bz2 opensim-SC-d51ce47b2d7635b17f3dd429158e8f59b78b83aa.tar.xz |
Update svn properties. Minor formatting cleanup.
Diffstat (limited to 'OpenSim/Region/Environment/Modules/World/Terrain/PaintBrushes/OlsenSphere.cs')
-rw-r--r-- | OpenSim/Region/Environment/Modules/World/Terrain/PaintBrushes/OlsenSphere.cs | 448 |
1 files changed, 224 insertions, 224 deletions
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 |