29 using System.Collections.Generic;
33 using OMV = OpenMetaverse;
35 namespace OpenSim.Region.PhysicsModule.BulletS
40 private bool HaveRegisteredForBeforeStepCallback =
false;
44 OMV.Vector3 LockAxisLinearFlags;
45 OMV.Vector3 LockAxisAngularFlags;
48 : base(physicsScene, pObj, actorName)
50 m_physicsScene.DetailLog(
"{0},BSActorLockAxis,constructor", m_controllingPrim.LocalID);
51 LockAxisConstraint = null;
52 HaveRegisteredForBeforeStepCallback =
false;
56 public override bool isActive
58 get {
return Enabled && m_controllingPrim.IsPhysicallyActive; }
66 UnRegisterForBeforeStepCallback();
67 RemoveAxisLockConstraint();
83 if (m_controllingPrim.LockedAngularAxis == m_controllingPrim.LockedAxisFree
84 && m_controllingPrim.LockedLinearAxis == m_controllingPrim.LockedAxisFree)
91 RegisterForBeforeStepCallback();
96 UnRegisterForBeforeStepCallback();
106 RemoveAxisLockConstraint();
109 private void RegisterForBeforeStepCallback()
111 if (!HaveRegisteredForBeforeStepCallback)
113 m_physicsScene.BeforeStep += PhysicsScene_BeforeStep;
114 HaveRegisteredForBeforeStepCallback =
true;
118 private void UnRegisterForBeforeStepCallback()
120 if (HaveRegisteredForBeforeStepCallback)
122 m_physicsScene.BeforeStep -= PhysicsScene_BeforeStep;
123 HaveRegisteredForBeforeStepCallback =
false;
127 private void PhysicsScene_BeforeStep(
float timestep)
130 if (m_controllingPrim.LockedAngularAxis == m_controllingPrim.LockedAxisFree
131 && m_controllingPrim.LockedLinearAxis == m_controllingPrim.LockedAxisFree)
140 if (m_controllingPrim.LockedLinearAxis !=
this.LockAxisLinearFlags
141 || m_controllingPrim.LockedAngularAxis !=
this.LockAxisAngularFlags)
144 RemoveAxisLockConstraint();
147 AddAxisLockConstraint();
151 RemoveAxisLockConstraint();
156 private void AddAxisLockConstraint()
158 if (LockAxisConstraint == null)
166 RemoveAxisLockConstraint();
168 BSConstraint6Dof axisConstrainer =
new BSConstraint6Dof(m_physicsScene.World, m_controllingPrim.PhysBody,
169 OMV.Vector3.Zero,
OMV.Quaternion.Identity,
171 LockAxisConstraint = axisConstrainer;
172 m_physicsScene.Constraints.AddConstraint(LockAxisConstraint);
175 LockAxisLinearFlags = m_controllingPrim.LockedLinearAxis;
176 LockAxisAngularFlags = m_controllingPrim.LockedAngularAxis;
180 if (!axisConstrainer.SetLinearLimits(m_controllingPrim.LockedLinearAxisLow, m_controllingPrim.LockedLinearAxisHigh))
182 m_physicsScene.DetailLog(
"{0},BSActorLockAxis.AddAxisLockConstraint,failedSetLinearLimits",
183 m_controllingPrim.LocalID);
186 if (!axisConstrainer.SetAngularLimits(m_controllingPrim.LockedAngularAxisLow, m_controllingPrim.LockedAngularAxisHigh))
188 m_physicsScene.DetailLog(
"{0},BSActorLockAxis.AddAxisLockConstraint,failedSetAngularLimits",
189 m_controllingPrim.LocalID);
192 m_physicsScene.DetailLog(
"{0},BSActorLockAxis.AddAxisLockConstraint,create,linLow={1},linHi={2},angLow={3},angHi={4}",
193 m_controllingPrim.LocalID,
194 m_controllingPrim.LockedLinearAxisLow,
195 m_controllingPrim.LockedLinearAxisHigh,
196 m_controllingPrim.LockedAngularAxisLow,
197 m_controllingPrim.LockedAngularAxisHigh);
200 axisConstrainer.TranslationalLimitMotor(
true , 5.0f, 0.1f);
202 axisConstrainer.RecomputeConstraintVariables(m_controllingPrim.RawMass);
204 RegisterForBeforeStepCallback();
208 private void RemoveAxisLockConstraint()
210 UnRegisterForBeforeStepCallback();
211 if (LockAxisConstraint != null)
213 m_physicsScene.Constraints.RemoveAndDestroyConstraint(LockAxisConstraint);
214 LockAxisConstraint = null;
215 m_physicsScene.DetailLog(
"{0},BSActorLockAxis.RemoveAxisLockConstraint,destroyingConstraint", m_controllingPrim.LocalID);
override void RemoveDependencies()
Each physical object can have 'actors' who are pushing the object around. This can be used for hover...
BSActorLockAxis(BSScene physicsScene, BSPhysObject pObj, string actorName)