aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Manipulators
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Manipulators')
-rw-r--r--OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Manipulators/AerobicErosion.cs170
-rw-r--r--OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Manipulators/HydraulicErosion.cs1
-rw-r--r--OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Manipulators/ThermalWeathering.cs113
3 files changed, 284 insertions, 0 deletions
diff --git a/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Manipulators/AerobicErosion.cs b/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Manipulators/AerobicErosion.cs
new file mode 100644
index 0000000..ebeabe9
--- /dev/null
+++ b/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Manipulators/AerobicErosion.cs
@@ -0,0 +1,170 @@
1/*
2Redistribution and use in source and binary forms, with or without
3modification, are permitted provided that the following conditions are
4met:
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
19THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
21LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
22A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
23OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
24SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
25LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30*/
31
32using System;
33using System.Collections.Generic;
34using System.Text;
35
36namespace libTerrain
37{
38 partial class Channel
39 {
40 // Ideas for Aerobic erosion
41 //
42 // Unlike thermal (gravity) and hydraulic (water suspension)
43 // aerobic erosion should displace mass by moving sediment
44 // in "hops". The length of the hop being dictated by the
45 // presence of sharp cliffs and wind speed.
46
47 // The ability to pickup sediment is defined by the total
48 // surface area, such that:
49 // 0 0 0
50 // 0 1 0
51 // 0 0 0
52 // Would be the best possible value for sediment to be
53 // picked up (total difference = 8) and flatter land
54 // will erode less quickly.
55
56 // Suspended particles assist the erosion process by hitting
57 // the surface and chiselling additional particles off faster
58 // than alone.
59
60 // Particles are deposited when one of two conditions is met
61 // First:
62 // When particles hit a wall - such that the
63 // wind direction points at a difference >= the
64 // deposition mininum talus.
65 // Second:
66 // When wind speed is lowered to below the minimum
67 // required for transit. An idea for this is to
68 // use the navier-stokes algorithms for simulating
69 // pressure across the terrain.
70
71 /// <summary>
72 /// An experimental erosion algorithm developed by Adam. Moves sediment by factoring the surface area of each height point.
73 /// </summary>
74 /// <param name="windspeed">0..1 The speed of the wind</param>
75 /// <param name="pickup_talus_minimum">The minimum angle at which rock is eroded 0..1 (recommended: <= 0.30)</param>
76 /// <param name="drop_talus_minimum">The minimum angle at which rock is dropped 0..1 (recommended: >= 0.00)</param>
77 /// <param name="carry">The percentage of rock which can be picked up to pickup 0..1</param>
78 /// <param name="rounds">The number of erosion rounds (recommended: 25+)</param>
79 /// <param name="lowest">Drop sediment at the lowest point?</param>
80 public void AerobicErosion(double windspeed, double pickup_talus_minimum, double drop_talus_minimum, double carry, int rounds, bool lowest)
81 {
82 Channel wind = new Channel(w, h) ;
83 Channel sediment = new Channel(w, h);
84 int x, y, i, j;
85
86 wind = this.copy();
87 wind.normalise(); // Cheap wind calculations
88 wind *= windspeed;
89 wind.pertubation(30); // Can do better later
90
91 for (i = 0; i < rounds; i++)
92 {
93 // Convert some rocks to sand
94 for (x = 1; x < w - 1; x++)
95 {
96 for (y = 1; y < h - 1; y++)
97 {
98 double me = get(x, y);
99 double surfacearea = 0.3; // Everything will erode even if it's flat. Just slower.
100
101 for (j = 0; j < 9; j++)
102 {
103 int[] coords = neighbours(NEIGHBOURS.NEIGHBOUR_MOORE, j);
104 double target = get(x + coords[0], y + coords[1]);
105
106 surfacearea += Math.Abs(target - me);
107 }
108
109 double amount = surfacearea * wind.map[x, y] * carry;
110
111 if (amount < 0)
112 amount = 0;
113
114 if (surfacearea > pickup_talus_minimum)
115 {
116 this.map[x, y] -= amount;
117 sediment.map[x, y] += amount;
118 }
119 }
120 }
121 sediment.pertubation(10); // Sediment is blown around a bit
122 sediment.seed++;
123 wind.pertubation(15); // So is the wind
124 wind.seed++;
125
126 // Convert some sand to rock
127 for (x = 1; x < w - 1; x++)
128 {
129 for (y = 1; y < h - 1; y++)
130 {
131 double me = get(x, y);
132 double surfacearea = 0.01; // Flat land does not get deposition
133 double min = double.MaxValue;
134 int[] minside = new int[2];
135
136 for (j = 0; j < 9; j++)
137 {
138 int[] coords = neighbours(NEIGHBOURS.NEIGHBOUR_MOORE, j);
139 double target = get(x + coords[0], y + coords[1]);
140
141 surfacearea += Math.Abs(target - me);
142
143 if (target < min && lowest)
144 {
145 minside = (int[])coords.Clone();
146 min = target;
147 }
148 }
149
150 double amount = surfacearea * (1.0 - wind.map[x, y]) * carry;
151
152 if (amount < 0)
153 amount = 0;
154
155 if (surfacearea > drop_talus_minimum)
156 {
157 this.map[x + minside[0], y + minside[1]] += amount;
158 sediment.map[x, y] -= amount;
159 }
160 }
161 }
162
163 }
164
165 Channel myself = this;
166 myself += sediment;
167 myself.normalise();
168 }
169 }
170} \ No newline at end of file
diff --git a/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Manipulators/HydraulicErosion.cs b/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Manipulators/HydraulicErosion.cs
new file mode 100644
index 0000000..0cec05d
--- /dev/null
+++ b/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Manipulators/HydraulicErosion.cs
@@ -0,0 +1 @@
/* Needs BSD rewrite */ \ No newline at end of file
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/*
2Redistribution and use in source and binary forms, with or without
3modification, are permitted provided that the following conditions are
4met:
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
19THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
21LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
22A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
23OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
24SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
25LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30*/
31
32using System;
33using System.Collections.Generic;
34using System.Text;
35
36namespace 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}