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.cs105
1 files changed, 51 insertions, 54 deletions
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSActorLockAxis.cs b/OpenSim/Region/Physics/BulletSPlugin/BSActorLockAxis.cs
index c40a499..09ee32b 100755
--- a/OpenSim/Region/Physics/BulletSPlugin/BSActorLockAxis.cs
+++ b/OpenSim/Region/Physics/BulletSPlugin/BSActorLockAxis.cs
@@ -36,7 +36,6 @@ namespace OpenSim.Region.Physics.BulletSPlugin
36{ 36{
37public class BSActorLockAxis : BSActor 37public class BSActorLockAxis : BSActor
38{ 38{
39 bool TryExperimentalLockAxisCode = true;
40 BSConstraint LockAxisConstraint = null; 39 BSConstraint LockAxisConstraint = null;
41 40
42 public BSActorLockAxis(BSScene physicsScene, BSPhysObject pObj, string actorName) 41 public BSActorLockAxis(BSScene physicsScene, BSPhysObject pObj, string actorName)
@@ -69,18 +68,13 @@ public class BSActorLockAxis : BSActor
69 // If all the axis are free, we don't need to exist 68 // If all the axis are free, we don't need to exist
70 if (m_controllingPrim.LockedAxis == m_controllingPrim.LockedAxisFree) 69 if (m_controllingPrim.LockedAxis == m_controllingPrim.LockedAxisFree)
71 { 70 {
72 m_physicsScene.DetailLog("{0},BSActorLockAxis,refresh,allAxisFree,removing={1}", m_controllingPrim.LocalID, ActorName); 71 Enabled = false;
73 m_controllingPrim.PhysicalActors.RemoveAndRelease(ActorName);
74 return;
75 } 72 }
73
76 // If the object is physically active, add the axis locking constraint 74 // If the object is physically active, add the axis locking constraint
77 if (Enabled 75 if (isActive)
78 && m_controllingPrim.IsPhysicallyActive
79 && TryExperimentalLockAxisCode
80 && m_controllingPrim.LockedAxis != m_controllingPrim.LockedAxisFree)
81 { 76 {
82 if (LockAxisConstraint == null) 77 AddAxisLockConstraint();
83 AddAxisLockConstraint();
84 } 78 }
85 else 79 else
86 { 80 {
@@ -108,58 +102,61 @@ public class BSActorLockAxis : BSActor
108 102
109 private void AddAxisLockConstraint() 103 private void AddAxisLockConstraint()
110 { 104 {
111 // Lock that axis by creating a 6DOF constraint that has one end in the world and 105 if (LockAxisConstraint == null)
112 // the other in the object. 106 {
113 // http://www.bulletphysics.org/Bullet/phpBB3/viewtopic.php?p=20817 107 // Lock that axis by creating a 6DOF constraint that has one end in the world and
114 // http://www.bulletphysics.org/Bullet/phpBB3/viewtopic.php?p=26380 108 // the other in the object.
109 // http://www.bulletphysics.org/Bullet/phpBB3/viewtopic.php?p=20817
110 // http://www.bulletphysics.org/Bullet/phpBB3/viewtopic.php?p=26380
115 111
116 // Remove any existing axis constraint (just to be sure) 112 // Remove any existing axis constraint (just to be sure)
117 RemoveAxisLockConstraint(); 113 RemoveAxisLockConstraint();
118 114
119 BSConstraint6Dof axisConstrainer = new BSConstraint6Dof(m_physicsScene.World, m_controllingPrim.PhysBody, 115 BSConstraint6Dof axisConstrainer = new BSConstraint6Dof(m_physicsScene.World, m_controllingPrim.PhysBody,
120 OMV.Vector3.Zero, OMV.Quaternion.Identity, 116 OMV.Vector3.Zero, OMV.Quaternion.Identity,
121 false /* useLinearReferenceFrameB */, true /* disableCollisionsBetweenLinkedBodies */); 117 false /* useLinearReferenceFrameB */, true /* disableCollisionsBetweenLinkedBodies */);
122 LockAxisConstraint = axisConstrainer; 118 LockAxisConstraint = axisConstrainer;
123 m_physicsScene.Constraints.AddConstraint(LockAxisConstraint); 119 m_physicsScene.Constraints.AddConstraint(LockAxisConstraint);
124 120
125 // The constraint is tied to the world and oriented to the prim. 121 // The constraint is tied to the world and oriented to the prim.
126 122
127 // Free to move linearly in the region 123 // Free to move linearly in the region
128 OMV.Vector3 linearLow = OMV.Vector3.Zero; 124 OMV.Vector3 linearLow = OMV.Vector3.Zero;
129 OMV.Vector3 linearHigh = m_physicsScene.TerrainManager.DefaultRegionSize; 125 OMV.Vector3 linearHigh = m_physicsScene.TerrainManager.DefaultRegionSize;
130 axisConstrainer.SetLinearLimits(linearLow, linearHigh); 126 axisConstrainer.SetLinearLimits(linearLow, linearHigh);
131 127
132 // Angular with some axis locked 128 // Angular with some axis locked
133 float fPI = (float)Math.PI; 129 float fPI = (float)Math.PI;
134 OMV.Vector3 angularLow = new OMV.Vector3(-fPI, -fPI, -fPI); 130 OMV.Vector3 angularLow = new OMV.Vector3(-fPI, -fPI, -fPI);
135 OMV.Vector3 angularHigh = new OMV.Vector3(fPI, fPI, fPI); 131 OMV.Vector3 angularHigh = new OMV.Vector3(fPI, fPI, fPI);
136 if (m_controllingPrim.LockedAxis.X != 1f) 132 if (m_controllingPrim.LockedAxis.X != 1f)
137 { 133 {
138 angularLow.X = 0f; 134 angularLow.X = 0f;
139 angularHigh.X = 0f; 135 angularHigh.X = 0f;
140 } 136 }
141 if (m_controllingPrim.LockedAxis.Y != 1f) 137 if (m_controllingPrim.LockedAxis.Y != 1f)
142 { 138 {
143 angularLow.Y = 0f; 139 angularLow.Y = 0f;
144 angularHigh.Y = 0f; 140 angularHigh.Y = 0f;
145 } 141 }
146 if (m_controllingPrim.LockedAxis.Z != 1f) 142 if (m_controllingPrim.LockedAxis.Z != 1f)
147 { 143 {
148 angularLow.Z = 0f; 144 angularLow.Z = 0f;
149 angularHigh.Z = 0f; 145 angularHigh.Z = 0f;
150 } 146 }
151 if (!axisConstrainer.SetAngularLimits(angularLow, angularHigh)) 147 if (!axisConstrainer.SetAngularLimits(angularLow, angularHigh))
152 { 148 {
153 m_physicsScene.DetailLog("{0},BSActorLockAxis.AddAxisLockConstraint,failedSetAngularLimits", m_controllingPrim.LocalID); 149 m_physicsScene.DetailLog("{0},BSActorLockAxis.AddAxisLockConstraint,failedSetAngularLimits", m_controllingPrim.LocalID);
154 } 150 }
155 151
156 m_physicsScene.DetailLog("{0},BSActorLockAxis.AddAxisLockConstraint,create,linLow={1},linHi={2},angLow={3},angHi={4}", 152 m_physicsScene.DetailLog("{0},BSActorLockAxis.AddAxisLockConstraint,create,linLow={1},linHi={2},angLow={3},angHi={4}",
157 m_controllingPrim.LocalID, linearLow, linearHigh, angularLow, angularHigh); 153 m_controllingPrim.LocalID, linearLow, linearHigh, angularLow, angularHigh);
158 154
159 // Constants from one of the posts mentioned above and used in Bullet's ConstraintDemo. 155 // Constants from one of the posts mentioned above and used in Bullet's ConstraintDemo.
160 axisConstrainer.TranslationalLimitMotor(true /* enable */, 5.0f, 0.1f); 156 axisConstrainer.TranslationalLimitMotor(true /* enable */, 5.0f, 0.1f);
161 157
162 axisConstrainer.RecomputeConstraintVariables(m_controllingPrim.RawMass); 158 axisConstrainer.RecomputeConstraintVariables(m_controllingPrim.RawMass);
159 }
163 } 160 }
164 161
165 private void RemoveAxisLockConstraint() 162 private void RemoveAxisLockConstraint()