// Broad-phase callback. private void AddPair(ref FixtureProxy proxyA, ref FixtureProxy proxyB) { Fixture fixtureA = proxyA.Fixture; Fixture fixtureB = proxyB.Fixture; int indexA = proxyA.ChildIndex; int indexB = proxyB.ChildIndex; Body bodyA = fixtureA.Body; Body bodyB = fixtureB.Body; // Are the fixtures on the same body? if (bodyA == bodyB) { return; } // Does a contact already exist? ContactEdge edge = bodyB.ContactList; while (edge != null) { if (edge.Other == bodyA) { Fixture fA = edge.Contact.FixtureA; Fixture fB = edge.Contact.FixtureB; int iA = edge.Contact.ChildIndexA; int iB = edge.Contact.ChildIndexB; if (fA == fixtureA && fB == fixtureB && iA == indexA && iB == indexB) { // A contact already exists. return; } if (fA == fixtureB && fB == fixtureA && iA == indexB && iB == indexA) { // A contact already exists. return; } } edge = edge.Next; } // Does a joint override collision? Is at least one body dynamic? if (bodyB.ShouldCollide(bodyA) == false) { return; } //Check default filter if (ShouldCollide(fixtureA, fixtureB) == false) { return; } // Check user filtering. if (ContactFilter != null && ContactFilter(fixtureA, fixtureB) == false) { return; } //FPE feature: BeforeCollision delegate if (fixtureA.BeforeCollision != null && fixtureA.BeforeCollision(fixtureA, fixtureB) == false) { return; } if (fixtureB.BeforeCollision != null && fixtureB.BeforeCollision(fixtureB, fixtureA) == false) { return; } Body specialSenseBody = null; Body otherBody = null; if (bodyA.SpecialSensor != BodySpecialSensor.None) { specialSenseBody = bodyA; otherBody = bodyB; } else if (bodyB.SpecialSensor != BodySpecialSensor.None) { specialSenseBody = bodyB; otherBody = bodyA; } if (specialSenseBody != null) { if (Collision.TestOverlap(fixtureA.Shape, indexA, fixtureB.Shape, indexB, ref bodyA._xf, ref bodyB._xf)) { specialSenseBody._specialSensorResults.Add(otherBody); if (specialSenseBody.SpecialSensor == BodySpecialSensor.ActiveOnce) { specialSenseBody.disabled = true; return; } } else { return; } } // Call the factory. Contact c = Contact.Create(fixtureA, indexA, fixtureB, indexB); if (c == null) { return; } // Contact creation may swap fixtures. fixtureA = c.FixtureA; fixtureB = c.FixtureB; bodyA = fixtureA.Body; bodyB = fixtureB.Body; // Insert into the world. ContactList.Add(c); #if USE_ACTIVE_CONTACT_SET ActiveContacts.Add(c); #endif // Connect to island graph. // Connect to body A c._nodeA.Contact = c; c._nodeA.Other = bodyB; c._nodeA.Prev = null; c._nodeA.Next = bodyA.ContactList; if (bodyA.ContactList != null) { bodyA.ContactList.Prev = c._nodeA; } bodyA.ContactList = c._nodeA; // Connect to body B c._nodeB.Contact = c; c._nodeB.Other = bodyA; c._nodeB.Prev = null; c._nodeB.Next = bodyB.ContactList; if (bodyB.ContactList != null) { bodyB.ContactList.Prev = c._nodeB; } bodyB.ContactList = c._nodeB; // Wake up the bodies if (fixtureA.IsSensor == false && fixtureB.IsSensor == false) { bodyA.Awake = true; bodyB.Awake = true; } }
private void AddPair(ref FixtureProxy proxyA, ref FixtureProxy proxyB) { Fixture fixture = proxyA.Fixture; Fixture fixture2 = proxyB.Fixture; int childIndex = proxyA.ChildIndex; int childIndex2 = proxyB.ChildIndex; Body body = fixture.Body; Body body2 = fixture2.Body; bool flag = body == body2; if (!flag) { for (ContactEdge contactEdge = body2.ContactList; contactEdge != null; contactEdge = contactEdge.Next) { bool flag2 = contactEdge.Other == body; if (flag2) { Fixture fixtureA = contactEdge.Contact.FixtureA; Fixture fixtureB = contactEdge.Contact.FixtureB; int childIndexA = contactEdge.Contact.ChildIndexA; int childIndexB = contactEdge.Contact.ChildIndexB; bool flag3 = fixtureA == fixture && fixtureB == fixture2 && childIndexA == childIndex && childIndexB == childIndex2; if (flag3) { return; } bool flag4 = fixtureA == fixture2 && fixtureB == fixture && childIndexA == childIndex2 && childIndexB == childIndex; if (flag4) { return; } } } bool flag5 = !body2.ShouldCollide(body); if (!flag5) { bool flag6 = !ContactManager.ShouldCollide(fixture, fixture2); if (!flag6) { bool flag7 = this.ContactFilter != null && !this.ContactFilter(fixture, fixture2); if (!flag7) { bool flag8 = fixture.BeforeCollision != null && !fixture.BeforeCollision(fixture, fixture2); if (!flag8) { bool flag9 = fixture2.BeforeCollision != null && !fixture2.BeforeCollision(fixture2, fixture); if (!flag9) { Body body3 = null; Body item = null; bool flag10 = body.SpecialSensor > BodySpecialSensor.None; if (flag10) { body3 = body; item = body2; } else { bool flag11 = body2.SpecialSensor > BodySpecialSensor.None; if (flag11) { body3 = body2; item = body; } } bool flag12 = body3 != null; if (flag12) { bool flag13 = Collision.TestOverlap(body.FixtureList[0].Shape, childIndex, body2.FixtureList[0].Shape, childIndex2, ref body._xf, ref body2._xf); if (!flag13) { return; } body3._specialSensorResults.Add(item); bool flag14 = body3.SpecialSensor == BodySpecialSensor.ActiveOnce; if (flag14) { body3.disabled = true; return; } } Contact contact = Contact.Create(fixture, childIndex, fixture2, childIndex2); bool flag15 = contact == null; if (!flag15) { fixture = contact.FixtureA; fixture2 = contact.FixtureB; body = fixture.Body; body2 = fixture2.Body; this.ContactList.Add(contact); contact._nodeA.Contact = contact; contact._nodeA.Other = body2; contact._nodeA.Prev = null; contact._nodeA.Next = body.ContactList; bool flag16 = body.ContactList != null; if (flag16) { body.ContactList.Prev = contact._nodeA; } body.ContactList = contact._nodeA; contact._nodeB.Contact = contact; contact._nodeB.Other = body; contact._nodeB.Prev = null; contact._nodeB.Next = body2.ContactList; bool flag17 = body2.ContactList != null; if (flag17) { body2.ContactList.Prev = contact._nodeB; } body2.ContactList = contact._nodeB; bool flag18 = !fixture.IsSensor && !fixture2.IsSensor; if (flag18) { body.Awake = true; body2.Awake = true; } } } } } } } } }
internal void Collide() { // Update awake contacts. #if USE_ACTIVE_CONTACT_SET ActiveList.AddRange(ActiveContacts); foreach (var c in ActiveList) { #else for (int i = 0; i < ContactList.Count; i++) { Contact c = ContactList[i]; #endif Fixture fixtureA = c.FixtureA; Fixture fixtureB = c.FixtureB; int indexA = c.ChildIndexA; int indexB = c.ChildIndexB; Body bodyA = fixtureA.Body; Body bodyB = fixtureB.Body; //Do no try to collide disabled bodies if (!bodyA.Enabled || !bodyB.Enabled) { continue; } // Is this contact flagged for filtering? if (c.FilterFlag) { // Should these bodies collide? if (bodyB.ShouldCollide(bodyA) == false) { Contact cNuke = c; Destroy(cNuke); continue; } // Check default filtering if (ShouldCollide(fixtureA, fixtureB) == false) { Contact cNuke = c; Destroy(cNuke); continue; } // Check user filtering. if (ContactFilter != null && ContactFilter(fixtureA, fixtureB) == false) { Contact cNuke = c; Destroy(cNuke); continue; } // Clear the filtering flag. c.FilterFlag = false; } bool activeA = bodyA.Awake && bodyA.BodyType != BodyType.Static; bool activeB = bodyB.Awake && bodyB.BodyType != BodyType.Static; // At least one body must be awake and it must be dynamic or kinematic. if (activeA == false && activeB == false) { #if USE_ACTIVE_CONTACT_SET ActiveContacts.Remove(c); #endif continue; } if (fixtureA == null || fixtureA.Proxies == null || fixtureB == null || fixtureB.Proxies == null) { continue; } int proxyIdA = fixtureA.Proxies[indexA].ProxyId; int proxyIdB = fixtureB.Proxies[indexB].ProxyId; bool overlap = BroadPhase.TestOverlap(proxyIdA, proxyIdB); // Here we destroy contacts that cease to overlap in the broad-phase. if (overlap == false) { Contact cNuke = c; Destroy(cNuke); continue; } // The contact persists. c.Update(this); } #if USE_ACTIVE_CONTACT_SET ActiveList.Clear(); #endif }
internal void Collide() { for (int i = 0; i < this.ContactList.Count; i++) { Contact contact = this.ContactList[i]; Fixture fixtureA = contact.FixtureA; Fixture fixtureB = contact.FixtureB; int childIndexA = contact.ChildIndexA; int childIndexB = contact.ChildIndexB; Body body = fixtureA.Body; Body body2 = fixtureB.Body; bool flag = !body.Enabled || !body2.Enabled; if (!flag) { bool filterFlag = contact.FilterFlag; if (filterFlag) { bool flag2 = !body2.ShouldCollide(body); if (flag2) { Contact contact2 = contact; this.Destroy(contact2); goto IL_198; } bool flag3 = !ContactManager.ShouldCollide(fixtureA, fixtureB); if (flag3) { Contact contact3 = contact; this.Destroy(contact3); goto IL_198; } bool flag4 = this.ContactFilter != null && !this.ContactFilter(fixtureA, fixtureB); if (flag4) { Contact contact4 = contact; this.Destroy(contact4); goto IL_198; } contact.FilterFlag = false; } bool flag5 = body.Awake && body.BodyType > BodyType.Static; bool flag6 = body2.Awake && body2.BodyType > BodyType.Static; bool flag7 = !flag5 && !flag6; if (!flag7) { int proxyId = fixtureA.Proxies[childIndexA].ProxyId; int proxyId2 = fixtureB.Proxies[childIndexB].ProxyId; bool flag8 = this.BroadPhase.TestOverlap(proxyId, proxyId2); bool flag9 = !flag8; if (flag9) { Contact contact5 = contact; this.Destroy(contact5); } else { contact.Update(this); } } } IL_198 :; } }