RigidBody constructor

RigidBody({
  1. Vec3? position,
  2. Quat? orientation,
  3. List<Shape>? shapes,
  4. String? name,
  5. RigidBodyType type = RigidBodyType.static,
  6. bool allowSleep = true,
  7. bool isSleeping = false,
  8. bool adjustPosition = true,
  9. Vec3? linearVelocity,
  10. Vec3? angularVelocity,
  11. double? mass,
  12. bool isTrigger = false,
})

Implementation

RigidBody({
  Vec3? position,
  Quat? orientation,
  List<Shape>? shapes,
  String? name,
  this.type = RigidBodyType.static,
  this.allowSleep = true,
  bool isSleeping = false,
  bool adjustPosition = true,
  Vec3? linearVelocity,
  Vec3? angularVelocity,
  double? mass,
  this.isTrigger = false
}){
  this.position = position ?? Vec3();
  this.orientation = orientation ?? Quat();
  this.linearVelocity = linearVelocity ?? Vec3();
  this.angularVelocity = angularVelocity ?? Vec3();

  initAngularVelocity = Vec3().copy(this.angularVelocity);
  initLinearVelocity = Vec3().copy(this.linearVelocity);
  initPosition = Vec3().copy(this.position);
  initOrientation = Quat().copy(this.orientation);

  //type = config.type;
  if(shapes!= null && shapes.isNotEmpty){
    for(int i = 0; i < shapes.length;i++){
      addShape(shapes[i]);
    }
  }

  id = RigidBody.idCounter++;
  this.name = name ?? id.toString();

  if(isKinematic){
    allowSleep = false;
  }

  if(mass == null || mass == 0){
    setupMass(adjustPosition);
  }
  else{
    this.mass = mass;
    type = RigidBodyType.static == type?RigidBodyType.dynamic:type;
    setupInertia(Vec3(),adjustPosition);
  }

  if(isDynamic){
    if(isSleeping){
      sleep();
    }
    else{
      awake();
    }
  }
}