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.cs204
1 files changed, 97 insertions, 107 deletions
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSDynamics.cs b/OpenSim/Region/Physics/BulletSPlugin/BSDynamics.cs
index 4d067cf..525aac4 100644
--- a/OpenSim/Region/Physics/BulletSPlugin/BSDynamics.cs
+++ b/OpenSim/Region/Physics/BulletSPlugin/BSDynamics.cs
@@ -98,7 +98,7 @@ namespace OpenSim.Region.Physics.BulletSPlugin
98 private float m_angularMotorTimescale = 0; // motor angular velocity ramp up rate 98 private float m_angularMotorTimescale = 0; // motor angular velocity ramp up rate
99 private float m_angularMotorDecayTimescale = 0; // motor angular velocity decay rate 99 private float m_angularMotorDecayTimescale = 0; // motor angular velocity decay rate
100 private Vector3 m_angularFrictionTimescale = Vector3.Zero; // body angular velocity decay rate 100 private Vector3 m_angularFrictionTimescale = Vector3.Zero; // body angular velocity decay rate
101 private Vector3 m_lastAngularVelocity = Vector3.Zero; // what was last applied to body 101 private Vector3 m_lastAngularCorrection = Vector3.Zero;
102 private Vector3 m_lastVertAttractor = Vector3.Zero; // what VA was last applied to body 102 private Vector3 m_lastVertAttractor = Vector3.Zero; // what VA was last applied to body
103 103
104 //Deflection properties 104 //Deflection properties
@@ -111,6 +111,7 @@ namespace OpenSim.Region.Physics.BulletSPlugin
111 private float m_bankingEfficiency = 0; 111 private float m_bankingEfficiency = 0;
112 private float m_bankingMix = 0; 112 private float m_bankingMix = 0;
113 private float m_bankingTimescale = 0; 113 private float m_bankingTimescale = 0;
114 private Vector3 m_lastBanking = Vector3.Zero;
114 115
115 //Hover and Buoyancy properties 116 //Hover and Buoyancy properties
116 private float m_VhoverHeight = 0f; 117 private float m_VhoverHeight = 0f;
@@ -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(0.01f, Math.Min(pValue,120)); 156 m_angularMotorDecayTimescale = ClampInRange(0.01f, pValue, 120);
156 m_angularMotor.TargetValueDecayTimeScale = m_angularMotorDecayTimescale; 157 m_angularMotor.TargetValueDecayTimeScale = m_angularMotorDecayTimescale;
157 break; 158 break;
158 case Vehicle.ANGULAR_MOTOR_TIMESCALE: 159 case Vehicle.ANGULAR_MOTOR_TIMESCALE:
@@ -240,9 +241,9 @@ namespace OpenSim.Region.Physics.BulletSPlugin
240 break; 241 break;
241 case Vehicle.ANGULAR_MOTOR_DIRECTION: 242 case Vehicle.ANGULAR_MOTOR_DIRECTION:
242 // Limit requested angular speed to 2 rps= 4 pi rads/sec 243 // Limit requested angular speed to 2 rps= 4 pi rads/sec
243 pValue.X = Math.Max(-12.56f, Math.Min(pValue.X, 12.56f)); 244 pValue.X = ClampInRange(-12.56f, pValue.X, 12.56f);
244 pValue.Y = Math.Max(-12.56f, Math.Min(pValue.Y, 12.56f)); 245 pValue.Y = ClampInRange(-12.56f, pValue.Y, 12.56f);
245 pValue.Z = Math.Max(-12.56f, Math.Min(pValue.Z, 12.56f)); 246 pValue.Z = ClampInRange(-12.56f, pValue.Z, 12.56f);
246 m_angularMotorDirection = new Vector3(pValue.X, pValue.Y, pValue.Z); 247 m_angularMotorDirection = new Vector3(pValue.X, pValue.Y, pValue.Z);
247 m_angularMotor.SetTarget(m_angularMotorDirection); 248 m_angularMotor.SetTarget(m_angularMotorDirection);
248 break; 249 break;
@@ -328,6 +329,7 @@ namespace OpenSim.Region.Physics.BulletSPlugin
328 m_bankingEfficiency = 0; 329 m_bankingEfficiency = 0;
329 m_bankingTimescale = 1000; 330 m_bankingTimescale = 1000;
330 m_bankingMix = 1; 331 m_bankingMix = 1;
332 m_lastBanking = Vector3.Zero;
331 333
332 m_referenceFrame = Quaternion.Identity; 334 m_referenceFrame = Quaternion.Identity;
333 m_flags = (VehicleFlag)0; 335 m_flags = (VehicleFlag)0;
@@ -362,6 +364,7 @@ namespace OpenSim.Region.Physics.BulletSPlugin
362 m_bankingEfficiency = 0; 364 m_bankingEfficiency = 0;
363 m_bankingTimescale = 10; 365 m_bankingTimescale = 10;
364 m_bankingMix = 1; 366 m_bankingMix = 1;
367 m_lastBanking = Vector3.Zero;
365 368
366 m_referenceFrame = Quaternion.Identity; 369 m_referenceFrame = Quaternion.Identity;
367 m_flags &= ~(VehicleFlag.HOVER_WATER_ONLY 370 m_flags &= ~(VehicleFlag.HOVER_WATER_ONLY
@@ -400,6 +403,7 @@ namespace OpenSim.Region.Physics.BulletSPlugin
400 m_bankingEfficiency = -0.2f; 403 m_bankingEfficiency = -0.2f;
401 m_bankingMix = 1; 404 m_bankingMix = 1;
402 m_bankingTimescale = 1; 405 m_bankingTimescale = 1;
406 m_lastBanking = Vector3.Zero;
403 407
404 m_referenceFrame = Quaternion.Identity; 408 m_referenceFrame = Quaternion.Identity;
405 m_flags &= ~(VehicleFlag.HOVER_WATER_ONLY 409 m_flags &= ~(VehicleFlag.HOVER_WATER_ONLY
@@ -438,6 +442,7 @@ namespace OpenSim.Region.Physics.BulletSPlugin
438 m_bankingEfficiency = -0.3f; 442 m_bankingEfficiency = -0.3f;
439 m_bankingMix = 0.8f; 443 m_bankingMix = 0.8f;
440 m_bankingTimescale = 1; 444 m_bankingTimescale = 1;
445 m_lastBanking = Vector3.Zero;
441 446
442 m_referenceFrame = Quaternion.Identity; 447 m_referenceFrame = Quaternion.Identity;
443 m_flags &= ~(VehicleFlag.HOVER_TERRAIN_ONLY 448 m_flags &= ~(VehicleFlag.HOVER_TERRAIN_ONLY
@@ -476,6 +481,7 @@ namespace OpenSim.Region.Physics.BulletSPlugin
476 m_bankingEfficiency = 1; 481 m_bankingEfficiency = 1;
477 m_bankingMix = 0.7f; 482 m_bankingMix = 0.7f;
478 m_bankingTimescale = 2; 483 m_bankingTimescale = 2;
484 m_lastBanking = Vector3.Zero;
479 485
480 m_referenceFrame = Quaternion.Identity; 486 m_referenceFrame = Quaternion.Identity;
481 m_flags &= ~(VehicleFlag.HOVER_WATER_ONLY 487 m_flags &= ~(VehicleFlag.HOVER_WATER_ONLY
@@ -514,6 +520,8 @@ namespace OpenSim.Region.Physics.BulletSPlugin
514 m_bankingEfficiency = 0; 520 m_bankingEfficiency = 0;
515 m_bankingMix = 0.7f; 521 m_bankingMix = 0.7f;
516 m_bankingTimescale = 5; 522 m_bankingTimescale = 5;
523 m_lastBanking = Vector3.Zero;
524
517 m_referenceFrame = Quaternion.Identity; 525 m_referenceFrame = Quaternion.Identity;
518 526
519 m_referenceFrame = Quaternion.Identity; 527 m_referenceFrame = Quaternion.Identity;
@@ -627,12 +635,16 @@ namespace OpenSim.Region.Physics.BulletSPlugin
627 { 635 {
628 if (m_knownChanged != 0) 636 if (m_knownChanged != 0)
629 { 637 {
630 if ((m_knownChanged & m_knownChangedPosition) != 0) Prim.ForcePosition = VehiclePosition; 638 if ((m_knownChanged & m_knownChangedPosition) != 0)
631 if ((m_knownChanged & m_knownChangedOrientation) != 0) Prim.ForceOrientation = VehicleOrientation; 639 Prim.ForcePosition = VehiclePosition;
632 if ((m_knownChanged & m_knownChangedVelocity) != 0) Prim.ForceVelocity = VehicleVelocity; 640 if ((m_knownChanged & m_knownChangedOrientation) != 0)
633 if ((m_knownChanged & m_knownChangedRotationalVelocity) != 0) Prim.ForceRotationalVelocity = VehicleRotationalVelocity; 641 Prim.ForceOrientation = VehicleOrientation;
634 // If we set one of the values (ie, the physics engine doesn't do it) we must make sure there 642 if ((m_knownChanged & m_knownChangedVelocity) != 0)
635 // is an UpdateProperties event to send the changes up to the simulator. 643 Prim.ForceVelocity = VehicleVelocity;
644 if ((m_knownChanged & m_knownChangedRotationalVelocity) != 0)
645 Prim.ForceRotationalVelocity = VehicleRotationalVelocity;
646 // If we set one of the values (ie, the physics engine didn't do it) we must force
647 // an UpdateProperties event to send the changes up to the simulator.
636 BulletSimAPI.PushUpdate2(Prim.PhysBody.ptr); 648 BulletSimAPI.PushUpdate2(Prim.PhysBody.ptr);
637 } 649 }
638 } 650 }
@@ -957,9 +969,12 @@ namespace OpenSim.Region.Physics.BulletSPlugin
957 // ======================================================================= 969 // =======================================================================
958 // ======================================================================= 970 // =======================================================================
959 // Apply the effect of the angular motor. 971 // Apply the effect of the angular motor.
972 // The 'contribution' is how much angular correction each function wants.
973 // All the contributions are added together and the orientation of the vehicle
974 // is changed by all the contributed corrections.
960 private void MoveAngular(float pTimestep) 975 private void MoveAngular(float pTimestep)
961 { 976 {
962 Vector3 angularMotorContribution = m_angularMotor.Step(pTimestep); 977 Vector3 angularMotorContribution = m_angularMotor.Step();
963 978
964 // ================================================================== 979 // ==================================================================
965 // From http://wiki.secondlife.com/wiki/LlSetVehicleFlags : 980 // From http://wiki.secondlife.com/wiki/LlSetVehicleFlags :
@@ -974,22 +989,41 @@ namespace OpenSim.Region.Physics.BulletSPlugin
974 VDetailLog("{0}, MoveAngular,noDeflectionUp,angularMotorContrib={1}", Prim.LocalID, angularMotorContribution); 989 VDetailLog("{0}, MoveAngular,noDeflectionUp,angularMotorContrib={1}", Prim.LocalID, angularMotorContribution);
975 } 990 }
976 991
977 Vector3 verticalAttractionContribution = ComputeAngularVerticalAttraction(pTimestep); 992 Vector3 verticalAttractionContribution = ComputeAngularVerticalAttraction();
978 993
979 Vector3 deflectionContribution = ComputeAngularDeflection(pTimestep); 994 Vector3 deflectionContribution = ComputeAngularDeflection();
980 995
981 Vector3 bankingContribution = ComputeAngularBanking(pTimestep); 996 Vector3 bankingContribution = ComputeAngularBanking(angularMotorContribution.Z);
982 997
983 // ================================================================== 998 // ==================================================================
984 m_lastVertAttractor = verticalAttractionContribution; 999 m_lastVertAttractor = verticalAttractionContribution;
985 1000
986 // Sum velocities 1001 // Sum corrections
987 m_lastAngularVelocity = angularMotorContribution 1002 m_lastAngularCorrection = angularMotorContribution
988 + verticalAttractionContribution 1003 + verticalAttractionContribution
989 + deflectionContribution 1004 + deflectionContribution
990 + bankingContribution; 1005 + bankingContribution;
991 1006
992 // ================================================================== 1007 // ==================================================================
1008 // The correction is applied to the current orientation.
1009 // Any angular velocity on the vehicle is not us so zero the current value.
1010 VehicleRotationalVelocity = Vector3.Zero;
1011 if (!m_lastAngularCorrection.ApproxEquals(Vector3.Zero, 0.01f))
1012 {
1013 Vector3 scaledCorrection = m_lastAngularCorrection * pTimestep;
1014 Quaternion quatCorrection = Quaternion.CreateFromEulers(scaledCorrection);
1015
1016 VehicleOrientation = Quaternion.Add(VehicleOrientation, quatCorrection);
1017
1018 VDetailLog("{0}, MoveAngular,done,nonZero,angMotorContrib={1},vertAttrContrib={2},bankContrib={3},deflectContrib={4},totalContrib={5},scaledCorr={6}",
1019 Prim.LocalID,
1020 angularMotorContribution, verticalAttractionContribution,
1021 bankingContribution, deflectionContribution,
1022 m_lastAngularCorrection, scaledCorrection
1023 );
1024 }
1025
1026 // ==================================================================
993 //Offset section 1027 //Offset section
994 if (m_linearMotorOffset != Vector3.Zero) 1028 if (m_linearMotorOffset != Vector3.Zero)
995 { 1029 {
@@ -1020,50 +1054,18 @@ namespace OpenSim.Region.Physics.BulletSPlugin
1020 VDetailLog("{0}, BSDynamic.MoveAngular,motorOffset,applyTorqueImpulse={1}", Prim.LocalID, torqueFromOffset); 1054 VDetailLog("{0}, BSDynamic.MoveAngular,motorOffset,applyTorqueImpulse={1}", Prim.LocalID, torqueFromOffset);
1021 } 1055 }
1022 1056
1023 // ==================================================================
1024 if (m_lastAngularVelocity.ApproxEquals(Vector3.Zero, 0.01f))
1025 {
1026 // TODO: zeroing is good but it also sets values in unmanaged code. Remove the stores when idle.
1027 VDetailLog("{0}, MoveAngular,done,zero", Prim.LocalID);
1028 VehicleRotationalVelocity = Vector3.Zero;
1029 Prim.ZeroAngularMotion(true);
1030 }
1031 else
1032 {
1033 // Apply to the body.
1034 // The above calculates the absolute angular velocity needed. Angular velocity is massless.
1035 // Since we are stuffing the angular velocity directly into the object, the computed
1036 // velocity needs to be scaled by the timestep.
1037 // Also remove any motion that is on the object so added motion is only from vehicle.
1038 Vector3 setAngularVelocity = ((m_lastAngularVelocity * pTimestep) - VehicleRotationalVelocity);
1039 VehicleRotationalVelocity = setAngularVelocity;
1040
1041 VDetailLog("{0}, MoveAngular,done,nonZero,angMotorContrib={1},vertAttrContrib={2},bankContrib={3},deflectContrib={4},totalContrib={5},setAngVelocity={6}",
1042 Prim.LocalID,
1043 angularMotorContribution, verticalAttractionContribution,
1044 bankingContribution, deflectionContribution,
1045 m_lastAngularVelocity, setAngularVelocity
1046 );
1047 }
1048 } 1057 }
1049 1058
1050 public Vector3 ComputeAngularVerticalAttraction(float pTimestep) 1059 public Vector3 ComputeAngularVerticalAttraction()
1051 { 1060 {
1052 Vector3 ret = Vector3.Zero; 1061 Vector3 ret = Vector3.Zero;
1053 1062
1054 // If vertical attaction timescale is reasonable and we applied an angular force last time... 1063 // If vertical attaction timescale is reasonable and we applied an angular force last time...
1055 if (m_verticalAttractionTimescale < 500) 1064 if (m_verticalAttractionTimescale < 500)
1056 { 1065 {
1057 /*
1058 Vector3 verticalError = Vector3.UnitZ * VehicleOrientation;
1059 verticalError.Normalize();
1060 m_verticalAttractionMotor.SetCurrent(verticalError);
1061 m_verticalAttractionMotor.SetTarget(Vector3.UnitZ);
1062 ret = m_verticalAttractionMotor.Step(pTimestep);
1063 */
1064 // Take a vector pointing up and convert it from world to vehicle relative coords. 1066 // Take a vector pointing up and convert it from world to vehicle relative coords.
1065 Vector3 verticalError = Vector3.UnitZ * VehicleOrientation; 1067 Vector3 verticalError = Vector3.UnitZ * VehicleOrientation;
1066 verticalError.Normalize(); 1068 // verticalError.Normalize();
1067 1069
1068 // If vertical attraction correction is needed, the vector that was pointing up (UnitZ) 1070 // If vertical attraction correction is needed, the vector that was pointing up (UnitZ)
1069 // is now leaning to one side (rotated around the X axis) and the Y value will 1071 // is now leaning to one side (rotated around the X axis) and the Y value will
@@ -1087,56 +1089,63 @@ namespace OpenSim.Region.Physics.BulletSPlugin
1087 // scale by the time scale and timestep 1089 // scale by the time scale and timestep
1088 Vector3 unscaledContrib = ret; 1090 Vector3 unscaledContrib = ret;
1089 ret /= m_verticalAttractionTimescale; 1091 ret /= m_verticalAttractionTimescale;
1090 ret *= pTimestep; 1092 // This returns the angular correction desired. Timestep is added later.
1093 // ret *= pTimestep;
1091 1094
1092 // apply efficiency 1095 // apply efficiency
1093 Vector3 preEfficiencyContrib = ret; 1096 Vector3 preEfficiencyContrib = ret;
1097 // TODO: implement efficiency.
1094 // Effenciency squared seems to give a more realistic effect 1098 // Effenciency squared seems to give a more realistic effect
1095 float efficencySquared = m_verticalAttractionEfficiency * m_verticalAttractionEfficiency; 1099 float efficencySquared = m_verticalAttractionEfficiency * m_verticalAttractionEfficiency;
1096 ret *= efficencySquared; 1100 // ret *= efficencySquared;
1097 1101
1098 VDetailLog("{0}, MoveAngular,verticalAttraction,,verticalError={1},unscaled={2},preEff={3},eff={4},effSq={5},vertAttr={6}", 1102 VDetailLog("{0}, MoveAngular,verticalAttraction,,verticalError={1},unscaled={2},preEff={3},eff={4},effSq={5},vertAttr={6}",
1099 Prim.LocalID, verticalError, unscaledContrib, preEfficiencyContrib, 1103 Prim.LocalID, verticalError, unscaledContrib, preEfficiencyContrib,
1100 m_verticalAttractionEfficiency, efficencySquared, 1104 m_verticalAttractionEfficiency, efficencySquared,
1101 ret); 1105 ret);
1102
1103 } 1106 }
1104 return ret; 1107 return ret;
1105 } 1108 }
1106 1109
1107 public Vector3 ComputeAngularDeflection(float pTimestep) 1110 // Return the angular correction to correct the direction the vehicle is pointing to be
1111 // the direction is should want to be pointing.
1112 public Vector3 ComputeAngularDeflection()
1108 { 1113 {
1109 Vector3 ret = Vector3.Zero; 1114 Vector3 ret = Vector3.Zero;
1110 1115
1111 if (m_angularDeflectionEfficiency != 0) 1116 if (m_angularDeflectionEfficiency != 0)
1112 { 1117 {
1113 // Compute a scaled vector that points in the preferred axis (X direction) 1118 // Where the vehicle should want to point relative to the vehicle
1114 Vector3 scaledDefaultDirection = 1119 Vector3 preferredDirection = Vector3.UnitX * m_referenceFrame;
1115 new Vector3((pTimestep * 10 * (m_angularDeflectionEfficiency / m_angularDeflectionTimescale)), 0, 0); 1120
1116 // Adding the current vehicle orientation and reference frame displaces the orientation to the frame. 1121 // Where the vehicle is pointing relative to the vehicle.
1117 // Rotate the scaled default axix relative to the actual vehicle direction giving where it should point. 1122 Vector3 currentDirection = Vector3.UnitX * Quaternion.Add(VehicleOrientation, m_referenceFrame);
1118 Vector3 preferredAxisOfMotion = scaledDefaultDirection * Quaternion.Add(VehicleOrientation, m_referenceFrame);
1119 1123
1120 // Scale by efficiency and timescale 1124 // Difference between where vehicle is pointing and where it should wish to point
1121 ret = (preferredAxisOfMotion * (m_angularDeflectionEfficiency) / m_angularDeflectionTimescale) * pTimestep; 1125 Vector3 directionCorrection = preferredDirection - currentDirection;
1122 1126
1123 VDetailLog("{0}, MoveAngular,Deflection,perfAxis={1},deflection={2}", Prim.LocalID, preferredAxisOfMotion, ret); 1127 // Scale the correction by recovery timescale and efficiency
1128 ret = directionCorrection * m_angularDeflectionEfficiency / m_angularDeflectionTimescale;
1124 1129
1125 // This deflection computation is not correct. 1130 VDetailLog("{0}, MoveAngular,Deflection,perfDir={1},currentDir={2},dirCorrection={3},ret={4}",
1126 ret = Vector3.Zero; 1131 Prim.LocalID, preferredDirection, currentDirection, directionCorrection, ret);
1127 } 1132 }
1128 return ret; 1133 return ret;
1129 } 1134 }
1130 1135
1131 public Vector3 ComputeAngularBanking(float pTimestep) 1136 // Return an angular change to tip the vehicle (around X axis) when turning (turned around Z).
1137 // Remembers the last banking value calculated and returns the difference needed this tick.
1138 // TurningFactor is rate going left or right (pos=left, neg=right, scale=0..1).
1139 public Vector3 ComputeAngularBanking(float turningFactor)
1132 { 1140 {
1133 Vector3 ret = Vector3.Zero; 1141 Vector3 ret = Vector3.Zero;
1142 Vector3 computedBanking = Vector3.Zero;
1134 1143
1135 if (m_bankingEfficiency != 0) 1144 if (m_bankingEfficiency != 0)
1136 { 1145 {
1137 Vector3 dir = Vector3.One * VehicleOrientation; 1146 Vector3 currentDirection = Vector3.UnitX * VehicleOrientation;
1147
1138 float mult = (m_bankingMix * m_bankingMix) * -1 * (m_bankingMix < 0 ? -1 : 1); 1148 float mult = (m_bankingMix * m_bankingMix) * -1 * (m_bankingMix < 0 ? -1 : 1);
1139 //Changes which way it banks in and out of turns
1140 1149
1141 //Use the square of the efficiency, as it looks much more how SL banking works 1150 //Use the square of the efficiency, as it looks much more how SL banking works
1142 float effSquared = (m_bankingEfficiency * m_bankingEfficiency); 1151 float effSquared = (m_bankingEfficiency * m_bankingEfficiency);
@@ -1144,51 +1153,27 @@ namespace OpenSim.Region.Physics.BulletSPlugin
1144 effSquared *= -1; //Keep the negative! 1153 effSquared *= -1; //Keep the negative!
1145 1154
1146 float mix = Math.Abs(m_bankingMix); 1155 float mix = Math.Abs(m_bankingMix);
1147 if (m_angularMotorVelocity.X == 0) 1156 // TODO: Must include reference frame.
1148 { 1157 float forwardSpeed = VehicleVelocity.X;
1149 // The vehicle is stopped
1150 /*if (!parent.Orientation.ApproxEquals(this.m_referenceFrame, 0.25f))
1151 {
1152 Vector3 axisAngle;
1153 float angle;
1154 parent.Orientation.GetAxisAngle(out axisAngle, out angle);
1155 Vector3 rotatedVel = parent.Velocity * parent.Orientation;
1156 if ((rotatedVel.X < 0 && axisAngle.Y > 0) || (rotatedVel.X > 0 && axisAngle.Y < 0))
1157 m_angularMotorVelocity.X += (effSquared * (mult * mix)) * (1f) * 10;
1158 else
1159 m_angularMotorVelocity.X += (effSquared * (mult * mix)) * (-1f) * 10;
1160 }*/
1161 }
1162 else
1163 {
1164 ret.Z += (effSquared * (mult * mix)) * (m_angularMotorVelocity.X) * 4;
1165 }
1166 1158
1167 //If they are colliding, we probably shouldn't shove the prim around... probably 1159 if (!Prim.IsColliding && forwardSpeed > mix)
1168 if (!Prim.IsColliding && Math.Abs(m_angularMotorVelocity.X) > mix)
1169 { 1160 {
1170 float angVelZ = m_angularMotorVelocity.X * -1; 1161 computedBanking.X = ClampInRange(-3f, turningFactor * (effSquared * mult), 3f);
1171 /*if(angVelZ > mix)
1172 angVelZ = mix;
1173 else if(angVelZ < -mix)
1174 angVelZ = -mix;*/
1175 //This controls how fast and how far the banking occurs
1176 Vector3 bankingRot = new Vector3(angVelZ * (effSquared * mult), 0, 0);
1177 if (bankingRot.X > 3)
1178 bankingRot.X = 3;
1179 else if (bankingRot.X < -3)
1180 bankingRot.X = -3;
1181 bankingRot *= VehicleOrientation;
1182 ret += bankingRot;
1183 } 1162 }
1184 m_angularMotorVelocity.X *= m_bankingEfficiency == 1 ? 0.0f : 1 - m_bankingEfficiency; 1163
1185 VDetailLog("{0}, MoveAngular,Banking,bEff={1},angMotVel={2},effSq={3},mult={4},mix={5},banking={6}", 1164 // 'computedBanking' is now how much banking that should be happening.
1186 Prim.LocalID, m_bankingEfficiency, m_angularMotorVelocity, effSquared, mult, mix, ret); 1165 ret = computedBanking - m_lastBanking;
1166
1167 // Scale the correction by timescale and efficiency
1168 ret /= m_bankingTimescale * m_bankingEfficiency;
1169
1170 VDetailLog("{0}, MoveAngular,Banking,computedB={1},lastB={2},bEff={3},effSq={4},mult={5},mix={6},banking={7}",
1171 Prim.LocalID, computedBanking, m_lastBanking, m_bankingEfficiency, effSquared, mult, mix, ret);
1187 } 1172 }
1173 m_lastBanking = computedBanking;
1188 return ret; 1174 return ret;
1189 } 1175 }
1190 1176
1191
1192 // This is from previous instantiations of XXXDynamics.cs. 1177 // This is from previous instantiations of XXXDynamics.cs.
1193 // Applies roll reference frame. 1178 // Applies roll reference frame.
1194 // TODO: is this the right way to separate the code to do this operation? 1179 // TODO: is this the right way to separate the code to do this operation?
@@ -1229,6 +1214,11 @@ namespace OpenSim.Region.Physics.BulletSPlugin
1229 1214
1230 } 1215 }
1231 1216
1217 private float ClampInRange(float low, float val, float high)
1218 {
1219 return Math.Max(low, Math.Min(val, high));
1220 }
1221
1232 // Invoke the detailed logger and output something if it's enabled. 1222 // Invoke the detailed logger and output something if it's enabled.
1233 private void VDetailLog(string msg, params Object[] args) 1223 private void VDetailLog(string msg, params Object[] args)
1234 { 1224 {