/** 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) { body.destroyFixture(fixture.fixture); fixtures.removeValue(fixture, true); world.fixtures.remove(fixture.fixture); }
@Override public void step(TestbedSettings settings) { if (nextShape != null) { m_body.destroyFixture(currFixture); currFixture = m_body.createFixture(nextShape, 1f); nextShape = null;
@Override public void keyPressed(char key, int argKeyCode) { switch (key) { case 'c': if (m_fixture2 == null) { CircleShape shape = new CircleShape(); shape.m_radius = 3.0f; shape.m_p.set(0.5f, -4.0f); m_fixture2 = m_body.createFixture(shape, 10.0f); m_body.setAwake(true); } break; case 'd': if (m_fixture2 != null) { m_body.destroyFixture(m_fixture2); m_fixture2 = null; m_body.setAwake(true); } break; } }
void Break() { // Create two bodies from one. Body body1 = m_piece1.getBody(); Vec2 center = body1.getWorldCenter(); body1.destroyFixture(m_piece2); m_piece2 = null; BodyDef bd = new BodyDef(); bd.type = BodyType.DYNAMIC; bd.position = body1.getPosition(); bd.angle = body1.getAngle(); Body body2 = getWorld().createBody(bd); m_piece2 = body2.createFixture(m_shape2, 1.0f); // Compute consistent velocities for new bodies based on // cached velocity. Vec2 center1 = body1.getWorldCenter(); Vec2 center2 = body2.getWorldCenter(); Vec2 velocity1 = m_velocity.add(Vec2.cross(m_angularVelocity, center1.sub(center))); Vec2 velocity2 = m_velocity.add(Vec2.cross(m_angularVelocity, center2.sub(center))); body1.setAngularVelocity(m_angularVelocity); body1.setLinearVelocity(velocity1); body2.setAngularVelocity(m_angularVelocity); body2.setLinearVelocity(velocity2); }
@Override public void step(TestbedSettings settings) { if (nextShape != null) { m_body.destroyFixture(currFixture); currFixture = m_body.createFixture(nextShape, 1f); nextShape = null;
@Override public void keyPressed(char key, int argKeyCode) { switch (key) { case 'c': if (m_fixture2 == null) { CircleShape shape = new CircleShape(); shape.m_radius = 3.0f; shape.m_p.set(0.5f, -4.0f); m_fixture2 = m_body.createFixture(shape, 10.0f); m_body.setAwake(true); } break; case 'd': if (m_fixture2 != null) { m_body.destroyFixture(m_fixture2); m_fixture2 = null; m_body.setAwake(true); } break; } }
void Break() { // Create two bodies from one. Body body1 = m_piece1.getBody(); Vec2 center = body1.getWorldCenter(); body1.destroyFixture(m_piece2); m_piece2 = null; BodyDef bd = new BodyDef(); bd.type = BodyType.DYNAMIC; bd.position = body1.getPosition(); bd.angle = body1.getAngle(); Body body2 = getWorld().createBody(bd); m_piece2 = body2.createFixture(m_shape2, 1.0f); // Compute consistent velocities for new bodies based on // cached velocity. Vec2 center1 = body1.getWorldCenter(); Vec2 center2 = body2.getWorldCenter(); Vec2 velocity1 = m_velocity.add(Vec2.cross(m_angularVelocity, center1.sub(center))); Vec2 velocity2 = m_velocity.add(Vec2.cross(m_angularVelocity, center2.sub(center))); body1.setAngularVelocity(m_angularVelocity); body1.setLinearVelocity(velocity1); body2.setAngularVelocity(m_angularVelocity); body2.setLinearVelocity(velocity2); }