aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs
diff options
context:
space:
mode:
authorRobert Adams2012-12-21 17:27:53 -0800
committerRobert Adams2012-12-21 17:27:53 -0800
commit3d659fe97d79c04983dcfa8c78e9dde1623f54f2 (patch)
tree6333754a97f616a1fdf1de5b91f0358c21a16c83 /OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs
parentBulletSim: repair vehicle problems introduced in previous 'improvements'. Fix... (diff)
downloadopensim-SC_OLD-3d659fe97d79c04983dcfa8c78e9dde1623f54f2.zip
opensim-SC_OLD-3d659fe97d79c04983dcfa8c78e9dde1623f54f2.tar.gz
opensim-SC_OLD-3d659fe97d79c04983dcfa8c78e9dde1623f54f2.tar.bz2
opensim-SC_OLD-3d659fe97d79c04983dcfa8c78e9dde1623f54f2.tar.xz
BulletSim: add BSPhysObject code to manage registrations of preStep events. Use same to implement setForce and setTorque so the values are restored at the beginning of each step (since Bullet zeros forces applied last step). Simplify implementation of AddForce and AddTorque by relying on the addition of forces in Bullet.
Diffstat (limited to 'OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs')
-rw-r--r--OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs112
1 files changed, 49 insertions, 63 deletions
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs b/OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs
index e43bf8e..e6aeebb 100644
--- a/OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs
+++ b/OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs
@@ -129,6 +129,7 @@ public sealed class BSPrim : BSPhysObject
129 public override void Destroy() 129 public override void Destroy()
130 { 130 {
131 // m_log.DebugFormat("{0}: Destroy, id={1}", LogHeader, LocalID); 131 // m_log.DebugFormat("{0}: Destroy, id={1}", LogHeader, LocalID);
132 base.Destroy();
132 133
133 // Undo any links between me and any other object 134 // Undo any links between me and any other object
134 BSPhysObject parentBefore = Linkset.LinksetRoot; 135 BSPhysObject parentBefore = Linkset.LinksetRoot;
@@ -434,12 +435,22 @@ public sealed class BSPrim : BSPhysObject
434 get { return _force; } 435 get { return _force; }
435 set { 436 set {
436 _force = value; 437 _force = value;
437 PhysicsScene.TaintedObject("BSPrim.setForce", delegate() 438 if (_force != OMV.Vector3.Zero)
438 { 439 {
439 // DetailLog("{0},BSPrim.setForce,taint,force={1}", LocalID, _force); 440 // If the force is non-zero, it must be reapplied each tick because
440 if (PhysBody.HasPhysicalBody) 441 // Bullet clears the forces applied last frame.
441 BulletSimAPI.SetObjectForce2(PhysBody.ptr, _force); 442 RegisterPreStepAction("BSPrim.setForce", LocalID,
442 }); 443 delegate(float timeStep)
444 {
445 if (PhysBody.HasPhysicalBody)
446 BulletSimAPI.ApplyCentralForce2(PhysBody.ptr, _force);
447 }
448 );
449 }
450 else
451 {
452 UnRegisterPreStepAction("BSPrim.setForce", LocalID);
453 }
443 } 454 }
444 } 455 }
445 456
@@ -550,7 +561,22 @@ public sealed class BSPrim : BSPhysObject
550 get { return _torque; } 561 get { return _torque; }
551 set { 562 set {
552 _torque = value; 563 _torque = value;
553 AddAngularForce(_torque, false, false); 564 if (_torque != OMV.Vector3.Zero)
565 {
566 // If the torque is non-zero, it must be reapplied each tick because
567 // Bullet clears the forces applied last frame.
568 RegisterPreStepAction("BSPrim.setTorque", LocalID,
569 delegate(float timeStep)
570 {
571 if (PhysBody.HasPhysicalBody)
572 AddAngularForce(_torque, false, true);
573 }
574 );
575 }
576 else
577 {
578 UnRegisterPreStepAction("BSPrim.setTorque", LocalID);
579 }
554 // DetailLog("{0},BSPrim.SetTorque,call,torque={1}", LocalID, _torque); 580 // DetailLog("{0},BSPrim.SetTorque,call,torque={1}", LocalID, _torque);
555 } 581 }
556 } 582 }
@@ -969,56 +995,32 @@ public sealed class BSPrim : BSPhysObject
969 public override float APIDStrength { set { return; } } 995 public override float APIDStrength { set { return; } }
970 public override float APIDDamping { set { return; } } 996 public override float APIDDamping { set { return; } }
971 997
972 private List<OMV.Vector3> m_accumulatedForces = new List<OMV.Vector3>();
973 public override void AddForce(OMV.Vector3 force, bool pushforce) { 998 public override void AddForce(OMV.Vector3 force, bool pushforce) {
974 AddForce(force, pushforce, false); 999 AddForce(force, pushforce, false);
975 } 1000 }
976 // Applying a force just adds this to the total force on the object. 1001 // Applying a force just adds this to the total force on the object.
1002 // This added force will only last the next simulation tick.
977 public void AddForce(OMV.Vector3 force, bool pushforce, bool inTaintTime) { 1003 public void AddForce(OMV.Vector3 force, bool pushforce, bool inTaintTime) {
978 // for an object, doesn't matter if force is a pushforce or not 1004 // for an object, doesn't matter if force is a pushforce or not
979 if (force.IsFinite()) 1005 if (force.IsFinite())
980 { 1006 {
981 // _force += force; 1007 OMV.Vector3 addForce = force;
982 lock (m_accumulatedForces) 1008 DetailLog("{0},BSPrim.addForce,call,force={1}", LocalID, addForce);
983 m_accumulatedForces.Add(new OMV.Vector3(force)); 1009 PhysicsScene.TaintedObject(inTaintTime, "BSPrim.AddForce", delegate()
1010 {
1011 // Bullet adds this central force to the total force for this tick
1012 DetailLog("{0},BSPrim.addForce,taint,force={1}", LocalID, addForce);
1013 if (PhysBody.HasPhysicalBody)
1014 BulletSimAPI.ApplyCentralForce2(PhysBody.ptr, addForce);
1015 });
984 } 1016 }
985 else 1017 else
986 { 1018 {
987 m_log.WarnFormat("{0}: Got a NaN force applied to a prim. LocalID={1}", LogHeader, LocalID); 1019 m_log.WarnFormat("{0}: Got a NaN force applied to a prim. LocalID={1}", LogHeader, LocalID);
988 return; 1020 return;
989 } 1021 }
990 PhysicsScene.TaintedObject(inTaintTime, "BSPrim.AddForce", delegate()
991 {
992 OMV.Vector3 fSum = OMV.Vector3.Zero;
993 lock (m_accumulatedForces)
994 {
995 // Sum the accumulated additional forces for one big force to apply once.
996 foreach (OMV.Vector3 v in m_accumulatedForces)
997 {
998 fSum += v;
999 }
1000 m_accumulatedForces.Clear();
1001 }
1002 DetailLog("{0},BSPrim.AddForce,taint,force={1}", LocalID, fSum);
1003 if (fSum != OMV.Vector3.Zero)
1004 if (PhysBody.HasPhysicalBody)
1005 BulletSimAPI.ApplyCentralForce2(PhysBody.ptr, fSum);
1006 });
1007 } 1022 }
1008 1023
1009 // An impulse force is scaled by the mass of the object.
1010 public void ApplyForceImpulse(OMV.Vector3 impulse, bool inTaintTime)
1011 {
1012 OMV.Vector3 applyImpulse = impulse;
1013 PhysicsScene.TaintedObject(inTaintTime, "BSPrim.ApplyForceImpulse", delegate()
1014 {
1015 DetailLog("{0},BSPrim.ApplyForceImpulse,taint,tImpulse={1}", LocalID, applyImpulse);
1016 if (PhysBody.HasPhysicalBody)
1017 BulletSimAPI.ApplyCentralImpulse2(PhysBody.ptr, applyImpulse);
1018 });
1019 }
1020
1021 private List<OMV.Vector3> m_accumulatedAngularForces = new List<OMV.Vector3>();
1022 public override void AddAngularForce(OMV.Vector3 force, bool pushforce) { 1024 public override void AddAngularForce(OMV.Vector3 force, bool pushforce) {
1023 AddAngularForce(force, pushforce, false); 1025 AddAngularForce(force, pushforce, false);
1024 } 1026 }
@@ -1026,36 +1028,20 @@ public sealed class BSPrim : BSPhysObject
1026 { 1028 {
1027 if (force.IsFinite()) 1029 if (force.IsFinite())
1028 { 1030 {
1029 // _force += force; 1031 OMV.Vector3 angForce = force;
1030 lock (m_accumulatedAngularForces) 1032 PhysicsScene.TaintedObject(inTaintTime, "BSPrim.AddAngularForce", delegate()
1031 m_accumulatedAngularForces.Add(new OMV.Vector3(force)); 1033 {
1034 if (PhysBody.HasPhysicalBody)
1035 BulletSimAPI.ApplyTorque2(PhysBody.ptr, angForce);
1036 });
1032 } 1037 }
1033 else 1038 else
1034 { 1039 {
1035 m_log.WarnFormat("{0}: Got a NaN force applied to a prim. LocalID={1}", LogHeader, LocalID); 1040 m_log.WarnFormat("{0}: Got a NaN force applied to a prim. LocalID={1}", LogHeader, LocalID);
1036 return; 1041 return;
1037 } 1042 }
1038 PhysicsScene.TaintedObject(inTaintTime, "BSPrim.AddAngularForce", delegate()
1039 {
1040 OMV.Vector3 fSum = OMV.Vector3.Zero;
1041 lock (m_accumulatedAngularForces)
1042 {
1043 // Sum the accumulated additional forces for one big force to apply once.
1044 foreach (OMV.Vector3 v in m_accumulatedAngularForces)
1045 {
1046 fSum += v;
1047 }
1048 m_accumulatedAngularForces.Clear();
1049 }
1050 DetailLog("{0},BSPrim.AddAngularForce,taint,aForce={1}", LocalID, fSum);
1051 if (fSum != OMV.Vector3.Zero)
1052 {
1053 if (PhysBody.HasPhysicalBody)
1054 BulletSimAPI.ApplyTorque2(PhysBody.ptr, fSum);
1055 _torque = fSum;
1056 }
1057 });
1058 } 1043 }
1044
1059 // A torque impulse. 1045 // A torque impulse.
1060 // ApplyTorqueImpulse adds torque directly to the angularVelocity. 1046 // ApplyTorqueImpulse adds torque directly to the angularVelocity.
1061 // AddAngularForce accumulates the force and applied it to the angular velocity all at once. 1047 // AddAngularForce accumulates the force and applied it to the angular velocity all at once.