aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/Physics/BulletSPlugin
diff options
context:
space:
mode:
authorRobert Adams2012-11-24 20:01:34 -0800
committerRobert Adams2012-11-25 20:04:28 -0800
commit22d5bf8ff9942707c3e189aa31e1e253dc20603b (patch)
tree08e33b0249a063798213f5726d827255f3d5e266 /OpenSim/Region/Physics/BulletSPlugin
parentBulletSim: add terrain collision margin and vehicle angular damping (diff)
downloadopensim-SC_OLD-22d5bf8ff9942707c3e189aa31e1e253dc20603b.zip
opensim-SC_OLD-22d5bf8ff9942707c3e189aa31e1e253dc20603b.tar.gz
opensim-SC_OLD-22d5bf8ff9942707c3e189aa31e1e253dc20603b.tar.bz2
opensim-SC_OLD-22d5bf8ff9942707c3e189aa31e1e253dc20603b.tar.xz
BulletSim: complete vector motor. Correct line endings.
Diffstat (limited to 'OpenSim/Region/Physics/BulletSPlugin')
-rwxr-xr-xOpenSim/Region/Physics/BulletSPlugin/BSMotors.cs233
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 @@
1using System; 1using System;
2using System.Collections.Generic; 2using System.Collections.Generic;
3using System.Text; 3using System.Text;
4using OpenMetaverse; 4using OpenMetaverse;
5 5
6namespace OpenSim.Region.Physics.BulletSPlugin 6namespace OpenSim.Region.Physics.BulletSPlugin
7{ 7{
8public abstract class BSMotor 8public 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 }
14public 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; 31public 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
73public 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}
97public class BSPIDMotor : BSMotor 97
98{ 98public 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}
122public class BSPIDMotor : BSMotor
123{
124 // TODO: write and use this one
125 BSPIDMotor() : base()
126 {
127 }
128}
129}