public bool AddConstraint(BSConstraint cons) { lock (m_constraints) { // There is only one constraint between any bodies. Remove any old just to make sure. RemoveAndDestroyConstraint(cons.Body1, cons.Body2); m_constraints.Add(cons); } return true; }
// Get the constraint between two bodies. There can be only one. // Return 'true' if a constraint was found. public bool TryGetConstraint(BulletBody body1, BulletBody body2, out BSConstraint returnConstraint) { bool found = false; BSConstraint foundConstraint = null; uint lookingID1 = body1.ID; uint lookingID2 = body2.ID; lock (m_constraints) { foreach (BSConstraint constrain in m_constraints) { if ((constrain.Body1.ID == lookingID1 && constrain.Body2.ID == lookingID2) || (constrain.Body1.ID == lookingID2 && constrain.Body2.ID == lookingID1)) { foundConstraint = constrain; found = true; break; } } } returnConstraint = foundConstraint; return found; }
// The constraint MUST exist in the collection // Could be called if the constraint was previously removed. // Return 'true' if the constraint was actually removed and disposed. public bool RemoveAndDestroyConstraint(BSConstraint constrain) { bool removed = false; lock (m_constraints) { // remove the constraint from our collection removed = m_constraints.Remove(constrain); } // Dispose() is safe to call multiple times constrain.Dispose(); return removed; }
public virtual void SetLinkParameters(BSConstraint constrain) { }
public BSActorLockAxis (BSScene physicsScene, BSPhysObject pObj, string actorName) : base (physicsScene, pObj, actorName) { m_physicsScene.DetailLog ("{0},BSActorLockAxis,constructor", m_controllingPrim.LocalID); LockAxisConstraint = null; }
void RemoveAxisLockConstraint () { UnRegisterForBeforeStepCallback (); if (LockAxisConstraint != null) { m_physicsScene.Constraints.RemoveAndDestroyConstraint (LockAxisConstraint); LockAxisConstraint = null; m_physicsScene.DetailLog ("{0},BSActorLockAxis.RemoveAxisLockConstraint,destroyingConstraint", m_controllingPrim.LocalID); } }
// Note that this relies on being called at TaintTime void AddAxisLockConstraint () { if (LockAxisConstraint == null) { // Lock that axis by creating a 6DOF constraint that has one end in the world and // the other in the object. // http://www.bulletphysics.org/Bullet/phpBB3/viewtopic.php?p=20817 // http://www.bulletphysics.org/Bullet/phpBB3/viewtopic.php?p=26380 // Remove any existing axis constraint (just to be sure) RemoveAxisLockConstraint (); BSConstraint6Dof axisConstrainer = new BSConstraint6Dof (m_physicsScene.World, m_controllingPrim.PhysBody, OMV.Vector3.Zero, OMV.Quaternion.Identity, false /* useLinearReferenceFrameB */, true /* disableCollisionsBetweenLinkedBodies */); LockAxisConstraint = axisConstrainer; m_physicsScene.Constraints.AddConstraint (LockAxisConstraint); // Remember the clocking being inforce so we can notice if they have changed LockAxisLinearFlags = m_controllingPrim.LockedLinearAxis; LockAxisAngularFlags = m_controllingPrim.LockedAngularAxis; // The constraint is tied to the world and oriented to the prim. if ( !axisConstrainer.SetLinearLimits (m_controllingPrim.LockedLinearAxisLow, m_controllingPrim.LockedLinearAxisHigh)) { m_physicsScene.DetailLog ("{0},BSActorLockAxis.AddAxisLockConstraint,failedSetLinearLimits", m_controllingPrim.LocalID); } if ( !axisConstrainer.SetAngularLimits (m_controllingPrim.LockedAngularAxisLow, m_controllingPrim.LockedAngularAxisHigh)) { m_physicsScene.DetailLog ("{0},BSActorLockAxis.AddAxisLockConstraint,failedSetAngularLimits", m_controllingPrim.LocalID); } m_physicsScene.DetailLog ( "{0},BSActorLockAxis.AddAxisLockConstraint,create,linLow={1},linHi={2},angLow={3},angHi={4}", m_controllingPrim.LocalID, m_controllingPrim.LockedLinearAxisLow, m_controllingPrim.LockedLinearAxisHigh, m_controllingPrim.LockedAngularAxisLow, m_controllingPrim.LockedAngularAxisHigh); // Constants from one of the posts mentioned above and used in Bullet's ConstraintDemo. axisConstrainer.TranslationalLimitMotor (true /* enable */, 5.0f, 0.1f); axisConstrainer.RecomputeConstraintVariables (m_controllingPrim.RawMass); RegisterForBeforeStepCallback (); } }
public BSLinkInfoConstraint(BSPrimLinkable pMember) : base(pMember) { constraint = null; ResetLink(); member.PhysicsScene.DetailLog("{0},BSLinkInfoConstraint.creation", member.LocalID); }