aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim
diff options
context:
space:
mode:
authorRobert Adams2012-10-26 13:55:20 -0700
committerRobert Adams2012-11-03 21:13:19 -0700
commit92d3c611e57fc320bf20b6b500c275eaebf912aa (patch)
tree97c49a44a4dbc329e62dadbed93d73b610ad5c9c /OpenSim
parentBulletSim: add ForEachMember(action) call for linkset. (diff)
downloadopensim-SC-92d3c611e57fc320bf20b6b500c275eaebf912aa.zip
opensim-SC-92d3c611e57fc320bf20b6b500c275eaebf912aa.tar.gz
opensim-SC-92d3c611e57fc320bf20b6b500c275eaebf912aa.tar.bz2
opensim-SC-92d3c611e57fc320bf20b6b500c275eaebf912aa.tar.xz
BulletSim: many small changes for vehicles simulation.
Diffstat (limited to 'OpenSim')
-rw-r--r--OpenSim/Region/Physics/BulletSPlugin/BSDynamics.cs71
1 files changed, 40 insertions, 31 deletions
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSDynamics.cs b/OpenSim/Region/Physics/BulletSPlugin/BSDynamics.cs
index 9b59bef..8bd8117 100644
--- a/OpenSim/Region/Physics/BulletSPlugin/BSDynamics.cs
+++ b/OpenSim/Region/Physics/BulletSPlugin/BSDynamics.cs
@@ -526,6 +526,12 @@ namespace OpenSim.Region.Physics.BulletSPlugin
526 BulletSimAPI.UpdateInertiaTensor2(Prim.BSBody.ptr); 526 BulletSimAPI.UpdateInertiaTensor2(Prim.BSBody.ptr);
527 } 527 }
528 */ 528 */
529 if (IsActive)
530 {
531 // Friction effects are handled by this vehicle code
532 BulletSimAPI.SetFriction2(Prim.BSBody.ptr, 0f);
533 BulletSimAPI.SetHitFraction2(Prim.BSBody.ptr, 0f);
534 }
529 } 535 }
530 536
531 // One step of the vehicle properties for the next 'pTimestep' seconds. 537 // One step of the vehicle properties for the next 'pTimestep' seconds.
@@ -552,6 +558,7 @@ namespace OpenSim.Region.Physics.BulletSPlugin
552 Prim.ForceOrientation = newOrientation; 558 Prim.ForceOrientation = newOrientation;
553 } 559 }
554 */ 560 */
561 BulletSimAPI.SetInterpolationVelocity2(Prim.BSBody.ptr, m_newVelocity, m_lastAngularVelocity);
555 562
556 // remember the position so next step we can limit absolute movement effects 563 // remember the position so next step we can limit absolute movement effects
557 m_lastPositionVector = Prim.ForcePosition; 564 m_lastPositionVector = Prim.ForcePosition;
@@ -570,17 +577,21 @@ namespace OpenSim.Region.Physics.BulletSPlugin
570 { 577 {
571 Vector3 origDir = m_linearMotorDirection; 578 Vector3 origDir = m_linearMotorDirection;
572 Vector3 origVel = m_lastLinearVelocityVector; 579 Vector3 origVel = m_lastLinearVelocityVector;
580 Vector3 vehicleVelocity = Prim.ForceVelocity * Quaternion.Inverse(Prim.ForceOrientation); // DEBUG
573 581
574 // add drive to body 582 // add drive to body
575 Vector3 addAmount = (m_linearMotorDirection - m_lastLinearVelocityVector)/(m_linearMotorTimescale / pTimestep); 583 Vector3 addAmount = (m_linearMotorDirection - m_lastLinearVelocityVector)/(m_linearMotorTimescale / pTimestep);
576 // lastLinearVelocityVector is the current body velocity vector 584 // lastLinearVelocityVector is the current body velocity vector
577 m_lastLinearVelocityVector += addAmount; 585 m_lastLinearVelocityVector += addAmount;
578 586
579 float keepfraction = 1.0f - (1.0f / (m_linearMotorDecayTimescale / pTimestep)); 587 float decayFactor = (1.0f / m_linearMotorDecayTimescale) * pTimestep;
580 m_linearMotorDirection *= keepfraction; 588 m_linearMotorDirection *= (1f - decayFactor);
581 589
582 VDetailLog("{0},MoveLinear,nonZero,origdir={1},origvel={2},add={3},notDecay={4},dir={5},vel={6}", 590 Vector3 frictionFactor = (Vector3.One / m_linearFrictionTimescale) * pTimestep;
583 Prim.LocalID, origDir, origVel, addAmount, keepfraction, m_linearMotorDirection, m_lastLinearVelocityVector); 591 m_lastLinearVelocityVector *= (Vector3.One - frictionFactor);
592
593 VDetailLog("{0},MoveLinear,nonZero,origdir={1},origvel={2},vehVel={3},add={4},decay={5},lmDir={6},lmVel={7}",
594 Prim.LocalID, origDir, origVel, vehicleVelocity, addAmount, decayFactor, m_linearMotorDirection, m_lastLinearVelocityVector);
584 595
585 // convert requested object velocity to object relative vector 596 // convert requested object velocity to object relative vector
586 m_newVelocity = m_lastLinearVelocityVector * Prim.ForceOrientation; 597 m_newVelocity = m_lastLinearVelocityVector * Prim.ForceOrientation;
@@ -661,18 +672,18 @@ namespace OpenSim.Region.Physics.BulletSPlugin
661 } 672 }
662 else 673 else
663 { 674 {
664 float horizontalError = pos.Z - m_VhoverTargetHeight; 675 float verticalError = pos.Z - m_VhoverTargetHeight;
665 // RA: where does the 50 come from> 676 // RA: where does the 50 come from>
666 float horizontalCorrectionVelocity = ((horizontalError * 50.0f) / (m_VhoverTimescale / pTimestep)); 677 float verticalCorrectionVelocity = pTimestep * ((verticalError * 50.0f) / m_VhoverTimescale);
667 // Replace Vertical speed with correction figure if significant 678 // Replace Vertical speed with correction figure if significant
668 if (Math.Abs(horizontalError) > 0.01f) 679 if (Math.Abs(verticalError) > 0.01f)
669 { 680 {
670 m_newVelocity.Z += horizontalCorrectionVelocity; 681 m_newVelocity.Z += verticalCorrectionVelocity;
671 //KF: m_VhoverEfficiency is not yet implemented 682 //KF: m_VhoverEfficiency is not yet implemented
672 } 683 }
673 else if (horizontalError < -0.01) 684 else if (verticalError < -0.01)
674 { 685 {
675 m_newVelocity.Z -= horizontalCorrectionVelocity; 686 m_newVelocity.Z -= verticalCorrectionVelocity;
676 } 687 }
677 else 688 else
678 { 689 {
@@ -748,16 +759,13 @@ namespace OpenSim.Region.Physics.BulletSPlugin
748 if ((m_flags & (VehicleFlag.NO_Z)) != 0) 759 if ((m_flags & (VehicleFlag.NO_Z)) != 0)
749 m_newVelocity.Z = 0; 760 m_newVelocity.Z = 0;
750 761
751 // Apply friction
752 Vector3 keepFraction = Vector3.One - (Vector3.One / (m_linearFrictionTimescale / pTimestep));
753 m_lastLinearVelocityVector *= keepFraction;
754
755 // Apply velocity 762 // Apply velocity
756 // Prim.ForceVelocity = m_newVelocity; 763 Prim.ForceVelocity = m_newVelocity;
757 Prim.AddForce(m_newVelocity, false); 764 // Prim.AddForce(m_newVelocity * Prim.Linkset.LinksetMass, false);
765 // Prim.AddForce(grav * Prim.Linkset.LinksetMass, false);
758 766
759 VDetailLog("{0},MoveLinear,done,lmDir={1},lmVel={2},newVel={3},grav={4},1Mdecay={5}", 767 VDetailLog("{0},MoveLinear,done,lmDir={1},lmVel={2},newVel={3},grav={4}",
760 Prim.LocalID, m_linearMotorDirection, m_lastLinearVelocityVector, m_newVelocity, grav, keepFraction); 768 Prim.LocalID, m_linearMotorDirection, m_lastLinearVelocityVector, m_newVelocity, grav);
761 769
762 } // end MoveLinear() 770 } // end MoveLinear()
763 771
@@ -858,14 +866,17 @@ namespace OpenSim.Region.Physics.BulletSPlugin
858 #region Deflection 866 #region Deflection
859 867
860 //Forward is the prefered direction, but if the reference frame has changed, we need to take this into account as well 868 //Forward is the prefered direction, but if the reference frame has changed, we need to take this into account as well
861 Vector3 PreferredAxisOfMotion = 869 if (m_angularDeflectionEfficiency != 0)
862 new Vector3((10*(m_angularDeflectionEfficiency/m_angularDeflectionTimescale)), 0, 0); 870 {
863 PreferredAxisOfMotion *= Quaternion.Add(Prim.ForceOrientation, m_referenceFrame); 871 Vector3 preferredAxisOfMotion =
872 new Vector3((pTimestep * 10 * (m_angularDeflectionEfficiency / m_angularDeflectionTimescale)), 0, 0);
873 preferredAxisOfMotion *= Quaternion.Add(Prim.ForceOrientation, m_referenceFrame);
864 874
865 //Multiply it so that it scales linearly 875 deflection = (preferredAxisOfMotion * (m_angularDeflectionEfficiency) / m_angularDeflectionTimescale) * pTimestep;
866 //deflection = PreferredAxisOfMotion;
867 876
868 //deflection = ((PreferredAxisOfMotion * m_angularDeflectionEfficiency) / (m_angularDeflectionTimescale / pTimestep)); 877 VDetailLog("{0},MoveAngular,Deflection,perfAxis={1},deflection={2}",
878 Prim.LocalID, preferredAxisOfMotion, deflection);
879 }
869 880
870 #endregion 881 #endregion
871 882
@@ -917,18 +928,16 @@ namespace OpenSim.Region.Physics.BulletSPlugin
917 banking += bankingRot; 928 banking += bankingRot;
918 } 929 }
919 m_angularMotorVelocity.X *= m_bankingEfficiency == 1 ? 0.0f : 1 - m_bankingEfficiency; 930 m_angularMotorVelocity.X *= m_bankingEfficiency == 1 ? 0.0f : 1 - m_bankingEfficiency;
931 VDetailLog("{0},MoveAngular,Banking,bEff={1},angMotVel={2},banking={3}",
932 Prim.LocalID, m_bankingEfficiency, m_angularMotorVelocity, banking);
920 } 933 }
921 934
922 #endregion 935 #endregion
923 936
924 m_lastVertAttractor = vertattr; 937 m_lastVertAttractor = vertattr;
925 938
926 // Bank section tba
927
928 // Deflection section tba
929
930 // Sum velocities 939 // Sum velocities
931 m_lastAngularVelocity = m_angularMotorVelocity + vertattr; // + bank + deflection 940 m_lastAngularVelocity = m_angularMotorVelocity + vertattr + banking + deflection;
932 941
933 if ((m_flags & (VehicleFlag.NO_DEFLECTION_UP)) != 0) 942 if ((m_flags & (VehicleFlag.NO_DEFLECTION_UP)) != 0)
934 { 943 {
@@ -948,8 +957,8 @@ namespace OpenSim.Region.Physics.BulletSPlugin
948 m_lastAngularVelocity -= m_lastAngularVelocity * decayamount; 957 m_lastAngularVelocity -= m_lastAngularVelocity * decayamount;
949 958
950 // Apply to the body 959 // Apply to the body
951 // Prim.ForceRotationalVelocity = m_lastAngularVelocity; 960 // The above calculates the absolute angular velocity needed
952 Prim.AddAngularForce(m_lastAngularVelocity, false); 961 Prim.ForceRotationalVelocity = m_lastAngularVelocity;
953 962
954 VDetailLog("{0},MoveAngular,done,decay={1},lastAngular={2}", Prim.LocalID, decayamount, m_lastAngularVelocity); 963 VDetailLog("{0},MoveAngular,done,decay={1},lastAngular={2}", Prim.LocalID, decayamount, m_lastAngularVelocity);
955 } //end MoveAngular 964 } //end MoveAngular