createFixtureFromFixtureDef method

Fixture createFixtureFromFixtureDef (FixtureDef def)

Creates a fixture and attach it to this body. Use this function if you need to set some fixture parameters, like friction. Otherwise you can create the fixture directly from a shape. If the density is non-zero, this function automatically updates the mass of the body. Contacts are not created until the next time step.

@param def the fixture definition. @warning This function is locked during callbacks.

Implementation

Fixture createFixtureFromFixtureDef(FixtureDef def) {
  assert(world.isLocked() == false);

  if (world.isLocked() == true) {
    return null;
  }

  Fixture fixture = new Fixture();
  fixture.create(this, def);

  if ((_flags & ACTIVE_FLAG) == ACTIVE_FLAG) {
    BroadPhase broadPhase = world._contactManager.broadPhase;
    fixture.createProxies(broadPhase, _transform);
  }

  fixture._next = _fixtureList;
  _fixtureList = fixture;
  ++_fixtureCount;

  fixture._body = this;

  // Adjust mass properties if needed.
  if (fixture._density > 0.0) {
    resetMassData();
  }

  // Let the world know we have a new fixture. This will cause new contacts
  // to be created at the beginning of the next time step.
  world._flags |= World.NEW_FIXTURE;

  return fixture;
}