aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs62
1 files changed, 50 insertions, 12 deletions
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs b/OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs
index f7b68ba..6a4365c 100644
--- a/OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs
+++ b/OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs
@@ -196,7 +196,7 @@ public sealed class BSPrim : BSPhysObject
196 _isSelected = value; 196 _isSelected = value;
197 PhysicsScene.TaintedObject("BSPrim.setSelected", delegate() 197 PhysicsScene.TaintedObject("BSPrim.setSelected", delegate()
198 { 198 {
199 // DetailLog("{0},BSPrim.selected,taint,selected={1}", LocalID, _isSelected); 199 DetailLog("{0},BSPrim.selected,taint,selected={1}", LocalID, _isSelected);
200 SetObjectDynamic(false); 200 SetObjectDynamic(false);
201 }); 201 });
202 } 202 }
@@ -265,6 +265,11 @@ public sealed class BSPrim : BSPhysObject
265 return _position; 265 return _position;
266 } 266 }
267 set { 267 set {
268 // If you must push the position into the physics engine, use ForcePosition.
269 if (_position == value)
270 {
271 return;
272 }
268 _position = value; 273 _position = value;
269 // TODO: what does it mean to set the position of a child prim?? Rebuild the constraint? 274 // TODO: what does it mean to set the position of a child prim?? Rebuild the constraint?
270 PositionSanityCheck(); 275 PositionSanityCheck();
@@ -322,7 +327,7 @@ public sealed class BSPrim : BSPhysObject
322 // A version of the sanity check that also makes sure a new position value is 327 // A version of the sanity check that also makes sure a new position value is
323 // pushed back to the physics engine. This routine would be used by anyone 328 // pushed back to the physics engine. This routine would be used by anyone
324 // who is not already pushing the value. 329 // who is not already pushing the value.
325 private bool PositionSanityCheck2(bool atTaintTime) 330 private bool PositionSanityCheck2(bool inTaintTime)
326 { 331 {
327 bool ret = false; 332 bool ret = false;
328 if (PositionSanityCheck()) 333 if (PositionSanityCheck())
@@ -334,7 +339,7 @@ public sealed class BSPrim : BSPhysObject
334 DetailLog("{0},BSPrim.PositionSanityCheck,taint,pos={1},orient={2}", LocalID, _position, _orientation); 339 DetailLog("{0},BSPrim.PositionSanityCheck,taint,pos={1},orient={2}", LocalID, _position, _orientation);
335 BulletSimAPI.SetObjectTranslation(PhysicsScene.WorldID, LocalID, _position, _orientation); 340 BulletSimAPI.SetObjectTranslation(PhysicsScene.WorldID, LocalID, _position, _orientation);
336 }; 341 };
337 if (atTaintTime) 342 if (inTaintTime)
338 sanityOperation(); 343 sanityOperation();
339 else 344 else
340 PhysicsScene.TaintedObject("BSPrim.PositionSanityCheck", sanityOperation); 345 PhysicsScene.TaintedObject("BSPrim.PositionSanityCheck", sanityOperation);
@@ -453,7 +458,6 @@ public sealed class BSPrim : BSPhysObject
453 } 458 }
454 return; 459 return;
455 } 460 }
456
457 public override OMV.Vector3 Velocity { 461 public override OMV.Vector3 Velocity {
458 get { return _velocity; } 462 get { return _velocity; }
459 set { 463 set {
@@ -465,6 +469,13 @@ public sealed class BSPrim : BSPhysObject
465 }); 469 });
466 } 470 }
467 } 471 }
472 public override OMV.Vector3 ForceVelocity {
473 get { return _velocity; }
474 set {
475 _velocity = value;
476 BulletSimAPI.SetLinearVelocity2(BSBody.ptr, _velocity);
477 }
478 }
468 public override OMV.Vector3 Torque { 479 public override OMV.Vector3 Torque {
469 get { return _torque; } 480 get { return _torque; }
470 set { _torque = value; 481 set { _torque = value;
@@ -490,6 +501,8 @@ public sealed class BSPrim : BSPhysObject
490 return _orientation; 501 return _orientation;
491 } 502 }
492 set { 503 set {
504 if (_orientation == value)
505 return;
493 _orientation = value; 506 _orientation = value;
494 // TODO: what does it mean if a child in a linkset changes its orientation? Rebuild the constraint? 507 // TODO: what does it mean if a child in a linkset changes its orientation? Rebuild the constraint?
495 PhysicsScene.TaintedObject("BSPrim.setOrientation", delegate() 508 PhysicsScene.TaintedObject("BSPrim.setOrientation", delegate()
@@ -570,7 +583,7 @@ public sealed class BSPrim : BSPhysObject
570 // Set up the object physicalness (does gravity and collisions move this object) 583 // Set up the object physicalness (does gravity and collisions move this object)
571 MakeDynamic(IsStatic); 584 MakeDynamic(IsStatic);
572 585
573 // Update vehicle specific parameters 586 // Update vehicle specific parameters (after MakeDynamic() so can change physical parameters)
574 _vehicle.Refresh(); 587 _vehicle.Refresh();
575 588
576 // Arrange for collision events if the simulator wants them 589 // Arrange for collision events if the simulator wants them
@@ -593,7 +606,7 @@ public sealed class BSPrim : BSPhysObject
593 // Recompute any linkset parameters. 606 // Recompute any linkset parameters.
594 // When going from non-physical to physical, this re-enables the constraints that 607 // When going from non-physical to physical, this re-enables the constraints that
595 // had been automatically disabled when the mass was set to zero. 608 // had been automatically disabled when the mass was set to zero.
596 Linkset.Refresh(this); 609 Linkset.Refresh(this, true);
597 610
598 DetailLog("{0},BSPrim.UpdatePhysicalParameters,exit,static={1},solid={2},mass={3},collide={4},cf={5:X},body={6},shape={7}", 611 DetailLog("{0},BSPrim.UpdatePhysicalParameters,exit,static={1},solid={2},mass={3},collide={4},cf={5:X},body={6},shape={7}",
599 LocalID, IsStatic, IsSolid, _mass, SubscribedEvents(), CurrentCollisionFlags, BSBody, BSShape); 612 LocalID, IsStatic, IsSolid, _mass, SubscribedEvents(), CurrentCollisionFlags, BSBody, BSShape);
@@ -620,8 +633,10 @@ public sealed class BSPrim : BSPhysObject
620 BulletSimAPI.UpdateInertiaTensor2(BSBody.ptr); 633 BulletSimAPI.UpdateInertiaTensor2(BSBody.ptr);
621 // There can be special things needed for implementing linksets 634 // There can be special things needed for implementing linksets
622 Linkset.MakeStatic(this); 635 Linkset.MakeStatic(this);
623 // The activation state is 'disabled' so Bullet will not try to act on it 636 // The activation state is 'disabled' so Bullet will not try to act on it.
624 BulletSimAPI.ForceActivationState2(BSBody.ptr, ActivationState.DISABLE_SIMULATION); 637 BulletSimAPI.ForceActivationState2(BSBody.ptr, ActivationState.DISABLE_SIMULATION);
638 // Start it out sleeping and physical actions could wake it up.
639 // BulletSimAPI.ForceActivationState2(BSBody.ptr, ActivationState.ISLAND_SLEEPING);
625 640
626 BSBody.collisionFilter = CollisionFilterGroups.StaticObjectFilter; 641 BSBody.collisionFilter = CollisionFilterGroups.StaticObjectFilter;
627 BSBody.collisionMask = CollisionFilterGroups.StaticObjectMask; 642 BSBody.collisionMask = CollisionFilterGroups.StaticObjectMask;
@@ -638,6 +653,9 @@ public sealed class BSPrim : BSPhysObject
638 // per http://www.bulletphysics.org/Bullet/phpBB3/viewtopic.php?t=3382 653 // per http://www.bulletphysics.org/Bullet/phpBB3/viewtopic.php?t=3382
639 BulletSimAPI.ClearAllForces2(BSBody.ptr); 654 BulletSimAPI.ClearAllForces2(BSBody.ptr);
640 655
656 // For good measure, make sure the transform is set through to the motion state
657 BulletSimAPI.SetTranslation2(BSBody.ptr, _position, _orientation);
658
641 // A dynamic object has mass 659 // A dynamic object has mass
642 IntPtr collisionShapePtr = BulletSimAPI.GetCollisionShape2(BSBody.ptr); 660 IntPtr collisionShapePtr = BulletSimAPI.GetCollisionShape2(BSBody.ptr);
643 OMV.Vector3 inertia = BulletSimAPI.CalculateLocalInertia2(collisionShapePtr, Mass); 661 OMV.Vector3 inertia = BulletSimAPI.CalculateLocalInertia2(collisionShapePtr, Mass);
@@ -655,8 +673,8 @@ public sealed class BSPrim : BSPhysObject
655 673
656 // Force activation of the object so Bullet will act on it. 674 // Force activation of the object so Bullet will act on it.
657 // Must do the ForceActivationState2() to overcome the DISABLE_SIMULATION from static objects. 675 // Must do the ForceActivationState2() to overcome the DISABLE_SIMULATION from static objects.
658 BulletSimAPI.ForceActivationState2(BSBody.ptr, ActivationState.ISLAND_SLEEPING); 676 BulletSimAPI.ForceActivationState2(BSBody.ptr, ActivationState.ACTIVE_TAG);
659 BulletSimAPI.Activate2(BSBody.ptr, true); 677 // BulletSimAPI.Activate2(BSBody.ptr, true);
660 678
661 BSBody.collisionFilter = CollisionFilterGroups.ObjectFilter; 679 BSBody.collisionFilter = CollisionFilterGroups.ObjectFilter;
662 BSBody.collisionMask = CollisionFilterGroups.ObjectMask; 680 BSBody.collisionMask = CollisionFilterGroups.ObjectMask;
@@ -774,6 +792,15 @@ public sealed class BSPrim : BSPhysObject
774 }); 792 });
775 } 793 }
776 } 794 }
795 public override OMV.Vector3 ForceRotationalVelocity {
796 get {
797 return _rotationalVelocity;
798 }
799 set {
800 _rotationalVelocity = value;
801 BulletSimAPI.SetAngularVelocity2(BSBody.ptr, _rotationalVelocity);
802 }
803 }
777 public override bool Kinematic { 804 public override bool Kinematic {
778 get { return _kinematic; } 805 get { return _kinematic; }
779 set { _kinematic = value; 806 set { _kinematic = value;
@@ -828,6 +855,9 @@ public sealed class BSPrim : BSPhysObject
828 855
829 private List<OMV.Vector3> m_accumulatedForces = new List<OMV.Vector3>(); 856 private List<OMV.Vector3> m_accumulatedForces = new List<OMV.Vector3>();
830 public override void AddForce(OMV.Vector3 force, bool pushforce) { 857 public override void AddForce(OMV.Vector3 force, bool pushforce) {
858 AddForce(force, pushforce, false);
859 }
860 public void AddForce(OMV.Vector3 force, bool pushforce, bool inTaintTime) {
831 // for an object, doesn't matter if force is a pushforce or not 861 // for an object, doesn't matter if force is a pushforce or not
832 if (force.IsFinite()) 862 if (force.IsFinite())
833 { 863 {
@@ -840,11 +870,12 @@ public sealed class BSPrim : BSPhysObject
840 m_log.WarnFormat("{0}: Got a NaN force applied to a prim. LocalID={1}", LogHeader, LocalID); 870 m_log.WarnFormat("{0}: Got a NaN force applied to a prim. LocalID={1}", LogHeader, LocalID);
841 return; 871 return;
842 } 872 }
843 PhysicsScene.TaintedObject("BSPrim.AddForce", delegate() 873 BSScene.TaintCallback addForceOperation = delegate()
844 { 874 {
845 OMV.Vector3 fSum = OMV.Vector3.Zero; 875 OMV.Vector3 fSum = OMV.Vector3.Zero;
846 lock (m_accumulatedForces) 876 lock (m_accumulatedForces)
847 { 877 {
878 // Sum the accumulated additional forces for one big force to apply once.
848 foreach (OMV.Vector3 v in m_accumulatedForces) 879 foreach (OMV.Vector3 v in m_accumulatedForces)
849 { 880 {
850 fSum += v; 881 fSum += v;
@@ -854,7 +885,11 @@ public sealed class BSPrim : BSPhysObject
854 // DetailLog("{0},BSPrim.AddObjectForce,taint,force={1}", LocalID, fSum); 885 // DetailLog("{0},BSPrim.AddObjectForce,taint,force={1}", LocalID, fSum);
855 // For unknown reasons, "ApplyCentralForce" adds this force to the total force on the object. 886 // For unknown reasons, "ApplyCentralForce" adds this force to the total force on the object.
856 BulletSimAPI.ApplyCentralForce2(BSBody.ptr, fSum); 887 BulletSimAPI.ApplyCentralForce2(BSBody.ptr, fSum);
857 }); 888 };
889 if (inTaintTime)
890 addForceOperation();
891 else
892 PhysicsScene.TaintedObject("BSPrim.AddForce", addForceOperation);
858 } 893 }
859 894
860 public override void AddAngularForce(OMV.Vector3 force, bool pushforce) { 895 public override void AddAngularForce(OMV.Vector3 force, bool pushforce) {
@@ -1204,6 +1239,7 @@ public sealed class BSPrim : BSPhysObject
1204 { 1239 {
1205 // Called if the current prim body is about to be destroyed. 1240 // Called if the current prim body is about to be destroyed.
1206 // Remove all the physical dependencies on the old body. 1241 // Remove all the physical dependencies on the old body.
1242 // (Maybe someday make the changing of BSShape an event handled by BSLinkset.)
1207 needToRestoreLinkset = Linkset.RemoveBodyDependencies(this); 1243 needToRestoreLinkset = Linkset.RemoveBodyDependencies(this);
1208 }); 1244 });
1209 1245
@@ -1294,6 +1330,8 @@ public sealed class BSPrim : BSPhysObject
1294 1330
1295 PositionSanityCheck2(true); 1331 PositionSanityCheck2(true);
1296 1332
1333 Linkset.UpdateProperties(this);
1334
1297 DetailLog("{0},BSPrim.UpdateProperties,call,pos={1},orient={2},vel={3},accel={4},rotVel={5}", 1335 DetailLog("{0},BSPrim.UpdateProperties,call,pos={1},orient={2},vel={3},accel={4},rotVel={5}",
1298 LocalID, _position, _orientation, _velocity, _acceleration, _rotationalVelocity); 1336 LocalID, _position, _orientation, _velocity, _acceleration, _rotationalVelocity);
1299 1337
@@ -1304,7 +1342,7 @@ public sealed class BSPrim : BSPhysObject
1304 /* 1342 /*
1305 else 1343 else
1306 { 1344 {
1307 // For debugging, we can also report the movement of children 1345 // For debugging, report the movement of children
1308 DetailLog("{0},BSPrim.UpdateProperties,child,pos={1},orient={2},vel={3},accel={4},rotVel={5}", 1346 DetailLog("{0},BSPrim.UpdateProperties,child,pos={1},orient={2},vel={3},accel={4},rotVel={5}",
1309 LocalID, entprop.Position, entprop.Rotation, entprop.Velocity, 1347 LocalID, entprop.Position, entprop.Rotation, entprop.Velocity,
1310 entprop.Acceleration, entprop.RotationalVelocity); 1348 entprop.Acceleration, entprop.RotationalVelocity);