/// Set the active state of the body. An inactive body is not /// simulated and cannot be collided with or woken up. /// If you pass a flag of true, all fixtures will be added to the /// broad-phase. /// If you pass a flag of false, all fixtures will be removed from /// the broad-phase and all contacts will be destroyed. /// Fixtures and joints are otherwise unaffected. You may continue /// to create/destroy fixtures and joints on inactive bodies. /// Fixtures on an inactive body are implicitly inactive and will /// not participate in collisions, ray-casts, or queries. /// Joints connected to an inactive body are implicitly inactive. /// An inactive body is still owned by a b2World object and remains /// in the body list. public void SetActive(bool flag) { Debug.Assert(m_world.IsLocked() == false); if (flag == IsActive()) { return; } if (flag) { m_flags |= BodyFlags.e_activeFlag; // Create all proxies. b2BroadPhase broadPhase = m_world.m_contactManager.m_broadPhase; for (b2Fixture f = m_fixtureList; f != null; f = f.m_next) { f.CreateProxies(broadPhase, m_xf); } // Contacts are created the next time step. } else { m_flags &= ~BodyFlags.e_activeFlag; // Destroy all proxies. b2BroadPhase broadPhase = m_world.m_contactManager.m_broadPhase; for (b2Fixture f = m_fixtureList; f != null; f = f.m_next) { f.DestroyProxies(broadPhase); } // Destroy 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; } }
/// 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(b2Fixture fixture) { if (fixture == null) { return; } Debug.Assert(m_world.IsLocked() == false); if (m_world.IsLocked() == true) { return; } Debug.Assert(fixture.m_body == this); // Remove the fixture from this body's singly linked list. Debug.Assert(m_fixtureCount > 0); b2Fixture node = m_fixtureList; bool found = false; while (node != null) { if (node == fixture) { node = fixture.m_next; found = true; break; } node = node.m_next; } // You tried to remove a shape that is not attached to this body. Debug.Assert(found); // Destroy any contacts associated with the fixture. b2ContactEdge edge = m_contactList; while (edge != null) { b2Contact c = edge.contact; edge = edge.next; b2Fixture fixtureA = c.GetFixtureA(); b2Fixture fixtureB = c.GetFixtureB(); if (fixture == fixtureA || fixture == fixtureB) { // This destroys the contact and removes it from // this body's contact list. m_world.m_contactManager.Destroy(c); } } if ((m_flags & BodyFlags.e_activeFlag) != 0) { b2BroadPhase broadPhase = m_world.m_contactManager.m_broadPhase; fixture.DestroyProxies(broadPhase); } fixture.m_body = null; fixture.m_next = null; fixture.Destroy(); --m_fixtureCount; // Reset the mass data. ResetMassData(); }