B2G/gecko/browser/devtools/tilt/TiltMath.jsm
/**
   * Rotates a matrix by the given angle around the specified axis.
   * If rotating around a primary axis (x, y, z) one of the specialized
   * rotation functions should be used instead for performance,
   *
   * @param {Array} aMat
   *                mat4 to rotate
   * @param {Number} aAngle
   *                 the angle (in radians) to rotate
   * @param {Array} aAxis
   *                vec3 representing the axis to rotate around
   * @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
   */
Rotates a matrix by the given angle around the specified axis.
If rotating around a primary axis (x, y, z) one of the specialized
rotation functions should be used instead for performance.

@param {Array} aMat
mat4 to rotate
@param {Number} aAngle
the angle (in radians) to rotate
@param {Array} aAxis
vec3 representing the axis to rotate around
@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
Rotates a matrix by the given angle around the specified axis . If rotating around a primary axis ( x y z ) one of the specialized rotation functions should be used instead for performance . @param { Array } aMat mat4 to rotate @param { Number } aAngle the angle ( in radians ) to rotate @param { Array } aAxis vec3 representing the axis to rotate around @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_rotate(aMat, aAngle, aAxis, aDest)
  {
    let x = aAxis[0];
    let y = aAxis[1];
    let z = aAxis[2];
    let len = 1 / (Math.sqrt(x * x + y * y + z * z) || EPSILON);
    x *= len;
    y *= len;
    z *= len;
    let s = Math.sin(aAngle);
    let c = Math.cos(aAngle);
    let t = 1 - c;
    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 b00 = x * x * t + c, b01 = y * x * t + z * s, b02 = z * x * t - y * s;
    let b10 = x * y * t - z * s, b11 = y * y * t + c, b12 = z * y * t + x * s;
    let b20 = x * z * t + y * s, b21 = y * z * t - x * s, b22 = z * z * t + c;
    if (!aDest) {
      aDest = aMat;
    } else if (aMat !== aDest) {
      aDest[12] = aMat[12];
      aDest[13] = aMat[13];
      aDest[14] = aMat[14];
      aDest[15] = aMat[15];
    }
    aDest[0] = a00 * b00 + a10 * b01 + a20 * b02;
    aDest[1] = a01 * b00 + a11 * b01 + a21 * b02;
    aDest[2] = a02 * b00 + a12 * b01 + a22 * b02;
    aDest[3] = a03 * b00 + a13 * b01 + a23 * b02;
    aDest[4] = a00 * b10 + a10 * b11 + a20 * b12;
    aDest[5] = a01 * b10 + a11 * b11 + a21 * b12;
    aDest[6] = a02 * b10 + a12 * b11 + a22 * b12;
    aDest[7] = a03 * b10 + a13 * b11 + a23 * b12;
    aDest[8] = a00 * b20 + a10 * b21 + a20 * b22;
    aDest[9] = a01 * b20 + a11 * b21 + a21 * b22;
    aDest[10] = a02 * b20 + a12 * b21 + a22 * b22;
    aDest[11] = a03 * b20 + a13 * b21 + a23 * b22;
    return aDest;
  }
function M4_rotate ( aMat , aAngle , aAxis , aDest ) { let x = aAxis [ 0 ] ; let y = aAxis [ 1 ] ; let z = aAxis [ 2 ] ; let len = 1 / ( Math . sqrt ( x * x + y * y + z * z ) || EPSILON ) ; x *= len ; y *= len ; z *= len ; let s = Math . sin ( aAngle ) ; let c = Math . cos ( aAngle ) ; let t = 1 - c ; 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 b00 = x * x * t + c , b01 = y * x * t + z * s , b02 = z * x * t - y * s ; let b10 = x * y * t - z * s , b11 = y * y * t + c , b12 = z * y * t + x * s ; let b20 = x * z * t + y * s , b21 = y * z * t - x * s , b22 = z * z * t + c ; if ( ! aDest ) { aDest = aMat ; } else if ( aMat !== aDest ) { aDest [ 12 ] = aMat [ 12 ] ; aDest [ 13 ] = aMat [ 13 ] ; aDest [ 14 ] = aMat [ 14 ] ; aDest [ 15 ] = aMat [ 15 ] ; } aDest [ 0 ] = a00 * b00 + a10 * b01 + a20 * b02 ; aDest [ 1 ] = a01 * b00 + a11 * b01 + a21 * b02 ; aDest [ 2 ] = a02 * b00 + a12 * b01 + a22 * b02 ; aDest [ 3 ] = a03 * b00 + a13 * b01 + a23 * b02 ; aDest [ 4 ] = a00 * b10 + a10 * b11 + a20 * b12 ; aDest [ 5 ] = a01 * b10 + a11 * b11 + a21 * b12 ; aDest [ 6 ] = a02 * b10 + a12 * b11 + a22 * b12 ; aDest [ 7 ] = a03 * b10 + a13 * b11 + a23 * b12 ; aDest [ 8 ] = a00 * b20 + a10 * b21 + a20 * b22 ; aDest [ 9 ] = a01 * b20 + a11 * b21 + a21 * b22 ; aDest [ 10 ] = a02 * b20 + a12 * b21 + a22 * b22 ; aDest [ 11 ] = a03 * b20 + a13 * b21 + a23 * b22 ; return aDest ; }
Rotates a matrix by the given angle around the specified axis.
Rotates a matrix by the given angle around the specified axis .