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.cs98
1 files changed, 81 insertions, 17 deletions
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs b/OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs
index 6bfce5c..6d0af63 100644
--- a/OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs
+++ b/OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs
@@ -94,8 +94,10 @@ public sealed class BSPrim : BSPhysObject
94 private int _nextCollisionOkTime = 0; 94 private int _nextCollisionOkTime = 0;
95 long _collidingStep; 95 long _collidingStep;
96 long _collidingGroundStep; 96 long _collidingGroundStep;
97 CollisionFlags m_currentCollisionFlags = 0;
97 98
98 public override BulletBody Body { get; set; } 99 public override BulletBody BSBody { get; set; }
100 public override BulletShape BSShape { get; set; }
99 101
100 private BSDynamics _vehicle; 102 private BSDynamics _vehicle;
101 103
@@ -113,6 +115,7 @@ public sealed class BSPrim : BSPhysObject
113 // m_log.DebugFormat("{0}: BSPrim creation of {1}, id={2}", LogHeader, primName, localID); 115 // m_log.DebugFormat("{0}: BSPrim creation of {1}, id={2}", LogHeader, primName, localID);
114 _localID = localID; 116 _localID = localID;
115 _avName = primName; 117 _avName = primName;
118 _physicsActorType = (int)ActorTypes.Prim;
116 _scene = parent_scene; 119 _scene = parent_scene;
117 _position = pos; 120 _position = pos;
118 _size = size; 121 _size = size;
@@ -142,7 +145,9 @@ public sealed class BSPrim : BSPhysObject
142 // Get the pointer to the physical body for this object. 145 // Get the pointer to the physical body for this object.
143 // 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
144 // 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.
145 Body = new BulletBody(LocalID, BulletSimAPI.GetBodyHandle2(_scene.World.Ptr, LocalID)); 148 BSBody = new BulletBody(LocalID, BulletSimAPI.GetBodyHandle2(_scene.World.Ptr, LocalID));
149 BSShape = new BulletShape(BulletSimAPI.GetCollisionShape2(BSBody.Ptr));
150 m_currentCollisionFlags = BulletSimAPI.GetCollisionFlags2(BSBody.Ptr);
146 }); 151 });
147 } 152 }
148 153
@@ -258,10 +263,10 @@ public sealed class BSPrim : BSPhysObject
258 _rotationalVelocity = OMV.Vector3.Zero; 263 _rotationalVelocity = OMV.Vector3.Zero;
259 264
260 // Zero some other properties directly into the physics engine 265 // Zero some other properties directly into the physics engine
261 BulletSimAPI.SetVelocity2(Body.Ptr, OMV.Vector3.Zero); 266 BulletSimAPI.SetLinearVelocity2(BSBody.Ptr, OMV.Vector3.Zero);
262 BulletSimAPI.SetAngularVelocity2(Body.Ptr, OMV.Vector3.Zero); 267 BulletSimAPI.SetAngularVelocity2(BSBody.Ptr, OMV.Vector3.Zero);
263 BulletSimAPI.SetInterpolation2(Body.Ptr, OMV.Vector3.Zero, OMV.Vector3.Zero); 268 BulletSimAPI.SetInterpolationVelocity2(BSBody.Ptr, OMV.Vector3.Zero, OMV.Vector3.Zero);
264 BulletSimAPI.ClearForces2(Body.Ptr); 269 BulletSimAPI.ClearForces2(BSBody.Ptr);
265 } 270 }
266 271
267 public override void LockAngularMotion(OMV.Vector3 axis) 272 public override void LockAngularMotion(OMV.Vector3 axis)
@@ -324,7 +329,7 @@ public sealed class BSPrim : BSPhysObject
324 { 329 {
325 DetailLog("{0},BSPrim.setForce,taint,force={1}", LocalID, _force); 330 DetailLog("{0},BSPrim.setForce,taint,force={1}", LocalID, _force);
326 // BulletSimAPI.SetObjectForce(_scene.WorldID, _localID, _force); 331 // BulletSimAPI.SetObjectForce(_scene.WorldID, _localID, _force);
327 BulletSimAPI.SetObjectForce2(Body.Ptr, _force); 332 BulletSimAPI.SetObjectForce2(BSBody.Ptr, _force);
328 }); 333 });
329 } 334 }
330 } 335 }
@@ -442,8 +447,7 @@ public sealed class BSPrim : BSPhysObject
442 } 447 }
443 public override int PhysicsActorType { 448 public override int PhysicsActorType {
444 get { return _physicsActorType; } 449 get { return _physicsActorType; }
445 set { _physicsActorType = value; 450 set { _physicsActorType = value; }
446 }
447 } 451 }
448 public override bool IsPhysical { 452 public override bool IsPhysical {
449 get { return _isPhysical; } 453 get { return _isPhysical; }
@@ -470,6 +474,11 @@ public sealed class BSPrim : BSPhysObject
470 474
471 // Make gravity work if the object is physical and not selected 475 // Make gravity work if the object is physical and not selected
472 // No locking here because only called when it is safe 476 // No locking here because only called when it is safe
477 // There are four flags we're interested in:
478 // IsStatic: Object does not move, otherwise the object has mass and moves
479 // isSolid: other objects bounce off of this object
480 // isVolumeDetect: other objects pass through but can generate collisions
481 // collisionEvents: whether this object returns collision events
473 private void SetObjectDynamic() 482 private void SetObjectDynamic()
474 { 483 {
475 // If it's becoming dynamic, it will need hullness 484 // If it's becoming dynamic, it will need hullness
@@ -479,12 +488,66 @@ public sealed class BSPrim : BSPhysObject
479 float mass = IsStatic ? 0f : _mass; 488 float mass = IsStatic ? 0f : _mass;
480 489
481 BulletSimAPI.SetObjectProperties(_scene.WorldID, LocalID, IsStatic, IsSolid, SubscribedEvents(), mass); 490 BulletSimAPI.SetObjectProperties(_scene.WorldID, LocalID, IsStatic, IsSolid, SubscribedEvents(), mass);
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();
499
500 m_currentCollisionFlags = BulletSimAPI.GetCollisionFlags2(BSBody.Ptr);
482 501
483 // recompute any linkset parameters 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.
484 Linkset.Refresh(this); 508 Linkset.Refresh(this);
485 509
486 CollisionFlags cf = BulletSimAPI.GetCollisionFlags2(Body.Ptr); 510 DetailLog("{0},BSPrim.SetObjectDynamic,taint,static={1},solid={2},mass={3}, cf={4}", LocalID, IsStatic, IsSolid, mass, m_currentCollisionFlags);
487 DetailLog("{0},BSPrim.SetObjectDynamic,taint,static={1},solid={2},mass={3}, cf={4}", LocalID, IsStatic, IsSolid, mass, cf); 511 }
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 {
488 } 551 }
489 552
490 // prims don't fly 553 // prims don't fly
@@ -609,7 +672,7 @@ public sealed class BSPrim : BSPhysObject
609 } 672 }
610 else 673 else
611 { 674 {
612 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);
613 return; 676 return;
614 } 677 }
615 _scene.TaintedObject("BSPrim.AddForce", delegate() 678 _scene.TaintedObject("BSPrim.AddForce", delegate()
@@ -624,7 +687,8 @@ public sealed class BSPrim : BSPhysObject
624 m_accumulatedForces.Clear(); 687 m_accumulatedForces.Clear();
625 } 688 }
626 DetailLog("{0},BSPrim.AddObjectForce,taint,force={1}", LocalID, _force); 689 DetailLog("{0},BSPrim.AddObjectForce,taint,force={1}", LocalID, _force);
627 BulletSimAPI.AddObjectForce2(Body.Ptr, fSum); 690 // For unknown reason, "ApplyCentralForce" is really additive.
691 BulletSimAPI.ApplyCentralForce2(BSBody.Ptr, fSum);
628 }); 692 });
629 } 693 }
630 694
@@ -644,7 +708,7 @@ public sealed class BSPrim : BSPhysObject
644 708
645 Scene.TaintedObject("BSPrim.SubscribeEvents", delegate() 709 Scene.TaintedObject("BSPrim.SubscribeEvents", delegate()
646 { 710 {
647 BulletSimAPI.AddToCollisionFlags2(Body.Ptr, CollisionFlags.BS_SUBSCRIBE_COLLISION_EVENTS); 711 m_currentCollisionFlags = BulletSimAPI.AddToCollisionFlags2(BSBody.Ptr, CollisionFlags.BS_SUBSCRIBE_COLLISION_EVENTS);
648 }); 712 });
649 } 713 }
650 } 714 }
@@ -652,7 +716,7 @@ public sealed class BSPrim : BSPhysObject
652 _subscribedEventsMs = 0; 716 _subscribedEventsMs = 0;
653 Scene.TaintedObject("BSPrim.UnSubscribeEvents", delegate() 717 Scene.TaintedObject("BSPrim.UnSubscribeEvents", delegate()
654 { 718 {
655 BulletSimAPI.RemoveFromCollisionFlags2(Body.Ptr, CollisionFlags.BS_SUBSCRIBE_COLLISION_EVENTS); 719 m_currentCollisionFlags = BulletSimAPI.RemoveFromCollisionFlags2(BSBody.Ptr, CollisionFlags.BS_SUBSCRIBE_COLLISION_EVENTS);
656 }); 720 });
657 } 721 }
658 public override bool SubscribedEvents() { 722 public override bool SubscribedEvents() {
@@ -1237,7 +1301,7 @@ public sealed class BSPrim : BSPhysObject
1237 bool ret = BulletSimAPI.CreateObject(_scene.WorldID, shape); 1301 bool ret = BulletSimAPI.CreateObject(_scene.WorldID, shape);
1238 1302
1239 // 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.
1240 Body = new BulletBody(LocalID, BulletSimAPI.GetBodyHandle2(_scene.World.Ptr, LocalID)); 1304 BSBody = new BulletBody(LocalID, BulletSimAPI.GetBodyHandle2(_scene.World.Ptr, LocalID));
1241 1305
1242 return ret; 1306 return ret;
1243 } 1307 }