* 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 reason0.6.0-stable
parent
b2d6b0a3d4
commit
0d69e06779
|
@ -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
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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<map.Width; x++)
|
||||
// {
|
||||
// for (y=0; y<map.Height; y++)
|
||||
// {
|
||||
// allowMask[x,y] = true;
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// ITerrainPaintableEffect effect = new RaiseSphere();
|
||||
//
|
||||
// effect.PaintEffect(map, allowMask, 128.0, 128.0, 23.0, 100, 0.1);
|
||||
// Assert.That(map[128, 128] > 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<map.Width; x++)
|
||||
{
|
||||
for (y=0; y<map.Height; y++)
|
||||
{
|
||||
allowMask[x,y] = true;
|
||||
}
|
||||
}
|
||||
|
||||
ITerrainPaintableEffect effect = new RaiseSphere();
|
||||
|
||||
effect.PaintEffect(map, allowMask, 128.0, 128.0, 23.0, 100, 0.1);
|
||||
Assert.That(map[128, 128] > 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()
|
||||
|
|
Loading…
Reference in New Issue