예제 #1
0
 public ContactManager(World argPool, BroadPhase broadPhase)
 {
     m_contactList = null;
     m_contactCount = 0;
     m_contactFilter = new ContactFilter();
     m_contactListener = null;
     m_broadPhase = broadPhase;
     pool = argPool;
 }
예제 #2
0
        // Implement contact listener.
        public override void beginContact(Contact contact)
        {
            Fixture fixtureA = contact.getFixtureA();
            Fixture fixtureB = contact.getFixtureB();

            if (fixtureA == m_sensor)
            {
                Object userData = fixtureB.getBody().getUserData();
                if (userData != null)
                {
                    ((BoolWrapper) userData).tf = true;
                }
            }

            if (fixtureB == m_sensor)
            {
                Object userData = fixtureA.getBody().getUserData();
                if (userData != null)
                {
                    ((BoolWrapper) userData).tf = true;
                }
            }
        }
예제 #3
0
        public override void postSolve(Contact contact, ContactImpulse impulse)
        {
            if (m_broke)
            {
                // The body already broke.
                return;
            }

            // Should the body break?
            int count = contact.getManifold().pointCount;

            float maxImpulse = 0.0f;
            for (int i = 0; i < count; ++i)
            {
                maxImpulse = MathUtils.max(maxImpulse, impulse.normalImpulses[i]);
            }

            if (maxImpulse > 40.0f)
            {
                // Flag the body for breaking.
                m_break = true;
            }
        }
예제 #4
0
        public override void preSolve(Contact contact, Manifold oldManifold)
        {
            base.preSolve(contact, oldManifold);

            Fixture fixtureA = contact.getFixtureA();
            Fixture fixtureB = contact.getFixtureB();

            if (fixtureA == m_platform || fixtureB == m_platform)
            {
                contact.setTangentSpeed(5.0f);
            }
        }
예제 #5
0
파일: Island.cs 프로젝트: Nomad1/sharpbox2d
 public void add(Contact contact)
 {
     Debug.Assert(m_contactCount < m_contactCapacity);
     m_contacts[m_contactCount++] = contact;
 }
예제 #6
0
        /**
           * Broad-phase callback.
           *
           * @param proxyUserDataA
           * @param proxyUserDataB
           */
        public void addPair(object proxyUserDataA, object proxyUserDataB)
        {
            FixtureProxy proxyA = (FixtureProxy) proxyUserDataA;
            FixtureProxy proxyB = (FixtureProxy) proxyUserDataB;

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

            // TODO_ERIN use a hash table to remove a potential bottleneck when both
            // bodies have a lot of contacts.
            // 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 && iA == indexA && fB == fixtureB && iB == indexB)
                    {
                        // A contact already exists.
                        return;
                    }

                    if (fA == fixtureB && iA == indexB && fB == fixtureA && 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 (m_contactFilter != null && m_contactFilter.shouldCollide(fixtureA, fixtureB) == false)
            {
                return;
            }

            // Call the factory.
            Contact c = pool.popContact(fixtureA, indexA, fixtureB, indexB);
            if (c == null)
            {
                return;
            }

            // 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.m_prev = null;
            c.m_next = m_contactList;
            if (m_contactList != null)
            {
                m_contactList.m_prev = c;
            }
            m_contactList = c;

            // Connect to island graph.

            // Connect to body A
            c.m_nodeA.contact = c;
            c.m_nodeA.other = bodyB;

            c.m_nodeA.prev = null;
            c.m_nodeA.next = bodyA.m_contactList;
            if (bodyA.m_contactList != null)
            {
                bodyA.m_contactList.prev = c.m_nodeA;
            }
            bodyA.m_contactList = c.m_nodeA;

            // Connect to body B
            c.m_nodeB.contact = c;
            c.m_nodeB.other = bodyA;

            c.m_nodeB.prev = null;
            c.m_nodeB.next = bodyB.m_contactList;
            if (bodyB.m_contactList != null)
            {
                bodyB.m_contactList.prev = c.m_nodeB;
            }
            bodyB.m_contactList = c.m_nodeB;

            // wake up the bodies
            if (!fixtureA.isSensor() && !fixtureB.isSensor())
            {
                bodyA.setAwake(true);
                bodyB.setAwake(true);
            }

            ++m_contactCount;
        }
예제 #7
0
        public void destroy(Contact c)
        {
            Fixture fixtureA = c.getFixtureA();
            Fixture fixtureB = c.getFixtureB();
            Body bodyA = fixtureA.getBody();
            Body bodyB = fixtureB.getBody();

            if (m_contactListener != null && c.isTouching())
            {
                m_contactListener.endContact(c);
            }

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

            if (c.m_next != null)
            {
                c.m_next.m_prev = c.m_prev;
            }

            if (c == m_contactList)
            {
                m_contactList = c.m_next;
            }

            // Remove from body 1
            if (c.m_nodeA.prev != null)
            {
                c.m_nodeA.prev.next = c.m_nodeA.next;
            }

            if (c.m_nodeA.next != null)
            {
                c.m_nodeA.next.prev = c.m_nodeA.prev;
            }

            if (c.m_nodeA == bodyA.m_contactList)
            {
                bodyA.m_contactList = c.m_nodeA.next;
            }

            // Remove from body 2
            if (c.m_nodeB.prev != null)
            {
                c.m_nodeB.prev.next = c.m_nodeB.next;
            }

            if (c.m_nodeB.next != null)
            {
                c.m_nodeB.next.prev = c.m_nodeB.prev;
            }

            if (c.m_nodeB == bodyB.m_contactList)
            {
                bodyB.m_contactList = c.m_nodeB.next;
            }

            // Call the factory.
            pool.pushContact(c);
            --m_contactCount;
        }
예제 #8
0
        public virtual void preSolve(Contact contact, Manifold oldManifold)
        {
            Manifold manifold = contact.getManifold();

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

            Fixture fixtureA = contact.getFixtureA();
            Fixture fixtureB = contact.getFixtureB();

            Collision.Collision.getPointStates(state1, state2, oldManifold, manifold);

            contact.getWorldManifold(worldManifold);

            for (int i = 0; i < manifold.pointCount && pointCount < MAX_CONTACT_POINTS; i++)
            {
                ContactPoint cp = points[pointCount];
                cp.fixtureA = fixtureA;
                cp.fixtureB = fixtureB;
                cp.position.set(worldManifold.points[i]);
                cp.normal.set(worldManifold.normal);
                cp.state = state2[i];
                cp.normalImpulse = manifold.points[i].normalImpulse;
                cp.tangentImpulse = manifold.points[i].tangentImpulse;
                cp.separation = worldManifold.separations[i];
                ++pointCount;
            }
        }
예제 #9
0
        public override void preSolve(Contact contact, Manifold oldManifold)
        {
            base.preSolve(contact, oldManifold);

            Fixture fixtureA = contact.getFixtureA();
            Fixture fixtureB = contact.getFixtureB();

            if (fixtureA != m_platform && fixtureA != m_character)
            {
                return;
            }

            if (fixtureB != m_character && fixtureB != m_character)
            {
                return;
            }

            Vec2 position = m_character.getBody().getPosition();

            if (position.y < m_top + m_radius - 3.0f*Settings.linearSlop)
            {
                contact.setEnabled(false);
            }
        }
예제 #10
0
 public virtual void postSolve(Contact contact, ContactImpulse impulse)
 {
 }
예제 #11
0
 public virtual void endContact(Contact contact)
 {
 }
예제 #12
0
 public virtual void beginContact(Contact contact)
 {
 }
예제 #13
0
파일: World.cs 프로젝트: Nomad1/sharpbox2d
        public void pushContact(Contact contact)
        {
            Fixture fixtureA = contact.getFixtureA();
            Fixture fixtureB = contact.getFixtureB();

            if (contact.m_manifold.pointCount > 0 && !fixtureA.isSensor() && !fixtureB.isSensor())
            {
                fixtureA.getBody().setAwake(true);
                fixtureB.getBody().setAwake(true);
            }

            ShapeType type1 = fixtureA.getType();
            ShapeType type2 = fixtureB.getType();

            IDynamicStack<Contact> creator = contactStacks[(int) type1][(int) type2].creator;
            creator.push(contact);
        }
예제 #14
0
        /** initialization for pooling */
        public virtual void init(Fixture fA, int indexA, Fixture fB, int indexB)
        {
            m_flags = ENABLED_FLAG;

            m_fixtureA = fA;
            m_fixtureB = fB;

            m_indexA = indexA;
            m_indexB = indexB;

            m_manifold.pointCount = 0;

            m_prev = null;
            m_next = null;

            m_nodeA.contact = null;
            m_nodeA.prev = null;
            m_nodeA.next = null;
            m_nodeA.other = null;

            m_nodeB.contact = null;
            m_nodeB.prev = null;
            m_nodeB.next = null;
            m_nodeB.other = null;

            m_toiCount = 0;
            m_friction = Contact.mixFriction(fA.m_friction, fB.m_friction);
            m_restitution = Contact.mixRestitution(fA.m_restitution, fB.m_restitution);

            m_tangentSpeed = 0;
        }