aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs')
-rw-r--r--OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs66
1 files changed, 40 insertions, 26 deletions
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs b/OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs
index a19d6d7..3be28e3 100644
--- a/OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs
+++ b/OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs
@@ -97,6 +97,9 @@ public sealed class BSPrim : PhysicsActor
97 long _collidingStep; 97 long _collidingStep;
98 long _collidingGroundStep; 98 long _collidingGroundStep;
99 99
100 private BulletBody m_body;
101 public BulletBody Body { get { return m_body; } }
102
100 private BSDynamics _vehicle; 103 private BSDynamics _vehicle;
101 104
102 private OMV.Vector3 _PIDTarget; 105 private OMV.Vector3 _PIDTarget;
@@ -138,6 +141,11 @@ public sealed class BSPrim : PhysicsActor
138 _scene.TaintedObject(delegate() 141 _scene.TaintedObject(delegate()
139 { 142 {
140 RecreateGeomAndObject(); 143 RecreateGeomAndObject();
144
145 // Get the pointer to the physical body for this object.
146 // At the moment, we're still letting BulletSim manage the creation and destruction
147 // of the object. Someday we'll move that into the C# code.
148 m_body = new BulletBody(LocalID, BulletSimAPI.GetBodyHandle2(_scene.World.Ptr, LocalID));
141 }); 149 });
142 } 150 }
143 151
@@ -161,7 +169,7 @@ public sealed class BSPrim : PhysicsActor
161 _parentPrim = null; 169 _parentPrim = null;
162 } 170 }
163 171
164 // make sure there are no possible children depending on me 172 // make sure there are no other prims linked to me
165 UnlinkAllChildren(); 173 UnlinkAllChildren();
166 174
167 // everything in the C# world will get garbage collected. Tell the C++ world to free stuff. 175 // everything in the C# world will get garbage collected. Tell the C++ world to free stuff.
@@ -333,11 +341,10 @@ public sealed class BSPrim : PhysicsActor
333 _rotationalVelocity = OMV.Vector3.Zero; 341 _rotationalVelocity = OMV.Vector3.Zero;
334 342
335 // Zero some other properties directly into the physics engine 343 // Zero some other properties directly into the physics engine
336 IntPtr obj = BulletSimAPI.GetBodyHandleWorldID2(_scene.WorldID, LocalID); 344 BulletSimAPI.SetVelocity2(Body.Ptr, OMV.Vector3.Zero);
337 BulletSimAPI.SetVelocity2(obj, OMV.Vector3.Zero); 345 BulletSimAPI.SetAngularVelocity2(Body.Ptr, OMV.Vector3.Zero);
338 BulletSimAPI.SetAngularVelocity2(obj, OMV.Vector3.Zero); 346 BulletSimAPI.SetInterpolation2(Body.Ptr, OMV.Vector3.Zero, OMV.Vector3.Zero);
339 BulletSimAPI.SetInterpolation2(obj, OMV.Vector3.Zero, OMV.Vector3.Zero); 347 BulletSimAPI.ClearForces2(Body.Ptr);
340 BulletSimAPI.ClearForces2(obj);
341 } 348 }
342 349
343 public override void LockAngularMotion(OMV.Vector3 axis) 350 public override void LockAngularMotion(OMV.Vector3 axis)
@@ -383,7 +390,8 @@ public sealed class BSPrim : PhysicsActor
383 _scene.TaintedObject(delegate() 390 _scene.TaintedObject(delegate()
384 { 391 {
385 DetailLog("{0},SetForce,taint,force={1}", LocalID, _force); 392 DetailLog("{0},SetForce,taint,force={1}", LocalID, _force);
386 BulletSimAPI.SetObjectForce(_scene.WorldID, _localID, _force); 393 // BulletSimAPI.SetObjectForce(_scene.WorldID, _localID, _force);
394 BulletSimAPI.SetObjectForce2(Body.Ptr, _force);
387 }); 395 });
388 } 396 }
389 } 397 }
@@ -407,8 +415,7 @@ public sealed class BSPrim : PhysicsActor
407 _scene.TaintedObject(delegate() 415 _scene.TaintedObject(delegate()
408 { 416 {
409 // Tell the physics engine to clear state 417 // Tell the physics engine to clear state
410 IntPtr obj = BulletSimAPI.GetBodyHandleWorldID2(_scene.WorldID, LocalID); 418 BulletSimAPI.ClearForces2(this.Body.Ptr);
411 BulletSimAPI.ClearForces2(obj);
412 }); 419 });
413 420
414 // make it so the scene will call us each tick to do vehicle things 421 // make it so the scene will call us each tick to do vehicle things
@@ -420,7 +427,6 @@ public sealed class BSPrim : PhysicsActor
420 } 427 }
421 public override void VehicleFloatParam(int param, float value) 428 public override void VehicleFloatParam(int param, float value)
422 { 429 {
423 m_log.DebugFormat("{0} VehicleFloatParam. {1} <= {2}", LogHeader, param, value);
424 _scene.TaintedObject(delegate() 430 _scene.TaintedObject(delegate()
425 { 431 {
426 _vehicle.ProcessFloatVehicleParam((Vehicle)param, value, _scene.LastSimulatedTimestep); 432 _vehicle.ProcessFloatVehicleParam((Vehicle)param, value, _scene.LastSimulatedTimestep);
@@ -428,7 +434,6 @@ public sealed class BSPrim : PhysicsActor
428 } 434 }
429 public override void VehicleVectorParam(int param, OMV.Vector3 value) 435 public override void VehicleVectorParam(int param, OMV.Vector3 value)
430 { 436 {
431 m_log.DebugFormat("{0} VehicleVectorParam. {1} <= {2}", LogHeader, param, value);
432 _scene.TaintedObject(delegate() 437 _scene.TaintedObject(delegate()
433 { 438 {
434 _vehicle.ProcessVectorVehicleParam((Vehicle)param, value, _scene.LastSimulatedTimestep); 439 _vehicle.ProcessVectorVehicleParam((Vehicle)param, value, _scene.LastSimulatedTimestep);
@@ -436,7 +441,6 @@ public sealed class BSPrim : PhysicsActor
436 } 441 }
437 public override void VehicleRotationParam(int param, OMV.Quaternion rotation) 442 public override void VehicleRotationParam(int param, OMV.Quaternion rotation)
438 { 443 {
439 m_log.DebugFormat("{0} VehicleRotationParam. {1} <= {2}", LogHeader, param, rotation);
440 _scene.TaintedObject(delegate() 444 _scene.TaintedObject(delegate()
441 { 445 {
442 _vehicle.ProcessRotationVehicleParam((Vehicle)param, rotation); 446 _vehicle.ProcessRotationVehicleParam((Vehicle)param, rotation);
@@ -444,7 +448,6 @@ public sealed class BSPrim : PhysicsActor
444 } 448 }
445 public override void VehicleFlags(int param, bool remove) 449 public override void VehicleFlags(int param, bool remove)
446 { 450 {
447 m_log.DebugFormat("{0} VehicleFlags. {1}. Remove={2}", LogHeader, param, remove);
448 _scene.TaintedObject(delegate() 451 _scene.TaintedObject(delegate()
449 { 452 {
450 _vehicle.ProcessVehicleFlags(param, remove); 453 _vehicle.ProcessVehicleFlags(param, remove);
@@ -1292,11 +1295,10 @@ public sealed class BSPrim : PhysicsActor
1292 // relative to each other. 1295 // relative to each other.
1293 void CreateLinkset() 1296 void CreateLinkset()
1294 { 1297 {
1295 DebugLog("{0}: CreateLinkset. Root prim={1}, prims={2}", LogHeader, LocalID, _childrenPrims.Count+1); 1298 // DebugLog("{0}: CreateLinkset. Root prim={1}, prims={2}", LogHeader, LocalID, _childrenPrims.Count+1);
1296 1299
1297 // remove any constraints that might be in place 1300 // remove any constraints that might be in place
1298 DebugLog("{0}: CreateLinkset: RemoveConstraints between me and any children", LogHeader, LocalID); 1301 UnlinkAllChildren();
1299 BulletSimAPI.RemoveConstraintByID(_scene.WorldID, LocalID);
1300 1302
1301 // create constraints between the root prim and each of the children 1303 // create constraints between the root prim and each of the children
1302 foreach (BSPrim prim in _childrenPrims) 1304 foreach (BSPrim prim in _childrenPrims)
@@ -1321,15 +1323,25 @@ public sealed class BSPrim : PhysicsActor
1321 1323
1322 // create a constraint that allows no freedom of movement between the two objects 1324 // create a constraint that allows no freedom of movement between the two objects
1323 // http://bulletphysics.org/Bullet/phpBB3/viewtopic.php?t=4818 1325 // http://bulletphysics.org/Bullet/phpBB3/viewtopic.php?t=4818
1324 DebugLog("{0}: CreateLinkset: Adding a constraint between root prim {1} and child prim {2}", LogHeader, LocalID, childPrim.LocalID); 1326 // DebugLog("{0}: CreateLinkset: Adding a constraint between root prim {1} and child prim {2}", LogHeader, LocalID, childPrim.LocalID);
1325 DetailLog("{0},LinkAChildToMe,taint,root={1},child={2}", LocalID, LocalID, childPrim.LocalID); 1327 DetailLog("{0},LinkAChildToMe,taint,root={1},child={2}", LocalID, LocalID, childPrim.LocalID);
1326 BulletSimAPI.AddConstraint(_scene.WorldID, LocalID, childPrim.LocalID, 1328 BSConstraint constrain = _scene.Constraints.CreateConstraint(
1327 childRelativePosition, 1329 _scene.World, this.Body, childPrim.Body,
1328 childRelativeRotation, 1330 childRelativePosition,
1329 OMV.Vector3.Zero, 1331 childRelativeRotation,
1330 OMV.Quaternion.Identity, 1332 OMV.Vector3.Zero,
1331 OMV.Vector3.Zero, OMV.Vector3.Zero, 1333 OMV.Quaternion.Identity);
1332 OMV.Vector3.Zero, OMV.Vector3.Zero); 1334 constrain.SetLinearLimits(OMV.Vector3.Zero, OMV.Vector3.Zero);
1335 constrain.SetAngularLimits(OMV.Vector3.Zero, OMV.Vector3.Zero);
1336
1337 // tweek the constraint to increase stability
1338 constrain.UseFrameOffset(_scene.BoolNumeric(_scene.Params.linkConstraintUseFrameOffset));
1339 if (_scene.BoolNumeric(_scene.Params.linkConstraintEnableTransMotor))
1340 {
1341 constrain.TranslationalLimitMotor(true,
1342 _scene.Params.linkConstraintTransMotorMaxVel,
1343 _scene.Params.linkConstraintTransMotorMaxForce);
1344 }
1333 } 1345 }
1334 1346
1335 // Remove linkage between myself and a particular child 1347 // Remove linkage between myself and a particular child
@@ -1339,7 +1351,8 @@ public sealed class BSPrim : PhysicsActor
1339 DebugLog("{0}: UnlinkAChildFromMe: RemoveConstraint between root prim {1} and child prim {2}", 1351 DebugLog("{0}: UnlinkAChildFromMe: RemoveConstraint between root prim {1} and child prim {2}",
1340 LogHeader, LocalID, childPrim.LocalID); 1352 LogHeader, LocalID, childPrim.LocalID);
1341 DetailLog("{0},UnlinkAChildFromMe,taint,root={1},child={2}", LocalID, LocalID, childPrim.LocalID); 1353 DetailLog("{0},UnlinkAChildFromMe,taint,root={1},child={2}", LocalID, LocalID, childPrim.LocalID);
1342 BulletSimAPI.RemoveConstraint(_scene.WorldID, LocalID, childPrim.LocalID); 1354 // BulletSimAPI.RemoveConstraint(_scene.WorldID, LocalID, childPrim.LocalID);
1355 _scene.Constraints.RemoveAndDestroyConstraint(this.Body, childPrim.Body);
1343 } 1356 }
1344 1357
1345 // Remove linkage between myself and any possible children I might have 1358 // Remove linkage between myself and any possible children I might have
@@ -1348,7 +1361,8 @@ public sealed class BSPrim : PhysicsActor
1348 { 1361 {
1349 DebugLog("{0}: UnlinkAllChildren:", LogHeader); 1362 DebugLog("{0}: UnlinkAllChildren:", LogHeader);
1350 DetailLog("{0},UnlinkAllChildren,taint", LocalID); 1363 DetailLog("{0},UnlinkAllChildren,taint", LocalID);
1351 BulletSimAPI.RemoveConstraintByID(_scene.WorldID, LocalID); 1364 _scene.Constraints.RemoveAndDestroyConstraint(this.Body);
1365 // BulletSimAPI.RemoveConstraintByID(_scene.WorldID, LocalID);
1352 } 1366 }
1353 1367
1354 #endregion // Linkset creation and destruction 1368 #endregion // Linkset creation and destruction