aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/Physics/BulletSPlugin/BSActorLockAxis.cs
diff options
context:
space:
mode:
authorMelanie Thielker2014-06-21 00:39:55 +0200
committerMelanie Thielker2014-06-21 00:39:55 +0200
commit159fcbf150b7da0e229b29aa7b94793484543d12 (patch)
treeb8c0ff3b4c758a3fba8315b556c923ef4c02a185 /OpenSim/Region/Physics/BulletSPlugin/BSActorLockAxis.cs
parentMerge commit '68c8633ba18f0a11cfc0ed04d1d0c7c59e6cec76' (diff)
parentMerge branch 'master' into careminster (diff)
downloadopensim-SC_OLD-159fcbf150b7da0e229b29aa7b94793484543d12.zip
opensim-SC_OLD-159fcbf150b7da0e229b29aa7b94793484543d12.tar.gz
opensim-SC_OLD-159fcbf150b7da0e229b29aa7b94793484543d12.tar.bz2
opensim-SC_OLD-159fcbf150b7da0e229b29aa7b94793484543d12.tar.xz
Merge branch 'master' of ssh://3dhosting.de/var/git/careminster
Conflicts: OpenSim/Region/Framework/Scenes/SceneObjectGroup.cs
Diffstat (limited to 'OpenSim/Region/Physics/BulletSPlugin/BSActorLockAxis.cs')
-rwxr-xr-xOpenSim/Region/Physics/BulletSPlugin/BSActorLockAxis.cs136
1 files changed, 74 insertions, 62 deletions
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSActorLockAxis.cs b/OpenSim/Region/Physics/BulletSPlugin/BSActorLockAxis.cs
index 7219617..8b0fdeb 100755
--- a/OpenSim/Region/Physics/BulletSPlugin/BSActorLockAxis.cs
+++ b/OpenSim/Region/Physics/BulletSPlugin/BSActorLockAxis.cs
@@ -36,11 +36,10 @@ 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)
43 : base(physicsScene, pObj,actorName) 42 : base(physicsScene, pObj, actorName)
44 { 43 {
45 m_physicsScene.DetailLog("{0},BSActorLockAxis,constructor", m_controllingPrim.LocalID); 44 m_physicsScene.DetailLog("{0},BSActorLockAxis,constructor", m_controllingPrim.LocalID);
46 LockAxisConstraint = null; 45 LockAxisConstraint = null;
@@ -64,23 +63,18 @@ public class BSActorLockAxis : BSActor
64 // BSActor.Refresh() 63 // BSActor.Refresh()
65 public override void Refresh() 64 public override void Refresh()
66 { 65 {
67 m_physicsScene.DetailLog("{0},BSActorLockAxis,refresh,lockedAxis={1},enabled={2},pActive={3}", 66 m_physicsScene.DetailLog("{0},BSActorLockAxis,refresh,lockedAxis={1},enabled={2},pActive={3}",
68 m_controllingPrim.LocalID, m_controllingPrim.LockedAxis, Enabled, m_controllingPrim.IsPhysicallyActive); 67 m_controllingPrim.LocalID, m_controllingPrim.LockedAngularAxis, Enabled, m_controllingPrim.IsPhysicallyActive);
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.LockedAngularAxis == 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 {
@@ -91,15 +85,15 @@ public class BSActorLockAxis : BSActor
91 // The object's physical representation is being rebuilt so pick up any physical dependencies (constraints, ...). 85 // The object's physical representation is being rebuilt so pick up any physical dependencies (constraints, ...).
92 // Register a prestep action to restore physical requirements before the next simulation step. 86 // Register a prestep action to restore physical requirements before the next simulation step.
93 // Called at taint-time. 87 // Called at taint-time.
94 // BSActor.RemoveBodyDependencies() 88 // BSActor.RemoveDependencies()
95 public override void RemoveBodyDependencies() 89 public override void RemoveDependencies()
96 { 90 {
97 if (LockAxisConstraint != null) 91 if (LockAxisConstraint != null)
98 { 92 {
99 // If a constraint is set up, remove it from the physical scene 93 // If a constraint is set up, remove it from the physical scene
100 RemoveAxisLockConstraint(); 94 RemoveAxisLockConstraint();
101 // Schedule a call before the next simulation step to restore the constraint. 95 // Schedule a call before the next simulation step to restore the constraint.
102 m_physicsScene.PostTaintObject(m_controllingPrim.LockedAxisActorName, m_controllingPrim.LocalID, delegate() 96 m_physicsScene.PostTaintObject("BSActorLockAxis:" + ActorName, m_controllingPrim.LocalID, delegate()
103 { 97 {
104 Refresh(); 98 Refresh();
105 }); 99 });
@@ -108,58 +102,76 @@ 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.
115 109 // http://www.bulletphysics.org/Bullet/phpBB3/viewtopic.php?p=20817
116 // Remove any existing axis constraint (just to be sure) 110 // http://www.bulletphysics.org/Bullet/phpBB3/viewtopic.php?p=26380
117 RemoveAxisLockConstraint();
118 111
119 BSConstraint6Dof axisConstrainer = new BSConstraint6Dof(m_physicsScene.World, m_controllingPrim.PhysBody, 112 // Remove any existing axis constraint (just to be sure)
120 OMV.Vector3.Zero, OMV.Quaternion.Identity, 113 RemoveAxisLockConstraint();
121 false /* useLinearReferenceFrameB */, true /* disableCollisionsBetweenLinkedBodies */);
122 LockAxisConstraint = axisConstrainer;
123 m_physicsScene.Constraints.AddConstraint(LockAxisConstraint);
124 114
125 // The constraint is tied to the world and oriented to the prim. 115 BSConstraint6Dof axisConstrainer = new BSConstraint6Dof(m_physicsScene.World, m_controllingPrim.PhysBody,
116 OMV.Vector3.Zero, OMV.Quaternion.Identity,
117 false /* useLinearReferenceFrameB */, true /* disableCollisionsBetweenLinkedBodies */);
118 LockAxisConstraint = axisConstrainer;
119 m_physicsScene.Constraints.AddConstraint(LockAxisConstraint);
126 120
127 // Free to move linearly in the region 121 // The constraint is tied to the world and oriented to the prim.
128 OMV.Vector3 linearLow = OMV.Vector3.Zero;
129 OMV.Vector3 linearHigh = m_physicsScene.TerrainManager.DefaultRegionSize;
130 axisConstrainer.SetLinearLimits(linearLow, linearHigh);
131 122
132 // Angular with some axis locked 123 // Free to move linearly in the region
133 float fPI = (float)Math.PI; 124 OMV.Vector3 linearLow = OMV.Vector3.Zero;
134 OMV.Vector3 angularLow = new OMV.Vector3(-fPI, -fPI, -fPI); 125 OMV.Vector3 linearHigh = m_physicsScene.TerrainManager.DefaultRegionSize;
135 OMV.Vector3 angularHigh = new OMV.Vector3(fPI, fPI, fPI); 126 if (m_controllingPrim.LockedLinearAxis.X != BSPhysObject.FreeAxis)
136 if (m_controllingPrim.LockedAxis.X != 1f) 127 {
137 { 128 linearLow.X = m_controllingPrim.RawPosition.X;
138 angularLow.X = 0f; 129 linearHigh.X = m_controllingPrim.RawPosition.X;
139 angularHigh.X = 0f; 130 }
140 } 131 if (m_controllingPrim.LockedLinearAxis.Y != BSPhysObject.FreeAxis)
141 if (m_controllingPrim.LockedAxis.Y != 1f) 132 {
142 { 133 linearLow.Y = m_controllingPrim.RawPosition.Y;
143 angularLow.Y = 0f; 134 linearHigh.Y = m_controllingPrim.RawPosition.Y;
144 angularHigh.Y = 0f; 135 }
145 } 136 if (m_controllingPrim.LockedLinearAxis.Z != BSPhysObject.FreeAxis)
146 if (m_controllingPrim.LockedAxis.Z != 1f) 137 {
147 { 138 linearLow.Z = m_controllingPrim.RawPosition.Z;
148 angularLow.Z = 0f; 139 linearHigh.Z = m_controllingPrim.RawPosition.Z;
149 angularHigh.Z = 0f; 140 }
150 } 141 axisConstrainer.SetLinearLimits(linearLow, linearHigh);
151 if (!axisConstrainer.SetAngularLimits(angularLow, angularHigh)) 142
152 { 143 // Angular with some axis locked
153 m_physicsScene.DetailLog("{0},BSActorLockAxis.AddAxisLockConstraint,failedSetAngularLimits", m_controllingPrim.LocalID); 144 float fPI = (float)Math.PI;
154 } 145 OMV.Vector3 angularLow = new OMV.Vector3(-fPI, -fPI, -fPI);
146 OMV.Vector3 angularHigh = new OMV.Vector3(fPI, fPI, fPI);
147 if (m_controllingPrim.LockedAngularAxis.X != BSPhysObject.FreeAxis)
148 {
149 angularLow.X = 0f;
150 angularHigh.X = 0f;
151 }
152 if (m_controllingPrim.LockedAngularAxis.Y != BSPhysObject.FreeAxis)
153 {
154 angularLow.Y = 0f;
155 angularHigh.Y = 0f;
156 }
157 if (m_controllingPrim.LockedAngularAxis.Z != BSPhysObject.FreeAxis)
158 {
159 angularLow.Z = 0f;
160 angularHigh.Z = 0f;
161 }
162 if (!axisConstrainer.SetAngularLimits(angularLow, angularHigh))
163 {
164 m_physicsScene.DetailLog("{0},BSActorLockAxis.AddAxisLockConstraint,failedSetAngularLimits", m_controllingPrim.LocalID);
165 }
155 166
156 m_physicsScene.DetailLog("{0},BSActorLockAxis.AddAxisLockConstraint,create,linLow={1},linHi={2},angLow={3},angHi={4}", 167 m_physicsScene.DetailLog("{0},BSActorLockAxis.AddAxisLockConstraint,create,linLow={1},linHi={2},angLow={3},angHi={4}",
157 m_controllingPrim.LocalID, linearLow, linearHigh, angularLow, angularHigh); 168 m_controllingPrim.LocalID, linearLow, linearHigh, angularLow, angularHigh);
158 169
159 // Constants from one of the posts mentioned above and used in Bullet's ConstraintDemo. 170 // Constants from one of the posts mentioned above and used in Bullet's ConstraintDemo.
160 axisConstrainer.TranslationalLimitMotor(true /* enable */, 5.0f, 0.1f); 171 axisConstrainer.TranslationalLimitMotor(true /* enable */, 5.0f, 0.1f);
161 172
162 axisConstrainer.RecomputeConstraintVariables(m_controllingPrim.RawMass); 173 axisConstrainer.RecomputeConstraintVariables(m_controllingPrim.RawMass);
174 }
163 } 175 }
164 176
165 private void RemoveAxisLockConstraint() 177 private void RemoveAxisLockConstraint()