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
// 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)

View File

@ -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;
}
if (linearMotorVelocity.Z > 0f)
linearMotorVelocity.Z = 0f;
}
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
Vector3 linearMotorForce = linearMotorVelocity - VehicleVelocity;
// Add this correction to the velocity to make it faster/slower.
VehicleVelocity += linearMotorVelocity;
// Act against the inertia of the vehicle
linearMotorForce *= m_vehicleMass;
VehicleAddForceImpulse(linearMotorForce * pTimestep);
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;

View File

@ -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;
}
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;
@ -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;

View File

@ -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())

View File

@ -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.