Body constructor
Body({
- int collisionFilterGroup = 1,
- int collisionFilterMask = -1,
- bool collisionResponse = true,
- Vector3? position,
- Vector3? velocity,
- double mass = 0,
- Material? material,
- double linearDamping = 0.01,
- BodyTypes? type,
- bool allowSleep = true,
- double sleepSpeedLimit = 0.1,
- num sleepTimeLimit = 1,
- Quaternion? quaternion,
- Vector3? angularVelocity,
- bool fixedRotation = false,
- double angularDamping = 0.01,
- Vector3? linearFactor,
- Vector3? angularFactor,
- Shape? shape,
- bool isTrigger = false,
Implementation
Body({
this.collisionFilterGroup = 1,
this.collisionFilterMask = -1,
this.collisionResponse = true,
Vector3? position,
Vector3? velocity,
this.mass = 0,
this.material,
this.linearDamping = 0.01,
BodyTypes? type,
this.allowSleep = true,
this.sleepSpeedLimit = 0.1,
this.sleepTimeLimit = 1,
Quaternion? quaternion,
Vector3? angularVelocity,
this.fixedRotation = false,
this.angularDamping = 0.01,
Vector3? linearFactor,
Vector3? angularFactor,
Shape? shape,
this.isTrigger = false,
}):super() {
id = Body.idCounter++;
if (position != null) {
this.position.setFrom(position);
previousPosition.setFrom(position);
interpolatedPosition.setFrom(position);
initPosition.setFrom(position);
}
if (velocity != null) {
this.velocity.setFrom(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.setFrom(quaternion);
previousQuaternion.setFrom(quaternion);
interpolatedQuaternion.setFrom(quaternion);
initQuaternion.setFrom(quaternion);
}
if (angularVelocity != null) {
this.angularVelocity.setFrom(angularVelocity);
}
if (linearFactor != null) {
this.linearFactor.setFrom(linearFactor);
}
if (angularFactor != null) {
this.angularFactor.setFrom(angularFactor);
}
if (shape != null) {
addShape(shape);
}
updateMassProperties();
}