B2G/gecko/browser/devtools/tilt/TiltMath.jsm
/**
   * Generates a look-at matrix with the given eye position, focal point, and
   * up axis.
   *
   * @param {Array} aEye
   *                vec3, position of the viewer
   * @param {Array} aCenter
   *                vec3, point the viewer is looking at
   * @param {Array} aUp
   *                vec3 pointing up
   * @param {Array} aDest
   *                optional, mat4 frustum matrix will be written into
   *                if not specified result is written to a new mat4
   *
   * @return {Array} the destination mat4 if specified, a new mat4 otherwise
   */
Generates a look-at matrix with the given eye position, focal point, and
up axis.

@param {Array} aEye
vec3, position of the viewer
@param {Array} aCenter
vec3, point the viewer is looking at
@param {Array} aUp
vec3 pointing up
@param {Array} aDest
optional, mat4 frustum matrix will be written into
if not specified result is written to a new mat4

@return {Array} the destination mat4 if specified, a new mat4 otherwise
Generates a look - at matrix with the given eye position focal point and up axis . @param { Array } aEye vec3 position of the viewer @param { Array } aCenter vec3 point the viewer is looking at @param { Array } aUp vec3 pointing up @param { Array } aDest optional mat4 frustum matrix will be written into if not specified result is written to a new mat4 @return { Array } the destination mat4 if specified a new mat4 otherwise
function M4_lookAt(aEye, aCenter, aUp, aDest)
  {
    if (!aDest) {
      aDest = new Float32Array(16);
    }
    let eyex = aEye[0];
    let eyey = aEye[1];
    let eyez = aEye[2];
    let upx = aUp[0];
    let upy = aUp[1];
    let upz = aUp[2];
    let centerx = aCenter[0];
    let centery = aCenter[1];
    let centerz = aCenter[2];
    let z0 = eyex - aCenter[0];
    let z1 = eyey - aCenter[1];
    let z2 = eyez - aCenter[2];
    let len = 1 / (Math.sqrt(z0 * z0 + z1 * z1 + z2 * z2) || EPSILON);
    z0 *= len;
    z1 *= len;
    z2 *= len;
    let x0 = upy * z2 - upz * z1;
    let x1 = upz * z0 - upx * z2;
    let x2 = upx * z1 - upy * z0;
    len = 1 / (Math.sqrt(x0 * x0 + x1 * x1 + x2 * x2) || EPSILON);
    x0 *= len;
    x1 *= len;
    x2 *= len;
    let y0 = z1 * x2 - z2 * x1;
    let y1 = z2 * x0 - z0 * x2;
    let y2 = z0 * x1 - z1 * x0;
    len = 1 / (Math.sqrt(y0 * y0 + y1 * y1 + y2 * y2) || EPSILON);
    y0 *= len;
    y1 *= len;
    y2 *= len;
    aDest[0] = x0;
    aDest[1] = y0;
    aDest[2] = z0;
    aDest[3] = 0;
    aDest[4] = x1;
    aDest[5] = y1;
    aDest[6] = z1;
    aDest[7] = 0;
    aDest[8] = x2;
    aDest[9] = y2;
    aDest[10] = z2;
    aDest[11] = 0;
    aDest[12] = -(x0 * eyex + x1 * eyey + x2 * eyez);
    aDest[13] = -(y0 * eyex + y1 * eyey + y2 * eyez);
    aDest[14] = -(z0 * eyex + z1 * eyey + z2 * eyez);
    aDest[15] = 1;
    return aDest;
  }
function M4_lookAt ( aEye , aCenter , aUp , aDest ) { if ( ! aDest ) { aDest = new Float32Array ( 16 ) ; } let eyex = aEye [ 0 ] ; let eyey = aEye [ 1 ] ; let eyez = aEye [ 2 ] ; let upx = aUp [ 0 ] ; let upy = aUp [ 1 ] ; let upz = aUp [ 2 ] ; let centerx = aCenter [ 0 ] ; let centery = aCenter [ 1 ] ; let centerz = aCenter [ 2 ] ; let z0 = eyex - aCenter [ 0 ] ; let z1 = eyey - aCenter [ 1 ] ; let z2 = eyez - aCenter [ 2 ] ; let len = 1 / ( Math . sqrt ( z0 * z0 + z1 * z1 + z2 * z2 ) || EPSILON ) ; z0 *= len ; z1 *= len ; z2 *= len ; let x0 = upy * z2 - upz * z1 ; let x1 = upz * z0 - upx * z2 ; let x2 = upx * z1 - upy * z0 ; len = 1 / ( Math . sqrt ( x0 * x0 + x1 * x1 + x2 * x2 ) || EPSILON ) ; x0 *= len ; x1 *= len ; x2 *= len ; let y0 = z1 * x2 - z2 * x1 ; let y1 = z2 * x0 - z0 * x2 ; let y2 = z0 * x1 - z1 * x0 ; len = 1 / ( Math . sqrt ( y0 * y0 + y1 * y1 + y2 * y2 ) || EPSILON ) ; y0 *= len ; y1 *= len ; y2 *= len ; aDest [ 0 ] = x0 ; aDest [ 1 ] = y0 ; aDest [ 2 ] = z0 ; aDest [ 3 ] = 0 ; aDest [ 4 ] = x1 ; aDest [ 5 ] = y1 ; aDest [ 6 ] = z1 ; aDest [ 7 ] = 0 ; aDest [ 8 ] = x2 ; aDest [ 9 ] = y2 ; aDest [ 10 ] = z2 ; aDest [ 11 ] = 0 ; aDest [ 12 ] = - ( x0 * eyex + x1 * eyey + x2 * eyez ) ; aDest [ 13 ] = - ( y0 * eyex + y1 * eyey + y2 * eyez ) ; aDest [ 14 ] = - ( z0 * eyex + z1 * eyey + z2 * eyez ) ; aDest [ 15 ] = 1 ; return aDest ; }
Generates a look-at matrix with the given eye position, focal point, and
 up axis.
Generates a look - at matrix with the given eye position focal point and up axis .