Exemple #1
0
        private FP RayCastCallbackWrapper(RayCastInput rayCastInput, int proxyId)
        {
            FixtureProxy  proxy      = this.ContactManager.BroadPhase.GetProxy(proxyId);
            Fixture       fixture    = proxy.Fixture;
            int           childIndex = proxy.ChildIndex;
            RayCastOutput rayCastOutput;
            bool          flag  = fixture.RayCast(out rayCastOutput, ref rayCastInput, childIndex);
            bool          flag2 = flag;
            FP            result;

            if (flag2)
            {
                FP        fraction = rayCastOutput.Fraction;
                TSVector2 arg      = (1f - fraction) * rayCastInput.Point1 + fraction * rayCastInput.Point2;
                result = this._rayCastCallback(fixture, arg, rayCastOutput.Normal, fraction);
            }
            else
            {
                result = rayCastInput.MaxFraction;
            }
            return(result);
        }
Exemple #2
0
        internal void Synchronize(IBroadPhase broadPhase, ref Transform transform1, ref Transform transform2)
        {
            if (ProxyCount == 0)
            {
                return;
            }

            for (int i = 0; i < ProxyCount; ++i)
            {
                FixtureProxy proxy = Proxies[i];

                // Compute an AABB that covers the swept Shape (may miss some rotation effect).
                AABB aabb1, aabb2;
                Shape.ComputeAABB(out aabb1, ref transform1, proxy.ChildIndex);
                Shape.ComputeAABB(out aabb2, ref transform2, proxy.ChildIndex);

                proxy.AABB.Combine(ref aabb1, ref aabb2);

                TSVector2 displacement = transform2.p - transform1.p;

                broadPhase.MoveProxy(proxy.ProxyId, ref proxy.AABB, displacement);
            }
        }
Exemple #3
0
        // 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;
            }
        }
Exemple #4
0
        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;
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
Exemple #5
0
        private bool QueryAABBCallbackWrapper(int proxyId)
        {
            FixtureProxy proxy = this.ContactManager.BroadPhase.GetProxy(proxyId);

            return(this._queryAABBCallback(proxy.Fixture));
        }