Пример #1
0
        public void BeginContact(Contact contact)
        {
            GameObject A = (GameObject)contact.GetFixtureA().GetUserData();
            GameObject B = (GameObject)contact.GetFixtureB().GetUserData();

            Manifold manifold;
            Transform xfA;
            Transform xfB;
            float radiusA;
            float radiusB;

            contact.GetFixtureA().GetBody().GetTransform(out xfA);
            contact.GetFixtureB().GetBody().GetTransform(out xfB);
            radiusA = contact.GetFixtureA().GetShape()._radius;
            radiusB = contact.GetFixtureB().GetShape()._radius;

            contact.GetManifold(out manifold);

            WorldManifold worldManifold = new WorldManifold(ref manifold,ref xfA,radiusA,ref xfB,radiusB);

            Vector2 ptA = worldManifold._points[0];
            Vector2 ptB = worldManifold._points[1];

            //System.Console.Write(" point {0} {1}\n", ptA, ptB);

            ColHdr cHdr;
            cHdr.goID1 = A.getIndexNum();
            cHdr.goID2 = B.getIndexNum();
            cHdr.pos = ptA;

            InputHdr iHdr;
            iHdr.colInfo = cHdr;
            iHdr.input = InputType.Collision;
            iHdr.player = PlayerID.none;
            iHdr.networked = false;

            OutputQueue.pushHeader(iHdr);

            //if (A.CollideAvailable == true && B.CollideAvailable == true)
            //{
            //    if (A.type < B.type)
            //    {
            //        A.Accept(B, ptA);
            //    }
            //    else
            //    {
            //        B.Accept(A, ptA);
            //    }
            //}

            //if (A.type == GameObjType.p1missiles || A.type == GameObjType.p2missiles)
            //{
            //    A.CollideAvailable = false;
            //}

            //if (B.type == GameObjType.p1missiles || B.type == GameObjType.p2missiles)
            //{
            //    B.CollideAvailable = false;
            //}
        }
Пример #2
0
        /// <summary>
        /// Set the contact filtering data. This will not update contacts until the next time
        /// step when either parent body is active and awake.
        /// </summary>
        /// <param name="filter"></param>
        public void SetFilterData(ref Filter filter)
        {
            _filter = filter;

            if (_body == null)
            {
                return;
            }

            // Flag associated contacts for filtering.
            ContactEdge edge = _body.GetContactList();

            while (edge != null)
            {
                Contact contact  = edge.Contact;
                Fixture fixtureA = contact.GetFixtureA();
                Fixture fixtureB = contact.GetFixtureB();
                if (fixtureA == this || fixtureB == this)
                {
                    contact.FlagForFiltering();
                }

                edge = edge.Next;
            }
        }
Пример #3
0
 public void PostSolve(Contact contact, ref ContactImpulse impulse)
 {
     Body[] bodies = new Body[2];
     bodies[0] = contact.GetFixtureA().GetBody();
     bodies[1] = contact.GetFixtureB().GetBody();
     mBodies.Add(bodies);
     if (mBodies.Count > 10000)
     {
         mBodies.Clear();
         Console.WriteLine("Clear contacts.");
     }
 }
        public void BeginContact(Contact contact)
        {
            Fixture fixtureA = contact.GetFixtureA();
            Fixture fixtureB = contact.GetFixtureB();
            var unitA = (Unit) fixtureA.GetBody().GetUserData();
            var unitB = (Unit) fixtureB.GetBody().GetUserData();

            bool shouldContact = GroupManager.Instance.ShouldContact(unitA.Group, unitB.Group);
            if (shouldContact)
            {
                if (fixtureA.IsSensor())
                {
                    var sensorData = (SensorInfo) fixtureA.GetUserData();
                    if (sensorData.Enable && !fixtureB.IsSensor())
                    {
                        if (unitB is Character && sensorData.SensorName == Constants.SURFACE_SENSOR)
                        {

                        }
                        sensorData.Add(unitB);
                    }
                }
                if (fixtureB.IsSensor())
                {
                    var sensorData = (SensorInfo) fixtureB.GetUserData();
                    if (sensorData.Enable && !fixtureA.IsSensor())
                    {
                        sensorData.Add(unitA);
                    }
                }
            }
            else
            {
                if (fixtureA.IsSensor())
                {
                    var sensorData = (SensorInfo)fixtureA.GetUserData();
                    if (sensorData.SensorName == Constants.VISUAL_SENSOR && sensorData.Enable && !fixtureB.IsSensor() && unitB is Character)
                    {
                        sensorData.Add(unitB);
                    }
                }
                if (fixtureB.IsSensor())
                {
                    var sensorData = (SensorInfo)fixtureB.GetUserData();
                    if (sensorData.SensorName == Constants.VISUAL_SENSOR && sensorData.Enable && !fixtureA.IsSensor() && unitA is Character)
                    {
                        sensorData.Add(unitA);
                    }
                }
            }
        }
Пример #5
0
        public void Initialize(Contact[] contacts, int count, Body toiBody)
        {
            _count   = count;
            _toiBody = toiBody;
            if (_constraints.Length < _count)
            {
                _constraints = new TOIConstraint[Math.Max(_constraints.Length * 2, _count)];
            }

            for (int i = 0; i < _count; ++i)
            {
                Contact contact = contacts[i];

                Fixture  fixtureA = contact.GetFixtureA();
                Fixture  fixtureB = contact.GetFixtureB();
                Shape    shapeA   = fixtureA.GetShape();
                Shape    shapeB   = fixtureB.GetShape();
                float    radiusA  = shapeA._radius;
                float    radiusB  = shapeB._radius;
                Body     bodyA    = fixtureA.GetBody();
                Body     bodyB    = fixtureB.GetBody();
                Manifold manifold;
                contact.GetManifold(out manifold);

                Debug.Assert(manifold._pointCount > 0);

                TOIConstraint constraint = _constraints[i];
                constraint.bodyA       = bodyA;
                constraint.bodyB       = bodyB;
                constraint.localNormal = manifold._localNormal;
                constraint.localPoint  = manifold._localPoint;
                constraint.type        = manifold._type;
                constraint.pointCount  = manifold._pointCount;
                constraint.radius      = radiusA + radiusB;

                for (int j = 0; j < constraint.pointCount; ++j)
                {
                    constraint.localPoints[j] = manifold._points[j].LocalPoint;
                }

                _constraints[i] = constraint;
            }
        }
Пример #6
0
        public void BeginContact(Contact contact)
        {
            object obj1 = contact.GetFixtureA().GetBody().GetUserData();
            object obj2 = contact.GetFixtureB().GetBody().GetUserData();

            if (obj1 == TYPE_WATER || obj2 == TYPE_WATER)
            {

                if (obj1 is Sprite)
                {
                    ((Sprite)obj1).Drown = true;
                }
                else if (obj2 is Sprite)
                {
                    ((Sprite)obj2).Drown = true;
                }

            }
        }
 public void EndContact(Contact contact)
 {
     Fixture fixtureA = contact.GetFixtureA();
     Fixture fixtureB = contact.GetFixtureB();
     if (fixtureA.IsSensor())
     {
         var sensorData = (SensorInfo) fixtureA.GetUserData();
         var unitB = (Unit) fixtureB.GetBody().GetUserData();
         if (sensorData.Enable)
         {
             sensorData.Remove(unitB);
         }
     }
     if (fixtureB.IsSensor())
     {
         var sensorData = (SensorInfo) fixtureB.GetUserData();
         var unitA = (Unit) fixtureA.GetBody().GetUserData();
         if (sensorData.Enable)
         {
             sensorData.Remove(unitA);
         }
     }
 }
Пример #8
0
        /// Destroy a fixture. This removes the fixture from the broad-phase and
        /// destroys all contacts associated with this fixture. This will
        /// automatically adjust the mass of the body if the body is dynamic and the
        /// fixture has positive density.
        /// All fixtures attached to a body are implicitly destroyed when the body is destroyed.
        /// @param fixture the fixture to be removed.
        /// @warning This function is locked during callbacks.
        public void DestroyFixture(Fixture fixture)
        {
            Debug.Assert(_world.IsLocked == false);
            if (_world.IsLocked == true)
            {
                return;
            }

            Debug.Assert(fixture._body == this);

            // Remove the fixture from this body's singly linked list.
            Debug.Assert(_fixtureCount > 0);
            Fixture node  = _fixtureList;
            bool    found = false;

            while (node != null)
            {
                if (node == fixture)
                {
                    _fixtureList = fixture._next;
                    found        = true;
                    break;
                }

                node = node._next;
            }

            // You tried to remove a shape that is not attached to this body.
            Debug.Assert(found);

            // Destroy any contacts associated with the fixture.
            ContactEdge edge = _contactList;

            while (edge != null)
            {
                Contact c = edge.Contact;
                edge = edge.Next;

                Fixture fixtureA = c.GetFixtureA();
                Fixture fixtureB = c.GetFixtureB();

                if (fixture == fixtureA || fixture == fixtureB)
                {
                    // This destroys the contact and removes it from
                    // this body's contact list.
                    _world._contactManager.Destroy(c);
                }
            }

            if ((_flags & BodyFlags.Active) == BodyFlags.Active)
            {
                Debug.Assert(fixture._proxyId != BroadPhase.NullProxy);

                BroadPhase broadPhase = _world._contactManager._broadPhase;
                fixture.DestroyProxies(broadPhase);
            }

            fixture.Destroy();
            fixture._body = null;
            fixture._next = null;

            --_fixtureCount;


            ResetMassData();
        }
Пример #9
0
        public override void BeginContact(Contact contact)
        {
            collisionObjA = (V2DSprite)contact.GetFixtureA().GetBody().GetUserData();
            collisionObjB = (V2DSprite)contact.GetFixtureB().GetBody().GetUserData();

            SmuckPlayer p = null;
            V2DSprite nonPlayerObj = null;
            if(collisionObjA is SmuckPlayer)
            {
                p = (SmuckPlayer)collisionObjA;
                nonPlayerObj = collisionObjB;
            }
            else if(collisionObjB is SmuckPlayer)
            {
                p = (SmuckPlayer)collisionObjB;
                nonPlayerObj = collisionObjA;
            }

            if (p != null)
            {
                LaneVehicle v = nonPlayerObj is LaneVehicle ? (LaneVehicle)nonPlayerObj : null;
                if (v != null)
                {
                    if (v.Lane.LaneKind == LaneKind.DrownWater && !collideWithBoats)
                    {
                        if (p.LivingState == LivingState.Alive)
                        {
                            p.aboardVehicle = v;
                        }
                        else
                        {
                            p.DestroyAfterUpdate(); // dont want drowning amin over boats
                        }
                    }
                    else
                    {
                        Manifold m;
                        contact.GetManifold(out m);
                        Vector2 dir = m._localNormal * (p == collisionObjA ? 20 : -20) + v.body.GetLinearVelocity() * 10;
                        if (Math.Abs(dir.Y) < 60)
                        {
                            dir.Y += rnd.Next(-400, 400);
                        }
                        p.isExploding = false;
                        p.body.ApplyLinearImpulse(dir, p.body.GetPosition());
                        float torque = dir.Y > 0 ? 1 : -1;
                        p.body.ApplyTorque(torque);
                        p.body.SetAngularVelocity(rnd.Next(15) * torque);

                        if (p.LivingState == LivingState.Alive) // first hit a whack
                        {
                            stage.audio.PlaySound(Sfx.whack);
                        }
                        stage.audio.PlaySound(Sfx.secondWhack);

                        this.KillPlayer(p);
                    }
                }
                else
                {
                    if (nonPlayerObj.InstanceName.StartsWith("water"))
                    {
                        p.IsOnWater = true;
                        if (p.aboardVehicle == null)
                        {
                            p.Lane = lanes[GetLaneFromY((int)nonPlayerObj.Y)];
                            p.LivingState = LivingState.Dying;
                            stage.audio.PlaySound(Sfx.bigSplash);
                        }
                    }
                    else if (p.LivingState == LivingState.Dying && nonPlayerObj.InstanceName.StartsWith("border"))
                    {
                        // no death icon when flying off left or right side of highway
                        if (nonPlayerObj.Index == 0 || nonPlayerObj.Index == 2)
                        {
                            p.skipDeathMarker = true;
                        }
                        p.DestroyAfterUpdate();
                    }
                }
            }
            else if (collisionObjA is LaneVehicle && collisionObjB is LaneVehicle)
            {
                LaneVehicle vA = (LaneVehicle)collisionObjA;
                LaneVehicle vB = (LaneVehicle)collisionObjB;
                const float boost = 15;
                if (vA.Lane.movesRight && vB.Lane.movesRight)
                {
                    if (vA.Position.X > vB.Position.X)
                    {
                        vA.MaxSpeed = vA.Lane.vehicleSpeed + boost;
                        vB.MaxSpeed = vA.MaxSpeed - boost;
                    }
                    else
                    {
                        vB.MaxSpeed = vB.Lane.vehicleSpeed + boost;
                        vA.MaxSpeed = vB.MaxSpeed - boost;
                    }
                }
                else if (!vA.Lane.movesRight && !vB.Lane.movesRight)
                {
                    if (vA.Position.X > vB.Position.X)
                    {
                        vB.MaxSpeed = vB.Lane.vehicleSpeed + boost;
                        vA.MaxSpeed = vB.MaxSpeed - boost;
                    }
                    else
                    {
                        vA.MaxSpeed = vA.Lane.vehicleSpeed + boost;
                        vB.MaxSpeed = vA.MaxSpeed - boost;
                    }
                }
            }
        }
Пример #10
0
        /// <summary>
        /// A callback function for Box2D to inform that two shapes are beginning to contact with 
        /// each other. Collects the information of the contacts and that information will be 
        /// handled after the physics simulation iterations are completed.
        /// </summary>
        /// <param name="contact">Box2D Contact</param>
        public virtual void BeginContact(Contact contact)
        {
            if (!bike.OffTheBike)
            {
                UserData data = (UserData)contact.GetFixtureA().GetBody().GetUserData();
                if (data != null)
                {
                    if (data.Name == "finish")
                    {
                        if (Win != null)
                            Win(this);
                    }
                    else if (data.Name == "nail")
                    {
                        if (TireFail != null)
                            TireFail(this);
                    }
                    else if ( (data.Name == "head" && contact.GetFixtureB().GetBody().GetType() == BodyType.Static) ||
                              (data.Name == null && ((UserData)contact.GetFixtureB().GetBody().GetUserData()).Name == "head") )
                    {
                        bikeShouldBeReleased = true;

                        if (HeadFail != null)
                            HeadFail(this);
                    }
                }
            }
        }
Пример #11
0
        //public override void BeginContact(Contact contact)
        //{
        //    base.BeginContact(contact);
        //    object objA = contact.GetFixtureA().GetBody().GetUserData();
        //    object objB = contact.GetFixtureB().GetBody().GetUserData();
        //    foreach (Type t in contactTypes.Keys)
        //    {
        //        if (objA.GetType() == t)
        //        {
        //            contactTypes[t](objA, objB);
        //            break;
        //        }
        //        else if (objB.GetType() == t)
        //        {
        //            contactTypes[t](objB, objA);
        //            break;
        //        }
        //    }
        //}
        public override void EndContact(Contact contact)
        {
            base.EndContact(contact);
            object objA = contact.GetFixtureA().GetBody().GetUserData();
            object objB = contact.GetFixtureB().GetBody().GetUserData();

            if (objA is Walker || objB is Walker)
            {
                walker.EndContact();
            }
        }
Пример #12
0
        protected virtual void OnShake(Contact contact, float intensity)
        {
            if (!(contact.GetFixtureA().GetBody().GetUserData() is Walker) && !(contact.GetFixtureB().GetBody().GetUserData() is Walker))
            {
                if (stage != null)
                {
                    if (intensity < .5f)
                    {
                        Cue c = stage.audio.PlaySound(Sfx.woodHit);
                        c.SetVariable("Volume", 1);
                    }
                    else
                    {
                        float vol = intensity / 4 + .75f;
                        vol = vol > 1 ? 1f : vol < 0.75f ? 0.75f : vol;

                        Cue c = stage.audio.PlaySound(Sfx.smash);
                        c.SetVariable("Volume", vol);
                    }
                }
            }
        }
Пример #13
0
        public override void EndContact(Contact contact)
        {
            V2DSprite objA = (V2DSprite)contact.GetFixtureA().GetBody().GetUserData();
            V2DSprite objB = (V2DSprite)contact.GetFixtureB().GetBody().GetUserData();

            SmuckPlayer p = objA is SmuckPlayer ? (SmuckPlayer)objA : objB is SmuckPlayer ? (SmuckPlayer)objB : null;
            LaneVehicle v = objA is LaneVehicle ? (LaneVehicle)objA : objB is LaneVehicle ? (LaneVehicle)objB : null;
            V2DSprite w = objA.InstanceName.StartsWith("water") ? objA : objB.InstanceName.StartsWith("water") ? objB : null;

            if (p != null)
            {
                if (w != null)
                {
                    p.IsOnWater = false;
                }
                else if (v != null)
                {
                    if (v.Lane.LaneKind == LaneKind.DrownWater)
                    {
                        p.aboardVehicle = null;
                        if (p.IsOnWater)
                        {
                            p.LivingState = LivingState.Dying;
                            stage.audio.PlaySound(Sfx.bigSplash);
                        }
                    }
                    else
                    {
                        this.KillPlayer(p);
                    }
                }
            }
        }
Пример #14
0
        /// Call this to draw shapes and other debug draw data.
        public void DrawDebugData()
        {
            if (DebugDraw == null)
            {
                return;
            }

            DebugDrawFlags flags = DebugDraw.Flags;

            if ((flags & DebugDrawFlags.Shape) == DebugDrawFlags.Shape)
            {
                for (Body b = _bodyList; b != null; b = b.GetNext())
                {
                    Transform xf;
                    b.GetTransform(out xf);
                    for (Fixture f = b.GetFixtureList(); f != null; f = f.GetNext())
                    {
                        if (b.IsActive() == false)
                        {
                            DrawShape(f, xf, new Color(0.5f, 0.5f, 0.3f));
                        }
                        else if (b.GetType() == BodyType.Static)
                        {
                            DrawShape(f, xf, new Color(0.5f, 0.9f, 0.5f));
                        }
                        else if (b.GetType() == BodyType.Kinematic)
                        {
                            DrawShape(f, xf, new Color(0.5f, 0.5f, 0.9f));
                        }
                        else if (b.IsAwake() == false)
                        {
                            DrawShape(f, xf, new Color(0.6f, 0.6f, 0.6f));
                        }
                        else
                        {
                            DrawShape(f, xf, new Color(0.9f, 0.7f, 0.7f));
                        }
                    }
                }
            }

            if ((flags & DebugDrawFlags.Joint) == DebugDrawFlags.Joint)
            {
                for (Joint j = _jointList; j != null; j = j.GetNext())
                {
                    DrawJoint(j);
                }
            }

            if ((flags & DebugDrawFlags.Pair) == DebugDrawFlags.Pair)
            {
                Color color = new Color(0.3f, 0.9f, 0.9f);
                for (Contact c = _contactManager._contactList; c != null; c = c.GetNext())
                {
                    Fixture fixtureA = c.GetFixtureA();
                    Fixture fixtureB = c.GetFixtureB();

                    AABB aabbA;
                    AABB aabbB;
                    fixtureA.GetAABB(out aabbA);
                    fixtureB.GetAABB(out aabbB);

                    Vector2 cA = aabbA.GetCenter();
                    Vector2 cB = aabbB.GetCenter();

                    DebugDraw.DrawSegment(cA, cB, color);
                }
            }

            if ((flags & DebugDrawFlags.AABB) == DebugDrawFlags.AABB)
            {
                Color      color = new Color(0.9f, 0.3f, 0.9f);
                BroadPhase bp    = _contactManager._broadPhase;

                for (Body b = _bodyList; b != null; b = b.GetNext())
                {
                    if (b.IsActive() == false)
                    {
                        continue;
                    }

                    for (Fixture f = b.GetFixtureList(); f != null; f = f.GetNext())
                    {
                        AABB aabb;
                        bp.GetFatAABB(f._proxyId, out aabb);
                        FixedArray8 <Vector2> vs = new FixedArray8 <Vector2>();
                        vs[0] = new Vector2(aabb.lowerBound.X, aabb.lowerBound.Y);
                        vs[1] = new Vector2(aabb.upperBound.X, aabb.lowerBound.Y);
                        vs[2] = new Vector2(aabb.upperBound.X, aabb.upperBound.Y);
                        vs[3] = new Vector2(aabb.lowerBound.X, aabb.upperBound.Y);

                        DebugDraw.DrawPolygon(ref vs, 4, color);
                    }
                }
            }

            if ((flags & DebugDrawFlags.CenterOfMass) == DebugDrawFlags.CenterOfMass)
            {
                for (Body b = _bodyList; b != null; b = b.GetNext())
                {
                    Transform xf;
                    b.GetTransform(out xf);
                    xf.Position = b.GetWorldCenter();
                    DebugDraw.DrawTransform(ref xf);
                }
            }
        }
Пример #15
0
 public void PreSolve(Contact contact, ref Manifold oldManifold)
 {
     var unitA = (Unit) contact.GetFixtureA().GetBody().GetUserData();
     var unitB = (Unit) contact.GetFixtureB().GetBody().GetUserData();
     if (!(unitA.EnableCollision && unitB.EnableCollision
           && GroupManager.Instance.ShouldContact(unitA.Group, unitB.Group)))
     {
         contact.SetEnabled(false);
     }
 }
        internal void Destroy(Contact c)
        {
            Fixture fixtureA = c.GetFixtureA();
            Fixture fixtureB = c.GetFixtureB();
            Body bodyA = fixtureA.GetBody();
            Body bodyB = fixtureB.GetBody();

            if (c.IsTouching())
            {
                ContactListener.EndContact(c);
            }

            // Remove from the world.
            if (c._prev != null)
            {
                c._prev._next = c._next;
            }

            if (c._next != null)
            {
                c._next._prev = c._prev;
            }

            if (c == _contactList)
            {
                _contactList = c._next;
            }

            // Remove from body 1
            if (c._nodeA.Prev != null)
            {
                c._nodeA.Prev.Next = c._nodeA.Next;
            }

            if (c._nodeA.Next != null)
            {
                c._nodeA.Next.Prev = c._nodeA.Prev;
            }

            if (c._nodeA == bodyA._contactList)
            {
                bodyA._contactList = c._nodeA.Next;
            }

            // Remove from body 2
            if (c._nodeB.Prev != null)
            {
                c._nodeB.Prev.Next = c._nodeB.Next;
            }

            if (c._nodeB.Next != null)
            {
                c._nodeB.Next.Prev = c._nodeB.Prev;
            }

            if (c._nodeB == bodyB._contactList)
            {
                bodyB._contactList = c._nodeB.Next;
            }

            c.Destroy();

            --_contactCount;
        }
Пример #17
0
        public virtual void EndContact(Contact contact)
        {
            object objA = contact.GetFixtureA().GetBody().GetUserData();
            object objB = contact.GetFixtureB().GetBody().GetUserData();

            foreach (Type t in contactEndTypes.Keys)
            {
                if (objA.GetType() == t)
                {
                    contactEndTypes[t](objA, objB, contact.GetFixtureA(), contact.GetFixtureB());
                    break;
                }
                else if (objB.GetType() == t)
                {
                    contactEndTypes[t](objB, objA, contact.GetFixtureB(), contact.GetFixtureA());
                    break;
                }
            }
        }
Пример #18
0
        protected void PreSolveCalcPoints(Contact contact, ref Manifold oldManifold)
        {
            Manifold manifold;
            contact.GetManifold(out manifold);

            if (manifold._pointCount == 0)
            {
                return;
            }

            Fixture fixtureA = contact.GetFixtureA();
            Fixture fixtureB = contact.GetFixtureB();

            FixedArray2<PointState> state1, state2;
            Collision.GetPointStates(out state1, out state2, ref oldManifold, ref manifold);

            WorldManifold worldManifold;
            contact.GetWorldManifold(out worldManifold);

            for (int i = 0; i < manifold._pointCount && _pointCount < k_maxContactPoints; ++i)
            {
                if (fixtureA == null)
                {
                    _points[i] = new ContactPoint();
                }
                ContactPoint cp = _points[_pointCount];
                cp.fixtureA = fixtureA;
                cp.fixtureB = fixtureB;
                cp.position = worldManifold._points[i];
                cp.normal = worldManifold._normal;
                cp.state = state2[i];
                _points[_pointCount] = cp;
                ++_pointCount;
            }
        }
        public override void EndContact(Contact contact)
        {
            base.EndContact(contact);
            object objA = contact.GetFixtureA().GetBody().GetUserData();
            object objB = contact.GetFixtureB().GetBody().GetUserData();

            if (objA is PlayerFeet && objB is V2DSprite)
            {
                ((PlayerFeet)objA).EndContact((V2DSprite)objB);
            }

            if (objB is PlayerFeet && objA is V2DSprite)
            {
                ((PlayerFeet)objB).EndContact((V2DSprite)objA);
            }
        }
Пример #20
0
        public void EndContact(Contact contact)
        {
            while (contact != null)
            {
                var lhsInfo = new ContactInfo();
                var rhsInfo = new ContactInfo();

                lhsInfo.contact = contact;
                rhsInfo.contact = contact;

                lhsInfo.fixtureType = FixtureType.A;
                rhsInfo.fixtureType = FixtureType.B;

                var lhsGo = contact.GetFixtureA().GetBody().GetUserData() as GameObject;
                var rhsGo = contact.GetFixtureB().GetBody().GetUserData() as GameObject;

                lhsInfo.other = rhsGo;
                rhsInfo.other = lhsGo;

                if (lhsGo != null) { lhsGo.EndContact(lhsInfo); }
                if (rhsGo != null) { rhsGo.EndContact(rhsInfo); }

                contact = contact.GetNext();
            }
        }
Пример #21
0
        // Broad-phase callback.
        internal void AddPair(FixtureProxy proxyA, FixtureProxy proxyB)
        {
            Fixture fixtureA = proxyA.fixture;
            Fixture fixtureB = proxyB.fixture;

            int indexA = proxyA.childIndex;
            int indexB = proxyB.childIndex;

            Body bodyA = fixtureA.GetBody();
            Body bodyB = fixtureB.GetBody();

            // Are the fixtures on the same body?
            if (bodyA == bodyB)
            {
                return;
            }

            // Does a contact already exist?
            ContactEdge edge = bodyB.GetContactList();

            while (edge != null)
            {
                if (edge.Other == bodyA)
                {
                    Fixture fA = edge.Contact.GetFixtureA();
                    Fixture fB = edge.Contact.GetFixtureB();
                    int     iA = edge.Contact.GetChildIndexA();
                    int     iB = edge.Contact.GetChildIndexB();

                    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 user filtering.
            if (ContactFilter != null && ContactFilter.ShouldCollide(fixtureA, fixtureB) == false)
            {
                return;
            }

            // Call the factory.
            Contact c = Contact.Create(fixtureA, indexA, fixtureB, indexB);

            // Contact creation may swap fixtures.
            fixtureA = c.GetFixtureA();
            fixtureB = c.GetFixtureB();
            indexA   = c.GetChildIndexA();
            indexB   = c.GetChildIndexB();
            bodyA    = fixtureA.GetBody();
            bodyB    = fixtureB.GetBody();

            // Insert into the world.
            c._prev = null;
            c._next = _contactList;
            if (_contactList != null)
            {
                _contactList._prev = c;
            }
            _contactList = c;

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

            ++_contactCount;
        }
Пример #22
0
        internal void Collide()
        {
            // Update awake contacts.
            Contact c = _contactList;

            while (c != null)
            {
                Fixture fixtureA = c.GetFixtureA();
                Fixture fixtureB = c.GetFixtureB();
                int     indexA   = c.GetChildIndexA();
                int     indexB   = c.GetChildIndexB();
                Body    bodyA    = fixtureA.GetBody();
                Body    bodyB    = fixtureB.GetBody();

                if (bodyA.IsAwake() == false && bodyB.IsAwake() == false)
                {
                    c = c.GetNext();
                    continue;
                }

                // Is this contact flagged for filtering?
                if ((c._flags & ContactFlags.Filter) == ContactFlags.Filter)
                {
                    // Should these bodies collide?
                    if (bodyB.ShouldCollide(bodyA) == false)
                    {
                        Contact cNuke = c;
                        c = cNuke.GetNext();
                        Destroy(cNuke);
                        continue;
                    }

                    // Check user filtering.
                    if (ContactFilter != null && ContactFilter.ShouldCollide(fixtureA, fixtureB) == false)
                    {
                        Contact cNuke = c;
                        c = cNuke.GetNext();
                        Destroy(cNuke);
                        continue;
                    }

                    // Clear the filtering flag.
                    c._flags &= ~ContactFlags.Filter;
                }

                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;
                    c = cNuke.GetNext();
                    Destroy(cNuke);
                    continue;
                }

                // The contact persists.
                c.Update(ContactListener);
                c = c.GetNext();
            }
        }
Пример #23
0
        internal void Destroy(Contact c)
        {
            Fixture fixtureA = c.GetFixtureA();
            Fixture fixtureB = c.GetFixtureB();
            Body    bodyA    = fixtureA.GetBody();
            Body    bodyB    = fixtureB.GetBody();

            if (ContactListener != null && c.IsTouching())
            {
                ContactListener.EndContact(c);
            }

            // Remove from the world.
            if (c._prev != null)
            {
                c._prev._next = c._next;
            }

            if (c._next != null)
            {
                c._next._prev = c._prev;
            }

            if (c == _contactList)
            {
                _contactList = c._next;
            }

            // Remove from body 1
            if (c._nodeA.Prev != null)
            {
                c._nodeA.Prev.Next = c._nodeA.Next;
            }

            if (c._nodeA.Next != null)
            {
                c._nodeA.Next.Prev = c._nodeA.Prev;
            }

            if (c._nodeA == bodyA._contactList)
            {
                bodyA._contactList = c._nodeA.Next;
            }

            // Remove from body 2
            if (c._nodeB.Prev != null)
            {
                c._nodeB.Prev.Next = c._nodeB.Next;
            }

            if (c._nodeB.Next != null)
            {
                c._nodeB.Next.Prev = c._nodeB.Prev;
            }

            if (c._nodeB == bodyB._contactList)
            {
                bodyB._contactList = c._nodeB.Next;
            }

            c.Destroy();

            --_contactCount;
        }