From 0d69e06779e23f10aba1a6bc38c1074ce3e133fc Mon Sep 17 00:00:00 2001 From: Justin Clarke Casey Date: Mon, 27 Oct 2008 14:27:45 +0000 Subject: * Temporarily revert terrain changes in r6976 and reinstate unit test from r6977. * If a change is going to affect a unit test, then please could we change the unit test at the same time? Otherwise this will never get done * It also seems a bad idea to disable tests which start failing unless there's a very good reason --- .../World/Terrain/PaintBrushes/LowerSphere.cs | 36 +++++--------- .../World/Terrain/PaintBrushes/RaiseSphere.cs | 35 ++++---------- .../Modules/World/Terrain/Tests/TerrainTest.cs | 56 +++++++++++----------- 3 files changed, 48 insertions(+), 79 deletions(-) (limited to 'OpenSim/Region/Environment/Modules/World/Terrain') diff --git a/OpenSim/Region/Environment/Modules/World/Terrain/PaintBrushes/LowerSphere.cs b/OpenSim/Region/Environment/Modules/World/Terrain/PaintBrushes/LowerSphere.cs index 290711f..fe82396 100644 --- a/OpenSim/Region/Environment/Modules/World/Terrain/PaintBrushes/LowerSphere.cs +++ b/OpenSim/Region/Environment/Modules/World/Terrain/PaintBrushes/LowerSphere.cs @@ -36,43 +36,29 @@ 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) { - int s = (int) (Math.Pow(2, strength) + 0.5); - + strength = TerrainUtil.MetersToSphericalStrength(strength); + duration = 0.03; //MCP Should be read from ini file + int 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++) + for (x = 0; x < map.Width; x++) { int y; - for (y = yFrom; y <= yTo; y++) + for (y = 0; y < map.Height; y++) { if (!mask[x,y]) continue; - // 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)); + // Calculate a sphere and add it to the heighmap + double z = strength; + z *= z; + z -= ((x - rx) * (x - rx)) + ((y - ry) * (y - ry)); + if (z > 0.0) map[x, y] -= z * duration; } } - } + #endregion } } diff --git a/OpenSim/Region/Environment/Modules/World/Terrain/PaintBrushes/RaiseSphere.cs b/OpenSim/Region/Environment/Modules/World/Terrain/PaintBrushes/RaiseSphere.cs index b1a52b0..92bac63 100644 --- a/OpenSim/Region/Environment/Modules/World/Terrain/PaintBrushes/RaiseSphere.cs +++ b/OpenSim/Region/Environment/Modules/World/Terrain/PaintBrushes/RaiseSphere.cs @@ -26,51 +26,34 @@ */ using System; -using System.Reflection; -using log4net; using OpenSim.Region.Environment.Interfaces; namespace OpenSim.Region.Environment.Modules.World.Terrain.PaintBrushes { public class RaiseSphere : ITerrainPaintableEffect { - private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); #region ITerrainPaintableEffect Members public void PaintEffect(ITerrainChannel map, bool[,] mask, double rx, double ry, double rz, double strength, double duration) { - int s = (int) (Math.Pow(2, strength) + 0.5); + duration = 0.03; //MCP Should be read from ini file + strength = TerrainUtil.MetersToSphericalStrength(strength); int 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++) + for (x = 0; x < map.Width; x++) { int y; - for (y = yFrom; y <= yTo; y++) + for (y = 0; y < map.Height; y++) { if (!mask[x,y]) continue; - // 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)); + // Calculate a sphere and add it to the heighmap + double z = strength; + z *= z; + z -= ((x - rx) * (x - rx)) + ((y - ry) * (y - ry)); + if (z > 0.0) map[x, y] += z * duration; } diff --git a/OpenSim/Region/Environment/Modules/World/Terrain/Tests/TerrainTest.cs b/OpenSim/Region/Environment/Modules/World/Terrain/Tests/TerrainTest.cs index 4d9cf61..5b4bc8c 100644 --- a/OpenSim/Region/Environment/Modules/World/Terrain/Tests/TerrainTest.cs +++ b/OpenSim/Region/Environment/Modules/World/Terrain/Tests/TerrainTest.cs @@ -34,34 +34,34 @@ namespace OpenSim.Region.Environment.Modules.World.Terrain.Tests [TestFixture] public class TerrainTest { -// [Test] -// public void BrushTest() -// { -// TerrainChannel map = new TerrainChannel(256, 256); -// bool[,] allowMask = new bool[map.Width,map.Height]; -// int x; -// int y; -// for (x=0; x 0.0, "Raise brush not raising values."); -// Assert.That(map[0, 128] > 0.0, "Raise brush lowering edge values."); -// -// map = new TerrainChannel(256, 256); -// effect = new LowerSphere(); -// -// effect.PaintEffect(map, allowMask, 128.0, 128.0, -1, 100, 0.1); -// Assert.That(map[128, 128] < 0.0, "Lower not lowering values."); -// Assert.That(map[0, 128] < 0.0, "Lower brush affecting edge values."); -// } + [Test] + public void BrushTest() + { + TerrainChannel map = new TerrainChannel(256, 256); + bool[,] allowMask = new bool[map.Width,map.Height]; + int x; + int y; + for (x=0; x 0.0, "Raise brush not raising values."); + Assert.That(map[0, 128] > 0.0, "Raise brush lowering edge values."); + + map = new TerrainChannel(256, 256); + effect = new LowerSphere(); + + effect.PaintEffect(map, allowMask, 128.0, 128.0, -1, 100, 0.1); + Assert.That(map[128, 128] < 0.0, "Lower not lowering values."); + Assert.That(map[0, 128] < 0.0, "Lower brush affecting edge values."); + } [Test] public void TerrainChannelTest() -- cgit v1.1