BulletSim: complete vector motor. Correct line endings.

connector_plugin^2
Robert Adams 2012-11-24 20:01:34 -08:00
parent d1480ac7ee
commit 22d5bf8ff9
1 changed files with 129 additions and 104 deletions

View File

@ -1,104 +1,129 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Text; using System.Text;
using OpenMetaverse; using OpenMetaverse;
namespace OpenSim.Region.Physics.BulletSPlugin namespace OpenSim.Region.Physics.BulletSPlugin
{ {
public abstract class BSMotor public abstract class BSMotor
{ {
public virtual void Reset() { } public BSMotor()
public virtual void Zero() { } {
} PhysicsScene = null;
// Can all the incremental stepping be replaced with motor classes? }
public class BSVMotor : BSMotor public virtual void Reset() { }
{ public virtual void Zero() { }
public Vector3 FrameOfReference { get; set; }
public Vector3 Offset { get; set; } // Used only for outputting debug information. Might not be set so check for null.
public BSScene PhysicsScene { get; set; }
public float TimeScale { get; set; } protected void MDetailLog(string msg, params Object[] parms)
public float TargetValueDecayTimeScale { get; set; } {
public Vector3 CurrentValueReductionTimescale { get; set; } if (PhysicsScene != null)
public float Efficiency { get; set; } {
if (PhysicsScene.VehicleLoggingEnabled)
public Vector3 TargetValue { get; private set; } {
public Vector3 CurrentValue { get; private set; } PhysicsScene.DetailLog(msg, parms);
}
}
}
BSVMotor(float timeScale, float decayTimeScale, Vector3 frictionTimeScale, float efficiency) }
{ // Can all the incremental stepping be replaced with motor classes?
TimeScale = timeScale; public class BSVMotor : BSMotor
TargetValueDecayTimeScale = decayTimeScale; {
CurrentValueReductionTimescale = frictionTimeScale; public Vector3 FrameOfReference { get; set; }
Efficiency = efficiency; public Vector3 Offset { get; set; }
}
public void SetCurrent(Vector3 current) public float TimeScale { get; set; }
{ public float TargetValueDecayTimeScale { get; set; }
CurrentValue = current; public Vector3 CurrentValueReductionTimescale { get; set; }
} public float Efficiency { get; set; }
public void SetTarget(Vector3 target)
{ public Vector3 TargetValue { get; private set; }
TargetValue = target; public Vector3 CurrentValue { get; private set; }
}
public Vector3 Step(float timeStep) BSVMotor(float timeScale, float decayTimeScale, Vector3 frictionTimeScale, float efficiency) : base()
{ {
if (CurrentValue.LengthSquared() > 0.001f) TimeScale = timeScale;
{ TargetValueDecayTimeScale = decayTimeScale;
// Vector3 origDir = Target; // DEBUG CurrentValueReductionTimescale = frictionTimeScale;
// Vector3 origVel = CurrentValue; // DEBUG Efficiency = efficiency;
CurrentValue = TargetValue = Vector3.Zero;
// Add (desiredVelocity - currentAppliedVelocity) / howLongItShouldTakeToComplete }
Vector3 addAmount = (TargetValue - CurrentValue)/(TargetValue) * timeStep; public void SetCurrent(Vector3 current)
CurrentValue += addAmount; {
CurrentValue = current;
float decayFactor = (1.0f / TargetValueDecayTimeScale) * timeStep; }
TargetValue *= (1f - decayFactor); public void SetTarget(Vector3 target)
{
Vector3 frictionFactor = (Vector3.One / CurrentValueReductionTimescale) * timeStep; TargetValue = target;
CurrentValue *= (Vector3.One - frictionFactor); }
} public Vector3 Step(float timeStep)
else {
{ Vector3 returnCurrent = Vector3.Zero;
// if what remains of direction is very small, zero it. if (CurrentValue.LengthSquared() > 0.001f)
TargetValue = Vector3.Zero; {
CurrentValue = Vector3.Zero; // Vector3 origDir = Target; // DEBUG
// Vector3 origVel = CurrentValue; // DEBUG
// VDetailLog("{0},MoveLinear,zeroed", Prim.LocalID);
} // Add (desiredVector - currentAppliedVector) / howLongItShouldTakeToComplete
return CurrentValue; Vector3 addAmount = (TargetValue - CurrentValue)/TimeScale * timeStep;
} CurrentValue += addAmount;
} returnCurrent = CurrentValue;
public class BSFMotor : BSMotor // The desired value reduces to zero when also reduces the difference with current.
{ float decayFactor = (1.0f / TargetValueDecayTimeScale) * timeStep;
public float TimeScale { get; set; } TargetValue *= (1f - decayFactor);
public float DecayTimeScale { get; set; }
public float Friction { get; set; } Vector3 frictionFactor = (Vector3.One / CurrentValueReductionTimescale) * timeStep;
public float Efficiency { get; set; } CurrentValue *= (Vector3.One - frictionFactor);
public float Target { get; private set; } MDetailLog("{0},BSVMotor.Step,nonZero,curr={1},target={2},add={3},decay={4},frict={5},ret={6}",
public float CurrentValue { get; private set; } BSScene.DetailLogZero, TargetValue, CurrentValue,
addAmount, decayFactor, frictionFactor, returnCurrent);
BSFMotor(float timeScale, float decayTimescale, float friction, float efficiency) }
{ else
} {
public void SetCurrent(float target) // Difference between what we have and target is small. Motor is done.
{ CurrentValue = Vector3.Zero;
} TargetValue = Vector3.Zero;
public void SetTarget(float target)
{ MDetailLog("{0},BSVMotor.Step,zero,curr={1},target={2},ret={3}",
} BSScene.DetailLogZero, TargetValue, CurrentValue, returnCurrent);
public float Step(float timeStep)
{ }
return 0f; return returnCurrent;
} }
} }
public class BSPIDMotor : BSMotor
{ public class BSFMotor : BSMotor
// TODO: write and use this one {
BSPIDMotor() public float TimeScale { get; set; }
{ public float DecayTimeScale { get; set; }
} public float Friction { get; set; }
} public float Efficiency { get; set; }
}
public float Target { get; private set; }
public float CurrentValue { get; private set; }
BSFMotor(float timeScale, float decayTimescale, float friction, float efficiency) : base()
{
}
public void SetCurrent(float target)
{
}
public void SetTarget(float target)
{
}
public float Step(float timeStep)
{
return 0f;
}
}
public class BSPIDMotor : BSMotor
{
// TODO: write and use this one
BSPIDMotor() : base()
{
}
}
}