From f84937367f7180140bd17444d507977f9b7e3d2e Mon Sep 17 00:00:00 2001 From: Adam Frisby Date: Sat, 21 Jul 2007 22:25:42 +0000 Subject: * Deleted libTerrain-BSD.dll * Added libTerrain to BasicTerrain directly as a subfolder --- .../libTerrainBSD/Channel/Generators/Cellular.cs | 1 + .../libTerrainBSD/Channel/Generators/Fracture.cs | 113 +++++++++ .../libTerrainBSD/Channel/Generators/Gradient.cs | 67 +++++ .../Channel/Generators/HillPlanter.cs | 278 +++++++++++++++++++++ .../libTerrainBSD/Channel/Generators/Midpoint.cs | 1 + .../libTerrainBSD/Channel/Generators/Mountain.cs | 1 + .../libTerrainBSD/Channel/Generators/Noise.cs | 57 +++++ .../libTerrainBSD/Channel/Generators/Spiral.cs | 152 +++++++++++ .../libTerrainBSD/Channel/Generators/Voronoi.cs | 212 ++++++++++++++++ .../libTerrainBSD/Channel/Generators/Worms.cs | 75 ++++++ 10 files changed, 957 insertions(+) create mode 100644 OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Generators/Cellular.cs create mode 100644 OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Generators/Fracture.cs create mode 100644 OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Generators/Gradient.cs create mode 100644 OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Generators/HillPlanter.cs create mode 100644 OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Generators/Midpoint.cs create mode 100644 OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Generators/Mountain.cs create mode 100644 OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Generators/Noise.cs create mode 100644 OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Generators/Spiral.cs create mode 100644 OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Generators/Voronoi.cs create mode 100644 OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Generators/Worms.cs (limited to 'OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Generators') diff --git a/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Generators/Cellular.cs b/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Generators/Cellular.cs new file mode 100644 index 0000000..0cec05d --- /dev/null +++ b/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Generators/Cellular.cs @@ -0,0 +1 @@ +/* Needs BSD rewrite */ \ No newline at end of file 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 @@ +/* +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are +met: + + * Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + + * Redistributions in binary form must reproduce the above + copyright notice, this list of conditions and the following + disclaimer in the documentation and/or other materials provided + with the distribution. + + * Neither the name of libTerrain nor the names of + its contributors may be used to endorse or promote products + derived from this software without specific prior written + permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + +using System; +using System.Collections.Generic; +using System.Text; + +namespace libTerrain +{ + partial class Channel + { + /// + /// Produces a set of coordinates defined by an edge point. Eg - 0 = 0,0. 256 = 0,256. 512 = 256,256 + /// Assumes a 256^2 heightmap. This needs fixing for input values of w,h + /// + /// + /// + /// + /// + private int[] radialEdge256(int val) + { + // Four cases: + // 1. 000..255 return 0,val + // 2. 256..511 return val - 256,255 + // 3. 512..767 return 255, val - 511 + // 4. 768..1023 return val - 768,0 + + int[] ret = new int[2]; + + if (val < 256) + { + ret[0] = 0; + ret[1] = val; + return ret; + } + if (val < 512) + { + ret[0] = (val % 256); + ret[1] = 255; + return ret; + } + if (val < 768) + { + ret[0] = 255; + ret[1] = 255 - (val % 256); + return ret; + } + if (val < 1024) + { + ret[0] = 255 - (val % 256); + ret[1] = 255; + return ret; + } + + throw new Exception("Out of bounds parameter (val)"); + } + public void fracture(int number, double scalemin, double scalemax) + { + Random rand = new Random(seed); + + for (int i = 0; i < number; i++) + { + int[] a, b; + + a = radialEdge256(rand.Next(1023)); // TODO: Broken + b = radialEdge256(rand.Next(1023)); // TODO: Broken + double z = rand.NextDouble(); + + for (int x = 0; x < w; x++) + { + for (int y = 0; y < h; y++) + { + double miny = Tools.linearInterpolate(a[1], b[1], (double)x / (double)w); + + if (y > miny) + { + map[x, y] += Tools.linearInterpolate(scalemin, scalemax, z); + } + } + } + } + normalise(); + } + } +} \ 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 new file mode 100644 index 0000000..8f45bf7 --- /dev/null +++ b/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Generators/Gradient.cs @@ -0,0 +1,67 @@ +/* +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are +met: + + * Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + + * Redistributions in binary form must reproduce the above + copyright notice, this list of conditions and the following + disclaimer in the documentation and/or other materials provided + with the distribution. + + * Neither the name of libTerrain nor the names of + its contributors may be used to endorse or promote products + derived from this software without specific prior written + permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + +using System; +using System.Collections.Generic; +using System.Text; + +namespace libTerrain +{ + partial class Channel + { + + public void gradientCube() + { + int x, y; + for (x = 0; x < w; x++) + { + for (y = 0; y < h; y++) + { + map[x, y] = x*y; + } + } + normalise(); + } + + public void gradientStripe() + { + int x, y; + for (x = 0; x < w; x++) + { + for (y = 0; y < h; y++) + { + map[x, y] = x; + } + } + normalise(); + } + } +} \ 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 new file mode 100644 index 0000000..9316911 --- /dev/null +++ b/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Generators/HillPlanter.cs @@ -0,0 +1,278 @@ +/* +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are +met: + + * Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + + * Redistributions in binary form must reproduce the above + copyright notice, this list of conditions and the following + disclaimer in the documentation and/or other materials provided + with the distribution. + + * Neither the name of libTerrain nor the names of + its contributors may be used to endorse or promote products + derived from this software without specific prior written + permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + +using System; +using System.Collections.Generic; +using System.Text; + +namespace libTerrain +{ + partial class Channel + { + /// + /// Generates a series of spheres which are then either max()'d or added together. Inspired by suggestion from jh. + /// + /// 3-Clause BSD Licensed + /// The number of hills to generate + /// The minimum size of each hill + /// The maximum size of each hill + /// Whether to bias hills towards the center of the map + /// Whether to add hills together or to pick the largest value + /// Generates hill-shaped noise instead of consistent hills + public void hillsSpheres(int number, double scale_min, double scale_range, bool island, bool additive, bool noisy) + { + Random random = new Random(seed); + + int x, y; + int i; + + for (i = 0; i < number; i++) + { + double rx = Math.Min(255.0, random.NextDouble() * w); + double ry = Math.Min(255.0, random.NextDouble() * h); + double rand = random.NextDouble(); + + if (island) + { + // Move everything towards the center + rx -= w / 2; + rx /= 2; + rx += w / 2; + + ry -= h / 2; + ry /= 2; + ry += h / 2; + } + + for (x = 0; x < w; x++) + { + for (y = 0; y < h; y++) + { + if (noisy) + rand = random.NextDouble(); + + double z = (scale_min + (scale_range * rand)); + z *= z; + z -= ((x - rx) * (x - rx)) + ((y - ry) * (y - ry)); + + if (z < 0) + z = 0; + + if (additive) + { + map[x, y] += z; + } + else + { + map[x, y] = Math.Max(map[x, y], z); + } + } + } + } + + normalise(); + } + + /// + /// Generates a series of cones which are then either max()'d or added together. Inspired by suggestion from jh. + /// + /// 3-Clause BSD Licensed + /// The number of hills to generate + /// The minimum size of each hill + /// The maximum size of each hill + /// Whether to bias hills towards the center of the map + /// Whether to add hills together or to pick the largest value + /// Generates hill-shaped noise instead of consistent hills + public void hillsCones(int number, double scale_min, double scale_range, bool island, bool additive, bool noisy) + { + Random random = new Random(seed); + + int x, y; + int i; + + for (i = 0; i < number; i++) + { + double rx = Math.Min(255.0, random.NextDouble() * w); + double ry = Math.Min(255.0, random.NextDouble() * h); + double rand = random.NextDouble(); + + if (island) + { + // Move everything towards the center + rx -= w / 2; + rx /= 2; + rx += w / 2; + + ry -= h / 2; + ry /= 2; + ry += h / 2; + } + + for (x = 0; x < w; x++) + { + for (y = 0; y < h; y++) + { + if (noisy) + rand = random.NextDouble(); + + double z = (scale_min + (scale_range * rand)); + z -= Math.Sqrt(((x - rx) * (x - rx)) + ((y - ry) * (y - ry))); + + if (z < 0) + z = 0; + + if (additive) + { + map[x, y] += z; + } + else + { + map[x, y] = Math.Max(map[x, y], z); + } + } + } + } + + normalise(); + } + + public void hillsBlocks(int number, double scale_min, double scale_range, bool island, bool additive, bool noisy) + { + Random random = new Random(seed); + + int x, y; + int i; + + for (i = 0; i < number; i++) + { + double rx = Math.Min(255.0, random.NextDouble() * w); + double ry = Math.Min(255.0, random.NextDouble() * h); + double rand = random.NextDouble(); + + if (island) + { + // Move everything towards the center + rx -= w / 2; + rx /= 2; + rx += w / 2; + + ry -= h / 2; + ry /= 2; + ry += h / 2; + } + + for (x = 0; x < w; x++) + { + for (y = 0; y < h; y++) + { + if (noisy) + rand = random.NextDouble(); + + double z = (scale_min + (scale_range * rand)); + z -= Math.Abs(x-rx) + Math.Abs(y-ry); + //z -= Math.Sqrt(((x - rx) * (x - rx)) + ((y - ry) * (y - ry))); + + if (z < 0) + z = 0; + + if (additive) + { + map[x, y] += z; + } + else + { + map[x, y] = Math.Max(map[x, y], z); + } + } + } + } + + normalise(); + } + + public void hillsSquared(int number, double scale_min, double scale_range, bool island, bool additive, bool noisy) + { + Random random = new Random(seed); + + int x, y; + int i; + + for (i = 0; i < number; i++) + { + double rx = Math.Min(255.0, random.NextDouble() * w); + double ry = Math.Min(255.0, random.NextDouble() * h); + double rand = random.NextDouble(); + + if (island) + { + // Move everything towards the center + rx -= w / 2; + rx /= 2; + rx += w / 2; + + ry -= h / 2; + ry /= 2; + ry += h / 2; + } + + for (x = 0; x < w; x++) + { + for (y = 0; y < h; y++) + { + if (noisy) + rand = random.NextDouble(); + + double z = (scale_min + (scale_range * rand)); + z *= z * z * z; + double dx = Math.Abs(x - rx); + double dy = Math.Abs(y - ry); + z -= (dx * dx * dx * dx) + (dy * dy * dy * dy); + + if (z < 0) + z = 0; + + if (additive) + { + map[x, y] += z; + } + else + { + map[x, y] = Math.Max(map[x, y], z); + } + } + } + } + + normalise(); + } + + } +} diff --git a/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Generators/Midpoint.cs b/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Generators/Midpoint.cs new file mode 100644 index 0000000..0cec05d --- /dev/null +++ b/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Generators/Midpoint.cs @@ -0,0 +1 @@ +/* Needs BSD rewrite */ \ No newline at end of file diff --git a/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Generators/Mountain.cs b/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Generators/Mountain.cs new file mode 100644 index 0000000..0cec05d --- /dev/null +++ b/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Generators/Mountain.cs @@ -0,0 +1 @@ +/* Needs BSD rewrite */ \ No newline at end of file diff --git a/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Generators/Noise.cs b/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Generators/Noise.cs new file mode 100644 index 0000000..7789d3e --- /dev/null +++ b/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Generators/Noise.cs @@ -0,0 +1,57 @@ +/* +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are +met: + + * Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + + * Redistributions in binary form must reproduce the above + copyright notice, this list of conditions and the following + disclaimer in the documentation and/or other materials provided + with the distribution. + + * Neither the name of libTerrain nor the names of + its contributors may be used to endorse or promote products + derived from this software without specific prior written + permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + +using System; +using System.Collections.Generic; +using System.Text; + +namespace libTerrain +{ + partial class Channel + { + /// + /// Fills a channel with 0..1 noise + /// + /// 3-Clause BSD Licensed + public void noise() + { + Random rand = new Random(seed); + int x, y; + for (x = 0; x < w; x++) + { + for (y = 0; y < h; y++) + { + map[x, y] = rand.NextDouble(); + } + } + } + } +} 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 @@ +/* +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are +met: + + * Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + + * Redistributions in binary form must reproduce the above + copyright notice, this list of conditions and the following + disclaimer in the documentation and/or other materials provided + with the distribution. + + * Neither the name of libTerrain nor the names of + its contributors may be used to endorse or promote products + derived from this software without specific prior written + permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + +using System; +using System.Collections.Generic; +using System.Text; + +namespace libTerrain +{ + partial class Channel + { + private double[] coordinatesToPolar(int x, int y) + { + + double theta = Math.Atan2(x - (w / 2), y - (h / 2)); + double rx = (double)x - ((double)w / 2); + double ry = (double)y - ((double)h / 2); + double r = Math.Sqrt((rx * rx) + (ry * ry)); + + double[] coords = new double[2]; + coords[0] = r; + coords[1] = theta; + return coords; + } + + public int[] polarToCoordinates(double r, double theta) { + double nx; + double ny; + + nx = (double)r * Math.Cos(theta); + ny = (double)r * Math.Sin(theta); + + nx += w / 2; + ny += h / 2; + + if (nx >= w) + nx = w - 1; + + if (ny >= h) + ny = h - 1; + + if (nx < 0) + nx = 0; + + if (ny < 0) + ny = 0; + + int[] coords = new int[2]; + coords[0] = (int)nx; + coords[1] = (int)ny; + return coords; + } + + public void Polar() + { + Channel n = this.copy(); + + int x, y; + for (x = 0; x < w; x++) + { + for (y = 0; y < h; y++) + { + double[] coords = coordinatesToPolar(x,y); + + coords[0] += w / 2.0; + coords[1] += h / 2.0; + + map[x, y] = n.map[(int)coords[0] % n.w, (int)coords[1] % n.h]; + } + } + } + + public void SpiralPlanter(int steps, double incAngle, double incRadius, double offsetRadius, double offsetAngle) + { + int i; + double r = offsetRadius; + double theta = offsetAngle; + for (i = 0; i < steps; i++) + { + r += incRadius; + theta += incAngle; + + int[] coords = polarToCoordinates(r,theta); + raise(coords[0], coords[1], 20, 1); + } + } + + public void SpiralCells(int steps, double incAngle, double incRadius, double offsetRadius, double offsetAngle, double[] c) + { + List points = new List(); + + int i; + double r = offsetRadius; + double theta = offsetAngle; + for (i = 0; i < steps; i++) + { + r += incRadius; + theta += incAngle; + + int[] coords = polarToCoordinates(r, theta); + points.Add(new Point2D(coords[0],coords[1])); + } + + voronoiDiagram(points, c); + } + + public void Spiral(double wid, double hig, double offset) + { + int x, y, z; + z = 0; + for (x = 0; x < w; x++) + { + for (y = 0; y < h; y++) + { + z++; + double dx = Math.Abs((w / 2) - x); + double dy = Math.Abs((h / 2) - y); + map[x, y] += Math.Sin(dx / wid) + Math.Cos(dy / hig); + } + } + normalise(); + } + } +} \ 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 new file mode 100644 index 0000000..df21ecc --- /dev/null +++ b/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Generators/Voronoi.cs @@ -0,0 +1,212 @@ +/* +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are +met: + + * Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + + * Redistributions in binary form must reproduce the above + copyright notice, this list of conditions and the following + disclaimer in the documentation and/or other materials provided + with the distribution. + + * Neither the name of libTerrain nor the names of + its contributors may be used to endorse or promote products + derived from this software without specific prior written + permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + +using System; +using System.Collections.Generic; +using System.Text; + +namespace libTerrain +{ + partial class Channel + { + /// + /// Generates a Voronoi diagram (sort of a stained glass effect) which will fill the entire channel + /// + /// 3-Clause BSD Licensed + /// The number of generator points in each block + /// A multiple of the channel width and height which will have voronoi points generated in it. + /// This is to ensure a more even distribution of the points than pure random allocation. + /// 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. + public void voronoiDiagram(int pointsPerBlock, int blockSize, double[] c) + { + List points = new List(); + Random generator = new Random(seed); + + // Generate the emitter points + int x, y, i; + for (x = -blockSize; x < w + blockSize; x += blockSize) + { + for (y = -blockSize; y < h + blockSize; y += blockSize) + { + for (i = 0; i < pointsPerBlock; i++) + { + double pX = x + (generator.NextDouble() * (double)blockSize); + double pY = y + (generator.NextDouble() * (double)blockSize); + + points.Add(new Point2D(pX, pY)); + } + } + } + + double[] distances = new double[points.Count]; + + // Calculate the distance each pixel is from an emitter + for (x = 0; x < w; x++) + { + for (y = 0; y < h; y++) + { + for (i = 0; i < points.Count; i++) + { + double dx, dy; + dx = Math.Abs((double)x - points[i].x); + dy = Math.Abs((double)y - points[i].y); + + distances[i] = (dx * dx + dy * dy); + } + + Array.Sort(distances); + + double f = 0.0; + + // Multiply the distances with their 'c' counterpart + // ordering the distances descending + for (i = 0; i < c.Length; i++) + { + if (i >= points.Count) + break; + + f += c[i] * distances[i]; + } + + map[x, y] = f; + } + } + + // Normalise the result + normalise(); + } + + public void voronoiDiagram(List points, double[] c) + { + + Random generator = new Random(seed); + int x, y, i; + double[] distances = new double[points.Count]; + + // Calculate the distance each pixel is from an emitter + for (x = 0; x < w; x++) + { + for (y = 0; y < h; y++) + { + for (i = 0; i < points.Count; i++) + { + double dx, dy; + dx = Math.Abs((double)x - points[i].x); + dy = Math.Abs((double)y - points[i].y); + + distances[i] = (dx * dx + dy * dy); + } + + Array.Sort(distances); + + double f = 0.0; + + // Multiply the distances with their 'c' counterpart + // ordering the distances descending + for (i = 0; i < c.Length; i++) + { + if (i >= points.Count) + break; + + f += c[i] * distances[i]; + } + + map[x, y] = f; + } + } + + // Normalise the result + normalise(); + } + + public void voroflatDiagram(int pointsPerBlock, int blockSize) + { + List points = new List(); + Random generator = new Random(seed); + + // Generate the emitter points + int x, y, i; + for (x = -blockSize; x < w + blockSize; x += blockSize) + { + for (y = -blockSize; y < h + blockSize; y += blockSize) + { + for (i = 0; i < pointsPerBlock; i++) + { + double pX = x + (generator.NextDouble() * (double)blockSize); + double pY = y + (generator.NextDouble() * (double)blockSize); + + points.Add(new Point2D(pX, pY)); + } + } + } + + double[] distances = new double[points.Count]; + + // Calculate the distance each pixel is from an emitter + for (x = 0; x < w; x++) + { + for (y = 0; y < h; y++) + { + for (i = 0; i < points.Count; i++) + { + double dx, dy; + dx = Math.Abs((double)x - points[i].x); + dy = Math.Abs((double)y - points[i].y); + + distances[i] = (dx * dx + dy * dy); + } + + //Array.Sort(distances); + + double f = 0.0; + + double min = double.MaxValue; + for (int j = 0; j < distances.Length;j++ ) + { + if (distances[j] < min) + { + min = distances[j]; + f = j; + } + } + + // Multiply the distances with their 'c' counterpart + // ordering the distances descending + + map[x, y] = f; + } + } + + // Normalise the result + normalise(); + } + } +} diff --git a/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Generators/Worms.cs b/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Generators/Worms.cs new file mode 100644 index 0000000..a54c946 --- /dev/null +++ b/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Generators/Worms.cs @@ -0,0 +1,75 @@ +/* +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are +met: + + * Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + + * Redistributions in binary form must reproduce the above + copyright notice, this list of conditions and the following + disclaimer in the documentation and/or other materials provided + with the distribution. + + * Neither the name of libTerrain nor the names of + its contributors may be used to endorse or promote products + derived from this software without specific prior written + permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + +using System; +using System.Collections.Generic; +using System.Text; + +namespace libTerrain +{ + partial class Channel + { + /// + /// Generates 'number' of worms which navigate randomly around the landscape creating terrain as they go. + /// + /// The number of worms which will traverse the map + /// The number of steps each worm will traverse + /// The maximum distance each worm will move each step + /// The size of the area around the worm modified + /// Do worms start in the middle, or randomly? + public void worms(int number, int rounds, double movement, double size, bool centerspawn) + { + Random random = new Random(seed); + int i, j; + + for (i = 0; i < number; i++) + { + double rx, ry; + if (centerspawn) + { + rx = w / 2.0; + ry = h / 2.0; + } + else + { + rx = random.NextDouble() * (w - 1); + ry = random.NextDouble() * (h - 1); + } + for (j = 0; j < rounds; j++) + { + rx += (random.NextDouble() * movement) - (movement / 2.0); + ry += (random.NextDouble() * movement) - (movement / 2.0); + raise(rx, ry, size, 1.0); + } + } + } + } +} \ No newline at end of file -- cgit v1.1