/// <summary>
        /// Removes the specified constraint from the collision filter.
        /// </summary>
        /// <param name="constraint">The constraint to be removed.</param>
        internal void UnregisterFromCollisionFilter(Constraint constraint)
        {
            Debug.Assert(constraint != null, "constraint is null.");
              Debug.Assert(constraint.BodyA != null, "constraint.BodyA is null.");
              Debug.Assert(constraint.BodyB != null, "constraint.BodyB is null.");

              var pair = new Pair<CollisionObject>(constraint.BodyA.CollisionObject, constraint.BodyB.CollisionObject);
              Debug.Assert(_constraints.ContainsKey(pair), "No constraint is stored in the collision filter for the given pair of collision objects.");
              List<Constraint> constraints = _constraints[pair];
              Debug.Assert(constraints.Contains(constraint));
              if (constraints.Count == 1)
              {
            // The constraint is the only constraint of this pair.
            // --> Remove the entry for this pair.
            Debug.Assert(constraints[0] == constraint, "Constraint is not registered in collision filter.");
            ResourcePools<Constraint>.Lists.Recycle(constraints);
            _constraints.Remove(pair);

            // Re-enable collisions.
            var filter = CollisionDomain.CollisionDetection.CollisionFilter as ICollisionFilter;
            if (filter != null)
              filter.Set(pair.First, pair.Second, true);
              }
              else
              {
            // Remove the constraint from the list.
            constraints.Remove(constraint);
              }
        }
        /// <summary>
        /// Adds the specified constraint to the collision filter.
        /// </summary>
        /// <param name="constraint">The constraint to be registered.</param>
        internal void RegisterInCollisionFilter(Constraint constraint)
        {
            Debug.Assert(constraint != null, "constraint is null.");
              Debug.Assert(constraint.BodyA != null, "constraint.BodyA is null.");
              Debug.Assert(constraint.BodyB != null, "constraint.BodyB is null.");
              Debug.Assert(constraint.Enabled && !constraint.CollisionEnabled, "Constraints should only be registered if it disabled collisions.");

              var pair = new Pair<CollisionObject>(constraint.BodyA.CollisionObject, constraint.BodyB.CollisionObject);
              List<Constraint> constraints;
              if (!_constraints.TryGetValue(pair, out constraints))
              {
            // Create new list of constraints for the current pair.
            constraints = ResourcePools<Constraint>.Lists.Obtain();
            _constraints[pair] = constraints;
              }

              if (!constraints.Contains(constraint))
              {
            if (constraints.Count == 0)
            {
              var filter = CollisionDomain.CollisionDetection.CollisionFilter as ICollisionFilter;
              if (filter != null)
            filter.Set(pair.First, pair.Second, false);
            }

            constraints.Add(constraint);
              }
        }