integrate method
Move the body forward in time. @param dt Time step; @param quatNormalize Set to true to normalize the body quaternion; @param quatNormalizeFast If the quaternion should be normalized using "fast" quaternion normalization;
Implementation
void integrate(double dt,[bool quatNormalize = false,bool quatNormalizeFast = false]){
// Save previous position
previousPosition.copy(position);
previousQuaternion.copy(quaternion);
if (!(type == BodyTypes.dynamic || type == BodyTypes.kinematic) || sleepState == BodySleepStates.sleeping) {
// Only for dynamic
return;
}
final velo = velocity;
final angularVelo = angularVelocity;
final pos = position;
final force = this.force;
final torque = this.torque;
final quat = quaternion;
final invMass = this.invMass;
final invInertia = invInertiaWorld;
final linearFactor = this.linearFactor;
final iMdt = invMass * dt;
velo.x += force.x * iMdt * linearFactor.x;
velo.y += force.y * iMdt * linearFactor.y;
velo.z += force.z * iMdt * linearFactor.z;
final e = invInertia.elements;
final angularFactor = this.angularFactor;
final tx = torque.x * angularFactor.x;
final ty = torque.y * angularFactor.y;
final tz = torque.z * angularFactor.z;
angularVelo.x += dt * (e[0] * tx + e[1] * ty + e[2] * tz);
angularVelo.y += dt * (e[3] * tx + e[4] * ty + e[5] * tz);
angularVelo.z += dt * (e[6] * tx + e[7] * ty + e[8] * tz);
// Use velocity - leap frog
pos.x += velo.x * dt;
pos.y += velo.y * dt;
pos.z += velo.z * dt;
quat.integrate(angularVelocity, dt, this.angularFactor, quat);
if (quatNormalize) {
if (quatNormalizeFast) {
quat.normalizeFast();
} else {
quat.normalize();
}
}
aabbNeedsUpdate = true;
// Update world inertia
updateInertiaWorld();
}