///<summary> /// Updates the pair handler's contacts. ///</summary> ///<param name="dt">Timestep duration.</param> protected virtual void UpdateContacts(float dt) { UpdateContainedPairs(dt); //Eliminate old pairs. foreach (TriangleEntry pair in subPairs.Keys) { if (!containedPairs.Contains(pair)) { pairsToRemove.Add(pair); } } for (int i = 0; i < pairsToRemove.Count; i++) { MobileMeshPairHandler toReturn = subPairs[pairsToRemove.Elements[i]]; subPairs.Remove(pairsToRemove.Elements[i]); //The contained pairs list pulled TriangleCollidables from a pool to create the opposing collidables. //Clean those up now. //CollidableA is used without checking, because MobileMeshPairHandlers always put the convex in slot A. CleanUpCollidable((TriangleCollidable)toReturn.CollidableA); toReturn.CleanUp(); toReturn.Factory.GiveBack(toReturn); } containedPairs.Clear(); pairsToRemove.Clear(); foreach (KeyValuePair <TriangleEntry, MobileMeshPairHandler> pair in subPairs) { if (pair.Value.BroadPhaseOverlap.collisionRule < CollisionRule.NoNarrowPhaseUpdate ) //Don't test if the collision rules say don't. { ConfigureCollidable(pair.Key, dt); //Update the contact count using our (the parent) contact count so that the child can avoid costly solidity testing. pair.Value.MeshManifold.parentContactCount = contactCount; pair.Value.UpdateCollision(dt); } } }
protected void TryToAdd(int index) { TriangleEntry entry = new TriangleEntry { Index = index }; if (!subPairs.ContainsKey(entry)) { CollidablePair collidablePair = new CollidablePair(CollidableA, entry.Collidable = GetOpposingCollidable(index)); MobileMeshPairHandler newPair = (MobileMeshPairHandler)NarrowPhaseHelper.GetPairHandler(ref collidablePair); if (newPair != null) { newPair.CollisionRule = CollisionRule; newPair.UpdateMaterialProperties(MaterialA, MaterialB); //Override the materials, if necessary. Meshes don't currently support custom materials but.. newPair.Parent = this; subPairs.Add(entry, newPair); } } containedPairs.Add(entry); }