setType method

void setType (BodyType type)

Set the type of this body. This may alter the mass and velocity.

@param type

Implementation

void setType(BodyType type) {
  assert(world.isLocked() == false);
  if (world.isLocked() == true) {
    return;
  }

  if (_bodyType == type) {
    return;
  }

  _bodyType = type;

  resetMassData();

  if (_bodyType == BodyType.STATIC) {
    _linearVelocity.setZero();
    _angularVelocity = 0.0;
    _sweep.a0 = _sweep.a;
    _sweep.c0.setFrom(_sweep.c);
    synchronizeFixtures();
  }

  setAwake(true);

  _force.setZero();
  _torque = 0.0;

  // Delete the attached contacts.
  ContactEdge ce = _contactList;
  while (ce != null) {
    ContactEdge ce0 = ce;
    ce = ce.next;
    world._contactManager.destroy(ce0.contact);
  }
  _contactList = null;

  // Touch the proxies so that new contacts will be created (when appropriate)
  BroadPhase broadPhase = world._contactManager.broadPhase;
  for (Fixture f = _fixtureList; f != null; f = f._next) {
    int proxyCount = f._proxyCount;
    for (int i = 0; i < proxyCount; ++i) {
      broadPhase.touchProxy(f._proxies[i].proxyId);
    }
  }
}