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.
user_profiles
Robert Adams 2013-01-20 09:33:13 -08:00
parent 2c517d792f
commit 3b0df52d10
5 changed files with 36 additions and 38 deletions

View File

@ -198,7 +198,8 @@ public sealed class BSCharacter : BSPhysObject
// TODO: Decide if the step parameters should be changed depending on the avatar's // 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. // 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 falling, we keep the world's downward vector no matter what the other axis specify.
if (!Flying && !IsColliding) if (!Flying && !IsColliding)

View File

@ -957,39 +957,25 @@ namespace OpenSim.Region.Physics.BulletSPlugin
public void ComputeLinearVelocity(float pTimestep) 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 // Motor is vehicle coordinates. Rotate it to world coordinates
// coordinates. Rotate the movement to world coordinates. Vector3 linearMotorVelocity = linearMotorCorrection * VehicleOrientation;
Vector3 linearMotorVelocity = linearMotorStep * VehicleOrientation;
// If we're a ground vehicle, don't loose any Z action (like gravity acceleration). // If we're a ground vehicle, don't add any upward Z movement
float mixFactor = 1f; // 1 means use all linear motor Z value, 0 means use all existing Z
if ((m_flags & VehicleFlag.LIMIT_MOTOR_UP) != 0) if ((m_flags & VehicleFlag.LIMIT_MOTOR_UP) != 0)
{ {
if (!Prim.IsColliding) if (linearMotorVelocity.Z > 0f)
{ linearMotorVelocity.Z = 0f;
// 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;
}
linearMotorVelocity.Z = mixFactor * linearMotorVelocity.Z + (1f - mixFactor) * VehicleVelocity.Z;
// What we want to contribute to the vehicle's existing velocity // Add this correction to the velocity to make it faster/slower.
Vector3 linearMotorForce = linearMotorVelocity - VehicleVelocity; VehicleVelocity += linearMotorVelocity;
// Act against the inertia of the vehicle VDetailLog("{0}, MoveLinear,velocity,vehVel={1},correction={2},force={3}",
linearMotorForce *= m_vehicleMass; Prim.LocalID, VehicleVelocity, linearMotorCorrection, linearMotorVelocity);
VehicleAddForceImpulse(linearMotorForce * pTimestep);
VDetailLog("{0}, MoveLinear,velocity,vehVel={1},step={2},stepVel={3},mix={4},force={5}",
Prim.LocalID, VehicleVelocity, linearMotorStep, linearMotorVelocity, mixFactor, linearMotorForce);
} }
public void ComputeLinearTerrainHeightCorrection(float pTimestep) public void ComputeLinearTerrainHeightCorrection(float pTimestep)
@ -1204,6 +1190,7 @@ namespace OpenSim.Region.Physics.BulletSPlugin
{ {
// The user wants this many radians per second angular change? // The user wants this many radians per second angular change?
Vector3 angularMotorContribution = m_angularMotor.Step(pTimestep); Vector3 angularMotorContribution = m_angularMotor.Step(pTimestep);
angularMotorContribution = m_angularMotor.CurrentValue;
// ================================================================== // ==================================================================
// From http://wiki.secondlife.com/wiki/LlSetVehicleFlags : // From http://wiki.secondlife.com/wiki/LlSetVehicleFlags :
@ -1234,7 +1221,7 @@ namespace OpenSim.Region.Physics.BulletSPlugin
+ deflectionContribution + deflectionContribution
+ bankingContribution; + 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. // Convert to world coordinates.
m_lastAngularVelocity *= VehicleOrientation; m_lastAngularVelocity *= VehicleOrientation;

View File

@ -138,7 +138,8 @@ public class BSVMotor : BSMotor
CurrentValue = TargetValue = Vector3.Zero; 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) public virtual Vector3 Step(float timeStep)
{ {
if (!Enabled) return TargetValue; if (!Enabled) return TargetValue;
@ -150,7 +151,7 @@ public class BSVMotor : BSMotor
Vector3 error = TargetValue - CurrentValue; Vector3 error = TargetValue - CurrentValue;
if (!ErrorIsZero(error)) if (!ErrorIsZero(error))
{ {
correction = Step(timeStep, error); correction = StepError(timeStep, error);
CurrentValue += correction; CurrentValue += correction;
@ -187,14 +188,20 @@ public class BSVMotor : BSMotor
else else
{ {
// Difference between what we have and target is small. Motor is done. // 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}", MDetailLog("{0}, BSVMotor.Step,zero,{1},origTgt={2},origCurr={3},ret={4}",
BSScene.DetailLogZero, UseName, origCurrVal, origTarget, CurrentValue); BSScene.DetailLogZero, UseName, origCurrVal, origTarget, CurrentValue);
} }
return CurrentValue; return correction;
} }
public virtual Vector3 Step(float timeStep, Vector3 error) // 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 StepError(float timeStep, Vector3 error)
{ {
if (!Enabled) return Vector3.Zero; if (!Enabled) return Vector3.Zero;
@ -304,7 +311,7 @@ public class BSFMotor : BSMotor
float error = TargetValue - CurrentValue; float error = TargetValue - CurrentValue;
if (!ErrorIsZero(error)) if (!ErrorIsZero(error))
{ {
correction = Step(timeStep, error); correction = StepError(timeStep, error);
CurrentValue += correction; CurrentValue += correction;
@ -347,7 +354,7 @@ public class BSFMotor : BSMotor
return CurrentValue; return CurrentValue;
} }
public virtual float Step(float timeStep, float error) public virtual float StepError(float timeStep, float error)
{ {
if (!Enabled) return 0f; 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. // Advance the PID computation on this error.
public override Vector3 Step(float timeStep, Vector3 error) public override Vector3 StepError(float timeStep, Vector3 error)
{ {
if (!Enabled) return Vector3.Zero; if (!Enabled) return Vector3.Zero;

View File

@ -1082,7 +1082,7 @@ public sealed class BSPrim : BSPhysObject
OMV.Vector3 origPosition = RawPosition; // DEBUG DEBUG (for printout below) OMV.Vector3 origPosition = RawPosition; // DEBUG DEBUG (for printout below)
// 'movePosition' is where we'd like the prim to be at this moment. // '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 we are very close to our target, turn off the movement motor.
if (_targetMotor.ErrorIsZero()) if (_targetMotor.ErrorIsZero())

View File

@ -74,7 +74,10 @@ Incorporate inter-relationship of angular corrections. For instance, angularDefl
GENERAL TODO LIST: GENERAL TODO LIST:
================================================= =================================================
Implement llSetPhysicalMaterial. Implement llSetPhysicalMaterial.
extend it with Center-of-mass, rolling friction, density
Implement llSetForceAndTorque. 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. Implement an avatar mesh shape. The Bullet capsule is way too limited.
Consider just hand creating a vertex/index array in a new BSShapeAvatar. 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. Verify/fix phantom, volume-detect objects do not fall to infinity. Should stop at terrain.