aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs
diff options
context:
space:
mode:
authorRobert Adams2012-09-07 15:46:14 -0700
committerRobert Adams2012-09-07 16:05:28 -0700
commit126eae71009001c5455e4896cf12317422bbac51 (patch)
tree7ceb0c01d5fb352707de447227a308bfe8715c39 /OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs
parentBulletSim: Add some comments (gasp) and log messages. (diff)
downloadopensim-SC-126eae71009001c5455e4896cf12317422bbac51.zip
opensim-SC-126eae71009001c5455e4896cf12317422bbac51.tar.gz
opensim-SC-126eae71009001c5455e4896cf12317422bbac51.tar.bz2
opensim-SC-126eae71009001c5455e4896cf12317422bbac51.tar.xz
BulletSim: Add Bullet body and shape to BSPhysObject and rename
'Body' to 'BSBody' for disambiguation when reading code. Complete the API2 interface so nearly all methods on bullet classes are available to the managed code. The efficient single call simulation step is kept in place while all other creation/destruction/parameterization can be done in the managed code.
Diffstat (limited to '')
-rw-r--r--OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs96
1 files changed, 77 insertions, 19 deletions
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs b/OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs
index 01f231b..6d0af63 100644
--- a/OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs
+++ b/OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs
@@ -96,7 +96,8 @@ public sealed class BSPrim : BSPhysObject
96 long _collidingGroundStep; 96 long _collidingGroundStep;
97 CollisionFlags m_currentCollisionFlags = 0; 97 CollisionFlags m_currentCollisionFlags = 0;
98 98
99 public override BulletBody Body { get; set; } 99 public override BulletBody BSBody { get; set; }
100 public override BulletShape BSShape { get; set; }
100 101
101 private BSDynamics _vehicle; 102 private BSDynamics _vehicle;
102 103
@@ -144,8 +145,9 @@ public sealed class BSPrim : BSPhysObject
144 // Get the pointer to the physical body for this object. 145 // Get the pointer to the physical body for this object.
145 // At the moment, we're still letting BulletSim manage the creation and destruction 146 // At the moment, we're still letting BulletSim manage the creation and destruction
146 // of the object. Someday we'll move that into the C# code. 147 // of the object. Someday we'll move that into the C# code.
147 Body = new BulletBody(LocalID, BulletSimAPI.GetBodyHandle2(_scene.World.Ptr, LocalID)); 148 BSBody = new BulletBody(LocalID, BulletSimAPI.GetBodyHandle2(_scene.World.Ptr, LocalID));
148 m_currentCollisionFlags = BulletSimAPI.GetCollisionFlags2(Body.Ptr); 149 BSShape = new BulletShape(BulletSimAPI.GetCollisionShape2(BSBody.Ptr));
150 m_currentCollisionFlags = BulletSimAPI.GetCollisionFlags2(BSBody.Ptr);
149 }); 151 });
150 } 152 }
151 153
@@ -261,10 +263,10 @@ public sealed class BSPrim : BSPhysObject
261 _rotationalVelocity = OMV.Vector3.Zero; 263 _rotationalVelocity = OMV.Vector3.Zero;
262 264
263 // Zero some other properties directly into the physics engine 265 // Zero some other properties directly into the physics engine
264 BulletSimAPI.SetVelocity2(Body.Ptr, OMV.Vector3.Zero); 266 BulletSimAPI.SetLinearVelocity2(BSBody.Ptr, OMV.Vector3.Zero);
265 BulletSimAPI.SetAngularVelocity2(Body.Ptr, OMV.Vector3.Zero); 267 BulletSimAPI.SetAngularVelocity2(BSBody.Ptr, OMV.Vector3.Zero);
266 BulletSimAPI.SetInterpolation2(Body.Ptr, OMV.Vector3.Zero, OMV.Vector3.Zero); 268 BulletSimAPI.SetInterpolationVelocity2(BSBody.Ptr, OMV.Vector3.Zero, OMV.Vector3.Zero);
267 BulletSimAPI.ClearForces2(Body.Ptr); 269 BulletSimAPI.ClearForces2(BSBody.Ptr);
268 } 270 }
269 271
270 public override void LockAngularMotion(OMV.Vector3 axis) 272 public override void LockAngularMotion(OMV.Vector3 axis)
@@ -327,7 +329,7 @@ public sealed class BSPrim : BSPhysObject
327 { 329 {
328 DetailLog("{0},BSPrim.setForce,taint,force={1}", LocalID, _force); 330 DetailLog("{0},BSPrim.setForce,taint,force={1}", LocalID, _force);
329 // BulletSimAPI.SetObjectForce(_scene.WorldID, _localID, _force); 331 // BulletSimAPI.SetObjectForce(_scene.WorldID, _localID, _force);
330 BulletSimAPI.SetObjectForce2(Body.Ptr, _force); 332 BulletSimAPI.SetObjectForce2(BSBody.Ptr, _force);
331 }); 333 });
332 } 334 }
333 } 335 }
@@ -472,10 +474,11 @@ public sealed class BSPrim : BSPhysObject
472 474
473 // Make gravity work if the object is physical and not selected 475 // Make gravity work if the object is physical and not selected
474 // No locking here because only called when it is safe 476 // No locking here because only called when it is safe
475 // There are three flags we're interested in: 477 // There are four flags we're interested in:
476 // IsStatic: Object does not move, otherwise the object has mass and moves 478 // IsStatic: Object does not move, otherwise the object has mass and moves
477 // isSolid: other objects bounce off of this object 479 // isSolid: other objects bounce off of this object
478 // collisionEvents: whether this object returns collision events 480 // isVolumeDetect: other objects pass through but can generate collisions
481 // collisionEvents: whether this object returns collision events
479 private void SetObjectDynamic() 482 private void SetObjectDynamic()
480 { 483 {
481 // If it's becoming dynamic, it will need hullness 484 // If it's becoming dynamic, it will need hullness
@@ -485,14 +488,68 @@ public sealed class BSPrim : BSPhysObject
485 float mass = IsStatic ? 0f : _mass; 488 float mass = IsStatic ? 0f : _mass;
486 489
487 BulletSimAPI.SetObjectProperties(_scene.WorldID, LocalID, IsStatic, IsSolid, SubscribedEvents(), mass); 490 BulletSimAPI.SetObjectProperties(_scene.WorldID, LocalID, IsStatic, IsSolid, SubscribedEvents(), mass);
488 m_currentCollisionFlags = BulletSimAPI.GetCollisionFlags2(Body.Ptr); 491 /*
492 BulletSimAPI.RemoveObjectFromWorld2(Scene.World.Ptr, BSBody.Ptr);
493
494 // Set up the object physicalness (static or dynamic)
495 MakeDynamic();
496
497 // Make solid or not and arrange for collisions, etc
498 MakeSolid();
489 499
490 // recompute any linkset parameters 500 m_currentCollisionFlags = BulletSimAPI.GetCollisionFlags2(BSBody.Ptr);
501
502 BulletSimAPI.AddObjectToWorld2(Scene.World.Ptr, BSBody.Ptr);
503 */
504
505 // Recompute any linkset parameters.
506 // When going from non-physical to physical, this re-enables the constraints that
507 // had been automatically disabled when the mass was set to zero.
491 Linkset.Refresh(this); 508 Linkset.Refresh(this);
492 509
493 DetailLog("{0},BSPrim.SetObjectDynamic,taint,static={1},solid={2},mass={3}, cf={4}", LocalID, IsStatic, IsSolid, mass, m_currentCollisionFlags); 510 DetailLog("{0},BSPrim.SetObjectDynamic,taint,static={1},solid={2},mass={3}, cf={4}", LocalID, IsStatic, IsSolid, mass, m_currentCollisionFlags);
494 } 511 }
495 512
513 // "Making dynamic" means changing to and from static.
514 // When static, gravity does not effect the object and it is fixed in space.
515 // When dynamic, the object can fall and be pushed by others.
516 // This is independent of its 'solidness' which controls what passes through
517 // this object and what interacts with it.
518 private void MakeDynamic()
519 {
520 if (IsStatic)
521 {
522 // Become a Bullet 'static' object type
523 BulletSimAPI.AddToCollisionFlags2(BSBody.Ptr, CollisionFlags.CF_STATIC_OBJECT);
524 // Stop all movement
525 BulletSimAPI.ClearAllForces2(BSBody.Ptr);
526 // Mass is zero which disables a bunch of physics stuff in Bullet
527 BulletSimAPI.SetMassProps2(BSBody.Ptr, 0f, OMV.Vector3.Zero);
528 // There is no inertia in a static object
529 BulletSimAPI.UpdateInertiaTensor2(BSBody.Ptr);
530 // The activation state is 'sleeping' so Bullet will not try to act on it
531 BulletSimAPI.ForceActivationState2(BSBody.Ptr, ActivationState.ISLAND_SLEEPING);
532 }
533 else
534 {
535 // Not a Bullet static object
536 BulletSimAPI.RemoveFromCollisionFlags2(BSBody.Ptr, CollisionFlags.CF_STATIC_OBJECT);
537 // A dynamic object has mass
538 BulletSimAPI.SetMassProps2(BSBody.Ptr, _mass, OMV.Vector3.Zero);
539 // The shape is interesting and has mass and a center of gravity
540 IntPtr collisionShapePtr = BulletSimAPI.GetCollisionShape2(BSBody.Ptr);
541 BulletSimAPI.CalculateLocalInertia2(collisionShapePtr, _mass, OMV.Vector3.Zero);
542 // Inertia is based on our new mass
543 BulletSimAPI.UpdateInertiaTensor2(BSBody.Ptr);
544 // Force activation of the object so Bullet will act on it.
545 BulletSimAPI.Activate2(BSBody.Ptr, true);
546 }
547 }
548
549 private void MakeSolid()
550 {
551 }
552
496 // prims don't fly 553 // prims don't fly
497 public override bool Flying { 554 public override bool Flying {
498 get { return _flying; } 555 get { return _flying; }
@@ -615,7 +672,7 @@ public sealed class BSPrim : BSPhysObject
615 } 672 }
616 else 673 else
617 { 674 {
618 m_log.WarnFormat("{0}: Got a NaN force applied to a Character", LogHeader); 675 m_log.WarnFormat("{0}: Got a NaN force applied to a prim. LocalID={1}", LogHeader, LocalID);
619 return; 676 return;
620 } 677 }
621 _scene.TaintedObject("BSPrim.AddForce", delegate() 678 _scene.TaintedObject("BSPrim.AddForce", delegate()
@@ -630,7 +687,8 @@ public sealed class BSPrim : BSPhysObject
630 m_accumulatedForces.Clear(); 687 m_accumulatedForces.Clear();
631 } 688 }
632 DetailLog("{0},BSPrim.AddObjectForce,taint,force={1}", LocalID, _force); 689 DetailLog("{0},BSPrim.AddObjectForce,taint,force={1}", LocalID, _force);
633 BulletSimAPI.AddObjectForce2(Body.Ptr, fSum); 690 // For unknown reason, "ApplyCentralForce" is really additive.
691 BulletSimAPI.ApplyCentralForce2(BSBody.Ptr, fSum);
634 }); 692 });
635 } 693 }
636 694
@@ -650,7 +708,7 @@ public sealed class BSPrim : BSPhysObject
650 708
651 Scene.TaintedObject("BSPrim.SubscribeEvents", delegate() 709 Scene.TaintedObject("BSPrim.SubscribeEvents", delegate()
652 { 710 {
653 m_currentCollisionFlags = BulletSimAPI.AddToCollisionFlags2(Body.Ptr, CollisionFlags.BS_SUBSCRIBE_COLLISION_EVENTS); 711 m_currentCollisionFlags = BulletSimAPI.AddToCollisionFlags2(BSBody.Ptr, CollisionFlags.BS_SUBSCRIBE_COLLISION_EVENTS);
654 }); 712 });
655 } 713 }
656 } 714 }
@@ -658,7 +716,7 @@ public sealed class BSPrim : BSPhysObject
658 _subscribedEventsMs = 0; 716 _subscribedEventsMs = 0;
659 Scene.TaintedObject("BSPrim.UnSubscribeEvents", delegate() 717 Scene.TaintedObject("BSPrim.UnSubscribeEvents", delegate()
660 { 718 {
661 m_currentCollisionFlags = BulletSimAPI.RemoveFromCollisionFlags2(Body.Ptr, CollisionFlags.BS_SUBSCRIBE_COLLISION_EVENTS); 719 m_currentCollisionFlags = BulletSimAPI.RemoveFromCollisionFlags2(BSBody.Ptr, CollisionFlags.BS_SUBSCRIBE_COLLISION_EVENTS);
662 }); 720 });
663 } 721 }
664 public override bool SubscribedEvents() { 722 public override bool SubscribedEvents() {
@@ -1243,7 +1301,7 @@ public sealed class BSPrim : BSPhysObject
1243 bool ret = BulletSimAPI.CreateObject(_scene.WorldID, shape); 1301 bool ret = BulletSimAPI.CreateObject(_scene.WorldID, shape);
1244 1302
1245 // the CreateObject() may have recreated the rigid body. Make sure we have the latest. 1303 // the CreateObject() may have recreated the rigid body. Make sure we have the latest.
1246 Body = new BulletBody(LocalID, BulletSimAPI.GetBodyHandle2(_scene.World.Ptr, LocalID)); 1304 BSBody = new BulletBody(LocalID, BulletSimAPI.GetBodyHandle2(_scene.World.Ptr, LocalID));
1247 1305
1248 return ret; 1306 return ret;
1249 } 1307 }