B2G/gecko/browser/devtools/tilt/TiltMath.jsm
/**
   * Calculate the inverse of the upper 3x3 elements of a mat4 and copies
   * the result into a mat3. The resulting matrix is useful for calculating
   * transformed normals.
   *
   * @param {Array} aMat
   *                mat4 containing values to invert and copy
   * @param {Array} aDest
   *                optional, mat3 receiving operation result
   *                if not specified result is written to the first operand
   *
   * @return {Array} the destination mat3 if specified, first operand otherwise
   */
Calculate the inverse of the upper 3x3 elements of a mat4 and copies
the result into a mat3. The resulting matrix is useful for calculating
transformed normals.

@param {Array} aMat
mat4 containing values to invert and copy
@param {Array} aDest
optional, mat3 receiving operation result
if not specified result is written to the first operand

@return {Array} the destination mat3 if specified, first operand otherwise
Calculate the inverse of the upper 3x3 elements of a mat4 and copies the result into a mat3 . The resulting matrix is useful for calculating transformed normals . @param { Array } aMat mat4 containing values to invert and copy @param { Array } aDest optional mat3 receiving operation result if not specified result is written to the first operand @return { Array } the destination mat3 if specified first operand otherwise
function M4_toInverseMat3(aMat, aDest)
  {
    if (!aDest) {
      aDest = new Float32Array(9);
    }
    let a00 = aMat[0], a01 = aMat[1], a02 = aMat[2];
    let a10 = aMat[4], a11 = aMat[5], a12 = aMat[6];
    let a20 = aMat[8], a21 = aMat[9], a22 = aMat[10];
    let b01 = a22 * a11 - a12 * a21;
    let b11 = -a22 * a10 + a12 * a20;
    let b21 = a21 * a10 - a11 * a20;
    let id = 1 / ((a00 * b01 + a01 * b11 + a02 * b21) || EPSILON);
    aDest[0] = b01 * id;
    aDest[1] = (-a22 * a01 + a02 * a21) * id;
    aDest[2] = ( a12 * a01 - a02 * a11) * id;
    aDest[3] = b11 * id;
    aDest[4] = ( a22 * a00 - a02 * a20) * id;
    aDest[5] = (-a12 * a00 + a02 * a10) * id;
    aDest[6] = b21 * id;
    aDest[7] = (-a21 * a00 + a01 * a20) * id;
    aDest[8] = ( a11 * a00 - a01 * a10) * id;
    return aDest;
  }
function M4_toInverseMat3 ( aMat , aDest ) { if ( ! aDest ) { aDest = new Float32Array ( 9 ) ; } let a00 = aMat [ 0 ] , a01 = aMat [ 1 ] , a02 = aMat [ 2 ] ; let a10 = aMat [ 4 ] , a11 = aMat [ 5 ] , a12 = aMat [ 6 ] ; let a20 = aMat [ 8 ] , a21 = aMat [ 9 ] , a22 = aMat [ 10 ] ; let b01 = a22 * a11 - a12 * a21 ; let b11 = - a22 * a10 + a12 * a20 ; let b21 = a21 * a10 - a11 * a20 ; let id = 1 / ( ( a00 * b01 + a01 * b11 + a02 * b21 ) || EPSILON ) ; aDest [ 0 ] = b01 * id ; aDest [ 1 ] = ( - a22 * a01 + a02 * a21 ) * id ; aDest [ 2 ] = ( a12 * a01 - a02 * a11 ) * id ; aDest [ 3 ] = b11 * id ; aDest [ 4 ] = ( a22 * a00 - a02 * a20 ) * id ; aDest [ 5 ] = ( - a12 * a00 + a02 * a10 ) * id ; aDest [ 6 ] = b21 * id ; aDest [ 7 ] = ( - a21 * a00 + a01 * a20 ) * id ; aDest [ 8 ] = ( a11 * a00 - a01 * a10 ) * id ; return aDest ; }
Calculate the inverse of the upper 3x3 elements of a mat4 and copies
 the result into a mat3.
Calculate the inverse of the upper 3x3 elements of a mat4 and copies the result into a mat3 .