Exemple #1
0
 public void ContactUpdate(CollideEventArg contact)
 {
     Contacted?.Invoke(this, contact);
 }
Exemple #2
0
        internal void Collide()
        {
            Dictionary <int, HashSet <Body> > dictionary = new Dictionary <int, HashSet <Body> >();
            HashSet <Contact> setOfContacts = null;

            // 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;

                //num++;
                //Debug.WriteLine(num);

                //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;
                }

                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.SetContactManager(this);
                c.MyUpdate(this, dictionary);
            }
            Contacted?.Invoke(this, new CollideEventArg(dictionary));

#if USE_ACTIVE_CONTACT_SET
            ActiveList.Clear();
#endif
        }