applyImpulse method
void
applyImpulse(
- Vector3 impulse, [
- Vector3? 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(Vector3 impulse, [Vector3? relativePoint]){
relativePoint ??= Vector3.zero();
if (type != BodyTypes.dynamic) {
return;
}
if (sleepState == BodySleepStates.sleeping) {
wakeUp();
}
// Compute point position relative to the body center
final Vector3 r = relativePoint;
// Compute produced central impulse velocity
final velo = _bodyApplyImpulseVelo;
velo.setFrom(impulse);
velo.scale2(invMass, velo);
// Add linear impulse
velocity.add2(velo, velocity);
// Compute produced rotational impulse velocity
final rotVelo = _bodyApplyImpulseRotVelo;
r.cross2(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.add2(rotVelo, angularVelocity);
}