aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Generators/Fracture.cs
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Generators/Fracture.cs')
-rw-r--r--OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Generators/Fracture.cs288
1 files changed, 144 insertions, 144 deletions
diff --git a/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Generators/Fracture.cs b/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Generators/Fracture.cs
index 13dd1bc..2d42759 100644
--- a/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Generators/Fracture.cs
+++ b/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Generators/Fracture.cs
@@ -1,145 +1,145 @@
1/* 1/*
2* Copyright (c) Contributors, http://www.openmetaverse.org/ 2* Copyright (c) Contributors, http://www.openmetaverse.org/
3* See CONTRIBUTORS.TXT for a full list of copyright holders. 3* See CONTRIBUTORS.TXT for a full list of copyright holders.
4* 4*
5* Redistribution and use in source and binary forms, with or without 5* Redistribution and use in source and binary forms, with or without
6* modification, are permitted provided that the following conditions are met: 6* modification, are permitted provided that the following conditions are met:
7* * Redistributions of source code must retain the above copyright 7* * Redistributions of source code must retain the above copyright
8* notice, this list of conditions and the following disclaimer. 8* notice, this list of conditions and the following disclaimer.
9* * Redistributions in binary form must reproduce the above copyright 9* * Redistributions in binary form must reproduce the above copyright
10* notice, this list of conditions and the following disclaimer in the 10* notice, this list of conditions and the following disclaimer in the
11* documentation and/or other materials provided with the distribution. 11* documentation and/or other materials provided with the distribution.
12* * Neither the name of the OpenSim Project nor the 12* * Neither the name of the OpenSim Project nor the
13* names of its contributors may be used to endorse or promote products 13* names of its contributors may be used to endorse or promote products
14* derived from this software without specific prior written permission. 14* derived from this software without specific prior written permission.
15* 15*
16* THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS AND ANY 16* THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS AND ANY
17* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 17* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 18* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19* DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY 19* DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
20* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 20* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 21* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 22* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 23* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 24* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26* 26*
27*/ 27*/
28 28
29using System; 29using System;
30using System.Collections.Generic; 30using System.Collections.Generic;
31using System.Text; 31using System.Text;
32 32
33namespace libTerrain 33namespace libTerrain
34{ 34{
35 partial class Channel 35 partial class Channel
36 { 36 {
37 /// <summary> 37 /// <summary>
38 /// Produces a set of coordinates defined by an edge point. Eg - 0 = 0,0. 256 = 0,256. 512 = 256,256 38 /// Produces a set of coordinates defined by an edge point. Eg - 0 = 0,0. 256 = 0,256. 512 = 256,256
39 /// Assumes a 256^2 heightmap. This needs fixing for input values of w,h 39 /// Assumes a 256^2 heightmap. This needs fixing for input values of w,h
40 /// </summary> 40 /// </summary>
41 /// <param name="val"></param> 41 /// <param name="val"></param>
42 /// <param name="w"></param> 42 /// <param name="w"></param>
43 /// <param name="h"></param> 43 /// <param name="h"></param>
44 /// <returns></returns> 44 /// <returns></returns>
45 private int[] RadialEdge256(int val) 45 private int[] RadialEdge256(int val)
46 { 46 {
47 // Four cases: 47 // Four cases:
48 // 1. 000..255 return 0,val 48 // 1. 000..255 return 0,val
49 // 2. 256..511 return val - 256,255 49 // 2. 256..511 return val - 256,255
50 // 3. 512..767 return 255, val - 511 50 // 3. 512..767 return 255, val - 511
51 // 4. 768..1023 return val - 768,0 51 // 4. 768..1023 return val - 768,0
52 52
53 int[] ret = new int[2]; 53 int[] ret = new int[2];
54 54
55 if (val < 256) 55 if (val < 256)
56 { 56 {
57 ret[0] = 0; 57 ret[0] = 0;
58 ret[1] = val; 58 ret[1] = val;
59 return ret; 59 return ret;
60 } 60 }
61 if (val < 512) 61 if (val < 512)
62 { 62 {
63 ret[0] = (val % 256); 63 ret[0] = (val % 256);
64 ret[1] = 255; 64 ret[1] = 255;
65 return ret; 65 return ret;
66 } 66 }
67 if (val < 768) 67 if (val < 768)
68 { 68 {
69 ret[0] = 255; 69 ret[0] = 255;
70 ret[1] = 255 - (val % 256); 70 ret[1] = 255 - (val % 256);
71 return ret; 71 return ret;
72 } 72 }
73 if (val < 1024) 73 if (val < 1024)
74 { 74 {
75 ret[0] = 255 - (val % 256); 75 ret[0] = 255 - (val % 256);
76 ret[1] = 255; 76 ret[1] = 255;
77 return ret; 77 return ret;
78 } 78 }
79 79
80 throw new Exception("Out of bounds parameter (val)"); 80 throw new Exception("Out of bounds parameter (val)");
81 } 81 }
82 82
83 public void Fracture(int number, double scalemin, double scalemax) 83 public void Fracture(int number, double scalemin, double scalemax)
84 { 84 {
85 SetDiff(); 85 SetDiff();
86 86
87 Random rand = new Random(seed); 87 Random rand = new Random(seed);
88 88
89 for (int i = 0; i < number; i++) 89 for (int i = 0; i < number; i++)
90 { 90 {
91 int[] a, b; 91 int[] a, b;
92 92
93 a = RadialEdge256(rand.Next(1023)); // TODO: Broken 93 a = RadialEdge256(rand.Next(1023)); // TODO: Broken
94 b = RadialEdge256(rand.Next(1023)); // TODO: Broken 94 b = RadialEdge256(rand.Next(1023)); // TODO: Broken
95 double z = rand.NextDouble(); 95 double z = rand.NextDouble();
96 double u = rand.NextDouble(); 96 double u = rand.NextDouble();
97 double v = rand.NextDouble(); 97 double v = rand.NextDouble();
98 98
99 for (int x = 0; x < w; x++) 99 for (int x = 0; x < w; x++)
100 { 100 {
101 for (int y = 0; y < h; y++) 101 for (int y = 0; y < h; y++)
102 { 102 {
103 double miny = Tools.linearInterpolate(a[1], b[1], (double)x / (double)w); 103 double miny = Tools.linearInterpolate(a[1], b[1], (double)x / (double)w);
104 104
105 if (v >= 0.5) 105 if (v >= 0.5)
106 { 106 {
107 if (u >= 0.5) 107 if (u >= 0.5)
108 { 108 {
109 if (y > miny) 109 if (y > miny)
110 { 110 {
111 map[x, y] += Tools.linearInterpolate(scalemin, scalemax, z); 111 map[x, y] += Tools.linearInterpolate(scalemin, scalemax, z);
112 } 112 }
113 } 113 }
114 else 114 else
115 { 115 {
116 if (y < miny) 116 if (y < miny)
117 { 117 {
118 map[x, y] += Tools.linearInterpolate(scalemin, scalemax, z); 118 map[x, y] += Tools.linearInterpolate(scalemin, scalemax, z);
119 } 119 }
120 } 120 }
121 } 121 }
122 else 122 else
123 { 123 {
124 if (u >= 0.5) 124 if (u >= 0.5)
125 { 125 {
126 if (x > miny) 126 if (x > miny)
127 { 127 {
128 map[x, y] += Tools.linearInterpolate(scalemin, scalemax, z); 128 map[x, y] += Tools.linearInterpolate(scalemin, scalemax, z);
129 } 129 }
130 } 130 }
131 else 131 else
132 { 132 {
133 if (x < miny) 133 if (x < miny)
134 { 134 {
135 map[x, y] += Tools.linearInterpolate(scalemin, scalemax, z); 135 map[x, y] += Tools.linearInterpolate(scalemin, scalemax, z);
136 } 136 }
137 } 137 }
138 } 138 }
139 } 139 }
140 } 140 }
141 } 141 }
142 Normalise(); 142 Normalise();
143 } 143 }
144 } 144 }
145} \ No newline at end of file 145} \ No newline at end of file