aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Generators/Spiral.cs
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Generators/Spiral.cs')
-rw-r--r--OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Generators/Spiral.cs152
1 files changed, 152 insertions, 0 deletions
diff --git a/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Generators/Spiral.cs b/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Generators/Spiral.cs
new file mode 100644
index 0000000..ede4600
--- /dev/null
+++ b/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Generators/Spiral.cs
@@ -0,0 +1,152 @@
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 private double[] coordinatesToPolar(int x, int y)
41 {
42
43 double theta = Math.Atan2(x - (w / 2), y - (h / 2));
44 double rx = (double)x - ((double)w / 2);
45 double ry = (double)y - ((double)h / 2);
46 double r = Math.Sqrt((rx * rx) + (ry * ry));
47
48 double[] coords = new double[2];
49 coords[0] = r;
50 coords[1] = theta;
51 return coords;
52 }
53
54 public int[] polarToCoordinates(double r, double theta) {
55 double nx;
56 double ny;
57
58 nx = (double)r * Math.Cos(theta);
59 ny = (double)r * Math.Sin(theta);
60
61 nx += w / 2;
62 ny += h / 2;
63
64 if (nx >= w)
65 nx = w - 1;
66
67 if (ny >= h)
68 ny = h - 1;
69
70 if (nx < 0)
71 nx = 0;
72
73 if (ny < 0)
74 ny = 0;
75
76 int[] coords = new int[2];
77 coords[0] = (int)nx;
78 coords[1] = (int)ny;
79 return coords;
80 }
81
82 public void Polar()
83 {
84 Channel n = this.copy();
85
86 int x, y;
87 for (x = 0; x < w; x++)
88 {
89 for (y = 0; y < h; y++)
90 {
91 double[] coords = coordinatesToPolar(x,y);
92
93 coords[0] += w / 2.0;
94 coords[1] += h / 2.0;
95
96 map[x, y] = n.map[(int)coords[0] % n.w, (int)coords[1] % n.h];
97 }
98 }
99 }
100
101 public void SpiralPlanter(int steps, double incAngle, double incRadius, double offsetRadius, double offsetAngle)
102 {
103 int i;
104 double r = offsetRadius;
105 double theta = offsetAngle;
106 for (i = 0; i < steps; i++)
107 {
108 r += incRadius;
109 theta += incAngle;
110
111 int[] coords = polarToCoordinates(r,theta);
112 raise(coords[0], coords[1], 20, 1);
113 }
114 }
115
116 public void SpiralCells(int steps, double incAngle, double incRadius, double offsetRadius, double offsetAngle, double[] c)
117 {
118 List<Point2D> points = new List<Point2D>();
119
120 int i;
121 double r = offsetRadius;
122 double theta = offsetAngle;
123 for (i = 0; i < steps; i++)
124 {
125 r += incRadius;
126 theta += incAngle;
127
128 int[] coords = polarToCoordinates(r, theta);
129 points.Add(new Point2D(coords[0],coords[1]));
130 }
131
132 voronoiDiagram(points, c);
133 }
134
135 public void Spiral(double wid, double hig, double offset)
136 {
137 int x, y, z;
138 z = 0;
139 for (x = 0; x < w; x++)
140 {
141 for (y = 0; y < h; y++)
142 {
143 z++;
144 double dx = Math.Abs((w / 2) - x);
145 double dy = Math.Abs((h / 2) - y);
146 map[x, y] += Math.Sin(dx / wid) + Math.Cos(dy / hig);
147 }
148 }
149 normalise();
150 }
151 }
152} \ No newline at end of file