///<summary> /// Updates the manifold. ///</summary> ///<param name="dt">Timestep duration.</param> public override void Update(float dt) { //First, refresh all existing contacts. This is an incremental manifold. ContactRefresher.ContactRefresh(contacts, supplementData, ref collidableA.worldTransform, ref collidableB.worldTransform, contactIndicesToRemove); RemoveQueuedContacts(); //Now, generate a contact between the two shapes. ContactData contact; if (pairTester.GenerateContactCandidate(out contact)) { //Eliminate any old contacts which have normals which would fight with this new contact. for (int i = 0; i < contacts.Count; ++i) { float normalDot; Vector3.Dot(ref contacts.Elements[i].Normal, ref contact.Normal, out normalDot); if (normalDot < 0) { Remove(i); break; } } //If a contact is unique, add it to the manifold separately. //If it is redundant, it will be used to update an existing contact... within the IsContactUnique call. //In other words: THIS FUNCTION HAS IMPORTANT SNEAKY SIDE EFFECTS. if (IsContactUnique(ref contact)) { //Check if adding the new contact would overflow the manifold. if (contacts.Count == 4) { //Adding that contact would overflow the manifold. Reduce to the best subset. bool addCandidate; ContactReducer.ReduceContacts(contacts, ref contact, contactIndicesToRemove, out addCandidate); RemoveQueuedContacts(); if (addCandidate) { Add(ref contact); } } else { //Won't overflow the manifold, so just toss it in. Add(ref contact); } } } else { //No collision, clean out the manifold. for (int i = contacts.Count - 1; i >= 0; i--) { Remove(i); } } }
///<summary> /// Updates the manifold. ///</summary> ///<param name="dt">Timestep duration.</param> public override void Update(float dt) { //First, refresh all existing contacts. This is an incremental manifold. ContactRefresher.ContactRefresh(contacts, supplementData, ref collidableA.worldTransform, ref collidableB.worldTransform, contactIndicesToRemove); RemoveQueuedContacts(); //Now, generate a contact between the two shapes. ContactData contact; if (pairTester.GenerateContactCandidate(out contact)) { if (IsContactUnique(ref contact)) { //Check if adding the new contact would overflow the manifold. if (contacts.count == 4) { //Adding that contact would overflow the manifold. Reduce to the best subset. bool addCandidate; ContactReducer.ReduceContacts(contacts, ref contact, contactIndicesToRemove, out addCandidate); RemoveQueuedContacts(); if (addCandidate) { Add(ref contact); } } else { //Won't overflow the manifold, so just toss it in. Add(ref contact); } } } else { //No collision, clean out the manifold. for (int i = contacts.count - 1; i >= 0; i--) { Remove(i); } } }