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 --- .../Region/Terrain.BasicTerrain/TerrainEngine.cs | 4 +- .../libTerrainBSD/Bitmap/Bitmap.cs | 77 ++++++ .../libTerrainBSD/Channel/Channel.cs | 66 +++++ .../libTerrainBSD/Channel/Common.cs | 228 +++++++++++++++++ .../libTerrainBSD/Channel/Editing/Flatten.cs | 102 ++++++++ .../libTerrainBSD/Channel/Editing/Raise.cs | 142 +++++++++++ .../libTerrainBSD/Channel/File.cs | 75 ++++++ .../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 ++++++ .../libTerrainBSD/Channel/Grid.cs | 264 +++++++++++++++++++ .../Channel/Manipulators/AerobicErosion.cs | 170 +++++++++++++ .../Channel/Manipulators/HydraulicErosion.cs | 1 + .../Channel/Manipulators/ThermalWeathering.cs | 113 +++++++++ .../libTerrainBSD/Channel/Neighbours.cs | 144 +++++++++++ .../libTerrainBSD/Channel/Operators.cs | 221 ++++++++++++++++ .../libTerrainBSD/Tools/Point2D.cs | 49 ++++ .../libTerrainBSD/Tools/Tools.cs | 60 +++++ 25 files changed, 2671 insertions(+), 2 deletions(-) create mode 100644 OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Bitmap/Bitmap.cs create mode 100644 OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Channel.cs create mode 100644 OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Common.cs create mode 100644 OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Editing/Flatten.cs create mode 100644 OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Editing/Raise.cs create mode 100644 OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/File.cs 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 create mode 100644 OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Grid.cs create mode 100644 OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Manipulators/AerobicErosion.cs create mode 100644 OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Manipulators/HydraulicErosion.cs create mode 100644 OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Manipulators/ThermalWeathering.cs create mode 100644 OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Neighbours.cs create mode 100644 OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Operators.cs create mode 100644 OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Tools/Point2D.cs create mode 100644 OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Tools/Tools.cs (limited to 'OpenSim/Region') diff --git a/OpenSim/Region/Terrain.BasicTerrain/TerrainEngine.cs b/OpenSim/Region/Terrain.BasicTerrain/TerrainEngine.cs index f965c41..7eb90a8 100644 --- a/OpenSim/Region/Terrain.BasicTerrain/TerrainEngine.cs +++ b/OpenSim/Region/Terrain.BasicTerrain/TerrainEngine.cs @@ -111,11 +111,11 @@ namespace OpenSim.Region.Terrain { if ((heightmap.get(x, y) > revertmap.get(x, y) + maxRaise)) { - heightmap.map[x, y] = revertmap(x, y) + maxRaise; + heightmap.map[x, y] = revertmap.get(x, y) + maxRaise; } if ((heightmap.get(x, y) > revertmap.get(x, y) - minLower)) { - heightmap.map[x, y] = revertmap(x, y) - minLower; + heightmap.map[x, y] = revertmap.get(x, y) - minLower; } } } diff --git a/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Bitmap/Bitmap.cs b/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Bitmap/Bitmap.cs new file mode 100644 index 0000000..923da47 --- /dev/null +++ b/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Bitmap/Bitmap.cs @@ -0,0 +1,77 @@ +/* +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; +using System.Drawing; + +namespace libTerrain +{ + class Raster + { + int w; + int h; + Bitmap bmp; + + public Raster(int width, int height) + { + w = width; + h = height; + bmp = new Bitmap(width, height, System.Drawing.Imaging.PixelFormat.Format24bppRgb); + } + + public Channel toChannel() + { + Channel chan = new Channel(bmp.Width, bmp.Height); + + int x, y; + for (x = 0; x < bmp.Width; x++) + { + for (y = 0; y < bmp.Height; y++) + { + Color val = bmp.GetPixel(x, y); + chan.map[x, y] = (((double)val.R + (double)val.G + (double)val.B) / 3.0) / 255.0; + } + } + + return chan; + } + + public void drawText(string txt, string font, double size) + { + Graphics gd = Graphics.FromImage(bmp); + //gd.DrawString(txt, + + + } + } +} diff --git a/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Channel.cs b/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Channel.cs new file mode 100644 index 0000000..9849ef2 --- /dev/null +++ b/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Channel.cs @@ -0,0 +1,66 @@ +/* +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; + + +/* Channel + * A channel is a single heightmap array + * */ + +namespace libTerrain +{ + partial class Channel + { + public double[,] map; + public int w; + public int h; + + public int seed = 1338; // One better than 1337 + + public Channel() + { + w = 256; + h = 256; + map = new double[w, h]; + } + + public Channel(int width, int height) + { + w = width; + h = height; + map = new double[w, h]; + } + + } +} diff --git a/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Common.cs b/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Common.cs new file mode 100644 index 0000000..438359c --- /dev/null +++ b/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Common.cs @@ -0,0 +1,228 @@ +/* +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 +{ + public partial class Channel + { + public int getWidth() + { + return w; + } + public int getHeight() + { + return h; + } + + public Channel copy() + { + Channel x = new Channel(w, h); + x.map = (double[,])this.map.Clone(); + return x; + } + + public void set(int x, int y, double val) + { + if (x >= w) + throw new Exception("Bounds error while setting pixel (width)"); + if (y >= h) + throw new Exception("Bounds error while setting pixel (height)"); + if (x < 0) + throw new Exception("Bounds error while setting pixel (width)"); + if (y < 0) + throw new Exception("Bounds error while setting pixel (height)"); + + map[x, y] = val; + } + + public void setClip(int x, int y, double val) + { + if (x >= w) + throw new Exception("Bounds error while setting pixel (width)"); + if (y >= h) + throw new Exception("Bounds error while setting pixel (height)"); + if (x < 0) + throw new Exception("Bounds error while setting pixel (width)"); + if (y < 0) + throw new Exception("Bounds error while setting pixel (height)"); + + if (val > 1.0) + val = 1.0; + if (val < 0.0) + val = 0.0; + + map[x, y] = val; + } + + private double getBilinearInterpolate(double x, double y) + { + if (x > w - 2.0) + x = w - 2.0; + if (y > h - 2.0) + y = h - 2.0; + if (x < 0.0) + x = 0.0; + if (y < 0.0) + y = 0.0; + + int STEP_SIZE = 1; + double h00 = get((int)x, (int)y); + double h10 = get((int)x + STEP_SIZE, (int)y); + double h01 = get((int)x, (int)y + STEP_SIZE); + double h11 = get((int)x + STEP_SIZE, (int)y + STEP_SIZE); + double h1 = h00; + double h2 = h10; + double h3 = h01; + double h4 = h11; + double a00 = h1; + double a10 = h2 - h1; + double a01 = h3 - h1; + double a11 = h1 - h2 - h3 + h4; + double partialx = x - (int)x; + double partialz = y - (int)y; + double hi = a00 + (a10 * partialx) + (a01 * partialz) + (a11 * partialx * partialz); + return hi; + } + + public double get(int x, int y) + { + if (x >= w) + x = w - 1; + if (y >= h) + y = h - 1; + if (x < 0) + x = 0; + if (y < 0) + y = 0; + return map[x, y]; + } + + public void setWrap(int x, int y, double val) + { + map[x % w, y % h] = val; + } + + public void setWrapClip(int x, int y, double val) + { + if (val > 1.0) + val = 1.0; + if (val < 0.0) + val = 0.0; + + map[x % w, y % h] = val; + } + + public void fill(double val) + { + int x, y; + for (x = 0; x < w; x++) + { + for (y = 0; y < h; y++) + { + map[x, y] = val; + } + } + } + + public void fill(double min, double max, double val) + { + int x, y; + for (x = 0; x < w; x++) + { + for (y = 0; y < h; y++) + { + if (map[x, y] >= min && map[x, y] <= max) + map[x, y] = val; + } + } + } + + public double findMax() + { + int x, y; + double max = double.MinValue; + + for (x = 0; x < w; x++) + { + for (y = 0; y < h; y++) + { + if (map[x, y] > max) + max = map[x, y]; + } + } + + return max; + } + + public double findMin() + { + int x, y; + double min = double.MaxValue; + + for (x = 0; x < w; x++) + { + for (y = 0; y < h; y++) + { + if (map[x, y] < min) + min = map[x, y]; + } + } + + return min; + } + + public double sum() + { + int x, y; + double sum = 0.0; + + for (x = 0; x < w; x++) + { + for (y = 0; y < h; y++) + { + sum += map[x, y]; + } + } + + return sum; + } + + public double avg() + { + return sum() / (w * h); + } + } +} diff --git a/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Editing/Flatten.cs b/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Editing/Flatten.cs new file mode 100644 index 0000000..5e5254d --- /dev/null +++ b/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Editing/Flatten.cs @@ -0,0 +1,102 @@ +/* +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 + { + /// + /// Flattens the area underneath rx,ry by moving it to the average of the area. Uses a spherical mask provided by the raise() function. + /// + /// The X coordinate of the terrain mask + /// The Y coordinate of the terrain mask + /// The size of the terrain mask + /// The scale of the terrain mask + public void flatten(double rx, double ry, double size, double amount) + { + // Generate the mask + Channel temp = new Channel(w, h); + temp.fill(0); + temp.raise(rx, ry, size, amount); + temp.normalise(); + double total_mod = temp.sum(); + + // Establish the average height under the area + Channel newmap = new Channel(w, h); + newmap.map = (double[,])map.Clone(); + + newmap *= temp; + + double total_terrain = newmap.sum(); + double avg_height = total_terrain / total_mod; + + // Create a flat terrain using the average height + Channel flat = new Channel(w, h); + flat.fill(avg_height); + + // Blend the current terrain with the average height terrain + // using the "raised" empty terrain as a mask + blend(flat, temp); + + } + + public void flatten(Channel mask, double amount) + { + // Generate the mask + Channel temp = mask * amount; + temp.clip(0, 1); // Cut off out-of-bounds values + + double total_mod = temp.sum(); + + // Establish the average height under the area + Channel map = new Channel(w, h); + map.map = (double[,])this.map.Clone(); + + map *= temp; + + double total_terrain = map.sum(); + double avg_height = total_terrain / total_mod; + + // Create a flat terrain using the average height + Channel flat = new Channel(w, h); + flat.fill(avg_height); + + // Blend the current terrain with the average height terrain + // using the "raised" empty terrain as a mask + blend(flat, temp); + } + } +} \ No newline at end of file diff --git a/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Editing/Raise.cs b/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Editing/Raise.cs new file mode 100644 index 0000000..21d2645 --- /dev/null +++ b/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Editing/Raise.cs @@ -0,0 +1,142 @@ +/* +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 + { + /// + /// Raises land around the selection + /// + /// The center the X coordinate of where you wish to raise the land + /// The center the Y coordinate of where you wish to raise the land + /// The radius of the dimple + /// How much impact to add to the terrain (0..2 usually) + public void raise(double rx, double ry, double size, double amount) + { + raiseSphere(rx, ry, size, amount); + } + + /// + /// Raises land in a sphere around the selection + /// + /// The center the X coordinate of where you wish to raise the land + /// The center the Y coordinate of where you wish to raise the land + /// The radius of the sphere dimple + /// How much impact to add to the terrain (0..2 usually) + public void raiseSphere(double rx, double ry, double size, double amount) + { + int x, y; + for (x = 0; x < w; x++) + { + for (y = 0; y < h; y++) + { + double z = size; + z *= z; + z -= ((x - rx) * (x - rx)) + ((y - ry) * (y - ry)); + + if (z < 0) + z = 0; + + map[x, y] += z * amount; + } + } + } + + /// + /// Raises land in a cone around the selection + /// + /// The center the X coordinate of where you wish to raise the land + /// The center the Y coordinate of where you wish to raise the land + /// The radius of the cone + /// How much impact to add to the terrain (0..2 usually) + public void raiseCone(double rx, double ry, double size, double amount) + { + int x, y; + for (x = 0; x < w; x++) + { + for (y = 0; y < h; y++) + { + double z = size; + z -= Math.Sqrt(((x - rx) * (x - rx)) + ((y - ry) * (y - ry))); + + if (z < 0) + z = 0; + + map[x, y] += z * amount; + } + } + } + + /// + /// Lowers land in a sphere around the selection + /// + /// The center the X coordinate of where you wish to lower the land + /// The center the Y coordinate of where you wish to lower the land + /// The radius of the sphere dimple + /// How much impact to remove from the terrain (0..2 usually) + public void lower(double rx, double ry, double size, double amount) + { + lowerSphere(rx, ry, size, amount); + } + + /// + /// Lowers land in a sphere around the selection + /// + /// The center the X coordinate of where you wish to lower the land + /// The center the Y coordinate of where you wish to lower the land + /// The radius of the sphere dimple + /// How much impact to remove from the terrain (0..2 usually) + public void lowerSphere(double rx, double ry, double size, double amount) + { + int x, y; + for (x = 0; x < w; x++) + { + for (y = 0; y < h; y++) + { + double z = size; + z *= z; + z -= ((x - rx) * (x - rx)) + ((y - ry) * (y - ry)); + + if (z < 0) + z = 0; + + map[x, y] -= z * amount; + } + } + } + } +} \ No newline at end of file diff --git a/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/File.cs b/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/File.cs new file mode 100644 index 0000000..4163a5f --- /dev/null +++ b/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/File.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; +using System.Drawing; + +namespace libTerrain +{ + partial class Channel + { + public Channel loadImage(string filename) + { + Bitmap bit = new Bitmap(filename); + Channel chan = new Channel(bit.Width, bit.Height); + + int x, y; + for (x = 0; x < bit.Width; x++) + { + for (y = 0; y < bit.Height; y++) + { + Color val = bit.GetPixel(x, y); + chan.map[x, y] = (((double)val.R + (double)val.G + (double)val.B) / 3.0) / 255.0; + } + } + + return chan; + } + + public void saveImage(string filename) + { + Bitmap bit = new Bitmap(w, h, System.Drawing.Imaging.PixelFormat.Format24bppRgb); + int x, y; + for (x = 0; x < w; x++) + { + for (y = 0; y < h; y++) + { + int val = Math.Min(255, (int)(map[x,y] * 255)); + Color col = Color.FromArgb(val,val,val); + bit.SetPixel(x, y, col); + } + } + bit.Save(filename); + } + } +} 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 diff --git a/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Grid.cs b/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Grid.cs new file mode 100644 index 0000000..41d20f6 --- /dev/null +++ b/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Grid.cs @@ -0,0 +1,264 @@ +/* +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 Channel normalise() + { + double max = findMax(); + double min = findMin(); + + int x, y; + + for (x = 0; x < w; x++) + { + for (y = 0; y < h; y++) + { + map[x, y] = (map[x, y] - min) * (1.0 / (max - min)); + } + } + + return this; + } + + public Channel normalise(double minv, double maxv) + { + double max = findMax(); + double min = findMin(); + + int x, y; + + for (x = 0; x < w; x++) + { + for (y = 0; y < h; y++) + { + double val = (map[x, y] - min) * (1.0 / max - min); + val *= maxv - minv; + val += minv; + + map[x, y] = val; + } + } + + return this; + } + + public Channel clip() + { + int x, y; + + for (x = 0; x < w; x++) + { + for (y = 0; y < h; y++) + { + setClip(x, y, map[x, y]); + } + } + + return this; + } + + public Channel clip(double min, double max) + { + int x, y; + for (x = 0; x < w; x++) + { + for (y = 0; y < h; y++) + { + double val = map[x, y]; + if (val > max) val = max; + if (val < min) val = min; + map[x, y] = val; + } + } + return this; + } + + public Channel crop(int x1, int y1, int x2, int y2) + { + int width = x1 - x2 + 1; + int height = y1 - y2 + 1; + Channel chan = new Channel(width, height); + + int x, y; + int nx, ny; + + nx = 0; + for (x = x1; x < x2; x++) + { + ny = 0; + for (y = y1; y < y2; y++) + { + chan.map[nx, ny] = map[x, y]; + + ny++; + } + nx++; + } + + return this; + } + + public Channel addClip(Channel other) + { + int x, y; + for (x = 0; x < w; x++) + { + for (y = 0; y < h; y++) + { + map[x, y] = other.map[x, y]; + if (map[x, y] > 1) + map[x, y] = 1; + if (map[x, y] < 0) + map[x, y] = 0; + } + } + return this; + } + + public void smooth(double amount) + { + double area = amount; + double step = amount / 4.0; + + double[,] manipulate = new double[w, h]; + int x, y; + double n, l; + for (x = 0; x < w; x++) + { + for (y = 0; y < h; y++) + { + double average = 0.0; + int avgsteps = 0; + + for (n = 0.0 - area; n < area; n += step) + { + for (l = 0.0 - area; l < area; l += step) + { + avgsteps++; + average += getBilinearInterpolate(x + n, y + l); + } + } + + manipulate[x, y] = average / avgsteps; + } + } + map = manipulate; + } + + public void pertubation(double amount) + { + // Simple pertubation filter + double[,] manipulated = new double[w, h]; + Random generator = new Random(seed); // Seeds FTW! + //double amount = 8.0; + + int x, y; + for (x = 0; x < w; x++) + { + for (y = 0; y < h; y++) + { + double offset_x = (double)x + (generator.NextDouble() * amount) - (amount / 2.0); + double offset_y = (double)y + (generator.NextDouble() * amount) - (amount / 2.0); + double p = getBilinearInterpolate(offset_x, offset_y); + manipulated[x, y] = p; + } + } + map = manipulated; + } + + public void pertubationMask(Channel mask) + { + // Simple pertubation filter + double[,] manipulated = new double[w, h]; + Random generator = new Random(seed); // Seeds FTW! + //double amount = 8.0; + + double amount; + + int x, y; + for (x = 0; x < w; x++) + { + for (y = 0; y < h; y++) + { + amount = mask.map[x, y]; + double offset_x = (double)x + (generator.NextDouble() * amount) - (amount / 2.0); + double offset_y = (double)y + (generator.NextDouble() * amount) - (amount / 2.0); + + if (offset_x > w) + offset_x = w - 1; + if (offset_y > h) + offset_y = h - 1; + if (offset_y < 0) + offset_y = 0; + if (offset_x < 0) + offset_x = 0; + + double p = getBilinearInterpolate(offset_x, offset_y); + manipulated[x, y] = p; + } + } + map = manipulated; + } + + public Channel blend(Channel other, double amount) + { + int x, y; + for (x = 0; x < w; x++) + { + for (y = 0; y < h; y++) + { + map[x, y] = Tools.linearInterpolate(map[x,y],other.map[x,y],amount); + } + } + return this; + } + + public Channel blend(Channel other, Channel amount) + { + int x, y; + for (x = 0; x < w; x++) + { + for (y = 0; y < h; y++) + { + map[x, y] = Tools.linearInterpolate(map[x, y], other.map[x, y], amount.map[x,y]); + } + } + return this; + } + } +} diff --git a/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Manipulators/AerobicErosion.cs b/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Manipulators/AerobicErosion.cs new file mode 100644 index 0000000..ebeabe9 --- /dev/null +++ b/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Manipulators/AerobicErosion.cs @@ -0,0 +1,170 @@ +/* +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 + { + // Ideas for Aerobic erosion + // + // Unlike thermal (gravity) and hydraulic (water suspension) + // aerobic erosion should displace mass by moving sediment + // in "hops". The length of the hop being dictated by the + // presence of sharp cliffs and wind speed. + + // The ability to pickup sediment is defined by the total + // surface area, such that: + // 0 0 0 + // 0 1 0 + // 0 0 0 + // Would be the best possible value for sediment to be + // picked up (total difference = 8) and flatter land + // will erode less quickly. + + // Suspended particles assist the erosion process by hitting + // the surface and chiselling additional particles off faster + // than alone. + + // Particles are deposited when one of two conditions is met + // First: + // When particles hit a wall - such that the + // wind direction points at a difference >= the + // deposition mininum talus. + // Second: + // When wind speed is lowered to below the minimum + // required for transit. An idea for this is to + // use the navier-stokes algorithms for simulating + // pressure across the terrain. + + /// + /// An experimental erosion algorithm developed by Adam. Moves sediment by factoring the surface area of each height point. + /// + /// 0..1 The speed of the wind + /// The minimum angle at which rock is eroded 0..1 (recommended: <= 0.30) + /// The minimum angle at which rock is dropped 0..1 (recommended: >= 0.00) + /// The percentage of rock which can be picked up to pickup 0..1 + /// The number of erosion rounds (recommended: 25+) + /// Drop sediment at the lowest point? + public void AerobicErosion(double windspeed, double pickup_talus_minimum, double drop_talus_minimum, double carry, int rounds, bool lowest) + { + Channel wind = new Channel(w, h) ; + Channel sediment = new Channel(w, h); + int x, y, i, j; + + wind = this.copy(); + wind.normalise(); // Cheap wind calculations + wind *= windspeed; + wind.pertubation(30); // Can do better later + + for (i = 0; i < rounds; i++) + { + // Convert some rocks to sand + for (x = 1; x < w - 1; x++) + { + for (y = 1; y < h - 1; y++) + { + double me = get(x, y); + double surfacearea = 0.3; // Everything will erode even if it's flat. Just slower. + + for (j = 0; j < 9; j++) + { + int[] coords = neighbours(NEIGHBOURS.NEIGHBOUR_MOORE, j); + double target = get(x + coords[0], y + coords[1]); + + surfacearea += Math.Abs(target - me); + } + + double amount = surfacearea * wind.map[x, y] * carry; + + if (amount < 0) + amount = 0; + + if (surfacearea > pickup_talus_minimum) + { + this.map[x, y] -= amount; + sediment.map[x, y] += amount; + } + } + } + sediment.pertubation(10); // Sediment is blown around a bit + sediment.seed++; + wind.pertubation(15); // So is the wind + wind.seed++; + + // Convert some sand to rock + for (x = 1; x < w - 1; x++) + { + for (y = 1; y < h - 1; y++) + { + double me = get(x, y); + double surfacearea = 0.01; // Flat land does not get deposition + double min = double.MaxValue; + int[] minside = new int[2]; + + for (j = 0; j < 9; j++) + { + int[] coords = neighbours(NEIGHBOURS.NEIGHBOUR_MOORE, j); + double target = get(x + coords[0], y + coords[1]); + + surfacearea += Math.Abs(target - me); + + if (target < min && lowest) + { + minside = (int[])coords.Clone(); + min = target; + } + } + + double amount = surfacearea * (1.0 - wind.map[x, y]) * carry; + + if (amount < 0) + amount = 0; + + if (surfacearea > drop_talus_minimum) + { + this.map[x + minside[0], y + minside[1]] += amount; + sediment.map[x, y] -= amount; + } + } + } + + } + + Channel myself = this; + myself += sediment; + myself.normalise(); + } + } +} \ No newline at end of file diff --git a/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Manipulators/HydraulicErosion.cs b/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Manipulators/HydraulicErosion.cs new file mode 100644 index 0000000..0cec05d --- /dev/null +++ b/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Manipulators/HydraulicErosion.cs @@ -0,0 +1 @@ +/* Needs BSD rewrite */ \ No newline at end of file diff --git a/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Manipulators/ThermalWeathering.cs b/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Manipulators/ThermalWeathering.cs new file mode 100644 index 0000000..0cae56d --- /dev/null +++ b/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Manipulators/ThermalWeathering.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 + { + /// + /// A thermal weathering implementation based on Musgrave's original 1989 algorithm. This is Adam's custom implementation which may differ slightly from the original. + /// + /// The rock angle (represented as a dy/dx ratio) at which point it will be succeptible to breakage + /// The number of erosion rounds + /// The amount of rock to carry each round + public Channel thermalWeathering(double talus, int rounds, double c) + { + double[,] lastFrame; + double[,] thisFrame; + + lastFrame = (double[,])map.Clone(); + thisFrame = (double[,])map.Clone(); + + NEIGHBOURS type = NEIGHBOURS.NEIGHBOUR_MOORE; // Using moore neighbourhood (twice as computationally expensive) + int NEIGHBOUR_ME = 4; // I am always 4 in both systems. + + int NEIGHBOUR_MAX = type == NEIGHBOURS.NEIGHBOUR_MOORE ? 9 : 5; + + int frames = rounds; // Number of thermal erosion iterations to run + int i, j; + int x, y; + + for (i = 0; i < frames; i++) + { + for (x = 0; x < w; x++) + { + for (y = 0; y < h; y++) + { + for (j = 0; j < NEIGHBOUR_MAX; j++) + { + if (j != NEIGHBOUR_ME) + { + int[] coords = neighbours(type, j); + + coords[0] += x; + coords[1] += y; + + if (coords[0] > w - 1) + coords[0] = w - 1; + if (coords[1] > h - 1) + coords[1] = h - 1; + if (coords[0] < 0) + coords[0] = 0; + if (coords[1] < 0) + coords[1] = 0; + + double heightF = thisFrame[x, y]; + double target = thisFrame[coords[0], coords[1]]; + + if (target > heightF + talus) + { + double calc = c * ((target - heightF) - talus); + heightF += calc; + target -= calc; + } + + thisFrame[x, y] = heightF; + thisFrame[coords[0], coords[1]] = target; + + } + } + } + } + lastFrame = (double[,])thisFrame.Clone(); + } + + map = thisFrame; + + normalise(); // Just to guaruntee a smooth 0..1 value + return this; + } + } +} diff --git a/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Neighbours.cs b/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Neighbours.cs new file mode 100644 index 0000000..f2b4aed --- /dev/null +++ b/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Neighbours.cs @@ -0,0 +1,144 @@ +/* +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 + { + enum NEIGHBOURS + { + NEIGHBOUR_MOORE, + NEIGHBOUR_VONNEUMANN + }; + + private int[] neighbours(NEIGHBOURS type, int index) + { + int[] coord = new int[2]; + + index++; + + switch (type) + { + case NEIGHBOURS.NEIGHBOUR_MOORE: + switch (index) + { + case 1: + coord[0] = -1; + coord[1] = -1; + break; + + case 2: + coord[0] = -0; + coord[1] = -1; + break; + + case 3: + coord[0] = +1; + coord[1] = -1; + break; + + case 4: + coord[0] = -1; + coord[1] = -0; + break; + + case 5: + coord[0] = -0; + coord[1] = -0; + break; + + case 6: + coord[0] = +1; + coord[1] = -0; + break; + + case 7: + coord[0] = -1; + coord[1] = +1; + break; + + case 8: + coord[0] = -0; + coord[1] = +1; + break; + + case 9: + coord[0] = +1; + coord[1] = +1; + break; + + default: + break; + } + break; + + case NEIGHBOURS.NEIGHBOUR_VONNEUMANN: + switch (index) + { + case 1: + coord[0] = 0; + coord[1] = -1; + break; + + case 2: + coord[0] = -1; + coord[1] = 0; + break; + + case 3: + coord[0] = +1; + coord[1] = 0; + break; + + case 4: + coord[0] = 0; + coord[1] = +1; + break; + + case 5: + coord[0] = -0; + coord[1] = -0; + break; + + default: + break; + } + break; + } + + return coord; + } + } +} diff --git a/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Operators.cs b/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Operators.cs new file mode 100644 index 0000000..81db690 --- /dev/null +++ b/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Operators.cs @@ -0,0 +1,221 @@ +/* +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 + { + /* Operator combination of channel datatypes */ + + public static Channel operator +(Channel A, Channel B) + { + if (A.h != B.h) + throw new Exception("Cannot add heightmaps, of different height."); + if (A.w != B.w) + throw new Exception("Cannot add heightmaps, of different width."); + + int x, y; + + for (x = 0; x < A.w; x++) + { + for (y = 0; y < A.h; y++) + { + A.map[x, y] += B.map[x, y]; + } + } + + return A; + } + + public static Channel operator *(Channel A, Channel B) + { + if (A.h != B.h) + throw new Exception("Cannot multiply heightmaps, of different height."); + if (A.w != B.w) + throw new Exception("Cannot multiply heightmaps, of different width."); + + int x, y; + + for (x = 0; x < A.w; x++) + { + for (y = 0; y < A.h; y++) + { + A.map[x, y] *= B.map[x, y]; + } + } + + return A; + } + + public static Channel operator -(Channel A, Channel B) + { + if (A.h != B.h) + throw new Exception("Cannot subtract heightmaps, of different height."); + if (A.w != B.w) + throw new Exception("Cannot subtract heightmaps, of different width."); + + int x, y; + + for (x = 0; x < A.w; x++) + { + for (y = 0; y < A.h; y++) + { + A.map[x, y] -= B.map[x, y]; + } + } + + return A; + } + + public static Channel operator /(Channel A, Channel B) + { + if (A.h != B.h) + throw new Exception("Cannot divide heightmaps, of different height."); + if (A.w != B.w) + throw new Exception("Cannot divide heightmaps, of different width."); + + int x, y; + + for (x = 0; x < A.w; x++) + { + for (y = 0; y < A.h; y++) + { + A.map[x, y] /= B.map[x, y]; + } + } + + return A; + } + + public static Channel operator ^(Channel A, Channel B) + { + if (A.h != B.h) + throw new Exception("Cannot divide heightmaps, of different height."); + if (A.w != B.w) + throw new Exception("Cannot divide heightmaps, of different width."); + + int x, y; + + for (x = 0; x < A.w; x++) + { + for (y = 0; y < A.h; y++) + { + A.map[x, y] = Math.Pow(A.map[x,y],B.map[x, y]); + } + } + + return A; + } + + + /* Operator combination of channel and double datatypes */ + + public static Channel operator +(Channel A, double B) + { + int x, y; + + for (x = 0; x < A.w; x++) + { + for (y = 0; y < A.h; y++) + { + A.map[x, y] += B; + } + } + + return A; + } + + public static Channel operator -(Channel A, double B) + { + int x, y; + + for (x = 0; x < A.w; x++) + { + for (y = 0; y < A.h; y++) + { + A.map[x, y] -= B; + } + } + + return A; + } + + public static Channel operator *(Channel A, double B) + { + int x, y; + + for (x = 0; x < A.w; x++) + { + for (y = 0; y < A.h; y++) + { + A.map[x, y] *= B; + } + } + + return A; + } + + public static Channel operator /(Channel A, double B) + { + int x, y; + + for (x = 0; x < A.w; x++) + { + for (y = 0; y < A.h; y++) + { + A.map[x, y] /= B; + } + } + + return A; + } + + public static Channel operator ^(Channel A, double B) + { + int x, y; + + for (x = 0; x < A.w; x++) + { + for (y = 0; y < A.h; y++) + { + A.map[x, y] = Math.Pow(A.map[x,y],B); + } + } + + return A; + } + + } +} diff --git a/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Tools/Point2D.cs b/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Tools/Point2D.cs new file mode 100644 index 0000000..69c1148 --- /dev/null +++ b/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Tools/Point2D.cs @@ -0,0 +1,49 @@ +/* +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 +{ + public class Point2D + { + public double x; + public double y; + + public Point2D(double X, double Y) + { + x = X; + y = Y; + } + } +} diff --git a/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Tools/Tools.cs b/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Tools/Tools.cs new file mode 100644 index 0000000..3f7ab68 --- /dev/null +++ b/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Tools/Tools.cs @@ -0,0 +1,60 @@ +/* +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 +{ + class Tools + { + public static double linearInterpolate(double a, double b, double amount) + { + return a + ((b - a) * amount); + } + public static double exponentialInterpolate(double a, double b, double amount) + { + a = Math.Pow(a, amount); + b = Math.Pow(b - a, 1.0 - amount); + return a+b; + } + public static int powerOf2Log2(int n) { + for (int i = 0; i < 31; i++) { + if ((n & 1) == 1) { + return i; + } + n >>= 1; + } + return 0; + } + } +} -- cgit v1.1