diff options
author | BlueWall | 2012-12-07 15:36:43 -0500 |
---|---|---|
committer | BlueWall | 2012-12-07 15:36:43 -0500 |
commit | 0b455d2882a51ce0841d003f12d4c35ad9edb753 (patch) | |
tree | c48c95f48786f8fe435fc5c90477ac3b7c9eaf6c /OpenSim/Region/Physics/BulletSPlugin/BSMotors.cs | |
parent | Merge branch 'master' into connector_plugin (diff) | |
parent | Merge branch 'master' of ssh://opensimulator.org/var/git/opensim (diff) | |
download | opensim-SC_OLD-0b455d2882a51ce0841d003f12d4c35ad9edb753.zip opensim-SC_OLD-0b455d2882a51ce0841d003f12d4c35ad9edb753.tar.gz opensim-SC_OLD-0b455d2882a51ce0841d003f12d4c35ad9edb753.tar.bz2 opensim-SC_OLD-0b455d2882a51ce0841d003f12d4c35ad9edb753.tar.xz |
Merge branch 'master' into connector_plugin
Diffstat (limited to 'OpenSim/Region/Physics/BulletSPlugin/BSMotors.cs')
-rwxr-xr-x | OpenSim/Region/Physics/BulletSPlugin/BSMotors.cs | 96 |
1 files changed, 82 insertions, 14 deletions
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSMotors.cs b/OpenSim/Region/Physics/BulletSPlugin/BSMotors.cs index 480da2c..851d508 100755 --- a/OpenSim/Region/Physics/BulletSPlugin/BSMotors.cs +++ b/OpenSim/Region/Physics/BulletSPlugin/BSMotors.cs | |||
@@ -1,3 +1,30 @@ | |||
1 | /* | ||
2 | * Copyright (c) Contributors, http://opensimulator.org/ | ||
3 | * See CONTRIBUTORS.TXT for a full list of copyright holders. | ||
4 | * | ||
5 | * Redistribution and use in source and binary forms, with or without | ||
6 | * modification, are permitted provided that the following conditions are met: | ||
7 | * * Redistributions of source code must retain the above copyright | ||
8 | * notice, this list of conditions and the following disclaimer. | ||
9 | * * Redistributions in binary form must reproduce the above copyright | ||
10 | * notice, this list of conditions and the following disclaimer in the | ||
11 | * documentation and/or other materials provided with the distribution. | ||
12 | * * Neither the name of the OpenSimulator Project nor the | ||
13 | * names of its contributors may be used to endorse or promote products | ||
14 | * derived from this software without specific prior written permission. | ||
15 | * | ||
16 | * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY | ||
17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
19 | * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY | ||
20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | ||
23 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
26 | * | ||
27 | */ | ||
1 | using System; | 28 | using System; |
2 | using System.Collections.Generic; | 29 | using System.Collections.Generic; |
3 | using System.Text; | 30 | using System.Text; |
@@ -7,6 +34,10 @@ namespace OpenSim.Region.Physics.BulletSPlugin | |||
7 | { | 34 | { |
8 | public abstract class BSMotor | 35 | public abstract class BSMotor |
9 | { | 36 | { |
37 | // Timescales and other things can be turned off by setting them to 'infinite'. | ||
38 | public const float Infinite = 12345f; | ||
39 | public readonly static Vector3 InfiniteVector = new Vector3(BSMotor.Infinite, BSMotor.Infinite, BSMotor.Infinite); | ||
40 | |||
10 | public BSMotor(string useName) | 41 | public BSMotor(string useName) |
11 | { | 42 | { |
12 | UseName = useName; | 43 | UseName = useName; |
@@ -15,7 +46,9 @@ public abstract class BSMotor | |||
15 | public virtual void Reset() { } | 46 | public virtual void Reset() { } |
16 | public virtual void Zero() { } | 47 | public virtual void Zero() { } |
17 | 48 | ||
49 | // A name passed at motor creation for easily identifyable debugging messages. | ||
18 | public string UseName { get; private set; } | 50 | public string UseName { get; private set; } |
51 | |||
19 | // Used only for outputting debug information. Might not be set so check for null. | 52 | // Used only for outputting debug information. Might not be set so check for null. |
20 | public BSScene PhysicsScene { get; set; } | 53 | public BSScene PhysicsScene { get; set; } |
21 | protected void MDetailLog(string msg, params Object[] parms) | 54 | protected void MDetailLog(string msg, params Object[] parms) |
@@ -30,10 +63,23 @@ public abstract class BSMotor | |||
30 | } | 63 | } |
31 | } | 64 | } |
32 | // Can all the incremental stepping be replaced with motor classes? | 65 | // Can all the incremental stepping be replaced with motor classes? |
66 | |||
67 | // Motor which moves CurrentValue to TargetValue over TimeScale seconds. | ||
68 | // The TargetValue is decays in TargetValueDecayTimeScale and | ||
69 | // the CurrentValue will be held back by FrictionTimeScale. | ||
70 | // TimeScale and TargetDelayTimeScale may be 'infinite' which means go decay. | ||
71 | |||
72 | // For instance, if something is moving at speed X and the desired speed is Y, | ||
73 | // CurrentValue is X and TargetValue is Y. As the motor is stepped, new | ||
74 | // values of CurrentValue are returned that approach the TargetValue. | ||
75 | // The feature of decaying TargetValue is so vehicles will eventually | ||
76 | // come to a stop rather than run forever. This can be disabled by | ||
77 | // setting TargetValueDecayTimescale to 'infinite'. | ||
78 | // The change from CurrentValue to TargetValue is linear over TimeScale seconds. | ||
33 | public class BSVMotor : BSMotor | 79 | public class BSVMotor : BSMotor |
34 | { | 80 | { |
35 | public Vector3 FrameOfReference { get; set; } | 81 | // public Vector3 FrameOfReference { get; set; } |
36 | public Vector3 Offset { get; set; } | 82 | // public Vector3 Offset { get; set; } |
37 | 83 | ||
38 | public float TimeScale { get; set; } | 84 | public float TimeScale { get; set; } |
39 | public float TargetValueDecayTimeScale { get; set; } | 85 | public float TargetValueDecayTimeScale { get; set; } |
@@ -46,8 +92,9 @@ public class BSVMotor : BSMotor | |||
46 | public BSVMotor(string useName) | 92 | public BSVMotor(string useName) |
47 | : base(useName) | 93 | : base(useName) |
48 | { | 94 | { |
49 | TimeScale = TargetValueDecayTimeScale = Efficiency = 1f; | 95 | TimeScale = TargetValueDecayTimeScale = BSMotor.Infinite; |
50 | FrictionTimescale = Vector3.Zero; | 96 | Efficiency = 1f; |
97 | FrictionTimescale = BSMotor.InfiniteVector; | ||
51 | CurrentValue = TargetValue = Vector3.Zero; | 98 | CurrentValue = TargetValue = Vector3.Zero; |
52 | } | 99 | } |
53 | public BSVMotor(string useName, float timeScale, float decayTimeScale, Vector3 frictionTimeScale, float efficiency) | 100 | public BSVMotor(string useName, float timeScale, float decayTimeScale, Vector3 frictionTimeScale, float efficiency) |
@@ -67,6 +114,14 @@ public class BSVMotor : BSMotor | |||
67 | { | 114 | { |
68 | TargetValue = target; | 115 | TargetValue = target; |
69 | } | 116 | } |
117 | |||
118 | // A form of stepping that does not take the time quantum into account. | ||
119 | // The caller must do the right thing later. | ||
120 | public Vector3 Step() | ||
121 | { | ||
122 | return Step(1f); | ||
123 | } | ||
124 | |||
70 | public Vector3 Step(float timeStep) | 125 | public Vector3 Step(float timeStep) |
71 | { | 126 | { |
72 | Vector3 returnCurrent = Vector3.Zero; | 127 | Vector3 returnCurrent = Vector3.Zero; |
@@ -78,23 +133,36 @@ public class BSVMotor : BSMotor | |||
78 | // Addition = (desiredVector - currentAppliedVector) / secondsItShouldTakeToComplete | 133 | // Addition = (desiredVector - currentAppliedVector) / secondsItShouldTakeToComplete |
79 | Vector3 addAmount = (TargetValue - CurrentValue)/TimeScale * timeStep; | 134 | Vector3 addAmount = (TargetValue - CurrentValue)/TimeScale * timeStep; |
80 | CurrentValue += addAmount; | 135 | CurrentValue += addAmount; |
136 | |||
81 | returnCurrent = CurrentValue; | 137 | returnCurrent = CurrentValue; |
82 | 138 | ||
83 | // The desired value reduces to zero when also reduces the difference with current. | 139 | // The desired value reduces to zero which also reduces the difference with current. |
84 | float decayFactor = (1.0f / TargetValueDecayTimeScale) * timeStep; | 140 | // If the decay time is infinite, don't decay at all. |
85 | TargetValue *= (1f - decayFactor); | 141 | float decayFactor = 0f; |
142 | if (TargetValueDecayTimeScale != BSMotor.Infinite) | ||
143 | { | ||
144 | decayFactor = (1.0f / TargetValueDecayTimeScale) * timeStep; | ||
145 | TargetValue *= (1f - decayFactor); | ||
146 | } | ||
86 | 147 | ||
87 | Vector3 frictionFactor = Vector3.Zero; | 148 | Vector3 frictionFactor = Vector3.Zero; |
88 | frictionFactor = (Vector3.One / FrictionTimescale) * timeStep; | 149 | if (FrictionTimescale != BSMotor.InfiniteVector) |
89 | CurrentValue *= (Vector3.One - frictionFactor); | 150 | { |
151 | // frictionFactor = (Vector3.One / FrictionTimescale) * timeStep; | ||
152 | // Individual friction components can be 'infinite' so compute each separately. | ||
153 | frictionFactor.X = FrictionTimescale.X == BSMotor.Infinite ? 0f : (1f / FrictionTimescale.X) * timeStep; | ||
154 | frictionFactor.Y = FrictionTimescale.Y == BSMotor.Infinite ? 0f : (1f / FrictionTimescale.Y) * timeStep; | ||
155 | frictionFactor.Z = FrictionTimescale.Z == BSMotor.Infinite ? 0f : (1f / FrictionTimescale.Z) * timeStep; | ||
156 | CurrentValue *= (Vector3.One - frictionFactor); | ||
157 | } | ||
90 | 158 | ||
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}", | 159 | MDetailLog("{0}, BSVMotor.Step,nonZero,{1},origCurr={2},origTarget={3},timeStep={4},timeScale={5},addAmnt={6},targetDecay={7},decayFact={8},fricTS={9},frictFact={10}", |
92 | BSScene.DetailLogZero, UseName, origTarget, origCurrVal, | 160 | BSScene.DetailLogZero, UseName, origCurrVal, origTarget, |
93 | timeStep, TimeScale, addAmount, | 161 | timeStep, TimeScale, addAmount, |
94 | TargetValueDecayTimeScale, decayFactor, | 162 | TargetValueDecayTimeScale, decayFactor, |
95 | FrictionTimescale, frictionFactor); | 163 | FrictionTimescale, frictionFactor); |
96 | MDetailLog("{0},BSVMotor.Step,nonZero,{1},curr={2},target={3},add={4},decay={5},frict={6},ret={7}", | 164 | MDetailLog("{0}, BSVMotor.Step,nonZero,{1},curr={2},target={3},add={4},decay={5},frict={6},ret={7}", |
97 | BSScene.DetailLogZero, UseName, TargetValue, CurrentValue, | 165 | BSScene.DetailLogZero, UseName, CurrentValue, TargetValue, |
98 | addAmount, decayFactor, frictionFactor, returnCurrent); | 166 | addAmount, decayFactor, frictionFactor, returnCurrent); |
99 | } | 167 | } |
100 | else | 168 | else |
@@ -103,7 +171,7 @@ public class BSVMotor : BSMotor | |||
103 | CurrentValue = Vector3.Zero; | 171 | CurrentValue = Vector3.Zero; |
104 | TargetValue = Vector3.Zero; | 172 | TargetValue = Vector3.Zero; |
105 | 173 | ||
106 | MDetailLog("{0},BSVMotor.Step,zero,{1},curr={2},target={3},ret={4}", | 174 | MDetailLog("{0}, BSVMotor.Step,zero,{1},curr={2},target={3},ret={4}", |
107 | BSScene.DetailLogZero, UseName, TargetValue, CurrentValue, returnCurrent); | 175 | BSScene.DetailLogZero, UseName, TargetValue, CurrentValue, returnCurrent); |
108 | 176 | ||
109 | } | 177 | } |