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.cs121
1 files changed, 70 insertions, 51 deletions
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSActorLockAxis.cs b/OpenSim/Region/Physics/BulletSPlugin/BSActorLockAxis.cs
index 7e61007..48cab64 100755
--- a/OpenSim/Region/Physics/BulletSPlugin/BSActorLockAxis.cs
+++ b/OpenSim/Region/Physics/BulletSPlugin/BSActorLockAxis.cs
@@ -37,12 +37,19 @@ namespace OpenSim.Region.Physics.BulletSPlugin
37public class BSActorLockAxis : BSActor 37public class BSActorLockAxis : BSActor
38{ 38{
39 BSConstraint LockAxisConstraint = null; 39 BSConstraint LockAxisConstraint = null;
40 // 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.
42 OMV.Vector3 LockAxisLinearFlags;
43 OMV.Vector3 LockAxisAngularFlags;
40 44
41 public BSActorLockAxis(BSScene physicsScene, BSPhysObject pObj, string actorName) 45 public BSActorLockAxis(BSScene physicsScene, BSPhysObject pObj, string actorName)
42 : base(physicsScene, pObj, actorName) 46 : base(physicsScene, pObj, actorName)
43 { 47 {
44 m_physicsScene.DetailLog("{0},BSActorLockAxis,constructor", m_controllingPrim.LocalID); 48 m_physicsScene.DetailLog("{0},BSActorLockAxis,constructor", m_controllingPrim.LocalID);
45 LockAxisConstraint = null; 49 LockAxisConstraint = null;
50
51 // we place our constraint just before the simulation step to make sure the linkset is complete
52 m_physicsScene.BeforeStep += PhysicsScene_BeforeStep;
46 } 53 }
47 54
48 // BSActor.isActive 55 // BSActor.isActive
@@ -55,6 +62,7 @@ public class BSActorLockAxis : BSActor
55 // BSActor.Dispose() 62 // BSActor.Dispose()
56 public override void Dispose() 63 public override void Dispose()
57 { 64 {
65 m_physicsScene.BeforeStep -= PhysicsScene_BeforeStep;
58 RemoveAxisLockConstraint(); 66 RemoveAxisLockConstraint();
59 } 67 }
60 68
@@ -63,10 +71,18 @@ public class BSActorLockAxis : BSActor
63 // BSActor.Refresh() 71 // BSActor.Refresh()
64 public override void Refresh() 72 public override void Refresh()
65 { 73 {
66 m_physicsScene.DetailLog("{0},BSActorLockAxis,refresh,lockedAxis={1},enabled={2},pActive={3}", 74 // Since the axis logging is done with a constraint, Refresh() time is good for
67 m_controllingPrim.LocalID, m_controllingPrim.LockedAngularAxis, Enabled, m_controllingPrim.IsPhysicallyActive); 75 // 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 /*
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);
68 // If all the axis are free, we don't need to exist 83 // If all the axis are free, we don't need to exist
69 if (m_controllingPrim.LockedAngularAxis == m_controllingPrim.LockedAxisFree) 84 if (m_controllingPrim.LockedAngularAxis == m_controllingPrim.LockedAxisFree
85 && m_controllingPrim.LockedLinearAxis == m_controllingPrim.LockedAxisFree)
70 { 86 {
71 Enabled = false; 87 Enabled = false;
72 } 88 }
@@ -74,12 +90,21 @@ public class BSActorLockAxis : BSActor
74 // If the object is physically active, add the axis locking constraint 90 // If the object is physically active, add the axis locking constraint
75 if (isActive) 91 if (isActive)
76 { 92 {
93 // Check to see if the locking parameters have changed
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
77 AddAxisLockConstraint(); 101 AddAxisLockConstraint();
78 } 102 }
79 else 103 else
80 { 104 {
81 RemoveAxisLockConstraint(); 105 RemoveAxisLockConstraint();
82 } 106 }
107 */
83 } 108 }
84 109
85 // The object's physical representation is being rebuilt so pick up any physical dependencies (constraints, ...). 110 // The object's physical representation is being rebuilt so pick up any physical dependencies (constraints, ...).
@@ -88,15 +113,35 @@ public class BSActorLockAxis : BSActor
88 // BSActor.RemoveDependencies() 113 // BSActor.RemoveDependencies()
89 public override void RemoveDependencies() 114 public override void RemoveDependencies()
90 { 115 {
91 if (LockAxisConstraint != null) 116 RemoveAxisLockConstraint();
117 // The pre-step action will restore the constraint of needed
118 }
119
120 private void PhysicsScene_BeforeStep(float timestep)
121 {
122 // If all the axis are free, we don't need to exist
123 if (m_controllingPrim.LockedAngularAxis == m_controllingPrim.LockedAxisFree
124 && m_controllingPrim.LockedLinearAxis == m_controllingPrim.LockedAxisFree)
92 { 125 {
93 // If a constraint is set up, remove it from the physical scene 126 Enabled = false;
94 RemoveAxisLockConstraint(); 127 }
95 // Schedule a call before the next simulation step to restore the constraint. 128
96 m_physicsScene.PostTaintObject("BSActorLockAxis:" + ActorName, m_controllingPrim.LocalID, delegate() 129 // If the object is physically active, add the axis locking constraint
130 if (isActive)
131 {
132 // Check to see if the locking parameters have changed
133 if (m_controllingPrim.LockedLinearAxis != this.LockAxisLinearFlags
134 || m_controllingPrim.LockedAngularAxis != this.LockAxisAngularFlags)
97 { 135 {
98 Refresh(); 136 // The locking has changed. Remove the old constraint and build a new one
99 }); 137 RemoveAxisLockConstraint();
138 }
139
140 AddAxisLockConstraint();
141 }
142 else
143 {
144 RemoveAxisLockConstraint();
100 } 145 }
101 } 146 }
102 147
@@ -118,56 +163,30 @@ public class BSActorLockAxis : BSActor
118 LockAxisConstraint = axisConstrainer; 163 LockAxisConstraint = axisConstrainer;
119 m_physicsScene.Constraints.AddConstraint(LockAxisConstraint); 164 m_physicsScene.Constraints.AddConstraint(LockAxisConstraint);
120 165
166 // Remember the clocking being inforced so we can notice if they have changed
167 LockAxisLinearFlags = m_controllingPrim.LockedLinearAxis;
168 LockAxisAngularFlags = m_controllingPrim.LockedAngularAxis;
169
121 // The constraint is tied to the world and oriented to the prim. 170 // The constraint is tied to the world and oriented to the prim.
122 171
123 // Free to move linearly in the region 172 if (!axisConstrainer.SetLinearLimits(m_controllingPrim.LockedLinearAxisLow, m_controllingPrim.LockedLinearAxisHigh))
124 // OMV.Vector3 linearLow = OMV.Vector3.Zero;
125 // OMV.Vector3 linearHigh = m_physicsScene.TerrainManager.DefaultRegionSize;
126 OMV.Vector3 linearLow = new OMV.Vector3(-10000f, -10000f, -10000f);
127 OMV.Vector3 linearHigh = new OMV.Vector3(10000f, 10000f, 10000f);
128 if (m_controllingPrim.LockedLinearAxis.X != BSPhysObject.FreeAxis)
129 {
130 linearLow.X = m_controllingPrim.RawPosition.X;
131 linearHigh.X = m_controllingPrim.RawPosition.X;
132 }
133 if (m_controllingPrim.LockedLinearAxis.Y != BSPhysObject.FreeAxis)
134 { 173 {
135 linearLow.Y = m_controllingPrim.RawPosition.Y; 174 m_physicsScene.DetailLog("{0},BSActorLockAxis.AddAxisLockConstraint,failedSetLinearLimits",
136 linearHigh.Y = m_controllingPrim.RawPosition.Y; 175 m_controllingPrim.LocalID);
137 } 176 }
138 if (m_controllingPrim.LockedLinearAxis.Z != BSPhysObject.FreeAxis)
139 {
140 linearLow.Z = m_controllingPrim.RawPosition.Z;
141 linearHigh.Z = m_controllingPrim.RawPosition.Z;
142 }
143 axisConstrainer.SetLinearLimits(linearLow, linearHigh);
144 177
145 // Angular with some axis locked 178 if (!axisConstrainer.SetAngularLimits(m_controllingPrim.LockedAngularAxisLow, m_controllingPrim.LockedAngularAxisHigh))
146 float fPI = (float)Math.PI;
147 OMV.Vector3 angularLow = new OMV.Vector3(-fPI, -fPI, -fPI);
148 OMV.Vector3 angularHigh = new OMV.Vector3(fPI, fPI, fPI);
149 if (m_controllingPrim.LockedAngularAxis.X != BSPhysObject.FreeAxis)
150 {
151 angularLow.X = 0f;
152 angularHigh.X = 0f;
153 }
154 if (m_controllingPrim.LockedAngularAxis.Y != BSPhysObject.FreeAxis)
155 {
156 angularLow.Y = 0f;
157 angularHigh.Y = 0f;
158 }
159 if (m_controllingPrim.LockedAngularAxis.Z != BSPhysObject.FreeAxis)
160 {
161 angularLow.Z = 0f;
162 angularHigh.Z = 0f;
163 }
164 if (!axisConstrainer.SetAngularLimits(angularLow, angularHigh))
165 { 179 {
166 m_physicsScene.DetailLog("{0},BSActorLockAxis.AddAxisLockConstraint,failedSetAngularLimits", m_controllingPrim.LocalID); 180 m_physicsScene.DetailLog("{0},BSActorLockAxis.AddAxisLockConstraint,failedSetAngularLimits",
181 m_controllingPrim.LocalID);
167 } 182 }
168 183
169 m_physicsScene.DetailLog("{0},BSActorLockAxis.AddAxisLockConstraint,create,linLow={1},linHi={2},angLow={3},angHi={4}", 184 m_physicsScene.DetailLog("{0},BSActorLockAxis.AddAxisLockConstraint,create,linLow={1},linHi={2},angLow={3},angHi={4}",
170 m_controllingPrim.LocalID, linearLow, linearHigh, angularLow, angularHigh); 185 m_controllingPrim.LocalID,
186 m_controllingPrim.LockedLinearAxisLow,
187 m_controllingPrim.LockedLinearAxisHigh,
188 m_controllingPrim.LockedAngularAxisLow,
189 m_controllingPrim.LockedAngularAxisHigh);
171 190
172 // Constants from one of the posts mentioned above and used in Bullet's ConstraintDemo. 191 // Constants from one of the posts mentioned above and used in Bullet's ConstraintDemo.
173 axisConstrainer.TranslationalLimitMotor(true /* enable */, 5.0f, 0.1f); 192 axisConstrainer.TranslationalLimitMotor(true /* enable */, 5.0f, 0.1f);