B2G/gecko/browser/devtools/tilt/TiltMath.jsm
/**
   * Projects a 3D point on a 2D screen plane.
   *
   * @param {Array} aP
   *                the [x, y, z] coordinates of the point to project
   * @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 projected coordinates
   */
Projects a 3D point on a 2D screen plane.

@return {Array} the projected coordinates
Projects a 3D point on a 2D screen plane . @return { Array } the projected coordinates
function V3_project(aP, aViewport, aMvMatrix, aProjMatrix, aDest)
  {
    let mvpMatrix = new Float32Array(16);
    let coordinates = new Float32Array(4);
    mat4.multiply(aProjMatrix, aMvMatrix, mvpMatrix);
    coordinates[0] = aP[0];
    coordinates[1] = aP[1];
    coordinates[2] = aP[2];
    coordinates[3] = 1;
    mat4.multiplyVec4(mvpMatrix, coordinates);
    coordinates[0] /= coordinates[3];
    coordinates[0] *= aViewport[2] * 0.5;
    coordinates[0] += aViewport[2] * 0.5;
    coordinates[1] /= coordinates[3];
    coordinates[1] *= -aViewport[3] * 0.5;
    coordinates[1] += aViewport[3] * 0.5;
    coordinates[2] = 0;
    if (!aDest) {
      vec3.set(coordinates, aP);
    } else {
      vec3.set(coordinates, aDest);
    }
    return coordinates;
  }
function V3_project ( aP , aViewport , aMvMatrix , aProjMatrix , aDest ) { let mvpMatrix = new Float32Array ( 16 ) ; let coordinates = new Float32Array ( 4 ) ; mat4 . multiply ( aProjMatrix , aMvMatrix , mvpMatrix ) ; coordinates [ 0 ] = aP [ 0 ] ; coordinates [ 1 ] = aP [ 1 ] ; coordinates [ 2 ] = aP [ 2 ] ; coordinates [ 3 ] = 1 ; mat4 . multiplyVec4 ( mvpMatrix , coordinates ) ; coordinates [ 0 ] /= coordinates [ 3 ] ; coordinates [ 0 ] *= aViewport [ 2 ] * 0.5 ; coordinates [ 0 ] += aViewport [ 2 ] * 0.5 ; coordinates [ 1 ] /= coordinates [ 3 ] ; coordinates [ 1 ] *= - aViewport [ 3 ] * 0.5 ; coordinates [ 1 ] += aViewport [ 3 ] * 0.5 ; coordinates [ 2 ] = 0 ; if ( ! aDest ) { vec3 . set ( coordinates , aP ) ; } else { vec3 . set ( coordinates , aDest ) ; } return coordinates ; }
Projects a 3D point on a 2D screen plane.
Projects a 3D point on a 2D screen plane .
/*jshint undef: false */ // compute the perspective * model view matrix // now transform that vector into homogenous coordinates // transform the homogenous coordinates into screen space