aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Manipulators/AerobicErosion.cs
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Manipulators/AerobicErosion.cs424
1 files changed, 212 insertions, 212 deletions
diff --git a/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Manipulators/AerobicErosion.cs b/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Manipulators/AerobicErosion.cs
index 589d360..5d2b4d4 100644
--- a/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Manipulators/AerobicErosion.cs
+++ b/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Manipulators/AerobicErosion.cs
@@ -1,213 +1,213 @@
1/* 1/*
2* Copyright (c) Contributors, http://www.openmetaverse.org/ 2* Copyright (c) Contributors, http://www.openmetaverse.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 28
29using System; 29using System;
30using System.Collections.Generic; 30using System.Collections.Generic;
31using System.Text; 31using System.Text;
32 32
33namespace libTerrain 33namespace libTerrain
34{ 34{
35 partial class Channel 35 partial class Channel
36 { 36 {
37 // Ideas for Aerobic erosion 37 // Ideas for Aerobic erosion
38 // 38 //
39 // Unlike thermal (gravity) and hydraulic (water suspension) 39 // Unlike thermal (gravity) and hydraulic (water suspension)
40 // aerobic erosion should displace mass by moving sediment 40 // aerobic erosion should displace mass by moving sediment
41 // in "hops". The length of the hop being dictated by the 41 // in "hops". The length of the hop being dictated by the
42 // presence of sharp cliffs and wind speed. 42 // presence of sharp cliffs and wind speed.
43 43
44 // The ability to pickup sediment is defined by the total 44 // The ability to pickup sediment is defined by the total
45 // surface area, such that: 45 // surface area, such that:
46 // 0 0 0 46 // 0 0 0
47 // 0 1 0 47 // 0 1 0
48 // 0 0 0 48 // 0 0 0
49 // Would be the best possible value for sediment to be 49 // Would be the best possible value for sediment to be
50 // picked up (total difference = 8) and flatter land 50 // picked up (total difference = 8) and flatter land
51 // will erode less quickly. 51 // will erode less quickly.
52 52
53 // Suspended particles assist the erosion process by hitting 53 // Suspended particles assist the erosion process by hitting
54 // the surface and chiselling additional particles off faster 54 // the surface and chiselling additional particles off faster
55 // than alone. 55 // than alone.
56 56
57 // Particles are deposited when one of two conditions is met 57 // Particles are deposited when one of two conditions is met
58 // First: 58 // First:
59 // When particles hit a wall - such that the 59 // When particles hit a wall - such that the
60 // wind direction points at a difference >= the 60 // wind direction points at a difference >= the
61 // deposition mininum talus. 61 // deposition mininum talus.
62 // Second: 62 // Second:
63 // When wind speed is lowered to below the minimum 63 // When wind speed is lowered to below the minimum
64 // required for transit. An idea for this is to 64 // required for transit. An idea for this is to
65 // use the navier-stokes algorithms for simulating 65 // use the navier-stokes algorithms for simulating
66 // pressure across the terrain. 66 // pressure across the terrain.
67 67
68 /// <summary> 68 /// <summary>
69 /// An experimental erosion algorithm developed by Adam. Moves sediment by factoring the surface area of each height point. 69 /// An experimental erosion algorithm developed by Adam. Moves sediment by factoring the surface area of each height point.
70 /// </summary> 70 /// </summary>
71 /// <param name="windspeed">0..1 The speed of the wind</param> 71 /// <param name="windspeed">0..1 The speed of the wind</param>
72 /// <param name="pickup_talus_minimum">The minimum angle at which rock is eroded 0..1 (recommended: <= 0.30)</param> 72 /// <param name="pickup_talus_minimum">The minimum angle at which rock is eroded 0..1 (recommended: <= 0.30)</param>
73 /// <param name="drop_talus_minimum">The minimum angle at which rock is dropped 0..1 (recommended: >= 0.00)</param> 73 /// <param name="drop_talus_minimum">The minimum angle at which rock is dropped 0..1 (recommended: >= 0.00)</param>
74 /// <param name="carry">The percentage of rock which can be picked up to pickup 0..1</param> 74 /// <param name="carry">The percentage of rock which can be picked up to pickup 0..1</param>
75 /// <param name="rounds">The number of erosion rounds (recommended: 25+)</param> 75 /// <param name="rounds">The number of erosion rounds (recommended: 25+)</param>
76 /// <param name="lowest">Drop sediment at the lowest point?</param> 76 /// <param name="lowest">Drop sediment at the lowest point?</param>
77 public void AerobicErosion(double windspeed, double pickupTalusMinimum, double dropTalusMinimum, double carry, int rounds, bool lowest, bool usingFluidDynamics) 77 public void AerobicErosion(double windspeed, double pickupTalusMinimum, double dropTalusMinimum, double carry, int rounds, bool lowest, bool usingFluidDynamics)
78 { 78 {
79 bool debugImages = false; 79 bool debugImages = false;
80 80
81 Channel wind = new Channel(w, h) ; 81 Channel wind = new Channel(w, h) ;
82 Channel sediment = new Channel(w, h); 82 Channel sediment = new Channel(w, h);
83 int x, y, i, j; 83 int x, y, i, j;
84 84
85 this.Normalise(); 85 this.Normalise();
86 86
87 wind = this.Copy(); 87 wind = this.Copy();
88 wind.Noise(); 88 wind.Noise();
89 89
90 if (debugImages) 90 if (debugImages)
91 wind.SaveImage("testimg/wind_start.png"); 91 wind.SaveImage("testimg/wind_start.png");
92 92
93 if (usingFluidDynamics) 93 if (usingFluidDynamics)
94 { 94 {
95 wind.navierStokes(20, 0.1, 0.0, 0.0); 95 wind.navierStokes(20, 0.1, 0.0, 0.0);
96 } 96 }
97 else 97 else
98 { 98 {
99 wind.Pertubation(30); 99 wind.Pertubation(30);
100 } 100 }
101 101
102 if (debugImages) 102 if (debugImages)
103 wind.SaveImage("testimg/wind_begin.png"); 103 wind.SaveImage("testimg/wind_begin.png");
104 104
105 for (i = 0; i < rounds; i++) 105 for (i = 0; i < rounds; i++)
106 { 106 {
107 // Convert some rocks to sand 107 // Convert some rocks to sand
108 for (x = 1; x < w - 1; x++) 108 for (x = 1; x < w - 1; x++)
109 { 109 {
110 for (y = 1; y < h - 1; y++) 110 for (y = 1; y < h - 1; y++)
111 { 111 {
112 double me = Get(x, y); 112 double me = Get(x, y);
113 double surfacearea = 0.3; // Everything will erode even if it's flat. Just slower. 113 double surfacearea = 0.3; // Everything will erode even if it's flat. Just slower.
114 114
115 for (j = 0; j < 9; j++) 115 for (j = 0; j < 9; j++)
116 { 116 {
117 int[] coords = Neighbours(NeighbourSystem.Moore, j); 117 int[] coords = Neighbours(NeighbourSystem.Moore, j);
118 double target = Get(x + coords[0], y + coords[1]); 118 double target = Get(x + coords[0], y + coords[1]);
119 119
120 surfacearea += Math.Abs(target - me); 120 surfacearea += Math.Abs(target - me);
121 } 121 }
122 122
123 double amount = surfacearea * wind.map[x, y] * carry; 123 double amount = surfacearea * wind.map[x, y] * carry;
124 124
125 if (amount < 0) 125 if (amount < 0)
126 amount = 0; 126 amount = 0;
127 127
128 if (surfacearea > pickupTalusMinimum) 128 if (surfacearea > pickupTalusMinimum)
129 { 129 {
130 Set(x, y, map[x, y] - amount); 130 Set(x, y, map[x, y] - amount);
131 sediment.map[x, y] += amount; 131 sediment.map[x, y] += amount;
132 } 132 }
133 } 133 }
134 } 134 }
135 135
136 if (usingFluidDynamics) 136 if (usingFluidDynamics)
137 { 137 {
138 sediment.navierStokes(7, 0.1, 0.0, 0.1); 138 sediment.navierStokes(7, 0.1, 0.0, 0.1);
139 139
140 Channel noiseChan = new Channel(w, h); 140 Channel noiseChan = new Channel(w, h);
141 noiseChan.Noise(); 141 noiseChan.Noise();
142 wind.Blend(noiseChan, 0.01); 142 wind.Blend(noiseChan, 0.01);
143 143
144 wind.navierStokes(10, 0.1, 0.01, 0.01); 144 wind.navierStokes(10, 0.1, 0.01, 0.01);
145 145
146 sediment.Distort(wind, windspeed); 146 sediment.Distort(wind, windspeed);
147 } 147 }
148 else 148 else
149 { 149 {
150 wind.Pertubation(15); // Can do better later 150 wind.Pertubation(15); // Can do better later
151 wind.seed++; 151 wind.seed++;
152 sediment.Pertubation(10); // Sediment is blown around a bit 152 sediment.Pertubation(10); // Sediment is blown around a bit
153 sediment.seed++; 153 sediment.seed++;
154 } 154 }
155 155
156 if (debugImages) 156 if (debugImages)
157 wind.SaveImage("testimg/wind_" + i.ToString() + ".png"); 157 wind.SaveImage("testimg/wind_" + i.ToString() + ".png");
158 158
159 // Convert some sand to rock 159 // Convert some sand to rock
160 for (x = 1; x < w - 1; x++) 160 for (x = 1; x < w - 1; x++)
161 { 161 {
162 for (y = 1; y < h - 1; y++) 162 for (y = 1; y < h - 1; y++)
163 { 163 {
164 double me = Get(x, y); 164 double me = Get(x, y);
165 double surfacearea = 0.01; // Flat land does not get deposition 165 double surfacearea = 0.01; // Flat land does not get deposition
166 double min = double.MaxValue; 166 double min = double.MaxValue;
167 int[] minside = new int[2]; 167 int[] minside = new int[2];
168 168
169 for (j = 0; j < 9; j++) 169 for (j = 0; j < 9; j++)
170 { 170 {
171 int[] coords = Neighbours(NeighbourSystem.Moore, j); 171 int[] coords = Neighbours(NeighbourSystem.Moore, j);
172 double target = Get(x + coords[0], y + coords[1]); 172 double target = Get(x + coords[0], y + coords[1]);
173 173
174 surfacearea += Math.Abs(target - me); 174 surfacearea += Math.Abs(target - me);
175 175
176 if (target < min && lowest) 176 if (target < min && lowest)
177 { 177 {
178 minside = (int[])coords.Clone(); 178 minside = (int[])coords.Clone();
179 min = target; 179 min = target;
180 } 180 }
181 } 181 }
182 182
183 double amount = surfacearea * (1.0 - wind.map[x, y]) * carry; 183 double amount = surfacearea * (1.0 - wind.map[x, y]) * carry;
184 184
185 if (amount < 0) 185 if (amount < 0)
186 amount = 0; 186 amount = 0;
187 187
188 if (surfacearea > dropTalusMinimum) 188 if (surfacearea > dropTalusMinimum)
189 { 189 {
190 Set(x + minside[0], y + minside[1], map[x + minside[0], y + minside[1]] + amount); 190 Set(x + minside[0], y + minside[1], map[x + minside[0], y + minside[1]] + amount);
191 sediment.map[x, y] -= amount; 191 sediment.map[x, y] -= amount;
192 } 192 }
193 } 193 }
194 } 194 }
195 195
196 if (debugImages) 196 if (debugImages)
197 sediment.SaveImage("testimg/sediment_" + i.ToString() + ".png"); 197 sediment.SaveImage("testimg/sediment_" + i.ToString() + ".png");
198 198
199 wind.Normalise(); 199 wind.Normalise();
200 wind *= windspeed; 200 wind *= windspeed;
201 201
202 this.Normalise(); 202 this.Normalise();
203 } 203 }
204 204
205 Channel myself = this; 205 Channel myself = this;
206 myself += sediment; 206 myself += sediment;
207 myself.Normalise(); 207 myself.Normalise();
208 208
209 if (debugImages) 209 if (debugImages)
210 this.SaveImage("testimg/output.png"); 210 this.SaveImage("testimg/output.png");
211 } 211 }
212 } 212 }
213} \ No newline at end of file 213} \ No newline at end of file