/// <summary> /// Update the contact manifold and touching status. /// Note: do not assume the fixture AABBs are overlapping or are valid. /// </summary> /// <param name="contactManager">The contact manager.</param> internal void Update(ContactManager contactManager) { Body bodyA = FixtureA.Body; Body bodyB = FixtureB.Body; if (FixtureA == null || FixtureB == null) { return; } if (!ContactManager.CheckCollisionConditions(FixtureA, FixtureB)) { Enabled = false; return; } Manifold oldManifold = Manifold; // Re-enable this contact. Enabled = true; bool touching; bool wasTouching = IsTouching; bool sensor = FixtureA.IsSensor || FixtureB.IsSensor; // Is this contact a sensor? if (sensor) { Shape shapeA = FixtureA.Shape; Shape shapeB = FixtureB.Shape; touching = Collision.TestOverlap(shapeA, ChildIndexA, shapeB, ChildIndexB, ref bodyA._xf, ref bodyB._xf); // Sensors don't generate manifolds. Manifold.PointCount = 0; } else { Evaluate(ref Manifold, ref bodyA._xf, ref bodyB._xf); touching = Manifold.PointCount > 0; // Match old contact ids to new contact ids and copy the // stored impulses to warm start the solver. for (int i = 0; i < Manifold.PointCount; ++i) { ManifoldPoint mp2 = Manifold.Points[i]; mp2.NormalImpulse = 0.0f; mp2.TangentImpulse = 0.0f; ContactID id2 = mp2.Id; for (int j = 0; j < oldManifold.PointCount; ++j) { ManifoldPoint mp1 = oldManifold.Points[j]; if (mp1.Id.Key == id2.Key) { mp2.NormalImpulse = mp1.NormalImpulse; mp2.TangentImpulse = mp1.TangentImpulse; break; } } Manifold.Points[i] = mp2; } if (touching != wasTouching) { bodyA.Awake = true; bodyB.Awake = true; } } IsTouching = touching; if (wasTouching == false) { if (touching) { if (Settings.AllCollisionCallbacksAgree) { bool enabledA = true, enabledB = true; // Report the collision to both participants. Track which ones returned true so we can // later call OnSeparation if the contact is disabled for a different reason. if (FixtureA.OnCollision != null) { foreach (OnCollisionEventHandler handler in FixtureA.OnCollision.GetInvocationList()) { enabledA = handler(FixtureA, FixtureB, this) && enabledA; } } // Reverse the order of the reported fixtures. The first fixture is always the one that the // user subscribed to. if (FixtureB.OnCollision != null) { foreach (OnCollisionEventHandler handler in FixtureB.OnCollision.GetInvocationList()) { enabledB = handler(FixtureB, FixtureA, this) && enabledB; } } Enabled = enabledA && enabledB; // BeginContact can also return false and disable the contact if (enabledA && enabledB && contactManager.BeginContact != null) { Enabled = contactManager.BeginContact(this); } } else { //Report the collision to both participants: if (FixtureA.OnCollision != null) { foreach (OnCollisionEventHandler handler in FixtureA.OnCollision.GetInvocationList()) { Enabled = handler(FixtureA, FixtureB, this); } } //Reverse the order of the reported fixtures. The first fixture is always the one that the //user subscribed to. if (FixtureB.OnCollision != null) { foreach (OnCollisionEventHandler handler in FixtureB.OnCollision.GetInvocationList()) { Enabled = handler(FixtureB, FixtureA, this); } } //BeginContact can also return false and disable the contact if (contactManager.BeginContact != null) { Enabled = contactManager.BeginContact(this); } } // If the user disabled the contact (needed to exclude it in TOI solver) at any point by // any of the callbacks, we need to mark it as not touching and call any separation // callbacks for fixtures that didn't explicitly disable the collision. if (!Enabled) { IsTouching = false; } } } else { if (touching == false) { //Report the separation to both participants: if (FixtureA != null && FixtureA.OnSeparation != null) { FixtureA.OnSeparation(FixtureA, FixtureB); } //Reverse the order of the reported fixtures. The first fixture is always the one that the //user subscribed to. if (FixtureB != null && FixtureB.OnSeparation != null) { FixtureB.OnSeparation(FixtureB, FixtureA); } if (contactManager.EndContact != null) { contactManager.EndContact(this); } } else { if (contactManager.StayContact != null) { contactManager.StayContact(this); } } } if (sensor) { return; } if (contactManager.PreSolve != null) { contactManager.PreSolve(this, ref oldManifold); } }
internal void Update(ContactManager contactManager) { Body body = this.FixtureA.Body; Body body2 = this.FixtureB.Body; bool flag = this.FixtureA == null || this.FixtureB == null; if (!flag) { bool flag2 = !ContactManager.CheckCollisionConditions(this.FixtureA, this.FixtureB); if (flag2) { this.Enabled = false; } else { Manifold manifold = this.Manifold; this.Enabled = true; bool isTouching = this.IsTouching; bool flag3 = this.FixtureA.IsSensor || this.FixtureB.IsSensor; bool flag4 = flag3; bool flag5; if (flag4) { Shape shape = this.FixtureA.Shape; Shape shape2 = this.FixtureB.Shape; flag5 = Collision.TestOverlap(shape, this.ChildIndexA, shape2, this.ChildIndexB, ref body._xf, ref body2._xf); this.Manifold.PointCount = 0; } else { this.Evaluate(ref this.Manifold, ref body._xf, ref body2._xf); flag5 = (this.Manifold.PointCount > 0); for (int i = 0; i < this.Manifold.PointCount; i++) { ManifoldPoint manifoldPoint = this.Manifold.Points[i]; manifoldPoint.NormalImpulse = 0f; manifoldPoint.TangentImpulse = 0f; ContactID id = manifoldPoint.Id; for (int j = 0; j < manifold.PointCount; j++) { ManifoldPoint manifoldPoint2 = manifold.Points[j]; bool flag6 = manifoldPoint2.Id.Key == id.Key; if (flag6) { manifoldPoint.NormalImpulse = manifoldPoint2.NormalImpulse; manifoldPoint.TangentImpulse = manifoldPoint2.TangentImpulse; break; } } this.Manifold.Points[i] = manifoldPoint; } bool flag7 = flag5 != isTouching; if (flag7) { body.Awake = true; body2.Awake = true; } } this.IsTouching = flag5; bool flag8 = !isTouching; if (flag8) { bool flag9 = flag5; if (flag9) { bool flag10 = true; bool flag11 = true; bool flag12 = this.FixtureA.OnCollision != null; if (flag12) { Delegate[] invocationList = this.FixtureA.OnCollision.GetInvocationList(); for (int k = 0; k < invocationList.Length; k++) { OnCollisionEventHandler onCollisionEventHandler = (OnCollisionEventHandler)invocationList[k]; flag10 = (onCollisionEventHandler(this.FixtureA, this.FixtureB, this) & flag10); } } bool flag13 = this.FixtureB.OnCollision != null; if (flag13) { Delegate[] invocationList2 = this.FixtureB.OnCollision.GetInvocationList(); for (int l = 0; l < invocationList2.Length; l++) { OnCollisionEventHandler onCollisionEventHandler2 = (OnCollisionEventHandler)invocationList2[l]; flag11 = (onCollisionEventHandler2(this.FixtureB, this.FixtureA, this) & flag11); } } this.Enabled = (flag10 & flag11); bool flag14 = (flag10 & flag11) && contactManager.BeginContact != null; if (flag14) { this.Enabled = contactManager.BeginContact(this); } bool flag15 = !this.Enabled; if (flag15) { this.IsTouching = false; } } } else { bool flag16 = !flag5; if (flag16) { bool flag17 = this.FixtureA != null && this.FixtureA.OnSeparation != null; if (flag17) { this.FixtureA.OnSeparation(this.FixtureA, this.FixtureB); } bool flag18 = this.FixtureB != null && this.FixtureB.OnSeparation != null; if (flag18) { this.FixtureB.OnSeparation(this.FixtureB, this.FixtureA); } bool flag19 = contactManager.EndContact != null; if (flag19) { contactManager.EndContact(this); } } else { bool flag20 = contactManager.StayContact != null; if (flag20) { contactManager.StayContact(this); } } } bool flag21 = flag3; if (!flag21) { bool flag22 = contactManager.PreSolve != null; if (flag22) { contactManager.PreSolve(this, ref manifold); } } } } }