* This time there are accompanying changes to the unit test to adapt it to the changes * Thanks tglion0.6.0-stable
parent
0d69e06779
commit
6ec9c2d706
|
@ -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)
|
public void PaintEffect(ITerrainChannel map, bool[,] mask, double rx, double ry, double rz, double strength, double duration)
|
||||||
{
|
{
|
||||||
strength = TerrainUtil.MetersToSphericalStrength(strength);
|
int s = (int) (Math.Pow(2, strength) + 0.5);
|
||||||
duration = 0.03; //MCP Should be read from ini file
|
|
||||||
|
|
||||||
int x;
|
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;
|
int y;
|
||||||
for (y = 0; y < map.Height; y++)
|
for (y = yFrom; y < yTo; y++)
|
||||||
{
|
{
|
||||||
if (!mask[x,y])
|
if (!mask[x,y])
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
// Calculate a sphere and add it to the heighmap
|
// Calculate a cos-sphere and add it to the heighmap
|
||||||
double z = strength;
|
double r = Math.Sqrt((x-rx) * (x-rx) + ((y-ry) * (y-ry)));
|
||||||
z *= z;
|
double z = Math.Cos(r * Math.PI / (s * 2));
|
||||||
z -= ((x - rx) * (x - rx)) + ((y - ry) * (y - ry));
|
|
||||||
|
|
||||||
if (z > 0.0)
|
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
|
#endregion
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -37,23 +37,37 @@ 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)
|
public void PaintEffect(ITerrainChannel map, bool[,] mask, double rx, double ry, double rz, double strength, double duration)
|
||||||
{
|
{
|
||||||
duration = 0.03; //MCP Should be read from ini file
|
int s = (int) (Math.Pow(2, strength) + 0.5);
|
||||||
strength = TerrainUtil.MetersToSphericalStrength(strength);
|
|
||||||
|
|
||||||
int x;
|
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;
|
int y;
|
||||||
for (y = 0; y < map.Height; y++)
|
for (y = yFrom; y < yTo; y++)
|
||||||
{
|
{
|
||||||
if (!mask[x,y])
|
if (!mask[x,y])
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
// Calculate a sphere and add it to the heighmap
|
// Calculate a cos-sphere and add it to the heighmap
|
||||||
double z = strength;
|
double r = Math.Sqrt((x-rx) * (x-rx) + ((y-ry) * (y-ry)));
|
||||||
z *= z;
|
double z = Math.Cos(r * Math.PI / (s * 2));
|
||||||
z -= ((x - rx) * (x - rx)) + ((y - ry) * (y - ry));
|
|
||||||
|
|
||||||
if (z > 0.0)
|
if (z > 0.0)
|
||||||
map[x, y] += z * duration;
|
map[x, y] += z * duration;
|
||||||
}
|
}
|
||||||
|
|
|
@ -37,30 +37,50 @@ namespace OpenSim.Region.Environment.Modules.World.Terrain.Tests
|
||||||
[Test]
|
[Test]
|
||||||
public void BrushTest()
|
public void BrushTest()
|
||||||
{
|
{
|
||||||
TerrainChannel map = new TerrainChannel(256, 256);
|
bool[,] allowMask = new bool[256, 256];
|
||||||
bool[,] allowMask = new bool[map.Width,map.Height];
|
|
||||||
int x;
|
int x;
|
||||||
int y;
|
int y;
|
||||||
for (x=0; x<map.Width; x++)
|
for (x=0; x<128; x++)
|
||||||
{
|
{
|
||||||
for (y=0; y<map.Height; y++)
|
for (y=0; y<256; y++)
|
||||||
{
|
{
|
||||||
allowMask[x,y] = true;
|
allowMask[x,y] = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// Test RaiseSphere
|
||||||
|
//
|
||||||
|
TerrainChannel map = new TerrainChannel(256, 256);
|
||||||
ITerrainPaintableEffect effect = new RaiseSphere();
|
ITerrainPaintableEffect effect = new RaiseSphere();
|
||||||
|
|
||||||
effect.PaintEffect(map, allowMask, 128.0, 128.0, 23.0, 100, 0.1);
|
effect.PaintEffect(map, allowMask, 128.0, 128.0, -1.0, 2, 0.1);
|
||||||
Assert.That(map[128, 128] > 0.0, "Raise brush not raising values.");
|
Assert.That(map[127, 128] > 0.0, "Raise brush should raising value at this point (127,128).");
|
||||||
Assert.That(map[0, 128] > 0.0, "Raise brush lowering edge values.");
|
Assert.That(map[124, 128] > 0.0, "Raise brush should raising value at this point (124,128).");
|
||||||
|
Assert.That(map[123, 128] == 0.0, "Raise brush should not change value at this point (123,128).");
|
||||||
|
Assert.That(map[128, 128] == 0.0, "Raise brush should not change value at this point (128,128).");
|
||||||
|
Assert.That(map[0, 128] == 0.0, "Raise brush should not change value at this point (0,128).");
|
||||||
|
|
||||||
|
//
|
||||||
|
// Test LowerSphere
|
||||||
|
//
|
||||||
map = new TerrainChannel(256, 256);
|
map = new TerrainChannel(256, 256);
|
||||||
|
for (x=0; x<map.Width; x++)
|
||||||
|
{
|
||||||
|
for (y=0; y<map.Height; y++)
|
||||||
|
{
|
||||||
|
map[x,y] = 1.0;
|
||||||
|
}
|
||||||
|
}
|
||||||
effect = new LowerSphere();
|
effect = new LowerSphere();
|
||||||
|
|
||||||
effect.PaintEffect(map, allowMask, 128.0, 128.0, -1, 100, 0.1);
|
effect.PaintEffect(map, allowMask, 128.0, 128.0, -1.0, 2, 6.0);
|
||||||
Assert.That(map[128, 128] < 0.0, "Lower not lowering values.");
|
Assert.That(map[127, 128] >= 0.0, "Lower should not lowering value below 0.0 at this point (127,128).");
|
||||||
Assert.That(map[0, 128] < 0.0, "Lower brush affecting edge values.");
|
Assert.That(map[127, 128] == 0.0, "Lower brush should lowering value to 0.0 at this point (127,128).");
|
||||||
|
Assert.That(map[124, 128] < 1.0, "Lower brush should lowering value at this point (124,128).");
|
||||||
|
Assert.That(map[123, 128] == 1.0, "Lower brush should not change value at this point (123,128).");
|
||||||
|
Assert.That(map[128, 128] == 1.0, "Lower brush should not change value at this point (128,128).");
|
||||||
|
Assert.That(map[0, 128] == 1.0, "Lower brush should not change value at this point (0,128).");
|
||||||
}
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
|
|
Loading…
Reference in New Issue