diff options
Start of the OpenSim library , for now only contains a few textures.
Diffstat (limited to 'OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Generators/Spiral.cs')
-rw-r--r-- | OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Generators/Spiral.cs | 310 |
1 files changed, 155 insertions, 155 deletions
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 |