protected void TryToAdd(Collidable a, Collidable b, Material materialA, Material materialB) { CollisionRule rule; if ((rule = CollisionRules.collisionRuleCalculator(a, b)) < CollisionRule.NoNarrowPhasePair) { //Clamp the rule to the parent's rule. Always use the more restrictive option. //Don't have to test for NoNarrowPhasePair rule on the parent's rule because then the parent wouldn't exist! if (rule < CollisionRule) { rule = CollisionRule; } CollidablePair pair = new CollidablePair(a, b); if (!subPairs.ContainsKey(pair)) { CollidablePairHandler newPair = NarrowPhaseHelper.GetPairHandler(ref pair, rule); if (newPair != null) { newPair.UpdateMaterialProperties(materialA, materialB); //Override the materials, if necessary. newPair.Parent = this; subPairs.Add(pair, newPair); } } containedPairs.Add(pair); } }
///<summary> /// Updates the pair handler's contacts. ///</summary> ///<param name="dt">Timestep duration.</param> protected virtual void UpdateContacts(float dt) { UpdateContainedPairs(); //Eliminate old pairs. foreach (CollidablePair pair in subPairs.Keys) { if (!containedPairs.Contains(pair)) { pairsToRemove.Add(pair); } } for (int i = 0; i < pairsToRemove.Count; i++) { CollidablePairHandler toReturn = subPairs[pairsToRemove.Elements[i]]; subPairs.Remove(pairsToRemove.Elements[i]); toReturn.CleanUp(); toReturn.Factory.GiveBack(toReturn); } containedPairs.Clear(); pairsToRemove.Clear(); foreach (CollidablePairHandler pair in subPairs.Values) { if (pair.BroadPhaseOverlap.collisionRule < CollisionRule.NoNarrowPhaseUpdate ) //Don't test if the collision rules say don't. { pair.UpdateCollision(dt); } } }
internal ContactCollection(CollidablePairHandler pair) { this.pair = pair; }