diff options
Diffstat (limited to 'OpenSim/Region/Physics/BulletSPlugin/BSMotors.cs')
-rwxr-xr-x | OpenSim/Region/Physics/BulletSPlugin/BSMotors.cs | 256 |
1 files changed, 152 insertions, 104 deletions
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSMotors.cs b/OpenSim/Region/Physics/BulletSPlugin/BSMotors.cs index bc6e4c4..480da2c 100755 --- a/OpenSim/Region/Physics/BulletSPlugin/BSMotors.cs +++ b/OpenSim/Region/Physics/BulletSPlugin/BSMotors.cs | |||
@@ -1,104 +1,152 @@ | |||
1 | using System; | 1 | using System; |
2 | using System.Collections.Generic; | 2 | using System.Collections.Generic; |
3 | using System.Text; | 3 | using System.Text; |
4 | using OpenMetaverse; | 4 | using OpenMetaverse; |
5 | 5 | ||
6 | namespace OpenSim.Region.Physics.BulletSPlugin | 6 | namespace OpenSim.Region.Physics.BulletSPlugin |
7 | { | 7 | { |
8 | public abstract class BSMotor | 8 | public abstract class BSMotor |
9 | { | 9 | { |
10 | public virtual void Reset() { } | 10 | public BSMotor(string useName) |
11 | public virtual void Zero() { } | 11 | { |
12 | } | 12 | UseName = useName; |
13 | // Can all the incremental stepping be replaced with motor classes? | 13 | PhysicsScene = null; |
14 | public class BSVMotor : BSMotor | 14 | } |
15 | { | 15 | public virtual void Reset() { } |
16 | public Vector3 FrameOfReference { get; set; } | 16 | public virtual void Zero() { } |
17 | public Vector3 Offset { get; set; } | 17 | |
18 | 18 | public string UseName { get; private set; } | |
19 | public float TimeScale { get; set; } | 19 | // Used only for outputting debug information. Might not be set so check for null. |
20 | public float TargetValueDecayTimeScale { get; set; } | 20 | public BSScene PhysicsScene { get; set; } |
21 | public Vector3 CurrentValueReductionTimescale { get; set; } | 21 | protected void MDetailLog(string msg, params Object[] parms) |
22 | public float Efficiency { get; set; } | 22 | { |
23 | 23 | if (PhysicsScene != null) | |
24 | public Vector3 TargetValue { get; private set; } | 24 | { |
25 | public Vector3 CurrentValue { get; private set; } | 25 | if (PhysicsScene.VehicleLoggingEnabled) |
26 | 26 | { | |
27 | 27 | PhysicsScene.DetailLog(msg, parms); | |
28 | 28 | } | |
29 | BSVMotor(float timeScale, float decayTimeScale, Vector3 frictionTimeScale, float efficiency) | 29 | } |
30 | { | 30 | } |
31 | TimeScale = timeScale; | 31 | } |
32 | TargetValueDecayTimeScale = decayTimeScale; | 32 | // Can all the incremental stepping be replaced with motor classes? |
33 | CurrentValueReductionTimescale = frictionTimeScale; | 33 | public class BSVMotor : BSMotor |
34 | Efficiency = efficiency; | 34 | { |
35 | } | 35 | public Vector3 FrameOfReference { get; set; } |
36 | public void SetCurrent(Vector3 current) | 36 | public Vector3 Offset { get; set; } |
37 | { | 37 | |
38 | CurrentValue = current; | 38 | public float TimeScale { get; set; } |
39 | } | 39 | public float TargetValueDecayTimeScale { get; set; } |
40 | public void SetTarget(Vector3 target) | 40 | public Vector3 FrictionTimescale { get; set; } |
41 | { | 41 | public float Efficiency { get; set; } |
42 | TargetValue = target; | 42 | |
43 | } | 43 | public Vector3 TargetValue { get; private set; } |
44 | public Vector3 Step(float timeStep) | 44 | public Vector3 CurrentValue { get; private set; } |
45 | { | 45 | |
46 | if (CurrentValue.LengthSquared() > 0.001f) | 46 | public BSVMotor(string useName) |
47 | { | 47 | : base(useName) |
48 | // Vector3 origDir = Target; // DEBUG | 48 | { |
49 | // Vector3 origVel = CurrentValue; // DEBUG | 49 | TimeScale = TargetValueDecayTimeScale = Efficiency = 1f; |
50 | 50 | FrictionTimescale = Vector3.Zero; | |
51 | // Add (desiredVelocity - currentAppliedVelocity) / howLongItShouldTakeToComplete | 51 | CurrentValue = TargetValue = Vector3.Zero; |
52 | Vector3 addAmount = (TargetValue - CurrentValue)/(TargetValue) * timeStep; | 52 | } |
53 | CurrentValue += addAmount; | 53 | public BSVMotor(string useName, float timeScale, float decayTimeScale, Vector3 frictionTimeScale, float efficiency) |
54 | 54 | : this(useName) | |
55 | float decayFactor = (1.0f / TargetValueDecayTimeScale) * timeStep; | 55 | { |
56 | TargetValue *= (1f - decayFactor); | 56 | TimeScale = timeScale; |
57 | 57 | TargetValueDecayTimeScale = decayTimeScale; | |
58 | Vector3 frictionFactor = (Vector3.One / CurrentValueReductionTimescale) * timeStep; | 58 | FrictionTimescale = frictionTimeScale; |
59 | CurrentValue *= (Vector3.One - frictionFactor); | 59 | Efficiency = efficiency; |
60 | } | 60 | CurrentValue = TargetValue = Vector3.Zero; |
61 | else | 61 | } |
62 | { | 62 | public void SetCurrent(Vector3 current) |
63 | // if what remains of direction is very small, zero it. | 63 | { |
64 | TargetValue = Vector3.Zero; | 64 | CurrentValue = current; |
65 | CurrentValue = Vector3.Zero; | 65 | } |
66 | 66 | public void SetTarget(Vector3 target) | |
67 | // VDetailLog("{0},MoveLinear,zeroed", Prim.LocalID); | 67 | { |
68 | } | 68 | TargetValue = target; |
69 | return CurrentValue; | 69 | } |
70 | } | 70 | public Vector3 Step(float timeStep) |
71 | } | 71 | { |
72 | 72 | Vector3 returnCurrent = Vector3.Zero; | |
73 | public class BSFMotor : BSMotor | 73 | if (!CurrentValue.ApproxEquals(TargetValue, 0.01f)) |
74 | { | 74 | { |
75 | public float TimeScale { get; set; } | 75 | Vector3 origTarget = TargetValue; // DEBUG |
76 | public float DecayTimeScale { get; set; } | 76 | Vector3 origCurrVal = CurrentValue; // DEBUG |
77 | public float Friction { get; set; } | 77 | |
78 | public float Efficiency { get; set; } | 78 | // Addition = (desiredVector - currentAppliedVector) / secondsItShouldTakeToComplete |
79 | 79 | Vector3 addAmount = (TargetValue - CurrentValue)/TimeScale * timeStep; | |
80 | public float Target { get; private set; } | 80 | CurrentValue += addAmount; |
81 | public float CurrentValue { get; private set; } | 81 | returnCurrent = CurrentValue; |
82 | 82 | ||
83 | BSFMotor(float timeScale, float decayTimescale, float friction, float efficiency) | 83 | // The desired value reduces to zero when also reduces the difference with current. |
84 | { | 84 | float decayFactor = (1.0f / TargetValueDecayTimeScale) * timeStep; |
85 | } | 85 | TargetValue *= (1f - decayFactor); |
86 | public void SetCurrent(float target) | 86 | |
87 | { | 87 | Vector3 frictionFactor = Vector3.Zero; |
88 | } | 88 | frictionFactor = (Vector3.One / FrictionTimescale) * timeStep; |
89 | public void SetTarget(float target) | 89 | CurrentValue *= (Vector3.One - frictionFactor); |
90 | { | 90 | |
91 | } | 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}", |
92 | public float Step(float timeStep) | 92 | BSScene.DetailLogZero, UseName, origTarget, origCurrVal, |
93 | { | 93 | timeStep, TimeScale, addAmount, |
94 | return 0f; | 94 | TargetValueDecayTimeScale, decayFactor, |
95 | } | 95 | FrictionTimescale, frictionFactor); |
96 | } | 96 | MDetailLog("{0},BSVMotor.Step,nonZero,{1},curr={2},target={3},add={4},decay={5},frict={6},ret={7}", |
97 | public class BSPIDMotor : BSMotor | 97 | BSScene.DetailLogZero, UseName, TargetValue, CurrentValue, |
98 | { | 98 | addAmount, decayFactor, frictionFactor, returnCurrent); |
99 | // TODO: write and use this one | 99 | } |
100 | BSPIDMotor() | 100 | else |
101 | { | 101 | { |
102 | } | 102 | // Difference between what we have and target is small. Motor is done. |
103 | } | 103 | CurrentValue = Vector3.Zero; |
104 | } | 104 | TargetValue = Vector3.Zero; |
105 | |||
106 | MDetailLog("{0},BSVMotor.Step,zero,{1},curr={2},target={3},ret={4}", | ||
107 | BSScene.DetailLogZero, UseName, TargetValue, CurrentValue, returnCurrent); | ||
108 | |||
109 | } | ||
110 | return returnCurrent; | ||
111 | } | ||
112 | public override string ToString() | ||
113 | { | ||
114 | return String.Format("<{0},curr={1},targ={2},decayTS={3},frictTS={4}>", | ||
115 | UseName, CurrentValue, TargetValue, TargetValueDecayTimeScale, FrictionTimescale); | ||
116 | } | ||
117 | } | ||
118 | |||
119 | public class BSFMotor : BSMotor | ||
120 | { | ||
121 | public float TimeScale { get; set; } | ||
122 | public float DecayTimeScale { get; set; } | ||
123 | public float Friction { get; set; } | ||
124 | public float Efficiency { get; set; } | ||
125 | |||
126 | public float Target { get; private set; } | ||
127 | public float CurrentValue { get; private set; } | ||
128 | |||
129 | public BSFMotor(string useName, float timeScale, float decayTimescale, float friction, float efficiency) | ||
130 | : base(useName) | ||
131 | { | ||
132 | } | ||
133 | public void SetCurrent(float target) | ||
134 | { | ||
135 | } | ||
136 | public void SetTarget(float target) | ||
137 | { | ||
138 | } | ||
139 | public float Step(float timeStep) | ||
140 | { | ||
141 | return 0f; | ||
142 | } | ||
143 | } | ||
144 | public class BSPIDMotor : BSMotor | ||
145 | { | ||
146 | // TODO: write and use this one | ||
147 | public BSPIDMotor(string useName) | ||
148 | : base(useName) | ||
149 | { | ||
150 | } | ||
151 | } | ||
152 | } | ||