B2G/gecko/browser/devtools/tilt/TiltMath.jsm
/**
   * Calculate the inverse of a mat4.
   *
   * @param {Array} aMat
   *                mat4 to calculate inverse of
   * @param {Array} aDest
   *                optional, mat4 receiving operation result
   *                if not specified result is written to the first operand
   *
   * @return {Array} the destination mat4 if specified, first operand otherwise
   */
Calculate the inverse of a mat4.
@param {Array} aMat
mat4 to calculate inverse of
@param {Array} aDest
optional, mat4 receiving operation result
if not specified result is written to the first operand

@return {Array} the destination mat4 if specified, first operand otherwise
Calculate the inverse of a mat4 . @param { Array } aMat mat4 to calculate inverse of @param { Array } aDest optional mat4 receiving operation result if not specified result is written to the first operand @return { Array } the destination mat4 if specified first operand otherwise
function M4_inverse(aMat, aDest)
  {
    if (!aDest) {
      aDest = aMat;
    }
    let a00 = aMat[0], a01 = aMat[1], a02 = aMat[2], a03 = aMat[3];
    let a10 = aMat[4], a11 = aMat[5], a12 = aMat[6], a13 = aMat[7];
    let a20 = aMat[8], a21 = aMat[9], a22 = aMat[10], a23 = aMat[11];
    let a30 = aMat[12], a31 = aMat[13], a32 = aMat[14], a33 = aMat[15];
    let b00 = a00 * a11 - a01 * a10;
    let b01 = a00 * a12 - a02 * a10;
    let b02 = a00 * a13 - a03 * a10;
    let b03 = a01 * a12 - a02 * a11;
    let b04 = a01 * a13 - a03 * a11;
    let b05 = a02 * a13 - a03 * a12;
    let b06 = a20 * a31 - a21 * a30;
    let b07 = a20 * a32 - a22 * a30;
    let b08 = a20 * a33 - a23 * a30;
    let b09 = a21 * a32 - a22 * a31;
    let b10 = a21 * a33 - a23 * a31;
    let b11 = a22 * a33 - a23 * a32;
    let id = 1 / ((b00 * b11 - b01 * b10 + b02 * b09 +
                   b03 * b08 - b04 * b07 + b05 * b06) || EPSILON);
    aDest[0] = ( a11 * b11 - a12 * b10 + a13 * b09) * id;
    aDest[1] = (-a01 * b11 + a02 * b10 - a03 * b09) * id;
    aDest[2] = ( a31 * b05 - a32 * b04 + a33 * b03) * id;
    aDest[3] = (-a21 * b05 + a22 * b04 - a23 * b03) * id;
    aDest[4] = (-a10 * b11 + a12 * b08 - a13 * b07) * id;
    aDest[5] = ( a00 * b11 - a02 * b08 + a03 * b07) * id;
    aDest[6] = (-a30 * b05 + a32 * b02 - a33 * b01) * id;
    aDest[7] = ( a20 * b05 - a22 * b02 + a23 * b01) * id;
    aDest[8] = ( a10 * b10 - a11 * b08 + a13 * b06) * id;
    aDest[9] = (-a00 * b10 + a01 * b08 - a03 * b06) * id;
    aDest[10] = ( a30 * b04 - a31 * b02 + a33 * b00) * id;
    aDest[11] = (-a20 * b04 + a21 * b02 - a23 * b00) * id;
    aDest[12] = (-a10 * b09 + a11 * b07 - a12 * b06) * id;
    aDest[13] = ( a00 * b09 - a01 * b07 + a02 * b06) * id;
    aDest[14] = (-a30 * b03 + a31 * b01 - a32 * b00) * id;
    aDest[15] = ( a20 * b03 - a21 * b01 + a22 * b00) * id;
    return aDest;
  }
function M4_inverse ( aMat , aDest ) { if ( ! aDest ) { aDest = aMat ; } let a00 = aMat [ 0 ] , a01 = aMat [ 1 ] , a02 = aMat [ 2 ] , a03 = aMat [ 3 ] ; let a10 = aMat [ 4 ] , a11 = aMat [ 5 ] , a12 = aMat [ 6 ] , a13 = aMat [ 7 ] ; let a20 = aMat [ 8 ] , a21 = aMat [ 9 ] , a22 = aMat [ 10 ] , a23 = aMat [ 11 ] ; let a30 = aMat [ 12 ] , a31 = aMat [ 13 ] , a32 = aMat [ 14 ] , a33 = aMat [ 15 ] ; let b00 = a00 * a11 - a01 * a10 ; let b01 = a00 * a12 - a02 * a10 ; let b02 = a00 * a13 - a03 * a10 ; let b03 = a01 * a12 - a02 * a11 ; let b04 = a01 * a13 - a03 * a11 ; let b05 = a02 * a13 - a03 * a12 ; let b06 = a20 * a31 - a21 * a30 ; let b07 = a20 * a32 - a22 * a30 ; let b08 = a20 * a33 - a23 * a30 ; let b09 = a21 * a32 - a22 * a31 ; let b10 = a21 * a33 - a23 * a31 ; let b11 = a22 * a33 - a23 * a32 ; let id = 1 / ( ( b00 * b11 - b01 * b10 + b02 * b09 + b03 * b08 - b04 * b07 + b05 * b06 ) || EPSILON ) ; aDest [ 0 ] = ( a11 * b11 - a12 * b10 + a13 * b09 ) * id ; aDest [ 1 ] = ( - a01 * b11 + a02 * b10 - a03 * b09 ) * id ; aDest [ 2 ] = ( a31 * b05 - a32 * b04 + a33 * b03 ) * id ; aDest [ 3 ] = ( - a21 * b05 + a22 * b04 - a23 * b03 ) * id ; aDest [ 4 ] = ( - a10 * b11 + a12 * b08 - a13 * b07 ) * id ; aDest [ 5 ] = ( a00 * b11 - a02 * b08 + a03 * b07 ) * id ; aDest [ 6 ] = ( - a30 * b05 + a32 * b02 - a33 * b01 ) * id ; aDest [ 7 ] = ( a20 * b05 - a22 * b02 + a23 * b01 ) * id ; aDest [ 8 ] = ( a10 * b10 - a11 * b08 + a13 * b06 ) * id ; aDest [ 9 ] = ( - a00 * b10 + a01 * b08 - a03 * b06 ) * id ; aDest [ 10 ] = ( a30 * b04 - a31 * b02 + a33 * b00 ) * id ; aDest [ 11 ] = ( - a20 * b04 + a21 * b02 - a23 * b00 ) * id ; aDest [ 12 ] = ( - a10 * b09 + a11 * b07 - a12 * b06 ) * id ; aDest [ 13 ] = ( a00 * b09 - a01 * b07 + a02 * b06 ) * id ; aDest [ 14 ] = ( - a30 * b03 + a31 * b01 - a32 * b00 ) * id ; aDest [ 15 ] = ( a20 * b03 - a21 * b01 + a22 * b00 ) * id ; return aDest ; }
Calculate the inverse of a mat4.
Calculate the inverse of a mat4 .