diff options
author | Robert Adams | 2012-09-18 11:26:19 -0700 |
---|---|---|
committer | Robert Adams | 2012-09-27 22:01:16 -0700 |
commit | 91efccabdcb45ed95ae35ab24ed5d3ed5508b463 (patch) | |
tree | fb801ca0bd72aae3427a5ca439f807ec3802d7c3 /OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs | |
parent | BulletSim: move a bunch of common logic out of BSPrim and BSCharacter (diff) | |
download | opensim-SC_OLD-91efccabdcb45ed95ae35ab24ed5d3ed5508b463.zip opensim-SC_OLD-91efccabdcb45ed95ae35ab24ed5d3ed5508b463.tar.gz opensim-SC_OLD-91efccabdcb45ed95ae35ab24ed5d3ed5508b463.tar.bz2 opensim-SC_OLD-91efccabdcb45ed95ae35ab24ed5d3ed5508b463.tar.xz |
BulletSim: Convert BSCharacter to use common BSPhysObject code and variables.
Fix avatar height calculation to properly account for the capsule ends.
Rearrange some locking in TerrainManager to eliminate possible race conditions.
Move DetailLog() definition into common BSPhysObject class.
Some variable renaming to make usage clearer (refactor.rename makes this so easy).
Diffstat (limited to 'OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs')
-rw-r--r-- | OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs | 40 |
1 files changed, 13 insertions, 27 deletions
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs b/OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs index 29f27e8..4f10d46 100644 --- a/OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs +++ b/OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs | |||
@@ -49,9 +49,6 @@ public sealed class BSPrim : BSPhysObject | |||
49 | private ulong _hullKey; | 49 | private ulong _hullKey; |
50 | private List<ConvexResult> _hulls; | 50 | private List<ConvexResult> _hulls; |
51 | 51 | ||
52 | private String _avName; | ||
53 | private uint _localID = 0; | ||
54 | |||
55 | // _size is what the user passed. _scale is what we pass to the physics engine with the mesh. | 52 | // _size is what the user passed. _scale is what we pass to the physics engine with the mesh. |
56 | // Often _scale is unity because the meshmerizer will apply _size when creating the mesh. | 53 | // Often _scale is unity because the meshmerizer will apply _size when creating the mesh. |
57 | private OMV.Vector3 _size; // the multiplier for each mesh dimension as passed by the user | 54 | private OMV.Vector3 _size; // the multiplier for each mesh dimension as passed by the user |
@@ -99,9 +96,7 @@ public sealed class BSPrim : BSPhysObject | |||
99 | OMV.Quaternion rotation, PrimitiveBaseShape pbs, bool pisPhysical) | 96 | OMV.Quaternion rotation, PrimitiveBaseShape pbs, bool pisPhysical) |
100 | { | 97 | { |
101 | // m_log.DebugFormat("{0}: BSPrim creation of {1}, id={2}", LogHeader, primName, localID); | 98 | // m_log.DebugFormat("{0}: BSPrim creation of {1}, id={2}", LogHeader, primName, localID); |
102 | base.BaseInitialize(parent_scene); | 99 | base.BaseInitialize(parent_scene, localID, primName); |
103 | _localID = localID; | ||
104 | _avName = primName; | ||
105 | _physicsActorType = (int)ActorTypes.Prim; | 100 | _physicsActorType = (int)ActorTypes.Prim; |
106 | _position = pos; | 101 | _position = pos; |
107 | _size = size; | 102 | _size = size; |
@@ -187,10 +182,6 @@ public sealed class BSPrim : BSPhysObject | |||
187 | }); | 182 | }); |
188 | } | 183 | } |
189 | } | 184 | } |
190 | public override uint LocalID { | ||
191 | set { _localID = value; } | ||
192 | get { return _localID; } | ||
193 | } | ||
194 | public override bool Grabbed { | 185 | public override bool Grabbed { |
195 | set { _grabbed = value; | 186 | set { _grabbed = value; |
196 | } | 187 | } |
@@ -267,7 +258,7 @@ public sealed class BSPrim : BSPhysObject | |||
267 | _position = BulletSimAPI.GetPosition2(BSBody.Ptr); | 258 | _position = BulletSimAPI.GetPosition2(BSBody.Ptr); |
268 | 259 | ||
269 | // don't do the GetObjectPosition for root elements because this function is called a zillion times | 260 | // don't do the GetObjectPosition for root elements because this function is called a zillion times |
270 | // _position = BulletSimAPI.GetObjectPosition(Scene.WorldID, _localID); | 261 | // _position = BulletSimAPI.GetObjectPosition(Scene.WorldID, LocalID); |
271 | return _position; | 262 | return _position; |
272 | } | 263 | } |
273 | set { | 264 | set { |
@@ -425,7 +416,7 @@ public sealed class BSPrim : BSPhysObject | |||
425 | // TODO: what does it mean if a child in a linkset changes its orientation? Rebuild the constraint? | 416 | // TODO: what does it mean if a child in a linkset changes its orientation? Rebuild the constraint? |
426 | PhysicsScene.TaintedObject("BSPrim.setOrientation", delegate() | 417 | PhysicsScene.TaintedObject("BSPrim.setOrientation", delegate() |
427 | { | 418 | { |
428 | // _position = BulletSimAPI.GetObjectPosition(Scene.WorldID, _localID); | 419 | // _position = BulletSimAPI.GetObjectPosition(Scene.WorldID, LocalID); |
429 | DetailLog("{0},BSPrim.setOrientation,taint,pos={1},orient={2}", LocalID, _position, _orientation); | 420 | DetailLog("{0},BSPrim.setOrientation,taint,pos={1},orient={2}", LocalID, _position, _orientation); |
430 | BulletSimAPI.SetTranslation2(BSBody.Ptr, _position, _orientation); | 421 | BulletSimAPI.SetTranslation2(BSBody.Ptr, _position, _orientation); |
431 | }); | 422 | }); |
@@ -666,7 +657,7 @@ public sealed class BSPrim : BSPhysObject | |||
666 | // Buoyancy is faked by changing the gravity applied to the object | 657 | // Buoyancy is faked by changing the gravity applied to the object |
667 | float grav = PhysicsScene.Params.gravity * (1f - _buoyancy); | 658 | float grav = PhysicsScene.Params.gravity * (1f - _buoyancy); |
668 | BulletSimAPI.SetGravity2(BSBody.Ptr, new OMV.Vector3(0f, 0f, grav)); | 659 | BulletSimAPI.SetGravity2(BSBody.Ptr, new OMV.Vector3(0f, 0f, grav)); |
669 | // BulletSimAPI.SetObjectBuoyancy(Scene.WorldID, _localID, _buoyancy); | 660 | // BulletSimAPI.SetObjectBuoyancy(Scene.WorldID, LocalID, _buoyancy); |
670 | }); | 661 | }); |
671 | } | 662 | } |
672 | } | 663 | } |
@@ -1127,7 +1118,7 @@ public sealed class BSPrim : BSPhysObject | |||
1127 | lod = PhysicsScene.MeshMegaPrimLOD; | 1118 | lod = PhysicsScene.MeshMegaPrimLOD; |
1128 | 1119 | ||
1129 | ulong newMeshKey = (ulong)_pbs.GetMeshKey(_size, lod); | 1120 | ulong newMeshKey = (ulong)_pbs.GetMeshKey(_size, lod); |
1130 | // m_log.DebugFormat("{0}: CreateGeomMesh: lID={1}, oldKey={2}, newKey={3}", LogHeader, _localID, _meshKey, newMeshKey); | 1121 | // m_log.DebugFormat("{0}: CreateGeomMesh: lID={1}, oldKey={2}, newKey={3}", LogHeader, LocalID, _meshKey, newMeshKey); |
1131 | 1122 | ||
1132 | // if this new shape is the same as last time, don't recreate the mesh | 1123 | // if this new shape is the same as last time, don't recreate the mesh |
1133 | if (_meshKey == newMeshKey) return false; | 1124 | if (_meshKey == newMeshKey) return false; |
@@ -1136,7 +1127,7 @@ public sealed class BSPrim : BSPhysObject | |||
1136 | // Since we're recreating new, get rid of any previously generated shape | 1127 | // Since we're recreating new, get rid of any previously generated shape |
1137 | if (_meshKey != 0) | 1128 | if (_meshKey != 0) |
1138 | { | 1129 | { |
1139 | // m_log.DebugFormat("{0}: CreateGeom: deleting old mesh. lID={1}, Key={2}", LogHeader, _localID, _meshKey); | 1130 | // m_log.DebugFormat("{0}: CreateGeom: deleting old mesh. lID={1}, Key={2}", LogHeader, LocalID, _meshKey); |
1140 | DetailLog("{0},BSPrim.CreateGeomMesh,deleteOld,key={1}", LocalID, _meshKey); | 1131 | DetailLog("{0},BSPrim.CreateGeomMesh,deleteOld,key={1}", LocalID, _meshKey); |
1141 | BulletSimAPI.DestroyMesh(PhysicsScene.WorldID, _meshKey); | 1132 | BulletSimAPI.DestroyMesh(PhysicsScene.WorldID, _meshKey); |
1142 | _mesh = null; | 1133 | _mesh = null; |
@@ -1145,7 +1136,7 @@ public sealed class BSPrim : BSPhysObject | |||
1145 | 1136 | ||
1146 | _meshKey = newMeshKey; | 1137 | _meshKey = newMeshKey; |
1147 | // always pass false for physicalness as this creates some sort of bounding box which we don't need | 1138 | // always pass false for physicalness as this creates some sort of bounding box which we don't need |
1148 | _mesh = PhysicsScene.mesher.CreateMesh(_avName, _pbs, _size, lod, false); | 1139 | _mesh = PhysicsScene.mesher.CreateMesh(PhysObjectName, _pbs, _size, lod, false); |
1149 | 1140 | ||
1150 | int[] indices = _mesh.getIndexListAsInt(); | 1141 | int[] indices = _mesh.getIndexListAsInt(); |
1151 | List<OMV.Vector3> vertices = _mesh.getVertexList(); | 1142 | List<OMV.Vector3> vertices = _mesh.getVertexList(); |
@@ -1160,7 +1151,7 @@ public sealed class BSPrim : BSPhysObject | |||
1160 | } | 1151 | } |
1161 | 1152 | ||
1162 | // m_log.DebugFormat("{0}: CreateGeomMesh: calling CreateMesh. lid={1}, key={2}, indices={3}, vertices={4}", | 1153 | // m_log.DebugFormat("{0}: CreateGeomMesh: calling CreateMesh. lid={1}, key={2}, indices={3}, vertices={4}", |
1163 | // LogHeader, _localID, _meshKey, indices.Length, vertices.Count); | 1154 | // LogHeader, LocalID, _meshKey, indices.Length, vertices.Count); |
1164 | BulletSimAPI.CreateMesh(PhysicsScene.WorldID, _meshKey, indices.GetLength(0), indices, | 1155 | BulletSimAPI.CreateMesh(PhysicsScene.WorldID, _meshKey, indices.GetLength(0), indices, |
1165 | vertices.Count, verticesAsFloats); | 1156 | vertices.Count, verticesAsFloats); |
1166 | 1157 | ||
@@ -1176,7 +1167,7 @@ public sealed class BSPrim : BSPhysObject | |||
1176 | { | 1167 | { |
1177 | float lod = _pbs.SculptEntry ? PhysicsScene.SculptLOD : PhysicsScene.MeshLOD; | 1168 | float lod = _pbs.SculptEntry ? PhysicsScene.SculptLOD : PhysicsScene.MeshLOD; |
1178 | ulong newHullKey = (ulong)_pbs.GetMeshKey(_size, lod); | 1169 | ulong newHullKey = (ulong)_pbs.GetMeshKey(_size, lod); |
1179 | // m_log.DebugFormat("{0}: CreateGeomHull: lID={1}, oldKey={2}, newKey={3}", LogHeader, _localID, _hullKey, newHullKey); | 1170 | // m_log.DebugFormat("{0}: CreateGeomHull: lID={1}, oldKey={2}, newKey={3}", LogHeader, LocalID, _hullKey, newHullKey); |
1180 | 1171 | ||
1181 | // if the hull hasn't changed, don't rebuild it | 1172 | // if the hull hasn't changed, don't rebuild it |
1182 | if (newHullKey == _hullKey) return false; | 1173 | if (newHullKey == _hullKey) return false; |
@@ -1276,7 +1267,7 @@ public sealed class BSPrim : BSPhysObject | |||
1276 | } | 1267 | } |
1277 | 1268 | ||
1278 | // create the hull definition in Bullet | 1269 | // create the hull definition in Bullet |
1279 | // m_log.DebugFormat("{0}: CreateGeom: calling CreateHull. lid={1}, key={2}, hulls={3}", LogHeader, _localID, _hullKey, hullCount); | 1270 | // m_log.DebugFormat("{0}: CreateGeom: calling CreateHull. lid={1}, key={2}, hulls={3}", LogHeader, LocalID, _hullKey, hullCount); |
1280 | BulletSimAPI.CreateHull(PhysicsScene.WorldID, _hullKey, hullCount, convHulls); | 1271 | BulletSimAPI.CreateHull(PhysicsScene.WorldID, _hullKey, hullCount, convHulls); |
1281 | _shapeType = ShapeData.PhysicsShapeType.SHAPE_HULL; | 1272 | _shapeType = ShapeData.PhysicsShapeType.SHAPE_HULL; |
1282 | // meshes are already scaled by the meshmerizer | 1273 | // meshes are already scaled by the meshmerizer |
@@ -1316,7 +1307,7 @@ public sealed class BSPrim : BSPhysObject | |||
1316 | // the mesh or hull must have already been created in Bullet | 1307 | // the mesh or hull must have already been created in Bullet |
1317 | ShapeData shape; | 1308 | ShapeData shape; |
1318 | FillShapeInfo(out shape); | 1309 | FillShapeInfo(out shape); |
1319 | // m_log.DebugFormat("{0}: CreateObject: lID={1}, shape={2}", LogHeader, _localID, shape.Type); | 1310 | // m_log.DebugFormat("{0}: CreateObject: lID={1}, shape={2}", LogHeader, LocalID, shape.Type); |
1320 | bool ret = BulletSimAPI.CreateObject(PhysicsScene.WorldID, shape); | 1311 | bool ret = BulletSimAPI.CreateObject(PhysicsScene.WorldID, shape); |
1321 | 1312 | ||
1322 | // the CreateObject() may have recreated the rigid body. Make sure we have the latest address. | 1313 | // the CreateObject() may have recreated the rigid body. Make sure we have the latest address. |
@@ -1329,7 +1320,7 @@ public sealed class BSPrim : BSPhysObject | |||
1329 | // Copy prim's info into the BulletSim shape description structure | 1320 | // Copy prim's info into the BulletSim shape description structure |
1330 | public void FillShapeInfo(out ShapeData shape) | 1321 | public void FillShapeInfo(out ShapeData shape) |
1331 | { | 1322 | { |
1332 | shape.ID = _localID; | 1323 | shape.ID = LocalID; |
1333 | shape.Type = _shapeType; | 1324 | shape.Type = _shapeType; |
1334 | shape.Position = _position; | 1325 | shape.Position = _position; |
1335 | shape.Rotation = _orientation; | 1326 | shape.Rotation = _orientation; |
@@ -1350,7 +1341,7 @@ public sealed class BSPrim : BSPhysObject | |||
1350 | // No locking here because this is done when the physics engine is not simulating | 1341 | // No locking here because this is done when the physics engine is not simulating |
1351 | private void CreateGeomAndObject(bool forceRebuild) | 1342 | private void CreateGeomAndObject(bool forceRebuild) |
1352 | { | 1343 | { |
1353 | // m_log.DebugFormat("{0}: CreateGeomAndObject. lID={1}, force={2}", LogHeader, _localID, forceRebuild); | 1344 | // m_log.DebugFormat("{0}: CreateGeomAndObject. lID={1}, force={2}", LogHeader, LocalID, forceRebuild); |
1354 | // Create the geometry that will make up the object | 1345 | // Create the geometry that will make up the object |
1355 | if (CreateGeom(forceRebuild)) | 1346 | if (CreateGeom(forceRebuild)) |
1356 | { | 1347 | { |
@@ -1453,10 +1444,5 @@ public sealed class BSPrim : BSPhysObject | |||
1453 | } | 1444 | } |
1454 | */ | 1445 | */ |
1455 | } | 1446 | } |
1456 | // Invoke the detailed logger and output something if it's enabled. | ||
1457 | private void DetailLog(string msg, params Object[] args) | ||
1458 | { | ||
1459 | PhysicsScene.PhysicsLogging.Write(msg, args); | ||
1460 | } | ||
1461 | } | 1447 | } |
1462 | } | 1448 | } |