From 4b0734c4ad75b93d84c11942531cf2d2e070ba6e Mon Sep 17 00:00:00 2001 From: Adam Frisby Date: Tue, 24 Jul 2007 04:53:21 +0000 Subject: * Terrain Fracture Generator now produces more appropriate results. * Terrain Flatten Brush has been optimised, now affects an appropriate sized section of terrain. * Navier-Stokes handler bounds issue partially fixed. --- .../libTerrainBSD/Channel/Editing/Flatten.cs | 50 ++++++++++++++++++++++ .../libTerrainBSD/Channel/Generators/Fracture.cs | 37 +++++++++++++++- .../Channel/Manipulators/NavierStokes.cs | 4 +- 3 files changed, 87 insertions(+), 4 deletions(-) diff --git a/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Editing/Flatten.cs b/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Editing/Flatten.cs index 57ba729..03b88a4 100644 --- a/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Editing/Flatten.cs +++ b/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Editing/Flatten.cs @@ -44,6 +44,11 @@ namespace libTerrain /// The scale of the terrain mask public void Flatten(double rx, double ry, double size, double amount) { + FlattenFast(rx, ry, size, amount); + } + + private void FlattenSlow(double rx, double ry, double size, double amount) + { // Generate the mask Channel temp = new Channel(w, h); temp.Fill(0); @@ -70,6 +75,51 @@ namespace libTerrain } + private void FlattenFast(double rx, double ry, double size, double amount) + { + int x, y; + double avg = 0; + double div = 0; + + int minX = Math.Max(0, (int)(rx - (size + 1))); + int maxX = Math.Min(w, (int)(rx + (size + 1))); + int minY = Math.Max(0, (int)(ry - (size + 1))); + int maxY = Math.Min(h, (int)(ry + (size + 1))); + + for (x = minX; x < maxX; x++) + { + for (y = minY; y < maxY; y++) + { + double z = size; + z *= z; + z -= ((x - rx) * (x - rx)) + ((y - ry) * (y - ry)); + + if (z < 0) + z = 0; + + avg += z * amount; + div += z; + } + } + + double height = avg / div; + + for (x = minX; x < maxX; x++) + { + for (y = minY; y < maxY; y++) + { + double z = size; + z *= z; + z -= ((x - rx) * (x - rx)) + ((y - ry) * (y - ry)); + + if (z < 0) + z = 0; + + map[x, y] = Tools.linearInterpolate(map[x, y], height, z); + } + } + } + public void Flatten(Channel mask, double amount) { // Generate the mask diff --git a/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Generators/Fracture.cs b/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Generators/Fracture.cs index b585caa..8427eab 100644 --- a/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Generators/Fracture.cs +++ b/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Generators/Fracture.cs @@ -79,6 +79,7 @@ namespace libTerrain throw new Exception("Out of bounds parameter (val)"); } + public void Fracture(int number, double scalemin, double scalemax) { Random rand = new Random(seed); @@ -90,6 +91,8 @@ namespace libTerrain a = RadialEdge256(rand.Next(1023)); // TODO: Broken b = RadialEdge256(rand.Next(1023)); // TODO: Broken double z = rand.NextDouble(); + double u = rand.NextDouble(); + double v = rand.NextDouble(); for (int x = 0; x < w; x++) { @@ -97,9 +100,39 @@ namespace libTerrain { double miny = Tools.linearInterpolate(a[1], b[1], (double)x / (double)w); - if (y > miny) + if (v >= 0.5) + { + if (u >= 0.5) + { + if (y > miny) + { + map[x, y] += Tools.linearInterpolate(scalemin, scalemax, z); + } + } + else + { + if (y < miny) + { + map[x, y] += Tools.linearInterpolate(scalemin, scalemax, z); + } + } + } + else { - map[x, y] += Tools.linearInterpolate(scalemin, scalemax, z); + if (u >= 0.5) + { + if (x > miny) + { + map[x, y] += Tools.linearInterpolate(scalemin, scalemax, z); + } + } + else + { + if (x < miny) + { + map[x, y] += Tools.linearInterpolate(scalemin, scalemax, z); + } + } } } } diff --git a/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Manipulators/NavierStokes.cs b/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Manipulators/NavierStokes.cs index 24ff37c..a035098 100644 --- a/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Manipulators/NavierStokes.cs +++ b/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Manipulators/NavierStokes.cs @@ -225,9 +225,9 @@ namespace libTerrain int i; int j; - for (i = 0; i <= N; i++) + for (i = 1; i <= N; i++) { - for (j = 0; j <= N; j++) + for (j = 1; j <= N; j++) { dens[nsIX(i, j, N)] = doubles[i, j]; } -- cgit v1.1