diff options
author | Robert Adams | 2013-01-20 09:33:13 -0800 |
---|---|---|
committer | Robert Adams | 2013-01-20 23:09:53 -0800 |
commit | 3b0df52d10c157cd2711d64ef9007d2afccbd468 (patch) | |
tree | ff548c66f9ee84933e33988ec21fb6712b6b82c1 /OpenSim/Region/Physics/BulletSPlugin/BSDynamics.cs | |
parent | This updates prebuild to remove BulletSimN, implements the BulletSim API in B... (diff) | |
download | opensim-SC-3b0df52d10c157cd2711d64ef9007d2afccbd468.zip opensim-SC-3b0df52d10c157cd2711d64ef9007d2afccbd468.tar.gz opensim-SC-3b0df52d10c157cd2711d64ef9007d2afccbd468.tar.bz2 opensim-SC-3b0df52d10c157cd2711d64ef9007d2afccbd468.tar.xz |
BulletSim: modify motors to return correction rather than current value
to better use them for incremental updates.
Modify prim and character to use the new motors.
Simplify the vehicle linear movement code to just update the velocity
directly or the basic movement.
Diffstat (limited to '')
-rw-r--r-- | OpenSim/Region/Physics/BulletSPlugin/BSDynamics.cs | 41 |
1 files changed, 14 insertions, 27 deletions
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSDynamics.cs b/OpenSim/Region/Physics/BulletSPlugin/BSDynamics.cs index f2c7cec..7c9b83b 100644 --- a/OpenSim/Region/Physics/BulletSPlugin/BSDynamics.cs +++ b/OpenSim/Region/Physics/BulletSPlugin/BSDynamics.cs | |||
@@ -957,39 +957,25 @@ namespace OpenSim.Region.Physics.BulletSPlugin | |||
957 | 957 | ||
958 | public void ComputeLinearVelocity(float pTimestep) | 958 | public void ComputeLinearVelocity(float pTimestep) |
959 | { | 959 | { |
960 | Vector3 linearMotorStep = m_linearMotor.Step(pTimestep); | 960 | // Step the motor from the current value. Get the correction needed this step. |
961 | Vector3 currentVel = VehicleVelocity * Quaternion.Inverse(VehicleOrientation); | ||
962 | Vector3 linearMotorCorrection = m_linearMotor.Step(pTimestep, currentVel); | ||
961 | 963 | ||
962 | // The movement computed in the linear motor is relative to the vehicle | 964 | // Motor is vehicle coordinates. Rotate it to world coordinates |
963 | // coordinates. Rotate the movement to world coordinates. | 965 | Vector3 linearMotorVelocity = linearMotorCorrection * VehicleOrientation; |
964 | Vector3 linearMotorVelocity = linearMotorStep * VehicleOrientation; | ||
965 | 966 | ||
966 | // If we're a ground vehicle, don't loose any Z action (like gravity acceleration). | 967 | // If we're a ground vehicle, don't add any upward Z movement |
967 | float mixFactor = 1f; // 1 means use all linear motor Z value, 0 means use all existing Z | ||
968 | if ((m_flags & VehicleFlag.LIMIT_MOTOR_UP) != 0) | 968 | if ((m_flags & VehicleFlag.LIMIT_MOTOR_UP) != 0) |
969 | { | 969 | { |
970 | if (!Prim.IsColliding) | 970 | if (linearMotorVelocity.Z > 0f) |
971 | { | 971 | linearMotorVelocity.Z = 0f; |
972 | // If a ground vehicle and not on the ground, I want gravity effect | ||
973 | mixFactor = 0.2f; | ||
974 | } | ||
975 | } | ||
976 | else | ||
977 | { | ||
978 | // I'm not a ground vehicle but don't totally loose the effect of the environment | ||
979 | mixFactor = 0.8f; | ||
980 | } | 972 | } |
981 | linearMotorVelocity.Z = mixFactor * linearMotorVelocity.Z + (1f - mixFactor) * VehicleVelocity.Z; | ||
982 | |||
983 | // What we want to contribute to the vehicle's existing velocity | ||
984 | Vector3 linearMotorForce = linearMotorVelocity - VehicleVelocity; | ||
985 | |||
986 | // Act against the inertia of the vehicle | ||
987 | linearMotorForce *= m_vehicleMass; | ||
988 | 973 | ||
989 | VehicleAddForceImpulse(linearMotorForce * pTimestep); | 974 | // Add this correction to the velocity to make it faster/slower. |
975 | VehicleVelocity += linearMotorVelocity; | ||
990 | 976 | ||
991 | VDetailLog("{0}, MoveLinear,velocity,vehVel={1},step={2},stepVel={3},mix={4},force={5}", | 977 | VDetailLog("{0}, MoveLinear,velocity,vehVel={1},correction={2},force={3}", |
992 | Prim.LocalID, VehicleVelocity, linearMotorStep, linearMotorVelocity, mixFactor, linearMotorForce); | 978 | Prim.LocalID, VehicleVelocity, linearMotorCorrection, linearMotorVelocity); |
993 | } | 979 | } |
994 | 980 | ||
995 | public void ComputeLinearTerrainHeightCorrection(float pTimestep) | 981 | public void ComputeLinearTerrainHeightCorrection(float pTimestep) |
@@ -1204,6 +1190,7 @@ namespace OpenSim.Region.Physics.BulletSPlugin | |||
1204 | { | 1190 | { |
1205 | // The user wants this many radians per second angular change? | 1191 | // The user wants this many radians per second angular change? |
1206 | Vector3 angularMotorContribution = m_angularMotor.Step(pTimestep); | 1192 | Vector3 angularMotorContribution = m_angularMotor.Step(pTimestep); |
1193 | angularMotorContribution = m_angularMotor.CurrentValue; | ||
1207 | 1194 | ||
1208 | // ================================================================== | 1195 | // ================================================================== |
1209 | // From http://wiki.secondlife.com/wiki/LlSetVehicleFlags : | 1196 | // From http://wiki.secondlife.com/wiki/LlSetVehicleFlags : |
@@ -1234,7 +1221,7 @@ namespace OpenSim.Region.Physics.BulletSPlugin | |||
1234 | + deflectionContribution | 1221 | + deflectionContribution |
1235 | + bankingContribution; | 1222 | + bankingContribution; |
1236 | 1223 | ||
1237 | // Add of the above computation are made relative to vehicle coordinates. | 1224 | // All of the above computation are made relative to vehicle coordinates. |
1238 | // Convert to world coordinates. | 1225 | // Convert to world coordinates. |
1239 | m_lastAngularVelocity *= VehicleOrientation; | 1226 | m_lastAngularVelocity *= VehicleOrientation; |
1240 | 1227 | ||