diff options
-rw-r--r-- | OpenSim/Region/Physics/BulletSPlugin/BSDynamics.cs | 31 |
1 files changed, 16 insertions, 15 deletions
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSDynamics.cs b/OpenSim/Region/Physics/BulletSPlugin/BSDynamics.cs index c27d3f0..82fe267 100644 --- a/OpenSim/Region/Physics/BulletSPlugin/BSDynamics.cs +++ b/OpenSim/Region/Physics/BulletSPlugin/BSDynamics.cs | |||
@@ -144,7 +144,7 @@ namespace OpenSim.Region.Physics.BulletSPlugin | |||
144 | public void SetupVehicleDebugging() | 144 | public void SetupVehicleDebugging() |
145 | { | 145 | { |
146 | enableAngularVerticalAttraction = true; | 146 | enableAngularVerticalAttraction = true; |
147 | enableAngularDeflection = false; | 147 | enableAngularDeflection = true; |
148 | enableAngularBanking = true; | 148 | enableAngularBanking = true; |
149 | if (BSParam.VehicleDebuggingEnable) | 149 | if (BSParam.VehicleDebuggingEnable) |
150 | { | 150 | { |
@@ -173,7 +173,7 @@ namespace OpenSim.Region.Physics.BulletSPlugin | |||
173 | switch (pParam) | 173 | switch (pParam) |
174 | { | 174 | { |
175 | case Vehicle.ANGULAR_DEFLECTION_EFFICIENCY: | 175 | case Vehicle.ANGULAR_DEFLECTION_EFFICIENCY: |
176 | m_angularDeflectionEfficiency = Math.Max(pValue, 0.01f); | 176 | m_angularDeflectionEfficiency = ClampInRange(0f, pValue, 1f); |
177 | break; | 177 | break; |
178 | case Vehicle.ANGULAR_DEFLECTION_TIMESCALE: | 178 | case Vehicle.ANGULAR_DEFLECTION_TIMESCALE: |
179 | m_angularDeflectionTimescale = Math.Max(pValue, 0.01f); | 179 | m_angularDeflectionTimescale = Math.Max(pValue, 0.01f); |
@@ -1512,11 +1512,7 @@ namespace OpenSim.Region.Physics.BulletSPlugin | |||
1512 | // in that direction. | 1512 | // in that direction. |
1513 | // TODO: implement reference frame. | 1513 | // TODO: implement reference frame. |
1514 | public void ComputeAngularDeflection() | 1514 | public void ComputeAngularDeflection() |
1515 | { | 1515 | { |
1516 | // Since angularMotorUp and angularDeflection are computed independently, they will calculate | ||
1517 | // approximately the same X or Y correction. When added together (when contributions are combined) | ||
1518 | // this creates an over-correction and then wabbling as the target is overshot. | ||
1519 | // TODO: rethink how the different correction computations inter-relate. | ||
1520 | 1516 | ||
1521 | if (enableAngularDeflection && m_angularDeflectionEfficiency != 0 && VehicleForwardSpeed > 0.2) | 1517 | if (enableAngularDeflection && m_angularDeflectionEfficiency != 0 && VehicleForwardSpeed > 0.2) |
1522 | { | 1518 | { |
@@ -1531,10 +1527,14 @@ namespace OpenSim.Region.Physics.BulletSPlugin | |||
1531 | 1527 | ||
1532 | // The direction the vehicle is pointing | 1528 | // The direction the vehicle is pointing |
1533 | Vector3 pointingDirection = Vector3.UnitX * VehicleOrientation; | 1529 | Vector3 pointingDirection = Vector3.UnitX * VehicleOrientation; |
1534 | pointingDirection.Normalize(); | 1530 | //Predict where the Vehicle will be pointing after AngularVelocity change is applied. This will keep |
1531 | // from overshooting and allow this correction to merge with the Vertical Attraction peacefully. | ||
1532 | Vector3 predictedPointingDirection = pointingDirection * Quaternion.CreateFromAxisAngle(VehicleRotationalVelocity, 0f); | ||
1533 | predictedPointingDirection.Normalize(); | ||
1535 | 1534 | ||
1536 | // The difference between what is and what should be. | 1535 | // The difference between what is and what should be. |
1537 | Vector3 deflectionError = movingDirection - pointingDirection; | 1536 | // Vector3 deflectionError = movingDirection - predictedPointingDirection; |
1537 | Vector3 deflectionError = Vector3.Cross(movingDirection, predictedPointingDirection); | ||
1538 | 1538 | ||
1539 | // Don't try to correct very large errors (not our job) | 1539 | // Don't try to correct very large errors (not our job) |
1540 | // if (Math.Abs(deflectionError.X) > PIOverFour) deflectionError.X = PIOverTwo * Math.Sign(deflectionError.X); | 1540 | // if (Math.Abs(deflectionError.X) > PIOverFour) deflectionError.X = PIOverTwo * Math.Sign(deflectionError.X); |
@@ -1547,15 +1547,16 @@ namespace OpenSim.Region.Physics.BulletSPlugin | |||
1547 | // ret = m_angularDeflectionCorrectionMotor(1f, deflectionError); | 1547 | // ret = m_angularDeflectionCorrectionMotor(1f, deflectionError); |
1548 | 1548 | ||
1549 | // Scale the correction by recovery timescale and efficiency | 1549 | // Scale the correction by recovery timescale and efficiency |
1550 | deflectContributionV = (-deflectionError) * m_angularDeflectionEfficiency; | 1550 | // Not modeling a spring so clamp the scale to no more then the arc |
1551 | deflectContributionV /= m_angularDeflectionTimescale; | 1551 | deflectContributionV = (-deflectionError) * ClampInRange(0, m_angularDeflectionEfficiency/m_angularDeflectionTimescale,1f); |
1552 | 1552 | //deflectContributionV /= m_angularDeflectionTimescale; | |
1553 | VehicleRotationalVelocity += deflectContributionV * VehicleOrientation; | ||
1554 | 1553 | ||
1554 | // VehicleRotationalVelocity += deflectContributionV * VehicleOrientation; | ||
1555 | VehicleRotationalVelocity += deflectContributionV; | ||
1555 | VDetailLog("{0}, MoveAngular,Deflection,movingDir={1},pointingDir={2},deflectError={3},ret={4}", | 1556 | VDetailLog("{0}, MoveAngular,Deflection,movingDir={1},pointingDir={2},deflectError={3},ret={4}", |
1556 | ControllingPrim.LocalID, movingDirection, pointingDirection, deflectionError, deflectContributionV); | 1557 | ControllingPrim.LocalID, movingDirection, pointingDirection, deflectionError, deflectContributionV); |
1557 | VDetailLog("{0}, MoveAngular,Deflection,fwdSpd={1},defEff={2},defTS={3}", | 1558 | VDetailLog("{0}, MoveAngular,Deflection,fwdSpd={1},defEff={2},defTS={3},PredictedPointingDir={4}", |
1558 | ControllingPrim.LocalID, VehicleForwardSpeed, m_angularDeflectionEfficiency, m_angularDeflectionTimescale); | 1559 | ControllingPrim.LocalID, VehicleForwardSpeed, m_angularDeflectionEfficiency, m_angularDeflectionTimescale, predictedPointingDirection); |
1559 | } | 1560 | } |
1560 | } | 1561 | } |
1561 | 1562 | ||