diff options
Diffstat (limited to 'OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Generators/Fracture.cs')
-rw-r--r-- | OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Generators/Fracture.cs | 113 |
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 | /* | ||
2 | Redistribution and use in source and binary forms, with or without | ||
3 | modification, are permitted provided that the following conditions are | ||
4 | met: | ||
5 | |||
6 | * Redistributions of source code must retain the above copyright | ||
7 | notice, this list of conditions and the following disclaimer. | ||
8 | |||
9 | * Redistributions in binary form must reproduce the above | ||
10 | copyright notice, this list of conditions and the following | ||
11 | disclaimer in the documentation and/or other materials provided | ||
12 | with the distribution. | ||
13 | |||
14 | * Neither the name of libTerrain nor the names of | ||
15 | its contributors may be used to endorse or promote products | ||
16 | derived from this software without specific prior written | ||
17 | permission. | ||
18 | |||
19 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | ||
20 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | ||
21 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | ||
22 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | ||
23 | OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
24 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | ||
25 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | ||
26 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | ||
27 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
28 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | ||
29 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
30 | */ | ||
31 | |||
32 | using System; | ||
33 | using System.Collections.Generic; | ||
34 | using System.Text; | ||
35 | |||
36 | namespace libTerrain | ||
37 | { | ||
38 | partial class Channel | ||
39 | { | ||
40 | /// <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 | ||