aboutsummaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
authorRobert Adams2013-01-07 22:00:50 -0800
committerRobert Adams2013-01-07 22:00:50 -0800
commit1603606f1d8bd62574cf98e051877d836cbeb012 (patch)
treecc8756cbedb2cf3e028debb93717cf26ddb27f53
parentBulletSim: add function to push avatar up when hitting stairs. (diff)
downloadopensim-SC_OLD-1603606f1d8bd62574cf98e051877d836cbeb012.zip
opensim-SC_OLD-1603606f1d8bd62574cf98e051877d836cbeb012.tar.gz
opensim-SC_OLD-1603606f1d8bd62574cf98e051877d836cbeb012.tar.bz2
opensim-SC_OLD-1603606f1d8bd62574cf98e051877d836cbeb012.tar.xz
BulletSim: improve vehicle angular banking and deflection computation. Rotate angular correction forces to be world relative rather than vehicle relative.
-rw-r--r--OpenSim/Region/Physics/BulletSPlugin/BSDynamics.cs37
1 files changed, 18 insertions, 19 deletions
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSDynamics.cs b/OpenSim/Region/Physics/BulletSPlugin/BSDynamics.cs
index a9fbc8b..eb695d9 100644
--- a/OpenSim/Region/Physics/BulletSPlugin/BSDynamics.cs
+++ b/OpenSim/Region/Physics/BulletSPlugin/BSDynamics.cs
@@ -1111,6 +1111,10 @@ namespace OpenSim.Region.Physics.BulletSPlugin
1111 + deflectionContribution 1111 + deflectionContribution
1112 + bankingContribution; 1112 + bankingContribution;
1113 1113
1114 // Add of the above computation are made relative to vehicle coordinates.
1115 // Convert to world coordinates.
1116 m_lastAngularVelocity *= VehicleOrientation;
1117
1114 // ================================================================== 1118 // ==================================================================
1115 // Apply the correction velocity. 1119 // Apply the correction velocity.
1116 // TODO: Should this be applied as an angular force (torque)? 1120 // TODO: Should this be applied as an angular force (torque)?
@@ -1222,14 +1226,13 @@ namespace OpenSim.Region.Physics.BulletSPlugin
1222 public Vector3 ComputeAngularDeflection() 1226 public Vector3 ComputeAngularDeflection()
1223 { 1227 {
1224 Vector3 ret = Vector3.Zero; 1228 Vector3 ret = Vector3.Zero;
1225 return ret; // DEBUG DEBUG DEBUG 1229
1226 // Disable angular deflection for the moment.
1227 // Since angularMotorUp and angularDeflection are computed independently, they will calculate 1230 // Since angularMotorUp and angularDeflection are computed independently, they will calculate
1228 // approximately the same X or Y correction. When added together (when contributions are combined) 1231 // approximately the same X or Y correction. When added together (when contributions are combined)
1229 // this creates an over-correction and then wabbling as the target is overshot. 1232 // this creates an over-correction and then wabbling as the target is overshot.
1230 // TODO: rethink how the different correction computations inter-relate. 1233 // TODO: rethink how the different correction computations inter-relate.
1231 1234
1232 if (m_angularDeflectionEfficiency != 0) 1235 if (m_angularDeflectionEfficiency != 0 && VehicleVelocity != Vector3.Zero)
1233 { 1236 {
1234 // The direction the vehicle is moving 1237 // The direction the vehicle is moving
1235 Vector3 movingDirection = VehicleVelocity; 1238 Vector3 movingDirection = VehicleVelocity;
@@ -1298,33 +1301,29 @@ namespace OpenSim.Region.Physics.BulletSPlugin
1298 1301
1299 if (m_bankingEfficiency != 0 && m_verticalAttractionTimescale < m_verticalAttractionCutoff) 1302 if (m_bankingEfficiency != 0 && m_verticalAttractionTimescale < m_verticalAttractionCutoff)
1300 { 1303 {
1301 // This works by rotating a unit vector to the orientation of the vehicle. The 1304 // Rotate a UnitZ vector (pointing up) to how the vehicle is oriented.
1302 // roll (tilt) will be Y component of a tilting Z vector (zero for no tilt 1305 // As the vehicle rolls to the right or left, the Y value will increase from
1303 // up to one for full over). 1306 // zero (straight up) to 1 or -1 (full tilt right or left)
1304 Vector3 rollComponents = Vector3.UnitZ * VehicleOrientation; 1307 Vector3 rollComponents = Vector3.UnitZ * VehicleOrientation;
1305 1308
1306 // Figure out the yaw value for this much roll. 1309 // Figure out the yaw value for this much roll.
1307 float turnComponent = rollComponents.Y * rollComponents.Y * m_bankingEfficiency; 1310 // Squared because that seems to give a good value
1308 // Keep the sign 1311 float yawAngle = (float)Math.Asin(rollComponents.Y * rollComponents.Y) * m_bankingEfficiency;
1309 if (rollComponents.Y < 0f)
1310 turnComponent = -turnComponent;
1311
1312 // TODO: there must be a better computation of the banking force.
1313 float bankingTurnForce = turnComponent;
1314 1312
1315 // actual error = static turn error + dynamic turn error 1313 // actual error = static turn error + dynamic turn error
1316 float mixedBankingError = bankingTurnForce * (1f - m_bankingMix) + bankingTurnForce * m_bankingMix * VehicleForwardSpeed; 1314 float mixedYawAngle = yawAngle * (1f - m_bankingMix) + yawAngle * m_bankingMix * VehicleForwardSpeed;
1315
1317 // TODO: the banking effect should not go to infinity but what to limit it to? 1316 // TODO: the banking effect should not go to infinity but what to limit it to?
1318 mixedBankingError = ClampInRange(-20f, mixedBankingError, 20f); 1317 mixedYawAngle = ClampInRange(-20f, mixedYawAngle, 20f);
1319 1318
1320 // Build the force vector to change rotation from what it is to what it should be 1319 // Build the force vector to change rotation from what it is to what it should be
1321 ret.Z = -mixedBankingError; 1320 ret.Z = -mixedYawAngle;
1322 1321
1323 // Don't do it all at once. 1322 // Don't do it all at once.
1324 ret /= m_bankingTimescale; 1323 ret /= m_bankingTimescale;
1325 1324
1326 VDetailLog("{0}, MoveAngular,Banking,rollComp={1},speed={2},turnComp={3},bankErr={4},mixedBankErr={5},ret={6}", 1325 VDetailLog("{0}, MoveAngular,Banking,rollComp={1},speed={2},rollComp={3},yAng={4},mYAng={5},ret={6}",
1327 Prim.LocalID, rollComponents, VehicleForwardSpeed, turnComponent, bankingTurnForce, mixedBankingError, ret); 1326 Prim.LocalID, rollComponents, VehicleForwardSpeed, rollComponents, yawAngle, mixedYawAngle, ret);
1328 } 1327 }
1329 return ret; 1328 return ret;
1330 } 1329 }