diff options
author | Robert Adams | 2013-05-06 13:29:19 -0700 |
---|---|---|
committer | Robert Adams | 2013-05-06 13:32:26 -0700 |
commit | 045aaa838ac0a6e129ff1d8ec65053508df1d51a (patch) | |
tree | dd164b3b646725d5a5f1ea9b1aebafb68a512059 | |
parent | BulletSim: simplify parameter specification by reducing the number of (diff) | |
download | opensim-SC-045aaa838ac0a6e129ff1d8ec65053508df1d51a.zip opensim-SC-045aaa838ac0a6e129ff1d8ec65053508df1d51a.tar.gz opensim-SC-045aaa838ac0a6e129ff1d8ec65053508df1d51a.tar.bz2 opensim-SC-045aaa838ac0a6e129ff1d8ec65053508df1d51a.tar.xz |
BulletSim: remove friction calcuation from BSMotor and move linear and
angular friction computation into linear and angular movement code.
The friction wasn't being applied properly. This will make it so vehicles
don't drift as much and the drift is tunable by changing the friction
timescales.
Diffstat (limited to '')
7 files changed, 47 insertions, 67 deletions
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSActorAvatarMove.cs b/OpenSim/Region/Physics/BulletSPlugin/BSActorAvatarMove.cs index 4e067b5..ac8c30c 100755 --- a/OpenSim/Region/Physics/BulletSPlugin/BSActorAvatarMove.cs +++ b/OpenSim/Region/Physics/BulletSPlugin/BSActorAvatarMove.cs | |||
@@ -118,7 +118,6 @@ public class BSActorAvatarMove : BSActor | |||
118 | m_velocityMotor = new BSVMotor("BSCharacter.Velocity", | 118 | m_velocityMotor = new BSVMotor("BSCharacter.Velocity", |
119 | 0.2f, // time scale | 119 | 0.2f, // time scale |
120 | BSMotor.Infinite, // decay time scale | 120 | BSMotor.Infinite, // decay time scale |
121 | BSMotor.InfiniteVector, // friction timescale | ||
122 | 1f // efficiency | 121 | 1f // efficiency |
123 | ); | 122 | ); |
124 | // _velocityMotor.PhysicsScene = PhysicsScene; // DEBUG DEBUG so motor will output detail log messages. | 123 | // _velocityMotor.PhysicsScene = PhysicsScene; // DEBUG DEBUG so motor will output detail log messages. |
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSActorHover.cs b/OpenSim/Region/Physics/BulletSPlugin/BSActorHover.cs index 3630ca8..8a79809 100755 --- a/OpenSim/Region/Physics/BulletSPlugin/BSActorHover.cs +++ b/OpenSim/Region/Physics/BulletSPlugin/BSActorHover.cs | |||
@@ -102,7 +102,6 @@ public class BSActorHover : BSActor | |||
102 | m_hoverMotor = new BSFMotor("BSActorHover", | 102 | m_hoverMotor = new BSFMotor("BSActorHover", |
103 | m_controllingPrim.HoverTau, // timeScale | 103 | m_controllingPrim.HoverTau, // timeScale |
104 | BSMotor.Infinite, // decay time scale | 104 | BSMotor.Infinite, // decay time scale |
105 | BSMotor.Infinite, // friction timescale | ||
106 | 1f // efficiency | 105 | 1f // efficiency |
107 | ); | 106 | ); |
108 | m_hoverMotor.SetTarget(ComputeCurrentHoverHeight()); | 107 | m_hoverMotor.SetTarget(ComputeCurrentHoverHeight()); |
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSActorMoveToTarget.cs b/OpenSim/Region/Physics/BulletSPlugin/BSActorMoveToTarget.cs index 1b598fd..75ff24e 100755 --- a/OpenSim/Region/Physics/BulletSPlugin/BSActorMoveToTarget.cs +++ b/OpenSim/Region/Physics/BulletSPlugin/BSActorMoveToTarget.cs | |||
@@ -105,7 +105,6 @@ public class BSActorMoveToTarget : BSActor | |||
105 | m_targetMotor = new BSVMotor("BSActorMoveToTargget.Activate", | 105 | m_targetMotor = new BSVMotor("BSActorMoveToTargget.Activate", |
106 | m_controllingPrim.MoveToTargetTau, // timeScale | 106 | m_controllingPrim.MoveToTargetTau, // timeScale |
107 | BSMotor.Infinite, // decay time scale | 107 | BSMotor.Infinite, // decay time scale |
108 | BSMotor.InfiniteVector, // friction timescale | ||
109 | 1f // efficiency | 108 | 1f // efficiency |
110 | ); | 109 | ); |
111 | m_targetMotor.PhysicsScene = m_physicsScene; // DEBUG DEBUG so motor will output detail log messages. | 110 | m_targetMotor.PhysicsScene = m_physicsScene; // DEBUG DEBUG so motor will output detail log messages. |
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSActorSetForce.cs b/OpenSim/Region/Physics/BulletSPlugin/BSActorSetForce.cs index c0f40fd..96fa0b6 100755 --- a/OpenSim/Region/Physics/BulletSPlugin/BSActorSetForce.cs +++ b/OpenSim/Region/Physics/BulletSPlugin/BSActorSetForce.cs | |||
@@ -101,7 +101,7 @@ public class BSActorSetForce : BSActor | |||
101 | if (m_forceMotor == null) | 101 | if (m_forceMotor == null) |
102 | { | 102 | { |
103 | // A fake motor that might be used someday | 103 | // A fake motor that might be used someday |
104 | m_forceMotor = new BSFMotor("setForce", 1f, 1f, 1f, 1f); | 104 | m_forceMotor = new BSFMotor("setForce", 1f, 1f, 1f); |
105 | 105 | ||
106 | m_physicsScene.BeforeStep += Mover; | 106 | m_physicsScene.BeforeStep += Mover; |
107 | } | 107 | } |
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSActorSetTorque.cs b/OpenSim/Region/Physics/BulletSPlugin/BSActorSetTorque.cs index b3806e1..65098e1 100755 --- a/OpenSim/Region/Physics/BulletSPlugin/BSActorSetTorque.cs +++ b/OpenSim/Region/Physics/BulletSPlugin/BSActorSetTorque.cs | |||
@@ -101,7 +101,7 @@ public class BSActorSetTorque : BSActor | |||
101 | if (m_torqueMotor == null) | 101 | if (m_torqueMotor == null) |
102 | { | 102 | { |
103 | // A fake motor that might be used someday | 103 | // A fake motor that might be used someday |
104 | m_torqueMotor = new BSFMotor("setTorque", 1f, 1f, 1f, 1f); | 104 | m_torqueMotor = new BSFMotor("setTorque", 1f, 1f, 1f); |
105 | 105 | ||
106 | m_physicsScene.BeforeStep += Mover; | 106 | m_physicsScene.BeforeStep += Mover; |
107 | } | 107 | } |
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSDynamics.cs b/OpenSim/Region/Physics/BulletSPlugin/BSDynamics.cs index 0dd2aa5..272a162 100644 --- a/OpenSim/Region/Physics/BulletSPlugin/BSDynamics.cs +++ b/OpenSim/Region/Physics/BulletSPlugin/BSDynamics.cs | |||
@@ -235,7 +235,6 @@ namespace OpenSim.Region.Physics.BulletSPlugin | |||
235 | // set all of the components to the same value | 235 | // set all of the components to the same value |
236 | case Vehicle.ANGULAR_FRICTION_TIMESCALE: | 236 | case Vehicle.ANGULAR_FRICTION_TIMESCALE: |
237 | m_angularFrictionTimescale = new Vector3(pValue, pValue, pValue); | 237 | m_angularFrictionTimescale = new Vector3(pValue, pValue, pValue); |
238 | m_angularMotor.FrictionTimescale = m_angularFrictionTimescale; | ||
239 | break; | 238 | break; |
240 | case Vehicle.ANGULAR_MOTOR_DIRECTION: | 239 | case Vehicle.ANGULAR_MOTOR_DIRECTION: |
241 | m_angularMotorDirection = new Vector3(pValue, pValue, pValue); | 240 | m_angularMotorDirection = new Vector3(pValue, pValue, pValue); |
@@ -244,7 +243,6 @@ namespace OpenSim.Region.Physics.BulletSPlugin | |||
244 | break; | 243 | break; |
245 | case Vehicle.LINEAR_FRICTION_TIMESCALE: | 244 | case Vehicle.LINEAR_FRICTION_TIMESCALE: |
246 | m_linearFrictionTimescale = new Vector3(pValue, pValue, pValue); | 245 | m_linearFrictionTimescale = new Vector3(pValue, pValue, pValue); |
247 | m_linearMotor.FrictionTimescale = m_linearFrictionTimescale; | ||
248 | break; | 246 | break; |
249 | case Vehicle.LINEAR_MOTOR_DIRECTION: | 247 | case Vehicle.LINEAR_MOTOR_DIRECTION: |
250 | m_linearMotorDirection = new Vector3(pValue, pValue, pValue); | 248 | m_linearMotorDirection = new Vector3(pValue, pValue, pValue); |
@@ -265,7 +263,6 @@ namespace OpenSim.Region.Physics.BulletSPlugin | |||
265 | { | 263 | { |
266 | case Vehicle.ANGULAR_FRICTION_TIMESCALE: | 264 | case Vehicle.ANGULAR_FRICTION_TIMESCALE: |
267 | m_angularFrictionTimescale = new Vector3(pValue.X, pValue.Y, pValue.Z); | 265 | m_angularFrictionTimescale = new Vector3(pValue.X, pValue.Y, pValue.Z); |
268 | m_angularMotor.FrictionTimescale = m_angularFrictionTimescale; | ||
269 | break; | 266 | break; |
270 | case Vehicle.ANGULAR_MOTOR_DIRECTION: | 267 | case Vehicle.ANGULAR_MOTOR_DIRECTION: |
271 | // Limit requested angular speed to 2 rps= 4 pi rads/sec | 268 | // Limit requested angular speed to 2 rps= 4 pi rads/sec |
@@ -278,7 +275,6 @@ namespace OpenSim.Region.Physics.BulletSPlugin | |||
278 | break; | 275 | break; |
279 | case Vehicle.LINEAR_FRICTION_TIMESCALE: | 276 | case Vehicle.LINEAR_FRICTION_TIMESCALE: |
280 | m_linearFrictionTimescale = new Vector3(pValue.X, pValue.Y, pValue.Z); | 277 | m_linearFrictionTimescale = new Vector3(pValue.X, pValue.Y, pValue.Z); |
281 | m_linearMotor.FrictionTimescale = m_linearFrictionTimescale; | ||
282 | break; | 278 | break; |
283 | case Vehicle.LINEAR_MOTOR_DIRECTION: | 279 | case Vehicle.LINEAR_MOTOR_DIRECTION: |
284 | m_linearMotorDirection = new Vector3(pValue.X, pValue.Y, pValue.Z); | 280 | m_linearMotorDirection = new Vector3(pValue.X, pValue.Y, pValue.Z); |
@@ -559,14 +555,10 @@ namespace OpenSim.Region.Physics.BulletSPlugin | |||
559 | break; | 555 | break; |
560 | } | 556 | } |
561 | 557 | ||
562 | m_linearMotor = new BSVMotor("LinearMotor", m_linearMotorTimescale, | 558 | m_linearMotor = new BSVMotor("LinearMotor", m_linearMotorTimescale, m_linearMotorDecayTimescale, 1f); |
563 | m_linearMotorDecayTimescale, m_linearFrictionTimescale, | ||
564 | 1f); | ||
565 | m_linearMotor.PhysicsScene = m_physicsScene; // DEBUG DEBUG DEBUG (enables detail logging) | 559 | m_linearMotor.PhysicsScene = m_physicsScene; // DEBUG DEBUG DEBUG (enables detail logging) |
566 | 560 | ||
567 | m_angularMotor = new BSVMotor("AngularMotor", m_angularMotorTimescale, | 561 | m_angularMotor = new BSVMotor("AngularMotor", m_angularMotorTimescale, m_angularMotorDecayTimescale, 1f); |
568 | m_angularMotorDecayTimescale, m_angularFrictionTimescale, | ||
569 | 1f); | ||
570 | m_angularMotor.PhysicsScene = m_physicsScene; // DEBUG DEBUG DEBUG (enables detail logging) | 562 | m_angularMotor.PhysicsScene = m_physicsScene; // DEBUG DEBUG DEBUG (enables detail logging) |
571 | 563 | ||
572 | /* Not implemented | 564 | /* Not implemented |
@@ -574,7 +566,6 @@ namespace OpenSim.Region.Physics.BulletSPlugin | |||
574 | BSMotor.Infinite, BSMotor.InfiniteVector, | 566 | BSMotor.Infinite, BSMotor.InfiniteVector, |
575 | m_verticalAttractionEfficiency); | 567 | m_verticalAttractionEfficiency); |
576 | // Z goes away and we keep X and Y | 568 | // Z goes away and we keep X and Y |
577 | m_verticalAttractionMotor.FrictionTimescale = new Vector3(BSMotor.Infinite, BSMotor.Infinite, 0.1f); | ||
578 | m_verticalAttractionMotor.PhysicsScene = PhysicsScene; // DEBUG DEBUG DEBUG (enables detail logging) | 569 | m_verticalAttractionMotor.PhysicsScene = PhysicsScene; // DEBUG DEBUG DEBUG (enables detail logging) |
579 | */ | 570 | */ |
580 | 571 | ||
@@ -1050,8 +1041,13 @@ namespace OpenSim.Region.Physics.BulletSPlugin | |||
1050 | // Add this correction to the velocity to make it faster/slower. | 1041 | // Add this correction to the velocity to make it faster/slower. |
1051 | VehicleVelocity += linearMotorVelocityW; | 1042 | VehicleVelocity += linearMotorVelocityW; |
1052 | 1043 | ||
1053 | VDetailLog("{0}, MoveLinear,velocity,origVelW={1},velV={2},correctV={3},correctW={4},newVelW={5}", | 1044 | // Friction reduces vehicle motion |
1054 | ControllingPrim.LocalID, origVelW, currentVelV, linearMotorCorrectionV, linearMotorVelocityW, VehicleVelocity); | 1045 | Vector3 frictionFactor = ComputeFrictionFactor(m_linearFrictionTimescale, pTimestep); |
1046 | VehicleVelocity -= (VehicleVelocity * frictionFactor); | ||
1047 | |||
1048 | VDetailLog("{0}, MoveLinear,velocity,origVelW={1},velV={2},correctV={3},correctW={4},newVelW={5},fricFact={6}", | ||
1049 | ControllingPrim.LocalID, origVelW, currentVelV, linearMotorCorrectionV, | ||
1050 | linearMotorVelocityW, VehicleVelocity, frictionFactor); | ||
1055 | } | 1051 | } |
1056 | 1052 | ||
1057 | public void ComputeLinearTerrainHeightCorrection(float pTimestep) | 1053 | public void ComputeLinearTerrainHeightCorrection(float pTimestep) |
@@ -1342,6 +1338,11 @@ namespace OpenSim.Region.Physics.BulletSPlugin | |||
1342 | // } | 1338 | // } |
1343 | 1339 | ||
1344 | VehicleRotationalVelocity += angularMotorContributionV * VehicleOrientation; | 1340 | VehicleRotationalVelocity += angularMotorContributionV * VehicleOrientation; |
1341 | |||
1342 | // Reduce any velocity by friction. | ||
1343 | Vector3 frictionFactor = ComputeFrictionFactor(m_angularFrictionTimescale, pTimestep); | ||
1344 | VehicleRotationalVelocity -= (VehicleRotationalVelocity * frictionFactor); | ||
1345 | |||
1345 | VDetailLog("{0}, MoveAngular,angularTurning,angularMotorContrib={1}", ControllingPrim.LocalID, angularMotorContributionV); | 1346 | VDetailLog("{0}, MoveAngular,angularTurning,angularMotorContrib={1}", ControllingPrim.LocalID, angularMotorContributionV); |
1346 | } | 1347 | } |
1347 | 1348 | ||
@@ -1629,6 +1630,23 @@ namespace OpenSim.Region.Physics.BulletSPlugin | |||
1629 | 1630 | ||
1630 | } | 1631 | } |
1631 | 1632 | ||
1633 | // Given a friction vector (reduction in seconds) and a timestep, return the factor to reduce | ||
1634 | // some value by to apply this friction. | ||
1635 | private Vector3 ComputeFrictionFactor(Vector3 friction, float pTimestep) | ||
1636 | { | ||
1637 | Vector3 frictionFactor = Vector3.Zero; | ||
1638 | if (friction != BSMotor.InfiniteVector) | ||
1639 | { | ||
1640 | // frictionFactor = (Vector3.One / FrictionTimescale) * timeStep; | ||
1641 | // Individual friction components can be 'infinite' so compute each separately. | ||
1642 | frictionFactor.X = (friction.X == BSMotor.Infinite) ? 0f : (1f / friction.X); | ||
1643 | frictionFactor.Y = (friction.Y == BSMotor.Infinite) ? 0f : (1f / friction.Y); | ||
1644 | frictionFactor.Z = (friction.Z == BSMotor.Infinite) ? 0f : (1f / friction.Z); | ||
1645 | frictionFactor *= pTimestep; | ||
1646 | } | ||
1647 | return frictionFactor; | ||
1648 | } | ||
1649 | |||
1632 | private float ClampInRange(float low, float val, float high) | 1650 | private float ClampInRange(float low, float val, float high) |
1633 | { | 1651 | { |
1634 | return Math.Max(low, Math.Min(val, high)); | 1652 | return Math.Max(low, Math.Min(val, high)); |
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSMotors.cs b/OpenSim/Region/Physics/BulletSPlugin/BSMotors.cs index 0128d8d..ef662b5 100755 --- a/OpenSim/Region/Physics/BulletSPlugin/BSMotors.cs +++ b/OpenSim/Region/Physics/BulletSPlugin/BSMotors.cs | |||
@@ -65,13 +65,11 @@ public abstract class BSMotor | |||
65 | } | 65 | } |
66 | 66 | ||
67 | // Motor which moves CurrentValue to TargetValue over TimeScale seconds. | 67 | // Motor which moves CurrentValue to TargetValue over TimeScale seconds. |
68 | // The TargetValue decays in TargetValueDecayTimeScale and | 68 | // The TargetValue decays in TargetValueDecayTimeScale. |
69 | // the CurrentValue will be held back by FrictionTimeScale. | ||
70 | // This motor will "zero itself" over time in that the targetValue will | 69 | // This motor will "zero itself" over time in that the targetValue will |
71 | // decay to zero and the currentValue will follow it to that zero. | 70 | // decay to zero and the currentValue will follow it to that zero. |
72 | // The overall effect is for the returned correction value to go from large | 71 | // The overall effect is for the returned correction value to go from large |
73 | // values (the total difference between current and target minus friction) | 72 | // values to small and eventually zero values. |
74 | // to small and eventually zero values. | ||
75 | // TimeScale and TargetDelayTimeScale may be 'infinite' which means no decay. | 73 | // TimeScale and TargetDelayTimeScale may be 'infinite' which means no decay. |
76 | 74 | ||
77 | // For instance, if something is moving at speed X and the desired speed is Y, | 75 | // For instance, if something is moving at speed X and the desired speed is Y, |
@@ -88,7 +86,6 @@ public class BSVMotor : BSMotor | |||
88 | 86 | ||
89 | public virtual float TimeScale { get; set; } | 87 | public virtual float TimeScale { get; set; } |
90 | public virtual float TargetValueDecayTimeScale { get; set; } | 88 | public virtual float TargetValueDecayTimeScale { get; set; } |
91 | public virtual Vector3 FrictionTimescale { get; set; } | ||
92 | public virtual float Efficiency { get; set; } | 89 | public virtual float Efficiency { get; set; } |
93 | 90 | ||
94 | public virtual float ErrorZeroThreshold { get; set; } | 91 | public virtual float ErrorZeroThreshold { get; set; } |
@@ -111,16 +108,14 @@ public class BSVMotor : BSMotor | |||
111 | { | 108 | { |
112 | TimeScale = TargetValueDecayTimeScale = BSMotor.Infinite; | 109 | TimeScale = TargetValueDecayTimeScale = BSMotor.Infinite; |
113 | Efficiency = 1f; | 110 | Efficiency = 1f; |
114 | FrictionTimescale = BSMotor.InfiniteVector; | ||
115 | CurrentValue = TargetValue = Vector3.Zero; | 111 | CurrentValue = TargetValue = Vector3.Zero; |
116 | ErrorZeroThreshold = 0.001f; | 112 | ErrorZeroThreshold = 0.001f; |
117 | } | 113 | } |
118 | public BSVMotor(string useName, float timeScale, float decayTimeScale, Vector3 frictionTimeScale, float efficiency) | 114 | public BSVMotor(string useName, float timeScale, float decayTimeScale, float efficiency) |
119 | : this(useName) | 115 | : this(useName) |
120 | { | 116 | { |
121 | TimeScale = timeScale; | 117 | TimeScale = timeScale; |
122 | TargetValueDecayTimeScale = decayTimeScale; | 118 | TargetValueDecayTimeScale = decayTimeScale; |
123 | FrictionTimescale = frictionTimeScale; | ||
124 | Efficiency = efficiency; | 119 | Efficiency = efficiency; |
125 | CurrentValue = TargetValue = Vector3.Zero; | 120 | CurrentValue = TargetValue = Vector3.Zero; |
126 | } | 121 | } |
@@ -165,26 +160,11 @@ public class BSVMotor : BSMotor | |||
165 | TargetValue *= (1f - decayFactor); | 160 | TargetValue *= (1f - decayFactor); |
166 | } | 161 | } |
167 | 162 | ||
168 | // The amount we can correct the error is reduced by the friction | ||
169 | Vector3 frictionFactor = Vector3.Zero; | ||
170 | if (FrictionTimescale != BSMotor.InfiniteVector) | ||
171 | { | ||
172 | // frictionFactor = (Vector3.One / FrictionTimescale) * timeStep; | ||
173 | // Individual friction components can be 'infinite' so compute each separately. | ||
174 | frictionFactor.X = (FrictionTimescale.X == BSMotor.Infinite) ? 0f : (1f / FrictionTimescale.X); | ||
175 | frictionFactor.Y = (FrictionTimescale.Y == BSMotor.Infinite) ? 0f : (1f / FrictionTimescale.Y); | ||
176 | frictionFactor.Z = (FrictionTimescale.Z == BSMotor.Infinite) ? 0f : (1f / FrictionTimescale.Z); | ||
177 | frictionFactor *= timeStep; | ||
178 | CurrentValue *= (Vector3.One - frictionFactor); | ||
179 | } | ||
180 | |||
181 | MDetailLog("{0}, BSVMotor.Step,nonZero,{1},origCurr={2},origTarget={3},timeStep={4},err={5},corr={6}", | 163 | MDetailLog("{0}, BSVMotor.Step,nonZero,{1},origCurr={2},origTarget={3},timeStep={4},err={5},corr={6}", |
182 | BSScene.DetailLogZero, UseName, origCurrVal, origTarget, | 164 | BSScene.DetailLogZero, UseName, origCurrVal, origTarget, |
183 | timeStep, error, correction); | 165 | timeStep, error, correction); |
184 | MDetailLog("{0}, BSVMotor.Step,nonZero,{1},tgtDecayTS={2},decayFact={3},frictTS={4},frictFact={5},tgt={6},curr={7}", | 166 | MDetailLog("{0}, BSVMotor.Step,nonZero,{1},tgtDecayTS={2},decayFact={3},tgt={4},curr={5}", |
185 | BSScene.DetailLogZero, UseName, | 167 | BSScene.DetailLogZero, UseName, TargetValueDecayTimeScale, decayFactor, TargetValue, CurrentValue); |
186 | TargetValueDecayTimeScale, decayFactor, FrictionTimescale, frictionFactor, | ||
187 | TargetValue, CurrentValue); | ||
188 | } | 168 | } |
189 | else | 169 | else |
190 | { | 170 | { |
@@ -235,9 +215,9 @@ public class BSVMotor : BSMotor | |||
235 | // maximum number of outputs to generate. | 215 | // maximum number of outputs to generate. |
236 | int maxOutput = 50; | 216 | int maxOutput = 50; |
237 | MDetailLog("{0},BSVMotor.Test,{1},===================================== BEGIN Test Output", BSScene.DetailLogZero, UseName); | 217 | MDetailLog("{0},BSVMotor.Test,{1},===================================== BEGIN Test Output", BSScene.DetailLogZero, UseName); |
238 | MDetailLog("{0},BSVMotor.Test,{1},timeScale={2},targDlyTS={3},frictTS={4},eff={5},curr={6},tgt={7}", | 218 | MDetailLog("{0},BSVMotor.Test,{1},timeScale={2},targDlyTS={3},eff={4},curr={5},tgt={6}", |
239 | BSScene.DetailLogZero, UseName, | 219 | BSScene.DetailLogZero, UseName, |
240 | TimeScale, TargetValueDecayTimeScale, FrictionTimescale, Efficiency, | 220 | TimeScale, TargetValueDecayTimeScale, Efficiency, |
241 | CurrentValue, TargetValue); | 221 | CurrentValue, TargetValue); |
242 | 222 | ||
243 | LastError = BSMotor.InfiniteVector; | 223 | LastError = BSMotor.InfiniteVector; |
@@ -254,8 +234,8 @@ public class BSVMotor : BSMotor | |||
254 | 234 | ||
255 | public override string ToString() | 235 | public override string ToString() |
256 | { | 236 | { |
257 | return String.Format("<{0},curr={1},targ={2},lastErr={3},decayTS={4},frictTS={5}>", | 237 | return String.Format("<{0},curr={1},targ={2},lastErr={3},decayTS={4}>", |
258 | UseName, CurrentValue, TargetValue, LastError, TargetValueDecayTimeScale, FrictionTimescale); | 238 | UseName, CurrentValue, TargetValue, LastError, TargetValueDecayTimeScale); |
259 | } | 239 | } |
260 | } | 240 | } |
261 | 241 | ||
@@ -265,7 +245,6 @@ public class BSFMotor : BSMotor | |||
265 | { | 245 | { |
266 | public virtual float TimeScale { get; set; } | 246 | public virtual float TimeScale { get; set; } |
267 | public virtual float TargetValueDecayTimeScale { get; set; } | 247 | public virtual float TargetValueDecayTimeScale { get; set; } |
268 | public virtual float FrictionTimescale { get; set; } | ||
269 | public virtual float Efficiency { get; set; } | 248 | public virtual float Efficiency { get; set; } |
270 | 249 | ||
271 | public virtual float ErrorZeroThreshold { get; set; } | 250 | public virtual float ErrorZeroThreshold { get; set; } |
@@ -283,12 +262,11 @@ public class BSFMotor : BSMotor | |||
283 | return (err >= -ErrorZeroThreshold && err <= ErrorZeroThreshold); | 262 | return (err >= -ErrorZeroThreshold && err <= ErrorZeroThreshold); |
284 | } | 263 | } |
285 | 264 | ||
286 | public BSFMotor(string useName, float timeScale, float decayTimescale, float friction, float efficiency) | 265 | public BSFMotor(string useName, float timeScale, float decayTimescale, float efficiency) |
287 | : base(useName) | 266 | : base(useName) |
288 | { | 267 | { |
289 | TimeScale = TargetValueDecayTimeScale = BSMotor.Infinite; | 268 | TimeScale = TargetValueDecayTimeScale = BSMotor.Infinite; |
290 | Efficiency = 1f; | 269 | Efficiency = 1f; |
291 | FrictionTimescale = BSMotor.Infinite; | ||
292 | CurrentValue = TargetValue = 0f; | 270 | CurrentValue = TargetValue = 0f; |
293 | ErrorZeroThreshold = 0.01f; | 271 | ErrorZeroThreshold = 0.01f; |
294 | } | 272 | } |
@@ -331,24 +309,11 @@ public class BSFMotor : BSMotor | |||
331 | TargetValue *= (1f - decayFactor); | 309 | TargetValue *= (1f - decayFactor); |
332 | } | 310 | } |
333 | 311 | ||
334 | // The amount we can correct the error is reduced by the friction | ||
335 | float frictionFactor = 0f; | ||
336 | if (FrictionTimescale != BSMotor.Infinite) | ||
337 | { | ||
338 | // frictionFactor = (Vector3.One / FrictionTimescale) * timeStep; | ||
339 | // Individual friction components can be 'infinite' so compute each separately. | ||
340 | frictionFactor = 1f / FrictionTimescale; | ||
341 | frictionFactor *= timeStep; | ||
342 | CurrentValue *= (1f - frictionFactor); | ||
343 | } | ||
344 | |||
345 | MDetailLog("{0}, BSFMotor.Step,nonZero,{1},origCurr={2},origTarget={3},timeStep={4},err={5},corr={6}", | 312 | MDetailLog("{0}, BSFMotor.Step,nonZero,{1},origCurr={2},origTarget={3},timeStep={4},err={5},corr={6}", |
346 | BSScene.DetailLogZero, UseName, origCurrVal, origTarget, | 313 | BSScene.DetailLogZero, UseName, origCurrVal, origTarget, |
347 | timeStep, error, correction); | 314 | timeStep, error, correction); |
348 | MDetailLog("{0}, BSFMotor.Step,nonZero,{1},tgtDecayTS={2},decayFact={3},frictTS={4},frictFact={5},tgt={6},curr={7}", | 315 | MDetailLog("{0}, BSFMotor.Step,nonZero,{1},tgtDecayTS={2},decayFact={3},tgt={4},curr={5}", |
349 | BSScene.DetailLogZero, UseName, | 316 | BSScene.DetailLogZero, UseName, TargetValueDecayTimeScale, decayFactor, TargetValue, CurrentValue); |
350 | TargetValueDecayTimeScale, decayFactor, FrictionTimescale, frictionFactor, | ||
351 | TargetValue, CurrentValue); | ||
352 | } | 317 | } |
353 | else | 318 | else |
354 | { | 319 | { |
@@ -390,8 +355,8 @@ public class BSFMotor : BSMotor | |||
390 | 355 | ||
391 | public override string ToString() | 356 | public override string ToString() |
392 | { | 357 | { |
393 | return String.Format("<{0},curr={1},targ={2},lastErr={3},decayTS={4},frictTS={5}>", | 358 | return String.Format("<{0},curr={1},targ={2},lastErr={3},decayTS={4}>", |
394 | UseName, CurrentValue, TargetValue, LastError, TargetValueDecayTimeScale, FrictionTimescale); | 359 | UseName, CurrentValue, TargetValue, LastError, TargetValueDecayTimeScale); |
395 | } | 360 | } |
396 | 361 | ||
397 | } | 362 | } |