aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/Physics/ChOdePlugin/ODEDynamics.cs
diff options
context:
space:
mode:
authorKitto Flora2009-12-31 16:07:36 -0500
committerKitto Flora2009-12-31 16:07:36 -0500
commit3f901d313bfd11070d5260f867c8a73c14f2d109 (patch)
tree20ecdfa6538c48ee23f9ad155579a102dfdf3898 /OpenSim/Region/Physics/ChOdePlugin/ODEDynamics.cs
parentMerge branch 'master' into careminster (diff)
downloadopensim-SC-3f901d313bfd11070d5260f867c8a73c14f2d109.zip
opensim-SC-3f901d313bfd11070d5260f867c8a73c14f2d109.tar.gz
opensim-SC-3f901d313bfd11070d5260f867c8a73c14f2d109.tar.bz2
opensim-SC-3f901d313bfd11070d5260f867c8a73c14f2d109.tar.xz
Vehicle Linear parameter adjustments
Diffstat (limited to 'OpenSim/Region/Physics/ChOdePlugin/ODEDynamics.cs')
-rw-r--r--OpenSim/Region/Physics/ChOdePlugin/ODEDynamics.cs40
1 files changed, 32 insertions, 8 deletions
diff --git a/OpenSim/Region/Physics/ChOdePlugin/ODEDynamics.cs b/OpenSim/Region/Physics/ChOdePlugin/ODEDynamics.cs
index 78b15be..ef2dccc 100644
--- a/OpenSim/Region/Physics/ChOdePlugin/ODEDynamics.cs
+++ b/OpenSim/Region/Physics/ChOdePlugin/ODEDynamics.cs
@@ -83,6 +83,12 @@ namespace OpenSim.Region.Physics.OdePlugin
83// private IntPtr m_jointGroup = IntPtr.Zero; 83// private IntPtr m_jointGroup = IntPtr.Zero;
84// private IntPtr m_aMotor = IntPtr.Zero; 84// private IntPtr m_aMotor = IntPtr.Zero;
85 85
86 // Correction factors, to match Sl
87 private static float m_linearVelocityFactor = 0.9f;
88 private static float m_linearAttackFactor = 0.4f;
89 private static float m_linearDecayFactor = 0.5f;
90 private static float m_linearFrictionFactor = 1.2f;
91
86 92
87 // Vehicle properties 93 // Vehicle properties
88 private Vehicle m_type = Vehicle.TYPE_NONE; // If a 'VEHICLE', and what kind 94 private Vehicle m_type = Vehicle.TYPE_NONE; // If a 'VEHICLE', and what kind
@@ -98,7 +104,7 @@ namespace OpenSim.Region.Physics.OdePlugin
98 104
99 // Linear properties 105 // Linear properties
100 private Vector3 m_linearMotorDirection = Vector3.Zero; // velocity requested by LSL, decayed by time 106 private Vector3 m_linearMotorDirection = Vector3.Zero; // velocity requested by LSL, decayed by time
101 private Vector3 m_linearMotorDirectionLASTSET = Vector3.Zero; // velocity requested by LSL 107 private Vector3 m_linearMotorDirectionLASTSET = Vector3.Zero; // velocity requested by LSL, for max limiting
102 private Vector3 m_dir = Vector3.Zero; // velocity applied to body 108 private Vector3 m_dir = Vector3.Zero; // velocity applied to body
103 private Vector3 m_linearFrictionTimescale = Vector3.Zero; 109 private Vector3 m_linearFrictionTimescale = Vector3.Zero;
104 private float m_linearMotorDecayTimescale = 0; 110 private float m_linearMotorDecayTimescale = 0;
@@ -267,8 +273,9 @@ namespace OpenSim.Region.Physics.OdePlugin
267 m_linearFrictionTimescale = new Vector3(pValue.X, pValue.Y, pValue.Z); 273 m_linearFrictionTimescale = new Vector3(pValue.X, pValue.Y, pValue.Z);
268 break; 274 break;
269 case Vehicle.LINEAR_MOTOR_DIRECTION: 275 case Vehicle.LINEAR_MOTOR_DIRECTION:
270 m_linearMotorDirection = new Vector3(pValue.X, pValue.Y, pValue.Z); 276 pValue *= m_linearVelocityFactor;
271 m_linearMotorDirectionLASTSET = new Vector3(pValue.X, pValue.Y, pValue.Z); 277 m_linearMotorDirection = new Vector3(pValue.X, pValue.Y, pValue.Z); // velocity requested by LSL, decayed by time
278 m_linearMotorDirectionLASTSET = new Vector3(pValue.X, pValue.Y, pValue.Z); // velocity requested by LSL, for max limiting
272 break; 279 break;
273 case Vehicle.LINEAR_MOTOR_OFFSET: 280 case Vehicle.LINEAR_MOTOR_OFFSET:
274 // m_linearMotorOffset = new Vector3(pValue.X, pValue.Y, pValue.Z); 281 // m_linearMotorOffset = new Vector3(pValue.X, pValue.Y, pValue.Z);
@@ -453,6 +460,17 @@ namespace OpenSim.Region.Physics.OdePlugin
453 MoveAngular(pTimestep); 460 MoveAngular(pTimestep);
454 }// end Step 461 }// end Step
455 462
463 internal void Halt()
464 { // Kill all motions, when non-physical
465 m_linearMotorDirection = Vector3.Zero;
466 m_linearMotorDirectionLASTSET = Vector3.Zero;
467 m_dir = Vector3.Zero;
468 m_lastLinearVelocityVector = Vector3.Zero;
469 m_angularMotorDirection = Vector3.Zero;
470 m_angularMotorVelocity = Vector3.Zero;
471 m_lastAngularVelocity = Vector3.Zero;
472 }
473
456 private void MoveLinear(float pTimestep, OdeScene _pParentScene) 474 private void MoveLinear(float pTimestep, OdeScene _pParentScene)
457 { 475 {
458 if (!m_linearMotorDirection.ApproxEquals(Vector3.Zero, 0.01f)) // requested m_linearMotorDirection is significant 476 if (!m_linearMotorDirection.ApproxEquals(Vector3.Zero, 0.01f)) // requested m_linearMotorDirection is significant
@@ -460,9 +478,15 @@ namespace OpenSim.Region.Physics.OdePlugin
460 if(!d.BodyIsEnabled (Body)) d.BodyEnable (Body); 478 if(!d.BodyIsEnabled (Body)) d.BodyEnable (Body);
461 479
462 // add drive to body 480 // add drive to body
463 Vector3 addAmount = m_linearMotorDirection/(m_linearMotorTimescale/pTimestep); 481 float linfactor = m_linearMotorTimescale/pTimestep;
464 m_lastLinearVelocityVector += (addAmount*10); // lastLinearVelocityVector is the current body velocity vector? 482 // Linear accel
465 483 Vector3 addAmount1 = (m_linearMotorDirection/linfactor) * 0.8f;
484 // Differential accel
485 Vector3 addAmount2 = ((m_linearMotorDirection - m_lastLinearVelocityVector)/linfactor) * 1.6f;
486 // SL correction
487 Vector3 addAmount = (addAmount1 + addAmount2) * m_linearAttackFactor;
488 m_lastLinearVelocityVector += addAmount; // lastLinearVelocityVector is the current body velocity vector
489//if(frcount == 0) Console.WriteLine("AL {0} + AD {1} AS{2} V {3}", addAmount1, addAmount2, addAmount, m_lastLinearVelocityVector);
466 // This will work temporarily, but we really need to compare speed on an axis 490 // This will work temporarily, but we really need to compare speed on an axis
467 // KF: Limit body velocity to applied velocity? 491 // KF: Limit body velocity to applied velocity?
468 if (Math.Abs(m_lastLinearVelocityVector.X) > Math.Abs(m_linearMotorDirectionLASTSET.X)) 492 if (Math.Abs(m_lastLinearVelocityVector.X) > Math.Abs(m_linearMotorDirectionLASTSET.X))
@@ -475,7 +499,7 @@ namespace OpenSim.Region.Physics.OdePlugin
475 // decay applied velocity 499 // decay applied velocity
476 Vector3 decayfraction = ((Vector3.One/(m_linearMotorDecayTimescale/pTimestep))); 500 Vector3 decayfraction = ((Vector3.One/(m_linearMotorDecayTimescale/pTimestep)));
477 //Console.WriteLine("decay: " + decayfraction); 501 //Console.WriteLine("decay: " + decayfraction);
478 m_linearMotorDirection -= m_linearMotorDirection * decayfraction * 0.5f; 502 m_linearMotorDirection -= m_linearMotorDirection * decayfraction * m_linearDecayFactor;
479 //Console.WriteLine("actual: " + m_linearMotorDirection); 503 //Console.WriteLine("actual: " + m_linearMotorDirection);
480 } 504 }
481 else 505 else
@@ -560,7 +584,7 @@ namespace OpenSim.Region.Physics.OdePlugin
560 584
561 // apply friction 585 // apply friction
562 Vector3 decayamount = Vector3.One / (m_linearFrictionTimescale / pTimestep); 586 Vector3 decayamount = Vector3.One / (m_linearFrictionTimescale / pTimestep);
563 m_lastLinearVelocityVector -= m_lastLinearVelocityVector * decayamount; 587 m_lastLinearVelocityVector -= m_lastLinearVelocityVector * decayamount * m_linearFrictionFactor;
564 } // end MoveLinear() 588 } // end MoveLinear()
565 589
566 private void MoveAngular(float pTimestep) 590 private void MoveAngular(float pTimestep)