RigidBody constructor

RigidBody({
  1. Vector3? position,
  2. Quaternion? 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. Vector3? linearVelocity,
  10. Vector3? angularVelocity,
  11. double? mass,
  12. bool isTrigger = false,
})

Implementation

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

  initAngularVelocity = Vector3.copy(this.angularVelocity);
  initLinearVelocity = Vector3.copy(this.linearVelocity);
  initPosition = Vector3.copy(this.position);
  initOrientation = Quaternion.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(Vector3.zero(),adjustPosition);
  }

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