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); }
// The constraint MUST exist in the collection public bool RemoveAndDestroyConstraint(BSConstraint constrain) { lock (m_constraints) { // remove the constraint from our collection m_constraints.Remove(constrain); } // tell the engine that all its structures need to be freed constrain.Dispose(); // we destroyed something return(true); }
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; }
// 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 public bool RemoveAndDestroyConstraint(BSConstraint constrain) { lock (m_constraints) { // remove the constraint from our collection m_constraints.Remove(constrain); } // tell the engine that all its structures need to be freed constrain.Dispose(); // we destroyed something return true; }