diff options
Diffstat (limited to 'OpenSim/Region/Physics/BulletSPlugin/BSMotors.cs')
-rwxr-xr-x | OpenSim/Region/Physics/BulletSPlugin/BSMotors.cs | 46 |
1 files changed, 32 insertions, 14 deletions
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSMotors.cs b/OpenSim/Region/Physics/BulletSPlugin/BSMotors.cs index b8bdd87..68eec2d 100755 --- a/OpenSim/Region/Physics/BulletSPlugin/BSMotors.cs +++ b/OpenSim/Region/Physics/BulletSPlugin/BSMotors.cs | |||
@@ -7,13 +7,15 @@ namespace OpenSim.Region.Physics.BulletSPlugin | |||
7 | { | 7 | { |
8 | public abstract class BSMotor | 8 | public abstract class BSMotor |
9 | { | 9 | { |
10 | public BSMotor() | 10 | public BSMotor(string useName) |
11 | { | 11 | { |
12 | UseName = useName; | ||
12 | PhysicsScene = null; | 13 | PhysicsScene = null; |
13 | } | 14 | } |
14 | public virtual void Reset() { } | 15 | public virtual void Reset() { } |
15 | public virtual void Zero() { } | 16 | public virtual void Zero() { } |
16 | 17 | ||
18 | public string UseName { get; private set; } | ||
17 | // Used only for outputting debug information. Might not be set so check for null. | 19 | // Used only for outputting debug information. Might not be set so check for null. |
18 | public BSScene PhysicsScene { get; set; } | 20 | public BSScene PhysicsScene { get; set; } |
19 | protected void MDetailLog(string msg, params Object[] parms) | 21 | protected void MDetailLog(string msg, params Object[] parms) |
@@ -35,17 +37,25 @@ public class BSVMotor : BSMotor | |||
35 | 37 | ||
36 | public float TimeScale { get; set; } | 38 | public float TimeScale { get; set; } |
37 | public float TargetValueDecayTimeScale { get; set; } | 39 | public float TargetValueDecayTimeScale { get; set; } |
38 | public Vector3 CurrentValueReductionTimescale { get; set; } | 40 | public Vector3 FrictionTimescale { get; set; } |
39 | public float Efficiency { get; set; } | 41 | public float Efficiency { get; set; } |
40 | 42 | ||
41 | public Vector3 TargetValue { get; private set; } | 43 | public Vector3 TargetValue { get; private set; } |
42 | public Vector3 CurrentValue { get; private set; } | 44 | public Vector3 CurrentValue { get; private set; } |
43 | 45 | ||
44 | BSVMotor(float timeScale, float decayTimeScale, Vector3 frictionTimeScale, float efficiency) : base() | 46 | public BSVMotor(string useName) |
47 | : base(useName) | ||
48 | { | ||
49 | TimeScale = TargetValueDecayTimeScale = Efficiency = 1f; | ||
50 | FrictionTimescale = Vector3.Zero; | ||
51 | CurrentValue = TargetValue = Vector3.Zero; | ||
52 | } | ||
53 | public BSVMotor(string useName, float timeScale, float decayTimeScale, Vector3 frictionTimeScale, float efficiency) | ||
54 | : this(useName) | ||
45 | { | 55 | { |
46 | TimeScale = timeScale; | 56 | TimeScale = timeScale; |
47 | TargetValueDecayTimeScale = decayTimeScale; | 57 | TargetValueDecayTimeScale = decayTimeScale; |
48 | CurrentValueReductionTimescale = frictionTimeScale; | 58 | FrictionTimescale = frictionTimeScale; |
49 | Efficiency = efficiency; | 59 | Efficiency = efficiency; |
50 | CurrentValue = TargetValue = Vector3.Zero; | 60 | CurrentValue = TargetValue = Vector3.Zero; |
51 | } | 61 | } |
@@ -60,10 +70,10 @@ public class BSVMotor : BSMotor | |||
60 | public Vector3 Step(float timeStep) | 70 | public Vector3 Step(float timeStep) |
61 | { | 71 | { |
62 | Vector3 returnCurrent = Vector3.Zero; | 72 | Vector3 returnCurrent = Vector3.Zero; |
63 | if (CurrentValue.LengthSquared() > 0.001f) | 73 | if (!CurrentValue.ApproxEquals(TargetValue, 0.01f)) |
64 | { | 74 | { |
65 | // Vector3 origDir = Target; // DEBUG | 75 | Vector3 origTarget = TargetValue; // DEBUG |
66 | // Vector3 origVel = CurrentValue; // DEBUG | 76 | Vector3 origCurrVal = CurrentValue; // DEBUG |
67 | 77 | ||
68 | // Add (desiredVector - currentAppliedVector) / howLongItShouldTakeToComplete | 78 | // Add (desiredVector - currentAppliedVector) / howLongItShouldTakeToComplete |
69 | Vector3 addAmount = (TargetValue - CurrentValue)/TimeScale * timeStep; | 79 | Vector3 addAmount = (TargetValue - CurrentValue)/TimeScale * timeStep; |
@@ -74,11 +84,17 @@ public class BSVMotor : BSMotor | |||
74 | float decayFactor = (1.0f / TargetValueDecayTimeScale) * timeStep; | 84 | float decayFactor = (1.0f / TargetValueDecayTimeScale) * timeStep; |
75 | TargetValue *= (1f - decayFactor); | 85 | TargetValue *= (1f - decayFactor); |
76 | 86 | ||
77 | Vector3 frictionFactor = (Vector3.One / CurrentValueReductionTimescale) * timeStep; | 87 | Vector3 frictionFactor = Vector3.Zero; |
88 | frictionFactor = (Vector3.One / FrictionTimescale) * timeStep; | ||
78 | CurrentValue *= (Vector3.One - frictionFactor); | 89 | CurrentValue *= (Vector3.One - frictionFactor); |
79 | 90 | ||
80 | MDetailLog("{0},BSVMotor.Step,nonZero,curr={1},target={2},add={3},decay={4},frict={5},ret={6}", | 91 | MDetailLog("{0},BSVMotor.Step,nonZero,{1},origTarget={2},origCurr={3},timeStep={4},timeScale={5},addAmnt={6},targetDecay={7},decayFact={8},fricTS={9},frictFact={10}", |
81 | BSScene.DetailLogZero, TargetValue, CurrentValue, | 92 | BSScene.DetailLogZero, UseName, origTarget, origCurrVal, |
93 | timeStep, TimeScale, addAmount, | ||
94 | TargetValueDecayTimeScale, decayFactor, | ||
95 | FrictionTimescale, frictionFactor); | ||
96 | MDetailLog("{0},BSVMotor.Step,nonZero,{1},curr={2},target={3},add={4},decay={5},frict={6},ret={7}", | ||
97 | BSScene.DetailLogZero, UseName, TargetValue, CurrentValue, | ||
82 | addAmount, decayFactor, frictionFactor, returnCurrent); | 98 | addAmount, decayFactor, frictionFactor, returnCurrent); |
83 | } | 99 | } |
84 | else | 100 | else |
@@ -87,8 +103,8 @@ public class BSVMotor : BSMotor | |||
87 | CurrentValue = Vector3.Zero; | 103 | CurrentValue = Vector3.Zero; |
88 | TargetValue = Vector3.Zero; | 104 | TargetValue = Vector3.Zero; |
89 | 105 | ||
90 | MDetailLog("{0},BSVMotor.Step,zero,curr={1},target={2},ret={3}", | 106 | MDetailLog("{0},BSVMotor.Step,zero,{1},curr={2},target={3},ret={4}", |
91 | BSScene.DetailLogZero, TargetValue, CurrentValue, returnCurrent); | 107 | BSScene.DetailLogZero, UseName, TargetValue, CurrentValue, returnCurrent); |
92 | 108 | ||
93 | } | 109 | } |
94 | return returnCurrent; | 110 | return returnCurrent; |
@@ -105,7 +121,8 @@ public class BSFMotor : BSMotor | |||
105 | public float Target { get; private set; } | 121 | public float Target { get; private set; } |
106 | public float CurrentValue { get; private set; } | 122 | public float CurrentValue { get; private set; } |
107 | 123 | ||
108 | BSFMotor(float timeScale, float decayTimescale, float friction, float efficiency) : base() | 124 | public BSFMotor(string useName, float timeScale, float decayTimescale, float friction, float efficiency) |
125 | : base(useName) | ||
109 | { | 126 | { |
110 | } | 127 | } |
111 | public void SetCurrent(float target) | 128 | public void SetCurrent(float target) |
@@ -122,7 +139,8 @@ public class BSFMotor : BSMotor | |||
122 | public class BSPIDMotor : BSMotor | 139 | public class BSPIDMotor : BSMotor |
123 | { | 140 | { |
124 | // TODO: write and use this one | 141 | // TODO: write and use this one |
125 | BSPIDMotor() : base() | 142 | public BSPIDMotor(string useName) |
143 | : base(useName) | ||
126 | { | 144 | { |
127 | } | 145 | } |
128 | } | 146 | } |