diff options
author | Adam Frisby | 2007-07-21 22:25:42 +0000 |
---|---|---|
committer | Adam Frisby | 2007-07-21 22:25:42 +0000 |
commit | f84937367f7180140bd17444d507977f9b7e3d2e (patch) | |
tree | 944f2824669e42b5df3b6655bd09999c89b50376 /OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Manipulators/AerobicErosion.cs | |
parent | * Renamed terrain functions to match OpenSim naming styles. (diff) | |
download | opensim-SC_OLD-f84937367f7180140bd17444d507977f9b7e3d2e.zip opensim-SC_OLD-f84937367f7180140bd17444d507977f9b7e3d2e.tar.gz opensim-SC_OLD-f84937367f7180140bd17444d507977f9b7e3d2e.tar.bz2 opensim-SC_OLD-f84937367f7180140bd17444d507977f9b7e3d2e.tar.xz |
* Deleted libTerrain-BSD.dll
* Added libTerrain to BasicTerrain directly as a subfolder
Diffstat (limited to 'OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Manipulators/AerobicErosion.cs')
-rw-r--r-- | OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Manipulators/AerobicErosion.cs | 170 |
1 files changed, 170 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 | /* | ||
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 | // 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 | ||