diff options
Diffstat (limited to '')
-rw-r--r-- | OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Manipulators/ThermalWeathering.cs | 113 |
1 files changed, 113 insertions, 0 deletions
diff --git a/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Manipulators/ThermalWeathering.cs b/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Manipulators/ThermalWeathering.cs new file mode 100644 index 0000000..0cae56d --- /dev/null +++ b/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Manipulators/ThermalWeathering.cs | |||
@@ -0,0 +1,113 @@ | |||
1 | /* | ||
2 | Redistribution and use in source and binary forms, with or without | ||
3 | modification, are permitted provided that the following conditions are | ||
4 | met: | ||
5 | |||
6 | * Redistributions of source code must retain the above copyright | ||
7 | notice, this list of conditions and the following disclaimer. | ||
8 | |||
9 | * Redistributions in binary form must reproduce the above | ||
10 | copyright notice, this list of conditions and the following | ||
11 | disclaimer in the documentation and/or other materials provided | ||
12 | with the distribution. | ||
13 | |||
14 | * Neither the name of libTerrain nor the names of | ||
15 | its contributors may be used to endorse or promote products | ||
16 | derived from this software without specific prior written | ||
17 | permission. | ||
18 | |||
19 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | ||
20 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | ||
21 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | ||
22 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | ||
23 | OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
24 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | ||
25 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | ||
26 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | ||
27 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
28 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | ||
29 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
30 | */ | ||
31 | |||
32 | using System; | ||
33 | using System.Collections.Generic; | ||
34 | using System.Text; | ||
35 | |||
36 | namespace libTerrain | ||
37 | { | ||
38 | partial class Channel | ||
39 | { | ||
40 | /// <summary> | ||
41 | /// A thermal weathering implementation based on Musgrave's original 1989 algorithm. This is Adam's custom implementation which may differ slightly from the original. | ||
42 | /// </summary> | ||
43 | /// <param name="talus">The rock angle (represented as a dy/dx ratio) at which point it will be succeptible to breakage</param> | ||
44 | /// <param name="rounds">The number of erosion rounds</param> | ||
45 | /// <param name="c">The amount of rock to carry each round</param> | ||
46 | public Channel thermalWeathering(double talus, int rounds, double c) | ||
47 | { | ||
48 | double[,] lastFrame; | ||
49 | double[,] thisFrame; | ||
50 | |||
51 | lastFrame = (double[,])map.Clone(); | ||
52 | thisFrame = (double[,])map.Clone(); | ||
53 | |||
54 | NEIGHBOURS type = NEIGHBOURS.NEIGHBOUR_MOORE; // Using moore neighbourhood (twice as computationally expensive) | ||
55 | int NEIGHBOUR_ME = 4; // I am always 4 in both systems. | ||
56 | |||
57 | int NEIGHBOUR_MAX = type == NEIGHBOURS.NEIGHBOUR_MOORE ? 9 : 5; | ||
58 | |||
59 | int frames = rounds; // Number of thermal erosion iterations to run | ||
60 | int i, j; | ||
61 | int x, y; | ||
62 | |||
63 | for (i = 0; i < frames; i++) | ||
64 | { | ||
65 | for (x = 0; x < w; x++) | ||
66 | { | ||
67 | for (y = 0; y < h; y++) | ||
68 | { | ||
69 | for (j = 0; j < NEIGHBOUR_MAX; j++) | ||
70 | { | ||
71 | if (j != NEIGHBOUR_ME) | ||
72 | { | ||
73 | int[] coords = neighbours(type, j); | ||
74 | |||
75 | coords[0] += x; | ||
76 | coords[1] += y; | ||
77 | |||
78 | if (coords[0] > w - 1) | ||
79 | coords[0] = w - 1; | ||
80 | if (coords[1] > h - 1) | ||
81 | coords[1] = h - 1; | ||
82 | if (coords[0] < 0) | ||
83 | coords[0] = 0; | ||
84 | if (coords[1] < 0) | ||
85 | coords[1] = 0; | ||
86 | |||
87 | double heightF = thisFrame[x, y]; | ||
88 | double target = thisFrame[coords[0], coords[1]]; | ||
89 | |||
90 | if (target > heightF + talus) | ||
91 | { | ||
92 | double calc = c * ((target - heightF) - talus); | ||
93 | heightF += calc; | ||
94 | target -= calc; | ||
95 | } | ||
96 | |||
97 | thisFrame[x, y] = heightF; | ||
98 | thisFrame[coords[0], coords[1]] = target; | ||
99 | |||
100 | } | ||
101 | } | ||
102 | } | ||
103 | } | ||
104 | lastFrame = (double[,])thisFrame.Clone(); | ||
105 | } | ||
106 | |||
107 | map = thisFrame; | ||
108 | |||
109 | normalise(); // Just to guaruntee a smooth 0..1 value | ||
110 | return this; | ||
111 | } | ||
112 | } | ||
113 | } | ||