From 3b0df52d10c157cd2711d64ef9007d2afccbd468 Mon Sep 17 00:00:00 2001 From: Robert Adams Date: Sun, 20 Jan 2013 09:33:13 -0800 Subject: 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. --- .../Region/Physics/BulletSPlugin/BSCharacter.cs | 3 +- OpenSim/Region/Physics/BulletSPlugin/BSDynamics.cs | 41 ++++++++-------------- OpenSim/Region/Physics/BulletSPlugin/BSMotors.cs | 25 ++++++++----- OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs | 2 +- .../Region/Physics/BulletSPlugin/BulletSimTODO.txt | 3 ++ 5 files changed, 36 insertions(+), 38 deletions(-) (limited to 'OpenSim/Region') 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 // TODO: Decide if the step parameters should be changed depending on the avatar's // state (flying, colliding, ...). There is code in ODE to do this. - OMV.Vector3 stepVelocity = _velocityMotor.Step(timeStep); + _velocityMotor.Step(timeStep); + OMV.Vector3 stepVelocity = _velocityMotor.CurrentValue; // If falling, we keep the world's downward vector no matter what the other axis specify. 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 public void ComputeLinearVelocity(float pTimestep) { - Vector3 linearMotorStep = m_linearMotor.Step(pTimestep); + // Step the motor from the current value. Get the correction needed this step. + Vector3 currentVel = VehicleVelocity * Quaternion.Inverse(VehicleOrientation); + Vector3 linearMotorCorrection = m_linearMotor.Step(pTimestep, currentVel); - // The movement computed in the linear motor is relative to the vehicle - // coordinates. Rotate the movement to world coordinates. - Vector3 linearMotorVelocity = linearMotorStep * VehicleOrientation; + // Motor is vehicle coordinates. Rotate it to world coordinates + Vector3 linearMotorVelocity = linearMotorCorrection * VehicleOrientation; - // If we're a ground vehicle, don't loose any Z action (like gravity acceleration). - float mixFactor = 1f; // 1 means use all linear motor Z value, 0 means use all existing Z + // If we're a ground vehicle, don't add any upward Z movement if ((m_flags & VehicleFlag.LIMIT_MOTOR_UP) != 0) { - if (!Prim.IsColliding) - { - // If a ground vehicle and not on the ground, I want gravity effect - mixFactor = 0.2f; - } - } - else - { - // I'm not a ground vehicle but don't totally loose the effect of the environment - mixFactor = 0.8f; + if (linearMotorVelocity.Z > 0f) + linearMotorVelocity.Z = 0f; } - linearMotorVelocity.Z = mixFactor * linearMotorVelocity.Z + (1f - mixFactor) * VehicleVelocity.Z; - - // What we want to contribute to the vehicle's existing velocity - Vector3 linearMotorForce = linearMotorVelocity - VehicleVelocity; - - // Act against the inertia of the vehicle - linearMotorForce *= m_vehicleMass; - VehicleAddForceImpulse(linearMotorForce * pTimestep); + // Add this correction to the velocity to make it faster/slower. + VehicleVelocity += linearMotorVelocity; - VDetailLog("{0}, MoveLinear,velocity,vehVel={1},step={2},stepVel={3},mix={4},force={5}", - Prim.LocalID, VehicleVelocity, linearMotorStep, linearMotorVelocity, mixFactor, linearMotorForce); + VDetailLog("{0}, MoveLinear,velocity,vehVel={1},correction={2},force={3}", + Prim.LocalID, VehicleVelocity, linearMotorCorrection, linearMotorVelocity); } public void ComputeLinearTerrainHeightCorrection(float pTimestep) @@ -1204,6 +1190,7 @@ namespace OpenSim.Region.Physics.BulletSPlugin { // The user wants this many radians per second angular change? Vector3 angularMotorContribution = m_angularMotor.Step(pTimestep); + angularMotorContribution = m_angularMotor.CurrentValue; // ================================================================== // From http://wiki.secondlife.com/wiki/LlSetVehicleFlags : @@ -1234,7 +1221,7 @@ namespace OpenSim.Region.Physics.BulletSPlugin + deflectionContribution + bankingContribution; - // Add of the above computation are made relative to vehicle coordinates. + // All of the above computation are made relative to vehicle coordinates. // Convert to world coordinates. m_lastAngularVelocity *= VehicleOrientation; 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 CurrentValue = TargetValue = Vector3.Zero; } - // Compute the next step and return the new current value + // Compute the next step and return the new current value. + // Returns the correction needed to move 'current' to 'target'. public virtual Vector3 Step(float timeStep) { if (!Enabled) return TargetValue; @@ -150,7 +151,7 @@ public class BSVMotor : BSMotor Vector3 error = TargetValue - CurrentValue; if (!ErrorIsZero(error)) { - correction = Step(timeStep, error); + correction = StepError(timeStep, error); CurrentValue += correction; @@ -187,14 +188,20 @@ public class BSVMotor : BSMotor else { // Difference between what we have and target is small. Motor is done. - CurrentValue = TargetValue; + CurrentValue = TargetValue = Vector3.Zero; MDetailLog("{0}, BSVMotor.Step,zero,{1},origTgt={2},origCurr={3},ret={4}", BSScene.DetailLogZero, UseName, origCurrVal, origTarget, CurrentValue); } - return CurrentValue; + return correction; + } + // version of step that sets the current value before doing the step + public virtual Vector3 Step(float timeStep, Vector3 current) + { + CurrentValue = current; + return Step(timeStep); } - public virtual Vector3 Step(float timeStep, Vector3 error) + public virtual Vector3 StepError(float timeStep, Vector3 error) { if (!Enabled) return Vector3.Zero; @@ -304,7 +311,7 @@ public class BSFMotor : BSMotor float error = TargetValue - CurrentValue; if (!ErrorIsZero(error)) { - correction = Step(timeStep, error); + correction = StepError(timeStep, error); CurrentValue += correction; @@ -347,7 +354,7 @@ public class BSFMotor : BSMotor return CurrentValue; } - public virtual float Step(float timeStep, float error) + public virtual float StepError(float timeStep, float error) { if (!Enabled) return 0f; @@ -440,8 +447,8 @@ public class BSPIDVMotor : BSVMotor } } - // Ignore Current and Target Values and just advance the PID computation on this error. - public override Vector3 Step(float timeStep, Vector3 error) + // Advance the PID computation on this error. + public override Vector3 StepError(float timeStep, Vector3 error) { if (!Enabled) return Vector3.Zero; 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 OMV.Vector3 origPosition = RawPosition; // DEBUG DEBUG (for printout below) // 'movePosition' is where we'd like the prim to be at this moment. - OMV.Vector3 movePosition = _targetMotor.Step(timeStep); + OMV.Vector3 movePosition = RawPosition + _targetMotor.Step(timeStep); // If we are very close to our target, turn off the movement motor. 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 GENERAL TODO LIST: ================================================= Implement llSetPhysicalMaterial. + extend it with Center-of-mass, rolling friction, density Implement llSetForceAndTorque. +Change BSPrim.moveToTarget to used forces rather than changing position + Changing position allows one to move through walls Implement an avatar mesh shape. The Bullet capsule is way too limited. Consider just hand creating a vertex/index array in a new BSShapeAvatar. Verify/fix phantom, volume-detect objects do not fall to infinity. Should stop at terrain. -- cgit v1.1