aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim
diff options
context:
space:
mode:
authorAdam Frisby2008-04-23 10:55:04 +0000
committerAdam Frisby2008-04-23 10:55:04 +0000
commit7c897043bab19bf748ac3078a05a74969c409fa7 (patch)
treef3f89972edbdebd9678025e754734f6aeb8b2952 /OpenSim
parent* Get rid of missing texture notification drop messages for now - obscuring t... (diff)
downloadopensim-SC_OLD-7c897043bab19bf748ac3078a05a74969c409fa7.zip
opensim-SC_OLD-7c897043bab19bf748ac3078a05a74969c409fa7.tar.gz
opensim-SC_OLD-7c897043bab19bf748ac3078a05a74969c409fa7.tar.bz2
opensim-SC_OLD-7c897043bab19bf748ac3078a05a74969c409fa7.tar.xz
* Removing old libTerrainBSD and associated Plugin & Project.
* Updated prebuild.xml accordingly.
Diffstat (limited to 'OpenSim')
-rw-r--r--OpenSim/Region/Terrain.BasicTerrain/Properties/AssemblyInfo.cs65
-rw-r--r--OpenSim/Region/Terrain.BasicTerrain/TerrainEngine.cs1451
-rw-r--r--OpenSim/Region/Terrain.BasicTerrain/TerrainFilter.cs125
-rw-r--r--OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Bitmap/Bitmap.cs85
-rw-r--r--OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Channel.cs59
-rw-r--r--OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Common.cs281
-rw-r--r--OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Editing/Flatten.cs141
-rw-r--r--OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Editing/Raise.cs191
-rw-r--r--OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/File.cs75
-rw-r--r--OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Generators/Cellular.cs28
-rw-r--r--OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Generators/Fracture.cs142
-rw-r--r--OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Generators/Gradient.cs60
-rw-r--r--OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Generators/HillPlanter.cs281
-rw-r--r--OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Generators/Midpoint.cs28
-rw-r--r--OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Generators/Mountain.cs28
-rw-r--r--OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Generators/Noise.cs53
-rw-r--r--OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Generators/Spiral.cs156
-rw-r--r--OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Generators/Voronoi.cs211
-rw-r--r--OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Generators/Worms.cs71
-rw-r--r--OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Grid.cs376
-rw-r--r--OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Manipulators/AerobicErosion.cs211
-rw-r--r--OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Manipulators/HydraulicErosion.cs144
-rw-r--r--OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Manipulators/NavierStokes.cs307
-rw-r--r--OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Manipulators/ThermalWeathering.cs107
-rw-r--r--OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Neighbours.cs136
-rw-r--r--OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Operators.cs239
-rw-r--r--OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Tools/Point2D.cs41
-rw-r--r--OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Tools/Tools.cs59
28 files changed, 0 insertions, 5151 deletions
diff --git a/OpenSim/Region/Terrain.BasicTerrain/Properties/AssemblyInfo.cs b/OpenSim/Region/Terrain.BasicTerrain/Properties/AssemblyInfo.cs
deleted file mode 100644
index ff5d999..0000000
--- a/OpenSim/Region/Terrain.BasicTerrain/Properties/AssemblyInfo.cs
+++ /dev/null
@@ -1,65 +0,0 @@
1/*
2 * Copyright (c) Contributors, http://opensimulator.org/
3 * See CONTRIBUTORS.TXT for a full list of copyright holders.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
7 * * Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * * Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 * * Neither the name of the OpenSim Project nor the
13 * names of its contributors may be used to endorse or promote products
14 * derived from this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
17 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19 * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
20 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
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
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
25 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */
27
28using System.Reflection;
29using System.Runtime.InteropServices;
30
31// General Information about an assembly is controlled through the following
32// set of attributes. Change these attribute values to modify the information
33// associated with an assembly.
34
35[assembly : AssemblyTitle("OpenSim.Region.Terrain.BasicTerrain")]
36[assembly : AssemblyDescription("")]
37[assembly : AssemblyConfiguration("")]
38[assembly : AssemblyCompany("")]
39[assembly : AssemblyProduct("OpenSim.Region.Terrain.BasicTerrain")]
40[assembly : AssemblyCopyright("Copyright (c) OpenSimulator.org Developers 2007-2008")]
41[assembly : AssemblyTrademark("")]
42[assembly : AssemblyCulture("")]
43
44// Setting ComVisible to false makes the types in this assembly not visible
45// to COM components. If you need to access a type in this assembly from
46// COM, set the ComVisible attribute to true on that type.
47
48[assembly : ComVisible(false)]
49
50// The following GUID is for the ID of the typelib if this project is exposed to COM
51
52[assembly : Guid("3263f5b5-0a41-4ed5-91a2-9baaaeecc849")]
53
54// Version information for an assembly consists of the following four values:
55//
56// Major Version
57// Minor Version
58// Build Number
59// Revision
60//
61// You can specify all the values or you can default the Revision and Build Numbers
62// by using the '*' as shown below:
63
64[assembly : AssemblyVersion("1.0.0.0")]
65[assembly : AssemblyFileVersion("1.0.0.0")]
diff --git a/OpenSim/Region/Terrain.BasicTerrain/TerrainEngine.cs b/OpenSim/Region/Terrain.BasicTerrain/TerrainEngine.cs
deleted file mode 100644
index 4ab535b..0000000
--- a/OpenSim/Region/Terrain.BasicTerrain/TerrainEngine.cs
+++ /dev/null
@@ -1,1451 +0,0 @@
1/*
2 * Copyright (c) Contributors, http://opensimulator.org/
3 * See CONTRIBUTORS.TXT for a full list of copyright holders.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
7 * * Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * * Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 * * Neither the name of the OpenSim Project nor the
13 * names of its contributors may be used to endorse or promote products
14 * derived from this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
17 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19 * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
20 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
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
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
25 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */
27
28using System;
29using System.Collections.Generic;
30using System.Drawing;
31using System.Drawing.Imaging;
32using System.Globalization;
33using System.IO;
34using System.Threading;
35using libTerrain;
36using OpenJPEGNet;
37using OpenSim.Framework;
38
39namespace OpenSim.Region.Terrain
40{
41 public class TerrainCommand
42 {
43 public virtual bool run(string[] cmdargs, ref string output)
44 {
45 return false;
46 }
47
48 public string args;
49 public string help;
50 }
51
52 public class TerrainEngine
53 {
54 public static Mutex fileIOLock = new Mutex();
55
56 /// <summary>
57 /// Plugin library for scripts
58 /// </summary>
59 public FilterHost customFilters = new FilterHost();
60
61 /// <summary>
62 /// A [normally] 256x256 heightmap
63 /// </summary>
64 public Channel heightmap;
65
66 /// <summary>
67 /// A copy of heightmap at the last save point (for reverting)
68 /// </summary>
69 public Channel revertmap;
70
71 /// <summary>
72 /// Water heightmap (needs clientside mods to work)
73 /// </summary>
74 public Channel watermap;
75
76 /// <summary>
77 /// Max amount the terrain can be raised from the revert parameters
78 /// </summary>
79 public double maxRaise = 500.0;
80
81 /// <summary>
82 /// Min amount the terrain can be lowered from the revert parameters
83 /// </summary>
84 public double minLower = 500.0;
85
86 /// <summary>
87 /// The last time the terrain was edited
88 /// </summary>
89 public DateTime lastEdit = DateTime.Now;
90
91
92 private int counter = 0;
93
94 /// <summary>
95 /// Whether or not the terrain has been modified since it was last saved and sent to the Physics engine.
96 /// Counts the number of modifications since the last save. (0 = Untainted)
97 /// </summary>
98 public int tainted;
99
100 private int w, h;
101
102 /// <summary>
103 /// Used to determine what offset to use when loading singular heightmaps across multiple sims
104 /// </summary>
105 private int offsetX;
106
107 private int offsetY;
108
109
110 /// <summary>
111 /// Generate a new TerrainEngine instance and creates a new heightmap
112 /// </summary>
113 public TerrainEngine(int X, int Y)
114 {
115 w = 256;
116 h = 256;
117 heightmap = new Channel(w, h);
118 revertmap = new Channel(w, h);
119 watermap = new Channel(w, h);
120 watermap.Fill(20);
121
122 offsetX = X;
123 offsetY = Y;
124
125 tainted++;
126 }
127
128 public bool IsTainted()
129 {
130 return (tainted != 0);
131 }
132
133 public bool IsUserStillEditing()
134 {
135 TimeSpan gap = DateTime.Now - lastEdit;
136
137 if (gap.TotalSeconds <= 4.0)
138 return true;
139
140 return false;
141 }
142
143 public bool IsTainted(int x, int y)
144 {
145 return (heightmap.diff[x/16, y/16] != 0);
146 }
147
148 public void ResetTaint()
149 {
150 tainted = 0;
151 heightmap.diff = new int[w/16,h/16];
152 }
153
154 //Testing to see if moving the TerraForming packet handling code into here works well
155 /// <summary>
156 /// Modifies terrain using the specified information
157 /// </summary>
158 /// <param name="height">The height at which the user started modifying the terrain</param>
159 /// <param name="seconds">The number of seconds the modify button was pressed</param>
160 /// <param name="brushsize">The size of the brush used</param>
161 /// <param name="action">The action to be performed</param>
162 /// <param name="north">Distance from the north border where the cursor is located</param>
163 /// <param name="west">Distance from the west border where the cursor is located</param>
164 public void ModifyTerrain(float height, float seconds, byte brushsize, byte action, float north, float west,
165 float south, float east,
166 IClientAPI remoteUser)
167 {
168 // Shiny.
169 double size = (double) (1 << brushsize);
170 //System.Console.WriteLine("SIZE:" + size.ToString() + " Seconds:" + seconds.ToString());
171 if (seconds == 1)
172 {
173 seconds = 0.0315f;
174 }
175 /* Okay, so here's the deal
176 * This has to handle both when a user draws on the terrain *and* when a user selects
177 * a selection of AABB on terrain and applies whatever routine the client requests
178 * There's something currently wrong with the brushsize --> size conversion.. however
179 * it's workable.. just unpredictable.
180 *
181 * North is always higher and East is always higher
182 * in the AABB representation
183 *
184 * Therefore what we're doing is looping from south to north and west to east
185 * and applying the associated algorithm with the brush.
186 *
187 * This works good on the fast ones, but things like smooth take 12 seconds a single click..
188 * for now, smooth won't be 'selectionated'
189 *
190 * If the user draws instead of selects, north will = south, and east will = west.
191 * if the user selects, then the selection is inclusive
192 * it'll always affect at least one point on the heightmap.
193 *
194 * that means we use the <= operator
195 *
196 * Again, libTerrain is yx instead of xy.. so, it's reflected in the function calls
197 *
198 */
199
200
201 switch (action)
202 {
203 case 0:
204 // flatten terrain
205 for (float x = south; x <= north; x++)
206 {
207 for (float y = west; y <= east; y++)
208 {
209 FlattenTerrain(y, x, size, (double) seconds/5.0);
210 lastEdit = DateTime.Now;
211 //remoteUser.SendLayerData((int)(x / 16), (int)(x / 16), GetHeights1D());
212
213 }
214 }
215 break;
216 case 1:
217 // raise terrain
218 for (float x = south; x <= north; x++)
219 {
220 for (float y = west; y <= east; y++)
221 {
222 RaiseTerrain(y, x, size, (double) seconds/5.0);
223 lastEdit = DateTime.Now;
224 //remoteUser.SendLayerData((int)(x / 16), (int)(x / 16), GetHeights1D());
225 }
226 }
227 break;
228 case 2:
229 //lower terrain
230 for (float x = south; x <= north; x++)
231 {
232 for (float y = west; y <= east; y++)
233 {
234 LowerTerrain(y, x, size, (double) seconds/5.0);
235 lastEdit = DateTime.Now;
236 //remoteUser.SendLayerData((int)(x / 16), (int)(x / 16), GetHeights1D());
237 }
238 }
239 break;
240 case 3:
241 // smooth terrain
242 //
243 // We're leaving this out of the parcel calculations for now
244 // because just a single one of these will stall your sim for
245 // 12 seconds. Looping over the parcel on this one is just stupid
246 //
247 //for (float x = south; x <= north; x++)
248 //{
249 //for (float y = west; y <= east; y++)
250 //{
251 //SmoothTerrain(y, x , size, (double)seconds / 5.0);
252 //}
253 //}
254 SmoothTerrain(west, north, size, (double) seconds/5.0);
255
256 break;
257 case 4:
258 // noise
259 for (float x = south; x <= north; x++)
260 {
261 for (float y = west; y <= east; y++)
262 {
263 NoiseTerrain(y, x, size, (double) seconds/5.0);
264 lastEdit = DateTime.Now;
265 }
266 }
267 break;
268 case 5:
269 // revert
270 for (float x = south; x <= north; x++)
271 {
272 for (float y = west; y <= east; y++)
273 {
274 RevertTerrain(y, x, size, (double) seconds/5.0);
275 lastEdit = DateTime.Now;
276 }
277 }
278 break;
279
280 // CLIENT EXTENSIONS GO HERE
281 case 128:
282 // erode-thermal
283 break;
284 case 129:
285 // erode-aerobic
286 break;
287 case 130:
288 // erode-hydraulic
289 break;
290 }
291
292 counter++;
293 if(counter==2)
294 {
295 counter=0;
296 for (int x = 0; x < 16; x++)
297 {
298 for (int y = 0; y < 16; y++)
299 {
300 if (IsTainted(x * 16, y * 16))
301 {
302 bool usingTerrainModule = true;
303
304 if (!usingTerrainModule)
305 {
306 remoteUser.SendLayerData(x, y, GetHeights1D());
307 }
308 }
309 }
310 }
311 }
312
313 lastEdit = DateTime.Now;
314
315 return;
316 }
317
318// TODO: unused
319// /// <summary>
320// /// Checks to make sure the terrain is within baked values +/- maxRaise/minLower
321// /// </summary>
322// private void SetTerrainWithinBounds()
323// {
324// int x, y;
325// for (x = 0; x < w; x++)
326// {
327// for (y = 0; y < h; y++)
328// {
329// if ((heightmap.Get(x, y) > revertmap.Get(x, y) + maxRaise))
330// {
331// heightmap.map[x, y] = revertmap.Get(x, y) + maxRaise;
332// }
333// if ((heightmap.Get(x, y) > revertmap.Get(x, y) - minLower))
334// {
335// heightmap.map[x, y] = revertmap.Get(x, y) - minLower;
336// }
337// }
338// }
339// }
340
341 /// <summary>
342 /// Converts the heightmap to a 65536 value 1D floating point array
343 /// </summary>
344 /// <returns>A float[65536] array containing the heightmap</returns>
345 public float[] GetHeights1D()
346 {
347 float[] heights = new float[w*h];
348 int i;
349
350 for (i = 0; i < w*h; i++)
351 {
352 heights[i] = (float) heightmap.map[i%w, i/w];
353 }
354
355 return heights;
356 }
357
358 /// <summary>
359 /// Converts the heightmap to a 256x256 value 2D floating point array.
360 /// </summary>
361 /// <returns>An array of 256,256 values containing the heightmap</returns>
362 public float[,] GetHeights2D()
363 {
364 float[,] heights = new float[w,h];
365 int x, y;
366 for (x = 0; x < w; x++)
367 {
368 for (y = 0; y < h; y++)
369 {
370 heights[x, y] = (float) heightmap.map[x, y];
371 }
372 }
373 return heights;
374 }
375
376 /// <summary>
377 /// Converts the heightmap to a 256x256 value 2D floating point array. Double precision version.
378 /// </summary>
379 /// <returns>An array of 256,256 values containing the heightmap</returns>
380 public double[,] GetHeights2DD()
381 {
382 return heightmap.map;
383 }
384
385 /// <summary>
386 /// Imports a 1D floating point array into the 2D heightmap array
387 /// </summary>
388 /// <param name="heights">The array to import (must have 65536 members)</param>
389 public void GetHeights1D(float[] heights)
390 {
391 int i;
392 for (i = 0; i < w*h; i++)
393 {
394 heightmap.map[i%w, i/w] = heights[i];
395 }
396
397 tainted++;
398 }
399
400 /// <summary>
401 /// Loads a 2D array of values into the heightmap
402 /// </summary>
403 /// <param name="heights">An array of 256,256 float values</param>
404 public void SetHeights2D(float[,] heights)
405 {
406 int x, y;
407 for (x = 0; x < w; x++)
408 {
409 for (y = 0; y < h; y++)
410 {
411 heightmap.Set(x, y, (double) heights[x, y]);
412 }
413 }
414 SaveRevertMap();
415 tainted++;
416 }
417
418 /// <summary>
419 /// Loads a 2D array of values into the heightmap (Double Precision Version)
420 /// </summary>
421 /// <param name="heights">An array of 256,256 float values</param>
422 public void SetHeights2D(double[,] heights)
423 {
424 int x, y;
425 for (x = 0; x < w; x++)
426 {
427 for (y = 0; y < h; y++)
428 {
429 heightmap.Set(x, y, heights[x, y]);
430 }
431 }
432 SaveRevertMap();
433 ResetTaint();
434 }
435
436 /// <summary>
437 /// Swaps the two heightmap buffers (the 'revert map' and the heightmap)
438 /// </summary>
439 public void SwapRevertMaps()
440 {
441 Channel backup = heightmap.Copy();
442 heightmap = revertmap;
443 revertmap = backup;
444 }
445
446 /// <summary>
447 /// Saves the current heightmap into the revertmap
448 /// </summary>
449 public void SaveRevertMap()
450 {
451 revertmap = heightmap.Copy();
452 }
453
454 /// <summary>
455 /// Processes a terrain-specific command
456 /// </summary>
457 /// <param name="args">Commandline arguments (space seperated)</param>
458 /// <param name="resultText">Reference that returns error or help text if returning false</param>
459 /// <returns>If the operation was successful (if not, the error is placed into resultText)</returns>
460 public bool RunTerrainCmd(string[] args, ref string resultText, string simName)
461 {
462 string command;
463 if (args.Length > 0)
464 {
465 command = args[0];
466 }
467 else
468 {
469 command = "help";
470 }
471
472 try
473 {
474 switch (command)
475 {
476 case "help":
477 resultText += "terrain regenerate - rebuilds the sims terrain using a default algorithm\n";
478 resultText +=
479 "terrain hills <type> <number of hills> <min height> <max height> <island t/f> <additive t/f> <noisy t/f>\n";
480 resultText += " type should be spheres, blocks, cones, or squared\n";
481 resultText +=
482 "terrain voronoi <points> <blocksize> - generates a worley fractal with X points per block";
483 resultText += "terrain seed <seed> - sets the random seed value to <seed>\n";
484 resultText +=
485 "terrain load <type> <filename> - loads a terrain from disk, type can be 'F32', 'F64', 'RAW' or 'IMG'\n";
486 resultText +=
487 "terrain save <type> <filename> - saves a terrain to disk, type can be 'F32', 'F64', 'PNG', 'RAW' or 'HIRAW'\n";
488 resultText +=
489 "terrain save grdmap <filename> <gradient map> - creates a PNG snapshot of the region using a named gradient map\n";
490 resultText +=
491 "terrain rescale <min> <max> - rescales a terrain to be between <min> and <max> meters high\n";
492 resultText += "terrain fill <val> - fills a terrain at the specified height\n";
493 resultText +=
494 "terrain erode aerobic <windspeed> <pickupmin> <dropmin> <carry> <rounds> <lowest t/f> <fluid dynamics t/f>\n";
495 resultText += "terrain erode thermal <talus> <rounds> <carry>\n";
496 resultText += "terrain erode hydraulic <rain> <evaporation> <solubility> <frequency> <rounds>\n";
497 resultText += "terrain multiply <val> - multiplies a terrain by <val>\n";
498 resultText += "terrain elevate <val> - elevates a terrain by <val>\n";
499 resultText += "terrain revert - reverts the terrain to the stored original\n";
500 resultText += "terrain bake - saves the current terrain into the revert map\n";
501 resultText +=
502 "terrain csfilter <filename.cs> - loads a new filter from the specified .cs file\n";
503 resultText +=
504 "terrain jsfilter <filename.js> - loads a new filter from the specified .js file\n";
505 foreach (KeyValuePair<string, ITerrainFilter> filter in customFilters.filters)
506 {
507 resultText += filter.Value.Help();
508 }
509
510 return false;
511
512 case "revert":
513 SwapRevertMaps();
514 SaveRevertMap();
515 break;
516
517 case "bake":
518 SaveRevertMap();
519 break;
520
521 case "seed":
522 SetSeed(Convert.ToInt32(args[1]));
523 break;
524
525 case "erode":
526 return ConsoleErosion(args, ref resultText);
527
528 case "voronoi":
529 double[] c = new double[2];
530 c[0] = -1;
531 c[1] = 1;
532 heightmap.VoronoiDiagram(Convert.ToInt32(args[1]), Convert.ToInt32(args[2]), c);
533 break;
534
535 case "hills":
536 return ConsoleHills(args, ref resultText);
537
538 case "regenerate":
539 SetDefaultTerrain();
540 break;
541
542 case "rescale":
543 SetRange(Convert.ToSingle(args[1]), Convert.ToSingle(args[2]));
544 break;
545
546 case "elevate":
547 Elevate(Convert.ToSingle(args[1]));
548 break;
549
550 case "fill":
551 heightmap.Fill(Convert.ToDouble(args[1]));
552 tainted++;
553 break;
554
555 case "clip":
556 heightmap.Clip(Convert.ToDouble(args[1]), Convert.ToDouble(args[2]));
557 tainted++;
558 break;
559
560 case "smooth":
561 heightmap.Smooth(Convert.ToDouble(args[1]));
562 tainted++;
563 break;
564
565 case "add":
566 heightmap += Convert.ToDouble(args[1]);
567 tainted++;
568 break;
569
570 case "multiply":
571 heightmap *= Convert.ToDouble(args[1]);
572 tainted++;
573 break;
574
575 case "load":
576 string filenameL = args[2].Replace("%name%", simName);
577 filenameL = filenameL.Replace("%x%", offsetX.ToString());
578 filenameL = filenameL.Replace("%y%", offsetY.ToString());
579
580 switch (args[1].ToLower())
581 {
582 case "f32":
583 LoadFromFileF32(filenameL);
584 break;
585
586 case "f64":
587 LoadFromFileF64(filenameL);
588 break;
589
590 case "raw":
591 LoadFromFileSLRAW(filenameL);
592 break;
593
594 case "img":
595 heightmap = heightmap.LoadImage(filenameL);
596 tainted++;
597 break;
598
599 default:
600 resultText = "Unknown image or data format";
601 return false;
602 }
603 break;
604
605 case "load-tile":
606 switch (args[1].ToLower())
607 {
608 case "f32":
609 LoadFromFileF32(args[2], Convert.ToInt32(args[3]), Convert.ToInt32(args[4]),
610 Convert.ToInt32(args[5]), Convert.ToInt32(args[6]));
611 break;
612 case "raw":
613 LoadFromFileSLRAW(args[2], Convert.ToInt32(args[3]), Convert.ToInt32(args[4]),
614 Convert.ToInt32(args[5]), Convert.ToInt32(args[6]));
615 break;
616 case "img":
617 LoadFromFileIMG(args[2], Convert.ToInt32(args[3]), Convert.ToInt32(args[4]),
618 Convert.ToInt32(args[5]), Convert.ToInt32(args[6]));
619 break;
620 default:
621 resultText = "Unknown or unsupported image or data format";
622 return false;
623 }
624 break;
625
626 case "save":
627 string filename = args[2].Replace("%name%", simName);
628 filename = filename.Replace("%x%", offsetX.ToString());
629 filename = filename.Replace("%y%", offsetY.ToString());
630
631 switch (args[1].ToLower())
632 {
633 case "f32":
634 WriteToFileF32(filename);
635 break;
636
637 case "f64":
638 WriteToFileF64(filename);
639 break;
640
641 case "grdmap":
642 if (args.Length >= 4)
643 WriteImage(filename, args[3]);
644 else
645 WriteImage(filename, "defaultstripe.png");
646 break;
647
648 case "png":
649 heightmap.SaveImage(filename);
650 break;
651
652 case "raw":
653 WriteToFileRAW(filename);
654 break;
655
656 case "hiraw":
657 WriteToFileHiRAW(filename);
658 break;
659
660 default:
661 resultText = "Unknown image or data format";
662 return false;
663 }
664 break;
665
666 case "csfilter":
667 customFilters.LoadFilterCSharp(args[1]);
668 break;
669 case "jsfilter":
670 customFilters.LoadFilterJScript(args[1]);
671 break;
672
673 default:
674 // Run any custom registered filters
675 if (customFilters.filters.ContainsKey(command))
676 {
677 customFilters.filters[command].Filter(heightmap, args);
678 break;
679 }
680 else
681 {
682 resultText = "Unknown terrain command";
683 return false;
684 }
685 }
686 return true;
687 }
688 catch (Exception e) // SEMI-LEGIT: Catching problems caused by user input or scripts
689 {
690 resultText = "Error running terrain command: " + e.ToString();
691 return false;
692 }
693 }
694
695 private bool ConsoleErosion(string[] args, ref string resultText)
696 {
697 double min = heightmap.FindMin();
698 double max = heightmap.FindMax();
699
700 switch (args[1].ToLower())
701 {
702 case "aerobic":
703 // WindSpeed, PickupMinimum,DropMinimum,Carry,Rounds,Lowest
704 heightmap.AerobicErosion(Convert.ToDouble(args[2]), Convert.ToDouble(args[3]),
705 Convert.ToDouble(args[4]), Convert.ToDouble(args[5]),
706 Convert.ToInt32(args[6]), Convert.ToBoolean(args[7]),
707 Convert.ToBoolean(args[8]));
708 break;
709 case "thermal":
710 heightmap.ThermalWeathering(Convert.ToDouble(args[2]), Convert.ToInt32(args[3]),
711 Convert.ToDouble(args[4]));
712 break;
713 case "hydraulic":
714 Channel rainMap = new Channel(w, h);
715 rainMap.Fill(Convert.ToDouble(args[2]));
716 heightmap.HydraulicErosion(rainMap, Convert.ToDouble(args[3]), Convert.ToDouble(args[4]),
717 Convert.ToInt32(args[5]), Convert.ToInt32(args[6]));
718 break;
719 default:
720 resultText = "Unknown erosion type";
721 return false;
722 }
723
724 heightmap.Normalise(min, max);
725
726 tainted++;
727 return true;
728 }
729
730 private bool ConsoleHills(string[] args, ref string resultText)
731 {
732 Random RandomClass = new Random();
733 SetSeed(RandomClass.Next());
734 int count;
735 double sizeMin;
736 double sizeRange;
737 bool island;
738 bool additive;
739 bool noisy;
740
741 if (args.GetLength(0) > 2)
742 {
743 int.TryParse(args[2].ToString(), out count);
744 double.TryParse(args[3].ToString(), NumberStyles.AllowDecimalPoint, Culture.NumberFormatInfo,
745 out sizeMin);
746 double.TryParse(args[4].ToString(), NumberStyles.AllowDecimalPoint, Culture.NumberFormatInfo,
747 out sizeRange);
748 bool.TryParse(args[5].ToString(), out island);
749 bool.TryParse(args[6].ToString(), out additive);
750 bool.TryParse(args[7].ToString(), out noisy);
751 }
752 else
753 {
754 count = 200;
755 sizeMin = 20;
756 sizeRange = 40;
757 island = true;
758 additive = true;
759 noisy = false;
760 }
761
762 switch (args[1].ToLower())
763 {
764 case "blocks":
765 heightmap.HillsBlocks(count, sizeMin, sizeRange, island, additive, noisy);
766 break;
767 case "cones":
768 heightmap.HillsCones(count, sizeMin, sizeRange, island, additive, noisy);
769 break;
770 case "spheres":
771 heightmap.HillsSpheres(count, sizeMin, sizeRange, island, additive, noisy);
772 break;
773 case "squared":
774 heightmap.HillsSquared(count, sizeMin, sizeRange, island, additive, noisy);
775 break;
776 default:
777 resultText = "Unknown hills type";
778 return false;
779 }
780 tainted++;
781 return true;
782 }
783
784 /// <summary>
785 /// Renormalises the array between min and max
786 /// </summary>
787 /// <param name="min">Minimum value of the new array</param>
788 /// <param name="max">Maximum value of the new array</param>
789 public void SetRange(float min, float max)
790 {
791 heightmap.Normalise((double) min, (double) max);
792 tainted++;
793 }
794
795 /// <summary>
796 /// Adds meters (positive or negative) to terrain height
797 /// </summary>
798 /// <param name="meters">Positive or negative value to add to new array</param>
799 public void Elevate(float meters)
800 {
801 heightmap.Elevate((double)meters);
802 tainted++;
803 }
804
805 /// <summary>
806 /// Loads a file consisting of 256x256 doubles and imports it as an array into the map.
807 /// </summary>
808 /// <remarks>TODO: Move this to libTerrain itself</remarks>
809 /// <param name="filename">The filename of the double array to import</param>
810 public void LoadFromFileF64(string filename)
811 {
812 FileInfo file = new FileInfo(filename);
813 FileStream s = file.Open(FileMode.Open, FileAccess.Read);
814 BinaryReader bs = new BinaryReader(s);
815 int x, y;
816 for (y = 0; y < h; y++)
817 {
818 for (x = 0; x < h; x++)
819 {
820 heightmap.Set(x, y, (double) bs.ReadSingle());
821 }
822 }
823
824 bs.Close();
825 s.Close();
826
827 tainted++;
828 }
829
830 /// <summary>
831 /// Loads a file consisting of 256x256 floats and imports it as an array into the map.
832 /// </summary>
833 /// <remarks>TODO: Move this to libTerrain itself</remarks>
834 /// <param name="filename">The filename of the float array to import</param>
835 public void LoadFromFileF32(string filename)
836 {
837 FileInfo file = new FileInfo(filename);
838 FileStream s = file.Open(FileMode.Open, FileAccess.Read);
839 BinaryReader bs = new BinaryReader(s);
840 int x, y;
841 for (y = 0; y < h; y++)
842 {
843 for (x = 0; x < w; x++)
844 {
845 heightmap.Set(x, y, (double) bs.ReadSingle());
846 }
847 }
848
849 bs.Close();
850 s.Close();
851
852 tainted++;
853 }
854
855 /// <summary>
856 /// Loads a section of a larger heightmap (F32)
857 /// </summary>
858 /// <param name="filename">File to load</param>
859 /// <param name="dimensionX">Size of the file</param>
860 /// <param name="dimensionY">Size of the file</param>
861 /// <param name="lowerboundX">Where do the region coords start for this terrain?</param>
862 /// <param name="lowerboundY">Where do the region coords start for this terrain?</param>
863 public void LoadFromFileF32(string filename, int dimensionX, int dimensionY, int lowerboundX, int lowerboundY)
864 {
865 fileIOLock.WaitOne();
866 try
867 {
868 int sectionToLoadX = ((offsetX - lowerboundX)*w);
869 int sectionToLoadY = ((offsetY - lowerboundY)*h);
870
871 double[,] tempMap = new double[dimensionX,dimensionY];
872
873 FileInfo file = new FileInfo(filename);
874 FileStream s = file.Open(FileMode.Open, FileAccess.Read);
875 BinaryReader bs = new BinaryReader(s);
876
877 int x, y;
878 for (x = 0; x < dimensionX; x++)
879 {
880 for (y = 0; y < dimensionY; y++)
881 {
882 tempMap[x, y] = (double) bs.ReadSingle();
883 }
884 }
885
886 for (y = 0; y < h; y++)
887 {
888 for (x = 0; x < w; x++)
889 {
890 heightmap.Set(x, y, tempMap[x + sectionToLoadX, y + sectionToLoadY]);
891 }
892 }
893
894 bs.Close();
895 s.Close();
896
897 tainted++;
898 }
899 finally
900 {
901 fileIOLock.ReleaseMutex();
902 }
903 }
904
905 /// <summary>
906 /// Loads a larger tiled image across a terrain
907 /// </summary>
908 /// <param name="filename">Filename to load from (any generic image format should work)</param>
909 /// <param name="dimensionX">The dimensions of the image</param>
910 /// <param name="dimensionY">The dimensions of the image</param>
911 /// <param name="lowerboundX">Where sim coords begin for this patch</param>
912 /// <param name="lowerboundY">Where sim coords begin for this patch</param>
913 public void LoadFromFileIMG(string filename, int dimensionX, int dimensionY, int lowerboundX, int lowerboundY)
914 {
915 int sectionToLoadX = ((offsetX - lowerboundX)*w);
916 int sectionToLoadY = ((offsetY - lowerboundY)*h);
917
918 double[,] tempMap = new double[dimensionX,dimensionY];
919
920 Bitmap lgrBmp = new Bitmap(filename);
921
922 int x, y;
923 for (x = 0; x < dimensionX; x++)
924 {
925 for (y = 0; y < dimensionY; y++)
926 {
927 tempMap[x, y] = (float) lgrBmp.GetPixel(x, y).GetBrightness();
928 }
929 }
930
931 for (y = 0; y < h; y++)
932 {
933 for (x = 0; x < w; x++)
934 {
935 heightmap.Set(x, y, tempMap[x + sectionToLoadX, y + sectionToLoadY]);
936 }
937 }
938
939 tainted++;
940 }
941
942 /// <summary>
943 /// Loads a file formatted in the SL .RAW Format used on the main grid
944 /// </summary>
945 /// <remarks>This file format stinks and is best avoided.</remarks>
946 /// <param name="filename">A path to the .RAW format</param>
947 public void LoadFromFileSLRAW(string filename)
948 {
949 FileInfo file = new FileInfo(filename);
950 FileStream s = file.Open(FileMode.Open, FileAccess.Read);
951 BinaryReader bs = new BinaryReader(s);
952 int x, y;
953 for (y = 0; y < h; y++)
954 {
955 for (x = 0; x < w; x++)
956 {
957 heightmap.Set(x, y, (double) bs.ReadByte()*((double) bs.ReadByte()/127.0));
958 bs.ReadBytes(11); // Advance the stream to next bytes.
959 }
960 }
961
962 bs.Close();
963 s.Close();
964
965 tainted++;
966 }
967
968 /// <summary>
969 /// Loads a section of a larger heightmap (RAW)
970 /// </summary>
971 /// <param name="filename">File to load</param>
972 /// <param name="dimensionX">Size of the file</param>
973 /// <param name="dimensionY">Size of the file</param>
974 /// <param name="lowerboundX">Where do the region coords start for this terrain?</param>
975 /// <param name="lowerboundY">Where do the region coords start for this terrain?</param>
976 public void LoadFromFileSLRAW(string filename, int dimensionX, int dimensionY, int lowerboundX, int lowerboundY)
977 {
978 // TODO: Mutex fails to release readlock on folder! --> only one file can be loaded into sim
979 //fileIOLock.WaitOne();
980 //try
981 //{
982 int sectionToLoadX = ((offsetX - lowerboundX)*w);
983 int sectionToLoadY = ((offsetY - lowerboundY)*h);
984
985 double[,] tempMap = new double[dimensionX,dimensionY];
986
987 FileInfo file = new FileInfo(filename);
988 FileStream s = file.Open(FileMode.Open, FileAccess.Read);
989 BinaryReader bs = new BinaryReader(s);
990
991 int x, y;
992 for (x = 0; x < dimensionX; x++)
993 {
994 for (y = 0; y < dimensionY; y++)
995 {
996 tempMap[x, y] = (double) bs.ReadByte()*((double) bs.ReadByte()/127.0);
997 bs.ReadBytes(11); // Advance the stream to next bytes.
998 }
999 }
1000
1001 for (y = 0; y < h; y++)
1002 {
1003 for (x = 0; x < w; x++)
1004 {
1005 heightmap.Set(x, y, tempMap[x + sectionToLoadX, y + sectionToLoadY]);
1006 }
1007 }
1008
1009 bs.Close();
1010 s.Close();
1011
1012 tainted++;
1013 //}
1014 //finally
1015 //{
1016 // fileIOLock.ReleaseMutex();
1017 //}
1018 }
1019
1020 /// <summary>
1021 /// Writes the current terrain heightmap to disk, in the format of a 65536 entry double[] array.
1022 /// </summary>
1023 /// <param name="filename">The desired output filename</param>
1024 public void WriteToFileF64(string filename)
1025 {
1026 FileInfo file = new FileInfo(filename);
1027 FileStream s = file.Open(FileMode.CreateNew, FileAccess.Write);
1028 BinaryWriter bs = new BinaryWriter(s);
1029
1030 int x, y;
1031 for (y = 0; y < h; y++)
1032 {
1033 for (x = 0; x < w; x++)
1034 {
1035 bs.Write(heightmap.Get(x, y));
1036 }
1037 }
1038
1039 bs.Close();
1040 s.Close();
1041 }
1042
1043 /// <summary>
1044 /// Writes the current terrain heightmap to disk, in the format of a 65536 entry float[] array
1045 /// </summary>
1046 /// <param name="filename">The desired output filename</param>
1047 public void WriteToFileF32(string filename)
1048 {
1049 FileInfo file = new FileInfo(filename);
1050 FileStream s = file.Open(FileMode.CreateNew, FileAccess.Write);
1051 BinaryWriter bs = new BinaryWriter(s);
1052
1053 int x, y;
1054 for (y = 0; y < h; y++)
1055 {
1056 for (x = 0; x < w; x++)
1057 {
1058 bs.Write((float) heightmap.Get(x, y));
1059 }
1060 }
1061
1062 bs.Close();
1063 s.Close();
1064 }
1065
1066 /// <summary>
1067 /// A very fast LL-RAW file output mechanism - lower precision mechanism but wont take 5 minutes to run either.
1068 /// (is also editable in an image application)
1069 /// </summary>
1070 /// <param name="filename">Filename to write to</param>
1071 public void WriteToFileRAW(string filename)
1072 {
1073 FileInfo file = new FileInfo(filename);
1074 FileStream s = file.Open(FileMode.CreateNew, FileAccess.Write);
1075 BinaryWriter binStream = new BinaryWriter(s);
1076
1077 int x, y;
1078
1079 // Used for the 'green' channel.
1080 byte avgMultiplier = (byte) heightmap.Avg();
1081 byte backupMultiplier = (byte) revertmap.Avg();
1082
1083 // Limit the multiplier so it can represent points >64m.
1084 if (avgMultiplier > 196)
1085 avgMultiplier = 196;
1086 if (backupMultiplier > 196)
1087 backupMultiplier = 196;
1088 // Make sure it's at least one to prevent a div by zero
1089 if (avgMultiplier < 1)
1090 avgMultiplier = 1;
1091 if (backupMultiplier < 1)
1092 backupMultiplier = 1;
1093
1094 for (y = 0; y < h; y++)
1095 {
1096 for (x = 0; x < h; x++)
1097 {
1098 byte red = (byte) (heightmap.Get(x, y)/((double) avgMultiplier/128.0));
1099 byte green = avgMultiplier;
1100 byte blue = (byte) watermap.Get(x, y);
1101 byte alpha1 = 0; // Land Parcels
1102 byte alpha2 = 0; // For Sale Land
1103 byte alpha3 = 0; // Public Edit Object
1104 byte alpha4 = 0; // Public Edit Land
1105 byte alpha5 = 255; // Safe Land
1106 byte alpha6 = 255; // Flying Allowed
1107 byte alpha7 = 255; // Create Landmark
1108 byte alpha8 = 255; // Outside Scripts
1109 byte alpha9 = (byte) (revertmap.Get(x, y)/((double) backupMultiplier/128.0));
1110 byte alpha10 = backupMultiplier;
1111
1112 binStream.Write(red);
1113 binStream.Write(green);
1114 binStream.Write(blue);
1115 binStream.Write(alpha1);
1116 binStream.Write(alpha2);
1117 binStream.Write(alpha3);
1118 binStream.Write(alpha4);
1119 binStream.Write(alpha5);
1120 binStream.Write(alpha6);
1121 binStream.Write(alpha7);
1122 binStream.Write(alpha8);
1123 binStream.Write(alpha9);
1124 binStream.Write(alpha10);
1125 }
1126 }
1127 binStream.Close();
1128 s.Close();
1129 }
1130
1131 /// <summary>
1132 /// Outputs to a LL compatible RAW in the most efficient manner possible
1133 /// </summary>
1134 /// <remarks>Does not calculate the revert map</remarks>
1135 /// <param name="filename">The filename to output to</param>
1136 public void WriteToFileHiRAW(string filename)
1137 {
1138 FileInfo file = new FileInfo(filename);
1139 FileStream s = file.Open(FileMode.CreateNew, FileAccess.Write);
1140 BinaryWriter binStream = new BinaryWriter(s);
1141
1142 // Generate a smegging big lookup table to speed the operation up (it needs it)
1143 double[] lookupHeightTable = new double[65536];
1144 int i, j, x, y;
1145 for (i = 0; i < 256; i++)
1146 {
1147 for (j = 0; j < 256; j++)
1148 {
1149 lookupHeightTable[i + (j*256)] = ((double) i*((double) j/127.0));
1150 }
1151 }
1152
1153 // Output the calculated raw
1154 for (y = 0; y < h; y++)
1155 {
1156 for (x = 0; x < w; x++)
1157 {
1158 double t = heightmap.Get(x, y);
1159 double min = double.MaxValue;
1160 int index = 0;
1161
1162 for (i = 0; i < 65536; i++)
1163 {
1164 if (Math.Abs(t - lookupHeightTable[i]) < min)
1165 {
1166 min = Math.Abs(t - lookupHeightTable[i]);
1167 index = i;
1168 }
1169 }
1170
1171 byte red = (byte) (index & 0xFF);
1172 byte green = (byte) ((index >> 8) & 0xFF);
1173 byte blue = (byte) watermap.Get(x, y);
1174 byte alpha1 = 0; // Land Parcels
1175 byte alpha2 = 0; // For Sale Land
1176 byte alpha3 = 0; // Public Edit Object
1177 byte alpha4 = 0; // Public Edit Land
1178 byte alpha5 = 255; // Safe Land
1179 byte alpha6 = 255; // Flying Allowed
1180 byte alpha7 = 255; // Create Landmark
1181 byte alpha8 = 255; // Outside Scripts
1182 byte alpha9 = red;
1183 byte alpha10 = green;
1184
1185 binStream.Write(red);
1186 binStream.Write(green);
1187 binStream.Write(blue);
1188 binStream.Write(alpha1);
1189 binStream.Write(alpha2);
1190 binStream.Write(alpha3);
1191 binStream.Write(alpha4);
1192 binStream.Write(alpha5);
1193 binStream.Write(alpha6);
1194 binStream.Write(alpha7);
1195 binStream.Write(alpha8);
1196 binStream.Write(alpha9);
1197 binStream.Write(alpha10);
1198 }
1199 }
1200
1201 binStream.Close();
1202 s.Close();
1203 }
1204
1205 /// <summary>
1206 /// Sets the random seed to be used by procedural functions which involve random numbers.
1207 /// </summary>
1208 /// <param name="val">The desired seed</param>
1209 public void SetSeed(int val)
1210 {
1211 heightmap.seed = val;
1212 }
1213
1214 /// <summary>
1215 /// Sets a particular heightmap point to a specified value
1216 /// </summary>
1217 /// <param name="x">X Coordinate</param>
1218 /// <param name="y">Y Coordinate</param>
1219 /// <param name="val">Value</param>
1220 public void Set(int x, int y, double val)
1221 {
1222 lock (heightmap)
1223 {
1224 heightmap.Set(x, y, val);
1225 }
1226 tainted++;
1227 }
1228
1229 /// <summary>
1230 /// Raises land in a sphere around the specified coordinates
1231 /// </summary>
1232 /// <param name="rx">Center of the sphere on the X axis</param>
1233 /// <param name="ry">Center of the sphere on the Y axis</param>
1234 /// <param name="size">The radius of the sphere</param>
1235 /// <param name="amount">Scale the height of the sphere by this amount (recommended 0..2)</param>
1236 public void RaiseTerrain(double rx, double ry, double size, double amount)
1237 {
1238 lock (heightmap)
1239 {
1240 heightmap.Raise(rx, ry, size, amount);
1241 }
1242
1243 tainted++;
1244 }
1245
1246 /// <summary>
1247 /// Lowers the land in a sphere around the specified coordinates
1248 /// </summary>
1249 /// <param name="rx">The center of the sphere at the X axis</param>
1250 /// <param name="ry">The center of the sphere at the Y axis</param>
1251 /// <param name="size">The radius of the sphere in meters</param>
1252 /// <param name="amount">Scale the height of the sphere by this amount (recommended 0..2)</param>
1253 public void LowerTerrain(double rx, double ry, double size, double amount)
1254 {
1255 lock (heightmap)
1256 {
1257 heightmap.Lower(rx, ry, size, amount);
1258 }
1259
1260 tainted++;
1261 }
1262
1263 /// <summary>
1264 /// Flattens the land under the brush of specified coordinates (spherical mask)
1265 /// </summary>
1266 /// <param name="rx">Center of sphere</param>
1267 /// <param name="ry">Center of sphere</param>
1268 /// <param name="size">Radius of the sphere</param>
1269 /// <param name="amount">Thickness of the mask (0..2 recommended)</param>
1270 public void FlattenTerrain(double rx, double ry, double size, double amount)
1271 {
1272 lock (heightmap)
1273 {
1274 heightmap.Flatten(rx, ry, size, amount);
1275 }
1276
1277 tainted++;
1278 }
1279
1280 /// <summary>
1281 /// Creates noise within the specified bounds
1282 /// </summary>
1283 /// <param name="rx">Center of the bounding sphere</param>
1284 /// <param name="ry">Center of the bounding sphere</param>
1285 /// <param name="size">The radius of the sphere</param>
1286 /// <param name="amount">Strength of the mask (0..2) recommended</param>
1287 public void NoiseTerrain(double rx, double ry, double size, double amount)
1288 {
1289 lock (heightmap)
1290 {
1291 Channel smoothed = new Channel();
1292 smoothed.Noise();
1293
1294 Channel mask = new Channel();
1295 mask.Raise(rx, ry, size, amount);
1296
1297 heightmap.Blend(smoothed, mask);
1298 }
1299
1300 tainted++;
1301 }
1302
1303 /// <summary>
1304 /// Reverts land within the specified bounds
1305 /// </summary>
1306 /// <param name="rx">Center of the bounding sphere</param>
1307 /// <param name="ry">Center of the bounding sphere</param>
1308 /// <param name="size">The radius of the sphere</param>
1309 /// <param name="amount">Strength of the mask (0..2) recommended</param>
1310 public void RevertTerrain(double rx, double ry, double size, double amount)
1311 {
1312 lock (heightmap)
1313 {
1314 Channel mask = new Channel();
1315 mask.Raise(rx, ry, size, amount);
1316
1317 heightmap.Blend(revertmap, mask);
1318 }
1319
1320 tainted++;
1321 }
1322
1323 /// <summary>
1324 /// Smooths land under the brush of specified coordinates (spherical mask)
1325 /// </summary>
1326 /// <param name="rx">Center of the sphere</param>
1327 /// <param name="ry">Center of the sphere</param>
1328 /// <param name="size">Radius of the sphere</param>
1329 /// <param name="amount">Thickness of the mask (0..2 recommended)</param>
1330 public void SmoothTerrain(double rx, double ry, double size, double amount)
1331 {
1332 lock (heightmap)
1333 {
1334 // perform essential computation as a channel method
1335 heightmap.SmoothRegion(rx, ry, size, amount);
1336 }
1337
1338 tainted++;
1339 }
1340
1341 /// <summary>
1342 /// Generates a simple set of hills in the shape of an island
1343 /// </summary>
1344 public void SetDefaultTerrain()
1345 {
1346 lock (heightmap)
1347 {
1348 heightmap.HillsSpheres(200, 20, 40, true, true, false);
1349 heightmap.Normalise();
1350 heightmap *= 60.0; // Raise to 60m
1351 heightmap.Clip(0.0, 25.0);
1352 heightmap.Pertubation(2.5);
1353 heightmap.Smooth(35.0);
1354 heightmap.Normalise(0.0, 21.0);
1355 }
1356
1357 tainted++;
1358 }
1359
1360 /// <summary>
1361 /// Wrapper to heightmap.get()
1362 /// </summary>
1363 /// <param name="x">X coord</param>
1364 /// <param name="y">Y coord</param>
1365 /// <returns>Height at specified coordinates</returns>
1366 public double GetHeight(int x, int y)
1367 {
1368 return heightmap.Get(x, y);
1369 }
1370
1371 /// <summary>
1372 /// Multiplies the heightfield by val
1373 /// </summary>
1374 /// <param name="meep">The heightfield</param>
1375 /// <param name="val">The multiplier</param>
1376 /// <returns></returns>
1377 public static TerrainEngine operator *(TerrainEngine terrain, Double val)
1378 {
1379 terrain.heightmap *= val;
1380 terrain.tainted++;
1381 return terrain;
1382 }
1383
1384 /// <summary>
1385 /// Exports the current heightmap to a PNG file
1386 /// </summary>
1387 /// <param name="filename">The destination filename for the image</param>
1388 /// <param name="gradientmap">A 1x*height* image which contains the colour gradient to export with. Must be at least 1x2 pixels, 1x256 or more is ideal.</param>
1389 public void WriteImage(string filename, string gradientmap)
1390 {
1391 try
1392 {
1393 Bitmap bmp = TerrainToBitmap(gradientmap);
1394
1395 bmp.Save(filename, ImageFormat.Png);
1396 }
1397 catch (Exception e) // LEGIT: Catching problems caused by OpenJPEG p/invoke
1398 {
1399 Console.WriteLine("Failed generating terrain map: " + e.ToString());
1400 }
1401 }
1402
1403 /// <summary>
1404 /// Exports the current heightmap in Jpeg2000 format to a byte[]
1405 /// </summary>
1406 /// <param name="gradientmap">A 1x*height* image which contains the colour gradient to export with. Must be at least 1x2 pixels, 1x256 or more is ideal.</param>
1407 public byte[] WriteJpegImage(string gradientmap)
1408 {
1409 byte[] imageData = null;
1410 try
1411 {
1412 Bitmap bmp = TerrainToBitmap(gradientmap);
1413
1414 imageData = OpenJPEG.EncodeFromImage(bmp, true);
1415 }
1416 catch (Exception e) // LEGIT: Catching problems caused by OpenJPEG p/invoke
1417 {
1418 Console.WriteLine("Failed generating terrain map: " + e.ToString());
1419 }
1420
1421 return imageData;
1422 }
1423
1424 private Bitmap TerrainToBitmap(string gradientmap)
1425 {
1426 Bitmap gradientmapLd = new Bitmap(gradientmap);
1427
1428 int pallete = gradientmapLd.Height;
1429
1430 Bitmap bmp = new Bitmap(heightmap.w, heightmap.h);
1431 Color[] colours = new Color[pallete];
1432
1433 for (int i = 0; i < pallete; i++)
1434 {
1435 colours[i] = gradientmapLd.GetPixel(0, i);
1436 }
1437
1438 Channel copy = heightmap.Copy();
1439 for (int y = 0; y < copy.h; y++)
1440 {
1441 for (int x = 0; x < copy.w; x++)
1442 {
1443 // 512 is the largest possible height before colours clamp
1444 int colorindex = (int) (Math.Max(Math.Min(1.0, copy.Get(x, y)/512.0), 0.0)*(pallete - 1));
1445 bmp.SetPixel(x, copy.h - y - 1, colours[colorindex]);
1446 }
1447 }
1448 return bmp;
1449 }
1450 }
1451}
diff --git a/OpenSim/Region/Terrain.BasicTerrain/TerrainFilter.cs b/OpenSim/Region/Terrain.BasicTerrain/TerrainFilter.cs
deleted file mode 100644
index 3e94dca..0000000
--- a/OpenSim/Region/Terrain.BasicTerrain/TerrainFilter.cs
+++ /dev/null
@@ -1,125 +0,0 @@
1/*
2 * Copyright (c) Contributors, http://opensimulator.org/
3 * See CONTRIBUTORS.TXT for a full list of copyright holders.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
7 * * Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * * Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 * * Neither the name of the OpenSim Project nor the
13 * names of its contributors may be used to endorse or promote products
14 * derived from this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
17 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19 * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
20 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
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
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
25 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */
27
28using System;
29using System.CodeDom.Compiler;
30using System.Collections.Generic;
31using libTerrain;
32using Microsoft.CSharp;
33using Microsoft.JScript;
34
35namespace OpenSim.Region.Terrain
36{
37 public interface ITerrainFilter
38 {
39 void Filter(Channel heightmap, string[] args);
40 string Register();
41 string Help();
42 }
43
44 public class TestFilter : ITerrainFilter
45 {
46 public void Filter(Channel heightmap, string[] args)
47 {
48 Console.WriteLine("Hello world");
49 }
50
51 public string Register()
52 {
53 return "demofilter";
54 }
55
56 public string Help()
57 {
58 return "demofilter - Does nothing";
59 }
60 }
61
62 public class FilterHost
63 {
64 public Dictionary<string, ITerrainFilter> filters = new Dictionary<string, ITerrainFilter>();
65
66 private void LoadFilter(CodeDomProvider compiler, string filename)
67 {
68 CompilerParameters compilerParams = new CompilerParameters();
69 CompilerResults compilerResults;
70 compilerParams.GenerateExecutable = false;
71 compilerParams.GenerateInMemory = true;
72 compilerParams.IncludeDebugInformation = false;
73 compilerParams.ReferencedAssemblies.Add("OpenSim.Terrain.BasicTerrain.dll");
74 compilerParams.ReferencedAssemblies.Add("System.dll");
75
76 compilerResults = compiler.CompileAssemblyFromFile(compilerParams, filename);
77
78 if (compilerResults.Errors.Count > 0)
79 {
80 Console.WriteLine("Compile errors:");
81 foreach (CompilerError error in compilerResults.Errors)
82 {
83 Console.WriteLine(error.Line.ToString() + ": " + error.ErrorText.ToString());
84 }
85 }
86 else
87 {
88 foreach (Type pluginType in compilerResults.CompiledAssembly.GetExportedTypes())
89 {
90 Type testInterface = pluginType.GetInterface("ITerrainFilter", true);
91
92 if (testInterface != null)
93 {
94 ITerrainFilter filter =
95 (ITerrainFilter) compilerResults.CompiledAssembly.CreateInstance(pluginType.ToString());
96
97 string filterName = filter.Register();
98 Console.WriteLine("Plugin: " + filterName + " loaded.");
99
100 if (!filters.ContainsKey(filterName))
101 {
102 filters.Add(filterName, filter);
103 }
104 else
105 {
106 filters[filterName] = filter;
107 }
108 }
109 }
110 }
111 }
112
113 public void LoadFilterCSharp(string filename)
114 {
115 CSharpCodeProvider compiler = new CSharpCodeProvider();
116 LoadFilter(compiler, filename);
117 }
118
119 public void LoadFilterJScript(string filename)
120 {
121 JScriptCodeProvider compiler = new JScriptCodeProvider();
122 LoadFilter(compiler, filename);
123 }
124 }
125}
diff --git a/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Bitmap/Bitmap.cs b/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Bitmap/Bitmap.cs
deleted file mode 100644
index 6bb717a..0000000
--- a/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Bitmap/Bitmap.cs
+++ /dev/null
@@ -1,85 +0,0 @@
1/*
2 * Copyright (c) Contributors, http://opensimulator.org/
3 * See CONTRIBUTORS.TXT for a full list of copyright holders.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
7 * * Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * * Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 * * Neither the name of the OpenSim Project nor the
13 * names of its contributors may be used to endorse or promote products
14 * derived from this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
17 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19 * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
20 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
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
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
25 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */
27
28using System.Drawing;
29using System.Drawing.Imaging;
30
31namespace libTerrain
32{
33 internal class Raster
34 {
35 private Bitmap bmp;
36
37 /// <summary>
38 /// Creates a new Raster channel for use with bitmap or GDI functions
39 /// </summary>
40 /// <param name="width">Width in pixels</param>
41 /// <param name="height">Height in pixels</param>
42 public Raster(int width, int height)
43 {
44 bmp = new Bitmap(width, height, PixelFormat.Format24bppRgb);
45 }
46
47 /// <summary>
48 /// Converts a raster image to a channel by averaging the RGB values to a single 0..1 heightmap
49 /// </summary>
50 /// <returns>A libTerrain Channel</returns>
51 public Channel ToChannel()
52 {
53 Channel chan = new Channel(bmp.Width, bmp.Height);
54
55 int x, y;
56 for (x = 0; x < bmp.Width; x++)
57 {
58 for (y = 0; y < bmp.Height; y++)
59 {
60 Color val = bmp.GetPixel(x, y);
61 chan.map[x, y] = (((double) val.R + (double) val.G + (double) val.B)/3.0)/255.0;
62 }
63 }
64
65 return chan;
66 }
67
68 /// <summary>
69 /// Draws a piece of text into the specified raster
70 /// </summary>
71 /// <param name="txt">The text string to print</param>
72 /// <param name="font">The font to use to draw the specified image</param>
73 /// <param name="size">Font size (points) to use</param>
74 public void DrawText(string txt, string font, double size)
75 {
76 Rectangle area = new Rectangle(0, 0, 256, 256);
77 StringFormat sf = new StringFormat();
78 sf.Alignment = StringAlignment.Center;
79 sf.LineAlignment = StringAlignment.Center;
80
81 Graphics gd = Graphics.FromImage(bmp);
82 gd.DrawString(txt, new Font(font, (float) size), new SolidBrush(Color.White), area, sf);
83 }
84 }
85}
diff --git a/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Channel.cs b/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Channel.cs
deleted file mode 100644
index b19a788..0000000
--- a/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Channel.cs
+++ /dev/null
@@ -1,59 +0,0 @@
1/*
2 * Copyright (c) Contributors, http://opensimulator.org/
3 * See CONTRIBUTORS.TXT for a full list of copyright holders.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
7 * * Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * * Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 * * Neither the name of the OpenSim Project nor the
13 * names of its contributors may be used to endorse or promote products
14 * derived from this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
17 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19 * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
20 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
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
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
25 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */
27
28/* Channel
29 * A channel is a single heightmap array
30 * */
31
32namespace libTerrain
33{
34 partial class Channel
35 {
36 public double[,] map;
37 public int[,] diff;
38 public int w;
39 public int h;
40
41 public int seed = 1338; // One better than 1337
42
43 public Channel()
44 {
45 w = 256;
46 h = 256;
47 map = new double[w,h];
48 diff = new int[(int) (w/16),(int) (h/16)];
49 }
50
51 public Channel(int width, int height)
52 {
53 w = width;
54 h = height;
55 map = new double[w,h];
56 diff = new int[(int) (w/16),(int) (h/16)];
57 }
58 }
59}
diff --git a/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Common.cs b/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Common.cs
deleted file mode 100644
index 0c71ed8..0000000
--- a/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Common.cs
+++ /dev/null
@@ -1,281 +0,0 @@
1/*
2 * Copyright (c) Contributors, http://opensimulator.org/
3 * See CONTRIBUTORS.TXT for a full list of copyright holders.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
7 * * Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * * Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 * * Neither the name of the OpenSim Project nor the
13 * names of its contributors may be used to endorse or promote products
14 * derived from this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
17 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19 * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
20 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
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
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
25 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */
27
28using System;
29
30namespace libTerrain
31{
32 public partial class Channel
33 {
34 public int GetWidth()
35 {
36 return w;
37 }
38
39 public int GetHeight()
40 {
41 return h;
42 }
43
44 public Channel Copy()
45 {
46 Channel x = new Channel(w, h);
47 x.map = (double[,]) map.Clone();
48 return x;
49 }
50
51 public void SetDiff()
52 {
53 SetDiff(1);
54 }
55
56 public void SetDiff(int val)
57 {
58 for (int x = 0; x < w/16; x++)
59 {
60 for (int y = 0; y < h/16; y++)
61 {
62 diff[x, y] = val;
63 }
64 }
65 }
66
67 public void SetDiff(int x, int y)
68 {
69 diff[x/16, y/16]++;
70 }
71
72 public void Set(int x, int y, double val)
73 {
74 if (x >= w)
75 throw new Exception("Bounds error while setting pixel (width)");
76 if (y >= h)
77 throw new Exception("Bounds error while setting pixel (height)");
78 if (x < 0)
79 throw new Exception("Bounds error while setting pixel (width)");
80 if (y < 0)
81 throw new Exception("Bounds error while setting pixel (height)");
82
83 if (map[x, y] != val)
84 {
85 SetDiff(x, y);
86
87 map[x, y] = val;
88 }
89 }
90
91 public void SetClip(int x, int y, double val)
92 {
93 SetDiff(x, y);
94
95 if (x >= w)
96 throw new Exception("Bounds error while setting pixel (width)");
97 if (y >= h)
98 throw new Exception("Bounds error while setting pixel (height)");
99 if (x < 0)
100 throw new Exception("Bounds error while setting pixel (width)");
101 if (y < 0)
102 throw new Exception("Bounds error while setting pixel (height)");
103
104 if (val > 1.0)
105 val = 1.0;
106 if (val < 0.0)
107 val = 0.0;
108
109 map[x, y] = val;
110 }
111
112 private double GetBilinearInterpolate(double x, double y)
113 {
114 if (x > w - 2.0)
115 x = w - 2.0;
116 if (y > h - 2.0)
117 y = h - 2.0;
118 if (x < 0.0)
119 x = 0.0;
120 if (y < 0.0)
121 y = 0.0;
122
123 int stepSize = 1;
124 double h00 = Get((int) x, (int) y);
125 double h10 = Get((int) x + stepSize, (int) y);
126 double h01 = Get((int) x, (int) y + stepSize);
127 double h11 = Get((int) x + stepSize, (int) y + stepSize);
128 double h1 = h00;
129 double h2 = h10;
130 double h3 = h01;
131 double h4 = h11;
132 double a00 = h1;
133 double a10 = h2 - h1;
134 double a01 = h3 - h1;
135 double a11 = h1 - h2 - h3 + h4;
136 double partialx = x - (int) x;
137 double partialz = y - (int) y;
138 double hi = a00 + (a10*partialx) + (a01*partialz) + (a11*partialx*partialz);
139 return hi;
140 }
141
142 public double Get(int x, int y)
143 {
144 try
145 {
146 return map[x, y];
147 }
148 catch (IndexOutOfRangeException)
149 {
150 if (x >= w)
151 x = w - 1;
152 if (y >= h)
153 y = h - 1;
154 if (x < 0)
155 x = 0;
156 if (y < 0)
157 y = 0;
158 return map[x, y];
159 }
160 }
161
162 public void SetWrap(int x, int y, double val)
163 {
164 SetDiff(x, y);
165
166 map[x%w, y%h] = val;
167 }
168
169 public void SetWrapClip(int x, int y, double val)
170 {
171 SetDiff(x, y);
172
173 if (val > 1.0)
174 val = 1.0;
175 if (val < 0.0)
176 val = 0.0;
177
178 map[x%w, y%h] = val;
179 }
180
181 public void Fill(double val)
182 {
183 SetDiff();
184
185 int x, y;
186 for (x = 0; x < w; x++)
187 {
188 for (y = 0; y < h; y++)
189 {
190 map[x, y] = val;
191 }
192 }
193 }
194
195 public void Fill(double min, double max, double val)
196 {
197 SetDiff();
198
199 int x, y;
200 for (x = 0; x < w; x++)
201 {
202 for (y = 0; y < h; y++)
203 {
204 if (map[x, y] >= min && map[x, y] <= max)
205 map[x, y] = val;
206 }
207 }
208 }
209
210 public double FindMax()
211 {
212 int x, y;
213 double max = double.MinValue;
214
215 for (x = 0; x < w; x++)
216 {
217 for (y = 0; y < h; y++)
218 {
219 if (map[x, y] > max)
220 max = map[x, y];
221 }
222 }
223
224 return max;
225 }
226
227 public double FindMin()
228 {
229 int x, y;
230 double min = double.MaxValue;
231
232 for (x = 0; x < w; x++)
233 {
234 for (y = 0; y < h; y++)
235 {
236 if (map[x, y] < min)
237 min = map[x, y];
238 }
239 }
240
241 return min;
242 }
243
244 public double Sum()
245 {
246 int x, y;
247 double sum = 0.0;
248
249 for (x = 0; x < w; x++)
250 {
251 for (y = 0; y < h; y++)
252 {
253 sum += map[x, y];
254 }
255 }
256
257 return sum;
258 }
259
260 public double Avg()
261 {
262 return Sum()/(w*h);
263 }
264
265 public bool ContainsNaN()
266 {
267 int x, y;
268 for (x = 0; x < w; x++)
269 {
270 for (y = 0; y < h; y++)
271 {
272 double elm = map[x, y];
273
274 if (Double.IsNaN(elm))
275 return true;
276 }
277 }
278 return false;
279 }
280 }
281}
diff --git a/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Editing/Flatten.cs b/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Editing/Flatten.cs
deleted file mode 100644
index 7162758..0000000
--- a/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Editing/Flatten.cs
+++ /dev/null
@@ -1,141 +0,0 @@
1/*
2 * Copyright (c) Contributors, http://opensimulator.org/
3 * See CONTRIBUTORS.TXT for a full list of copyright holders.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
7 * * Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * * Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 * * Neither the name of the OpenSim Project nor the
13 * names of its contributors may be used to endorse or promote products
14 * derived from this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
17 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19 * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
20 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
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
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
25 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */
27
28namespace libTerrain
29{
30 partial class Channel
31 {
32 /// <summary>
33 /// Flattens the area underneath rx,ry by moving it to the average of the area. Uses a spherical mask provided by the raise() function.
34 /// </summary>
35 /// <param name="rx">The X coordinate of the terrain mask</param>
36 /// <param name="ry">The Y coordinate of the terrain mask</param>
37 /// <param name="size">The size of the terrain mask</param>
38 /// <param name="amount">The scale of the terrain mask</param>
39 public void Flatten(double rx, double ry, double size, double amount)
40 {
41 FlattenSlow(rx, ry, size, amount);
42 }
43
44 private void FlattenSlow(double rx, double ry, double size, double amount)
45 {
46 // Generate the mask
47 Channel temp = new Channel(w, h);
48 temp.Fill(0);
49 temp.Raise(rx, ry, size, amount);
50 temp.Normalise();
51 double total_mod = temp.Sum();
52
53 // Establish the average height under the area
54 Channel newmap = new Channel(w, h);
55 newmap.map = (double[,]) map.Clone();
56
57 newmap *= temp;
58
59 double total_terrain = newmap.Sum();
60 double avg_height = total_terrain/total_mod;
61
62 // Create a flat terrain using the average height
63 Channel flat = new Channel(w, h);
64 flat.Fill(avg_height);
65
66 // Blend the current terrain with the average height terrain
67 // using the "raised" empty terrain as a mask
68 Blend(flat, temp);
69 }
70
71// TODO: unused
72// private void FlattenFast(double rx, double ry, double size, double amount)
73// {
74// int x, y;
75// double avg = 0;
76// double div = 0;
77
78// int minX = Math.Max(0, (int) (rx - (size + 1)));
79// int maxX = Math.Min(w, (int) (rx + (size + 1)));
80// int minY = Math.Max(0, (int) (ry - (size + 1)));
81// int maxY = Math.Min(h, (int) (ry + (size + 1)));
82
83// for (x = minX; x < maxX; x++)
84// {
85// for (y = minY; y < maxY; y++)
86// {
87// double z = size;
88// z *= z;
89// z -= ((x - rx)*(x - rx)) + ((y - ry)*(y - ry));
90
91// if (z < 0)
92// z = 0;
93
94// avg += z*amount;
95// div += z;
96// }
97// }
98
99// double height = avg/div;
100
101// for (x = minX; x < maxX; x++)
102// {
103// for (y = minY; y < maxY; y++)
104// {
105// double z = size;
106// z *= z;
107// z -= ((x - rx)*(x - rx)) + ((y - ry)*(y - ry));
108
109// if (z > 0.0)
110// Set(x, y, Tools.LinearInterpolate(map[x, y], height, z));
111// }
112// }
113// }
114
115 public void Flatten(Channel mask, double amount)
116 {
117 // Generate the mask
118 Channel temp = mask*amount;
119 temp.Clip(0, 1); // Cut off out-of-bounds values
120
121 double total_mod = temp.Sum();
122
123 // Establish the average height under the area
124 Channel map = new Channel(w, h);
125 map.map = (double[,]) this.map.Clone();
126
127 map *= temp;
128
129 double total_terrain = map.Sum();
130 double avg_height = total_terrain/total_mod;
131
132 // Create a flat terrain using the average height
133 Channel flat = new Channel(w, h);
134 flat.Fill(avg_height);
135
136 // Blend the current terrain with the average height terrain
137 // using the "raised" empty terrain as a mask
138 Blend(flat, temp);
139 }
140 }
141}
diff --git a/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Editing/Raise.cs b/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Editing/Raise.cs
deleted file mode 100644
index 465005a..0000000
--- a/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Editing/Raise.cs
+++ /dev/null
@@ -1,191 +0,0 @@
1/*
2 * Copyright (c) Contributors, http://opensimulator.org/
3 * See CONTRIBUTORS.TXT for a full list of copyright holders.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
7 * * Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * * Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 * * Neither the name of the OpenSim Project nor the
13 * names of its contributors may be used to endorse or promote products
14 * derived from this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
17 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19 * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
20 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
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
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
25 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */
27
28using System;
29
30namespace libTerrain
31{
32 partial class Channel
33 {
34 /// <summary>
35 /// Raises land around the selection
36 /// </summary>
37 /// <param name="rx">The center the X coordinate of where you wish to raise the land</param>
38 /// <param name="ry">The center the Y coordinate of where you wish to raise the land</param>
39 /// <param name="size">The radius of the dimple</param>
40 /// <param name="amount">How much impact to add to the terrain (0..2 usually)</param>
41 public void Raise(double rx, double ry, double size, double amount)
42 {
43 RaiseSphere(rx, ry, size, amount);
44 }
45
46 /// <summary>
47 /// Raises land in a sphere around the selection
48 /// </summary>
49 /// <param name="rx">The center the X coordinate of where you wish to raise the land</param>
50 /// <param name="ry">The center the Y coordinate of where you wish to raise the land</param>
51 /// <param name="size">The radius of the sphere dimple</param>
52 /// <param name="amount">How much impact to add to the terrain (0..2 usually)</param>
53 public void RaiseSphere(double rx, double ry, double size, double amount)
54 {
55 int x, y;
56 for (x = 0; x < w; x++)
57 {
58 for (y = 0; y < h; y++)
59 {
60 double z = size;
61 z *= z;
62 z -= ((x - rx)*(x - rx)) + ((y - ry)*(y - ry));
63
64 if (z > 0.0)
65 Set(x, y, map[x, y] + (z * amount));
66 }
67 }
68 }
69
70 /// <summary>
71 /// Raises land in a cone around the selection
72 /// </summary>
73 /// <param name="rx">The center the X coordinate of where you wish to raise the land</param>
74 /// <param name="ry">The center the Y coordinate of where you wish to raise the land</param>
75 /// <param name="size">The radius of the cone</param>
76 /// <param name="amount">How much impact to add to the terrain (0..2 usually)</param>
77 public void RaiseCone(double rx, double ry, double size, double amount)
78 {
79 int x, y;
80 for (x = 0; x < w; x++)
81 {
82 for (y = 0; y < h; y++)
83 {
84 double z = size;
85 z -= Math.Sqrt(((x - rx)*(x - rx)) + ((y - ry)*(y - ry)));
86
87 if (z > 0.0)
88 Set(x, y, map[x, y] + (z * amount));
89 }
90 }
91 }
92
93 /// <summary>
94 /// Lowers land in a sphere around the selection
95 /// </summary>
96 /// <param name="rx">The center the X coordinate of where you wish to lower the land</param>
97 /// <param name="ry">The center the Y coordinate of where you wish to lower the land</param>
98 /// <param name="size">The radius of the sphere dimple</param>
99 /// <param name="amount">How much impact to remove from the terrain (0..2 usually)</param>
100 public void Lower(double rx, double ry, double size, double amount)
101 {
102 LowerSphere(rx, ry, size, amount);
103 }
104
105 /// <summary>
106 /// Lowers land in a sphere around the selection
107 /// </summary>
108 /// <param name="rx">The center the X coordinate of where you wish to lower the land</param>
109 /// <param name="ry">The center the Y coordinate of where you wish to lower the land</param>
110 /// <param name="size">The radius of the sphere dimple</param>
111 /// <param name="amount">How much impact to remove from the terrain (0..2 usually)</param>
112 public void LowerSphere(double rx, double ry, double size, double amount)
113 {
114 int x, y;
115 for (x = 0; x < w; x++)
116 {
117 for (y = 0; y < h; y++)
118 {
119 double z = size;
120 z *= z;
121 z -= ((x - rx)*(x - rx)) + ((y - ry)*(y - ry));
122
123 if (z > 0.0)
124 Set(x, y, map[x, y] - (z * amount));
125 }
126 }
127 }
128
129 public double SphericalFactor(double x, double y, double rx, double ry, double size)
130 {
131 double z = size * size - ((x - rx) * (x - rx) + (y - ry) * (y - ry));
132 return z;
133 }
134
135 public void SmoothRegion(double rx, double ry, double size, double amount)
136 {
137 int x, y;
138 double[,] tweak = new double[w, h];
139
140 double n, l;
141 double area = size;
142 double step = size / 4.0;
143
144 // compute delta map
145 for (x = 0; x < w; x++)
146 {
147 for (y = 0; y < h; y++)
148 {
149 double z = SphericalFactor(x, y, rx, ry, size);
150
151 if (z > 0) // add in non-zero amount
152 {
153 double average = 0.0;
154 int avgsteps = 0;
155
156 for (n = 0.0 - area; n < area; n += step)
157 {
158 for (l = 0.0 - area; l < area; l += step)
159 {
160 avgsteps++;
161 average += GetBilinearInterpolate(x + n, y + l);
162 }
163 }
164 tweak[x, y] = average / avgsteps;
165 //if (x == rx && y == ry)
166 // Console.WriteLine("tweak[ " + x + " , " + y + " ] = " + tweak[x, y]);
167 }
168 }
169 }
170 // blend in map
171 for (x = 0; x < w; x++)
172 {
173 for (y = 0; y < h; y++)
174 {
175 double z = SphericalFactor(x, y, rx, ry, size);
176
177 if (z > 0) // add in non-zero amount
178 {
179 double da = z * amount;
180 double a = (map[x, y] - tweak[x, y]) * da;
181 double newz = map[x, y] - a;
182 //if (rx == x || ry == y)
183 // Console.WriteLine("map[ " + x + " , " + y + " ] = " + map[x, y] + " tweak, a , da, z, size, amount = " + tweak[x, y] + " " + a + " " + da + " " + z + " " + size + " " + amount);
184 if (newz > 0.0)
185 Set(x, y, newz);
186 }
187 }
188 }
189 }
190 }
191}
diff --git a/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/File.cs b/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/File.cs
deleted file mode 100644
index 84eca54..0000000
--- a/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/File.cs
+++ /dev/null
@@ -1,75 +0,0 @@
1/*
2 * Copyright (c) Contributors, http://opensimulator.org/
3 * See CONTRIBUTORS.TXT for a full list of copyright holders.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
7 * * Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * * Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 * * Neither the name of the OpenSim Project nor the
13 * names of its contributors may be used to endorse or promote products
14 * derived from this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
17 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19 * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
20 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
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
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
25 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */
27
28using System;
29using System.Drawing;
30using System.Drawing.Imaging;
31
32namespace libTerrain
33{
34 partial class Channel
35 {
36 public Channel LoadImage(string filename)
37 {
38 SetDiff();
39
40 Bitmap bit = new Bitmap(filename);
41 Channel chan = new Channel(bit.Width, bit.Height);
42
43 int x, y;
44 for (x = 0; x < bit.Width; x++)
45 {
46 for (y = 0; y < bit.Height; y++)
47 {
48 Color val = bit.GetPixel(x, y);
49 chan.map[x, y] = (((double) val.R + (double) val.G + (double) val.B)/3.0)/255.0;
50 }
51 }
52
53 return chan;
54 }
55
56 public void SaveImage(string filename)
57 {
58 Channel outmap = Copy();
59 outmap.Normalise();
60
61 Bitmap bit = new Bitmap(w, h, PixelFormat.Format24bppRgb);
62 int x, y;
63 for (x = 0; x < w; x++)
64 {
65 for (y = 0; y < h; y++)
66 {
67 int val = Math.Min(255, (int) (outmap.map[x, y]*255));
68 Color col = Color.FromArgb(val, val, val);
69 bit.SetPixel(x, y, col);
70 }
71 }
72 bit.Save(filename);
73 }
74 }
75}
diff --git a/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Generators/Cellular.cs b/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Generators/Cellular.cs
deleted file mode 100644
index 06e7e3c..0000000
--- a/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Generators/Cellular.cs
+++ /dev/null
@@ -1,28 +0,0 @@
1/*
2 * Copyright (c) Contributors, http://opensimulator.org/
3 * See CONTRIBUTORS.TXT for a full list of copyright holders.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
7 * * Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * * Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 * * Neither the name of the OpenSim Project nor the
13 * names of its contributors may be used to endorse or promote products
14 * derived from this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
17 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19 * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
20 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
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
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
25 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */
27
28/* TODO: Needs BSD rewrite */
diff --git a/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Generators/Fracture.cs b/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Generators/Fracture.cs
deleted file mode 100644
index 3e1c34c..0000000
--- a/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Generators/Fracture.cs
+++ /dev/null
@@ -1,142 +0,0 @@
1/*
2 * Copyright (c) Contributors, http://opensimulator.org/
3 * See CONTRIBUTORS.TXT for a full list of copyright holders.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
7 * * Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * * Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 * * Neither the name of the OpenSim Project nor the
13 * names of its contributors may be used to endorse or promote products
14 * derived from this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
17 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19 * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
20 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
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
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
25 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */
27
28using System;
29
30namespace libTerrain
31{
32 partial class Channel
33 {
34 /// <summary>
35 /// Produces a set of coordinates defined by an edge point. Eg - 0 = 0,0. 256 = 0,256. 512 = 256,256
36 /// Assumes a 256^2 heightmap. This needs fixing for input values of w,h
37 /// </summary>
38 /// <param name="val"></param>
39 /// <param name="w"></param>
40 /// <param name="h"></param>
41 /// <returns></returns>
42 private int[] RadialEdge256(int val)
43 {
44 // Four cases:
45 // 1. 000..255 return 0,val
46 // 2. 256..511 return val - 256,255
47 // 3. 512..767 return 255, val - 511
48 // 4. 768..1023 return val - 768,0
49
50 int[] ret = new int[2];
51
52 if (val < 256)
53 {
54 ret[0] = 0;
55 ret[1] = val;
56 return ret;
57 }
58 if (val < 512)
59 {
60 ret[0] = (val%256);
61 ret[1] = 255;
62 return ret;
63 }
64 if (val < 768)
65 {
66 ret[0] = 255;
67 ret[1] = 255 - (val%256);
68 return ret;
69 }
70 if (val < 1024)
71 {
72 ret[0] = 255 - (val%256);
73 ret[1] = 255;
74 return ret;
75 }
76
77 throw new Exception("Out of bounds parameter (val)");
78 }
79
80 public void Fracture(int number, double scalemin, double scalemax)
81 {
82 SetDiff();
83
84 Random rand = new Random(seed);
85
86 for (int i = 0; i < number; i++)
87 {
88 int[] a, b;
89
90 a = RadialEdge256(rand.Next(1023)); // TODO: Broken
91 b = RadialEdge256(rand.Next(1023)); // TODO: Broken
92 double z = rand.NextDouble();
93 double u = rand.NextDouble();
94 double v = rand.NextDouble();
95
96 for (int x = 0; x < w; x++)
97 {
98 for (int y = 0; y < h; y++)
99 {
100 double miny = Tools.LinearInterpolate(a[1], b[1], (double) x/(double) w);
101
102 if (v >= 0.5)
103 {
104 if (u >= 0.5)
105 {
106 if (y > miny)
107 {
108 map[x, y] += Tools.LinearInterpolate(scalemin, scalemax, z);
109 }
110 }
111 else
112 {
113 if (y < miny)
114 {
115 map[x, y] += Tools.LinearInterpolate(scalemin, scalemax, z);
116 }
117 }
118 }
119 else
120 {
121 if (u >= 0.5)
122 {
123 if (x > miny)
124 {
125 map[x, y] += Tools.LinearInterpolate(scalemin, scalemax, z);
126 }
127 }
128 else
129 {
130 if (x < miny)
131 {
132 map[x, y] += Tools.LinearInterpolate(scalemin, scalemax, z);
133 }
134 }
135 }
136 }
137 }
138 }
139 Normalise();
140 }
141 }
142}
diff --git a/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Generators/Gradient.cs b/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Generators/Gradient.cs
deleted file mode 100644
index afe0877..0000000
--- a/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Generators/Gradient.cs
+++ /dev/null
@@ -1,60 +0,0 @@
1/*
2 * Copyright (c) Contributors, http://opensimulator.org/
3 * See CONTRIBUTORS.TXT for a full list of copyright holders.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
7 * * Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * * Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 * * Neither the name of the OpenSim Project nor the
13 * names of its contributors may be used to endorse or promote products
14 * derived from this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
17 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19 * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
20 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
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
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
25 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */
27
28namespace libTerrain
29{
30 partial class Channel
31 {
32 public void GradientCube()
33 {
34 SetDiff();
35
36 int x, y;
37 for (x = 0; x < w; x++)
38 {
39 for (y = 0; y < h; y++)
40 {
41 map[x, y] = x*y;
42 }
43 }
44 Normalise();
45 }
46
47 public void GradientStripe()
48 {
49 int x, y;
50 for (x = 0; x < w; x++)
51 {
52 for (y = 0; y < h; y++)
53 {
54 map[x, y] = x;
55 }
56 }
57 Normalise();
58 }
59 }
60}
diff --git a/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Generators/HillPlanter.cs b/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Generators/HillPlanter.cs
deleted file mode 100644
index 82b0cfd..0000000
--- a/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Generators/HillPlanter.cs
+++ /dev/null
@@ -1,281 +0,0 @@
1/*
2 * Copyright (c) Contributors, http://opensimulator.org/
3 * See CONTRIBUTORS.TXT for a full list of copyright holders.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
7 * * Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * * Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 * * Neither the name of the OpenSim Project nor the
13 * names of its contributors may be used to endorse or promote products
14 * derived from this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
17 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19 * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
20 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
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
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
25 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */
27
28using System;
29
30namespace libTerrain
31{
32 partial class Channel
33 {
34 /// <summary>
35 /// Generates a series of spheres which are then either max()'d or added together. Inspired by suggestion from jh.
36 /// </summary>
37 /// <remarks>3-Clause BSD Licensed</remarks>
38 /// <param name="number">The number of hills to generate</param>
39 /// <param name="scale_min">The minimum size of each hill</param>
40 /// <param name="scale_range">The maximum size of each hill</param>
41 /// <param name="island">Whether to bias hills towards the center of the map</param>
42 /// <param name="additive">Whether to add hills together or to pick the largest value</param>
43 /// <param name="noisy">Generates hill-shaped noise instead of consistent hills</param>
44 public void HillsSpheres(int number, double scale_min, double scale_range, bool island, bool additive,
45 bool noisy)
46 {
47 SetDiff();
48
49 Random random = new Random(seed);
50
51 int x, y;
52 int i;
53
54 for (i = 0; i < number; i++)
55 {
56 double rx = Math.Min(255.0, random.NextDouble()*w);
57 double ry = Math.Min(255.0, random.NextDouble()*h);
58 double rand = random.NextDouble();
59
60 if (island)
61 {
62 // Move everything towards the center
63 rx -= w/2;
64 rx /= 2;
65 rx += w/2;
66
67 ry -= h/2;
68 ry /= 2;
69 ry += h/2;
70 }
71
72 for (x = 0; x < w; x++)
73 {
74 for (y = 0; y < h; y++)
75 {
76 if (noisy)
77 rand = random.NextDouble();
78
79 double z = (scale_min + (scale_range*rand));
80 z *= z;
81 z -= ((x - rx)*(x - rx)) + ((y - ry)*(y - ry));
82
83 if (z < 0)
84 z = 0;
85
86 if (additive)
87 {
88 map[x, y] += z;
89 }
90 else
91 {
92 map[x, y] = Math.Max(map[x, y], z);
93 }
94 }
95 }
96 }
97
98 Normalise();
99 }
100
101 /// <summary>
102 /// Generates a series of cones which are then either max()'d or added together. Inspired by suggestion from jh.
103 /// </summary>
104 /// <remarks>3-Clause BSD Licensed</remarks>
105 /// <param name="number">The number of hills to generate</param>
106 /// <param name="scale_min">The minimum size of each hill</param>
107 /// <param name="scale_range">The maximum size of each hill</param>
108 /// <param name="island">Whether to bias hills towards the center of the map</param>
109 /// <param name="additive">Whether to add hills together or to pick the largest value</param>
110 /// <param name="noisy">Generates hill-shaped noise instead of consistent hills</param>
111 public void HillsCones(int number, double scale_min, double scale_range, bool island, bool additive, bool noisy)
112 {
113 SetDiff();
114
115 Random random = new Random(seed);
116
117 int x, y;
118 int i;
119
120 for (i = 0; i < number; i++)
121 {
122 double rx = Math.Min(255.0, random.NextDouble()*w);
123 double ry = Math.Min(255.0, random.NextDouble()*h);
124 double rand = random.NextDouble();
125
126 if (island)
127 {
128 // Move everything towards the center
129 rx -= w/2;
130 rx /= 2;
131 rx += w/2;
132
133 ry -= h/2;
134 ry /= 2;
135 ry += h/2;
136 }
137
138 for (x = 0; x < w; x++)
139 {
140 for (y = 0; y < h; y++)
141 {
142 if (noisy)
143 rand = random.NextDouble();
144
145 double z = (scale_min + (scale_range*rand));
146 z -= Math.Sqrt(((x - rx)*(x - rx)) + ((y - ry)*(y - ry)));
147
148 if (z < 0)
149 z = 0;
150
151 if (additive)
152 {
153 map[x, y] += z;
154 }
155 else
156 {
157 map[x, y] = Math.Max(map[x, y], z);
158 }
159 }
160 }
161 }
162
163 Normalise();
164 }
165
166 public void HillsBlocks(int number, double scale_min, double scale_range, bool island, bool additive, bool noisy)
167 {
168 SetDiff();
169
170 Random random = new Random(seed);
171
172 int x, y;
173 int i;
174
175 for (i = 0; i < number; i++)
176 {
177 double rx = Math.Min(255.0, random.NextDouble()*w);
178 double ry = Math.Min(255.0, random.NextDouble()*h);
179 double rand = random.NextDouble();
180
181 if (island)
182 {
183 // Move everything towards the center
184 rx -= w/2;
185 rx /= 2;
186 rx += w/2;
187
188 ry -= h/2;
189 ry /= 2;
190 ry += h/2;
191 }
192
193 for (x = 0; x < w; x++)
194 {
195 for (y = 0; y < h; y++)
196 {
197 if (noisy)
198 rand = random.NextDouble();
199
200 double z = (scale_min + (scale_range*rand));
201 z -= Math.Abs(x - rx) + Math.Abs(y - ry);
202 //z -= Math.Sqrt(((x - rx) * (x - rx)) + ((y - ry) * (y - ry)));
203
204 if (z < 0)
205 z = 0;
206
207 if (additive)
208 {
209 map[x, y] += z;
210 }
211 else
212 {
213 map[x, y] = Math.Max(map[x, y], z);
214 }
215 }
216 }
217 }
218
219 Normalise();
220 }
221
222 public void HillsSquared(int number, double scale_min, double scale_range, bool island, bool additive,
223 bool noisy)
224 {
225 SetDiff();
226
227 Random random = new Random(seed);
228
229 int x, y;
230 int i;
231
232 for (i = 0; i < number; i++)
233 {
234 double rx = Math.Min(255.0, random.NextDouble()*w);
235 double ry = Math.Min(255.0, random.NextDouble()*h);
236 double rand = random.NextDouble();
237
238 if (island)
239 {
240 // Move everything towards the center
241 rx -= w/2;
242 rx /= 2;
243 rx += w/2;
244
245 ry -= h/2;
246 ry /= 2;
247 ry += h/2;
248 }
249
250 for (x = 0; x < w; x++)
251 {
252 for (y = 0; y < h; y++)
253 {
254 if (noisy)
255 rand = random.NextDouble();
256
257 double z = (scale_min + (scale_range*rand));
258 z *= z*z*z;
259 double dx = Math.Abs(x - rx);
260 double dy = Math.Abs(y - ry);
261 z -= (dx*dx*dx*dx) + (dy*dy*dy*dy);
262
263 if (z < 0)
264 z = 0;
265
266 if (additive)
267 {
268 map[x, y] += z;
269 }
270 else
271 {
272 map[x, y] = Math.Max(map[x, y], z);
273 }
274 }
275 }
276 }
277
278 Normalise();
279 }
280 }
281}
diff --git a/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Generators/Midpoint.cs b/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Generators/Midpoint.cs
deleted file mode 100644
index 06e7e3c..0000000
--- a/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Generators/Midpoint.cs
+++ /dev/null
@@ -1,28 +0,0 @@
1/*
2 * Copyright (c) Contributors, http://opensimulator.org/
3 * See CONTRIBUTORS.TXT for a full list of copyright holders.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
7 * * Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * * Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 * * Neither the name of the OpenSim Project nor the
13 * names of its contributors may be used to endorse or promote products
14 * derived from this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
17 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19 * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
20 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
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
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
25 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */
27
28/* TODO: Needs BSD rewrite */
diff --git a/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Generators/Mountain.cs b/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Generators/Mountain.cs
deleted file mode 100644
index 06e7e3c..0000000
--- a/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Generators/Mountain.cs
+++ /dev/null
@@ -1,28 +0,0 @@
1/*
2 * Copyright (c) Contributors, http://opensimulator.org/
3 * See CONTRIBUTORS.TXT for a full list of copyright holders.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
7 * * Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * * Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 * * Neither the name of the OpenSim Project nor the
13 * names of its contributors may be used to endorse or promote products
14 * derived from this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
17 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19 * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
20 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
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
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
25 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */
27
28/* TODO: Needs BSD rewrite */
diff --git a/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Generators/Noise.cs b/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Generators/Noise.cs
deleted file mode 100644
index 10e8160..0000000
--- a/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Generators/Noise.cs
+++ /dev/null
@@ -1,53 +0,0 @@
1/*
2 * Copyright (c) Contributors, http://opensimulator.org/
3 * See CONTRIBUTORS.TXT for a full list of copyright holders.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
7 * * Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * * Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 * * Neither the name of the OpenSim Project nor the
13 * names of its contributors may be used to endorse or promote products
14 * derived from this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
17 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19 * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
20 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
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
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
25 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */
27
28using System;
29
30namespace libTerrain
31{
32 partial class Channel
33 {
34 /// <summary>
35 /// Fills a channel with 0..1 noise
36 /// </summary>
37 /// <remarks>3-Clause BSD Licensed</remarks>
38 public void Noise()
39 {
40 SetDiff();
41
42 Random rand = new Random(seed);
43 int x, y;
44 for (x = 0; x < w; x++)
45 {
46 for (y = 0; y < h; y++)
47 {
48 map[x, y] = rand.NextDouble();
49 }
50 }
51 }
52 }
53}
diff --git a/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Generators/Spiral.cs b/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Generators/Spiral.cs
deleted file mode 100644
index a516d8d..0000000
--- a/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Generators/Spiral.cs
+++ /dev/null
@@ -1,156 +0,0 @@
1/*
2 * Copyright (c) Contributors, http://opensimulator.org/
3 * See CONTRIBUTORS.TXT for a full list of copyright holders.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
7 * * Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * * Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 * * Neither the name of the OpenSim Project nor the
13 * names of its contributors may be used to endorse or promote products
14 * derived from this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
17 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19 * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
20 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
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
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
25 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */
27
28using System;
29using System.Collections.Generic;
30
31namespace libTerrain
32{
33 partial class Channel
34 {
35 private double[] CoordinatesToPolar(int x, int y)
36 {
37 double theta = Math.Atan2(x - (w/2), y - (h/2));
38 double rx = (double) x - ((double) w/2);
39 double ry = (double) y - ((double) h/2);
40 double r = Math.Sqrt((rx*rx) + (ry*ry));
41
42 double[] coords = new double[2];
43 coords[0] = r;
44 coords[1] = theta;
45 return coords;
46 }
47
48 public int[] PolarToCoordinates(double r, double theta)
49 {
50 double nx;
51 double ny;
52
53 nx = (double) r*Math.Cos(theta);
54 ny = (double) r*Math.Sin(theta);
55
56 nx += w/2;
57 ny += h/2;
58
59 if (nx >= w)
60 nx = w - 1;
61
62 if (ny >= h)
63 ny = h - 1;
64
65 if (nx < 0)
66 nx = 0;
67
68 if (ny < 0)
69 ny = 0;
70
71 int[] coords = new int[2];
72 coords[0] = (int) nx;
73 coords[1] = (int) ny;
74 return coords;
75 }
76
77 public void Polar()
78 {
79 SetDiff();
80
81 Channel n = Copy();
82
83 int x, y;
84 for (x = 0; x < w; x++)
85 {
86 for (y = 0; y < h; y++)
87 {
88 double[] coords = CoordinatesToPolar(x, y);
89
90 coords[0] += w/2.0;
91 coords[1] += h/2.0;
92
93 map[x, y] = n.map[(int) coords[0]%n.w, (int) coords[1]%n.h];
94 }
95 }
96 }
97
98 public void SpiralPlanter(int steps, double incAngle, double incRadius, double offsetRadius, double offsetAngle)
99 {
100 SetDiff();
101
102 int i;
103 double r = offsetRadius;
104 double theta = offsetAngle;
105 for (i = 0; i < steps; i++)
106 {
107 r += incRadius;
108 theta += incAngle;
109
110 int[] coords = PolarToCoordinates(r, theta);
111 Raise(coords[0], coords[1], 20, 1);
112 }
113 }
114
115 public void SpiralCells(int steps, double incAngle, double incRadius, double offsetRadius, double offsetAngle,
116 double[] c)
117 {
118 SetDiff();
119
120 List<Point2D> points = new List<Point2D>();
121
122 int i;
123 double r = offsetRadius;
124 double theta = offsetAngle;
125 for (i = 0; i < steps; i++)
126 {
127 r += incRadius;
128 theta += incAngle;
129
130 int[] coords = PolarToCoordinates(r, theta);
131 points.Add(new Point2D(coords[0], coords[1]));
132 }
133
134 VoronoiDiagram(points, c);
135 }
136
137 public void Spiral(double wid, double hig, double offset)
138 {
139 SetDiff();
140
141 int x, y, z;
142 z = 0;
143 for (x = 0; x < w; x++)
144 {
145 for (y = 0; y < h; y++)
146 {
147 z++;
148 double dx = Math.Abs((w/2) - x);
149 double dy = Math.Abs((h/2) - y);
150 map[x, y] += Math.Sin(dx/wid) + Math.Cos(dy/hig);
151 }
152 }
153 Normalise();
154 }
155 }
156}
diff --git a/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Generators/Voronoi.cs b/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Generators/Voronoi.cs
deleted file mode 100644
index a4966a4..0000000
--- a/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Generators/Voronoi.cs
+++ /dev/null
@@ -1,211 +0,0 @@
1/*
2 * Copyright (c) Contributors, http://opensimulator.org/
3 * See CONTRIBUTORS.TXT for a full list of copyright holders.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
7 * * Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * * Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 * * Neither the name of the OpenSim Project nor the
13 * names of its contributors may be used to endorse or promote products
14 * derived from this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
17 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19 * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
20 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
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
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
25 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */
27
28using System;
29using System.Collections.Generic;
30
31namespace libTerrain
32{
33 partial class Channel
34 {
35 /// <summary>
36 /// Generates a Voronoi diagram (sort of a stained glass effect) which will fill the entire channel
37 /// </summary>
38 /// <remarks>3-Clause BSD Licensed</remarks>
39 /// <param name="pointsPerBlock">The number of generator points in each block</param>
40 /// <param name="blockSize">A multiple of the channel width and height which will have voronoi points generated in it.
41 /// <para>This is to ensure a more even distribution of the points than pure random allocation.</para></param>
42 /// <param name="c">The Voronoi diagram type. Usually an array with values consisting of [-1,1]. Experiment with the chain, you can have as many values as you like.</param>
43 public void VoronoiDiagram(int pointsPerBlock, int blockSize, double[] c)
44 {
45 SetDiff();
46
47 List<Point2D> points = new List<Point2D>();
48 Random generator = new Random(seed);
49
50 // Generate the emitter points
51 int x, y, i;
52 for (x = -blockSize; x < w + blockSize; x += blockSize)
53 {
54 for (y = -blockSize; y < h + blockSize; y += blockSize)
55 {
56 for (i = 0; i < pointsPerBlock; i++)
57 {
58 double pX = x + (generator.NextDouble()*(double) blockSize);
59 double pY = y + (generator.NextDouble()*(double) blockSize);
60
61 points.Add(new Point2D(pX, pY));
62 }
63 }
64 }
65
66 double[] distances = new double[points.Count];
67
68 // Calculate the distance each pixel is from an emitter
69 for (x = 0; x < w; x++)
70 {
71 for (y = 0; y < h; y++)
72 {
73 for (i = 0; i < points.Count; i++)
74 {
75 double dx, dy;
76 dx = Math.Abs((double) x - points[i].x);
77 dy = Math.Abs((double) y - points[i].y);
78
79 distances[i] = (dx*dx + dy*dy);
80 }
81
82 Array.Sort(distances);
83
84 double f = 0.0;
85
86 // Multiply the distances with their 'c' counterpart
87 // ordering the distances descending
88 for (i = 0; i < c.Length; i++)
89 {
90 if (i >= points.Count)
91 break;
92
93 f += c[i]*distances[i];
94 }
95
96 map[x, y] = f;
97 }
98 }
99
100 // Normalise the result
101 Normalise();
102 }
103
104 public void VoronoiDiagram(List<Point2D> points, double[] c)
105 {
106 SetDiff();
107
108 int x, y, i;
109 double[] distances = new double[points.Count];
110
111 // Calculate the distance each pixel is from an emitter
112 for (x = 0; x < w; x++)
113 {
114 for (y = 0; y < h; y++)
115 {
116 for (i = 0; i < points.Count; i++)
117 {
118 double dx, dy;
119 dx = Math.Abs((double) x - points[i].x);
120 dy = Math.Abs((double) y - points[i].y);
121
122 distances[i] = (dx*dx + dy*dy);
123 }
124
125 Array.Sort(distances);
126
127 double f = 0.0;
128
129 // Multiply the distances with their 'c' counterpart
130 // ordering the distances descending
131 for (i = 0; i < c.Length; i++)
132 {
133 if (i >= points.Count)
134 break;
135
136 f += c[i]*distances[i];
137 }
138
139 map[x, y] = f;
140 }
141 }
142
143 // Normalise the result
144 Normalise();
145 }
146
147 public void VoroflatDiagram(int pointsPerBlock, int blockSize)
148 {
149 SetDiff();
150
151 List<Point2D> points = new List<Point2D>();
152 Random generator = new Random(seed);
153
154 // Generate the emitter points
155 int x, y, i;
156 for (x = -blockSize; x < w + blockSize; x += blockSize)
157 {
158 for (y = -blockSize; y < h + blockSize; y += blockSize)
159 {
160 for (i = 0; i < pointsPerBlock; i++)
161 {
162 double pX = x + (generator.NextDouble()*(double) blockSize);
163 double pY = y + (generator.NextDouble()*(double) blockSize);
164
165 points.Add(new Point2D(pX, pY));
166 }
167 }
168 }
169
170 double[] distances = new double[points.Count];
171
172 // Calculate the distance each pixel is from an emitter
173 for (x = 0; x < w; x++)
174 {
175 for (y = 0; y < h; y++)
176 {
177 for (i = 0; i < points.Count; i++)
178 {
179 double dx, dy;
180 dx = Math.Abs((double) x - points[i].x);
181 dy = Math.Abs((double) y - points[i].y);
182
183 distances[i] = (dx*dx + dy*dy);
184 }
185
186 //Array.Sort(distances);
187
188 double f = 0.0;
189
190 double min = double.MaxValue;
191 for (int j = 0; j < distances.Length; j++)
192 {
193 if (distances[j] < min)
194 {
195 min = distances[j];
196 f = j;
197 }
198 }
199
200 // Multiply the distances with their 'c' counterpart
201 // ordering the distances descending
202
203 map[x, y] = f;
204 }
205 }
206
207 // Normalise the result
208 Normalise();
209 }
210 }
211}
diff --git a/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Generators/Worms.cs b/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Generators/Worms.cs
deleted file mode 100644
index d9f0990..0000000
--- a/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Generators/Worms.cs
+++ /dev/null
@@ -1,71 +0,0 @@
1/*
2 * Copyright (c) Contributors, http://opensimulator.org/
3 * See CONTRIBUTORS.TXT for a full list of copyright holders.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
7 * * Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * * Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 * * Neither the name of the OpenSim Project nor the
13 * names of its contributors may be used to endorse or promote products
14 * derived from this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
17 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19 * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
20 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
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
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
25 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */
27
28using System;
29
30namespace libTerrain
31{
32 partial class Channel
33 {
34 /// <summary>
35 /// Generates 'number' of worms which navigate randomly around the landscape creating terrain as they go.
36 /// </summary>
37 /// <param name="number">The number of worms which will traverse the map</param>
38 /// <param name="rounds">The number of steps each worm will traverse</param>
39 /// <param name="movement">The maximum distance each worm will move each step</param>
40 /// <param name="size">The size of the area around the worm modified</param>
41 /// <param name="centerspawn">Do worms start in the middle, or randomly?</param>
42 public void Worms(int number, int rounds, double movement, double size, bool centerspawn)
43 {
44 SetDiff();
45
46 Random random = new Random(seed);
47 int i, j;
48
49 for (i = 0; i < number; i++)
50 {
51 double rx, ry;
52 if (centerspawn)
53 {
54 rx = w/2.0;
55 ry = h/2.0;
56 }
57 else
58 {
59 rx = random.NextDouble()*(w - 1);
60 ry = random.NextDouble()*(h - 1);
61 }
62 for (j = 0; j < rounds; j++)
63 {
64 rx += (random.NextDouble()*movement) - (movement/2.0);
65 ry += (random.NextDouble()*movement) - (movement/2.0);
66 Raise(rx, ry, size, 1.0);
67 }
68 }
69 }
70 }
71}
diff --git a/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Grid.cs b/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Grid.cs
deleted file mode 100644
index a3e24a2..0000000
--- a/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Grid.cs
+++ /dev/null
@@ -1,376 +0,0 @@
1/*
2 * Copyright (c) Contributors, http://opensimulator.org/
3 * See CONTRIBUTORS.TXT for a full list of copyright holders.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
7 * * Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * * Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 * * Neither the name of the OpenSim Project nor the
13 * names of its contributors may be used to endorse or promote products
14 * derived from this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
17 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19 * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
20 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
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
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
25 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */
27
28using System;
29
30namespace libTerrain
31{
32 partial class Channel
33 {
34 public Channel Normalise()
35 {
36 SetDiff();
37
38 double max = FindMax();
39 double min = FindMin();
40
41 int x, y;
42
43 if (max != min)
44 {
45 for (x = 0; x < w; x++)
46 {
47 for (y = 0; y < h; y++)
48 {
49 map[x, y] = (map[x, y] - min)*(1.0/(max - min));
50 }
51 }
52 }
53 else
54 {
55 Fill(0.5);
56 }
57
58 return this;
59 }
60
61 public Channel Normalise(double minv, double maxv)
62 {
63 SetDiff();
64
65 if (minv == maxv)
66 {
67 Fill(minv);
68 return this;
69 }
70
71 double max = FindMax();
72 double min = FindMin();
73
74 int x, y;
75
76 for (x = 0; x < w; x++)
77 {
78 for (y = 0; y < h; y++)
79 {
80 if (min != max)
81 {
82 double val = (map[x, y] - min)*(1.0/(max - min));
83 val *= maxv - minv;
84 val += minv;
85
86 map[x, y] = val;
87 }
88 else
89 {
90 map[x, y] = 0.5;
91 }
92 }
93 }
94
95 return this;
96 }
97
98 public Channel Elevate(double meters)
99 {
100 SetDiff();
101
102 int x, y;
103
104 for (x = 0; x < w; x++)
105 {
106 for (y = 0; y < h; y++)
107 {
108 map[x, y] += meters;
109 }
110 }
111
112 return this;
113 }
114
115
116 public Channel Clip()
117 {
118 int x, y;
119
120 for (x = 0; x < w; x++)
121 {
122 for (y = 0; y < h; y++)
123 {
124 SetClip(x, y, map[x, y]);
125 }
126 }
127
128 return this;
129 }
130
131 public Channel Clip(double min, double max)
132 {
133 int x, y;
134 for (x = 0; x < w; x++)
135 {
136 for (y = 0; y < h; y++)
137 {
138 double val = map[x, y];
139 if (val > max) val = max;
140 if (val < min) val = min;
141
142 Set(x, y, val);
143 }
144 }
145 return this;
146 }
147
148 public Channel Crop(int x1, int y1, int x2, int y2)
149 {
150 int width = x1 - x2 + 1;
151 int height = y1 - y2 + 1;
152 Channel chan = new Channel(width, height);
153
154 int x, y;
155 int nx, ny;
156
157 nx = 0;
158 for (x = x1; x < x2; x++)
159 {
160 ny = 0;
161 for (y = y1; y < y2; y++)
162 {
163 chan.map[nx, ny] = map[x, y];
164
165 ny++;
166 }
167 nx++;
168 }
169
170 return this;
171 }
172
173 public Channel AddClip(Channel other)
174 {
175 SetDiff();
176
177 int x, y;
178 for (x = 0; x < w; x++)
179 {
180 for (y = 0; y < h; y++)
181 {
182 map[x, y] = other.map[x, y];
183 if (map[x, y] > 1)
184 map[x, y] = 1;
185 if (map[x, y] < 0)
186 map[x, y] = 0;
187 }
188 }
189 return this;
190 }
191
192 public void Smooth(double amount)
193 {
194 SetDiff();
195
196 double area = amount;
197 double step = amount/4.0;
198
199 double[,] manipulate = new double[w,h];
200 int x, y;
201 double n, l;
202 for (x = 0; x < w; x++)
203 {
204 for (y = 0; y < h; y++)
205 {
206 double average = 0.0;
207 int avgsteps = 0;
208
209 for (n = 0.0 - area; n < area; n += step)
210 {
211 for (l = 0.0 - area; l < area; l += step)
212 {
213 avgsteps++;
214 average += GetBilinearInterpolate(x + n, y + l);
215 }
216 }
217
218 manipulate[x, y] = average/avgsteps;
219 }
220 }
221 map = manipulate;
222 }
223
224 public void Pertubation(double amount)
225 {
226 SetDiff();
227
228 // Simple pertubation filter
229 double[,] manipulated = new double[w,h];
230 Random generator = new Random(seed); // Seeds FTW!
231 //double amount = 8.0;
232
233 int x, y;
234 for (x = 0; x < w; x++)
235 {
236 for (y = 0; y < h; y++)
237 {
238 double offset_x = (double) x + (generator.NextDouble()*amount) - (amount/2.0);
239 double offset_y = (double) y + (generator.NextDouble()*amount) - (amount/2.0);
240 double p = GetBilinearInterpolate(offset_x, offset_y);
241 manipulated[x, y] = p;
242 }
243 }
244 map = manipulated;
245 }
246
247 public void PertubationMask(Channel mask)
248 {
249 // Simple pertubation filter
250 double[,] manipulated = new double[w,h];
251 Random generator = new Random(seed); // Seeds FTW!
252 //double amount = 8.0;
253
254 double amount;
255
256 int x, y;
257 for (x = 0; x < w; x++)
258 {
259 for (y = 0; y < h; y++)
260 {
261 amount = mask.map[x, y];
262 double offset_x = (double) x + (generator.NextDouble()*amount) - (amount/2.0);
263 double offset_y = (double) y + (generator.NextDouble()*amount) - (amount/2.0);
264
265 if (offset_x > w)
266 offset_x = w - 1;
267 if (offset_y > h)
268 offset_y = h - 1;
269 if (offset_y < 0)
270 offset_y = 0;
271 if (offset_x < 0)
272 offset_x = 0;
273
274 double p = GetBilinearInterpolate(offset_x, offset_y);
275 manipulated[x, y] = p;
276 SetDiff(x, y);
277 }
278 }
279 map = manipulated;
280 }
281
282 public void Distort(Channel mask, double str)
283 {
284 // Simple pertubation filter
285 double[,] manipulated = new double[w,h];
286
287 double amount;
288
289 int x, y;
290 for (x = 0; x < w; x++)
291 {
292 for (y = 0; y < h; y++)
293 {
294 amount = mask.map[x, y];
295 double offset_x = (double) x + (amount*str) - (0.5*str);
296 double offset_y = (double) y + (amount*str) - (0.5*str);
297
298 if (offset_x > w)
299 offset_x = w - 1;
300 if (offset_y > h)
301 offset_y = h - 1;
302 if (offset_y < 0)
303 offset_y = 0;
304 if (offset_x < 0)
305 offset_x = 0;
306
307 double p = GetBilinearInterpolate(offset_x, offset_y);
308 manipulated[x, y] = p;
309 SetDiff(x, y);
310 }
311 }
312 map = manipulated;
313 }
314
315 public void Distort(Channel mask, Channel mask2, double str)
316 {
317 // Simple pertubation filter
318 double[,] manipulated = new double[w,h];
319
320 double amountX;
321 double amountY;
322
323 int x, y;
324 for (x = 0; x < w; x++)
325 {
326 for (y = 0; y < h; y++)
327 {
328 amountX = mask.map[x, y];
329 amountY = mask2.map[x, y];
330 double offset_x = (double) x + (amountX*str) - (0.5*str);
331 double offset_y = (double) y + (amountY*str) - (0.5*str);
332
333 if (offset_x > w)
334 offset_x = w - 1;
335 if (offset_y > h)
336 offset_y = h - 1;
337 if (offset_y < 0)
338 offset_y = 0;
339 if (offset_x < 0)
340 offset_x = 0;
341
342 double p = GetBilinearInterpolate(offset_x, offset_y);
343 manipulated[x, y] = p;
344 SetDiff(x, y);
345 }
346 }
347 map = manipulated;
348 }
349
350 public Channel Blend(Channel other, double amount)
351 {
352 int x, y;
353 for (x = 0; x < w; x++)
354 {
355 for (y = 0; y < h; y++)
356 {
357 Set(x, y, Tools.LinearInterpolate(map[x, y], other.map[x, y], amount));
358 }
359 }
360 return this;
361 }
362
363 public Channel Blend(Channel other, Channel amount)
364 {
365 int x, y;
366 for (x = 0; x < w; x++)
367 {
368 for (y = 0; y < h; y++)
369 {
370 Set(x, y, Tools.LinearInterpolate(map[x, y], other.map[x, y], amount.map[x, y]));
371 }
372 }
373 return this;
374 }
375 }
376}
diff --git a/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Manipulators/AerobicErosion.cs b/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Manipulators/AerobicErosion.cs
deleted file mode 100644
index 6a846cd..0000000
--- a/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Manipulators/AerobicErosion.cs
+++ /dev/null
@@ -1,211 +0,0 @@
1/*
2 * Copyright (c) Contributors, http://opensimulator.org/
3 * See CONTRIBUTORS.TXT for a full list of copyright holders.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
7 * * Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * * Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 * * Neither the name of the OpenSim Project nor the
13 * names of its contributors may be used to endorse or promote products
14 * derived from this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
17 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19 * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
20 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
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
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
25 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */
27
28using System;
29
30namespace libTerrain
31{
32 partial class Channel
33 {
34 // Ideas for Aerobic erosion
35 //
36 // Unlike thermal (gravity) and hydraulic (water suspension)
37 // aerobic erosion should displace mass by moving sediment
38 // in "hops". The length of the hop being dictated by the
39 // presence of sharp cliffs and wind speed.
40
41 // The ability to pickup sediment is defined by the total
42 // surface area, such that:
43 // 0 0 0
44 // 0 1 0
45 // 0 0 0
46 // Would be the best possible value for sediment to be
47 // picked up (total difference = 8) and flatter land
48 // will erode less quickly.
49
50 // Suspended particles assist the erosion process by hitting
51 // the surface and chiselling additional particles off faster
52 // than alone.
53
54 // Particles are deposited when one of two conditions is met
55 // First:
56 // When particles hit a wall - such that the
57 // wind direction points at a difference >= the
58 // deposition mininum talus.
59 // Second:
60 // When wind speed is lowered to below the minimum
61 // required for transit. An idea for this is to
62 // use the navier-stokes algorithms for simulating
63 // pressure across the terrain.
64
65 /// <summary>
66 /// An experimental erosion algorithm developed by Adam. Moves sediment by factoring the surface area of each height point.
67 /// </summary>
68 /// <param name="windspeed">0..1 The speed of the wind</param>
69 /// <param name="pickup_talus_minimum">The minimum angle at which rock is eroded 0..1 (recommended: <= 0.30)</param>
70 /// <param name="drop_talus_minimum">The minimum angle at which rock is dropped 0..1 (recommended: >= 0.00)</param>
71 /// <param name="carry">The percentage of rock which can be picked up to pickup 0..1</param>
72 /// <param name="rounds">The number of erosion rounds (recommended: 25+)</param>
73 /// <param name="lowest">Drop sediment at the lowest point?</param>
74 public void AerobicErosion(double windspeed, double pickupTalusMinimum, double dropTalusMinimum, double carry,
75 int rounds, bool lowest, bool usingFluidDynamics)
76 {
77 bool debugImages = false;
78
79 Channel wind = new Channel(w, h);
80 Channel sediment = new Channel(w, h);
81 int x, y, i, j;
82
83 Normalise();
84
85 wind = Copy();
86 wind.Noise();
87
88 if (debugImages)
89 wind.SaveImage("testimg/wind_start.png");
90
91 if (usingFluidDynamics)
92 {
93 wind.navierStokes(20, 0.1, 0.0, 0.0);
94 }
95 else
96 {
97 wind.Pertubation(30);
98 }
99
100 if (debugImages)
101 wind.SaveImage("testimg/wind_begin.png");
102
103 for (i = 0; i < rounds; i++)
104 {
105 // Convert some rocks to sand
106 for (x = 1; x < w - 1; x++)
107 {
108 for (y = 1; y < h - 1; y++)
109 {
110 double me = Get(x, y);
111 double surfacearea = 0.3; // Everything will erode even if it's flat. Just slower.
112
113 for (j = 0; j < 9; j++)
114 {
115 int[] coords = Neighbours(NeighbourSystem.Moore, j);
116 double target = Get(x + coords[0], y + coords[1]);
117
118 surfacearea += Math.Abs(target - me);
119 }
120
121 double amount = surfacearea*wind.map[x, y]*carry;
122
123 if (amount < 0)
124 amount = 0;
125
126 if (surfacearea > pickupTalusMinimum)
127 {
128 Set(x, y, map[x, y] - amount);
129 sediment.map[x, y] += amount;
130 }
131 }
132 }
133
134 if (usingFluidDynamics)
135 {
136 sediment.navierStokes(7, 0.1, 0.0, 0.1);
137
138 Channel noiseChan = new Channel(w, h);
139 noiseChan.Noise();
140 wind.Blend(noiseChan, 0.01);
141
142 wind.navierStokes(10, 0.1, 0.01, 0.01);
143
144 sediment.Distort(wind, windspeed);
145 }
146 else
147 {
148 wind.Pertubation(15); // Can do better later
149 wind.seed++;
150 sediment.Pertubation(10); // Sediment is blown around a bit
151 sediment.seed++;
152 }
153
154 if (debugImages)
155 wind.SaveImage("testimg/wind_" + i.ToString() + ".png");
156
157 // Convert some sand to rock
158 for (x = 1; x < w - 1; x++)
159 {
160 for (y = 1; y < h - 1; y++)
161 {
162 double me = Get(x, y);
163 double surfacearea = 0.01; // Flat land does not get deposition
164 double min = double.MaxValue;
165 int[] minside = new int[2];
166
167 for (j = 0; j < 9; j++)
168 {
169 int[] coords = Neighbours(NeighbourSystem.Moore, j);
170 double target = Get(x + coords[0], y + coords[1]);
171
172 surfacearea += Math.Abs(target - me);
173
174 if (target < min && lowest)
175 {
176 minside = (int[]) coords.Clone();
177 min = target;
178 }
179 }
180
181 double amount = surfacearea*(1.0 - wind.map[x, y])*carry;
182
183 if (amount < 0)
184 amount = 0;
185
186 if (surfacearea > dropTalusMinimum)
187 {
188 Set(x + minside[0], y + minside[1], map[x + minside[0], y + minside[1]] + amount);
189 sediment.map[x, y] -= amount;
190 }
191 }
192 }
193
194 if (debugImages)
195 sediment.SaveImage("testimg/sediment_" + i.ToString() + ".png");
196
197 wind.Normalise();
198 wind *= windspeed;
199
200 Normalise();
201 }
202
203 Channel myself = this;
204 myself += sediment;
205 myself.Normalise();
206
207 if (debugImages)
208 SaveImage("testimg/output.png");
209 }
210 }
211}
diff --git a/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Manipulators/HydraulicErosion.cs b/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Manipulators/HydraulicErosion.cs
deleted file mode 100644
index 608e0e3..0000000
--- a/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Manipulators/HydraulicErosion.cs
+++ /dev/null
@@ -1,144 +0,0 @@
1/*
2 * Copyright (c) Contributors, http://opensimulator.org/
3 * See CONTRIBUTORS.TXT for a full list of copyright holders.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
7 * * Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * * Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 * * Neither the name of the OpenSim Project nor the
13 * names of its contributors may be used to endorse or promote products
14 * derived from this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
17 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19 * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
20 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
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
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
25 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */
27
28using System;
29
30namespace libTerrain
31{
32 partial class Channel
33 {
34 public void HydraulicErosion(Channel rain, double evaporation, double solubility, int frequency, int rounds)
35 {
36 SetDiff();
37
38 Channel water = new Channel(w, h);
39 Channel sediment = new Channel(w, h);
40 Channel terrain = this;
41 Channel waterFlow = new Channel(w, h);
42
43 NeighbourSystem type = NeighbourSystem.Moore;
44 int NEIGHBOUR_ME = 4;
45
46 int NEIGHBOUR_MAX = type == NeighbourSystem.Moore ? 9 : 5;
47
48 for (int i = 0; i < rounds; i++)
49 {
50 water += rain;
51
52 sediment = terrain*water;
53 terrain -= sediment;
54
55 for (int x = 1; x < w - 1; x++)
56 {
57 for (int y = 1; y < h - 1; y++)
58 {
59 double[] heights = new double[NEIGHBOUR_MAX];
60 double[] diffs = new double[NEIGHBOUR_MAX];
61
62 double heightCenter = map[x, y];
63
64 for (int j = 0; j < NEIGHBOUR_MAX; j++)
65 {
66 if (j != NEIGHBOUR_ME)
67 {
68 int[] coords = Neighbours(type, j);
69 coords[0] += x;
70 coords[1] += y;
71
72 heights[j] = map[coords[0], coords[1]] + water.map[coords[0], coords[1]] +
73 sediment.map[coords[0], coords[1]];
74 diffs[j] = heightCenter - heights[j];
75 }
76 }
77
78 double totalHeight = 0;
79 double totalHeightDiff = 0;
80 int totalCellsCounted = 1;
81
82 for (int j = 0; j < NEIGHBOUR_MAX; j++)
83 {
84 if (j != NEIGHBOUR_ME)
85 {
86 if (diffs[j] > 0)
87 {
88 totalHeight += heights[j];
89 totalHeightDiff += diffs[j];
90 totalCellsCounted++;
91 }
92 }
93 }
94
95 if (totalCellsCounted == 1)
96 continue;
97
98 double averageHeight = totalHeight/totalCellsCounted;
99 double waterAmount = Math.Min(water.map[x, y], heightCenter - averageHeight);
100
101 // TODO: Check this.
102 waterFlow.map[x, y] += waterFlow.map[x, y] - waterAmount;
103
104 double totalInverseDiff = waterAmount/totalHeightDiff;
105
106 for (int j = 0; j < NEIGHBOUR_MAX; j++)
107 {
108 if (j != NEIGHBOUR_ME)
109 {
110 int[] coords = Neighbours(type, j);
111 coords[0] += x;
112 coords[1] += y;
113
114 if (diffs[j] > 0)
115 {
116 waterFlow.SetWrap(coords[0], coords[1],
117 waterFlow.map[coords[0], coords[1]] + diffs[j]*totalInverseDiff);
118 }
119 }
120 }
121 }
122 }
123
124 water += waterFlow;
125 waterFlow.Fill(0);
126
127 water *= evaporation;
128
129 for (int x = 0; x < w; x++)
130 {
131 for (int y = 0; y < h; y++)
132 {
133 double deposition = sediment.map[x, y] - water.map[x, y]*solubility;
134 if (deposition > 0)
135 {
136 sediment.map[x, y] -= deposition;
137 terrain.map[x, y] += deposition;
138 }
139 }
140 }
141 }
142 }
143 }
144}
diff --git a/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Manipulators/NavierStokes.cs b/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Manipulators/NavierStokes.cs
deleted file mode 100644
index 8f12637..0000000
--- a/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Manipulators/NavierStokes.cs
+++ /dev/null
@@ -1,307 +0,0 @@
1/*
2 * Copyright (c) Contributors, http://opensimulator.org/
3 * See CONTRIBUTORS.TXT for a full list of copyright holders.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
7 * * Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * * Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 * * Neither the name of the OpenSim Project nor the
13 * names of its contributors may be used to endorse or promote products
14 * derived from this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
17 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19 * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
20 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
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
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
25 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */
27
28namespace libTerrain
29{
30 partial class Channel
31 {
32 // Navier Stokes Algorithms ported from
33 // "Real-Time Fluid Dynamics for Games" by Jos Stam.
34 // presented at GDC 2003.
35
36 // Poorly ported from C++. (I gave up making it properly native somewhere after nsSetBnd)
37
38 private static int nsIX(int i, int j, int N)
39 {
40 return ((i) + (N + 2)*(j));
41 }
42
43// TODO: unused
44// private static void nsSwap(ref double x0, ref double x)
45// {
46// double tmp = x0;
47// x0 = x;
48// x = tmp;
49// }
50
51 private static void nsSwap(ref double[] x0, ref double[] x)
52 {
53 double[] tmp = x0;
54 x0 = x;
55 x = tmp;
56 }
57
58 private void nsAddSource(int N, ref double[] x, ref double[] s, double dt)
59 {
60 int i;
61 int size = (N + 2)*(N + 2);
62 for (i = 0; i < size; i++)
63 {
64 x[i] += dt*s[i];
65 }
66 }
67
68 private void nsSetBnd(int N, int b, ref double[] x)
69 {
70 int i;
71 for (i = 0; i <= N; i++)
72 {
73 x[nsIX(0, i, N)] = b == 1 ? -x[nsIX(1, i, N)] : x[nsIX(1, i, N)];
74 x[nsIX(0, N + 1, N)] = b == 1 ? -x[nsIX(N, i, N)] : x[nsIX(N, i, N)];
75 x[nsIX(i, 0, N)] = b == 2 ? -x[nsIX(i, 1, N)] : x[nsIX(i, 1, N)];
76 x[nsIX(i, N + 1, N)] = b == 2 ? -x[nsIX(i, N, N)] : x[nsIX(i, N, N)];
77 }
78 x[nsIX(0, 0, N)] = 0.5f*(x[nsIX(1, 0, N)] + x[nsIX(0, 1, N)]);
79 x[nsIX(0, N + 1, N)] = 0.5f*(x[nsIX(1, N + 1, N)] + x[nsIX(0, N, N)]);
80 x[nsIX(N + 1, 0, N)] = 0.5f*(x[nsIX(N, 0, N)] + x[nsIX(N + 1, 1, N)]);
81 x[nsIX(N + 1, N + 1, N)] = 0.5f*(x[nsIX(N, N + 1, N)] + x[nsIX(N + 1, N, N)]);
82 }
83
84 private void nsLinSolve(int N, int b, ref double[] x, ref double[] x0, double a, double c)
85 {
86 int i, j;
87 for (i = 1; i <= N; i++)
88 {
89 for (j = 1; j <= N; j++)
90 {
91 x[nsIX(i, j, N)] = (x0[nsIX(i, j, N)] + a*
92 (x[nsIX(i - 1, j, N)] +
93 x[nsIX(i + 1, j, N)] +
94 x[nsIX(i, j - 1, N)] + x[nsIX(i, j + 1, N)])
95 )/c;
96 }
97 }
98
99 nsSetBnd(N, b, ref x);
100 }
101
102 private void nsDiffuse(int N, int b, ref double[] x, ref double[] x0, double diff, double dt)
103 {
104 double a = dt*diff*N*N;
105 nsLinSolve(N, b, ref x, ref x0, a, 1 + 4*a);
106 }
107
108 private void nsAdvect(int N, int b, ref double[] d, ref double[] d0, ref double[] u, ref double[] v, double dt)
109 {
110 int i, j, i0, j0, i1, j1;
111 double x, y, s0, t0, s1, t1, dt0;
112
113 dt0 = dt*N;
114
115 for (i = 1; i <= N; i++)
116 {
117 for (j = 1; j <= N; j++)
118 {
119 x = i - dt0*u[nsIX(i, j, N)];
120 y = j - dt0*v[nsIX(i, j, N)];
121
122 if (x < 0.5)
123 x = 0.5;
124 if (x > N + 0.5)
125 x = N + 0.5;
126 i0 = (int) x;
127 i1 = i0 + 1;
128
129 if (y < 0.5)
130 y = 0.5;
131 if (y > N + 0.5)
132 y = N + 0.5;
133 j0 = (int) y;
134 j1 = j0 + 1;
135
136 s1 = x - i0;
137 s0 = 1 - s1;
138 t1 = y - j0;
139 t0 = 1 - t1;
140
141 d[nsIX(i, j, N)] = s0*(t0*d0[nsIX(i0, j0, N)] + t1*d0[nsIX(i0, j1, N)]) +
142 s1*(t0*d0[nsIX(i1, j0, N)] + t1*d0[nsIX(i1, j1, N)]);
143 }
144 }
145
146 nsSetBnd(N, b, ref d);
147 }
148
149 public void nsProject(int N, ref double[] u, ref double[] v, ref double[] p, ref double[] div)
150 {
151 int i, j;
152
153 for (i = 1; i <= N; i++)
154 {
155 for (j = 1; j <= N; j++)
156 {
157 div[nsIX(i, j, N)] = -0.5*
158 (u[nsIX(i + 1, j, N)] - u[nsIX(i - 1, j, N)] + v[nsIX(i, j + 1, N)] -
159 v[nsIX(i, j - 1, N)])/N;
160 p[nsIX(i, j, N)] = 0;
161 }
162 }
163
164 nsSetBnd(N, 0, ref div);
165 nsSetBnd(N, 0, ref p);
166
167 nsLinSolve(N, 0, ref p, ref div, 1, 4);
168
169 for (i = 1; i <= N; i++)
170 {
171 for (j = 1; j <= N; j++)
172 {
173 u[nsIX(i, j, N)] -= 0.5*N*(p[nsIX(i + 1, j, N)] - p[nsIX(i - 1, j, N)]);
174 v[nsIX(i, j, N)] -= 0.5*N*(p[nsIX(i, j + 1, N)] - p[nsIX(i, j - 1, N)]);
175 }
176 }
177
178 nsSetBnd(N, 1, ref u);
179 nsSetBnd(N, 2, ref v);
180 }
181
182 private void nsDensStep(int N, ref double[] x, ref double[] x0, ref double[] u, ref double[] v, double diff,
183 double dt)
184 {
185 nsAddSource(N, ref x, ref x0, dt);
186 nsSwap(ref x0, ref x);
187 nsDiffuse(N, 0, ref x, ref x0, diff, dt);
188 nsSwap(ref x0, ref x);
189 nsAdvect(N, 0, ref x, ref x0, ref u, ref v, dt);
190 }
191
192 private void nsVelStep(int N, ref double[] u, ref double[] v, ref double[] u0, ref double[] v0, double visc,
193 double dt)
194 {
195 nsAddSource(N, ref u, ref u0, dt);
196 nsAddSource(N, ref v, ref v0, dt);
197 nsSwap(ref u0, ref u);
198 nsDiffuse(N, 1, ref u, ref u0, visc, dt);
199 nsSwap(ref v0, ref v);
200 nsDiffuse(N, 2, ref v, ref v0, visc, dt);
201 nsProject(N, ref u, ref v, ref u0, ref v0);
202 nsSwap(ref u0, ref u);
203 nsSwap(ref v0, ref v);
204 nsAdvect(N, 1, ref u, ref u0, ref u0, ref v0, dt);
205 nsAdvect(N, 2, ref v, ref v0, ref u0, ref v0, dt);
206 nsProject(N, ref u, ref v, ref u0, ref v0);
207 }
208
209 private void nsBufferToDoubles(ref double[] dens, int N, ref double[,] doubles)
210 {
211 int i;
212 int j;
213
214 for (i = 1; i <= N; i++)
215 {
216 for (j = 1; j <= N; j++)
217 {
218 doubles[i - 1, j - 1] = dens[nsIX(i, j, N)];
219 }
220 }
221 }
222
223 private void nsDoublesToBuffer(double[,] doubles, int N, ref double[] dens)
224 {
225 int i;
226 int j;
227
228 for (i = 1; i <= N; i++)
229 {
230 for (j = 1; j <= N; j++)
231 {
232 dens[nsIX(i, j, N)] = doubles[i - 1, j - 1];
233 }
234 }
235 }
236
237 private void nsSimulate(int N, int rounds, double dt, double diff, double visc)
238 {
239 int size = (N*2)*(N*2);
240
241 double[] u = new double[size]; // Force, X axis
242 double[] v = new double[size]; // Force, Y axis
243 double[] u_prev = new double[size];
244 double[] v_prev = new double[size];
245 double[] dens = new double[size];
246 double[] dens_prev = new double[size];
247
248 nsDoublesToBuffer(map, N, ref dens);
249 nsDoublesToBuffer(map, N, ref dens_prev);
250
251 for (int i = 0; i < rounds; i++)
252 {
253 u_prev = u;
254 v_prev = v;
255 dens_prev = dens;
256
257 nsVelStep(N, ref u, ref v, ref u_prev, ref v_prev, visc, dt);
258 nsDensStep(N, ref dens, ref dens_prev, ref u, ref v, diff, dt);
259 }
260
261 nsBufferToDoubles(ref dens, N, ref map);
262 }
263
264 /// <summary>
265 /// Performs computational fluid dynamics on a channel
266 /// </summary>
267 /// <param name="rounds">The number of steps to perform (Recommended: 20)</param>
268 /// <param name="dt">Delta Time - The time between steps (Recommended: 0.1)</param>
269 /// <param name="diff">Fluid diffusion rate (Recommended: 0.0)</param>
270 /// <param name="visc">Fluid viscosity (Recommended: 0.0)</param>
271 public void navierStokes(int rounds, double dt, double diff, double visc)
272 {
273 nsSimulate(h, rounds, dt, diff, visc);
274 }
275
276 public void navierStokes(int rounds, double dt, double diff, double visc, ref double[,] uret, ref double[,] vret)
277 {
278 int N = h;
279
280 int size = (N*2)*(N*2);
281
282 double[] u = new double[size]; // Force, X axis
283 double[] v = new double[size]; // Force, Y axis
284 double[] u_prev = new double[size];
285 double[] v_prev = new double[size];
286 double[] dens = new double[size];
287 double[] dens_prev = new double[size];
288
289 nsDoublesToBuffer(map, N, ref dens);
290 nsDoublesToBuffer(map, N, ref dens_prev);
291
292 for (int i = 0; i < rounds; i++)
293 {
294 u_prev = u;
295 v_prev = v;
296 dens_prev = dens;
297
298 nsVelStep(N, ref u, ref v, ref u_prev, ref v_prev, visc, dt);
299 nsDensStep(N, ref dens, ref dens_prev, ref u, ref v, diff, dt);
300 }
301
302 nsBufferToDoubles(ref u, N, ref uret);
303 nsBufferToDoubles(ref v, N, ref vret);
304 nsBufferToDoubles(ref dens, N, ref map);
305 }
306 }
307}
diff --git a/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Manipulators/ThermalWeathering.cs b/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Manipulators/ThermalWeathering.cs
deleted file mode 100644
index 532c2d6..0000000
--- a/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Manipulators/ThermalWeathering.cs
+++ /dev/null
@@ -1,107 +0,0 @@
1/*
2 * Copyright (c) Contributors, http://opensimulator.org/
3 * See CONTRIBUTORS.TXT for a full list of copyright holders.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
7 * * Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * * Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 * * Neither the name of the OpenSim Project nor the
13 * names of its contributors may be used to endorse or promote products
14 * derived from this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
17 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19 * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
20 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
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
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
25 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */
27
28namespace libTerrain
29{
30 partial class Channel
31 {
32 /// <summary>
33 /// A thermal weathering implementation based on Musgrave's original 1989 algorithm. This is Adam's custom implementation which may differ slightly from the original.
34 /// </summary>
35 /// <param name="talus">The rock angle (represented as a dy/dx ratio) at which point it will be succeptible to breakage</param>
36 /// <param name="rounds">The number of erosion rounds</param>
37 /// <param name="c">The amount of rock to carry each round</param>
38 public Channel ThermalWeathering(double talus, int rounds, double c)
39 {
40 SetDiff();
41
42 double[,] lastFrame;
43 double[,] thisFrame;
44
45 lastFrame = (double[,]) map.Clone();
46 thisFrame = (double[,]) map.Clone();
47
48 NeighbourSystem type = NeighbourSystem.Moore;
49 // Using moore neighbourhood (twice as computationally expensive)
50 int NEIGHBOUR_ME = 4; // I am always 4 in both systems.
51
52 int NEIGHBOUR_MAX = type == NeighbourSystem.Moore ? 9 : 5;
53
54 int frames = rounds; // Number of thermal erosion iterations to run
55 int i, j;
56 int x, y;
57
58 for (i = 0; i < frames; i++)
59 {
60 for (x = 0; x < w; x++)
61 {
62 for (y = 0; y < h; y++)
63 {
64 for (j = 0; j < NEIGHBOUR_MAX; j++)
65 {
66 if (j != NEIGHBOUR_ME)
67 {
68 int[] coords = Neighbours(type, j);
69
70 coords[0] += x;
71 coords[1] += y;
72
73 if (coords[0] > w - 1)
74 coords[0] = w - 1;
75 if (coords[1] > h - 1)
76 coords[1] = h - 1;
77 if (coords[0] < 0)
78 coords[0] = 0;
79 if (coords[1] < 0)
80 coords[1] = 0;
81
82 double heightF = thisFrame[x, y];
83 double target = thisFrame[coords[0], coords[1]];
84
85 if (target > heightF + talus)
86 {
87 double calc = c*((target - heightF) - talus);
88 heightF += calc;
89 target -= calc;
90 }
91
92 thisFrame[x, y] = heightF;
93 thisFrame[coords[0], coords[1]] = target;
94 }
95 }
96 }
97 }
98 lastFrame = (double[,]) thisFrame.Clone();
99 }
100
101 map = thisFrame;
102
103 Normalise(); // Just to guaruntee a smooth 0..1 value
104 return this;
105 }
106 }
107}
diff --git a/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Neighbours.cs b/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Neighbours.cs
deleted file mode 100644
index d1027a3..0000000
--- a/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Neighbours.cs
+++ /dev/null
@@ -1,136 +0,0 @@
1/*
2 * Copyright (c) Contributors, http://opensimulator.org/
3 * See CONTRIBUTORS.TXT for a full list of copyright holders.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
7 * * Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * * Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 * * Neither the name of the OpenSim Project nor the
13 * names of its contributors may be used to endorse or promote products
14 * derived from this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
17 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19 * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
20 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
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
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
25 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */
27
28namespace libTerrain
29{
30 partial class Channel
31 {
32 private enum NeighbourSystem
33 {
34 Moore,
35 VonNeumann
36 } ;
37
38 private int[] Neighbours(NeighbourSystem type, int index)
39 {
40 int[] coord = new int[2];
41
42 index++;
43
44 switch (type)
45 {
46 case NeighbourSystem.Moore:
47 switch (index)
48 {
49 case 1:
50 coord[0] = -1;
51 coord[1] = -1;
52 break;
53
54 case 2:
55 coord[0] = -0;
56 coord[1] = -1;
57 break;
58
59 case 3:
60 coord[0] = +1;
61 coord[1] = -1;
62 break;
63
64 case 4:
65 coord[0] = -1;
66 coord[1] = -0;
67 break;
68
69 case 5:
70 coord[0] = -0;
71 coord[1] = -0;
72 break;
73
74 case 6:
75 coord[0] = +1;
76 coord[1] = -0;
77 break;
78
79 case 7:
80 coord[0] = -1;
81 coord[1] = +1;
82 break;
83
84 case 8:
85 coord[0] = -0;
86 coord[1] = +1;
87 break;
88
89 case 9:
90 coord[0] = +1;
91 coord[1] = +1;
92 break;
93
94 default:
95 break;
96 }
97 break;
98
99 case NeighbourSystem.VonNeumann:
100 switch (index)
101 {
102 case 1:
103 coord[0] = 0;
104 coord[1] = -1;
105 break;
106
107 case 2:
108 coord[0] = -1;
109 coord[1] = 0;
110 break;
111
112 case 3:
113 coord[0] = +1;
114 coord[1] = 0;
115 break;
116
117 case 4:
118 coord[0] = 0;
119 coord[1] = +1;
120 break;
121
122 case 5:
123 coord[0] = -0;
124 coord[1] = -0;
125 break;
126
127 default:
128 break;
129 }
130 break;
131 }
132
133 return coord;
134 }
135 }
136}
diff --git a/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Operators.cs b/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Operators.cs
deleted file mode 100644
index 6e1386d..0000000
--- a/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Operators.cs
+++ /dev/null
@@ -1,239 +0,0 @@
1/*
2 * Copyright (c) Contributors, http://opensimulator.org/
3 * See CONTRIBUTORS.TXT for a full list of copyright holders.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
7 * * Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * * Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 * * Neither the name of the OpenSim Project nor the
13 * names of its contributors may be used to endorse or promote products
14 * derived from this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
17 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19 * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
20 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
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
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
25 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */
27
28using System;
29
30namespace libTerrain
31{
32 partial class Channel
33 {
34 /* Operator combination of channel datatypes */
35
36 public static Channel operator +(Channel A, Channel B)
37 {
38 if (A.h != B.h)
39 throw new Exception("Cannot add heightmaps, of different height.");
40 if (A.w != B.w)
41 throw new Exception("Cannot add heightmaps, of different width.");
42
43 int x, y;
44
45 for (x = 0; x < A.w; x++)
46 {
47 for (y = 0; y < A.h; y++)
48 {
49 if (B.map[x, y] != 0)
50 A.SetDiff(x, y);
51
52 A.map[x, y] += B.map[x, y];
53 }
54 }
55
56 return A;
57 }
58
59 public static Channel operator *(Channel A, Channel B)
60 {
61 if (A.h != B.h)
62 throw new Exception("Cannot multiply heightmaps, of different height.");
63 if (A.w != B.w)
64 throw new Exception("Cannot multiply heightmaps, of different width.");
65
66 int x, y;
67
68 for (x = 0; x < A.w; x++)
69 {
70 for (y = 0; y < A.h; y++)
71 {
72 A.map[x, y] *= B.map[x, y];
73 }
74 }
75
76 A.SetDiff();
77
78 return A;
79 }
80
81 public static Channel operator -(Channel A, Channel B)
82 {
83 if (A.h != B.h)
84 throw new Exception("Cannot subtract heightmaps, of different height.");
85 if (A.w != B.w)
86 throw new Exception("Cannot subtract heightmaps, of different width.");
87
88 int x, y;
89
90 for (x = 0; x < A.w; x++)
91 {
92 for (y = 0; y < A.h; y++)
93 {
94 if (B.map[x, y] != 0)
95 A.SetDiff(x, y);
96 A.map[x, y] -= B.map[x, y];
97 }
98 }
99
100 return A;
101 }
102
103 public static Channel operator /(Channel A, Channel B)
104 {
105 if (A.h != B.h)
106 throw new Exception("Cannot divide heightmaps, of different height.");
107 if (A.w != B.w)
108 throw new Exception("Cannot divide heightmaps, of different width.");
109
110 int x, y;
111
112 for (x = 0; x < A.w; x++)
113 {
114 for (y = 0; y < A.h; y++)
115 {
116 A.map[x, y] /= B.map[x, y];
117 }
118 }
119
120 A.SetDiff();
121
122 return A;
123 }
124
125 public static Channel operator ^(Channel A, Channel B)
126 {
127 if (A.h != B.h)
128 throw new Exception("Cannot divide heightmaps, of different height.");
129 if (A.w != B.w)
130 throw new Exception("Cannot divide heightmaps, of different width.");
131
132 int x, y;
133
134 for (x = 0; x < A.w; x++)
135 {
136 for (y = 0; y < A.h; y++)
137 {
138 A.map[x, y] = Math.Pow(A.map[x, y], B.map[x, y]);
139 }
140 }
141
142 A.SetDiff();
143
144 return A;
145 }
146
147
148 /* Operator combination of channel and double datatypes */
149
150 public static Channel operator +(Channel A, double B)
151 {
152 int x, y;
153
154 for (x = 0; x < A.w; x++)
155 {
156 for (y = 0; y < A.h; y++)
157 {
158 A.map[x, y] += B;
159 }
160 }
161
162 if (B != 0)
163 A.SetDiff();
164
165 return A;
166 }
167
168 public static Channel operator -(Channel A, double B)
169 {
170 int x, y;
171
172 for (x = 0; x < A.w; x++)
173 {
174 for (y = 0; y < A.h; y++)
175 {
176 A.map[x, y] -= B;
177 }
178 }
179
180 if (B != 0)
181 A.SetDiff();
182
183 return A;
184 }
185
186 public static Channel operator *(Channel A, double B)
187 {
188 int x, y;
189
190 for (x = 0; x < A.w; x++)
191 {
192 for (y = 0; y < A.h; y++)
193 {
194 A.map[x, y] *= B;
195 }
196 }
197
198 if (B != 1)
199 A.SetDiff();
200
201 return A;
202 }
203
204 public static Channel operator /(Channel A, double B)
205 {
206 int x, y;
207
208 for (x = 0; x < A.w; x++)
209 {
210 for (y = 0; y < A.h; y++)
211 {
212 A.map[x, y] /= B;
213 }
214 }
215
216 if (B != 1)
217 A.SetDiff();
218
219 return A;
220 }
221
222 public static Channel operator ^(Channel A, double B)
223 {
224 int x, y;
225
226 for (x = 0; x < A.w; x++)
227 {
228 for (y = 0; y < A.h; y++)
229 {
230 A.map[x, y] = Math.Pow(A.map[x, y], B);
231 }
232 }
233
234 A.SetDiff();
235
236 return A;
237 }
238 }
239}
diff --git a/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Tools/Point2D.cs b/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Tools/Point2D.cs
deleted file mode 100644
index 19a09a4..0000000
--- a/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Tools/Point2D.cs
+++ /dev/null
@@ -1,41 +0,0 @@
1/*
2 * Copyright (c) Contributors, http://opensimulator.org/
3 * See CONTRIBUTORS.TXT for a full list of copyright holders.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
7 * * Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * * Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 * * Neither the name of the OpenSim Project nor the
13 * names of its contributors may be used to endorse or promote products
14 * derived from this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
17 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19 * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
20 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
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
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
25 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */
27
28namespace libTerrain
29{
30 public class Point2D
31 {
32 public double x;
33 public double y;
34
35 public Point2D(double X, double Y)
36 {
37 x = X;
38 y = Y;
39 }
40 }
41}
diff --git a/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Tools/Tools.cs b/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Tools/Tools.cs
deleted file mode 100644
index b653971..0000000
--- a/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Tools/Tools.cs
+++ /dev/null
@@ -1,59 +0,0 @@
1/*
2 * Copyright (c) Contributors, http://opensimulator.org/
3 * See CONTRIBUTORS.TXT for a full list of copyright holders.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
7 * * Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * * Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 * * Neither the name of the OpenSim Project nor the
13 * names of its contributors may be used to endorse or promote products
14 * derived from this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
17 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19 * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
20 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
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
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
25 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */
27
28using System;
29
30namespace libTerrain
31{
32 internal class Tools
33 {
34 public static double LinearInterpolate(double a, double b, double amount)
35 {
36 return a + ((b - a)*amount);
37 }
38
39 public static double ExponentialInterpolate(double a, double b, double amount)
40 {
41 a = Math.Pow(a, amount);
42 b = Math.Pow(b - a, 1.0 - amount);
43 return a + b;
44 }
45
46 public static int PowerOf2Log2(int n)
47 {
48 for (int i = 0; i < 31; i++)
49 {
50 if ((n & 1) == 1)
51 {
52 return i;
53 }
54 n >>= 1;
55 }
56 return 0;
57 }
58 }
59}