aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/Physics/BulletSPlugin/BSDynamics.cs
diff options
context:
space:
mode:
authorRobert Adams2012-11-25 17:41:15 -0800
committerRobert Adams2012-11-25 20:04:31 -0800
commit319ec3235c69bb207fe04415feb8bc9f90601f37 (patch)
treeb95ad900f5bc2a0ff96b539e8d2ccc38913d7978 /OpenSim/Region/Physics/BulletSPlugin/BSDynamics.cs
parentBulletSim: update DLLs and SOs with new collision margin setting function. (diff)
downloadopensim-SC-319ec3235c69bb207fe04415feb8bc9f90601f37.zip
opensim-SC-319ec3235c69bb207fe04415feb8bc9f90601f37.tar.gz
opensim-SC-319ec3235c69bb207fe04415feb8bc9f90601f37.tar.bz2
opensim-SC-319ec3235c69bb207fe04415feb8bc9f90601f37.tar.xz
BulletSim: add BSVMotor as BSDynamics linear motor.
Properly limit *_MOTOR_DECAY_TIMESCALE to 120 as per specs. Invode BSDynamics.Refresh() when vehicle type is changed. Previously the vehicle properties weren't getting set because the physical properties were set before the vehicle type was set. Add a "use name" to BSMotors for identification while debugging. Correct current and target confusion in BSVMotor design. Rename CurrentValueReductionTimescale to FrictionTimescale. Event more detailed logging.
Diffstat (limited to 'OpenSim/Region/Physics/BulletSPlugin/BSDynamics.cs')
-rw-r--r--OpenSim/Region/Physics/BulletSPlugin/BSDynamics.cs55
1 files changed, 42 insertions, 13 deletions
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSDynamics.cs b/OpenSim/Region/Physics/BulletSPlugin/BSDynamics.cs
index 7fd7b82..bf8a004 100644
--- a/OpenSim/Region/Physics/BulletSPlugin/BSDynamics.cs
+++ b/OpenSim/Region/Physics/BulletSPlugin/BSDynamics.cs
@@ -80,6 +80,7 @@ namespace OpenSim.Region.Physics.BulletSPlugin
80 private Quaternion m_referenceFrame = Quaternion.Identity; 80 private Quaternion m_referenceFrame = Quaternion.Identity;
81 81
82 // Linear properties 82 // Linear properties
83 private BSVMotor m_linearMotor = new BSVMotor("LinearMotor");
83 private Vector3 m_linearMotorDirection = Vector3.Zero; // velocity requested by LSL, decayed by time 84 private Vector3 m_linearMotorDirection = Vector3.Zero; // velocity requested by LSL, decayed by time
84 private Vector3 m_linearMotorOffset = Vector3.Zero; // the point of force can be offset from the center 85 private Vector3 m_linearMotorOffset = Vector3.Zero; // the point of force can be offset from the center
85 private Vector3 m_linearMotorDirectionLASTSET = Vector3.Zero; // velocity requested by LSL 86 private Vector3 m_linearMotorDirectionLASTSET = Vector3.Zero; // velocity requested by LSL
@@ -152,7 +153,7 @@ namespace OpenSim.Region.Physics.BulletSPlugin
152 m_angularDeflectionTimescale = Math.Max(pValue, 0.01f); 153 m_angularDeflectionTimescale = Math.Max(pValue, 0.01f);
153 break; 154 break;
154 case Vehicle.ANGULAR_MOTOR_DECAY_TIMESCALE: 155 case Vehicle.ANGULAR_MOTOR_DECAY_TIMESCALE:
155 m_angularMotorDecayTimescale = Math.Max(pValue, 0.01f); 156 m_angularMotorDecayTimescale = Math.Max(0.01f, Math.Min(pValue,120));
156 break; 157 break;
157 case Vehicle.ANGULAR_MOTOR_TIMESCALE: 158 case Vehicle.ANGULAR_MOTOR_TIMESCALE:
158 m_angularMotorTimescale = Math.Max(pValue, 0.01f); 159 m_angularMotorTimescale = Math.Max(pValue, 0.01f);
@@ -185,10 +186,12 @@ namespace OpenSim.Region.Physics.BulletSPlugin
185 m_linearDeflectionTimescale = Math.Max(pValue, 0.01f); 186 m_linearDeflectionTimescale = Math.Max(pValue, 0.01f);
186 break; 187 break;
187 case Vehicle.LINEAR_MOTOR_DECAY_TIMESCALE: 188 case Vehicle.LINEAR_MOTOR_DECAY_TIMESCALE:
188 m_linearMotorDecayTimescale = Math.Max(pValue, 0.01f); 189 m_linearMotorDecayTimescale = Math.Max(0.01f, Math.Min(pValue,120));
190 m_linearMotor.TargetValueDecayTimeScale = m_linearMotorDecayTimescale;
189 break; 191 break;
190 case Vehicle.LINEAR_MOTOR_TIMESCALE: 192 case Vehicle.LINEAR_MOTOR_TIMESCALE:
191 m_linearMotorTimescale = Math.Max(pValue, 0.01f); 193 m_linearMotorTimescale = Math.Max(pValue, 0.01f);
194 m_linearMotor.TimeScale = m_linearMotorTimescale;
192 break; 195 break;
193 case Vehicle.VERTICAL_ATTRACTION_EFFICIENCY: 196 case Vehicle.VERTICAL_ATTRACTION_EFFICIENCY:
194 m_verticalAttractionEfficiency = Math.Max(0.1f, Math.Min(pValue, 1f)); 197 m_verticalAttractionEfficiency = Math.Max(0.1f, Math.Min(pValue, 1f));
@@ -208,10 +211,12 @@ namespace OpenSim.Region.Physics.BulletSPlugin
208 break; 211 break;
209 case Vehicle.LINEAR_FRICTION_TIMESCALE: 212 case Vehicle.LINEAR_FRICTION_TIMESCALE:
210 m_linearFrictionTimescale = new Vector3(pValue, pValue, pValue); 213 m_linearFrictionTimescale = new Vector3(pValue, pValue, pValue);
214 m_linearMotor.FrictionTimescale = m_linearFrictionTimescale;
211 break; 215 break;
212 case Vehicle.LINEAR_MOTOR_DIRECTION: 216 case Vehicle.LINEAR_MOTOR_DIRECTION:
213 m_linearMotorDirection = new Vector3(pValue, pValue, pValue); 217 m_linearMotorDirection = new Vector3(pValue, pValue, pValue);
214 m_linearMotorDirectionLASTSET = new Vector3(pValue, pValue, pValue); 218 m_linearMotorDirectionLASTSET = new Vector3(pValue, pValue, pValue);
219 m_linearMotor.SetTarget(m_linearMotorDirection);
215 break; 220 break;
216 case Vehicle.LINEAR_MOTOR_OFFSET: 221 case Vehicle.LINEAR_MOTOR_OFFSET:
217 m_linearMotorOffset = new Vector3(pValue, pValue, pValue); 222 m_linearMotorOffset = new Vector3(pValue, pValue, pValue);
@@ -238,10 +243,12 @@ namespace OpenSim.Region.Physics.BulletSPlugin
238 break; 243 break;
239 case Vehicle.LINEAR_FRICTION_TIMESCALE: 244 case Vehicle.LINEAR_FRICTION_TIMESCALE:
240 m_linearFrictionTimescale = new Vector3(pValue.X, pValue.Y, pValue.Z); 245 m_linearFrictionTimescale = new Vector3(pValue.X, pValue.Y, pValue.Z);
246 m_linearMotor.FrictionTimescale = m_linearFrictionTimescale;
241 break; 247 break;
242 case Vehicle.LINEAR_MOTOR_DIRECTION: 248 case Vehicle.LINEAR_MOTOR_DIRECTION:
243 m_linearMotorDirection = new Vector3(pValue.X, pValue.Y, pValue.Z); 249 m_linearMotorDirection = new Vector3(pValue.X, pValue.Y, pValue.Z);
244 m_linearMotorDirectionLASTSET = new Vector3(pValue.X, pValue.Y, pValue.Z); 250 m_linearMotorDirectionLASTSET = new Vector3(pValue.X, pValue.Y, pValue.Z);
251 m_linearMotor.SetTarget(m_linearMotorDirection);
245 break; 252 break;
246 case Vehicle.LINEAR_MOTOR_OFFSET: 253 case Vehicle.LINEAR_MOTOR_OFFSET:
247 m_linearMotorOffset = new Vector3(pValue.X, pValue.Y, pValue.Z); 254 m_linearMotorOffset = new Vector3(pValue.X, pValue.Y, pValue.Z);
@@ -319,6 +326,7 @@ namespace OpenSim.Region.Physics.BulletSPlugin
319 326
320 m_referenceFrame = Quaternion.Identity; 327 m_referenceFrame = Quaternion.Identity;
321 m_flags = (VehicleFlag)0; 328 m_flags = (VehicleFlag)0;
329
322 break; 330 break;
323 331
324 case Vehicle.TYPE_SLED: 332 case Vehicle.TYPE_SLED:
@@ -510,6 +518,12 @@ namespace OpenSim.Region.Physics.BulletSPlugin
510 | VehicleFlag.HOVER_GLOBAL_HEIGHT); 518 | VehicleFlag.HOVER_GLOBAL_HEIGHT);
511 break; 519 break;
512 } 520 }
521
522 // Update any physical parameters based on this type.
523 Refresh();
524
525 m_linearMotor = new BSVMotor("LinearMotor", m_linearMotorTimescale, m_linearMotorDecayTimescale, m_linearFrictionTimescale, 1f);
526 m_linearMotor.PhysicsScene = PhysicsScene; // DEBUG DEBUG DEBUG (enables detail logging)
513 } 527 }
514 528
515 // Some of the properties of this prim may have changed. 529 // Some of the properties of this prim may have changed.
@@ -518,18 +532,25 @@ namespace OpenSim.Region.Physics.BulletSPlugin
518 { 532 {
519 if (IsActive) 533 if (IsActive)
520 { 534 {
521 VDetailLog("{0},BSDynamics.Refresh", Prim.LocalID);
522 m_vehicleMass = Prim.Linkset.LinksetMass; 535 m_vehicleMass = Prim.Linkset.LinksetMass;
523 536
524 // Friction effects are handled by this vehicle code 537 // Friction effects are handled by this vehicle code
525 BulletSimAPI.SetFriction2(Prim.PhysBody.ptr, 0f); 538 float friction = 0f;
526 BulletSimAPI.SetHitFraction2(Prim.PhysBody.ptr, 0f); 539 BulletSimAPI.SetFriction2(Prim.PhysBody.ptr, friction);
527 540
528 BulletSimAPI.SetAngularDamping2(Prim.PhysBody.ptr, PhysicsScene.Params.vehicleAngularDamping); 541 // Moderate angular movement introduced by Bullet.
529 542 // TODO: possibly set AngularFactor and LinearFactor for the type of vehicle.
530 BulletSimAPI.SetMassProps2(Prim.PhysBody.ptr, m_vehicleMass, new Vector3(1f, 1f, 1f)); 543 // Maybe compute linear and angular factor and damping from params.
531 544 float angularDamping = PhysicsScene.Params.vehicleAngularDamping;
532 545 BulletSimAPI.SetAngularDamping2(Prim.PhysBody.ptr, angularDamping);
546
547 // DEBUG DEBUG DEBUG: use uniform inertia to smooth movement added by Bullet
548 // Vector3 localInertia = new Vector3(1f, 1f, 1f);
549 Vector3 localInertia = new Vector3(m_vehicleMass, m_vehicleMass, m_vehicleMass);
550 BulletSimAPI.SetMassProps2(Prim.PhysBody.ptr, m_vehicleMass, localInertia);
551
552 VDetailLog("{0},BSDynamics.Refresh,frict={1},inert={2},aDamp={3}",
553 Prim.LocalID, friction, localInertia, angularDamping);
533 } 554 }
534 } 555 }
535 556
@@ -591,6 +612,7 @@ namespace OpenSim.Region.Physics.BulletSPlugin
591 // Also does hover and float. 612 // Also does hover and float.
592 private void MoveLinear(float pTimestep) 613 private void MoveLinear(float pTimestep)
593 { 614 {
615 /*
594 // m_linearMotorDirection is the target direction we are moving relative to the vehicle coordinates 616 // m_linearMotorDirection is the target direction we are moving relative to the vehicle coordinates
595 // m_lastLinearVelocityVector is the current speed we are moving in that direction 617 // m_lastLinearVelocityVector is the current speed we are moving in that direction
596 if (m_linearMotorDirection.LengthSquared() > 0.001f) 618 if (m_linearMotorDirection.LengthSquared() > 0.001f)
@@ -627,6 +649,12 @@ namespace OpenSim.Region.Physics.BulletSPlugin
627 649
628 VDetailLog("{0},MoveLinear,zeroed", Prim.LocalID); 650 VDetailLog("{0},MoveLinear,zeroed", Prim.LocalID);
629 } 651 }
652 */
653
654 m_newVelocity = m_linearMotor.Step(pTimestep);
655
656 // Rotate new object velocity from vehicle relative to world coordinates
657 m_newVelocity *= Prim.ForceOrientation;
630 658
631 // m_newVelocity is velocity computed from linear motor in world coordinates 659 // m_newVelocity is velocity computed from linear motor in world coordinates
632 660
@@ -785,12 +813,13 @@ namespace OpenSim.Region.Physics.BulletSPlugin
785 m_newVelocity.Z = 0; 813 m_newVelocity.Z = 0;
786 814
787 // Clamp REALLY high or low velocities 815 // Clamp REALLY high or low velocities
788 if (m_newVelocity.LengthSquared() > 1e6f) 816 float newVelocityLengthSq = m_newVelocity.LengthSquared();
817 if (newVelocityLengthSq > 1e6f)
789 { 818 {
790 m_newVelocity /= m_newVelocity.Length(); 819 m_newVelocity /= m_newVelocity.Length();
791 m_newVelocity *= 1000f; 820 m_newVelocity *= 1000f;
792 } 821 }
793 else if (m_newVelocity.LengthSquared() < 1e-6f) 822 else if (newVelocityLengthSq < 1e-6f)
794 m_newVelocity = Vector3.Zero; 823 m_newVelocity = Vector3.Zero;
795 824
796 // Stuff new linear velocity into the vehicle 825 // Stuff new linear velocity into the vehicle