Esempio n. 1
0
    /// Set the type of this body. This may alter the mass and velocity.
    public void SetType(BodyType type)
    {
        Debug.Assert(m_world.IsLocked() == false);
        if (m_world.IsLocked() == true)
        {
            return;
        }

        if (m_type == type)
        {
            return;
        }

        m_type = type;

        ResetMassData();

        if (m_type == BodyType.b2_staticBody)
        {
            m_linearVelocity.SetZero();
            m_angularVelocity = 0.0f;
            m_sweep.a0        = m_sweep.a;


            m_sweep.c0 = m_sweep.c;
            SynchronizeFixtures();
        }

        SetAwake(true);

        m_force.SetZero();
        m_torque = 0.0f;

        // Delete the attached contacts.
        b2ContactEdge ce = m_contactList;

        while (ce != null)
        {
            b2ContactEdge ce0 = ce;
            ce = ce.next;
            m_world.m_contactManager.Destroy(ce0.contact);
        }
        m_contactList = null;

        // Touch the proxies so that new contacts will be created (when appropriate)
        b2BroadPhase broadPhase = m_world.m_contactManager.m_broadPhase;

        for (b2Fixture f = m_fixtureList; f != null; f = f.m_next)
        {
            int proxyCount = f.m_proxyCount;
            for (int i = 0; i < proxyCount; ++i)
            {
                broadPhase.TouchProxy(f.m_proxies[i].proxyId);
            }
        }
    }
Esempio n. 2
0
        public virtual void Refilter()
        {
            if (m_body == null)
            {
                return;
            }

            // Flag associated contacts for filtering.
            b2ContactEdge edge = m_body.ContactList;

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

                edge = edge.Next;
            }

            b2World world = m_body.World;

            if (world == null)
            {
                return;
            }

            // Touch each proxy so that new pairs may be created
            b2BroadPhase broadPhase = world.ContactManager.BroadPhase;

            for (int i = 0; i < m_proxyCount; ++i)
            {
                broadPhase.TouchProxy(m_proxies[i].proxyId);
            }
        }