From 6ec9c2d7068bd7b9da0cb32b6f0847d8fc6b0a53 Mon Sep 17 00:00:00 2001 From: Justin Clarke Casey Date: Mon, 27 Oct 2008 17:06:47 +0000 Subject: * Apply http://opensimulator.org/mantis/view.php?id=2468 * This time there are accompanying changes to the unit test to adapt it to the changes * Thanks tglion --- .../World/Terrain/PaintBrushes/LowerSphere.cs | 44 ++++++++++++++++------ 1 file changed, 32 insertions(+), 12 deletions(-) (limited to 'OpenSim/Region/Environment/Modules/World/Terrain/PaintBrushes/LowerSphere.cs') diff --git a/OpenSim/Region/Environment/Modules/World/Terrain/PaintBrushes/LowerSphere.cs b/OpenSim/Region/Environment/Modules/World/Terrain/PaintBrushes/LowerSphere.cs index fe82396..745d3da 100644 --- a/OpenSim/Region/Environment/Modules/World/Terrain/PaintBrushes/LowerSphere.cs +++ b/OpenSim/Region/Environment/Modules/World/Terrain/PaintBrushes/LowerSphere.cs @@ -36,29 +36,49 @@ namespace OpenSim.Region.Environment.Modules.World.Terrain.PaintBrushes public void PaintEffect(ITerrainChannel map, bool[,] mask, double rx, double ry, double rz, double strength, double duration) { - strength = TerrainUtil.MetersToSphericalStrength(strength); - duration = 0.03; //MCP Should be read from ini file - + int s = (int) (Math.Pow(2, strength) + 0.5); + int x; - for (x = 0; x < map.Width; x++) + int xFrom = (int)(rx-s+0.5); + int xTo = (int)(rx+s+0.5) + 1; + int yFrom = (int)(ry-s+0.5); + int yTo = (int)(ry+s+0.5) + 1; + + if (xFrom < 0) + xFrom = 0; + + if (yFrom < 0) + yFrom = 0; + + if (xTo > map.Width) + xTo = map.Width; + + if (yTo > map.Width) + yTo = map.Width; + + for (x = xFrom; x < xTo; x++) { int y; - for (y = 0; y < map.Height; y++) + for (y = yFrom; y < yTo; y++) { if (!mask[x,y]) continue; - // Calculate a sphere and add it to the heighmap - double z = strength; - z *= z; - z -= ((x - rx) * (x - rx)) + ((y - ry) * (y - ry)); - + // Calculate a cos-sphere and add it to the heighmap + double r = Math.Sqrt((x-rx) * (x-rx) + ((y-ry) * (y-ry))); + double z = Math.Cos(r * Math.PI / (s * 2)); if (z > 0.0) - map[x, y] -= z * duration; + { + double newz = map[x, y] - z * duration; + if (newz < 0.0) + map[x, y] = 0.0; + else + map[x, y] = newz; + } } } - } + } #endregion } } -- cgit v1.1