diff options
Start of the OpenSim library , for now only contains a few textures.
Diffstat (limited to 'OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Generators')
7 files changed, 990 insertions, 990 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 | ||
29 | using System; | 29 | using System; |
30 | using System.Collections.Generic; | 30 | using System.Collections.Generic; |
31 | using System.Text; | 31 | using System.Text; |
32 | 32 | ||
33 | namespace libTerrain | 33 | namespace 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 |
diff --git a/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Generators/Gradient.cs b/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Generators/Gradient.cs index 47b7a66..141fe04 100644 --- a/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Generators/Gradient.cs +++ b/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Generators/Gradient.cs | |||
@@ -1,66 +1,66 @@ | |||
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 | ||
29 | using System; | 29 | using System; |
30 | using System.Collections.Generic; | 30 | using System.Collections.Generic; |
31 | using System.Text; | 31 | using System.Text; |
32 | 32 | ||
33 | namespace libTerrain | 33 | namespace libTerrain |
34 | { | 34 | { |
35 | partial class Channel | 35 | partial class Channel |
36 | { | 36 | { |
37 | 37 | ||
38 | public void GradientCube() | 38 | public void GradientCube() |
39 | { | 39 | { |
40 | SetDiff(); | 40 | SetDiff(); |
41 | 41 | ||
42 | int x, y; | 42 | int x, y; |
43 | for (x = 0; x < w; x++) | 43 | for (x = 0; x < w; x++) |
44 | { | 44 | { |
45 | for (y = 0; y < h; y++) | 45 | for (y = 0; y < h; y++) |
46 | { | 46 | { |
47 | map[x, y] = x*y; | 47 | map[x, y] = x*y; |
48 | } | 48 | } |
49 | } | 49 | } |
50 | Normalise(); | 50 | Normalise(); |
51 | } | 51 | } |
52 | 52 | ||
53 | public void GradientStripe() | 53 | public void GradientStripe() |
54 | { | 54 | { |
55 | int x, y; | 55 | int x, y; |
56 | for (x = 0; x < w; x++) | 56 | for (x = 0; x < w; x++) |
57 | { | 57 | { |
58 | for (y = 0; y < h; y++) | 58 | for (y = 0; y < h; y++) |
59 | { | 59 | { |
60 | map[x, y] = x; | 60 | map[x, y] = x; |
61 | } | 61 | } |
62 | } | 62 | } |
63 | Normalise(); | 63 | Normalise(); |
64 | } | 64 | } |
65 | } | 65 | } |
66 | } \ No newline at end of file | 66 | } \ No newline at end of file |
diff --git a/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Generators/HillPlanter.cs b/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Generators/HillPlanter.cs index 5a697b1..aa18e40 100644 --- a/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Generators/HillPlanter.cs +++ b/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Generators/HillPlanter.cs | |||
@@ -1,283 +1,283 @@ | |||
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 | ||
29 | using System; | 29 | using System; |
30 | using System.Collections.Generic; | 30 | using System.Collections.Generic; |
31 | using System.Text; | 31 | using System.Text; |
32 | 32 | ||
33 | namespace libTerrain | 33 | namespace libTerrain |
34 | { | 34 | { |
35 | partial class Channel | 35 | partial class Channel |
36 | { | 36 | { |
37 | /// <summary> | 37 | /// <summary> |
38 | /// Generates a series of spheres which are then either max()'d or added together. Inspired by suggestion from jh. | 38 | /// Generates a series of spheres which are then either max()'d or added together. Inspired by suggestion from jh. |
39 | /// </summary> | 39 | /// </summary> |
40 | /// <remarks>3-Clause BSD Licensed</remarks> | 40 | /// <remarks>3-Clause BSD Licensed</remarks> |
41 | /// <param name="number">The number of hills to generate</param> | 41 | /// <param name="number">The number of hills to generate</param> |
42 | /// <param name="scale_min">The minimum size of each hill</param> | 42 | /// <param name="scale_min">The minimum size of each hill</param> |
43 | /// <param name="scale_range">The maximum size of each hill</param> | 43 | /// <param name="scale_range">The maximum size of each hill</param> |
44 | /// <param name="island">Whether to bias hills towards the center of the map</param> | 44 | /// <param name="island">Whether to bias hills towards the center of the map</param> |
45 | /// <param name="additive">Whether to add hills together or to pick the largest value</param> | 45 | /// <param name="additive">Whether to add hills together or to pick the largest value</param> |
46 | /// <param name="noisy">Generates hill-shaped noise instead of consistent hills</param> | 46 | /// <param name="noisy">Generates hill-shaped noise instead of consistent hills</param> |
47 | public void HillsSpheres(int number, double scale_min, double scale_range, bool island, bool additive, bool noisy) | 47 | public void HillsSpheres(int number, double scale_min, double scale_range, bool island, bool additive, bool noisy) |
48 | { | 48 | { |
49 | SetDiff(); | 49 | SetDiff(); |
50 | 50 | ||
51 | Random random = new Random(seed); | 51 | Random random = new Random(seed); |
52 | 52 | ||
53 | int x, y; | 53 | int x, y; |
54 | int i; | 54 | int i; |
55 | 55 | ||
56 | for (i = 0; i < number; i++) | 56 | for (i = 0; i < number; i++) |
57 | { | 57 | { |
58 | double rx = Math.Min(255.0, random.NextDouble() * w); | 58 | double rx = Math.Min(255.0, random.NextDouble() * w); |
59 | double ry = Math.Min(255.0, random.NextDouble() * h); | 59 | double ry = Math.Min(255.0, random.NextDouble() * h); |
60 | double rand = random.NextDouble(); | 60 | double rand = random.NextDouble(); |
61 | 61 | ||
62 | if (island) | 62 | if (island) |
63 | { | 63 | { |
64 | // Move everything towards the center | 64 | // Move everything towards the center |
65 | rx -= w / 2; | 65 | rx -= w / 2; |
66 | rx /= 2; | 66 | rx /= 2; |
67 | rx += w / 2; | 67 | rx += w / 2; |
68 | 68 | ||
69 | ry -= h / 2; | 69 | ry -= h / 2; |
70 | ry /= 2; | 70 | ry /= 2; |
71 | ry += h / 2; | 71 | ry += h / 2; |
72 | } | 72 | } |
73 | 73 | ||
74 | for (x = 0; x < w; x++) | 74 | for (x = 0; x < w; x++) |
75 | { | 75 | { |
76 | for (y = 0; y < h; y++) | 76 | for (y = 0; y < h; y++) |
77 | { | 77 | { |
78 | if (noisy) | 78 | if (noisy) |
79 | rand = random.NextDouble(); | 79 | rand = random.NextDouble(); |
80 | 80 | ||
81 | double z = (scale_min + (scale_range * rand)); | 81 | double z = (scale_min + (scale_range * rand)); |
82 | z *= z; | 82 | z *= z; |
83 | z -= ((x - rx) * (x - rx)) + ((y - ry) * (y - ry)); | 83 | z -= ((x - rx) * (x - rx)) + ((y - ry) * (y - ry)); |
84 | 84 | ||
85 | if (z < 0) | 85 | if (z < 0) |
86 | z = 0; | 86 | z = 0; |
87 | 87 | ||
88 | if (additive) | 88 | if (additive) |
89 | { | 89 | { |
90 | map[x, y] += z; | 90 | map[x, y] += z; |
91 | } | 91 | } |
92 | else | 92 | else |
93 | { | 93 | { |
94 | map[x, y] = Math.Max(map[x, y], z); | 94 | map[x, y] = Math.Max(map[x, y], z); |
95 | } | 95 | } |
96 | } | 96 | } |
97 | } | 97 | } |
98 | } | 98 | } |
99 | 99 | ||
100 | Normalise(); | 100 | Normalise(); |
101 | } | 101 | } |
102 | 102 | ||
103 | /// <summary> | 103 | /// <summary> |
104 | /// Generates a series of cones which are then either max()'d or added together. Inspired by suggestion from jh. | 104 | /// Generates a series of cones which are then either max()'d or added together. Inspired by suggestion from jh. |
105 | /// </summary> | 105 | /// </summary> |
106 | /// <remarks>3-Clause BSD Licensed</remarks> | 106 | /// <remarks>3-Clause BSD Licensed</remarks> |
107 | /// <param name="number">The number of hills to generate</param> | 107 | /// <param name="number">The number of hills to generate</param> |
108 | /// <param name="scale_min">The minimum size of each hill</param> | 108 | /// <param name="scale_min">The minimum size of each hill</param> |
109 | /// <param name="scale_range">The maximum size of each hill</param> | 109 | /// <param name="scale_range">The maximum size of each hill</param> |
110 | /// <param name="island">Whether to bias hills towards the center of the map</param> | 110 | /// <param name="island">Whether to bias hills towards the center of the map</param> |
111 | /// <param name="additive">Whether to add hills together or to pick the largest value</param> | 111 | /// <param name="additive">Whether to add hills together or to pick the largest value</param> |
112 | /// <param name="noisy">Generates hill-shaped noise instead of consistent hills</param> | 112 | /// <param name="noisy">Generates hill-shaped noise instead of consistent hills</param> |
113 | public void HillsCones(int number, double scale_min, double scale_range, bool island, bool additive, bool noisy) | 113 | public void HillsCones(int number, double scale_min, double scale_range, bool island, bool additive, bool noisy) |
114 | { | 114 | { |
115 | SetDiff(); | 115 | SetDiff(); |
116 | 116 | ||
117 | Random random = new Random(seed); | 117 | Random random = new Random(seed); |
118 | 118 | ||
119 | int x, y; | 119 | int x, y; |
120 | int i; | 120 | int i; |
121 | 121 | ||
122 | for (i = 0; i < number; i++) | 122 | for (i = 0; i < number; i++) |
123 | { | 123 | { |
124 | double rx = Math.Min(255.0, random.NextDouble() * w); | 124 | double rx = Math.Min(255.0, random.NextDouble() * w); |
125 | double ry = Math.Min(255.0, random.NextDouble() * h); | 125 | double ry = Math.Min(255.0, random.NextDouble() * h); |
126 | double rand = random.NextDouble(); | 126 | double rand = random.NextDouble(); |
127 | 127 | ||
128 | if (island) | 128 | if (island) |
129 | { | 129 | { |
130 | // Move everything towards the center | 130 | // Move everything towards the center |
131 | rx -= w / 2; | 131 | rx -= w / 2; |
132 | rx /= 2; | 132 | rx /= 2; |
133 | rx += w / 2; | 133 | rx += w / 2; |
134 | 134 | ||
135 | ry -= h / 2; | 135 | ry -= h / 2; |
136 | ry /= 2; | 136 | ry /= 2; |
137 | ry += h / 2; | 137 | ry += h / 2; |
138 | } | 138 | } |
139 | 139 | ||
140 | for (x = 0; x < w; x++) | 140 | for (x = 0; x < w; x++) |
141 | { | 141 | { |
142 | for (y = 0; y < h; y++) | 142 | for (y = 0; y < h; y++) |
143 | { | 143 | { |
144 | if (noisy) | 144 | if (noisy) |
145 | rand = random.NextDouble(); | 145 | rand = random.NextDouble(); |
146 | 146 | ||
147 | double z = (scale_min + (scale_range * rand)); | 147 | double z = (scale_min + (scale_range * rand)); |
148 | z -= Math.Sqrt(((x - rx) * (x - rx)) + ((y - ry) * (y - ry))); | 148 | z -= Math.Sqrt(((x - rx) * (x - rx)) + ((y - ry) * (y - ry))); |
149 | 149 | ||
150 | if (z < 0) | 150 | if (z < 0) |
151 | z = 0; | 151 | z = 0; |
152 | 152 | ||
153 | if (additive) | 153 | if (additive) |
154 | { | 154 | { |
155 | map[x, y] += z; | 155 | map[x, y] += z; |
156 | } | 156 | } |
157 | else | 157 | else |
158 | { | 158 | { |
159 | map[x, y] = Math.Max(map[x, y], z); | 159 | map[x, y] = Math.Max(map[x, y], z); |
160 | } | 160 | } |
161 | } | 161 | } |
162 | } | 162 | } |
163 | } | 163 | } |
164 | 164 | ||
165 | Normalise(); | 165 | Normalise(); |
166 | } | 166 | } |
167 | 167 | ||
168 | public void HillsBlocks(int number, double scale_min, double scale_range, bool island, bool additive, bool noisy) | 168 | public void HillsBlocks(int number, double scale_min, double scale_range, bool island, bool additive, bool noisy) |
169 | { | 169 | { |
170 | SetDiff(); | 170 | SetDiff(); |
171 | 171 | ||
172 | Random random = new Random(seed); | 172 | Random random = new Random(seed); |
173 | 173 | ||
174 | int x, y; | 174 | int x, y; |
175 | int i; | 175 | int i; |
176 | 176 | ||
177 | for (i = 0; i < number; i++) | 177 | for (i = 0; i < number; i++) |
178 | { | 178 | { |
179 | double rx = Math.Min(255.0, random.NextDouble() * w); | 179 | double rx = Math.Min(255.0, random.NextDouble() * w); |
180 | double ry = Math.Min(255.0, random.NextDouble() * h); | 180 | double ry = Math.Min(255.0, random.NextDouble() * h); |
181 | double rand = random.NextDouble(); | 181 | double rand = random.NextDouble(); |
182 | 182 | ||
183 | if (island) | 183 | if (island) |
184 | { | 184 | { |
185 | // Move everything towards the center | 185 | // Move everything towards the center |
186 | rx -= w / 2; | 186 | rx -= w / 2; |
187 | rx /= 2; | 187 | rx /= 2; |
188 | rx += w / 2; | 188 | rx += w / 2; |
189 | 189 | ||
190 | ry -= h / 2; | 190 | ry -= h / 2; |
191 | ry /= 2; | 191 | ry /= 2; |
192 | ry += h / 2; | 192 | ry += h / 2; |
193 | } | 193 | } |
194 | 194 | ||
195 | for (x = 0; x < w; x++) | 195 | for (x = 0; x < w; x++) |
196 | { | 196 | { |
197 | for (y = 0; y < h; y++) | 197 | for (y = 0; y < h; y++) |
198 | { | 198 | { |
199 | if (noisy) | 199 | if (noisy) |
200 | rand = random.NextDouble(); | 200 | rand = random.NextDouble(); |
201 | 201 | ||
202 | double z = (scale_min + (scale_range * rand)); | 202 | double z = (scale_min + (scale_range * rand)); |
203 | z -= Math.Abs(x-rx) + Math.Abs(y-ry); | 203 | z -= Math.Abs(x-rx) + Math.Abs(y-ry); |
204 | //z -= Math.Sqrt(((x - rx) * (x - rx)) + ((y - ry) * (y - ry))); | 204 | //z -= Math.Sqrt(((x - rx) * (x - rx)) + ((y - ry) * (y - ry))); |
205 | 205 | ||
206 | if (z < 0) | 206 | if (z < 0) |
207 | z = 0; | 207 | z = 0; |
208 | 208 | ||
209 | if (additive) | 209 | if (additive) |
210 | { | 210 | { |
211 | map[x, y] += z; | 211 | map[x, y] += z; |
212 | } | 212 | } |
213 | else | 213 | else |
214 | { | 214 | { |
215 | map[x, y] = Math.Max(map[x, y], z); | 215 | map[x, y] = Math.Max(map[x, y], z); |
216 | } | 216 | } |
217 | } | 217 | } |
218 | } | 218 | } |
219 | } | 219 | } |
220 | 220 | ||
221 | Normalise(); | 221 | Normalise(); |
222 | } | 222 | } |
223 | 223 | ||
224 | public void HillsSquared(int number, double scale_min, double scale_range, bool island, bool additive, bool noisy) | 224 | public void HillsSquared(int number, double scale_min, double scale_range, bool island, bool additive, bool noisy) |
225 | { | 225 | { |
226 | SetDiff(); | 226 | SetDiff(); |
227 | 227 | ||
228 | Random random = new Random(seed); | 228 | Random random = new Random(seed); |
229 | 229 | ||
230 | int x, y; | 230 | int x, y; |
231 | int i; | 231 | int i; |
232 | 232 | ||
233 | for (i = 0; i < number; i++) | 233 | for (i = 0; i < number; i++) |
234 | { | 234 | { |
235 | double rx = Math.Min(255.0, random.NextDouble() * w); | 235 | double rx = Math.Min(255.0, random.NextDouble() * w); |
236 | double ry = Math.Min(255.0, random.NextDouble() * h); | 236 | double ry = Math.Min(255.0, random.NextDouble() * h); |
237 | double rand = random.NextDouble(); | 237 | double rand = random.NextDouble(); |
238 | 238 | ||
239 | if (island) | 239 | if (island) |
240 | { | 240 | { |
241 | // Move everything towards the center | 241 | // Move everything towards the center |
242 | rx -= w / 2; | 242 | rx -= w / 2; |
243 | rx /= 2; | 243 | rx /= 2; |
244 | rx += w / 2; | 244 | rx += w / 2; |
245 | 245 | ||
246 | ry -= h / 2; | 246 | ry -= h / 2; |
247 | ry /= 2; | 247 | ry /= 2; |
248 | ry += h / 2; | 248 | ry += h / 2; |
249 | } | 249 | } |
250 | 250 | ||
251 | for (x = 0; x < w; x++) | 251 | for (x = 0; x < w; x++) |
252 | { | 252 | { |
253 | for (y = 0; y < h; y++) | 253 | for (y = 0; y < h; y++) |
254 | { | 254 | { |
255 | if (noisy) | 255 | if (noisy) |
256 | rand = random.NextDouble(); | 256 | rand = random.NextDouble(); |
257 | 257 | ||
258 | double z = (scale_min + (scale_range * rand)); | 258 | double z = (scale_min + (scale_range * rand)); |
259 | z *= z * z * z; | 259 | z *= z * z * z; |
260 | double dx = Math.Abs(x - rx); | 260 | double dx = Math.Abs(x - rx); |
261 | double dy = Math.Abs(y - ry); | 261 | double dy = Math.Abs(y - ry); |
262 | z -= (dx * dx * dx * dx) + (dy * dy * dy * dy); | 262 | z -= (dx * dx * dx * dx) + (dy * dy * dy * dy); |
263 | 263 | ||
264 | if (z < 0) | 264 | if (z < 0) |
265 | z = 0; | 265 | z = 0; |
266 | 266 | ||
267 | if (additive) | 267 | if (additive) |
268 | { | 268 | { |
269 | map[x, y] += z; | 269 | map[x, y] += z; |
270 | } | 270 | } |
271 | else | 271 | else |
272 | { | 272 | { |
273 | map[x, y] = Math.Max(map[x, y], z); | 273 | map[x, y] = Math.Max(map[x, y], z); |
274 | } | 274 | } |
275 | } | 275 | } |
276 | } | 276 | } |
277 | } | 277 | } |
278 | 278 | ||
279 | Normalise(); | 279 | Normalise(); |
280 | } | 280 | } |
281 | 281 | ||
282 | } | 282 | } |
283 | } | 283 | } |
diff --git a/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Generators/Noise.cs b/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Generators/Noise.cs index 3cefcfe..d40302c 100644 --- a/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Generators/Noise.cs +++ b/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Generators/Noise.cs | |||
@@ -1,56 +1,56 @@ | |||
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 | ||
29 | using System; | 29 | using System; |
30 | using System.Collections.Generic; | 30 | using System.Collections.Generic; |
31 | using System.Text; | 31 | using System.Text; |
32 | 32 | ||
33 | namespace libTerrain | 33 | namespace libTerrain |
34 | { | 34 | { |
35 | partial class Channel | 35 | partial class Channel |
36 | { | 36 | { |
37 | /// <summary> | 37 | /// <summary> |
38 | /// Fills a channel with 0..1 noise | 38 | /// Fills a channel with 0..1 noise |
39 | /// </summary> | 39 | /// </summary> |
40 | /// <remarks>3-Clause BSD Licensed</remarks> | 40 | /// <remarks>3-Clause BSD Licensed</remarks> |
41 | public void Noise() | 41 | public void Noise() |
42 | { | 42 | { |
43 | SetDiff(); | 43 | SetDiff(); |
44 | 44 | ||
45 | Random rand = new Random(seed); | 45 | Random rand = new Random(seed); |
46 | int x, y; | 46 | int x, y; |
47 | for (x = 0; x < w; x++) | 47 | for (x = 0; x < w; x++) |
48 | { | 48 | { |
49 | for (y = 0; y < h; y++) | 49 | for (y = 0; y < h; y++) |
50 | { | 50 | { |
51 | map[x, y] = rand.NextDouble(); | 51 | map[x, y] = rand.NextDouble(); |
52 | } | 52 | } |
53 | } | 53 | } |
54 | } | 54 | } |
55 | } | 55 | } |
56 | } | 56 | } |
diff --git a/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Generators/Spiral.cs b/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Generators/Spiral.cs index 80abfe5..59d877a 100644 --- a/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Generators/Spiral.cs +++ b/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Generators/Spiral.cs | |||
@@ -1,156 +1,156 @@ | |||
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 | ||
29 | using System; | 29 | using System; |
30 | using System.Collections.Generic; | 30 | using System.Collections.Generic; |
31 | using System.Text; | 31 | using System.Text; |
32 | 32 | ||
33 | namespace libTerrain | 33 | namespace libTerrain |
34 | { | 34 | { |
35 | partial class Channel | 35 | partial class Channel |
36 | { | 36 | { |
37 | private double[] CoordinatesToPolar(int x, int y) | 37 | private double[] CoordinatesToPolar(int x, int y) |
38 | { | 38 | { |
39 | double theta = Math.Atan2(x - (w / 2), y - (h / 2)); | 39 | double theta = Math.Atan2(x - (w / 2), y - (h / 2)); |
40 | double rx = (double)x - ((double)w / 2); | 40 | double rx = (double)x - ((double)w / 2); |
41 | double ry = (double)y - ((double)h / 2); | 41 | double ry = (double)y - ((double)h / 2); |
42 | double r = Math.Sqrt((rx * rx) + (ry * ry)); | 42 | double r = Math.Sqrt((rx * rx) + (ry * ry)); |
43 | 43 | ||
44 | double[] coords = new double[2]; | 44 | double[] coords = new double[2]; |
45 | coords[0] = r; | 45 | coords[0] = r; |
46 | coords[1] = theta; | 46 | coords[1] = theta; |
47 | return coords; | 47 | return coords; |
48 | } | 48 | } |
49 | 49 | ||
50 | public int[] PolarToCoordinates(double r, double theta) { | 50 | public int[] PolarToCoordinates(double r, double theta) { |
51 | double nx; | 51 | double nx; |
52 | double ny; | 52 | double ny; |
53 | 53 | ||
54 | nx = (double)r * Math.Cos(theta); | 54 | nx = (double)r * Math.Cos(theta); |
55 | ny = (double)r * Math.Sin(theta); | 55 | ny = (double)r * Math.Sin(theta); |
56 | 56 | ||
57 | nx += w / 2; | 57 | nx += w / 2; |
58 | ny += h / 2; | 58 | ny += h / 2; |
59 | 59 | ||
60 | if (nx >= w) | 60 | if (nx >= w) |
61 | nx = w - 1; | 61 | nx = w - 1; |
62 | 62 | ||
63 | if (ny >= h) | 63 | if (ny >= h) |
64 | ny = h - 1; | 64 | ny = h - 1; |
65 | 65 | ||
66 | if (nx < 0) | 66 | if (nx < 0) |
67 | nx = 0; | 67 | nx = 0; |
68 | 68 | ||
69 | if (ny < 0) | 69 | if (ny < 0) |
70 | ny = 0; | 70 | ny = 0; |
71 | 71 | ||
72 | int[] coords = new int[2]; | 72 | int[] coords = new int[2]; |
73 | coords[0] = (int)nx; | 73 | coords[0] = (int)nx; |
74 | coords[1] = (int)ny; | 74 | coords[1] = (int)ny; |
75 | return coords; | 75 | return coords; |
76 | } | 76 | } |
77 | 77 | ||
78 | public void Polar() | 78 | public void Polar() |
79 | { | 79 | { |
80 | SetDiff(); | 80 | SetDiff(); |
81 | 81 | ||
82 | Channel n = this.Copy(); | 82 | Channel n = this.Copy(); |
83 | 83 | ||
84 | int x, y; | 84 | int x, y; |
85 | for (x = 0; x < w; x++) | 85 | for (x = 0; x < w; x++) |
86 | { | 86 | { |
87 | for (y = 0; y < h; y++) | 87 | for (y = 0; y < h; y++) |
88 | { | 88 | { |
89 | double[] coords = CoordinatesToPolar(x,y); | 89 | double[] coords = CoordinatesToPolar(x,y); |
90 | 90 | ||
91 | coords[0] += w / 2.0; | 91 | coords[0] += w / 2.0; |
92 | coords[1] += h / 2.0; | 92 | coords[1] += h / 2.0; |
93 | 93 | ||
94 | map[x, y] = n.map[(int)coords[0] % n.w, (int)coords[1] % n.h]; | 94 | map[x, y] = n.map[(int)coords[0] % n.w, (int)coords[1] % n.h]; |
95 | } | 95 | } |
96 | } | 96 | } |
97 | } | 97 | } |
98 | 98 | ||
99 | public void SpiralPlanter(int steps, double incAngle, double incRadius, double offsetRadius, double offsetAngle) | 99 | public void SpiralPlanter(int steps, double incAngle, double incRadius, double offsetRadius, double offsetAngle) |
100 | { | 100 | { |
101 | SetDiff(); | 101 | SetDiff(); |
102 | 102 | ||
103 | int i; | 103 | int i; |
104 | double r = offsetRadius; | 104 | double r = offsetRadius; |
105 | double theta = offsetAngle; | 105 | double theta = offsetAngle; |
106 | for (i = 0; i < steps; i++) | 106 | for (i = 0; i < steps; i++) |
107 | { | 107 | { |
108 | r += incRadius; | 108 | r += incRadius; |
109 | theta += incAngle; | 109 | theta += incAngle; |
110 | 110 | ||
111 | int[] coords = PolarToCoordinates(r,theta); | 111 | int[] coords = PolarToCoordinates(r,theta); |
112 | Raise(coords[0], coords[1], 20, 1); | 112 | Raise(coords[0], coords[1], 20, 1); |
113 | } | 113 | } |
114 | } | 114 | } |
115 | 115 | ||
116 | public void SpiralCells(int steps, double incAngle, double incRadius, double offsetRadius, double offsetAngle, double[] c) | 116 | public void SpiralCells(int steps, double incAngle, double incRadius, double offsetRadius, double offsetAngle, double[] c) |
117 | { | 117 | { |
118 | SetDiff(); | 118 | SetDiff(); |
119 | 119 | ||
120 | List<Point2D> points = new List<Point2D>(); | 120 | List<Point2D> points = new List<Point2D>(); |
121 | 121 | ||
122 | int i; | 122 | int i; |
123 | double r = offsetRadius; | 123 | double r = offsetRadius; |
124 | double theta = offsetAngle; | 124 | double theta = offsetAngle; |
125 | for (i = 0; i < steps; i++) | 125 | for (i = 0; i < steps; i++) |
126 | { | 126 | { |
127 | r += incRadius; | 127 | r += incRadius; |
128 | theta += incAngle; | 128 | theta += incAngle; |
129 | 129 | ||
130 | int[] coords = PolarToCoordinates(r, theta); | 130 | int[] coords = PolarToCoordinates(r, theta); |
131 | points.Add(new Point2D(coords[0],coords[1])); | 131 | points.Add(new Point2D(coords[0],coords[1])); |
132 | } | 132 | } |
133 | 133 | ||
134 | VoronoiDiagram(points, c); | 134 | VoronoiDiagram(points, c); |
135 | } | 135 | } |
136 | 136 | ||
137 | public void Spiral(double wid, double hig, double offset) | 137 | public void Spiral(double wid, double hig, double offset) |
138 | { | 138 | { |
139 | SetDiff(); | 139 | SetDiff(); |
140 | 140 | ||
141 | int x, y, z; | 141 | int x, y, z; |
142 | z = 0; | 142 | z = 0; |
143 | for (x = 0; x < w; x++) | 143 | for (x = 0; x < w; x++) |
144 | { | 144 | { |
145 | for (y = 0; y < h; y++) | 145 | for (y = 0; y < h; y++) |
146 | { | 146 | { |
147 | z++; | 147 | z++; |
148 | double dx = Math.Abs((w / 2) - x); | 148 | double dx = Math.Abs((w / 2) - x); |
149 | double dy = Math.Abs((h / 2) - y); | 149 | double dy = Math.Abs((h / 2) - y); |
150 | map[x, y] += Math.Sin(dx / wid) + Math.Cos(dy / hig); | 150 | map[x, y] += Math.Sin(dx / wid) + Math.Cos(dy / hig); |
151 | } | 151 | } |
152 | } | 152 | } |
153 | Normalise(); | 153 | Normalise(); |
154 | } | 154 | } |
155 | } | 155 | } |
156 | } \ No newline at end of file | 156 | } \ No newline at end of file |
diff --git a/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Generators/Voronoi.cs b/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Generators/Voronoi.cs index eb8f7ba..3411ccf 100644 --- a/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Generators/Voronoi.cs +++ b/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Generators/Voronoi.cs | |||
@@ -1,214 +1,214 @@ | |||
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 | ||
29 | using System; | 29 | using System; |
30 | using System.Collections.Generic; | 30 | using System.Collections.Generic; |
31 | using System.Text; | 31 | using System.Text; |
32 | 32 | ||
33 | namespace libTerrain | 33 | namespace libTerrain |
34 | { | 34 | { |
35 | partial class Channel | 35 | partial class Channel |
36 | { | 36 | { |
37 | /// <summary> | 37 | /// <summary> |
38 | /// Generates a Voronoi diagram (sort of a stained glass effect) which will fill the entire channel | 38 | /// Generates a Voronoi diagram (sort of a stained glass effect) which will fill the entire channel |
39 | /// </summary> | 39 | /// </summary> |
40 | /// <remarks>3-Clause BSD Licensed</remarks> | 40 | /// <remarks>3-Clause BSD Licensed</remarks> |
41 | /// <param name="pointsPerBlock">The number of generator points in each block</param> | 41 | /// <param name="pointsPerBlock">The number of generator points in each block</param> |
42 | /// <param name="blockSize">A multiple of the channel width and height which will have voronoi points generated in it. | 42 | /// <param name="blockSize">A multiple of the channel width and height which will have voronoi points generated in it. |
43 | /// <para>This is to ensure a more even distribution of the points than pure random allocation.</para></param> | 43 | /// <para>This is to ensure a more even distribution of the points than pure random allocation.</para></param> |
44 | /// <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> | 44 | /// <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> |
45 | public void VoronoiDiagram(int pointsPerBlock, int blockSize, double[] c) | 45 | public void VoronoiDiagram(int pointsPerBlock, int blockSize, double[] c) |
46 | { | 46 | { |
47 | SetDiff(); | 47 | SetDiff(); |
48 | 48 | ||
49 | List<Point2D> points = new List<Point2D>(); | 49 | List<Point2D> points = new List<Point2D>(); |
50 | Random generator = new Random(seed); | 50 | Random generator = new Random(seed); |
51 | 51 | ||
52 | // Generate the emitter points | 52 | // Generate the emitter points |
53 | int x, y, i; | 53 | int x, y, i; |
54 | for (x = -blockSize; x < w + blockSize; x += blockSize) | 54 | for (x = -blockSize; x < w + blockSize; x += blockSize) |
55 | { | 55 | { |
56 | for (y = -blockSize; y < h + blockSize; y += blockSize) | 56 | for (y = -blockSize; y < h + blockSize; y += blockSize) |
57 | { | 57 | { |
58 | for (i = 0; i < pointsPerBlock; i++) | 58 | for (i = 0; i < pointsPerBlock; i++) |
59 | { | 59 | { |
60 | double pX = x + (generator.NextDouble() * (double)blockSize); | 60 | double pX = x + (generator.NextDouble() * (double)blockSize); |
61 | double pY = y + (generator.NextDouble() * (double)blockSize); | 61 | double pY = y + (generator.NextDouble() * (double)blockSize); |
62 | 62 | ||
63 | points.Add(new Point2D(pX, pY)); | 63 | points.Add(new Point2D(pX, pY)); |
64 | } | 64 | } |
65 | } | 65 | } |
66 | } | 66 | } |
67 | 67 | ||
68 | double[] distances = new double[points.Count]; | 68 | double[] distances = new double[points.Count]; |
69 | 69 | ||
70 | // Calculate the distance each pixel is from an emitter | 70 | // Calculate the distance each pixel is from an emitter |
71 | for (x = 0; x < w; x++) | 71 | for (x = 0; x < w; x++) |
72 | { | 72 | { |
73 | for (y = 0; y < h; y++) | 73 | for (y = 0; y < h; y++) |
74 | { | 74 | { |
75 | for (i = 0; i < points.Count; i++) | 75 | for (i = 0; i < points.Count; i++) |
76 | { | 76 | { |
77 | double dx, dy; | 77 | double dx, dy; |
78 | dx = Math.Abs((double)x - points[i].x); | 78 | dx = Math.Abs((double)x - points[i].x); |
79 | dy = Math.Abs((double)y - points[i].y); | 79 | dy = Math.Abs((double)y - points[i].y); |
80 | 80 | ||
81 | distances[i] = (dx * dx + dy * dy); | 81 | distances[i] = (dx * dx + dy * dy); |
82 | } | 82 | } |
83 | 83 | ||
84 | Array.Sort(distances); | 84 | Array.Sort(distances); |
85 | 85 | ||
86 | double f = 0.0; | 86 | double f = 0.0; |
87 | 87 | ||
88 | // Multiply the distances with their 'c' counterpart | 88 | // Multiply the distances with their 'c' counterpart |
89 | // ordering the distances descending | 89 | // ordering the distances descending |
90 | for (i = 0; i < c.Length; i++) | 90 | for (i = 0; i < c.Length; i++) |
91 | { | 91 | { |
92 | if (i >= points.Count) | 92 | if (i >= points.Count) |
93 | break; | 93 | break; |
94 | 94 | ||
95 | f += c[i] * distances[i]; | 95 | f += c[i] * distances[i]; |
96 | } | 96 | } |
97 | 97 | ||
98 | map[x, y] = f; | 98 | map[x, y] = f; |
99 | } | 99 | } |
100 | } | 100 | } |
101 | 101 | ||
102 | // Normalise the result | 102 | // Normalise the result |
103 | Normalise(); | 103 | Normalise(); |
104 | } | 104 | } |
105 | 105 | ||
106 | public void VoronoiDiagram(List<Point2D> points, double[] c) | 106 | public void VoronoiDiagram(List<Point2D> points, double[] c) |
107 | { | 107 | { |
108 | SetDiff(); | 108 | SetDiff(); |
109 | 109 | ||
110 | Random generator = new Random(seed); | 110 | Random generator = new Random(seed); |
111 | int x, y, i; | 111 | int x, y, i; |
112 | double[] distances = new double[points.Count]; | 112 | double[] distances = new double[points.Count]; |
113 | 113 | ||
114 | // Calculate the distance each pixel is from an emitter | 114 | // Calculate the distance each pixel is from an emitter |
115 | for (x = 0; x < w; x++) | 115 | for (x = 0; x < w; x++) |
116 | { | 116 | { |
117 | for (y = 0; y < h; y++) | 117 | for (y = 0; y < h; y++) |
118 | { | 118 | { |
119 | for (i = 0; i < points.Count; i++) | 119 | for (i = 0; i < points.Count; i++) |
120 | { | 120 | { |
121 | double dx, dy; | 121 | double dx, dy; |
122 | dx = Math.Abs((double)x - points[i].x); | 122 | dx = Math.Abs((double)x - points[i].x); |
123 | dy = Math.Abs((double)y - points[i].y); | 123 | dy = Math.Abs((double)y - points[i].y); |
124 | 124 | ||
125 | distances[i] = (dx * dx + dy * dy); | 125 | distances[i] = (dx * dx + dy * dy); |
126 | } | 126 | } |
127 | 127 | ||
128 | Array.Sort(distances); | 128 | Array.Sort(distances); |
129 | 129 | ||
130 | double f = 0.0; | 130 | double f = 0.0; |
131 | 131 | ||
132 | // Multiply the distances with their 'c' counterpart | 132 | // Multiply the distances with their 'c' counterpart |
133 | // ordering the distances descending | 133 | // ordering the distances descending |
134 | for (i = 0; i < c.Length; i++) | 134 | for (i = 0; i < c.Length; i++) |
135 | { | 135 | { |
136 | if (i >= points.Count) | 136 | if (i >= points.Count) |
137 | break; | 137 | break; |
138 | 138 | ||
139 | f += c[i] * distances[i]; | 139 | f += c[i] * distances[i]; |
140 | } | 140 | } |
141 | 141 | ||
142 | map[x, y] = f; | 142 | map[x, y] = f; |
143 | } | 143 | } |
144 | } | 144 | } |
145 | 145 | ||
146 | // Normalise the result | 146 | // Normalise the result |
147 | Normalise(); | 147 | Normalise(); |
148 | } | 148 | } |
149 | 149 | ||
150 | public void VoroflatDiagram(int pointsPerBlock, int blockSize) | 150 | public void VoroflatDiagram(int pointsPerBlock, int blockSize) |
151 | { | 151 | { |
152 | SetDiff(); | 152 | SetDiff(); |
153 | 153 | ||
154 | List<Point2D> points = new List<Point2D>(); | 154 | List<Point2D> points = new List<Point2D>(); |
155 | Random generator = new Random(seed); | 155 | Random generator = new Random(seed); |
156 | 156 | ||
157 | // Generate the emitter points | 157 | // Generate the emitter points |
158 | int x, y, i; | 158 | int x, y, i; |
159 | for (x = -blockSize; x < w + blockSize; x += blockSize) | 159 | for (x = -blockSize; x < w + blockSize; x += blockSize) |
160 | { | 160 | { |
161 | for (y = -blockSize; y < h + blockSize; y += blockSize) | 161 | for (y = -blockSize; y < h + blockSize; y += blockSize) |
162 | { | 162 | { |
163 | for (i = 0; i < pointsPerBlock; i++) | 163 | for (i = 0; i < pointsPerBlock; i++) |
164 | { | 164 | { |
165 | double pX = x + (generator.NextDouble() * (double)blockSize); | 165 | double pX = x + (generator.NextDouble() * (double)blockSize); |
166 | double pY = y + (generator.NextDouble() * (double)blockSize); | 166 | double pY = y + (generator.NextDouble() * (double)blockSize); |
167 | 167 | ||
168 | points.Add(new Point2D(pX, pY)); | 168 | points.Add(new Point2D(pX, pY)); |
169 | } | 169 | } |
170 | } | 170 | } |
171 | } | 171 | } |
172 | 172 | ||
173 | double[] distances = new double[points.Count]; | 173 | double[] distances = new double[points.Count]; |
174 | 174 | ||
175 | // Calculate the distance each pixel is from an emitter | 175 | // Calculate the distance each pixel is from an emitter |
176 | for (x = 0; x < w; x++) | 176 | for (x = 0; x < w; x++) |
177 | { | 177 | { |
178 | for (y = 0; y < h; y++) | 178 | for (y = 0; y < h; y++) |
179 | { | 179 | { |
180 | for (i = 0; i < points.Count; i++) | 180 | for (i = 0; i < points.Count; i++) |
181 | { | 181 | { |
182 | double dx, dy; | 182 | double dx, dy; |
183 | dx = Math.Abs((double)x - points[i].x); | 183 | dx = Math.Abs((double)x - points[i].x); |
184 | dy = Math.Abs((double)y - points[i].y); | 184 | dy = Math.Abs((double)y - points[i].y); |
185 | 185 | ||
186 | distances[i] = (dx * dx + dy * dy); | 186 | distances[i] = (dx * dx + dy * dy); |
187 | } | 187 | } |
188 | 188 | ||
189 | //Array.Sort(distances); | 189 | //Array.Sort(distances); |
190 | 190 | ||
191 | double f = 0.0; | 191 | double f = 0.0; |
192 | 192 | ||
193 | double min = double.MaxValue; | 193 | double min = double.MaxValue; |
194 | for (int j = 0; j < distances.Length;j++ ) | 194 | for (int j = 0; j < distances.Length;j++ ) |
195 | { | 195 | { |
196 | if (distances[j] < min) | 196 | if (distances[j] < min) |
197 | { | 197 | { |
198 | min = distances[j]; | 198 | min = distances[j]; |
199 | f = j; | 199 | f = j; |
200 | } | 200 | } |
201 | } | 201 | } |
202 | 202 | ||
203 | // Multiply the distances with their 'c' counterpart | 203 | // Multiply the distances with their 'c' counterpart |
204 | // ordering the distances descending | 204 | // ordering the distances descending |
205 | 205 | ||
206 | map[x, y] = f; | 206 | map[x, y] = f; |
207 | } | 207 | } |
208 | } | 208 | } |
209 | 209 | ||
210 | // Normalise the result | 210 | // Normalise the result |
211 | Normalise(); | 211 | Normalise(); |
212 | } | 212 | } |
213 | } | 213 | } |
214 | } | 214 | } |
diff --git a/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Generators/Worms.cs b/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Generators/Worms.cs index ce36daf..ba2fad6 100644 --- a/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Generators/Worms.cs +++ b/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Generators/Worms.cs | |||
@@ -1,74 +1,74 @@ | |||
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 | ||
29 | using System; | 29 | using System; |
30 | using System.Collections.Generic; | 30 | using System.Collections.Generic; |
31 | using System.Text; | 31 | using System.Text; |
32 | 32 | ||
33 | namespace libTerrain | 33 | namespace libTerrain |
34 | { | 34 | { |
35 | partial class Channel | 35 | partial class Channel |
36 | { | 36 | { |
37 | /// <summary> | 37 | /// <summary> |
38 | /// Generates 'number' of worms which navigate randomly around the landscape creating terrain as they go. | 38 | /// Generates 'number' of worms which navigate randomly around the landscape creating terrain as they go. |
39 | /// </summary> | 39 | /// </summary> |
40 | /// <param name="number">The number of worms which will traverse the map</param> | 40 | /// <param name="number">The number of worms which will traverse the map</param> |
41 | /// <param name="rounds">The number of steps each worm will traverse</param> | 41 | /// <param name="rounds">The number of steps each worm will traverse</param> |
42 | /// <param name="movement">The maximum distance each worm will move each step</param> | 42 | /// <param name="movement">The maximum distance each worm will move each step</param> |
43 | /// <param name="size">The size of the area around the worm modified</param> | 43 | /// <param name="size">The size of the area around the worm modified</param> |
44 | /// <param name="centerspawn">Do worms start in the middle, or randomly?</param> | 44 | /// <param name="centerspawn">Do worms start in the middle, or randomly?</param> |
45 | public void Worms(int number, int rounds, double movement, double size, bool centerspawn) | 45 | public void Worms(int number, int rounds, double movement, double size, bool centerspawn) |
46 | { | 46 | { |
47 | SetDiff(); | 47 | SetDiff(); |
48 | 48 | ||
49 | Random random = new Random(seed); | 49 | Random random = new Random(seed); |
50 | int i, j; | 50 | int i, j; |
51 | 51 | ||
52 | for (i = 0; i < number; i++) | 52 | for (i = 0; i < number; i++) |
53 | { | 53 | { |
54 | double rx, ry; | 54 | double rx, ry; |
55 | if (centerspawn) | 55 | if (centerspawn) |
56 | { | 56 | { |
57 | rx = w / 2.0; | 57 | rx = w / 2.0; |
58 | ry = h / 2.0; | 58 | ry = h / 2.0; |
59 | } | 59 | } |
60 | else | 60 | else |
61 | { | 61 | { |
62 | rx = random.NextDouble() * (w - 1); | 62 | rx = random.NextDouble() * (w - 1); |
63 | ry = random.NextDouble() * (h - 1); | 63 | ry = random.NextDouble() * (h - 1); |
64 | } | 64 | } |
65 | for (j = 0; j < rounds; j++) | 65 | for (j = 0; j < rounds; j++) |
66 | { | 66 | { |
67 | rx += (random.NextDouble() * movement) - (movement / 2.0); | 67 | rx += (random.NextDouble() * movement) - (movement / 2.0); |
68 | ry += (random.NextDouble() * movement) - (movement / 2.0); | 68 | ry += (random.NextDouble() * movement) - (movement / 2.0); |
69 | Raise(rx, ry, size, 1.0); | 69 | Raise(rx, ry, size, 1.0); |
70 | } | 70 | } |
71 | } | 71 | } |
72 | } | 72 | } |
73 | } | 73 | } |
74 | } \ No newline at end of file | 74 | } \ No newline at end of file |