diff options
Diffstat (limited to '')
-rwxr-xr-x | OpenSim/Region/Physics/BulletSPlugin/BSTerrainHeightmap.cs | 55 |
1 files changed, 28 insertions, 27 deletions
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSTerrainHeightmap.cs b/OpenSim/Region/Physics/BulletSPlugin/BSTerrainHeightmap.cs index 3ca756c..e4fecc3 100755 --- a/OpenSim/Region/Physics/BulletSPlugin/BSTerrainHeightmap.cs +++ b/OpenSim/Region/Physics/BulletSPlugin/BSTerrainHeightmap.cs | |||
@@ -44,7 +44,7 @@ public sealed class BSTerrainHeightmap : BSTerrainPhys | |||
44 | { | 44 | { |
45 | static string LogHeader = "[BULLETSIM TERRAIN HEIGHTMAP]"; | 45 | static string LogHeader = "[BULLETSIM TERRAIN HEIGHTMAP]"; |
46 | 46 | ||
47 | BulletHeightMapInfo m_mapInfo = null; | 47 | BulletHMapInfo m_mapInfo = null; |
48 | 48 | ||
49 | // Constructor to build a default, flat heightmap terrain. | 49 | // Constructor to build a default, flat heightmap terrain. |
50 | public BSTerrainHeightmap(BSScene physicsScene, Vector3 regionBase, uint id, Vector3 regionSize) | 50 | public BSTerrainHeightmap(BSScene physicsScene, Vector3 regionBase, uint id, Vector3 regionSize) |
@@ -58,7 +58,7 @@ public sealed class BSTerrainHeightmap : BSTerrainPhys | |||
58 | { | 58 | { |
59 | initialMap[ii] = BSTerrainManager.HEIGHT_INITIALIZATION; | 59 | initialMap[ii] = BSTerrainManager.HEIGHT_INITIALIZATION; |
60 | } | 60 | } |
61 | m_mapInfo = new BulletHeightMapInfo(id, initialMap, IntPtr.Zero); | 61 | m_mapInfo = new BulletHMapInfo(id, initialMap); |
62 | m_mapInfo.minCoords = minTerrainCoords; | 62 | m_mapInfo.minCoords = minTerrainCoords; |
63 | m_mapInfo.maxCoords = maxTerrainCoords; | 63 | m_mapInfo.maxCoords = maxTerrainCoords; |
64 | m_mapInfo.terrainRegionBase = TerrainBase; | 64 | m_mapInfo.terrainRegionBase = TerrainBase; |
@@ -72,7 +72,7 @@ public sealed class BSTerrainHeightmap : BSTerrainPhys | |||
72 | Vector3 minCoords, Vector3 maxCoords) | 72 | Vector3 minCoords, Vector3 maxCoords) |
73 | : base(physicsScene, regionBase, id) | 73 | : base(physicsScene, regionBase, id) |
74 | { | 74 | { |
75 | m_mapInfo = new BulletHeightMapInfo(id, initialMap, IntPtr.Zero); | 75 | m_mapInfo = new BulletHMapInfo(id, initialMap); |
76 | m_mapInfo.minCoords = minCoords; | 76 | m_mapInfo.minCoords = minCoords; |
77 | m_mapInfo.maxCoords = maxCoords; | 77 | m_mapInfo.maxCoords = maxCoords; |
78 | m_mapInfo.minZ = minCoords.Z; | 78 | m_mapInfo.minZ = minCoords.Z; |
@@ -91,13 +91,11 @@ public sealed class BSTerrainHeightmap : BSTerrainPhys | |||
91 | // Using the information in m_mapInfo, create the physical representation of the heightmap. | 91 | // Using the information in m_mapInfo, create the physical representation of the heightmap. |
92 | private void BuildHeightmapTerrain() | 92 | private void BuildHeightmapTerrain() |
93 | { | 93 | { |
94 | m_mapInfo.Ptr = BulletSimAPI.CreateHeightMapInfo2(PhysicsScene.World.ptr, m_mapInfo.ID, | ||
95 | m_mapInfo.minCoords, m_mapInfo.maxCoords, | ||
96 | m_mapInfo.heightMap, BSTerrainManager.TERRAIN_COLLISION_MARGIN); | ||
97 | |||
98 | // Create the terrain shape from the mapInfo | 94 | // Create the terrain shape from the mapInfo |
99 | m_mapInfo.terrainShape = new BulletShape(BulletSimAPI.CreateTerrainShape2(m_mapInfo.Ptr), | 95 | m_mapInfo.terrainShape = PhysicsScene.PE.CreateTerrainShape( m_mapInfo.ID, |
100 | BSPhysicsShapeType.SHAPE_TERRAIN); | 96 | new Vector3(m_mapInfo.sizeX, m_mapInfo.sizeY, 0), m_mapInfo.minZ, m_mapInfo.maxZ, |
97 | m_mapInfo.heightMap, 1f, BSParam.TerrainCollisionMargin); | ||
98 | |||
101 | 99 | ||
102 | // The terrain object initial position is at the center of the object | 100 | // The terrain object initial position is at the center of the object |
103 | Vector3 centerPos; | 101 | Vector3 centerPos; |
@@ -105,28 +103,26 @@ public sealed class BSTerrainHeightmap : BSTerrainPhys | |||
105 | centerPos.Y = m_mapInfo.minCoords.Y + (m_mapInfo.sizeY / 2f); | 103 | centerPos.Y = m_mapInfo.minCoords.Y + (m_mapInfo.sizeY / 2f); |
106 | centerPos.Z = m_mapInfo.minZ + ((m_mapInfo.maxZ - m_mapInfo.minZ) / 2f); | 104 | centerPos.Z = m_mapInfo.minZ + ((m_mapInfo.maxZ - m_mapInfo.minZ) / 2f); |
107 | 105 | ||
108 | m_mapInfo.terrainBody = new BulletBody(m_mapInfo.ID, | 106 | m_mapInfo.terrainBody = PhysicsScene.PE.CreateBodyWithDefaultMotionState(m_mapInfo.terrainShape, |
109 | BulletSimAPI.CreateBodyWithDefaultMotionState2(m_mapInfo.terrainShape.ptr, | 107 | m_mapInfo.ID, centerPos, Quaternion.Identity); |
110 | m_mapInfo.ID, centerPos, Quaternion.Identity)); | ||
111 | 108 | ||
112 | // Set current terrain attributes | 109 | // Set current terrain attributes |
113 | BulletSimAPI.SetFriction2(m_mapInfo.terrainBody.ptr, PhysicsScene.Params.terrainFriction); | 110 | PhysicsScene.PE.SetFriction(m_mapInfo.terrainBody, BSParam.TerrainFriction); |
114 | BulletSimAPI.SetHitFraction2(m_mapInfo.terrainBody.ptr, PhysicsScene.Params.terrainHitFraction); | 111 | PhysicsScene.PE.SetHitFraction(m_mapInfo.terrainBody, BSParam.TerrainHitFraction); |
115 | BulletSimAPI.SetRestitution2(m_mapInfo.terrainBody.ptr, PhysicsScene.Params.terrainRestitution); | 112 | PhysicsScene.PE.SetRestitution(m_mapInfo.terrainBody, BSParam.TerrainRestitution); |
116 | BulletSimAPI.SetCollisionFlags2(m_mapInfo.terrainBody.ptr, CollisionFlags.CF_STATIC_OBJECT); | 113 | PhysicsScene.PE.SetCollisionFlags(m_mapInfo.terrainBody, CollisionFlags.CF_STATIC_OBJECT); |
117 | 114 | ||
118 | // Return the new terrain to the world of physical objects | 115 | // Return the new terrain to the world of physical objects |
119 | BulletSimAPI.AddObjectToWorld2(PhysicsScene.World.ptr, m_mapInfo.terrainBody.ptr); | 116 | PhysicsScene.PE.AddObjectToWorld(PhysicsScene.World, m_mapInfo.terrainBody); |
120 | 117 | ||
121 | // redo its bounding box now that it is in the world | 118 | // redo its bounding box now that it is in the world |
122 | BulletSimAPI.UpdateSingleAabb2(PhysicsScene.World.ptr, m_mapInfo.terrainBody.ptr); | 119 | PhysicsScene.PE.UpdateSingleAabb(PhysicsScene.World, m_mapInfo.terrainBody); |
123 | 120 | ||
124 | BulletSimAPI.SetCollisionFilterMask2(m_mapInfo.terrainBody.ptr, | 121 | m_mapInfo.terrainBody.collisionType = CollisionType.Terrain; |
125 | (uint)CollisionFilterGroups.TerrainFilter, | 122 | m_mapInfo.terrainBody.ApplyCollisionMask(PhysicsScene); |
126 | (uint)CollisionFilterGroups.TerrainMask); | ||
127 | 123 | ||
128 | // Make it so the terrain will not move or be considered for movement. | 124 | // Make it so the terrain will not move or be considered for movement. |
129 | BulletSimAPI.ForceActivationState2(m_mapInfo.terrainBody.ptr, ActivationState.DISABLE_SIMULATION); | 125 | PhysicsScene.PE.ForceActivationState(m_mapInfo.terrainBody, ActivationState.DISABLE_SIMULATION); |
130 | 126 | ||
131 | return; | 127 | return; |
132 | } | 128 | } |
@@ -136,19 +132,18 @@ public sealed class BSTerrainHeightmap : BSTerrainPhys | |||
136 | { | 132 | { |
137 | if (m_mapInfo != null) | 133 | if (m_mapInfo != null) |
138 | { | 134 | { |
139 | if (m_mapInfo.terrainBody.ptr != IntPtr.Zero) | 135 | if (m_mapInfo.terrainBody.HasPhysicalBody) |
140 | { | 136 | { |
141 | BulletSimAPI.RemoveObjectFromWorld2(PhysicsScene.World.ptr, m_mapInfo.terrainBody.ptr); | 137 | PhysicsScene.PE.RemoveObjectFromWorld(PhysicsScene.World, m_mapInfo.terrainBody); |
142 | // Frees both the body and the shape. | 138 | // Frees both the body and the shape. |
143 | BulletSimAPI.DestroyObject2(PhysicsScene.World.ptr, m_mapInfo.terrainBody.ptr); | 139 | PhysicsScene.PE.DestroyObject(PhysicsScene.World, m_mapInfo.terrainBody); |
144 | BulletSimAPI.ReleaseHeightMapInfo2(m_mapInfo.Ptr); | ||
145 | } | 140 | } |
146 | } | 141 | } |
147 | m_mapInfo = null; | 142 | m_mapInfo = null; |
148 | } | 143 | } |
149 | 144 | ||
150 | // The passed position is relative to the base of the region. | 145 | // The passed position is relative to the base of the region. |
151 | public override float GetHeightAtXYZ(Vector3 pos) | 146 | public override float GetTerrainHeightAtXYZ(Vector3 pos) |
152 | { | 147 | { |
153 | float ret = BSTerrainManager.HEIGHT_GETHEIGHT_RET; | 148 | float ret = BSTerrainManager.HEIGHT_GETHEIGHT_RET; |
154 | 149 | ||
@@ -166,5 +161,11 @@ public sealed class BSTerrainHeightmap : BSTerrainPhys | |||
166 | } | 161 | } |
167 | return ret; | 162 | return ret; |
168 | } | 163 | } |
164 | |||
165 | // The passed position is relative to the base of the region. | ||
166 | public override float GetWaterLevelAtXYZ(Vector3 pos) | ||
167 | { | ||
168 | return PhysicsScene.SimpleWaterLevel; | ||
169 | } | ||
169 | } | 170 | } |
170 | } | 171 | } |