From: Joe Wreschnig Date: Sat, 18 Apr 2015 18:12:48 +0000 (+0200) Subject: glMatrix 2.2.2. X-Git-Url: https://git.yukkurigames.com/?a=commitdiff_plain;h=9ceff62f76f5ae2049cac00465d7756b0bc3cb9b;p=pwl6.git glMatrix 2.2.2. --- diff --git a/src/ext/gl-matrix.js b/src/ext/gl-matrix.js index 3965a55..5f7d811 100644 --- a/src/ext/gl-matrix.js +++ b/src/ext/gl-matrix.js @@ -2,7 +2,7 @@ * @fileoverview gl-matrix - High performance matrix and vector operations * @author Brandon Jones * @author Colin MacKenzie IV - * @version 2.2.1 + * @version 2.2.2 */ /* Copyright (c) 2013, Brandon Jones, Colin MacKenzie IV. All rights reserved. @@ -91,7 +91,7 @@ if(!GLMAT_RANDOM) { var glMatrix = {}; /** - * Sets the type of array used when creating new vectors and matricies + * Sets the type of array used when creating new vectors and matrices * * @param {Type} type Array type, such as Float32Array or Array */ @@ -427,6 +427,19 @@ vec2.negate = function(out, a) { return out; }; +/** + * Returns the inverse of the components of a vec2 + * + * @param {vec2} out the receiving vector + * @param {vec2} a vector to invert + * @returns {vec2} out + */ +vec2.inverse = function(out, a) { + out[0] = 1.0 / a[0]; + out[1] = 1.0 / a[1]; + return out; +}; + /** * Normalize a vec2 * @@ -961,6 +974,20 @@ vec3.negate = function(out, a) { return out; }; +/** + * Returns the inverse of the components of a vec3 + * + * @param {vec3} out the receiving vector + * @param {vec3} a vector to invert + * @returns {vec3} out + */ +vec3.inverse = function(out, a) { + out[0] = 1.0 / a[0]; + out[1] = 1.0 / a[1]; + out[2] = 1.0 / a[2]; + return out; +}; + /** * Normalize a vec3 * @@ -1061,10 +1088,12 @@ vec3.random = function (out, scale) { * @returns {vec3} out */ vec3.transformMat4 = function(out, a, m) { - var x = a[0], y = a[1], z = a[2]; - out[0] = m[0] * x + m[4] * y + m[8] * z + m[12]; - out[1] = m[1] * x + m[5] * y + m[9] * z + m[13]; - out[2] = m[2] * x + m[6] * y + m[10] * z + m[14]; + var x = a[0], y = a[1], z = a[2], + w = m[3] * x + m[7] * y + m[11] * z + m[15]; + w = w || 1.0; + out[0] = (m[0] * x + m[4] * y + m[8] * z + m[12]) / w; + out[1] = (m[1] * x + m[5] * y + m[9] * z + m[13]) / w; + out[2] = (m[2] * x + m[6] * y + m[10] * z + m[14]) / w; return out; }; @@ -1111,14 +1140,14 @@ vec3.transformQuat = function(out, a, q) { return out; }; -/* -* Rotate a 3D vector around the x-axis -* @param {vec3} out The receiving vec3 -* @param {vec3} a The vec3 point to rotate -* @param {vec3} b The origin of the rotation -* @param {Number} c The angle of rotation -* @returns {vec3} out -*/ +/** + * Rotate a 3D vector around the x-axis + * @param {vec3} out The receiving vec3 + * @param {vec3} a The vec3 point to rotate + * @param {vec3} b The origin of the rotation + * @param {Number} c The angle of rotation + * @returns {vec3} out + */ vec3.rotateX = function(out, a, b, c){ var p = [], r=[]; //Translate point to the origin @@ -1139,14 +1168,14 @@ vec3.rotateX = function(out, a, b, c){ return out; }; -/* -* Rotate a 3D vector around the y-axis -* @param {vec3} out The receiving vec3 -* @param {vec3} a The vec3 point to rotate -* @param {vec3} b The origin of the rotation -* @param {Number} c The angle of rotation -* @returns {vec3} out -*/ +/** + * Rotate a 3D vector around the y-axis + * @param {vec3} out The receiving vec3 + * @param {vec3} a The vec3 point to rotate + * @param {vec3} b The origin of the rotation + * @param {Number} c The angle of rotation + * @returns {vec3} out + */ vec3.rotateY = function(out, a, b, c){ var p = [], r=[]; //Translate point to the origin @@ -1167,14 +1196,14 @@ vec3.rotateY = function(out, a, b, c){ return out; }; -/* -* Rotate a 3D vector around the z-axis -* @param {vec3} out The receiving vec3 -* @param {vec3} a The vec3 point to rotate -* @param {vec3} b The origin of the rotation -* @param {Number} c The angle of rotation -* @returns {vec3} out -*/ +/** + * Rotate a 3D vector around the z-axis + * @param {vec3} out The receiving vec3 + * @param {vec3} a The vec3 point to rotate + * @param {vec3} b The origin of the rotation + * @param {Number} c The angle of rotation + * @returns {vec3} out + */ vec3.rotateZ = function(out, a, b, c){ var p = [], r=[]; //Translate point to the origin @@ -1236,6 +1265,29 @@ vec3.forEach = (function() { }; })(); +/** + * Get the angle between two 3D vectors + * @param {vec3} a The first operand + * @param {vec3} b The second operand + * @returns {Number} The angle in radians + */ +vec3.angle = function(a, b) { + + var tempA = vec3.fromValues(a[0], a[1], a[2]); + var tempB = vec3.fromValues(b[0], b[1], b[2]); + + vec3.normalize(tempA, tempA); + vec3.normalize(tempB, tempB); + + var cosine = vec3.dot(tempA, tempB); + + if(cosine > 1.0){ + return 0; + } else { + return Math.acos(cosine); + } +}; + /** * Returns a string representation of a vector * @@ -1603,6 +1655,21 @@ vec4.negate = function(out, a) { return out; }; +/** + * Returns the inverse of the components of a vec4 + * + * @param {vec4} out the receiving vector + * @param {vec4} a vector to invert + * @returns {vec4} out + */ +vec4.inverse = function(out, a) { + out[0] = 1.0 / a[0]; + out[1] = 1.0 / a[1]; + out[2] = 1.0 / a[2]; + out[3] = 1.0 / a[3]; + return out; +}; + /** * Normalize a vec4 * @@ -1726,7 +1793,7 @@ vec4.transformQuat = function(out, a, q) { * @param {Array} a the array of vectors to iterate over * @param {Number} stride Number of elements between the start of each vec4. If 0 assumes tightly packed * @param {Number} offset Number of elements to skip at the beginning of the array - * @param {Number} count Number of vec2s to iterate over. If 0 iterates over entire array + * @param {Number} count Number of vec4s to iterate over. If 0 iterates over entire array * @param {Function} fn Function to call for each vector in the array * @param {Object} [arg] additional argument to pass to fn * @returns {Array} a @@ -3693,7 +3760,7 @@ mat4.str = function (a) { * @returns {Number} Frobenius norm */ mat4.frob = function (a) { - return(Math.sqrt(Math.pow(a[0], 2) + Math.pow(a[1], 2) + Math.pow(a[2], 2) + Math.pow(a[3], 2) + Math.pow(a[4], 2) + Math.pow(a[5], 2) + Math.pow(a[6], 2) + Math.pow(a[6], 2) + Math.pow(a[7], 2) + Math.pow(a[8], 2) + Math.pow(a[9], 2) + Math.pow(a[10], 2) + Math.pow(a[11], 2) + Math.pow(a[12], 2) + Math.pow(a[13], 2) + Math.pow(a[14], 2) + Math.pow(a[15], 2) )) + return(Math.sqrt(Math.pow(a[0], 2) + Math.pow(a[1], 2) + Math.pow(a[2], 2) + Math.pow(a[3], 2) + Math.pow(a[4], 2) + Math.pow(a[5], 2) + Math.pow(a[6], 2) + Math.pow(a[7], 2) + Math.pow(a[8], 2) + Math.pow(a[9], 2) + Math.pow(a[10], 2) + Math.pow(a[11], 2) + Math.pow(a[12], 2) + Math.pow(a[13], 2) + Math.pow(a[14], 2) + Math.pow(a[15], 2) )) }; @@ -4018,7 +4085,7 @@ quat.calculateW = function (out, a) { out[0] = x; out[1] = y; out[2] = z; - out[3] = -Math.sqrt(Math.abs(1.0 - x * x - y * y - z * z)); + out[3] = Math.sqrt(Math.abs(1.0 - x * x - y * y - z * z)); return out; }; @@ -4193,9 +4260,9 @@ quat.fromMat3 = function(out, m) { fRoot = Math.sqrt(fTrace + 1.0); // 2w out[3] = 0.5 * fRoot; fRoot = 0.5/fRoot; // 1/(4w) - out[0] = (m[7]-m[5])*fRoot; - out[1] = (m[2]-m[6])*fRoot; - out[2] = (m[3]-m[1])*fRoot; + out[0] = (m[5]-m[7])*fRoot; + out[1] = (m[6]-m[2])*fRoot; + out[2] = (m[1]-m[3])*fRoot; } else { // |w| <= 1/2 var i = 0; @@ -4209,7 +4276,7 @@ quat.fromMat3 = function(out, m) { fRoot = Math.sqrt(m[i*3+i]-m[j*3+j]-m[k*3+k] + 1.0); out[i] = 0.5 * fRoot; fRoot = 0.5 / fRoot; - out[3] = (m[k*3+j] - m[j*3+k]) * fRoot; + out[3] = (m[j*3+k] - m[k*3+j]) * fRoot; out[j] = (m[j*3+i] + m[i*3+j]) * fRoot; out[k] = (m[k*3+i] + m[i*3+k]) * fRoot; }