Body constructor

Body(BodyDef bd, World world)

Implementation

Body(final BodyDef bd, this.world) {
  assert(MathUtils.vector2IsValid(bd.position));
  assert(MathUtils.vector2IsValid(bd.linearVelocity));
  assert(bd.gravityScale >= 0.0);
  assert(bd.angularDamping >= 0.0);
  assert(bd.linearDamping >= 0.0);

  _flags = 0;

  if (bd.bullet) {
    _flags |= BULLET_FLAG;
  }
  if (bd.fixedRotation) {
    _flags |= FIXED_ROTATION_FLAG;
  }
  if (bd.allowSleep) {
    _flags |= AUTO_SLEEP_FLAG;
  }
  if (bd.awake) {
    _flags |= AWAKE_FLAG;
  }
  if (bd.active) {
    _flags |= ACTIVE_FLAG;
  }

  _transform.p.setFrom(bd.position);
  _transform.q.setAngle(bd.angle);

  _sweep.localCenter.setZero();
  _sweep.c0.setFrom(_transform.p);
  _sweep.c.setFrom(_transform.p);
  _sweep.a0 = bd.angle;
  _sweep.a = bd.angle;
  _sweep.alpha0 = 0.0;

  _jointList = null;
  _contactList = null;
  _prev = null;
  _next = null;

  _linearVelocity.setFrom(bd.linearVelocity);
  _angularVelocity = bd.angularVelocity;

  _linearDamping = bd.linearDamping;
  angularDamping = bd.angularDamping;
  _gravityScale = bd.gravityScale;

  _force.setZero();

  _sleepTime = 0.0;

  _bodyType = bd.type;

  if (_bodyType == BodyType.DYNAMIC) {
    _mass = 1.0;
    _invMass = 1.0;
  } else {
    _mass = 0.0;
    _invMass = 0.0;
  }

  _I = 0.0;
  _invI = 0.0;

  userData = bd.userData;

  _fixtureList = null;
  _fixtureCount = 0;
}