B2G/gecko/browser/devtools/tilt/TiltMath.jsm
/**
   * Unprojects a 2D point to 3D space.
   *
   * @param {Array} aP
   *                the [x, y, z] coordinates of the point to unproject;
   *                the z value should range between 0 and 1, as clipping plane
   * @param {Array} aViewport
   *                the viewport [x, y, width, height] coordinates
   * @param {Array} aMvMatrix
   *                the model view matrix
   * @param {Array} aProjMatrix
   *                the projection matrix
   * @param {Array} aDest
   *                optional parameter, the array to write the values to
   *
   * @return {Array} the unprojected coordinates
   */
Unprojects a 2D point to 3D space.

@return {Array} the unprojected coordinates
Unprojects a 2D point to 3D space . @return { Array } the unprojected coordinates
function V3_unproject(
    aP, aViewport, aMvMatrix, aProjMatrix, aDest)
  {
    let mvpMatrix = new Float32Array(16);
    let coordinates = new Float32Array(4);
    mat4.multiply(aProjMatrix, aMvMatrix, mvpMatrix);
    mat4.inverse(mvpMatrix);
    coordinates[0] = +((aP[0] - aViewport[0]) / aViewport[2] * 2 - 1);
    coordinates[1] = -((aP[1] - aViewport[1]) / aViewport[3] * 2 - 1);
    coordinates[2] = 2 * aP[2] - 1;
    coordinates[3] = 1;
    mat4.multiplyVec4(mvpMatrix, coordinates);
    coordinates[3] = 1 / coordinates[3];
    coordinates[0] *= coordinates[3];
    coordinates[1] *= coordinates[3];
    coordinates[2] *= coordinates[3];
    if (!aDest) {
      vec3.set(coordinates, aP);
    } else {
      vec3.set(coordinates, aDest);
    }
    return coordinates;
  }
function V3_unproject ( aP , aViewport , aMvMatrix , aProjMatrix , aDest ) { let mvpMatrix = new Float32Array ( 16 ) ; let coordinates = new Float32Array ( 4 ) ; mat4 . multiply ( aProjMatrix , aMvMatrix , mvpMatrix ) ; mat4 . inverse ( mvpMatrix ) ; coordinates [ 0 ] = + ( ( aP [ 0 ] - aViewport [ 0 ] ) / aViewport [ 2 ] * 2 - 1 ) ; coordinates [ 1 ] = - ( ( aP [ 1 ] - aViewport [ 1 ] ) / aViewport [ 3 ] * 2 - 1 ) ; coordinates [ 2 ] = 2 * aP [ 2 ] - 1 ; coordinates [ 3 ] = 1 ; mat4 . multiplyVec4 ( mvpMatrix , coordinates ) ; coordinates [ 3 ] = 1 / coordinates [ 3 ] ; coordinates [ 0 ] *= coordinates [ 3 ] ; coordinates [ 1 ] *= coordinates [ 3 ] ; coordinates [ 2 ] *= coordinates [ 3 ] ; if ( ! aDest ) { vec3 . set ( coordinates , aP ) ; } else { vec3 . set ( coordinates , aDest ) ; } return coordinates ; }
Unprojects a 2D point to 3D space.
Unprojects a 2D point to 3D space .
/*jshint undef: false */ // compute the inverse of the perspective * model view matrix // transformation of normalized coordinates (-1 to 1) // now transform that vector into space coordinates // invert to normalize x, y, and z values