From c54cb59a717e86e4501d7abfff44cd3a6c113f72 Mon Sep 17 00:00:00 2001 From: "Teravus Ovares (Dan Olivares)" Date: Tue, 18 Aug 2009 11:05:07 -0400 Subject: [PATCH] * Some Physics Scene Changes to prepare for larger regions --- .../Region/Physics/Manager/PhysicsScene.cs | 2 +- .../Region/Physics/OdePlugin/ODECharacter.cs | 6 +- OpenSim/Region/Physics/OdePlugin/ODEPrim.cs | 2 +- OpenSim/Region/Physics/OdePlugin/OdePlugin.cs | 101 ++++++++++-------- 4 files changed, 59 insertions(+), 52 deletions(-) diff --git a/OpenSim/Region/Physics/Manager/PhysicsScene.cs b/OpenSim/Region/Physics/Manager/PhysicsScene.cs index 139f89869b..5c46344c8f 100644 --- a/OpenSim/Region/Physics/Manager/PhysicsScene.cs +++ b/OpenSim/Region/Physics/Manager/PhysicsScene.cs @@ -167,7 +167,7 @@ namespace OpenSim.Region.Physics.Manager return false; } - public virtual void Combine(PhysicsScene pScene, Vector3 offset) + public virtual void Combine(PhysicsScene pScene, Vector3 offset, Vector3 extents) { return; } diff --git a/OpenSim/Region/Physics/OdePlugin/ODECharacter.cs b/OpenSim/Region/Physics/OdePlugin/ODECharacter.cs index 759692f3fa..35433c697e 100644 --- a/OpenSim/Region/Physics/OdePlugin/ODECharacter.cs +++ b/OpenSim/Region/Physics/OdePlugin/ODECharacter.cs @@ -161,7 +161,7 @@ namespace OpenSim.Region.Physics.OdePlugin } else { - _position = new PhysicsVector(((int)Constants.RegionSize * 0.5f), ((int)Constants.RegionSize * 0.5f), parent_scene.GetTerrainHeightAtXY(128, 128) + 10); + _position = new PhysicsVector(((int)_parent_scene.WorldExtents.X * 0.5f), ((int)_parent_scene.WorldExtents.Y * 0.5f), parent_scene.GetTerrainHeightAtXY(128, 128) + 10); m_taintPosition.X = _position.X; m_taintPosition.Y = _position.Y; m_taintPosition.Z = _position.Z; @@ -1096,8 +1096,8 @@ namespace OpenSim.Region.Physics.OdePlugin // kluge to keep things in bounds. ODE lets dead avatars drift away (they should be removed!) if (vec.X < 0.0f) vec.X = 0.0f; if (vec.Y < 0.0f) vec.Y = 0.0f; - if (vec.X > (int)Constants.RegionSize - 0.05f) vec.X = (int)Constants.RegionSize - 0.05f; - if (vec.Y > (int)Constants.RegionSize - 0.05f) vec.Y = (int)Constants.RegionSize - 0.05f; + if (vec.X > (int)_parent_scene.WorldExtents.X - 0.05f) vec.X = (int)_parent_scene.WorldExtents.X - 0.05f; + if (vec.Y > (int)_parent_scene.WorldExtents.Y - 0.05f) vec.Y = (int)_parent_scene.WorldExtents.Y - 0.05f; _position.X = vec.X; _position.Y = vec.Y; diff --git a/OpenSim/Region/Physics/OdePlugin/ODEPrim.cs b/OpenSim/Region/Physics/OdePlugin/ODEPrim.cs index 443788c5b9..d0f77e6f55 100644 --- a/OpenSim/Region/Physics/OdePlugin/ODEPrim.cs +++ b/OpenSim/Region/Physics/OdePlugin/ODEPrim.cs @@ -2538,7 +2538,7 @@ namespace OpenSim.Region.Physics.OdePlugin l_orientation.Z = ori.Z; l_orientation.W = ori.W; - if (l_position.X > ((int)Constants.RegionSize - 0.05f) || l_position.X < 0f || l_position.Y > ((int)Constants.RegionSize - 0.05f) || l_position.Y < 0f) + if (l_position.X > ((int)_parent_scene.WorldExtents.X - 0.05f) || l_position.X < 0f || l_position.Y > ((int)_parent_scene.WorldExtents.Y - 0.05f) || l_position.Y < 0f) { //base.RaiseOutOfBounds(l_position); diff --git a/OpenSim/Region/Physics/OdePlugin/OdePlugin.cs b/OpenSim/Region/Physics/OdePlugin/OdePlugin.cs index 00163f69cd..3d25acdde1 100644 --- a/OpenSim/Region/Physics/OdePlugin/OdePlugin.cs +++ b/OpenSim/Region/Physics/OdePlugin/OdePlugin.cs @@ -312,7 +312,7 @@ namespace OpenSim.Region.Physics.OdePlugin private volatile int m_global_contactcount = 0; private Vector3 m_worldOffset = Vector3.Zero; - private Vector2 m_worldExtents = new Vector2((int)Constants.RegionSize, (int)Constants.RegionSize); + public Vector2 WorldExtents = new Vector2((int)Constants.RegionSize, (int)Constants.RegionSize); private ODERayCastRequestManager m_rayCastManager; @@ -351,10 +351,10 @@ namespace OpenSim.Region.Physics.OdePlugin } // zero out a heightmap array float array (single dimention [flattened])) - if ((int)Constants.RegionSize == 256) + if ((int)WorldExtents.X == 256 && (int)m_worldOffset.Y == 256) _heightmap = new float[514*514]; else - _heightmap = new float[(((int)Constants.RegionSize + 2) * ((int)Constants.RegionSize + 2))]; + _heightmap = new float[(((int)WorldExtents.Y + 2) * ((int)WorldExtents.X + 2))]; _watermap = new float[258 * 258]; @@ -1564,7 +1564,12 @@ namespace OpenSim.Region.Physics.OdePlugin } #endregion - + + public override void Combine(PhysicsScene pScene, Vector3 offset, Vector3 extents) + { + m_worldOffset = offset; + WorldExtents = new Vector2(extents.X, extents.Y); + } // Recovered for use by fly height. Kitto Flora public float GetTerrainHeightAtXY(float x, float y) { @@ -1576,14 +1581,14 @@ namespace OpenSim.Region.Physics.OdePlugin // Is there any reason that we don't do this in ScenePresence? // The only physics engine that benefits from it in the physics plugin is this one - if ((int)x > Constants.RegionSize || (int)y > Constants.RegionSize || + if ((int)x > WorldExtents.X || (int)y > WorldExtents.Y || (int)x < 0.001f || (int)y < 0.001f) return 0; - index = (int) ((int)y * Constants.RegionSize + (int)x); + index = (int)((int)y * WorldExtents.Y + (int)x); if (index < _origheightmap.Length) - return (float)_origheightmap[(int)y * Constants.RegionSize + (int)x]; + return (float)_origheightmap[(int)y * (int)WorldExtents.Y + (int)x]; else return 0; } @@ -3018,14 +3023,14 @@ namespace OpenSim.Region.Physics.OdePlugin public float[] ResizeTerrain512NearestNeighbour(float[] heightMap) { float[] returnarr = new float[262144]; - float[,] resultarr = new float[m_regionWidth, m_regionHeight]; + float[,] resultarr = new float[(int)WorldExtents.X, (int)WorldExtents.Y]; // Filling out the array into it's multi-dimentional components - for (int y = 0; y < m_regionHeight; y++) + for (int y = 0; y < WorldExtents.Y; y++) { - for (int x = 0; x < m_regionWidth; x++) + for (int x = 0; x < WorldExtents.X; x++) { - resultarr[y, x] = heightMap[y * m_regionWidth + x]; + resultarr[y, x] = heightMap[y * (int)WorldExtents.Y + x]; } } @@ -3089,21 +3094,21 @@ namespace OpenSim.Region.Physics.OdePlugin // on single loop. float[,] resultarr2 = new float[512, 512]; - for (int y = 0; y < m_regionHeight; y++) + for (int y = 0; y < WorldExtents.Y; y++) { - for (int x = 0; x < m_regionWidth; x++) + for (int x = 0; x < WorldExtents.X; x++) { resultarr2[y * 2, x * 2] = resultarr[y, x]; - if (y < m_regionHeight) + if (y < WorldExtents.Y) { resultarr2[(y * 2) + 1, x * 2] = resultarr[y, x]; } - if (x < m_regionWidth) + if (x < WorldExtents.X) { resultarr2[y * 2, (x * 2) + 1] = resultarr[y, x]; } - if (x < m_regionWidth && y < m_regionHeight) + if (x < WorldExtents.X && y < WorldExtents.Y) { resultarr2[(y * 2) + 1, (x * 2) + 1] = resultarr[y, x]; } @@ -3131,14 +3136,14 @@ namespace OpenSim.Region.Physics.OdePlugin public float[] ResizeTerrain512Interpolation(float[] heightMap) { float[] returnarr = new float[262144]; - float[,] resultarr = new float[m_regionWidth,m_regionHeight]; + float[,] resultarr = new float[(int)WorldExtents.X,(int)WorldExtents.Y]; // Filling out the array into it's multi-dimentional components - for (int y = 0; y < m_regionHeight; y++) + for (int y = 0; y < WorldExtents.Y; y++) { - for (int x = 0; x < m_regionWidth; x++) + for (int x = 0; x < WorldExtents.X; x++) { - resultarr[y, x] = heightMap[y*m_regionWidth + x]; + resultarr[y, x] = heightMap[y*(int)WorldExtents.Y + x]; } } @@ -3202,17 +3207,17 @@ namespace OpenSim.Region.Physics.OdePlugin // on single loop. float[,] resultarr2 = new float[512,512]; - for (int y = 0; y < m_regionHeight; y++) + for (int y = 0; y < WorldExtents.Y; y++) { - for (int x = 0; x < m_regionWidth; x++) + for (int x = 0; x < WorldExtents.X; x++) { resultarr2[y*2, x*2] = resultarr[y, x]; - if (y < m_regionHeight) + if (y < WorldExtents.Y) { - if (y + 1 < m_regionHeight) + if (y + 1 < WorldExtents.Y) { - if (x + 1 < m_regionWidth) + if (x + 1 < WorldExtents.X) { resultarr2[(y*2) + 1, x*2] = ((resultarr[y, x] + resultarr[y + 1, x] + resultarr[y, x + 1] + resultarr[y + 1, x + 1])/4); @@ -3227,11 +3232,11 @@ namespace OpenSim.Region.Physics.OdePlugin resultarr2[(y*2) + 1, x*2] = resultarr[y, x]; } } - if (x < m_regionWidth) + if (x < WorldExtents.X) { - if (x + 1 < m_regionWidth) + if (x + 1 < WorldExtents.X) { - if (y + 1 < m_regionHeight) + if (y + 1 < WorldExtents.Y) { resultarr2[y*2, (x*2) + 1] = ((resultarr[y, x] + resultarr[y + 1, x] + resultarr[y, x + 1] + resultarr[y + 1, x + 1])/4); @@ -3246,9 +3251,9 @@ namespace OpenSim.Region.Physics.OdePlugin resultarr2[y*2, (x*2) + 1] = resultarr[y, x]; } } - if (x < m_regionWidth && y < m_regionHeight) + if (x < WorldExtents.X && y < WorldExtents.Y) { - if ((x + 1 < m_regionWidth) && (y + 1 < m_regionHeight)) + if ((x + 1 < WorldExtents.X) && (y + 1 < WorldExtents.Y)) { resultarr2[(y*2) + 1, (x*2) + 1] = ((resultarr[y, x] + resultarr[y + 1, x] + resultarr[y, x + 1] + resultarr[y + 1, x + 1])/4); @@ -3286,24 +3291,26 @@ namespace OpenSim.Region.Physics.OdePlugin // this._heightmap[i] = (double)heightMap[i]; // dbm (danx0r) -- creating a buffer zone of one extra sample all around _origheightmap = heightMap; // Used for Fly height. Kitto Flora - uint heightmapWidth = m_regionWidth + 1; - uint heightmapHeight = m_regionHeight + 1; + uint heightmapWidth = (uint)WorldExtents.X + 1; + uint heightmapHeight = (uint)WorldExtents.Y + 1; uint heightmapWidthSamples; uint heightmapHeightSamples; - if (((int)Constants.RegionSize) == 256) + /* + if (((int)m_worldExtents.X) == 256 && (int)m_worldExtents.Y == 256) { - heightmapWidthSamples = 2*m_regionWidth + 2; - heightmapHeightSamples = 2*m_regionHeight + 2; + heightmapWidthSamples = 2 * (uint)m_worldExtents.X + 2; + heightmapHeightSamples = 2*(uint)m_worldExtents.Y + 2; heightmapWidth++; heightmapHeight++; } else { - heightmapWidthSamples = m_regionWidth + 1; - heightmapHeightSamples = m_regionHeight + 1; - } + */ + heightmapWidthSamples = (uint)WorldExtents.X + 1; + heightmapHeightSamples = (uint)WorldExtents.Y + 1; + //} const float scale = 1.0f; const float offset = 0.0f; @@ -3312,12 +3319,12 @@ namespace OpenSim.Region.Physics.OdePlugin //Double resolution - if (((int)Constants.RegionSize) == 256) - heightMap = ResizeTerrain512Interpolation(heightMap); + //if (((int)m_worldExtents.X) == 256 && (int)m_worldExtents.Y == 256) + // heightMap = ResizeTerrain512Interpolation(heightMap); - int regionsize = (int)Constants.RegionSize; - if (regionsize == 256) - regionsize = 512; + + //if (((int)m_worldExtents.X) == 256 && (int)m_worldExtents.Y == 256) + // regionsize = 512; float hfmin = 2000; float hfmax = -2000; @@ -3325,10 +3332,10 @@ namespace OpenSim.Region.Physics.OdePlugin { for (int y = 0; y < heightmapHeightSamples; y++) { - int xx = Util.Clip(x - 1, 0, regionsize - 1); - int yy = Util.Clip(y - 1, 0, regionsize - 1); + int xx = Util.Clip(x - 1, 0, (int)WorldExtents.X - 1); + int yy = Util.Clip(y - 1, 0, (int)WorldExtents.Y - 1); - float val = heightMap[yy*regionsize + xx]; + float val = heightMap[yy*(int)WorldExtents.Y + xx]; _heightmap[x*heightmapHeightSamples + y] = val; hfmin = (val < hfmin) ? val : hfmin; hfmax = (val > hfmax) ? val : hfmax; @@ -3369,7 +3376,7 @@ namespace OpenSim.Region.Physics.OdePlugin d.RFromAxisAndAngle(out R, v3.X, v3.Y, v3.Z, angle); d.GeomSetRotation(LandGeom, ref R); - d.GeomSetPosition(LandGeom, (int)Constants.RegionSize * 0.5f, (int)Constants.RegionSize * 0.5f, 0); + d.GeomSetPosition(LandGeom, (int)WorldExtents.X * 0.5f, (int)WorldExtents.Y * 0.5f, 0); } }