aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/Physics/BulletSPlugin/BSActorLockAxis.cs
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim/Region/Physics/BulletSPlugin/BSActorLockAxis.cs')
-rwxr-xr-xOpenSim/Region/Physics/BulletSPlugin/BSActorLockAxis.cs59
1 files changed, 35 insertions, 24 deletions
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSActorLockAxis.cs b/OpenSim/Region/Physics/BulletSPlugin/BSActorLockAxis.cs
index 48cab64..3b3c161 100755
--- a/OpenSim/Region/Physics/BulletSPlugin/BSActorLockAxis.cs
+++ b/OpenSim/Region/Physics/BulletSPlugin/BSActorLockAxis.cs
@@ -36,7 +36,9 @@ namespace OpenSim.Region.Physics.BulletSPlugin
36{ 36{
37public class BSActorLockAxis : BSActor 37public class BSActorLockAxis : BSActor
38{ 38{
39 BSConstraint LockAxisConstraint = null; 39 private BSConstraint LockAxisConstraint = null;
40 private bool HaveRegisteredForBeforeStepCallback = false;
41
40 // The lock access flags (which axises were locked) when the contraint was built. 42 // The lock access flags (which axises were locked) when the contraint was built.
41 // Used to see if locking has changed since when the constraint was built. 43 // Used to see if locking has changed since when the constraint was built.
42 OMV.Vector3 LockAxisLinearFlags; 44 OMV.Vector3 LockAxisLinearFlags;
@@ -47,9 +49,7 @@ public class BSActorLockAxis : BSActor
47 { 49 {
48 m_physicsScene.DetailLog("{0},BSActorLockAxis,constructor", m_controllingPrim.LocalID); 50 m_physicsScene.DetailLog("{0},BSActorLockAxis,constructor", m_controllingPrim.LocalID);
49 LockAxisConstraint = null; 51 LockAxisConstraint = null;
50 52 HaveRegisteredForBeforeStepCallback = false;
51 // we place our constraint just before the simulation step to make sure the linkset is complete
52 m_physicsScene.BeforeStep += PhysicsScene_BeforeStep;
53 } 53 }
54 54
55 // BSActor.isActive 55 // BSActor.isActive
@@ -62,7 +62,8 @@ public class BSActorLockAxis : BSActor
62 // BSActor.Dispose() 62 // BSActor.Dispose()
63 public override void Dispose() 63 public override void Dispose()
64 { 64 {
65 m_physicsScene.BeforeStep -= PhysicsScene_BeforeStep; 65 Enabled = false;
66 UnRegisterForBeforeStepCallback();
66 RemoveAxisLockConstraint(); 67 RemoveAxisLockConstraint();
67 } 68 }
68 69
@@ -74,37 +75,26 @@ public class BSActorLockAxis : BSActor
74 // Since the axis logging is done with a constraint, Refresh() time is good for 75 // Since the axis logging is done with a constraint, Refresh() time is good for
75 // changing parameters but this needs to wait until the prim/linkset is physically 76 // changing parameters but this needs to wait until the prim/linkset is physically
76 // constructed. Therefore, the constraint itself is placed at pre-step time. 77 // constructed. Therefore, the constraint itself is placed at pre-step time.
77 /* 78
78 m_physicsScene.DetailLog("{0},BSActorLockAxis,refresh,lockedLinear={1},lockedAngular={2},enabled={3},pActive={4}",
79 m_controllingPrim.LocalID,
80 m_controllingPrim.LockedLinearAxis,
81 m_controllingPrim.LockedAngularAxis,
82 Enabled, m_controllingPrim.IsPhysicallyActive);
83 // If all the axis are free, we don't need to exist 79 // If all the axis are free, we don't need to exist
80 // Refresh() only turns off. Enabling is done by InitializeAxisActor()
81 // whenever parameters are changed.
82 // This leaves 'enable' free to turn off an actor when it is not wanted to run.
84 if (m_controllingPrim.LockedAngularAxis == m_controllingPrim.LockedAxisFree 83 if (m_controllingPrim.LockedAngularAxis == m_controllingPrim.LockedAxisFree
85 && m_controllingPrim.LockedLinearAxis == m_controllingPrim.LockedAxisFree) 84 && m_controllingPrim.LockedLinearAxis == m_controllingPrim.LockedAxisFree)
86 { 85 {
87 Enabled = false; 86 Enabled = false;
88 } 87 }
89 88
90 // If the object is physically active, add the axis locking constraint
91 if (isActive) 89 if (isActive)
92 { 90 {
93 // Check to see if the locking parameters have changed 91 RegisterForBeforeStepCallback();
94 if (m_controllingPrim.LockedLinearAxis != this.LockAxisLinearFlags
95 || m_controllingPrim.LockedAngularAxis != this.LockAxisAngularFlags)
96 {
97 // The locking has changed. Remove the old constraint and build a new one
98 RemoveAxisLockConstraint();
99 }
100
101 AddAxisLockConstraint();
102 } 92 }
103 else 93 else
104 { 94 {
105 RemoveAxisLockConstraint(); 95 RemoveDependencies();
96 UnRegisterForBeforeStepCallback();
106 } 97 }
107 */
108 } 98 }
109 99
110 // The object's physical representation is being rebuilt so pick up any physical dependencies (constraints, ...). 100 // The object's physical representation is being rebuilt so pick up any physical dependencies (constraints, ...).
@@ -114,7 +104,24 @@ public class BSActorLockAxis : BSActor
114 public override void RemoveDependencies() 104 public override void RemoveDependencies()
115 { 105 {
116 RemoveAxisLockConstraint(); 106 RemoveAxisLockConstraint();
117 // The pre-step action will restore the constraint of needed 107 }
108
109 private void RegisterForBeforeStepCallback()
110 {
111 if (!HaveRegisteredForBeforeStepCallback)
112 {
113 m_physicsScene.BeforeStep += PhysicsScene_BeforeStep;
114 HaveRegisteredForBeforeStepCallback = true;
115 }
116 }
117
118 private void UnRegisterForBeforeStepCallback()
119 {
120 if (HaveRegisteredForBeforeStepCallback)
121 {
122 m_physicsScene.BeforeStep -= PhysicsScene_BeforeStep;
123 HaveRegisteredForBeforeStepCallback = false;
124 }
118 } 125 }
119 126
120 private void PhysicsScene_BeforeStep(float timestep) 127 private void PhysicsScene_BeforeStep(float timestep)
@@ -145,6 +152,7 @@ public class BSActorLockAxis : BSActor
145 } 152 }
146 } 153 }
147 154
155 // Note that this relies on being called at TaintTime
148 private void AddAxisLockConstraint() 156 private void AddAxisLockConstraint()
149 { 157 {
150 if (LockAxisConstraint == null) 158 if (LockAxisConstraint == null)
@@ -192,11 +200,14 @@ public class BSActorLockAxis : BSActor
192 axisConstrainer.TranslationalLimitMotor(true /* enable */, 5.0f, 0.1f); 200 axisConstrainer.TranslationalLimitMotor(true /* enable */, 5.0f, 0.1f);
193 201
194 axisConstrainer.RecomputeConstraintVariables(m_controllingPrim.RawMass); 202 axisConstrainer.RecomputeConstraintVariables(m_controllingPrim.RawMass);
203
204 RegisterForBeforeStepCallback();
195 } 205 }
196 } 206 }
197 207
198 private void RemoveAxisLockConstraint() 208 private void RemoveAxisLockConstraint()
199 { 209 {
210 UnRegisterForBeforeStepCallback();
200 if (LockAxisConstraint != null) 211 if (LockAxisConstraint != null)
201 { 212 {
202 m_physicsScene.Constraints.RemoveAndDestroyConstraint(LockAxisConstraint); 213 m_physicsScene.Constraints.RemoveAndDestroyConstraint(LockAxisConstraint);