28 using System.Collections.Generic;
31 using OpenSim.Framework;
32 using OpenSim.Region.Framework;
33 using OpenSim.Region.PhysicsModules.SharedBase;
40 namespace OpenSim.
Region.PhysicsModule.BulletS
44 static string LogHeader =
"[BULLETSIM TERRAIN HEIGHTMAP]";
50 : base(physicsScene, regionBase, id)
54 int totalHeights = (int)maxTerrainCoords.X * (
int)maxTerrainCoords.Y;
55 float[] initialMap =
new float[totalHeights];
56 for (
int ii = 0; ii < totalHeights; ii++)
58 initialMap[ii] = BSTerrainManager.HEIGHT_INITIALIZATION;
60 m_mapInfo =
new BulletHMapInfo(
id, initialMap, regionSize.X, regionSize.Y);
61 m_mapInfo.minCoords = minTerrainCoords;
62 m_mapInfo.maxCoords = maxTerrainCoords;
63 m_mapInfo.terrainRegionBase = TerrainBase;
65 BuildHeightmapTerrain();
71 Vector3 minCoords, Vector3 maxCoords)
72 : base(physicsScene, regionBase, id)
74 m_mapInfo =
new BulletHMapInfo(
id, initialMap, maxCoords.X - minCoords.X, maxCoords.Y - minCoords.Y);
75 m_mapInfo.minCoords = minCoords;
76 m_mapInfo.maxCoords = maxCoords;
77 m_mapInfo.minZ = minCoords.Z;
78 m_mapInfo.maxZ = maxCoords.Z;
79 m_mapInfo.terrainRegionBase = TerrainBase;
82 BuildHeightmapTerrain();
87 ReleaseHeightMapTerrain();
91 private void BuildHeightmapTerrain()
94 m_mapInfo.terrainShape = m_physicsScene.PE.CreateTerrainShape( m_mapInfo.ID,
95 new Vector3(m_mapInfo.sizeX, m_mapInfo.sizeY, 0), m_mapInfo.minZ, m_mapInfo.maxZ,
96 m_mapInfo.heightMap, 1f, BSParam.TerrainCollisionMargin);
101 centerPos.X = m_mapInfo.minCoords.X + (m_mapInfo.sizeX / 2f);
102 centerPos.Y = m_mapInfo.minCoords.Y + (m_mapInfo.sizeY / 2f);
103 centerPos.Z = m_mapInfo.minZ + ((m_mapInfo.maxZ - m_mapInfo.minZ) / 2f);
105 m_mapInfo.terrainBody = m_physicsScene.PE.CreateBodyWithDefaultMotionState(m_mapInfo.terrainShape,
106 m_mapInfo.ID, centerPos, Quaternion.Identity);
109 m_physicsScene.PE.SetFriction(m_mapInfo.terrainBody, BSParam.TerrainFriction);
110 m_physicsScene.PE.SetHitFraction(m_mapInfo.terrainBody, BSParam.TerrainHitFraction);
111 m_physicsScene.PE.SetRestitution(m_mapInfo.terrainBody, BSParam.TerrainRestitution);
112 m_physicsScene.PE.SetCollisionFlags(m_mapInfo.terrainBody, CollisionFlags.CF_STATIC_OBJECT);
114 m_mapInfo.terrainBody.collisionType = CollisionType.Terrain;
117 m_physicsScene.PE.AddObjectToWorld(m_physicsScene.World, m_mapInfo.terrainBody);
120 m_physicsScene.PE.UpdateSingleAabb(m_physicsScene.World, m_mapInfo.terrainBody);
123 m_physicsScene.PE.ForceActivationState(m_mapInfo.terrainBody, ActivationState.DISABLE_SIMULATION);
129 private void ReleaseHeightMapTerrain()
131 if (m_mapInfo != null)
133 if (m_mapInfo.terrainBody.HasPhysicalBody)
135 m_physicsScene.PE.RemoveObjectFromWorld(m_physicsScene.World, m_mapInfo.terrainBody);
137 m_physicsScene.PE.DestroyObject(m_physicsScene.World, m_mapInfo.terrainBody);
146 float ret = BSTerrainManager.HEIGHT_GETHEIGHT_RET;
148 int mapIndex = (int)pos.Y * (
int)m_mapInfo.sizeY + (int)pos.X;
151 ret = m_mapInfo.heightMap[mapIndex];
156 m_physicsScene.Logger.WarnFormat(
"{0} Bad request for terrain height. terrainBase={1}, pos={2}",
157 LogHeader, m_mapInfo.terrainRegionBase, pos);
158 ret = BSTerrainManager.HEIGHT_GETHEIGHT_RET;
166 return m_physicsScene.SimpleWaterLevel;
override float GetTerrainHeightAtXYZ(Vector3 pos)
const float HEIGHT_EQUAL_FUDGE
BSTerrainHeightmap(BSScene physicsScene, Vector3 regionBase, uint id, Vector3 regionSize)
const float HEIGHT_INITIALIZATION
override float GetWaterLevelAtXYZ(Vector3 pos)
BSTerrainHeightmap(BSScene physicsScene, Vector3 regionBase, uint id, float[] initialMap, Vector3 minCoords, Vector3 maxCoords)