aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/Physics/BulletSPlugin/BSDynamics.cs
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim/Region/Physics/BulletSPlugin/BSDynamics.cs')
-rw-r--r--OpenSim/Region/Physics/BulletSPlugin/BSDynamics.cs66
1 files changed, 50 insertions, 16 deletions
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSDynamics.cs b/OpenSim/Region/Physics/BulletSPlugin/BSDynamics.cs
index 311cf4f..07e87d1 100644
--- a/OpenSim/Region/Physics/BulletSPlugin/BSDynamics.cs
+++ b/OpenSim/Region/Physics/BulletSPlugin/BSDynamics.cs
@@ -209,7 +209,7 @@ namespace OpenSim.Region.Physics.BulletSPlugin
209 m_VhoverTimescale = Math.Max(pValue, 0.01f); 209 m_VhoverTimescale = Math.Max(pValue, 0.01f);
210 break; 210 break;
211 case Vehicle.LINEAR_DEFLECTION_EFFICIENCY: 211 case Vehicle.LINEAR_DEFLECTION_EFFICIENCY:
212 m_linearDeflectionEfficiency = Math.Max(pValue, 0.01f); 212 m_linearDeflectionEfficiency = ClampInRange(0f, pValue, 1f);
213 break; 213 break;
214 case Vehicle.LINEAR_DEFLECTION_TIMESCALE: 214 case Vehicle.LINEAR_DEFLECTION_TIMESCALE:
215 m_linearDeflectionTimescale = Math.Max(pValue, 0.01f); 215 m_linearDeflectionTimescale = Math.Max(pValue, 0.01f);
@@ -707,7 +707,6 @@ namespace OpenSim.Region.Physics.BulletSPlugin
707 private Vector3 m_knownRotationalVelocity; 707 private Vector3 m_knownRotationalVelocity;
708 private Vector3 m_knownRotationalForce; 708 private Vector3 m_knownRotationalForce;
709 private Vector3 m_knownRotationalImpulse; 709 private Vector3 m_knownRotationalImpulse;
710 private Vector3 m_knownForwardVelocity; // vehicle relative forward speed
711 710
712 private const int m_knownChangedPosition = 1 << 0; 711 private const int m_knownChangedPosition = 1 << 0;
713 private const int m_knownChangedVelocity = 1 << 1; 712 private const int m_knownChangedVelocity = 1 << 1;
@@ -719,7 +718,6 @@ namespace OpenSim.Region.Physics.BulletSPlugin
719 private const int m_knownChangedRotationalImpulse = 1 << 7; 718 private const int m_knownChangedRotationalImpulse = 1 << 7;
720 private const int m_knownChangedTerrainHeight = 1 << 8; 719 private const int m_knownChangedTerrainHeight = 1 << 8;
721 private const int m_knownChangedWaterLevel = 1 << 9; 720 private const int m_knownChangedWaterLevel = 1 << 9;
722 private const int m_knownChangedForwardVelocity = 1 <<10;
723 721
724 public void ForgetKnownVehicleProperties() 722 public void ForgetKnownVehicleProperties()
725 { 723 {
@@ -923,12 +921,7 @@ namespace OpenSim.Region.Physics.BulletSPlugin
923 { 921 {
924 get 922 get
925 { 923 {
926 if ((m_knownHas & m_knownChangedForwardVelocity) == 0) 924 return VehicleVelocity * Quaternion.Inverse(Quaternion.Normalize(VehicleOrientation));
927 {
928 m_knownForwardVelocity = VehicleVelocity * Quaternion.Inverse(Quaternion.Normalize(VehicleOrientation));
929 m_knownHas |= m_knownChangedForwardVelocity;
930 }
931 return m_knownForwardVelocity;
932 } 925 }
933 } 926 }
934 private float VehicleForwardSpeed 927 private float VehicleForwardSpeed
@@ -981,6 +974,8 @@ namespace OpenSim.Region.Physics.BulletSPlugin
981 { 974 {
982 ComputeLinearVelocity(pTimestep); 975 ComputeLinearVelocity(pTimestep);
983 976
977 ComputeLinearDeflection(pTimestep);
978
984 ComputeLinearTerrainHeightCorrection(pTimestep); 979 ComputeLinearTerrainHeightCorrection(pTimestep);
985 980
986 ComputeLinearHover(pTimestep); 981 ComputeLinearHover(pTimestep);
@@ -1026,12 +1021,12 @@ namespace OpenSim.Region.Physics.BulletSPlugin
1026 { 1021 {
1027 // Step the motor from the current value. Get the correction needed this step. 1022 // Step the motor from the current value. Get the correction needed this step.
1028 Vector3 origVelW = VehicleVelocity; // DEBUG 1023 Vector3 origVelW = VehicleVelocity; // DEBUG
1029 Vector3 currentVelV = VehicleVelocity * Quaternion.Inverse(VehicleOrientation); 1024 Vector3 currentVelV = VehicleForwardVelocity;
1030 Vector3 linearMotorCorrectionV = m_linearMotor.Step(pTimestep, currentVelV); 1025 Vector3 linearMotorCorrectionV = m_linearMotor.Step(pTimestep, currentVelV);
1031 1026
1032 // Friction reduces vehicle motion 1027 // Friction reduces vehicle motion based on absolute speed. Slow vehicle down by friction.
1033 Vector3 frictionFactorW = ComputeFrictionFactor(m_linearFrictionTimescale, pTimestep); 1028 Vector3 frictionFactorV = ComputeFrictionFactor(m_linearFrictionTimescale, pTimestep);
1034 linearMotorCorrectionV -= (currentVelV * frictionFactorW); 1029 linearMotorCorrectionV -= (currentVelV * frictionFactorV);
1035 1030
1036 // Motor is vehicle coordinates. Rotate it to world coordinates 1031 // Motor is vehicle coordinates. Rotate it to world coordinates
1037 Vector3 linearMotorVelocityW = linearMotorCorrectionV * VehicleOrientation; 1032 Vector3 linearMotorVelocityW = linearMotorCorrectionV * VehicleOrientation;
@@ -1046,11 +1041,38 @@ namespace OpenSim.Region.Physics.BulletSPlugin
1046 // Add this correction to the velocity to make it faster/slower. 1041 // Add this correction to the velocity to make it faster/slower.
1047 VehicleVelocity += linearMotorVelocityW; 1042 VehicleVelocity += linearMotorVelocityW;
1048 1043
1049
1050
1051 VDetailLog("{0}, MoveLinear,velocity,origVelW={1},velV={2},correctV={3},correctW={4},newVelW={5},fricFact={6}", 1044 VDetailLog("{0}, MoveLinear,velocity,origVelW={1},velV={2},correctV={3},correctW={4},newVelW={5},fricFact={6}",
1052 ControllingPrim.LocalID, origVelW, currentVelV, linearMotorCorrectionV, 1045 ControllingPrim.LocalID, origVelW, currentVelV, linearMotorCorrectionV,
1053 linearMotorVelocityW, VehicleVelocity, frictionFactorW); 1046 linearMotorVelocityW, VehicleVelocity, frictionFactorV);
1047 }
1048
1049 //Given a Deflection Effiency and a Velocity, Returns a Velocity that is Partially Deflected onto the X Axis
1050 //Clamped so that a DeflectionTimescale of less then 1 does not increase force over original velocity
1051 private void ComputeLinearDeflection(float pTimestep)
1052 {
1053 Vector3 linearDeflectionV = Vector3.Zero;
1054 Vector3 velocityV = VehicleForwardVelocity;
1055
1056 // Velocity in Y and Z dimensions is movement to the side or turning.
1057 // Compute deflection factor from the to the side and rotational velocity
1058 linearDeflectionV.Y = SortedClampInRange(0, (velocityV.Y * m_linearDeflectionEfficiency) / m_linearDeflectionTimescale, velocityV.Y);
1059 linearDeflectionV.Z = SortedClampInRange(0, (velocityV.Z * m_linearDeflectionEfficiency) / m_linearDeflectionTimescale, velocityV.Z);
1060
1061 // Velocity to the side and around is corrected and moved into the forward direction
1062 linearDeflectionV.X += Math.Abs(linearDeflectionV.Y);
1063 linearDeflectionV.X += Math.Abs(linearDeflectionV.Z);
1064
1065 // Scale the deflection to the fractional simulation time
1066 linearDeflectionV *= pTimestep;
1067
1068 // Subtract the sideways and rotational velocity deflection factors while adding the correction forward
1069 linearDeflectionV *= new Vector3(1,-1,-1);
1070
1071 // Correciont is vehicle relative. Convert to world coordinates and add to the velocity
1072 VehicleVelocity += linearDeflectionV * VehicleOrientation;
1073
1074 VDetailLog("{0}, MoveLinear,LinearDeflection,linDefEff={1},linDefTS={2},linDeflectionV={3}",
1075 ControllingPrim.LocalID, m_linearDeflectionEfficiency, m_linearDeflectionTimescale, linearDeflectionV);
1054 } 1076 }
1055 1077
1056 public void ComputeLinearTerrainHeightCorrection(float pTimestep) 1078 public void ComputeLinearTerrainHeightCorrection(float pTimestep)
@@ -1652,6 +1674,18 @@ namespace OpenSim.Region.Physics.BulletSPlugin
1652 return frictionFactor; 1674 return frictionFactor;
1653 } 1675 }
1654 1676
1677 private float SortedClampInRange(float clampa, float val, float clampb)
1678 {
1679 if (clampa > clampb)
1680 {
1681 float temp = clampa;
1682 clampa = clampb;
1683 clampb = temp;
1684 }
1685 return ClampInRange(clampa, val, clampb);
1686
1687 }
1688
1655 private float ClampInRange(float low, float val, float high) 1689 private float ClampInRange(float low, float val, float high)
1656 { 1690 {
1657 return Math.Max(low, Math.Min(val, high)); 1691 return Math.Max(low, Math.Min(val, high));