diff -Nur opensim-/OpenSim/Region/Physics/Manager/PhysicsScene.cs opensim/OpenSim/Region/Physics/Manager/PhysicsScene.cs --- opensim-/OpenSim/Region/Physics/Manager/PhysicsScene.cs 2010-10-19 13:27:14.000000000 +0900 +++ opensim/OpenSim/Region/Physics/Manager/PhysicsScene.cs 2010-10-19 13:29:58.000000000 +0900 @@ -172,16 +172,36 @@ return false; } + + // by Fumi.Iseki for Mega Region + private Vector2 worldExtents = new Vector2((int)Constants.RegionSize, (int)Constants.RegionSize); + + public virtual Vector2 GetWorldExtents() + { + return worldExtents; + } + + public virtual float GetWorldExtentsHeight(float x, float y) + { + return 0.0f; + } + + public virtual void SetWorldExtentsHeight(float x, float y, float heigt) + { + } + public virtual void Combine(PhysicsScene pScene, Vector3 offset, Vector3 extents) { + worldExtents = new Vector2(0.0f, 0.0f); return; } public virtual void UnCombine(PhysicsScene pScene) { - + worldExtents = new Vector2((int)Constants.RegionSize, (int)Constants.RegionSize); } + /// /// Queue a raycast against the physics scene. /// The provided callback method will be called when the raycast is complete diff -Nur opensim-/OpenSim/Region/Physics/OdePlugin/OdePlugin.cs opensim/OpenSim/Region/Physics/OdePlugin/OdePlugin.cs --- opensim-/OpenSim/Region/Physics/OdePlugin/OdePlugin.cs 2010-10-19 13:27:14.000000000 +0900 +++ opensim/OpenSim/Region/Physics/OdePlugin/OdePlugin.cs 2010-10-19 13:29:58.000000000 +0900 @@ -322,6 +322,13 @@ private ODERayCastRequestManager m_rayCastManager; + + // Fumi.Iseki for Mega Region + private int combineXsize = 1; + private int combineYsize = 1; + private Vector2 worldExtents = new Vector2((int)Constants.RegionSize, (int)Constants.RegionSize); + + /// /// Initiailizes the scene /// Sets many properties that ODE requires to be stable @@ -1588,14 +1595,66 @@ #endregion + + // Fumi.Iseki for MegaRegion + public override Vector2 GetWorldExtents() + { + return WorldExtents; + } + + + public override float GetWorldExtentsHeight(float x, float y) + { + return GetTerrainHeightAtXY(x, y); + } + + + public override void SetWorldExtentsHeight(float x, float y, float height) + { + int offsetX = ((int)(x / (int)Constants.RegionSize)) * (int)Constants.RegionSize; + int offsetY = ((int)(y / (int)Constants.RegionSize)) * (int)Constants.RegionSize; + + IntPtr heightFieldGeom = IntPtr.Zero; + + if (RegionTerrain.TryGetValue(new Vector3(offsetX,offsetY,0), out heightFieldGeom)) + { + if (heightFieldGeom != IntPtr.Zero) + { + if (TerrainHeightFieldHeights.ContainsKey(heightFieldGeom)) + { + int index; + + if ((int)x > WorldExtents.X || (int)y > WorldExtents.Y || (int)x < 0 || (int)y < 0) return; + + x = x - offsetX; + y = y - offsetY; + index = (int)((int)x * ((int)Constants.RegionSize + 2) + (int)y); + + if (index < TerrainHeightFieldHeights[heightFieldGeom].Length) + { + TerrainHeightFieldHeights[heightFieldGeom][index] = height; + } + } + } + } + + return; + } + + public override void Combine(PhysicsScene pScene, Vector3 offset, Vector3 extents) { m_worldOffset = offset; - WorldExtents = new Vector2(extents.X, extents.Y); m_parentScene = pScene; - + + if (worldExtents.X!=extents.X && worldExtents.Y==extents.Y) combineXsize++; + if (worldExtents.X==extents.X && worldExtents.Y!=extents.Y) combineYsize++; + + worldExtents = new Vector2(extents.X, extents.Y); + WorldExtents = new Vector2(Constants.RegionSize*combineXsize, Constants.RegionSize*combineYsize); } + // Recovered for use by fly height. Kitto Flora public float GetTerrainHeightAtXY(float x, float y) { diff -Nur opensim-/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs opensim/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs --- opensim-/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs 2010-10-19 13:27:14.000000000 +0900 +++ opensim/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs 2010-10-19 13:29:58.000000000 +0900 @@ -1111,19 +1111,34 @@ //Get the slope normal. This gives us the equation of the plane tangent to the slope. LSL_Vector vsn = llGroundNormal(offset); + float baseheight = 0.0f; - // 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; + // for Mega Region by Fumi.Iseki + Vector2 worldExtents = World.PhysicsScene.GetWorldExtents(); + if (worldExtents.X>World.Heightmap.Width && worldExtents.Y>World.Heightmap.Height) + { + if (pos.X < 0) pos.X = 0; + else if (pos.X >= worldExtents.X) pos.X = worldExtents.X - 1; + if (pos.Y < 0) pos.Y = 0; + else if (pos.Y >= worldExtents.Y) pos.Y = worldExtents.Y - 1; + + baseheight = World.PhysicsScene.GetWorldExtentsHeight(pos.X, pos.Y); + } + else + { + // 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]; + //Get the height for the integer coordinates from the Heightmap + 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); @@ -5742,33 +5757,64 @@ Vector3 pos = m_host.GetWorldPosition() + new Vector3((float)offset.x, (float)offset.y, (float)offset.z); - // 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; - - //Find two points in addition to the position to define a plane - Vector3 p0 = new Vector3(pos.X, pos.Y, - (float)World.Heightmap[(int)pos.X, (int)pos.Y]); - Vector3 p1 = new Vector3(); - Vector3 p2 = new Vector3(); - if ((pos.X + 1.0f) >= World.Heightmap.Width) - p1 = new Vector3(pos.X + 1.0f, pos.Y, - (float)World.Heightmap[(int)pos.X, (int)pos.Y]); - else - p1 = new Vector3(pos.X + 1.0f, pos.Y, - (float)World.Heightmap[(int)(pos.X + 1.0f), (int)pos.Y]); - if ((pos.Y + 1.0f) >= World.Heightmap.Height) - p2 = new Vector3(pos.X, pos.Y + 1.0f, - (float)World.Heightmap[(int)pos.X, (int)pos.Y]); + + Vector3 p0, p1, p2; + + // for Mega Region by Fumi.Iseki + Vector2 worldExtents = World.PhysicsScene.GetWorldExtents(); + if (worldExtents.X>World.Heightmap.Width && worldExtents.Y>World.Heightmap.Height) + { + if (pos.X < 0) pos.X = 0; + else if (pos.X >= worldExtents.X) pos.X = worldExtents.X - 1; + if (pos.Y < 0) pos.Y = 0; + else if (pos.Y >= worldExtents.Y) pos.Y = worldExtents.Y - 1; + + float height = World.PhysicsScene.GetWorldExtentsHeight(pos.X, pos.Y); + + p0 = new Vector3(pos.X, pos.Y, height); + p1 = new Vector3(); + p2 = new Vector3(); + + if ((pos.X + 1.0f) >= worldExtents.X) + p1 = new Vector3(pos.X+1.0f, pos.Y, height); + else + p1 = new Vector3(pos.X+1.0f, pos.Y, World.PhysicsScene.GetWorldExtentsHeight(pos.X+1.0f, pos.Y)); + + if ((pos.Y + 1.0f) >= worldExtents.Y) + p2 = new Vector3(pos.X, pos.Y+1.0f, height); + else + p2 = new Vector3(pos.X, pos.Y+1.0f, World.PhysicsScene.GetWorldExtentsHeight(pos.X, pos.Y+1.0f)); + } else - p2 = new Vector3(pos.X, pos.Y + 1.0f, - (float)World.Heightmap[(int)pos.X, (int)(pos.Y + 1.0f)]); + { + // 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; + + //Find two points in addition to the position to define a plane + p0 = new Vector3(pos.X, pos.Y, + (float)World.Heightmap[(int)pos.X, (int)pos.Y]); + p1 = new Vector3(); + p2 = new Vector3(); + if ((pos.X + 1.0f) >= World.Heightmap.Width) + p1 = new Vector3(pos.X + 1.0f, pos.Y, + (float)World.Heightmap[(int)pos.X, (int)pos.Y]); + else + p1 = new Vector3(pos.X + 1.0f, pos.Y, + (float)World.Heightmap[(int)(pos.X + 1.0f), (int)pos.Y]); + if ((pos.Y + 1.0f) >= World.Heightmap.Height) + p2 = new Vector3(pos.X, pos.Y + 1.0f, + (float)World.Heightmap[(int)pos.X, (int)pos.Y]); + else + p2 = new Vector3(pos.X, pos.Y + 1.0f, + (float)World.Heightmap[(int)pos.X, (int)(pos.Y + 1.0f)]); + } //Find normalized vectors from p0 to p1 and p0 to p2 Vector3 v0 = new Vector3(p1.X - p0.X, p1.Y - p0.Y, p1.Z - p0.Z);