Example #1
0
        protected void Init(b2Fixture fA, int indexA, b2Fixture fB, int indexB)
        {
            Flags = b2ContactFlags.e_enabledFlag;

            FixtureA = fA;
            FixtureB = fB;

            m_indexA = indexA;
            m_indexB = indexB;

            m_manifold.pointCount = 0;

            Prev = null;
            Next = null;

            NodeA.Contact = null;
            NodeA.hasPrev = false;
            NodeA.hasNext = false;
            NodeA.Other   = null;

            NodeB.Contact = null;
            NodeB.hasPrev = false;
            NodeB.hasNext = false;
            NodeB.Other   = null;

            m_toiCount = 0;

            Friction    = b2Math.b2MixFriction(FixtureA.Friction, FixtureB.Friction);
            Restitution = b2Math.b2MixRestitution(FixtureA.Restitution, FixtureB.Restitution);
        }
Example #2
0
        public b2Contact(b2Fixture fA, int indexA, b2Fixture fB, int indexB)
        {
            m_flags = b2ContactFlags.e_enabledFlag;

            m_fixtureA = fA;
            m_fixtureB = fB;

            m_indexA = indexA;
            m_indexB = indexB;

            m_manifold            = b2Manifold.Create();
            m_manifold.pointCount = 0;

            Prev = null;
            Next = null;

            m_NodeA         = new b2ContactEdge();
            m_NodeA.Contact = null;
            m_NodeA.hasPrev = false;
            m_NodeA.hasNext = false;
            m_NodeA.Other   = null;

            m_nodeB         = new b2ContactEdge();
            m_nodeB.Contact = null;
            m_nodeB.hasPrev = false;
            m_nodeB.hasNext = false;
            m_nodeB.Other   = null;

            m_toiCount = 0;

            m_friction    = b2Math.b2MixFriction(m_fixtureA.Friction, m_fixtureB.Friction);
            m_restitution = b2Math.b2MixRestitution(m_fixtureA.Restitution, m_fixtureB.Restitution);
        }
Example #3
0
 public virtual void SetEnabled(bool flag)
 {
     if (flag)
     {
         Flags |= b2ContactFlags.e_enabledFlag;
     }
     else
     {
         Flags &= ~b2ContactFlags.e_enabledFlag;
     }
 }
Example #4
0
 public virtual void FlagForFiltering()
 {
     Flags |= b2ContactFlags.e_filterFlag;
 }
Example #5
0
        // Update the contact manifold and touching status.
        // Note: do not assume the fixture AABBs are overlapping or are valid.
        public virtual void Update(b2ContactListener listener)
        {
            oldManifold.CopyFrom(m_manifold);

            // Re-enable this contact.
            Flags |= b2ContactFlags.e_enabledFlag;

            bool touching    = false;
            bool wasTouching = (Flags & b2ContactFlags.e_touchingFlag) == b2ContactFlags.e_touchingFlag;

            bool sensor = FixtureA.m_isSensor || FixtureB.m_isSensor;

            b2Body      bodyA = FixtureA.Body;
            b2Body      bodyB = FixtureB.Body;
            b2Transform xfA   = bodyA.Transform;
            b2Transform xfB   = bodyB.Transform;

            // Is this contact a sensor?
            if (sensor)
            {
                b2Shape shapeA = FixtureA.Shape;
                b2Shape shapeB = FixtureB.Shape;
                touching = b2Collision.b2TestOverlap(shapeA, m_indexA, shapeB, m_indexB, ref xfA, ref xfB);

                // Sensors don't generate manifolds.
                m_manifold.pointCount = 0;
            }
            else
            {
                Evaluate(m_manifold, ref xfA, ref xfB);
                touching = m_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 < m_manifold.pointCount; ++i)
                {
                    b2ManifoldPoint mp2 = m_manifold.points[i];
                    mp2.normalImpulse  = 0.0f;
                    mp2.tangentImpulse = 0.0f;
                    b2ContactFeature id2 = mp2.id;

                    for (int j = 0; j < oldManifold.pointCount; ++j)
                    {
                        b2ManifoldPoint mp1 = oldManifold.points[j];

                        if (mp1.id.key == id2.key)
                        {
                            mp2.normalImpulse  = mp1.normalImpulse;
                            mp2.tangentImpulse = mp1.tangentImpulse;
                            break;
                        }
                    }
                }

                if (touching != wasTouching)
                {
                    bodyA.SetAwake(true);
                    bodyB.SetAwake(true);
                }
            }

            if (touching)
            {
                Flags |= b2ContactFlags.e_touchingFlag;
            }
            else
            {
                Flags &= ~b2ContactFlags.e_touchingFlag;
            }

            if (wasTouching == false && touching == true && listener != null)
            {
                listener.BeginContact(this);
            }

            if (wasTouching == true && touching == false && listener != null)
            {
                listener.EndContact(this);
            }

            if (sensor == false && touching && listener != null)
            {
                listener.PreSolve(this, oldManifold);
            }
        }
Example #6
0
 public static bool HasFlag(this b2ContactFlags flag, b2ContactFlags testFlag)
 {
     return ((flag & testFlag) == testFlag);
 }
Example #7
0
        // Update the contact manifold and touching status.
        // Note: do not assume the fixture AABBs are overlapping or are valid.
        public virtual void Update(b2ContactListener listener)
        {
            b2Manifold oldManifold = m_manifold;
            oldManifold.points = m_manifold.CopyPoints();

            // Re-enable this contact.
            m_flags |= b2ContactFlags.e_enabledFlag;

            bool touching = false;
            bool wasTouching = (m_flags & b2ContactFlags.e_touchingFlag) == b2ContactFlags.e_touchingFlag;

            bool sensorA = m_fixtureA.IsSensor;
            bool sensorB = m_fixtureB.IsSensor;
            bool sensor = sensorA || sensorB;

            b2Body bodyA = m_fixtureA.Body;
            b2Body bodyB = m_fixtureB.Body;
            b2Transform xfA = bodyA.Transform;
            b2Transform xfB = bodyB.Transform;

            // Is this contact a sensor?
            if (sensor)
            {
                b2Shape shapeA = m_fixtureA.Shape;
                b2Shape shapeB = m_fixtureB.Shape;
                touching = b2Collision.b2TestOverlap(shapeA, m_indexA, shapeB, m_indexB, ref xfA, ref xfB);

                // Sensors don't generate manifolds.
                m_manifold.pointCount = 0;
            }
            else
            {
                Evaluate(ref m_manifold, ref xfA, ref xfB);
                touching = m_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 < m_manifold.pointCount; ++i)
                {
                    b2ManifoldPoint mp2 = m_manifold.points[i];
                    mp2.normalImpulse = 0.0f;
                    mp2.tangentImpulse = 0.0f;
                    b2ContactFeature id2 = mp2.id;

                    for (int j = 0; j < oldManifold.pointCount; ++j)
                    {
                        b2ManifoldPoint mp1 = oldManifold.points[j];

                        if (mp1.id.key == id2.key)
                        {
                            mp2.normalImpulse = mp1.normalImpulse;
                            mp2.tangentImpulse = mp1.tangentImpulse;
                            break;
                        }
                    }
                    m_manifold.points[i] = mp2;
                }

                if (touching != wasTouching)
                {
                    bodyA.SetAwake(true);
                    bodyB.SetAwake(true);
                }
            }

            if (touching)
            {
                m_flags |= b2ContactFlags.e_touchingFlag;
            }
            else
            {
                m_flags &= ~b2ContactFlags.e_touchingFlag;
            }

            if (wasTouching == false && touching == true && listener != null)
            {
                listener.BeginContact(this);
            }

            if (wasTouching == true && touching == false && listener != null)
            {
                listener.EndContact(this);
            }

            if (sensor == false && touching && listener != null)
            {
                listener.PreSolve(this, ref oldManifold);
            }
        }
Example #8
0
 public virtual void SetEnabled(bool flag)
 {
     if (flag)
     {
         m_flags |= b2ContactFlags.e_enabledFlag;
     }
     else
     {
         m_flags &= ~b2ContactFlags.e_enabledFlag;
     }
 }
Example #9
0
 public virtual void FlagForFiltering()
 {
     m_flags |= b2ContactFlags.e_filterFlag;
 }
Example #10
0
        public b2Contact(b2Fixture fA, int indexA, b2Fixture fB, int indexB)
        {
            m_flags = b2ContactFlags.e_enabledFlag;

            m_fixtureA = fA;
            m_fixtureB = fB;

            m_indexA = indexA;
            m_indexB = indexB;

            m_manifold = b2Manifold.Create();
            m_manifold.pointCount = 0;

            Prev = null;
            Next = null;

            m_NodeA = new b2ContactEdge();
            m_NodeA.Contact = null;
            m_NodeA.hasPrev = false;
            m_NodeA.hasNext = false;
            m_NodeA.Other = null;

            m_nodeB = new b2ContactEdge();
            m_nodeB.Contact = null;
            m_nodeB.hasPrev = false;
            m_nodeB.hasNext = false;
            m_nodeB.Other = null;

            m_toiCount = 0;

            m_friction = b2Math.b2MixFriction(m_fixtureA.Friction, m_fixtureB.Friction);
            m_restitution = b2Math.b2MixRestitution(m_fixtureA.Restitution, m_fixtureB.Restitution);
        }
Example #11
0
 public static bool HasFlag(this b2ContactFlags flag, b2ContactFlags testFlag)
 {
     return((flag & testFlag) == testFlag);
 }