diff --git a/OpenSim/Framework/TerrainData.cs b/OpenSim/Framework/TerrainData.cs index f937b706aa..d021362fcf 100644 --- a/OpenSim/Framework/TerrainData.cs +++ b/OpenSim/Framework/TerrainData.cs @@ -121,6 +121,70 @@ namespace OpenSim.Framework set { this[x, y] = value; } } + public float GetHeight(float x, float y) + { + // integer indexs + int ix; + int iy; + // interpolators offset + float dx; + float dy; + + // make position fit into array + if (x <= 0) + { + ix = 0; + dx = 0; + } + else if (x < SizeX) + { + ix = (int)x; + dx = x - ix; + } + else // out world use external height + { + ix = SizeX - 1; + dx = 0; + } + if (y <= 0) + { + iy = 0; + dy = 0; + } + else if (y < SizeY) + { + iy = (int)y; + dy = y - iy; + } + else + { + iy = SizeY - 1; + dy = 0; + } + + float h0 = m_heightmap[ix, iy]; // 0,0 vertice + float h1; + float h2; + + if (dy > dx) + { + iy++; + h2 = m_heightmap[ix, iy]; // 0,1 vertice + h1 = (h2 - h0) * dy; // 0,1 vertice minus 0,0 + ix++; + h2 = (m_heightmap[ix, iy] - h2) * dx; // 1,1 vertice minus 0,1 + } + else + { + ix++; + h2 = m_heightmap[ix, iy]; // vertice 1,0 + h1 = (h2 - h0) * dx; // 1,0 vertice minus 0,0 + iy++; + h2 = (m_heightmap[ix, iy] - h2) * dy; // 1,1 vertice minus 1,0 + } + return h0 + h1 + h2; + } + public TerrainTaintsArray GetTaints() { return m_taints; diff --git a/OpenSim/Region/ClientStack/Linden/Caps/EstateAccess.cs b/OpenSim/Region/ClientStack/Linden/Caps/EstateAccess.cs index fe9fab4e5e..caf7fb7e8e 100644 --- a/OpenSim/Region/ClientStack/Linden/Caps/EstateAccess.cs +++ b/OpenSim/Region/ClientStack/Linden/Caps/EstateAccess.cs @@ -49,8 +49,7 @@ namespace OpenSim.Region.ClientStack.Linden [Extension(Path = "/OpenSim/RegionModules", NodeName = "RegionModule", Id = "EstateAcessCapModule")] public class EstateAccessCapModule : INonSharedRegionModule { -// private static readonly ILog m_log = -// LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); + // private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); private Scene m_scene; private bool m_Enabled = false; diff --git a/OpenSim/Region/Framework/Interfaces/ITerrainChannel.cs b/OpenSim/Region/Framework/Interfaces/ITerrainChannel.cs index 9e1fa5bad0..d5073589f2 100644 --- a/OpenSim/Region/Framework/Interfaces/ITerrainChannel.cs +++ b/OpenSim/Region/Framework/Interfaces/ITerrainChannel.cs @@ -38,6 +38,7 @@ namespace OpenSim.Region.Framework.Interfaces float this[int x, int y] { get; set; } + float GetHeight(float x, float y); float GetHeightAtXYZ(float x, float y, float z); // Return the packaged terrain data for passing into lower levels of communication diff --git a/OpenSim/Region/Framework/Scenes/Scene.cs b/OpenSim/Region/Framework/Scenes/Scene.cs index e234358042..e6c2cb4486 100755 --- a/OpenSim/Region/Framework/Scenes/Scene.cs +++ b/OpenSim/Region/Framework/Scenes/Scene.cs @@ -5563,65 +5563,7 @@ Environment.Exit(1); // does a linear approximation of the height at this intermediate point. public float GetGroundHeight(float x, float y) { - int ix; - int iy; - float dx; - float dy; - - // make position fit into array - if (x < 0) - { - ix = 0; - dx = 0; - } - else if (x < Heightmap.Width - 1) - { - ix = (int)x; - dx = x - ix; - } - else // out world use external height - { - ix = Heightmap.Width - 2; - dx = 0; - } - if (y < 0) - { - iy = 0; - dy = 0; - } - else if (y < Heightmap.Height - 1) - { - iy = (int)y; - dy = y - iy; - } - else - { - iy = Heightmap.Height - 2; - dy = 0; - } - - float h1; - float h2; - float h0 = Heightmap[ix, iy]; // 0,0 vertice - - if (dy > dx) - { - ++iy; - h2 = Heightmap[ix, iy]; // 0,1 vertice - h1 = (h2 - h0) * dy; // 0,1 vertice minus 0,0 - ++ix; - h2 = (Heightmap[ix, iy] - h2) * dx; // 1,1 vertice minus 0,1 - } - else - { - ++ix; - h2 = Heightmap[ix, iy]; // vertice 1,0 - h1 = (h2 - h0) * dx; // 1,0 vertice minus 0,0 - ++iy; - h2 = (Heightmap[ix, iy] - h2) * dy; // 1,1 vertice minus 1,0 - } - - return h0 + h1 + h2; + return Heightmap.GetHeight(x, y); } private void CheckHeartbeat() diff --git a/OpenSim/Region/Framework/Scenes/TerrainChannel.cs b/OpenSim/Region/Framework/Scenes/TerrainChannel.cs index 67d3806ed1..088874af64 100644 --- a/OpenSim/Region/Framework/Scenes/TerrainChannel.cs +++ b/OpenSim/Region/Framework/Scenes/TerrainChannel.cs @@ -159,12 +159,14 @@ namespace OpenSim.Region.Framework.Scenes } } - // ITerrainChannel.GetHieghtAtXYZ(x, y, z) + public float GetHeight(float x, float y) + { + return m_terrainData.GetHeight(x, y); + } + public float GetHeightAtXYZ(float x, float y, float z) { - if (x < 0 || x >= Width || y < 0 || y >= Height) - return 0; - return m_terrainData[(int)x, (int)y]; + return m_terrainData.GetHeight(x, y); } // ITerrainChannel.Tainted() diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs index 46c2d5eee9..14fb2c8b2d 100644 --- a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs +++ b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs @@ -1496,29 +1496,9 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api public LSL_Float llGround(LSL_Vector offset) { - Vector3 pos = m_host.GetWorldPosition() + (Vector3)offset; - - //Get the slope normal. This gives us the equation of the plane tangent to the slope. - LSL_Vector vsn = llGroundNormal(offset); - - // Clamp to valid position - if (pos.X < 0) - pos.X = 0; - else if (pos.X >= World.Heightmap.Width) - pos.X = World.Heightmap.Width - 1; - if (pos.Y < 0) - pos.Y = 0; - else if (pos.Y >= World.Heightmap.Height) - pos.Y = World.Heightmap.Height - 1; - - //Get the height for the integer coordinates from the Heightmap - float baseheight = (float)World.Heightmap[(int)pos.X, (int)pos.Y]; - - //Calculate the difference between the actual coordinates and the integer coordinates - float xdiff = pos.X - (float)((int)pos.X); - float ydiff = pos.Y - (float)((int)pos.Y); - - //Use the equation of the tangent plane to adjust the height to account for slope + Vector3 pos = m_host.GetWorldPosition(); + pos.X += (float)offset.x; + pos.Y += (float)offset.y; return (((vsn.x * xdiff) + (vsn.y * ydiff)) / (-1 * vsn.z)) + baseheight; }