B2G/gecko/browser/devtools/tilt/TiltMath.jsm
/**
   * Performs a spherical linear interpolation between two quat4.
   *
   * @param {Array} aQuat
   *                first quaternion
   * @param {Array} aQuat2
   *                second quaternion
   * @param {Number} aSlerp
   *                 interpolation amount between the two inputs
   * @param {Array} aDest
   *                 optional, quat4 receiving the operation result
   *                 if not specified result is written to the first operand
   *
   * @return {Array} the destination quat if specified, first operand otherwise
   */
Performs a spherical linear interpolation between two quat4.
@param {Array} aQuat
first quaternion
@param {Array} aQuat2
second quaternion
@param {Number} aSlerp
interpolation amount between the two inputs
@param {Array} aDest
optional, quat4 receiving the operation result
if not specified result is written to the first operand

@return {Array} the destination quat if specified, first operand otherwise
Performs a spherical linear interpolation between two quat4 . @param { Array } aQuat first quaternion @param { Array } aQuat2 second quaternion @param { Number } aSlerp interpolation amount between the two inputs @param { Array } aDest optional quat4 receiving the operation result if not specified result is written to the first operand @return { Array } the destination quat if specified first operand otherwise
function Q4_slerp(aQuat, aQuat2, aSlerp, aDest)
  {
    if (!aDest) {
      aDest = aQuat;
    }
    let cosHalfTheta = aQuat[0] * aQuat2[0] +
                       aQuat[1] * aQuat2[1] +
                       aQuat[2] * aQuat2[2] +
                       aQuat[3] * aQuat2[3];
    if (Math.abs(cosHalfTheta) >= 1) {
      aDest[0] = aQuat[0];
      aDest[1] = aQuat[1];
      aDest[2] = aQuat[2];
      aDest[3] = aQuat[3];
      return aDest;
    }
    let halfTheta = Math.acos(cosHalfTheta);
    let sinHalfTheta = Math.sqrt(1 - cosHalfTheta * cosHalfTheta);
    if (Math.abs(sinHalfTheta) < EPSILON) {
      aDest[0] = (aQuat[0] * 0.5 + aQuat2[0] * 0.5);
      aDest[1] = (aQuat[1] * 0.5 + aQuat2[1] * 0.5);
      aDest[2] = (aQuat[2] * 0.5 + aQuat2[2] * 0.5);
      aDest[3] = (aQuat[3] * 0.5 + aQuat2[3] * 0.5);
      return aDest;
    }
    let ratioA = Math.sin((1 - aSlerp) * halfTheta) / sinHalfTheta;
    let ratioB = Math.sin(aSlerp * halfTheta) / sinHalfTheta;
    aDest[0] = (aQuat[0] * ratioA + aQuat2[0] * ratioB);
    aDest[1] = (aQuat[1] * ratioA + aQuat2[1] * ratioB);
    aDest[2] = (aQuat[2] * ratioA + aQuat2[2] * ratioB);
    aDest[3] = (aQuat[3] * ratioA + aQuat2[3] * ratioB);
    return aDest;
  }
function Q4_slerp ( aQuat , aQuat2 , aSlerp , aDest ) { if ( ! aDest ) { aDest = aQuat ; } let cosHalfTheta = aQuat [ 0 ] * aQuat2 [ 0 ] + aQuat [ 1 ] * aQuat2 [ 1 ] + aQuat [ 2 ] * aQuat2 [ 2 ] + aQuat [ 3 ] * aQuat2 [ 3 ] ; if ( Math . abs ( cosHalfTheta ) >= 1 ) { aDest [ 0 ] = aQuat [ 0 ] ; aDest [ 1 ] = aQuat [ 1 ] ; aDest [ 2 ] = aQuat [ 2 ] ; aDest [ 3 ] = aQuat [ 3 ] ; return aDest ; } let halfTheta = Math . acos ( cosHalfTheta ) ; let sinHalfTheta = Math . sqrt ( 1 - cosHalfTheta * cosHalfTheta ) ; if ( Math . abs ( sinHalfTheta ) < EPSILON ) { aDest [ 0 ] = ( aQuat [ 0 ] * 0.5 + aQuat2 [ 0 ] * 0.5 ) ; aDest [ 1 ] = ( aQuat [ 1 ] * 0.5 + aQuat2 [ 1 ] * 0.5 ) ; aDest [ 2 ] = ( aQuat [ 2 ] * 0.5 + aQuat2 [ 2 ] * 0.5 ) ; aDest [ 3 ] = ( aQuat [ 3 ] * 0.5 + aQuat2 [ 3 ] * 0.5 ) ; return aDest ; } let ratioA = Math . sin ( ( 1 - aSlerp ) * halfTheta ) / sinHalfTheta ; let ratioB = Math . sin ( aSlerp * halfTheta ) / sinHalfTheta ; aDest [ 0 ] = ( aQuat [ 0 ] * ratioA + aQuat2 [ 0 ] * ratioB ) ; aDest [ 1 ] = ( aQuat [ 1 ] * ratioA + aQuat2 [ 1 ] * ratioB ) ; aDest [ 2 ] = ( aQuat [ 2 ] * ratioA + aQuat2 [ 2 ] * ratioB ) ; aDest [ 3 ] = ( aQuat [ 3 ] * ratioA + aQuat2 [ 3 ] * ratioB ) ; return aDest ; }
Performs a spherical linear interpolation between two quat4.
Performs a spherical linear interpolation between two quat4 .