diff options
Diffstat (limited to 'OpenSim/Region/Physics/BulletSPlugin/BSDynamics.cs')
-rw-r--r-- | OpenSim/Region/Physics/BulletSPlugin/BSDynamics.cs | 45 |
1 files changed, 27 insertions, 18 deletions
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSDynamics.cs b/OpenSim/Region/Physics/BulletSPlugin/BSDynamics.cs index aa247dd..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); |
@@ -774,7 +774,7 @@ namespace OpenSim.Region.Physics.BulletSPlugin | |||
774 | 774 | ||
775 | // Since the computation of terrain height can be a little involved, this routine | 775 | // Since the computation of terrain height can be a little involved, this routine |
776 | // is used to fetch the height only once for each vehicle simulation step. | 776 | // is used to fetch the height only once for each vehicle simulation step. |
777 | Vector3 lastRememberedHeightPos; | 777 | Vector3 lastRememberedHeightPos = new Vector3(-1, -1, -1); |
778 | private float GetTerrainHeight(Vector3 pos) | 778 | private float GetTerrainHeight(Vector3 pos) |
779 | { | 779 | { |
780 | if ((m_knownHas & m_knownChangedTerrainHeight) == 0 || pos != lastRememberedHeightPos) | 780 | if ((m_knownHas & m_knownChangedTerrainHeight) == 0 || pos != lastRememberedHeightPos) |
@@ -788,14 +788,16 @@ namespace OpenSim.Region.Physics.BulletSPlugin | |||
788 | 788 | ||
789 | // Since the computation of water level can be a little involved, this routine | 789 | // Since the computation of water level can be a little involved, this routine |
790 | // is used ot fetch the level only once for each vehicle simulation step. | 790 | // is used ot fetch the level only once for each vehicle simulation step. |
791 | Vector3 lastRememberedWaterHeightPos = new Vector3(-1, -1, -1); | ||
791 | private float GetWaterLevel(Vector3 pos) | 792 | private float GetWaterLevel(Vector3 pos) |
792 | { | 793 | { |
793 | if ((m_knownHas & m_knownChangedWaterLevel) == 0) | 794 | if ((m_knownHas & m_knownChangedWaterLevel) == 0 || pos != lastRememberedWaterHeightPos) |
794 | { | 795 | { |
796 | lastRememberedWaterHeightPos = pos; | ||
795 | m_knownWaterLevel = ControllingPrim.PhysScene.TerrainManager.GetWaterLevelAtXYZ(pos); | 797 | m_knownWaterLevel = ControllingPrim.PhysScene.TerrainManager.GetWaterLevelAtXYZ(pos); |
796 | m_knownHas |= m_knownChangedWaterLevel; | 798 | m_knownHas |= m_knownChangedWaterLevel; |
797 | } | 799 | } |
798 | return (float)m_knownWaterLevel; | 800 | return m_knownWaterLevel; |
799 | } | 801 | } |
800 | 802 | ||
801 | private Vector3 VehiclePosition | 803 | private Vector3 VehiclePosition |
@@ -991,11 +993,17 @@ namespace OpenSim.Region.Physics.BulletSPlugin | |||
991 | { | 993 | { |
992 | Vector3 vel = VehicleVelocity; | 994 | Vector3 vel = VehicleVelocity; |
993 | if ((m_flags & (VehicleFlag.NO_X)) != 0) | 995 | if ((m_flags & (VehicleFlag.NO_X)) != 0) |
996 | { | ||
994 | vel.X = 0; | 997 | vel.X = 0; |
998 | } | ||
995 | if ((m_flags & (VehicleFlag.NO_Y)) != 0) | 999 | if ((m_flags & (VehicleFlag.NO_Y)) != 0) |
1000 | { | ||
996 | vel.Y = 0; | 1001 | vel.Y = 0; |
1002 | } | ||
997 | if ((m_flags & (VehicleFlag.NO_Z)) != 0) | 1003 | if ((m_flags & (VehicleFlag.NO_Z)) != 0) |
1004 | { | ||
998 | vel.Z = 0; | 1005 | vel.Z = 0; |
1006 | } | ||
999 | VehicleVelocity = vel; | 1007 | VehicleVelocity = vel; |
1000 | } | 1008 | } |
1001 | 1009 | ||
@@ -1504,11 +1512,7 @@ namespace OpenSim.Region.Physics.BulletSPlugin | |||
1504 | // in that direction. | 1512 | // in that direction. |
1505 | // TODO: implement reference frame. | 1513 | // TODO: implement reference frame. |
1506 | public void ComputeAngularDeflection() | 1514 | public void ComputeAngularDeflection() |
1507 | { | 1515 | { |
1508 | // Since angularMotorUp and angularDeflection are computed independently, they will calculate | ||
1509 | // approximately the same X or Y correction. When added together (when contributions are combined) | ||
1510 | // this creates an over-correction and then wabbling as the target is overshot. | ||
1511 | // TODO: rethink how the different correction computations inter-relate. | ||
1512 | 1516 | ||
1513 | if (enableAngularDeflection && m_angularDeflectionEfficiency != 0 && VehicleForwardSpeed > 0.2) | 1517 | if (enableAngularDeflection && m_angularDeflectionEfficiency != 0 && VehicleForwardSpeed > 0.2) |
1514 | { | 1518 | { |
@@ -1523,10 +1527,14 @@ namespace OpenSim.Region.Physics.BulletSPlugin | |||
1523 | 1527 | ||
1524 | // The direction the vehicle is pointing | 1528 | // The direction the vehicle is pointing |
1525 | Vector3 pointingDirection = Vector3.UnitX * VehicleOrientation; | 1529 | Vector3 pointingDirection = Vector3.UnitX * VehicleOrientation; |
1526 | 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(); | ||
1527 | 1534 | ||
1528 | // The difference between what is and what should be. | 1535 | // The difference between what is and what should be. |
1529 | Vector3 deflectionError = movingDirection - pointingDirection; | 1536 | // Vector3 deflectionError = movingDirection - predictedPointingDirection; |
1537 | Vector3 deflectionError = Vector3.Cross(movingDirection, predictedPointingDirection); | ||
1530 | 1538 | ||
1531 | // Don't try to correct very large errors (not our job) | 1539 | // Don't try to correct very large errors (not our job) |
1532 | // 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); |
@@ -1539,15 +1547,16 @@ namespace OpenSim.Region.Physics.BulletSPlugin | |||
1539 | // ret = m_angularDeflectionCorrectionMotor(1f, deflectionError); | 1547 | // ret = m_angularDeflectionCorrectionMotor(1f, deflectionError); |
1540 | 1548 | ||
1541 | // Scale the correction by recovery timescale and efficiency | 1549 | // Scale the correction by recovery timescale and efficiency |
1542 | deflectContributionV = (-deflectionError) * m_angularDeflectionEfficiency; | 1550 | // Not modeling a spring so clamp the scale to no more then the arc |
1543 | deflectContributionV /= m_angularDeflectionTimescale; | 1551 | deflectContributionV = (-deflectionError) * ClampInRange(0, m_angularDeflectionEfficiency/m_angularDeflectionTimescale,1f); |
1544 | 1552 | //deflectContributionV /= m_angularDeflectionTimescale; | |
1545 | VehicleRotationalVelocity += deflectContributionV * VehicleOrientation; | ||
1546 | 1553 | ||
1554 | // VehicleRotationalVelocity += deflectContributionV * VehicleOrientation; | ||
1555 | VehicleRotationalVelocity += deflectContributionV; | ||
1547 | 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}", |
1548 | ControllingPrim.LocalID, movingDirection, pointingDirection, deflectionError, deflectContributionV); | 1557 | ControllingPrim.LocalID, movingDirection, pointingDirection, deflectionError, deflectContributionV); |
1549 | VDetailLog("{0}, MoveAngular,Deflection,fwdSpd={1},defEff={2},defTS={3}", | 1558 | VDetailLog("{0}, MoveAngular,Deflection,fwdSpd={1},defEff={2},defTS={3},PredictedPointingDir={4}", |
1550 | ControllingPrim.LocalID, VehicleForwardSpeed, m_angularDeflectionEfficiency, m_angularDeflectionTimescale); | 1559 | ControllingPrim.LocalID, VehicleForwardSpeed, m_angularDeflectionEfficiency, m_angularDeflectionTimescale, predictedPointingDirection); |
1551 | } | 1560 | } |
1552 | } | 1561 | } |
1553 | 1562 | ||