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 +++++++++++++++++++++++++++++++++++
1 file changed, 72 insertions(+)
create mode 100644 OpenSim.Terrain.BasicTerrain/Hills.cs
(limited to 'OpenSim.Terrain.BasicTerrain/Hills.cs')
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);
+ }
+ }
+ }
+ }
+ }
+ }
+}
--
cgit v1.1