///<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); } } }
///<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 (var pair in subPairs.Keys) { if (!containedPairs.Contains(pair)) { pairsToRemove.Add(pair); } } for (int i = 0; i < pairsToRemove.Count; i++) { var toReturn = subPairs[pairsToRemove.Elements[i]]; subPairs.Remove(pairsToRemove.Elements[i]); toReturn.CleanUp(); toReturn.Factory.GiveBack(toReturn); } containedPairs.Clear(); pairsToRemove.Clear(); foreach (var 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); } } }
///<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 (var pair in subPairs.Keys) { if (!containedPairs.Contains(pair)) { pairsToRemove.Add(pair); } } for (int i = 0; i < pairsToRemove.Count; i++) { var 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 (var 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); } } }
public override void UpdateCollision(float dt) { WasContaining = Containing; WasTouching = Touching; //Gather current pairs. UpdateContainedPairs(); //Eliminate old pairs. foreach (var other in subPairs.Keys) { if (!containedPairs.Contains(other)) { pairsToRemove.Add(other); } } for (int i = 0; i < pairsToRemove.Count; i++) { var toReturn = subPairs[pairsToRemove.Elements[i]]; subPairs.Remove(pairsToRemove.Elements[i]); toReturn.CleanUp(); toReturn.Factory.GiveBack(toReturn); } containedPairs.Clear(); pairsToRemove.Clear(); //Scan the pairs in sequence, updating the state as we go. //Touching can be set to true by a single touching subpair. Touching = false; //Containing can be set to false by a single noncontaining or nontouching subpair. Containing = subPairs.Count > 0; foreach (var pair in subPairs.Values) { //For child convex pairs, we don't need to always perform containment checks. //Only check if the containment state has not yet been invalidated or a touching state has not been identified. var convexPair = pair as DetectorVolumeConvexPairHandler; if (convexPair != null) { convexPair.CheckContainment = Containing || !Touching; } pair.UpdateCollision(dt); if (pair.Touching) { Touching = true; //If one child is touching, then we are touching too. } else { Containing = false; //If one child isn't touching, then we aren't containing. } if (!pair.Containing) //If one child isn't containing, then we aren't containing. { Containing = false; } if (!Containing && Touching) { //If it's touching but not containing, no further pairs will change the state. //Containment has been invalidated by something that either didn't touch or wasn't contained. //Touching has been ensured by at least one object touching. break; } } NotifyDetectorVolumeOfChanges(); }