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 | |
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 'OpenSim/Region')
5 files changed, 36 insertions, 38 deletions
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSCharacter.cs b/OpenSim/Region/Physics/BulletSPlugin/BSCharacter.cs index 478aeab..696c4bd 100644 --- a/OpenSim/Region/Physics/BulletSPlugin/BSCharacter.cs +++ b/OpenSim/Region/Physics/BulletSPlugin/BSCharacter.cs | |||
@@ -198,7 +198,8 @@ public sealed class BSCharacter : BSPhysObject | |||
198 | // TODO: Decide if the step parameters should be changed depending on the avatar's | 198 | // TODO: Decide if the step parameters should be changed depending on the avatar's |
199 | // state (flying, colliding, ...). There is code in ODE to do this. | 199 | // state (flying, colliding, ...). There is code in ODE to do this. |
200 | 200 | ||
201 | OMV.Vector3 stepVelocity = _velocityMotor.Step(timeStep); | 201 | _velocityMotor.Step(timeStep); |
202 | OMV.Vector3 stepVelocity = _velocityMotor.CurrentValue; | ||
202 | 203 | ||
203 | // If falling, we keep the world's downward vector no matter what the other axis specify. | 204 | // If falling, we keep the world's downward vector no matter what the other axis specify. |
204 | if (!Flying && !IsColliding) | 205 | if (!Flying && !IsColliding) |
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 | ||
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSMotors.cs b/OpenSim/Region/Physics/BulletSPlugin/BSMotors.cs index 6d0db2e..82fd2d2 100755 --- a/OpenSim/Region/Physics/BulletSPlugin/BSMotors.cs +++ b/OpenSim/Region/Physics/BulletSPlugin/BSMotors.cs | |||
@@ -138,7 +138,8 @@ public class BSVMotor : BSMotor | |||
138 | CurrentValue = TargetValue = Vector3.Zero; | 138 | CurrentValue = TargetValue = Vector3.Zero; |
139 | } | 139 | } |
140 | 140 | ||
141 | // Compute the next step and return the new current value | 141 | // Compute the next step and return the new current value. |
142 | // Returns the correction needed to move 'current' to 'target'. | ||
142 | public virtual Vector3 Step(float timeStep) | 143 | public virtual Vector3 Step(float timeStep) |
143 | { | 144 | { |
144 | if (!Enabled) return TargetValue; | 145 | if (!Enabled) return TargetValue; |
@@ -150,7 +151,7 @@ public class BSVMotor : BSMotor | |||
150 | Vector3 error = TargetValue - CurrentValue; | 151 | Vector3 error = TargetValue - CurrentValue; |
151 | if (!ErrorIsZero(error)) | 152 | if (!ErrorIsZero(error)) |
152 | { | 153 | { |
153 | correction = Step(timeStep, error); | 154 | correction = StepError(timeStep, error); |
154 | 155 | ||
155 | CurrentValue += correction; | 156 | CurrentValue += correction; |
156 | 157 | ||
@@ -187,14 +188,20 @@ public class BSVMotor : BSMotor | |||
187 | else | 188 | else |
188 | { | 189 | { |
189 | // Difference between what we have and target is small. Motor is done. | 190 | // Difference between what we have and target is small. Motor is done. |
190 | CurrentValue = TargetValue; | 191 | CurrentValue = TargetValue = Vector3.Zero; |
191 | MDetailLog("{0}, BSVMotor.Step,zero,{1},origTgt={2},origCurr={3},ret={4}", | 192 | MDetailLog("{0}, BSVMotor.Step,zero,{1},origTgt={2},origCurr={3},ret={4}", |
192 | BSScene.DetailLogZero, UseName, origCurrVal, origTarget, CurrentValue); | 193 | BSScene.DetailLogZero, UseName, origCurrVal, origTarget, CurrentValue); |
193 | } | 194 | } |
194 | 195 | ||
195 | return CurrentValue; | 196 | return correction; |
197 | } | ||
198 | // version of step that sets the current value before doing the step | ||
199 | public virtual Vector3 Step(float timeStep, Vector3 current) | ||
200 | { | ||
201 | CurrentValue = current; | ||
202 | return Step(timeStep); | ||
196 | } | 203 | } |
197 | public virtual Vector3 Step(float timeStep, Vector3 error) | 204 | public virtual Vector3 StepError(float timeStep, Vector3 error) |
198 | { | 205 | { |
199 | if (!Enabled) return Vector3.Zero; | 206 | if (!Enabled) return Vector3.Zero; |
200 | 207 | ||
@@ -304,7 +311,7 @@ public class BSFMotor : BSMotor | |||
304 | float error = TargetValue - CurrentValue; | 311 | float error = TargetValue - CurrentValue; |
305 | if (!ErrorIsZero(error)) | 312 | if (!ErrorIsZero(error)) |
306 | { | 313 | { |
307 | correction = Step(timeStep, error); | 314 | correction = StepError(timeStep, error); |
308 | 315 | ||
309 | CurrentValue += correction; | 316 | CurrentValue += correction; |
310 | 317 | ||
@@ -347,7 +354,7 @@ public class BSFMotor : BSMotor | |||
347 | return CurrentValue; | 354 | return CurrentValue; |
348 | } | 355 | } |
349 | 356 | ||
350 | public virtual float Step(float timeStep, float error) | 357 | public virtual float StepError(float timeStep, float error) |
351 | { | 358 | { |
352 | if (!Enabled) return 0f; | 359 | if (!Enabled) return 0f; |
353 | 360 | ||
@@ -440,8 +447,8 @@ public class BSPIDVMotor : BSVMotor | |||
440 | } | 447 | } |
441 | } | 448 | } |
442 | 449 | ||
443 | // Ignore Current and Target Values and just advance the PID computation on this error. | 450 | // Advance the PID computation on this error. |
444 | public override Vector3 Step(float timeStep, Vector3 error) | 451 | public override Vector3 StepError(float timeStep, Vector3 error) |
445 | { | 452 | { |
446 | if (!Enabled) return Vector3.Zero; | 453 | if (!Enabled) return Vector3.Zero; |
447 | 454 | ||
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs b/OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs index aaa6fe5..22afdc9 100644 --- a/OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs +++ b/OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs | |||
@@ -1082,7 +1082,7 @@ public sealed class BSPrim : BSPhysObject | |||
1082 | OMV.Vector3 origPosition = RawPosition; // DEBUG DEBUG (for printout below) | 1082 | OMV.Vector3 origPosition = RawPosition; // DEBUG DEBUG (for printout below) |
1083 | 1083 | ||
1084 | // 'movePosition' is where we'd like the prim to be at this moment. | 1084 | // 'movePosition' is where we'd like the prim to be at this moment. |
1085 | OMV.Vector3 movePosition = _targetMotor.Step(timeStep); | 1085 | OMV.Vector3 movePosition = RawPosition + _targetMotor.Step(timeStep); |
1086 | 1086 | ||
1087 | // If we are very close to our target, turn off the movement motor. | 1087 | // If we are very close to our target, turn off the movement motor. |
1088 | if (_targetMotor.ErrorIsZero()) | 1088 | if (_targetMotor.ErrorIsZero()) |
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BulletSimTODO.txt b/OpenSim/Region/Physics/BulletSPlugin/BulletSimTODO.txt index 9bfec19..23b7ca8 100755 --- a/OpenSim/Region/Physics/BulletSPlugin/BulletSimTODO.txt +++ b/OpenSim/Region/Physics/BulletSPlugin/BulletSimTODO.txt | |||
@@ -74,7 +74,10 @@ Incorporate inter-relationship of angular corrections. For instance, angularDefl | |||
74 | GENERAL TODO LIST: | 74 | GENERAL TODO LIST: |
75 | ================================================= | 75 | ================================================= |
76 | Implement llSetPhysicalMaterial. | 76 | Implement llSetPhysicalMaterial. |
77 | extend it with Center-of-mass, rolling friction, density | ||
77 | Implement llSetForceAndTorque. | 78 | Implement llSetForceAndTorque. |
79 | Change BSPrim.moveToTarget to used forces rather than changing position | ||
80 | Changing position allows one to move through walls | ||
78 | Implement an avatar mesh shape. The Bullet capsule is way too limited. | 81 | Implement an avatar mesh shape. The Bullet capsule is way too limited. |
79 | Consider just hand creating a vertex/index array in a new BSShapeAvatar. | 82 | Consider just hand creating a vertex/index array in a new BSShapeAvatar. |
80 | Verify/fix phantom, volume-detect objects do not fall to infinity. Should stop at terrain. | 83 | Verify/fix phantom, volume-detect objects do not fall to infinity. Should stop at terrain. |