From c009e2e0956ab6c43aebe0ba9275a0dbcc25e9ce Mon Sep 17 00:00:00 2001 From: Sean Dague Date: Fri, 29 Feb 2008 20:36:14 +0000 Subject: From: Mike Pitman Below is a patch for the smooth tool. I factored out the essential computations and placed it in a channel method to work similar to raise and lower. It now performs about the same rate as raise and lower. --- .../libTerrainBSD/Channel/Editing/Raise.cs | 62 ++++++++++++++++++++++ 1 file changed, 62 insertions(+) (limited to 'OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD') diff --git a/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Editing/Raise.cs b/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Editing/Raise.cs index 523a065..20bca51 100644 --- a/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Editing/Raise.cs +++ b/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Editing/Raise.cs @@ -127,5 +127,67 @@ namespace libTerrain } } } + + public double SphericalFactor(double x, double y, double rx, double ry, double size) + { + double z = size * size - ((x - rx) * (x - rx) + (y - ry) * (y - ry)); + return z; + } + + public void SmoothRegion(double rx, double ry, double size, double amount) + { + int x, y; + double[,] tweak = new double[w, h]; + + double n, l; + double area = size; + double step = size / 4.0; + + // compute delta map + for (x = 0; x < w; x++) + { + for (y = 0; y < h; y++) + { + double z = SphericalFactor(x, y, rx, ry, size); + + if (z > 0) // add in non-zero amount + { + 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); + } + } + tweak[x, y] = average / avgsteps; + //if (x == rx && y == ry) + // Console.WriteLine("tweak[ " + x + " , " + y + " ] = " + tweak[x, y]); + } + } + } + // blend in map + for (x = 0; x < w; x++) + { + for (y = 0; y < h; y++) + { + double z = SphericalFactor(x, y, rx, ry, size); + + if (z > 0) // add in non-zero amount + { + double da = z * amount; + double a = (map[x, y] - tweak[x, y]) * da; + double newz = map[x, y] - a; + //if (rx == x || ry == y) + // Console.WriteLine("map[ " + x + " , " + y + " ] = " + map[x, y] + " tweak, a , da, z, size, amount = " + tweak[x, y] + " " + a + " " + da + " " + z + " " + size + " " + amount); + if (newz > 0.0) + Set(x, y, newz); + } + } + } + } } } \ No newline at end of file -- cgit v1.1