From fb0dffbf13a79aabe9537f16b7bb151af62c75bf Mon Sep 17 00:00:00 2001 From: Adam Frisby Date: Fri, 6 Apr 2007 18:48:23 +0000 Subject: **BREAKING CHANGE** Changing the way terrain is stored and used internally. --- OpenSim.Terrain.BasicTerrain/Hills.cs | 72 ++++++++++++++++ .../OpenSim.Terrain.BasicTerrain.csproj | 4 +- OpenSim.Terrain.BasicTerrain/RaiseLower.cs | 91 +++++++++++++++++++++ OpenSim.Terrain.BasicTerrain/TerrainEngine.cs | 64 +++++++++++++++ OpenSim.Terrain.BasicTerrain/TerrainManager.cs | 11 --- .../bin/Debug/OpenSim.Terrain.BasicTerrain.dll | Bin 0 -> 16384 bytes .../bin/Debug/OpenSim.Terrain.BasicTerrain.pdb | Bin 0 -> 19968 bytes .../obj/Debug/OpenSim.Terrain.BasicTerrain.dll | Bin 0 -> 16384 bytes .../obj/Debug/OpenSim.Terrain.BasicTerrain.pdb | Bin 0 -> 19968 bytes ...penSim.Terrain.BasicTerrain.csproj.FileList.txt | 5 ++ 10 files changed, 235 insertions(+), 12 deletions(-) create mode 100644 OpenSim.Terrain.BasicTerrain/Hills.cs create mode 100644 OpenSim.Terrain.BasicTerrain/RaiseLower.cs create mode 100644 OpenSim.Terrain.BasicTerrain/TerrainEngine.cs delete mode 100644 OpenSim.Terrain.BasicTerrain/TerrainManager.cs create mode 100644 OpenSim.Terrain.BasicTerrain/bin/Debug/OpenSim.Terrain.BasicTerrain.dll create mode 100644 OpenSim.Terrain.BasicTerrain/bin/Debug/OpenSim.Terrain.BasicTerrain.pdb create mode 100644 OpenSim.Terrain.BasicTerrain/obj/Debug/OpenSim.Terrain.BasicTerrain.dll create mode 100644 OpenSim.Terrain.BasicTerrain/obj/Debug/OpenSim.Terrain.BasicTerrain.pdb create mode 100644 OpenSim.Terrain.BasicTerrain/obj/OpenSim.Terrain.BasicTerrain.csproj.FileList.txt (limited to 'OpenSim.Terrain.BasicTerrain') diff --git a/OpenSim.Terrain.BasicTerrain/Hills.cs b/OpenSim.Terrain.BasicTerrain/Hills.cs new file mode 100644 index 0000000..40543a9 --- /dev/null +++ b/OpenSim.Terrain.BasicTerrain/Hills.cs @@ -0,0 +1,72 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace OpenSim.Terrain.BasicTerrain +{ + static class Hills + { + /// + /// 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 static void hillsSpheres(float[,] map,int seed, int number, double scale_min, double scale_range, bool island, bool additive, bool noisy) + { + Random random = new Random(seed); + int w = map.GetLength(0); + int h = map.GetLength(1); + 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] += (float)z; + } + else + { + map[x, y] = (float)Math.Max(map[x, y], z); + } + } + } + } + } + } +} diff --git a/OpenSim.Terrain.BasicTerrain/OpenSim.Terrain.BasicTerrain.csproj b/OpenSim.Terrain.BasicTerrain/OpenSim.Terrain.BasicTerrain.csproj index 4da1ede..2103902 100644 --- a/OpenSim.Terrain.BasicTerrain/OpenSim.Terrain.BasicTerrain.csproj +++ b/OpenSim.Terrain.BasicTerrain/OpenSim.Terrain.BasicTerrain.csproj @@ -33,7 +33,9 @@ - + + + diff --git a/OpenSim.Terrain.BasicTerrain/RaiseLower.cs b/OpenSim.Terrain.BasicTerrain/RaiseLower.cs new file mode 100644 index 0000000..384bcc0 --- /dev/null +++ b/OpenSim.Terrain.BasicTerrain/RaiseLower.cs @@ -0,0 +1,91 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace OpenSim.Terrain.BasicTerrain +{ + static class RaiseLower + { + /// + /// 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 static void raise(float[,] map, double rx, double ry, double size, double amount) + { + raiseSphere(map, 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 static void raiseSphere(float[,] map, double rx, double ry, double size, double amount) + { + int x, y; + int w = map.GetLength(0); + int h = map.GetLength(1); + + 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] += (float)(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 static void lower(float[,] map, double rx, double ry, double size, double amount) + { + lowerSphere(map, 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 static void lowerSphere(float[,] map, double rx, double ry, double size, double amount) + { + int x, y; + int w = map.GetLength(0); + int h = map.GetLength(1); + + 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] -= (float)(z * amount); + } + } + } + } +} diff --git a/OpenSim.Terrain.BasicTerrain/TerrainEngine.cs b/OpenSim.Terrain.BasicTerrain/TerrainEngine.cs new file mode 100644 index 0000000..f805d18 --- /dev/null +++ b/OpenSim.Terrain.BasicTerrain/TerrainEngine.cs @@ -0,0 +1,64 @@ +using System; +using System.Collections.Generic; +using System.Text; +using OpenSim.Terrain.BasicTerrain; + +namespace OpenSim.Terrain +{ + public class TerrainEngine + { + public float[,] map; + public float[,] water; + int w, h; + + public TerrainEngine() + { + w = 256; + h = 256; + map = new float[w, h]; + water = new float[w, h]; + + } + + /// + /// Swaps the references between the height and water buffers to allow you to edit the water heightmap. Remember to swap back when you are done. + /// + public void swapWaterBuffer() + { + float[,] temp = map; + map = water; + water = temp; + } + + /// + /// Raises land in a sphere around the specified coordinates + /// + /// Center of the sphere on the X axis + /// Center of the sphere on the Y axis + /// The radius of the sphere + /// Scale the height of the sphere by this amount (recommended 0..2) + public void raise(double rx, double ry, double size, double amount) + { + lock (map) + { + RaiseLower.raiseSphere(this.map, rx, ry, size, amount); + } + } + public void lower(double rx, double ry, double size, double amount) + { + lock (map) + { + RaiseLower.lowerSphere(this.map, rx, ry, size, amount); + } + } + + public void hills() + { + lock (map) + { + Hills.hillsSpheres(this.map, 1337, 200, 20, 40, true, true, false); + } + } + + } +} diff --git a/OpenSim.Terrain.BasicTerrain/TerrainManager.cs b/OpenSim.Terrain.BasicTerrain/TerrainManager.cs deleted file mode 100644 index 65880eb..0000000 --- a/OpenSim.Terrain.BasicTerrain/TerrainManager.cs +++ /dev/null @@ -1,11 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Text; - -namespace OpenSim.Terrain -{ - public class TerrainManager - { - - } -} diff --git a/OpenSim.Terrain.BasicTerrain/bin/Debug/OpenSim.Terrain.BasicTerrain.dll b/OpenSim.Terrain.BasicTerrain/bin/Debug/OpenSim.Terrain.BasicTerrain.dll new file mode 100644 index 0000000..0cfa595 Binary files /dev/null and b/OpenSim.Terrain.BasicTerrain/bin/Debug/OpenSim.Terrain.BasicTerrain.dll differ diff --git a/OpenSim.Terrain.BasicTerrain/bin/Debug/OpenSim.Terrain.BasicTerrain.pdb b/OpenSim.Terrain.BasicTerrain/bin/Debug/OpenSim.Terrain.BasicTerrain.pdb new file mode 100644 index 0000000..ce440c6 Binary files /dev/null and b/OpenSim.Terrain.BasicTerrain/bin/Debug/OpenSim.Terrain.BasicTerrain.pdb differ diff --git a/OpenSim.Terrain.BasicTerrain/obj/Debug/OpenSim.Terrain.BasicTerrain.dll b/OpenSim.Terrain.BasicTerrain/obj/Debug/OpenSim.Terrain.BasicTerrain.dll new file mode 100644 index 0000000..0cfa595 Binary files /dev/null and b/OpenSim.Terrain.BasicTerrain/obj/Debug/OpenSim.Terrain.BasicTerrain.dll differ diff --git a/OpenSim.Terrain.BasicTerrain/obj/Debug/OpenSim.Terrain.BasicTerrain.pdb b/OpenSim.Terrain.BasicTerrain/obj/Debug/OpenSim.Terrain.BasicTerrain.pdb new file mode 100644 index 0000000..ce440c6 Binary files /dev/null and b/OpenSim.Terrain.BasicTerrain/obj/Debug/OpenSim.Terrain.BasicTerrain.pdb differ diff --git a/OpenSim.Terrain.BasicTerrain/obj/OpenSim.Terrain.BasicTerrain.csproj.FileList.txt b/OpenSim.Terrain.BasicTerrain/obj/OpenSim.Terrain.BasicTerrain.csproj.FileList.txt new file mode 100644 index 0000000..4728b51 --- /dev/null +++ b/OpenSim.Terrain.BasicTerrain/obj/OpenSim.Terrain.BasicTerrain.csproj.FileList.txt @@ -0,0 +1,5 @@ +bin\Debug\OpenSim.Terrain.BasicTerrain.dll +bin\Debug\OpenSim.Terrain.BasicTerrain.pdb +obj\Debug\ResolveAssemblyReference.cache +obj\Debug\OpenSim.Terrain.BasicTerrain.dll +obj\Debug\OpenSim.Terrain.BasicTerrain.pdb -- cgit v1.1