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