aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/Environment/Modules/World/Terrain
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim/Region/Environment/Modules/World/Terrain')
-rw-r--r--OpenSim/Region/Environment/Modules/World/Terrain/PaintBrushes/LowerSphere.cs44
-rw-r--r--OpenSim/Region/Environment/Modules/World/Terrain/PaintBrushes/RaiseSphere.cs32
-rw-r--r--OpenSim/Region/Environment/Modules/World/Terrain/Tests/TerrainTest.cs40
3 files changed, 85 insertions, 31 deletions
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
36 36
37 public void PaintEffect(ITerrainChannel map, bool[,] mask, double rx, double ry, double rz, double strength, double duration) 37 public void PaintEffect(ITerrainChannel map, bool[,] mask, double rx, double ry, double rz, double strength, double duration)
38 { 38 {
39 strength = TerrainUtil.MetersToSphericalStrength(strength); 39 int s = (int) (Math.Pow(2, strength) + 0.5);
40 duration = 0.03; //MCP Should be read from ini file 40
41
42 int x; 41 int x;
43 for (x = 0; x < map.Width; x++) 42 int xFrom = (int)(rx-s+0.5);
43 int xTo = (int)(rx+s+0.5) + 1;
44 int yFrom = (int)(ry-s+0.5);
45 int yTo = (int)(ry+s+0.5) + 1;
46
47 if (xFrom < 0)
48 xFrom = 0;
49
50 if (yFrom < 0)
51 yFrom = 0;
52
53 if (xTo > map.Width)
54 xTo = map.Width;
55
56 if (yTo > map.Width)
57 yTo = map.Width;
58
59 for (x = xFrom; x < xTo; x++)
44 { 60 {
45 int y; 61 int y;
46 for (y = 0; y < map.Height; y++) 62 for (y = yFrom; y < yTo; y++)
47 { 63 {
48 if (!mask[x,y]) 64 if (!mask[x,y])
49 continue; 65 continue;
50 66
51 // Calculate a sphere and add it to the heighmap 67 // Calculate a cos-sphere and add it to the heighmap
52 double z = strength; 68 double r = Math.Sqrt((x-rx) * (x-rx) + ((y-ry) * (y-ry)));
53 z *= z; 69 double z = Math.Cos(r * Math.PI / (s * 2));
54 z -= ((x - rx) * (x - rx)) + ((y - ry) * (y - ry));
55
56 if (z > 0.0) 70 if (z > 0.0)
57 map[x, y] -= z * duration; 71 {
72 double newz = map[x, y] - z * duration;
73 if (newz < 0.0)
74 map[x, y] = 0.0;
75 else
76 map[x, y] = newz;
77 }
58 } 78 }
59 } 79 }
60 }
61 80
81 }
62 #endregion 82 #endregion
63 } 83 }
64} 84}
diff --git a/OpenSim/Region/Environment/Modules/World/Terrain/PaintBrushes/RaiseSphere.cs b/OpenSim/Region/Environment/Modules/World/Terrain/PaintBrushes/RaiseSphere.cs
index 92bac63..56813ab 100644
--- a/OpenSim/Region/Environment/Modules/World/Terrain/PaintBrushes/RaiseSphere.cs
+++ b/OpenSim/Region/Environment/Modules/World/Terrain/PaintBrushes/RaiseSphere.cs
@@ -37,23 +37,37 @@ namespace OpenSim.Region.Environment.Modules.World.Terrain.PaintBrushes
37 37
38 public void PaintEffect(ITerrainChannel map, bool[,] mask, double rx, double ry, double rz, double strength, double duration) 38 public void PaintEffect(ITerrainChannel map, bool[,] mask, double rx, double ry, double rz, double strength, double duration)
39 { 39 {
40 duration = 0.03; //MCP Should be read from ini file 40 int s = (int) (Math.Pow(2, strength) + 0.5);
41 strength = TerrainUtil.MetersToSphericalStrength(strength);
42 41
43 int x; 42 int x;
44 for (x = 0; x < map.Width; x++) 43 int xFrom = (int)(rx-s+0.5);
44 int xTo = (int)(rx+s+0.5) + 1;
45 int yFrom = (int)(ry-s+0.5);
46 int yTo = (int)(ry+s+0.5) + 1;
47
48 if (xFrom < 0)
49 xFrom = 0;
50
51 if (yFrom < 0)
52 yFrom = 0;
53
54 if (xTo > map.Width)
55 xTo = map.Width;
56
57 if (yTo > map.Width)
58 yTo = map.Width;
59
60 for (x = xFrom; x < xTo; x++)
45 { 61 {
46 int y; 62 int y;
47 for (y = 0; y < map.Height; y++) 63 for (y = yFrom; y < yTo; y++)
48 { 64 {
49 if (!mask[x,y]) 65 if (!mask[x,y])
50 continue; 66 continue;
51 67
52 // Calculate a sphere and add it to the heighmap 68 // Calculate a cos-sphere and add it to the heighmap
53 double z = strength; 69 double r = Math.Sqrt((x-rx) * (x-rx) + ((y-ry) * (y-ry)));
54 z *= z; 70 double z = Math.Cos(r * Math.PI / (s * 2));
55 z -= ((x - rx) * (x - rx)) + ((y - ry) * (y - ry));
56
57 if (z > 0.0) 71 if (z > 0.0)
58 map[x, y] += z * duration; 72 map[x, y] += z * duration;
59 } 73 }
diff --git a/OpenSim/Region/Environment/Modules/World/Terrain/Tests/TerrainTest.cs b/OpenSim/Region/Environment/Modules/World/Terrain/Tests/TerrainTest.cs
index 5b4bc8c..3511988 100644
--- a/OpenSim/Region/Environment/Modules/World/Terrain/Tests/TerrainTest.cs
+++ b/OpenSim/Region/Environment/Modules/World/Terrain/Tests/TerrainTest.cs
@@ -37,30 +37,50 @@ namespace OpenSim.Region.Environment.Modules.World.Terrain.Tests
37 [Test] 37 [Test]
38 public void BrushTest() 38 public void BrushTest()
39 { 39 {
40 TerrainChannel map = new TerrainChannel(256, 256); 40 bool[,] allowMask = new bool[256, 256];
41 bool[,] allowMask = new bool[map.Width,map.Height];
42 int x; 41 int x;
43 int y; 42 int y;
44 for (x=0; x<map.Width; x++) 43 for (x=0; x<128; x++)
45 { 44 {
46 for (y=0; y<map.Height; y++) 45 for (y=0; y<256; y++)
47 { 46 {
48 allowMask[x,y] = true; 47 allowMask[x,y] = true;
49 } 48 }
50 } 49 }
51 50
51 //
52 // Test RaiseSphere
53 //
54 TerrainChannel map = new TerrainChannel(256, 256);
52 ITerrainPaintableEffect effect = new RaiseSphere(); 55 ITerrainPaintableEffect effect = new RaiseSphere();
53 56
54 effect.PaintEffect(map, allowMask, 128.0, 128.0, 23.0, 100, 0.1); 57 effect.PaintEffect(map, allowMask, 128.0, 128.0, -1.0, 2, 0.1);
55 Assert.That(map[128, 128] > 0.0, "Raise brush not raising values."); 58 Assert.That(map[127, 128] > 0.0, "Raise brush should raising value at this point (127,128).");
56 Assert.That(map[0, 128] > 0.0, "Raise brush lowering edge values."); 59 Assert.That(map[124, 128] > 0.0, "Raise brush should raising value at this point (124,128).");
60 Assert.That(map[123, 128] == 0.0, "Raise brush should not change value at this point (123,128).");
61 Assert.That(map[128, 128] == 0.0, "Raise brush should not change value at this point (128,128).");
62 Assert.That(map[0, 128] == 0.0, "Raise brush should not change value at this point (0,128).");
57 63
64 //
65 // Test LowerSphere
66 //
58 map = new TerrainChannel(256, 256); 67 map = new TerrainChannel(256, 256);
68 for (x=0; x<map.Width; x++)
69 {
70 for (y=0; y<map.Height; y++)
71 {
72 map[x,y] = 1.0;
73 }
74 }
59 effect = new LowerSphere(); 75 effect = new LowerSphere();
60 76
61 effect.PaintEffect(map, allowMask, 128.0, 128.0, -1, 100, 0.1); 77 effect.PaintEffect(map, allowMask, 128.0, 128.0, -1.0, 2, 6.0);
62 Assert.That(map[128, 128] < 0.0, "Lower not lowering values."); 78 Assert.That(map[127, 128] >= 0.0, "Lower should not lowering value below 0.0 at this point (127,128).");
63 Assert.That(map[0, 128] < 0.0, "Lower brush affecting edge values."); 79 Assert.That(map[127, 128] == 0.0, "Lower brush should lowering value to 0.0 at this point (127,128).");
80 Assert.That(map[124, 128] < 1.0, "Lower brush should lowering value at this point (124,128).");
81 Assert.That(map[123, 128] == 1.0, "Lower brush should not change value at this point (123,128).");
82 Assert.That(map[128, 128] == 1.0, "Lower brush should not change value at this point (128,128).");
83 Assert.That(map[0, 128] == 1.0, "Lower brush should not change value at this point (0,128).");
64 } 84 }
65 85
66 [Test] 86 [Test]