Body constructor

Body({
  1. int collisionFilterGroup = 1,
  2. int collisionFilterMask = -1,
  3. bool collisionResponse = true,
  4. Vec3? position,
  5. Vec3? velocity,
  6. double mass = 0,
  7. Material? material,
  8. double linearDamping = 0.01,
  9. BodyTypes? type,
  10. bool allowSleep = true,
  11. double sleepSpeedLimit = 0.1,
  12. num sleepTimeLimit = 1,
  13. Quaternion? quaternion,
  14. Vec3? angularVelocity,
  15. bool fixedRotation = false,
  16. double angularDamping = 0.01,
  17. Vec3? linearFactor,
  18. Vec3? angularFactor,
  19. Shape? shape,
  20. bool isTrigger = false,
})

Implementation

Body({
  this.collisionFilterGroup = 1,
  this.collisionFilterMask = -1,
  this.collisionResponse = true,
  Vec3? position,
  Vec3? velocity,
  this.mass = 0,
  this.material,
  this.linearDamping = 0.01,
  BodyTypes? type,
  this.allowSleep = true,
  this.sleepSpeedLimit = 0.1,
  this.sleepTimeLimit = 1,
  Quaternion? quaternion,
  Vec3? angularVelocity,
  this.fixedRotation = false,
  this.angularDamping = 0.01,
  Vec3? linearFactor,
  Vec3? angularFactor,
  Shape? shape,
  this.isTrigger = false,
}):super() {
  id = Body.idCounter++;
  if (position != null) {
    this.position.copy(position);
    previousPosition.copy(position);
    interpolatedPosition.copy(position);
    initPosition.copy(position);
  }
  if (velocity != null) {
    this.velocity.copy(velocity);
  }

  invMass = mass > 0 ? 1.0 / mass : 0;
  this.type = mass <= 0.0 ? BodyTypes.static : BodyTypes.dynamic;
  // if (type == BodyTypes.static) {
  //   this.type = type!;
  // }
  this.type = type ?? this.type;
  if (quaternion != null) {
    this.quaternion.copy(quaternion);
    previousQuaternion.copy(quaternion);
    interpolatedQuaternion.copy(quaternion);
    initQuaternion.copy(quaternion);
  }
  if (angularVelocity != null) {
    this.angularVelocity.copy(angularVelocity);
  }
  if (linearFactor != null) {
    this.linearFactor.copy(linearFactor);
  }
  if (angularFactor != null) {
    this.angularFactor.copy(angularFactor);
  }
  if (shape != null) {
    addShape(shape);
  }

  updateMassProperties();
}