diff options
Diffstat (limited to '')
-rwxr-xr-x | OpenSim/Region/Physics/BulletSPlugin/BSActorLockAxis.cs | 62 |
1 files changed, 34 insertions, 28 deletions
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSActorLockAxis.cs b/OpenSim/Region/Physics/BulletSPlugin/BSActorLockAxis.cs index 5f74a14..aa75663 100755 --- a/OpenSim/Region/Physics/BulletSPlugin/BSActorLockAxis.cs +++ b/OpenSim/Region/Physics/BulletSPlugin/BSActorLockAxis.cs | |||
@@ -42,14 +42,14 @@ public class BSActorLockAxis : BSActor | |||
42 | public BSActorLockAxis(BSScene physicsScene, BSPhysObject pObj, string actorName) | 42 | public BSActorLockAxis(BSScene physicsScene, BSPhysObject pObj, string actorName) |
43 | : base(physicsScene, pObj,actorName) | 43 | : base(physicsScene, pObj,actorName) |
44 | { | 44 | { |
45 | PhysicsScene.DetailLog("{0},BSActorLockAxis,constructor", Prim.LocalID); | 45 | m_physicsScene.DetailLog("{0},BSActorLockAxis,constructor", m_controllingPrim.LocalID); |
46 | LockAxisConstraint = null; | 46 | LockAxisConstraint = null; |
47 | } | 47 | } |
48 | 48 | ||
49 | // BSActor.isActive | 49 | // BSActor.isActive |
50 | public override bool isActive | 50 | public override bool isActive |
51 | { | 51 | { |
52 | get { return Enabled && Prim.IsPhysicallyActive; } | 52 | get { return Enabled && m_controllingPrim.IsPhysicallyActive; } |
53 | } | 53 | } |
54 | 54 | ||
55 | // Release any connections and resources used by the actor. | 55 | // Release any connections and resources used by the actor. |
@@ -64,21 +64,22 @@ public class BSActorLockAxis : BSActor | |||
64 | // BSActor.Refresh() | 64 | // BSActor.Refresh() |
65 | public override void Refresh() | 65 | public override void Refresh() |
66 | { | 66 | { |
67 | PhysicsScene.DetailLog("{0},BSActorLockAxis,refresh,lockedAxis={1},enabled={2},pActive={3}", | 67 | m_physicsScene.DetailLog("{0},BSActorLockAxis,refresh,lockedAxis={1},enabled={2},pActive={3}", |
68 | Prim.LocalID, Prim.LockedAxis, Enabled, Prim.IsPhysicallyActive); | 68 | m_controllingPrim.LocalID, m_controllingPrim.LockedAxis, Enabled, m_controllingPrim.IsPhysicallyActive); |
69 | // If all the axis are free, we don't need to exist | 69 | // If all the axis are free, we don't need to exist |
70 | if (Prim.LockedAxis == Prim.LockedAxisFree) | 70 | if (m_controllingPrim.LockedAxis == m_controllingPrim.LockedAxisFree) |
71 | { | 71 | { |
72 | Prim.PhysicalActors.RemoveAndRelease(ActorName); | 72 | m_physicsScene.DetailLog("{0},BSActorLockAxis,refresh,allAxisFree,removing={1}", m_controllingPrim.LocalID, ActorName); |
73 | m_controllingPrim.PhysicalActors.RemoveAndRelease(ActorName); | ||
73 | return; | 74 | return; |
74 | } | 75 | } |
75 | // If the object is physically active, add the axis locking constraint | 76 | // If the object is physically active, add the axis locking constraint |
76 | if (Enabled | 77 | if (Enabled |
77 | && Prim.IsPhysicallyActive | 78 | && m_controllingPrim.IsPhysicallyActive |
78 | && TryExperimentalLockAxisCode | 79 | && TryExperimentalLockAxisCode |
79 | && Prim.LockedAxis != Prim.LockedAxisFree) | 80 | && m_controllingPrim.LockedAxis != m_controllingPrim.LockedAxisFree) |
80 | { | 81 | { |
81 | if (LockAxisConstraint != null) | 82 | if (LockAxisConstraint == null) |
82 | AddAxisLockConstraint(); | 83 | AddAxisLockConstraint(); |
83 | } | 84 | } |
84 | else | 85 | else |
@@ -98,7 +99,7 @@ public class BSActorLockAxis : BSActor | |||
98 | // If a constraint is set up, remove it from the physical scene | 99 | // If a constraint is set up, remove it from the physical scene |
99 | RemoveAxisLockConstraint(); | 100 | RemoveAxisLockConstraint(); |
100 | // Schedule a call before the next simulation step to restore the constraint. | 101 | // Schedule a call before the next simulation step to restore the constraint. |
101 | PhysicsScene.PostTaintObject(Prim.LockedAxisActorName, Prim.LocalID, delegate() | 102 | m_physicsScene.PostTaintObject(m_controllingPrim.LockedAxisActorName, m_controllingPrim.LocalID, delegate() |
102 | { | 103 | { |
103 | Refresh(); | 104 | Refresh(); |
104 | }); | 105 | }); |
@@ -115,56 +116,61 @@ public class BSActorLockAxis : BSActor | |||
115 | // Remove any existing axis constraint (just to be sure) | 116 | // Remove any existing axis constraint (just to be sure) |
116 | RemoveAxisLockConstraint(); | 117 | RemoveAxisLockConstraint(); |
117 | 118 | ||
118 | BSConstraint6Dof axisConstrainer = new BSConstraint6Dof(PhysicsScene.World, Prim.PhysBody, | 119 | BSConstraint6Dof axisConstrainer = new BSConstraint6Dof(m_physicsScene.World, m_controllingPrim.PhysBody, |
119 | OMV.Vector3.Zero, OMV.Quaternion.Inverse(Prim.RawOrientation), | 120 | // OMV.Vector3.Zero, OMV.Quaternion.Identity, |
120 | true /* useLinearReferenceFrameB */, true /* disableCollisionsBetweenLinkedBodies */); | 121 | OMV.Vector3.Zero, OMV.Quaternion.Inverse(m_controllingPrim.RawOrientation), |
122 | // OMV.Vector3.Zero, m_controllingPrim.RawOrientation, | ||
123 | false /* useLinearReferenceFrameB */, true /* disableCollisionsBetweenLinkedBodies */); | ||
121 | LockAxisConstraint = axisConstrainer; | 124 | LockAxisConstraint = axisConstrainer; |
122 | PhysicsScene.Constraints.AddConstraint(LockAxisConstraint); | 125 | m_physicsScene.Constraints.AddConstraint(LockAxisConstraint); |
123 | 126 | ||
124 | // The constraint is tied to the world and oriented to the prim. | 127 | // The constraint is tied to the world and oriented to the prim. |
125 | 128 | ||
126 | // Free to move linearly | 129 | // Free to move linearly in the region |
127 | OMV.Vector3 linearLow = OMV.Vector3.Zero; | 130 | OMV.Vector3 linearLow = OMV.Vector3.Zero; |
128 | OMV.Vector3 linearHigh = PhysicsScene.TerrainManager.DefaultRegionSize; | 131 | OMV.Vector3 linearHigh = m_physicsScene.TerrainManager.DefaultRegionSize; |
129 | axisConstrainer.SetLinearLimits(linearLow, linearHigh); | 132 | axisConstrainer.SetLinearLimits(linearLow, linearHigh); |
130 | 133 | ||
131 | // Angular with some axis locked | 134 | // Angular with some axis locked |
132 | float f2PI = (float)Math.PI * 2f; | 135 | float fPI = (float)Math.PI; |
133 | OMV.Vector3 angularLow = new OMV.Vector3(-f2PI, -f2PI, -f2PI); | 136 | OMV.Vector3 angularLow = new OMV.Vector3(-fPI, -fPI, -fPI); |
134 | OMV.Vector3 angularHigh = new OMV.Vector3(f2PI, f2PI, f2PI); | 137 | OMV.Vector3 angularHigh = new OMV.Vector3(fPI, fPI, fPI); |
135 | if (Prim.LockedAxis.X != 1f) | 138 | if (m_controllingPrim.LockedAxis.X != 1f) |
136 | { | 139 | { |
137 | angularLow.X = 0f; | 140 | angularLow.X = 0f; |
138 | angularHigh.X = 0f; | 141 | angularHigh.X = 0f; |
139 | } | 142 | } |
140 | if (Prim.LockedAxis.Y != 1f) | 143 | if (m_controllingPrim.LockedAxis.Y != 1f) |
141 | { | 144 | { |
142 | angularLow.Y = 0f; | 145 | angularLow.Y = 0f; |
143 | angularHigh.Y = 0f; | 146 | angularHigh.Y = 0f; |
144 | } | 147 | } |
145 | if (Prim.LockedAxis.Z != 1f) | 148 | if (m_controllingPrim.LockedAxis.Z != 1f) |
146 | { | 149 | { |
147 | angularLow.Z = 0f; | 150 | angularLow.Z = 0f; |
148 | angularHigh.Z = 0f; | 151 | angularHigh.Z = 0f; |
149 | } | 152 | } |
150 | axisConstrainer.SetAngularLimits(angularLow, angularHigh); | 153 | if (!axisConstrainer.SetAngularLimits(angularLow, angularHigh)) |
154 | { | ||
155 | m_physicsScene.DetailLog("{0},BSActorLockAxis.AddAxisLockConstraint,failedSetAngularLimits", m_controllingPrim.LocalID); | ||
156 | } | ||
151 | 157 | ||
152 | PhysicsScene.DetailLog("{0},BSPrim.LockAngularMotion,create,linLow={1},linHi={2},angLow={3},angHi={4}", | 158 | m_physicsScene.DetailLog("{0},BSActorLockAxis.AddAxisLockConstraint,create,linLow={1},linHi={2},angLow={3},angHi={4}", |
153 | Prim.LocalID, linearLow, linearHigh, angularLow, angularHigh); | 159 | m_controllingPrim.LocalID, linearLow, linearHigh, angularLow, angularHigh); |
154 | 160 | ||
155 | // Constants from one of the posts mentioned above and used in Bullet's ConstraintDemo. | 161 | // Constants from one of the posts mentioned above and used in Bullet's ConstraintDemo. |
156 | axisConstrainer.TranslationalLimitMotor(true /* enable */, 5.0f, 0.1f); | 162 | axisConstrainer.TranslationalLimitMotor(true /* enable */, 5.0f, 0.1f); |
157 | 163 | ||
158 | axisConstrainer.RecomputeConstraintVariables(Prim.RawMass); | 164 | axisConstrainer.RecomputeConstraintVariables(m_controllingPrim.RawMass); |
159 | } | 165 | } |
160 | 166 | ||
161 | private void RemoveAxisLockConstraint() | 167 | private void RemoveAxisLockConstraint() |
162 | { | 168 | { |
163 | if (LockAxisConstraint != null) | 169 | if (LockAxisConstraint != null) |
164 | { | 170 | { |
165 | PhysicsScene.Constraints.RemoveAndDestroyConstraint(LockAxisConstraint); | 171 | m_physicsScene.Constraints.RemoveAndDestroyConstraint(LockAxisConstraint); |
166 | LockAxisConstraint = null; | 172 | LockAxisConstraint = null; |
167 | PhysicsScene.DetailLog("{0},BSPrim.CleanUpLockAxisPhysicals,destroyingConstraint", Prim.LocalID); | 173 | m_physicsScene.DetailLog("{0},BSActorLockAxis.RemoveAxisLockConstraint,destroyingConstraint", m_controllingPrim.LocalID); |
168 | } | 174 | } |
169 | } | 175 | } |
170 | } | 176 | } |