applyImpulse method

void applyImpulse(
  1. Vec3 impulse, [
  2. Vec3? relativePoint
])

Apply impulse to a point of the body. This could for example be a point on the Body surface. An impulse is a force added to a body during a short period of time (impulse = force * time). Impulses will be added to Body.velocity and Body.angularVelocity.; @param impulse The amount of impulse to add.; @param relativePoint A point relative to the center of mass to apply the force on.

Implementation

void applyImpulse(Vec3 impulse, [Vec3? relativePoint]){
  relativePoint ??= Vec3();
  if (type != BodyTypes.dynamic) {
    return;
  }

  if (sleepState == BodySleepStates.sleeping) {
    wakeUp();
  }

  // Compute point position relative to the body center
  final Vec3 r = relativePoint;

  // Compute produced central impulse velocity
  final velo = _bodyApplyImpulseVelo;
  velo.copy(impulse);
  velo.scale(invMass, velo);

  // Add linear impulse
  velocity.vadd(velo, velocity);

  // Compute produced rotational impulse velocity
  final rotVelo = _bodyApplyImpulseRotVelo;
  r.cross(impulse, rotVelo);

  /*
   rotVelo.x *= this.invInertia.x;
   rotVelo.y *= this.invInertia.y;
   rotVelo.z *= this.invInertia.z;
   */
  invInertiaWorld.vmult(rotVelo, rotVelo);

  // Add rotational Impulse
  angularVelocity.vadd(rotVelo, angularVelocity);
}