aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Generators/Fracture.cs
diff options
context:
space:
mode:
authorAdam Frisby2007-07-21 22:25:42 +0000
committerAdam Frisby2007-07-21 22:25:42 +0000
commitf84937367f7180140bd17444d507977f9b7e3d2e (patch)
tree944f2824669e42b5df3b6655bd09999c89b50376 /OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Generators/Fracture.cs
parent* Renamed terrain functions to match OpenSim naming styles. (diff)
downloadopensim-SC_OLD-f84937367f7180140bd17444d507977f9b7e3d2e.zip
opensim-SC_OLD-f84937367f7180140bd17444d507977f9b7e3d2e.tar.gz
opensim-SC_OLD-f84937367f7180140bd17444d507977f9b7e3d2e.tar.bz2
opensim-SC_OLD-f84937367f7180140bd17444d507977f9b7e3d2e.tar.xz
* Deleted libTerrain-BSD.dll
* Added libTerrain to BasicTerrain directly as a subfolder
Diffstat (limited to 'OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Generators/Fracture.cs')
-rw-r--r--OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Generators/Fracture.cs113
1 files changed, 113 insertions, 0 deletions
diff --git a/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Generators/Fracture.cs b/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Generators/Fracture.cs
new file mode 100644
index 0000000..2a24ecf
--- /dev/null
+++ b/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Generators/Fracture.cs
@@ -0,0 +1,113 @@
1/*
2Redistribution and use in source and binary forms, with or without
3modification, are permitted provided that the following conditions are
4met:
5
6 * Redistributions of source code must retain the above copyright
7 notice, this list of conditions and the following disclaimer.
8
9 * Redistributions in binary form must reproduce the above
10 copyright notice, this list of conditions and the following
11 disclaimer in the documentation and/or other materials provided
12 with the distribution.
13
14 * Neither the name of libTerrain nor the names of
15 its contributors may be used to endorse or promote products
16 derived from this software without specific prior written
17 permission.
18
19THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
21LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
22A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
23OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
24SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
25LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30*/
31
32using System;
33using System.Collections.Generic;
34using System.Text;
35
36namespace libTerrain
37{
38 partial class Channel
39 {
40 /// <summary>
41 /// Produces a set of coordinates defined by an edge point. Eg - 0 = 0,0. 256 = 0,256. 512 = 256,256
42 /// Assumes a 256^2 heightmap. This needs fixing for input values of w,h
43 /// </summary>
44 /// <param name="val"></param>
45 /// <param name="w"></param>
46 /// <param name="h"></param>
47 /// <returns></returns>
48 private int[] radialEdge256(int val)
49 {
50 // Four cases:
51 // 1. 000..255 return 0,val
52 // 2. 256..511 return val - 256,255
53 // 3. 512..767 return 255, val - 511
54 // 4. 768..1023 return val - 768,0
55
56 int[] ret = new int[2];
57
58 if (val < 256)
59 {
60 ret[0] = 0;
61 ret[1] = val;
62 return ret;
63 }
64 if (val < 512)
65 {
66 ret[0] = (val % 256);
67 ret[1] = 255;
68 return ret;
69 }
70 if (val < 768)
71 {
72 ret[0] = 255;
73 ret[1] = 255 - (val % 256);
74 return ret;
75 }
76 if (val < 1024)
77 {
78 ret[0] = 255 - (val % 256);
79 ret[1] = 255;
80 return ret;
81 }
82
83 throw new Exception("Out of bounds parameter (val)");
84 }
85 public void fracture(int number, double scalemin, double scalemax)
86 {
87 Random rand = new Random(seed);
88
89 for (int i = 0; i < number; i++)
90 {
91 int[] a, b;
92
93 a = radialEdge256(rand.Next(1023)); // TODO: Broken
94 b = radialEdge256(rand.Next(1023)); // TODO: Broken
95 double z = rand.NextDouble();
96
97 for (int x = 0; x < w; x++)
98 {
99 for (int y = 0; y < h; y++)
100 {
101 double miny = Tools.linearInterpolate(a[1], b[1], (double)x / (double)w);
102
103 if (y > miny)
104 {
105 map[x, y] += Tools.linearInterpolate(scalemin, scalemax, z);
106 }
107 }
108 }
109 }
110 normalise();
111 }
112 }
113} \ No newline at end of file