diff --git a/README.md b/README.md index e7b83c4..bdf59bd 100644 Binary files a/README.md and b/README.md differ diff --git a/client/public/gl-matrix.js b/client/public/gl-matrix.js new file mode 100644 index 0000000..6ef3575 --- /dev/null +++ b/client/public/gl-matrix.js @@ -0,0 +1,6609 @@ +/** + * @fileoverview gl-matrix - High performance matrix and vector operations + * @author Brandon Jones + * @author Colin MacKenzie IV + * @version 2.3.2 + */ + +/* Copyright (c) 2015, Brandon Jones, Colin MacKenzie IV. + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. */ + +(function webpackUniversalModuleDefinition(root, factory) { + if(typeof exports === 'object' && typeof module === 'object') + module.exports = factory(); + else if(typeof define === 'function' && define.amd) + define([], factory); + else { + var a = factory(); + for(var i in a) (typeof exports === 'object' ? exports : root)[i] = a[i]; + } +})(this, function() { +return /******/ (function(modules) { // webpackBootstrap +/******/ // The module cache +/******/ var installedModules = {}; + +/******/ // The require function +/******/ function __webpack_require__(moduleId) { + +/******/ // Check if module is in cache +/******/ if(installedModules[moduleId]) +/******/ return installedModules[moduleId].exports; + +/******/ // Create a new module (and put it into the cache) +/******/ var module = installedModules[moduleId] = { +/******/ exports: {}, +/******/ id: moduleId, +/******/ loaded: false +/******/ }; + +/******/ // Execute the module function +/******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__); + +/******/ // Flag the module as loaded +/******/ module.loaded = true; + +/******/ // Return the exports of the module +/******/ return module.exports; +/******/ } + + +/******/ // expose the modules object (__webpack_modules__) +/******/ __webpack_require__.m = modules; + +/******/ // expose the module cache +/******/ __webpack_require__.c = installedModules; + +/******/ // __webpack_public_path__ +/******/ __webpack_require__.p = ""; + +/******/ // Load entry module and return exports +/******/ return __webpack_require__(0); +/******/ }) +/************************************************************************/ +/******/ ([ +/* 0 */ +/***/ function(module, exports, __webpack_require__) { + + /** + * @fileoverview gl-matrix - High performance matrix and vector operations + * @author Brandon Jones + * @author Colin MacKenzie IV + * @version 2.3.2 + */ + + /* Copyright (c) 2015, Brandon Jones, Colin MacKenzie IV. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. */ + // END HEADER + + exports.glMatrix = __webpack_require__(1); + exports.mat2 = __webpack_require__(2); + exports.mat2d = __webpack_require__(3); + exports.mat3 = __webpack_require__(4); + exports.mat4 = __webpack_require__(5); + exports.quat = __webpack_require__(6); + exports.vec2 = __webpack_require__(9); + exports.vec3 = __webpack_require__(7); + exports.vec4 = __webpack_require__(8); + +/***/ }, +/* 1 */ +/***/ function(module, exports) { + + /* Copyright (c) 2015, Brandon Jones, Colin MacKenzie IV. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. */ + + /** + * @class Common utilities + * @name glMatrix + */ + var glMatrix = {}; + + // Configuration Constants + glMatrix.EPSILON = 0.000001; + glMatrix.ARRAY_TYPE = (typeof Float32Array !== 'undefined') ? Float32Array : Array; + glMatrix.RANDOM = Math.random; + glMatrix.ENABLE_SIMD = false; + + // Capability detection + glMatrix.SIMD_AVAILABLE = (glMatrix.ARRAY_TYPE === this.Float32Array) && ('SIMD' in this); + glMatrix.USE_SIMD = glMatrix.ENABLE_SIMD && glMatrix.SIMD_AVAILABLE; + + /** + * Sets the type of array used when creating new vectors and matrices + * + * @param {Type} type Array type, such as Float32Array or Array + */ + glMatrix.setMatrixArrayType = function(type) { + glMatrix.ARRAY_TYPE = type; + } + + var degree = Math.PI / 180; + + /** + * Convert Degree To Radian + * + * @param {Number} a Angle in Degrees + */ + glMatrix.toRadian = function(a){ + return a * degree; + } + + /** + * Tests whether or not the arguments have approximately the same value, within an absolute + * or relative tolerance of glMatrix.EPSILON (an absolute tolerance is used for values less + * than or equal to 1.0, and a relative tolerance is used for larger values) + * + * @param {Number} a The first number to test. + * @param {Number} b The second number to test. + * @returns {Boolean} True if the numbers are approximately equal, false otherwise. + */ + glMatrix.equals = function(a, b) { + return Math.abs(a - b) <= glMatrix.EPSILON*Math.max(1.0, Math.abs(a), Math.abs(b)); + } + + module.exports = glMatrix; + + +/***/ }, +/* 2 */ +/***/ function(module, exports, __webpack_require__) { + + /* Copyright (c) 2015, Brandon Jones, Colin MacKenzie IV. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. */ + + var glMatrix = __webpack_require__(1); + + /** + * @class 2x2 Matrix + * @name mat2 + */ + var mat2 = {}; + + /** + * Creates a new identity mat2 + * + * @returns {mat2} a new 2x2 matrix + */ + mat2.create = function() { + var out = new glMatrix.ARRAY_TYPE(4); + out[0] = 1; + out[1] = 0; + out[2] = 0; + out[3] = 1; + return out; + }; + + /** + * Creates a new mat2 initialized with values from an existing matrix + * + * @param {mat2} a matrix to clone + * @returns {mat2} a new 2x2 matrix + */ + mat2.clone = function(a) { + var out = new glMatrix.ARRAY_TYPE(4); + out[0] = a[0]; + out[1] = a[1]; + out[2] = a[2]; + out[3] = a[3]; + return out; + }; + + /** + * Copy the values from one mat2 to another + * + * @param {mat2} out the receiving matrix + * @param {mat2} a the source matrix + * @returns {mat2} out + */ + mat2.copy = function(out, a) { + out[0] = a[0]; + out[1] = a[1]; + out[2] = a[2]; + out[3] = a[3]; + return out; + }; + + /** + * Set a mat2 to the identity matrix + * + * @param {mat2} out the receiving matrix + * @returns {mat2} out + */ + mat2.identity = function(out) { + out[0] = 1; + out[1] = 0; + out[2] = 0; + out[3] = 1; + return out; + }; + + /** + * Create a new mat2 with the given values + * + * @param {Number} m00 Component in column 0, row 0 position (index 0) + * @param {Number} m01 Component in column 0, row 1 position (index 1) + * @param {Number} m10 Component in column 1, row 0 position (index 2) + * @param {Number} m11 Component in column 1, row 1 position (index 3) + * @returns {mat2} out A new 2x2 matrix + */ + mat2.fromValues = function(m00, m01, m10, m11) { + var out = new glMatrix.ARRAY_TYPE(4); + out[0] = m00; + out[1] = m01; + out[2] = m10; + out[3] = m11; + return out; + }; + + /** + * Set the components of a mat2 to the given values + * + * @param {mat2} out the receiving matrix + * @param {Number} m00 Component in column 0, row 0 position (index 0) + * @param {Number} m01 Component in column 0, row 1 position (index 1) + * @param {Number} m10 Component in column 1, row 0 position (index 2) + * @param {Number} m11 Component in column 1, row 1 position (index 3) + * @returns {mat2} out + */ + mat2.set = function(out, m00, m01, m10, m11) { + out[0] = m00; + out[1] = m01; + out[2] = m10; + out[3] = m11; + return out; + }; + + + /** + * Transpose the values of a mat2 + * + * @param {mat2} out the receiving matrix + * @param {mat2} a the source matrix + * @returns {mat2} out + */ + mat2.transpose = function(out, a) { + // If we are transposing ourselves we can skip a few steps but have to cache some values + if (out === a) { + var a1 = a[1]; + out[1] = a[2]; + out[2] = a1; + } else { + out[0] = a[0]; + out[1] = a[2]; + out[2] = a[1]; + out[3] = a[3]; + } + + return out; + }; + + /** + * Inverts a mat2 + * + * @param {mat2} out the receiving matrix + * @param {mat2} a the source matrix + * @returns {mat2} out + */ + mat2.invert = function(out, a) { + var a0 = a[0], a1 = a[1], a2 = a[2], a3 = a[3], + + // Calculate the determinant + det = a0 * a3 - a2 * a1; + + if (!det) { + return null; + } + det = 1.0 / det; + + out[0] = a3 * det; + out[1] = -a1 * det; + out[2] = -a2 * det; + out[3] = a0 * det; + + return out; + }; + + /** + * Calculates the adjugate of a mat2 + * + * @param {mat2} out the receiving matrix + * @param {mat2} a the source matrix + * @returns {mat2} out + */ + mat2.adjoint = function(out, a) { + // Caching this value is nessecary if out == a + var a0 = a[0]; + out[0] = a[3]; + out[1] = -a[1]; + out[2] = -a[2]; + out[3] = a0; + + return out; + }; + + /** + * Calculates the determinant of a mat2 + * + * @param {mat2} a the source matrix + * @returns {Number} determinant of a + */ + mat2.determinant = function (a) { + return a[0] * a[3] - a[2] * a[1]; + }; + + /** + * Multiplies two mat2's + * + * @param {mat2} out the receiving matrix + * @param {mat2} a the first operand + * @param {mat2} b the second operand + * @returns {mat2} out + */ + mat2.multiply = function (out, a, b) { + var a0 = a[0], a1 = a[1], a2 = a[2], a3 = a[3]; + var b0 = b[0], b1 = b[1], b2 = b[2], b3 = b[3]; + out[0] = a0 * b0 + a2 * b1; + out[1] = a1 * b0 + a3 * b1; + out[2] = a0 * b2 + a2 * b3; + out[3] = a1 * b2 + a3 * b3; + return out; + }; + + /** + * Alias for {@link mat2.multiply} + * @function + */ + mat2.mul = mat2.multiply; + + /** + * Rotates a mat2 by the given angle + * + * @param {mat2} out the receiving matrix + * @param {mat2} a the matrix to rotate + * @param {Number} rad the angle to rotate the matrix by + * @returns {mat2} out + */ + mat2.rotate = function (out, a, rad) { + var a0 = a[0], a1 = a[1], a2 = a[2], a3 = a[3], + s = Math.sin(rad), + c = Math.cos(rad); + out[0] = a0 * c + a2 * s; + out[1] = a1 * c + a3 * s; + out[2] = a0 * -s + a2 * c; + out[3] = a1 * -s + a3 * c; + return out; + }; + + /** + * Scales the mat2 by the dimensions in the given vec2 + * + * @param {mat2} out the receiving matrix + * @param {mat2} a the matrix to rotate + * @param {vec2} v the vec2 to scale the matrix by + * @returns {mat2} out + **/ + mat2.scale = function(out, a, v) { + var a0 = a[0], a1 = a[1], a2 = a[2], a3 = a[3], + v0 = v[0], v1 = v[1]; + out[0] = a0 * v0; + out[1] = a1 * v0; + out[2] = a2 * v1; + out[3] = a3 * v1; + return out; + }; + + /** + * Creates a matrix from a given angle + * This is equivalent to (but much faster than): + * + * mat2.identity(dest); + * mat2.rotate(dest, dest, rad); + * + * @param {mat2} out mat2 receiving operation result + * @param {Number} rad the angle to rotate the matrix by + * @returns {mat2} out + */ + mat2.fromRotation = function(out, rad) { + var s = Math.sin(rad), + c = Math.cos(rad); + out[0] = c; + out[1] = s; + out[2] = -s; + out[3] = c; + return out; + } + + /** + * Creates a matrix from a vector scaling + * This is equivalent to (but much faster than): + * + * mat2.identity(dest); + * mat2.scale(dest, dest, vec); + * + * @param {mat2} out mat2 receiving operation result + * @param {vec2} v Scaling vector + * @returns {mat2} out + */ + mat2.fromScaling = function(out, v) { + out[0] = v[0]; + out[1] = 0; + out[2] = 0; + out[3] = v[1]; + return out; + } + + /** + * Returns a string representation of a mat2 + * + * @param {mat2} a matrix to represent as a string + * @returns {String} string representation of the matrix + */ + mat2.str = function (a) { + return 'mat2(' + a[0] + ', ' + a[1] + ', ' + a[2] + ', ' + a[3] + ')'; + }; + + /** + * Returns Frobenius norm of a mat2 + * + * @param {mat2} a the matrix to calculate Frobenius norm of + * @returns {Number} Frobenius norm + */ + mat2.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))) + }; + + /** + * Returns L, D and U matrices (Lower triangular, Diagonal and Upper triangular) by factorizing the input matrix + * @param {mat2} L the lower triangular matrix + * @param {mat2} D the diagonal matrix + * @param {mat2} U the upper triangular matrix + * @param {mat2} a the input matrix to factorize + */ + + mat2.LDU = function (L, D, U, a) { + L[2] = a[2]/a[0]; + U[0] = a[0]; + U[1] = a[1]; + U[3] = a[3] - L[2] * U[1]; + return [L, D, U]; + }; + + /** + * Adds two mat2's + * + * @param {mat2} out the receiving matrix + * @param {mat2} a the first operand + * @param {mat2} b the second operand + * @returns {mat2} out + */ + mat2.add = function(out, a, b) { + out[0] = a[0] + b[0]; + out[1] = a[1] + b[1]; + out[2] = a[2] + b[2]; + out[3] = a[3] + b[3]; + return out; + }; + + /** + * Subtracts matrix b from matrix a + * + * @param {mat2} out the receiving matrix + * @param {mat2} a the first operand + * @param {mat2} b the second operand + * @returns {mat2} out + */ + mat2.subtract = function(out, a, b) { + out[0] = a[0] - b[0]; + out[1] = a[1] - b[1]; + out[2] = a[2] - b[2]; + out[3] = a[3] - b[3]; + return out; + }; + + /** + * Alias for {@link mat2.subtract} + * @function + */ + mat2.sub = mat2.subtract; + + /** + * Returns whether or not the matrices have exactly the same elements in the same position (when compared with ===) + * + * @param {mat2} a The first matrix. + * @param {mat2} b The second matrix. + * @returns {Boolean} True if the matrices are equal, false otherwise. + */ + mat2.exactEquals = function (a, b) { + return a[0] === b[0] && a[1] === b[1] && a[2] === b[2] && a[3] === b[3]; + }; + + /** + * Returns whether or not the matrices have approximately the same elements in the same position. + * + * @param {mat2} a The first matrix. + * @param {mat2} b The second matrix. + * @returns {Boolean} True if the matrices are equal, false otherwise. + */ + mat2.equals = function (a, b) { + var a0 = a[0], a1 = a[1], a2 = a[2], a3 = a[3]; + var b0 = b[0], b1 = b[1], b2 = b[2], b3 = b[3]; + return (Math.abs(a0 - b0) <= glMatrix.EPSILON*Math.max(1.0, Math.abs(a0), Math.abs(b0)) && + Math.abs(a1 - b1) <= glMatrix.EPSILON*Math.max(1.0, Math.abs(a1), Math.abs(b1)) && + Math.abs(a2 - b2) <= glMatrix.EPSILON*Math.max(1.0, Math.abs(a2), Math.abs(b2)) && + Math.abs(a3 - b3) <= glMatrix.EPSILON*Math.max(1.0, Math.abs(a3), Math.abs(b3))); + }; + + /** + * Multiply each element of the matrix by a scalar. + * + * @param {mat2} out the receiving matrix + * @param {mat2} a the matrix to scale + * @param {Number} b amount to scale the matrix's elements by + * @returns {mat2} out + */ + mat2.multiplyScalar = function(out, a, b) { + out[0] = a[0] * b; + out[1] = a[1] * b; + out[2] = a[2] * b; + out[3] = a[3] * b; + return out; + }; + + /** + * Adds two mat2's after multiplying each element of the second operand by a scalar value. + * + * @param {mat2} out the receiving vector + * @param {mat2} a the first operand + * @param {mat2} b the second operand + * @param {Number} scale the amount to scale b's elements by before adding + * @returns {mat2} out + */ + mat2.multiplyScalarAndAdd = function(out, a, b, scale) { + out[0] = a[0] + (b[0] * scale); + out[1] = a[1] + (b[1] * scale); + out[2] = a[2] + (b[2] * scale); + out[3] = a[3] + (b[3] * scale); + return out; + }; + + module.exports = mat2; + + +/***/ }, +/* 3 */ +/***/ function(module, exports, __webpack_require__) { + + /* Copyright (c) 2015, Brandon Jones, Colin MacKenzie IV. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. */ + + var glMatrix = __webpack_require__(1); + + /** + * @class 2x3 Matrix + * @name mat2d + * + * @description + * A mat2d contains six elements defined as: + *
+	 * [a, c, tx,
+	 *  b, d, ty]
+	 * 
+ * This is a short form for the 3x3 matrix: + *
+	 * [a, c, tx,
+	 *  b, d, ty,
+	 *  0, 0, 1]
+	 * 
+ * The last row is ignored so the array is shorter and operations are faster. + */ + var mat2d = {}; + + /** + * Creates a new identity mat2d + * + * @returns {mat2d} a new 2x3 matrix + */ + mat2d.create = function() { + var out = new glMatrix.ARRAY_TYPE(6); + out[0] = 1; + out[1] = 0; + out[2] = 0; + out[3] = 1; + out[4] = 0; + out[5] = 0; + return out; + }; + + /** + * Creates a new mat2d initialized with values from an existing matrix + * + * @param {mat2d} a matrix to clone + * @returns {mat2d} a new 2x3 matrix + */ + mat2d.clone = function(a) { + var out = new glMatrix.ARRAY_TYPE(6); + out[0] = a[0]; + out[1] = a[1]; + out[2] = a[2]; + out[3] = a[3]; + out[4] = a[4]; + out[5] = a[5]; + return out; + }; + + /** + * Copy the values from one mat2d to another + * + * @param {mat2d} out the receiving matrix + * @param {mat2d} a the source matrix + * @returns {mat2d} out + */ + mat2d.copy = function(out, a) { + out[0] = a[0]; + out[1] = a[1]; + out[2] = a[2]; + out[3] = a[3]; + out[4] = a[4]; + out[5] = a[5]; + return out; + }; + + /** + * Set a mat2d to the identity matrix + * + * @param {mat2d} out the receiving matrix + * @returns {mat2d} out + */ + mat2d.identity = function(out) { + out[0] = 1; + out[1] = 0; + out[2] = 0; + out[3] = 1; + out[4] = 0; + out[5] = 0; + return out; + }; + + /** + * Create a new mat2d with the given values + * + * @param {Number} a Component A (index 0) + * @param {Number} b Component B (index 1) + * @param {Number} c Component C (index 2) + * @param {Number} d Component D (index 3) + * @param {Number} tx Component TX (index 4) + * @param {Number} ty Component TY (index 5) + * @returns {mat2d} A new mat2d + */ + mat2d.fromValues = function(a, b, c, d, tx, ty) { + var out = new glMatrix.ARRAY_TYPE(6); + out[0] = a; + out[1] = b; + out[2] = c; + out[3] = d; + out[4] = tx; + out[5] = ty; + return out; + }; + + /** + * Set the components of a mat2d to the given values + * + * @param {mat2d} out the receiving matrix + * @param {Number} a Component A (index 0) + * @param {Number} b Component B (index 1) + * @param {Number} c Component C (index 2) + * @param {Number} d Component D (index 3) + * @param {Number} tx Component TX (index 4) + * @param {Number} ty Component TY (index 5) + * @returns {mat2d} out + */ + mat2d.set = function(out, a, b, c, d, tx, ty) { + out[0] = a; + out[1] = b; + out[2] = c; + out[3] = d; + out[4] = tx; + out[5] = ty; + return out; + }; + + /** + * Inverts a mat2d + * + * @param {mat2d} out the receiving matrix + * @param {mat2d} a the source matrix + * @returns {mat2d} out + */ + mat2d.invert = function(out, a) { + var aa = a[0], ab = a[1], ac = a[2], ad = a[3], + atx = a[4], aty = a[5]; + + var det = aa * ad - ab * ac; + if(!det){ + return null; + } + det = 1.0 / det; + + out[0] = ad * det; + out[1] = -ab * det; + out[2] = -ac * det; + out[3] = aa * det; + out[4] = (ac * aty - ad * atx) * det; + out[5] = (ab * atx - aa * aty) * det; + return out; + }; + + /** + * Calculates the determinant of a mat2d + * + * @param {mat2d} a the source matrix + * @returns {Number} determinant of a + */ + mat2d.determinant = function (a) { + return a[0] * a[3] - a[1] * a[2]; + }; + + /** + * Multiplies two mat2d's + * + * @param {mat2d} out the receiving matrix + * @param {mat2d} a the first operand + * @param {mat2d} b the second operand + * @returns {mat2d} out + */ + mat2d.multiply = function (out, a, b) { + var a0 = a[0], a1 = a[1], a2 = a[2], a3 = a[3], a4 = a[4], a5 = a[5], + b0 = b[0], b1 = b[1], b2 = b[2], b3 = b[3], b4 = b[4], b5 = b[5]; + out[0] = a0 * b0 + a2 * b1; + out[1] = a1 * b0 + a3 * b1; + out[2] = a0 * b2 + a2 * b3; + out[3] = a1 * b2 + a3 * b3; + out[4] = a0 * b4 + a2 * b5 + a4; + out[5] = a1 * b4 + a3 * b5 + a5; + return out; + }; + + /** + * Alias for {@link mat2d.multiply} + * @function + */ + mat2d.mul = mat2d.multiply; + + /** + * Rotates a mat2d by the given angle + * + * @param {mat2d} out the receiving matrix + * @param {mat2d} a the matrix to rotate + * @param {Number} rad the angle to rotate the matrix by + * @returns {mat2d} out + */ + mat2d.rotate = function (out, a, rad) { + var a0 = a[0], a1 = a[1], a2 = a[2], a3 = a[3], a4 = a[4], a5 = a[5], + s = Math.sin(rad), + c = Math.cos(rad); + out[0] = a0 * c + a2 * s; + out[1] = a1 * c + a3 * s; + out[2] = a0 * -s + a2 * c; + out[3] = a1 * -s + a3 * c; + out[4] = a4; + out[5] = a5; + return out; + }; + + /** + * Scales the mat2d by the dimensions in the given vec2 + * + * @param {mat2d} out the receiving matrix + * @param {mat2d} a the matrix to translate + * @param {vec2} v the vec2 to scale the matrix by + * @returns {mat2d} out + **/ + mat2d.scale = function(out, a, v) { + var a0 = a[0], a1 = a[1], a2 = a[2], a3 = a[3], a4 = a[4], a5 = a[5], + v0 = v[0], v1 = v[1]; + out[0] = a0 * v0; + out[1] = a1 * v0; + out[2] = a2 * v1; + out[3] = a3 * v1; + out[4] = a4; + out[5] = a5; + return out; + }; + + /** + * Translates the mat2d by the dimensions in the given vec2 + * + * @param {mat2d} out the receiving matrix + * @param {mat2d} a the matrix to translate + * @param {vec2} v the vec2 to translate the matrix by + * @returns {mat2d} out + **/ + mat2d.translate = function(out, a, v) { + var a0 = a[0], a1 = a[1], a2 = a[2], a3 = a[3], a4 = a[4], a5 = a[5], + v0 = v[0], v1 = v[1]; + out[0] = a0; + out[1] = a1; + out[2] = a2; + out[3] = a3; + out[4] = a0 * v0 + a2 * v1 + a4; + out[5] = a1 * v0 + a3 * v1 + a5; + return out; + }; + + /** + * Creates a matrix from a given angle + * This is equivalent to (but much faster than): + * + * mat2d.identity(dest); + * mat2d.rotate(dest, dest, rad); + * + * @param {mat2d} out mat2d receiving operation result + * @param {Number} rad the angle to rotate the matrix by + * @returns {mat2d} out + */ + mat2d.fromRotation = function(out, rad) { + var s = Math.sin(rad), c = Math.cos(rad); + out[0] = c; + out[1] = s; + out[2] = -s; + out[3] = c; + out[4] = 0; + out[5] = 0; + return out; + } + + /** + * Creates a matrix from a vector scaling + * This is equivalent to (but much faster than): + * + * mat2d.identity(dest); + * mat2d.scale(dest, dest, vec); + * + * @param {mat2d} out mat2d receiving operation result + * @param {vec2} v Scaling vector + * @returns {mat2d} out + */ + mat2d.fromScaling = function(out, v) { + out[0] = v[0]; + out[1] = 0; + out[2] = 0; + out[3] = v[1]; + out[4] = 0; + out[5] = 0; + return out; + } + + /** + * Creates a matrix from a vector translation + * This is equivalent to (but much faster than): + * + * mat2d.identity(dest); + * mat2d.translate(dest, dest, vec); + * + * @param {mat2d} out mat2d receiving operation result + * @param {vec2} v Translation vector + * @returns {mat2d} out + */ + mat2d.fromTranslation = function(out, v) { + out[0] = 1; + out[1] = 0; + out[2] = 0; + out[3] = 1; + out[4] = v[0]; + out[5] = v[1]; + return out; + } + + /** + * Returns a string representation of a mat2d + * + * @param {mat2d} a matrix to represent as a string + * @returns {String} string representation of the matrix + */ + mat2d.str = function (a) { + return 'mat2d(' + a[0] + ', ' + a[1] + ', ' + a[2] + ', ' + + a[3] + ', ' + a[4] + ', ' + a[5] + ')'; + }; + + /** + * Returns Frobenius norm of a mat2d + * + * @param {mat2d} a the matrix to calculate Frobenius norm of + * @returns {Number} Frobenius norm + */ + mat2d.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) + 1)) + }; + + /** + * Adds two mat2d's + * + * @param {mat2d} out the receiving matrix + * @param {mat2d} a the first operand + * @param {mat2d} b the second operand + * @returns {mat2d} out + */ + mat2d.add = function(out, a, b) { + out[0] = a[0] + b[0]; + out[1] = a[1] + b[1]; + out[2] = a[2] + b[2]; + out[3] = a[3] + b[3]; + out[4] = a[4] + b[4]; + out[5] = a[5] + b[5]; + return out; + }; + + /** + * Subtracts matrix b from matrix a + * + * @param {mat2d} out the receiving matrix + * @param {mat2d} a the first operand + * @param {mat2d} b the second operand + * @returns {mat2d} out + */ + mat2d.subtract = function(out, a, b) { + out[0] = a[0] - b[0]; + out[1] = a[1] - b[1]; + out[2] = a[2] - b[2]; + out[3] = a[3] - b[3]; + out[4] = a[4] - b[4]; + out[5] = a[5] - b[5]; + return out; + }; + + /** + * Alias for {@link mat2d.subtract} + * @function + */ + mat2d.sub = mat2d.subtract; + + /** + * Multiply each element of the matrix by a scalar. + * + * @param {mat2d} out the receiving matrix + * @param {mat2d} a the matrix to scale + * @param {Number} b amount to scale the matrix's elements by + * @returns {mat2d} out + */ + mat2d.multiplyScalar = function(out, a, b) { + out[0] = a[0] * b; + out[1] = a[1] * b; + out[2] = a[2] * b; + out[3] = a[3] * b; + out[4] = a[4] * b; + out[5] = a[5] * b; + return out; + }; + + /** + * Adds two mat2d's after multiplying each element of the second operand by a scalar value. + * + * @param {mat2d} out the receiving vector + * @param {mat2d} a the first operand + * @param {mat2d} b the second operand + * @param {Number} scale the amount to scale b's elements by before adding + * @returns {mat2d} out + */ + mat2d.multiplyScalarAndAdd = function(out, a, b, scale) { + out[0] = a[0] + (b[0] * scale); + out[1] = a[1] + (b[1] * scale); + out[2] = a[2] + (b[2] * scale); + out[3] = a[3] + (b[3] * scale); + out[4] = a[4] + (b[4] * scale); + out[5] = a[5] + (b[5] * scale); + return out; + }; + + /** + * Returns whether or not the matrices have exactly the same elements in the same position (when compared with ===) + * + * @param {mat2d} a The first matrix. + * @param {mat2d} b The second matrix. + * @returns {Boolean} True if the matrices are equal, false otherwise. + */ + mat2d.exactEquals = function (a, b) { + return a[0] === b[0] && a[1] === b[1] && a[2] === b[2] && a[3] === b[3] && a[4] === b[4] && a[5] === b[5]; + }; + + /** + * Returns whether or not the matrices have approximately the same elements in the same position. + * + * @param {mat2d} a The first matrix. + * @param {mat2d} b The second matrix. + * @returns {Boolean} True if the matrices are equal, false otherwise. + */ + mat2d.equals = function (a, b) { + var a0 = a[0], a1 = a[1], a2 = a[2], a3 = a[3], a4 = a[4], a5 = a[5]; + var b0 = b[0], b1 = b[1], b2 = b[2], b3 = b[3], b4 = b[4], b5 = b[5]; + return (Math.abs(a0 - b0) <= glMatrix.EPSILON*Math.max(1.0, Math.abs(a0), Math.abs(b0)) && + Math.abs(a1 - b1) <= glMatrix.EPSILON*Math.max(1.0, Math.abs(a1), Math.abs(b1)) && + Math.abs(a2 - b2) <= glMatrix.EPSILON*Math.max(1.0, Math.abs(a2), Math.abs(b2)) && + Math.abs(a3 - b3) <= glMatrix.EPSILON*Math.max(1.0, Math.abs(a3), Math.abs(b3)) && + Math.abs(a4 - b4) <= glMatrix.EPSILON*Math.max(1.0, Math.abs(a4), Math.abs(b4)) && + Math.abs(a5 - b5) <= glMatrix.EPSILON*Math.max(1.0, Math.abs(a5), Math.abs(b5))); + }; + + module.exports = mat2d; + + +/***/ }, +/* 4 */ +/***/ function(module, exports, __webpack_require__) { + + /* Copyright (c) 2015, Brandon Jones, Colin MacKenzie IV. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. */ + + var glMatrix = __webpack_require__(1); + + /** + * @class 3x3 Matrix + * @name mat3 + */ + var mat3 = {}; + + /** + * Creates a new identity mat3 + * + * @returns {mat3} a new 3x3 matrix + */ + mat3.create = function() { + var out = new glMatrix.ARRAY_TYPE(9); + out[0] = 1; + out[1] = 0; + out[2] = 0; + out[3] = 0; + out[4] = 1; + out[5] = 0; + out[6] = 0; + out[7] = 0; + out[8] = 1; + return out; + }; + + /** + * Copies the upper-left 3x3 values into the given mat3. + * + * @param {mat3} out the receiving 3x3 matrix + * @param {mat4} a the source 4x4 matrix + * @returns {mat3} out + */ + mat3.fromMat4 = function(out, a) { + out[0] = a[0]; + out[1] = a[1]; + out[2] = a[2]; + out[3] = a[4]; + out[4] = a[5]; + out[5] = a[6]; + out[6] = a[8]; + out[7] = a[9]; + out[8] = a[10]; + return out; + }; + + /** + * Creates a new mat3 initialized with values from an existing matrix + * + * @param {mat3} a matrix to clone + * @returns {mat3} a new 3x3 matrix + */ + mat3.clone = function(a) { + var out = new glMatrix.ARRAY_TYPE(9); + out[0] = a[0]; + out[1] = a[1]; + out[2] = a[2]; + out[3] = a[3]; + out[4] = a[4]; + out[5] = a[5]; + out[6] = a[6]; + out[7] = a[7]; + out[8] = a[8]; + return out; + }; + + /** + * Copy the values from one mat3 to another + * + * @param {mat3} out the receiving matrix + * @param {mat3} a the source matrix + * @returns {mat3} out + */ + mat3.copy = function(out, a) { + out[0] = a[0]; + out[1] = a[1]; + out[2] = a[2]; + out[3] = a[3]; + out[4] = a[4]; + out[5] = a[5]; + out[6] = a[6]; + out[7] = a[7]; + out[8] = a[8]; + return out; + }; + + /** + * Create a new mat3 with the given values + * + * @param {Number} m00 Component in column 0, row 0 position (index 0) + * @param {Number} m01 Component in column 0, row 1 position (index 1) + * @param {Number} m02 Component in column 0, row 2 position (index 2) + * @param {Number} m10 Component in column 1, row 0 position (index 3) + * @param {Number} m11 Component in column 1, row 1 position (index 4) + * @param {Number} m12 Component in column 1, row 2 position (index 5) + * @param {Number} m20 Component in column 2, row 0 position (index 6) + * @param {Number} m21 Component in column 2, row 1 position (index 7) + * @param {Number} m22 Component in column 2, row 2 position (index 8) + * @returns {mat3} A new mat3 + */ + mat3.fromValues = function(m00, m01, m02, m10, m11, m12, m20, m21, m22) { + var out = new glMatrix.ARRAY_TYPE(9); + out[0] = m00; + out[1] = m01; + out[2] = m02; + out[3] = m10; + out[4] = m11; + out[5] = m12; + out[6] = m20; + out[7] = m21; + out[8] = m22; + return out; + }; + + /** + * Set the components of a mat3 to the given values + * + * @param {mat3} out the receiving matrix + * @param {Number} m00 Component in column 0, row 0 position (index 0) + * @param {Number} m01 Component in column 0, row 1 position (index 1) + * @param {Number} m02 Component in column 0, row 2 position (index 2) + * @param {Number} m10 Component in column 1, row 0 position (index 3) + * @param {Number} m11 Component in column 1, row 1 position (index 4) + * @param {Number} m12 Component in column 1, row 2 position (index 5) + * @param {Number} m20 Component in column 2, row 0 position (index 6) + * @param {Number} m21 Component in column 2, row 1 position (index 7) + * @param {Number} m22 Component in column 2, row 2 position (index 8) + * @returns {mat3} out + */ + mat3.set = function(out, m00, m01, m02, m10, m11, m12, m20, m21, m22) { + out[0] = m00; + out[1] = m01; + out[2] = m02; + out[3] = m10; + out[4] = m11; + out[5] = m12; + out[6] = m20; + out[7] = m21; + out[8] = m22; + return out; + }; + + /** + * Set a mat3 to the identity matrix + * + * @param {mat3} out the receiving matrix + * @returns {mat3} out + */ + mat3.identity = function(out) { + out[0] = 1; + out[1] = 0; + out[2] = 0; + out[3] = 0; + out[4] = 1; + out[5] = 0; + out[6] = 0; + out[7] = 0; + out[8] = 1; + return out; + }; + + /** + * Transpose the values of a mat3 + * + * @param {mat3} out the receiving matrix + * @param {mat3} a the source matrix + * @returns {mat3} out + */ + mat3.transpose = function(out, a) { + // If we are transposing ourselves we can skip a few steps but have to cache some values + if (out === a) { + var a01 = a[1], a02 = a[2], a12 = a[5]; + out[1] = a[3]; + out[2] = a[6]; + out[3] = a01; + out[5] = a[7]; + out[6] = a02; + out[7] = a12; + } else { + out[0] = a[0]; + out[1] = a[3]; + out[2] = a[6]; + out[3] = a[1]; + out[4] = a[4]; + out[5] = a[7]; + out[6] = a[2]; + out[7] = a[5]; + out[8] = a[8]; + } + + return out; + }; + + /** + * Inverts a mat3 + * + * @param {mat3} out the receiving matrix + * @param {mat3} a the source matrix + * @returns {mat3} out + */ + mat3.invert = function(out, a) { + var a00 = a[0], a01 = a[1], a02 = a[2], + a10 = a[3], a11 = a[4], a12 = a[5], + a20 = a[6], a21 = a[7], a22 = a[8], + + b01 = a22 * a11 - a12 * a21, + b11 = -a22 * a10 + a12 * a20, + b21 = a21 * a10 - a11 * a20, + + // Calculate the determinant + det = a00 * b01 + a01 * b11 + a02 * b21; + + if (!det) { + return null; + } + det = 1.0 / det; + + out[0] = b01 * det; + out[1] = (-a22 * a01 + a02 * a21) * det; + out[2] = (a12 * a01 - a02 * a11) * det; + out[3] = b11 * det; + out[4] = (a22 * a00 - a02 * a20) * det; + out[5] = (-a12 * a00 + a02 * a10) * det; + out[6] = b21 * det; + out[7] = (-a21 * a00 + a01 * a20) * det; + out[8] = (a11 * a00 - a01 * a10) * det; + return out; + }; + + /** + * Calculates the adjugate of a mat3 + * + * @param {mat3} out the receiving matrix + * @param {mat3} a the source matrix + * @returns {mat3} out + */ + mat3.adjoint = function(out, a) { + var a00 = a[0], a01 = a[1], a02 = a[2], + a10 = a[3], a11 = a[4], a12 = a[5], + a20 = a[6], a21 = a[7], a22 = a[8]; + + out[0] = (a11 * a22 - a12 * a21); + out[1] = (a02 * a21 - a01 * a22); + out[2] = (a01 * a12 - a02 * a11); + out[3] = (a12 * a20 - a10 * a22); + out[4] = (a00 * a22 - a02 * a20); + out[5] = (a02 * a10 - a00 * a12); + out[6] = (a10 * a21 - a11 * a20); + out[7] = (a01 * a20 - a00 * a21); + out[8] = (a00 * a11 - a01 * a10); + return out; + }; + + /** + * Calculates the determinant of a mat3 + * + * @param {mat3} a the source matrix + * @returns {Number} determinant of a + */ + mat3.determinant = function (a) { + var a00 = a[0], a01 = a[1], a02 = a[2], + a10 = a[3], a11 = a[4], a12 = a[5], + a20 = a[6], a21 = a[7], a22 = a[8]; + + return a00 * (a22 * a11 - a12 * a21) + a01 * (-a22 * a10 + a12 * a20) + a02 * (a21 * a10 - a11 * a20); + }; + + /** + * Multiplies two mat3's + * + * @param {mat3} out the receiving matrix + * @param {mat3} a the first operand + * @param {mat3} b the second operand + * @returns {mat3} out + */ + mat3.multiply = function (out, a, b) { + var a00 = a[0], a01 = a[1], a02 = a[2], + a10 = a[3], a11 = a[4], a12 = a[5], + a20 = a[6], a21 = a[7], a22 = a[8], + + b00 = b[0], b01 = b[1], b02 = b[2], + b10 = b[3], b11 = b[4], b12 = b[5], + b20 = b[6], b21 = b[7], b22 = b[8]; + + out[0] = b00 * a00 + b01 * a10 + b02 * a20; + out[1] = b00 * a01 + b01 * a11 + b02 * a21; + out[2] = b00 * a02 + b01 * a12 + b02 * a22; + + out[3] = b10 * a00 + b11 * a10 + b12 * a20; + out[4] = b10 * a01 + b11 * a11 + b12 * a21; + out[5] = b10 * a02 + b11 * a12 + b12 * a22; + + out[6] = b20 * a00 + b21 * a10 + b22 * a20; + out[7] = b20 * a01 + b21 * a11 + b22 * a21; + out[8] = b20 * a02 + b21 * a12 + b22 * a22; + return out; + }; + + /** + * Alias for {@link mat3.multiply} + * @function + */ + mat3.mul = mat3.multiply; + + /** + * Translate a mat3 by the given vector + * + * @param {mat3} out the receiving matrix + * @param {mat3} a the matrix to translate + * @param {vec2} v vector to translate by + * @returns {mat3} out + */ + mat3.translate = function(out, a, v) { + var a00 = a[0], a01 = a[1], a02 = a[2], + a10 = a[3], a11 = a[4], a12 = a[5], + a20 = a[6], a21 = a[7], a22 = a[8], + x = v[0], y = v[1]; + + out[0] = a00; + out[1] = a01; + out[2] = a02; + + out[3] = a10; + out[4] = a11; + out[5] = a12; + + out[6] = x * a00 + y * a10 + a20; + out[7] = x * a01 + y * a11 + a21; + out[8] = x * a02 + y * a12 + a22; + return out; + }; + + /** + * Rotates a mat3 by the given angle + * + * @param {mat3} out the receiving matrix + * @param {mat3} a the matrix to rotate + * @param {Number} rad the angle to rotate the matrix by + * @returns {mat3} out + */ + mat3.rotate = function (out, a, rad) { + var a00 = a[0], a01 = a[1], a02 = a[2], + a10 = a[3], a11 = a[4], a12 = a[5], + a20 = a[6], a21 = a[7], a22 = a[8], + + s = Math.sin(rad), + c = Math.cos(rad); + + out[0] = c * a00 + s * a10; + out[1] = c * a01 + s * a11; + out[2] = c * a02 + s * a12; + + out[3] = c * a10 - s * a00; + out[4] = c * a11 - s * a01; + out[5] = c * a12 - s * a02; + + out[6] = a20; + out[7] = a21; + out[8] = a22; + return out; + }; + + /** + * Scales the mat3 by the dimensions in the given vec2 + * + * @param {mat3} out the receiving matrix + * @param {mat3} a the matrix to rotate + * @param {vec2} v the vec2 to scale the matrix by + * @returns {mat3} out + **/ + mat3.scale = function(out, a, v) { + var x = v[0], y = v[1]; + + out[0] = x * a[0]; + out[1] = x * a[1]; + out[2] = x * a[2]; + + out[3] = y * a[3]; + out[4] = y * a[4]; + out[5] = y * a[5]; + + out[6] = a[6]; + out[7] = a[7]; + out[8] = a[8]; + return out; + }; + + /** + * Creates a matrix from a vector translation + * This is equivalent to (but much faster than): + * + * mat3.identity(dest); + * mat3.translate(dest, dest, vec); + * + * @param {mat3} out mat3 receiving operation result + * @param {vec2} v Translation vector + * @returns {mat3} out + */ + mat3.fromTranslation = function(out, v) { + out[0] = 1; + out[1] = 0; + out[2] = 0; + out[3] = 0; + out[4] = 1; + out[5] = 0; + out[6] = v[0]; + out[7] = v[1]; + out[8] = 1; + return out; + } + + /** + * Creates a matrix from a given angle + * This is equivalent to (but much faster than): + * + * mat3.identity(dest); + * mat3.rotate(dest, dest, rad); + * + * @param {mat3} out mat3 receiving operation result + * @param {Number} rad the angle to rotate the matrix by + * @returns {mat3} out + */ + mat3.fromRotation = function(out, rad) { + var s = Math.sin(rad), c = Math.cos(rad); + + out[0] = c; + out[1] = s; + out[2] = 0; + + out[3] = -s; + out[4] = c; + out[5] = 0; + + out[6] = 0; + out[7] = 0; + out[8] = 1; + return out; + } + + /** + * Creates a matrix from a vector scaling + * This is equivalent to (but much faster than): + * + * mat3.identity(dest); + * mat3.scale(dest, dest, vec); + * + * @param {mat3} out mat3 receiving operation result + * @param {vec2} v Scaling vector + * @returns {mat3} out + */ + mat3.fromScaling = function(out, v) { + out[0] = v[0]; + out[1] = 0; + out[2] = 0; + + out[3] = 0; + out[4] = v[1]; + out[5] = 0; + + out[6] = 0; + out[7] = 0; + out[8] = 1; + return out; + } + + /** + * Copies the values from a mat2d into a mat3 + * + * @param {mat3} out the receiving matrix + * @param {mat2d} a the matrix to copy + * @returns {mat3} out + **/ + mat3.fromMat2d = function(out, a) { + out[0] = a[0]; + out[1] = a[1]; + out[2] = 0; + + out[3] = a[2]; + out[4] = a[3]; + out[5] = 0; + + out[6] = a[4]; + out[7] = a[5]; + out[8] = 1; + return out; + }; + + /** + * Calculates a 3x3 matrix from the given quaternion + * + * @param {mat3} out mat3 receiving operation result + * @param {quat} q Quaternion to create matrix from + * + * @returns {mat3} out + */ + mat3.fromQuat = function (out, q) { + var x = q[0], y = q[1], z = q[2], w = q[3], + x2 = x + x, + y2 = y + y, + z2 = z + z, + + xx = x * x2, + yx = y * x2, + yy = y * y2, + zx = z * x2, + zy = z * y2, + zz = z * z2, + wx = w * x2, + wy = w * y2, + wz = w * z2; + + out[0] = 1 - yy - zz; + out[3] = yx - wz; + out[6] = zx + wy; + + out[1] = yx + wz; + out[4] = 1 - xx - zz; + out[7] = zy - wx; + + out[2] = zx - wy; + out[5] = zy + wx; + out[8] = 1 - xx - yy; + + return out; + }; + + /** + * Calculates a 3x3 normal matrix (transpose inverse) from the 4x4 matrix + * + * @param {mat3} out mat3 receiving operation result + * @param {mat4} a Mat4 to derive the normal matrix from + * + * @returns {mat3} out + */ + mat3.normalFromMat4 = function (out, a) { + var a00 = a[0], a01 = a[1], a02 = a[2], a03 = a[3], + a10 = a[4], a11 = a[5], a12 = a[6], a13 = a[7], + a20 = a[8], a21 = a[9], a22 = a[10], a23 = a[11], + a30 = a[12], a31 = a[13], a32 = a[14], a33 = a[15], + + b00 = a00 * a11 - a01 * a10, + b01 = a00 * a12 - a02 * a10, + b02 = a00 * a13 - a03 * a10, + b03 = a01 * a12 - a02 * a11, + b04 = a01 * a13 - a03 * a11, + b05 = a02 * a13 - a03 * a12, + b06 = a20 * a31 - a21 * a30, + b07 = a20 * a32 - a22 * a30, + b08 = a20 * a33 - a23 * a30, + b09 = a21 * a32 - a22 * a31, + b10 = a21 * a33 - a23 * a31, + b11 = a22 * a33 - a23 * a32, + + // Calculate the determinant + det = b00 * b11 - b01 * b10 + b02 * b09 + b03 * b08 - b04 * b07 + b05 * b06; + + if (!det) { + return null; + } + det = 1.0 / det; + + out[0] = (a11 * b11 - a12 * b10 + a13 * b09) * det; + out[1] = (a12 * b08 - a10 * b11 - a13 * b07) * det; + out[2] = (a10 * b10 - a11 * b08 + a13 * b06) * det; + + out[3] = (a02 * b10 - a01 * b11 - a03 * b09) * det; + out[4] = (a00 * b11 - a02 * b08 + a03 * b07) * det; + out[5] = (a01 * b08 - a00 * b10 - a03 * b06) * det; + + out[6] = (a31 * b05 - a32 * b04 + a33 * b03) * det; + out[7] = (a32 * b02 - a30 * b05 - a33 * b01) * det; + out[8] = (a30 * b04 - a31 * b02 + a33 * b00) * det; + + return out; + }; + + /** + * Returns a string representation of a mat3 + * + * @param {mat3} a matrix to represent as a string + * @returns {String} string representation of the matrix + */ + mat3.str = function (a) { + return 'mat3(' + a[0] + ', ' + a[1] + ', ' + a[2] + ', ' + + a[3] + ', ' + a[4] + ', ' + a[5] + ', ' + + a[6] + ', ' + a[7] + ', ' + a[8] + ')'; + }; + + /** + * Returns Frobenius norm of a mat3 + * + * @param {mat3} a the matrix to calculate Frobenius norm of + * @returns {Number} Frobenius norm + */ + mat3.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[7], 2) + Math.pow(a[8], 2))) + }; + + /** + * Adds two mat3's + * + * @param {mat3} out the receiving matrix + * @param {mat3} a the first operand + * @param {mat3} b the second operand + * @returns {mat3} out + */ + mat3.add = function(out, a, b) { + out[0] = a[0] + b[0]; + out[1] = a[1] + b[1]; + out[2] = a[2] + b[2]; + out[3] = a[3] + b[3]; + out[4] = a[4] + b[4]; + out[5] = a[5] + b[5]; + out[6] = a[6] + b[6]; + out[7] = a[7] + b[7]; + out[8] = a[8] + b[8]; + return out; + }; + + /** + * Subtracts matrix b from matrix a + * + * @param {mat3} out the receiving matrix + * @param {mat3} a the first operand + * @param {mat3} b the second operand + * @returns {mat3} out + */ + mat3.subtract = function(out, a, b) { + out[0] = a[0] - b[0]; + out[1] = a[1] - b[1]; + out[2] = a[2] - b[2]; + out[3] = a[3] - b[3]; + out[4] = a[4] - b[4]; + out[5] = a[5] - b[5]; + out[6] = a[6] - b[6]; + out[7] = a[7] - b[7]; + out[8] = a[8] - b[8]; + return out; + }; + + /** + * Alias for {@link mat3.subtract} + * @function + */ + mat3.sub = mat3.subtract; + + /** + * Multiply each element of the matrix by a scalar. + * + * @param {mat3} out the receiving matrix + * @param {mat3} a the matrix to scale + * @param {Number} b amount to scale the matrix's elements by + * @returns {mat3} out + */ + mat3.multiplyScalar = function(out, a, b) { + out[0] = a[0] * b; + out[1] = a[1] * b; + out[2] = a[2] * b; + out[3] = a[3] * b; + out[4] = a[4] * b; + out[5] = a[5] * b; + out[6] = a[6] * b; + out[7] = a[7] * b; + out[8] = a[8] * b; + return out; + }; + + /** + * Adds two mat3's after multiplying each element of the second operand by a scalar value. + * + * @param {mat3} out the receiving vector + * @param {mat3} a the first operand + * @param {mat3} b the second operand + * @param {Number} scale the amount to scale b's elements by before adding + * @returns {mat3} out + */ + mat3.multiplyScalarAndAdd = function(out, a, b, scale) { + out[0] = a[0] + (b[0] * scale); + out[1] = a[1] + (b[1] * scale); + out[2] = a[2] + (b[2] * scale); + out[3] = a[3] + (b[3] * scale); + out[4] = a[4] + (b[4] * scale); + out[5] = a[5] + (b[5] * scale); + out[6] = a[6] + (b[6] * scale); + out[7] = a[7] + (b[7] * scale); + out[8] = a[8] + (b[8] * scale); + return out; + }; + + /** + * Returns whether or not the matrices have exactly the same elements in the same position (when compared with ===) + * + * @param {mat3} a The first matrix. + * @param {mat3} b The second matrix. + * @returns {Boolean} True if the matrices are equal, false otherwise. + */ + mat3.exactEquals = function (a, b) { + return a[0] === b[0] && a[1] === b[1] && a[2] === b[2] && + a[3] === b[3] && a[4] === b[4] && a[5] === b[5] && + a[6] === b[6] && a[7] === b[7] && a[8] === b[8]; + }; + + /** + * Returns whether or not the matrices have approximately the same elements in the same position. + * + * @param {mat3} a The first matrix. + * @param {mat3} b The second matrix. + * @returns {Boolean} True if the matrices are equal, false otherwise. + */ + mat3.equals = function (a, b) { + var a0 = a[0], a1 = a[1], a2 = a[2], a3 = a[3], a4 = a[4], a5 = a[5], a6 = a[6], a7 = a[7], a8 = a[8]; + var b0 = b[0], b1 = b[1], b2 = b[2], b3 = b[3], b4 = b[4], b5 = b[5], b6 = a[6], b7 = b[7], b8 = b[8]; + return (Math.abs(a0 - b0) <= glMatrix.EPSILON*Math.max(1.0, Math.abs(a0), Math.abs(b0)) && + Math.abs(a1 - b1) <= glMatrix.EPSILON*Math.max(1.0, Math.abs(a1), Math.abs(b1)) && + Math.abs(a2 - b2) <= glMatrix.EPSILON*Math.max(1.0, Math.abs(a2), Math.abs(b2)) && + Math.abs(a3 - b3) <= glMatrix.EPSILON*Math.max(1.0, Math.abs(a3), Math.abs(b3)) && + Math.abs(a4 - b4) <= glMatrix.EPSILON*Math.max(1.0, Math.abs(a4), Math.abs(b4)) && + Math.abs(a5 - b5) <= glMatrix.EPSILON*Math.max(1.0, Math.abs(a5), Math.abs(b5)) && + Math.abs(a6 - b6) <= glMatrix.EPSILON*Math.max(1.0, Math.abs(a6), Math.abs(b6)) && + Math.abs(a7 - b7) <= glMatrix.EPSILON*Math.max(1.0, Math.abs(a7), Math.abs(b7)) && + Math.abs(a8 - b8) <= glMatrix.EPSILON*Math.max(1.0, Math.abs(a8), Math.abs(b8))); + }; + + + module.exports = mat3; + + +/***/ }, +/* 5 */ +/***/ function(module, exports, __webpack_require__) { + + /* Copyright (c) 2015, Brandon Jones, Colin MacKenzie IV. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. */ + + var glMatrix = __webpack_require__(1); + + /** + * @class 4x4 Matrix + * @name mat4 + */ + var mat4 = { + scalar: {}, + SIMD: {} + }; + + /** + * Creates a new identity mat4 + * + * @returns {mat4} a new 4x4 matrix + */ + mat4.create = function() { + var out = new glMatrix.ARRAY_TYPE(16); + out[0] = 1; + out[1] = 0; + out[2] = 0; + out[3] = 0; + out[4] = 0; + out[5] = 1; + out[6] = 0; + out[7] = 0; + out[8] = 0; + out[9] = 0; + out[10] = 1; + out[11] = 0; + out[12] = 0; + out[13] = 0; + out[14] = 0; + out[15] = 1; + return out; + }; + + /** + * Creates a new mat4 initialized with values from an existing matrix + * + * @param {mat4} a matrix to clone + * @returns {mat4} a new 4x4 matrix + */ + mat4.clone = function(a) { + var out = new glMatrix.ARRAY_TYPE(16); + out[0] = a[0]; + out[1] = a[1]; + out[2] = a[2]; + out[3] = a[3]; + out[4] = a[4]; + out[5] = a[5]; + out[6] = a[6]; + out[7] = a[7]; + out[8] = a[8]; + out[9] = a[9]; + out[10] = a[10]; + out[11] = a[11]; + out[12] = a[12]; + out[13] = a[13]; + out[14] = a[14]; + out[15] = a[15]; + return out; + }; + + /** + * Copy the values from one mat4 to another + * + * @param {mat4} out the receiving matrix + * @param {mat4} a the source matrix + * @returns {mat4} out + */ + mat4.copy = function(out, a) { + out[0] = a[0]; + out[1] = a[1]; + out[2] = a[2]; + out[3] = a[3]; + out[4] = a[4]; + out[5] = a[5]; + out[6] = a[6]; + out[7] = a[7]; + out[8] = a[8]; + out[9] = a[9]; + out[10] = a[10]; + out[11] = a[11]; + out[12] = a[12]; + out[13] = a[13]; + out[14] = a[14]; + out[15] = a[15]; + return out; + }; + + /** + * Create a new mat4 with the given values + * + * @param {Number} m00 Component in column 0, row 0 position (index 0) + * @param {Number} m01 Component in column 0, row 1 position (index 1) + * @param {Number} m02 Component in column 0, row 2 position (index 2) + * @param {Number} m03 Component in column 0, row 3 position (index 3) + * @param {Number} m10 Component in column 1, row 0 position (index 4) + * @param {Number} m11 Component in column 1, row 1 position (index 5) + * @param {Number} m12 Component in column 1, row 2 position (index 6) + * @param {Number} m13 Component in column 1, row 3 position (index 7) + * @param {Number} m20 Component in column 2, row 0 position (index 8) + * @param {Number} m21 Component in column 2, row 1 position (index 9) + * @param {Number} m22 Component in column 2, row 2 position (index 10) + * @param {Number} m23 Component in column 2, row 3 position (index 11) + * @param {Number} m30 Component in column 3, row 0 position (index 12) + * @param {Number} m31 Component in column 3, row 1 position (index 13) + * @param {Number} m32 Component in column 3, row 2 position (index 14) + * @param {Number} m33 Component in column 3, row 3 position (index 15) + * @returns {mat4} A new mat4 + */ + mat4.fromValues = function(m00, m01, m02, m03, m10, m11, m12, m13, m20, m21, m22, m23, m30, m31, m32, m33) { + var out = new glMatrix.ARRAY_TYPE(16); + out[0] = m00; + out[1] = m01; + out[2] = m02; + out[3] = m03; + out[4] = m10; + out[5] = m11; + out[6] = m12; + out[7] = m13; + out[8] = m20; + out[9] = m21; + out[10] = m22; + out[11] = m23; + out[12] = m30; + out[13] = m31; + out[14] = m32; + out[15] = m33; + return out; + }; + + /** + * Set the components of a mat4 to the given values + * + * @param {mat4} out the receiving matrix + * @param {Number} m00 Component in column 0, row 0 position (index 0) + * @param {Number} m01 Component in column 0, row 1 position (index 1) + * @param {Number} m02 Component in column 0, row 2 position (index 2) + * @param {Number} m03 Component in column 0, row 3 position (index 3) + * @param {Number} m10 Component in column 1, row 0 position (index 4) + * @param {Number} m11 Component in column 1, row 1 position (index 5) + * @param {Number} m12 Component in column 1, row 2 position (index 6) + * @param {Number} m13 Component in column 1, row 3 position (index 7) + * @param {Number} m20 Component in column 2, row 0 position (index 8) + * @param {Number} m21 Component in column 2, row 1 position (index 9) + * @param {Number} m22 Component in column 2, row 2 position (index 10) + * @param {Number} m23 Component in column 2, row 3 position (index 11) + * @param {Number} m30 Component in column 3, row 0 position (index 12) + * @param {Number} m31 Component in column 3, row 1 position (index 13) + * @param {Number} m32 Component in column 3, row 2 position (index 14) + * @param {Number} m33 Component in column 3, row 3 position (index 15) + * @returns {mat4} out + */ + mat4.set = function(out, m00, m01, m02, m03, m10, m11, m12, m13, m20, m21, m22, m23, m30, m31, m32, m33) { + out[0] = m00; + out[1] = m01; + out[2] = m02; + out[3] = m03; + out[4] = m10; + out[5] = m11; + out[6] = m12; + out[7] = m13; + out[8] = m20; + out[9] = m21; + out[10] = m22; + out[11] = m23; + out[12] = m30; + out[13] = m31; + out[14] = m32; + out[15] = m33; + return out; + }; + + + /** + * Set a mat4 to the identity matrix + * + * @param {mat4} out the receiving matrix + * @returns {mat4} out + */ + mat4.identity = function(out) { + out[0] = 1; + out[1] = 0; + out[2] = 0; + out[3] = 0; + out[4] = 0; + out[5] = 1; + out[6] = 0; + out[7] = 0; + out[8] = 0; + out[9] = 0; + out[10] = 1; + out[11] = 0; + out[12] = 0; + out[13] = 0; + out[14] = 0; + out[15] = 1; + return out; + }; + + /** + * Transpose the values of a mat4 not using SIMD + * + * @param {mat4} out the receiving matrix + * @param {mat4} a the source matrix + * @returns {mat4} out + */ + mat4.scalar.transpose = function(out, a) { + // If we are transposing ourselves we can skip a few steps but have to cache some values + if (out === a) { + var a01 = a[1], a02 = a[2], a03 = a[3], + a12 = a[6], a13 = a[7], + a23 = a[11]; + + out[1] = a[4]; + out[2] = a[8]; + out[3] = a[12]; + out[4] = a01; + out[6] = a[9]; + out[7] = a[13]; + out[8] = a02; + out[9] = a12; + out[11] = a[14]; + out[12] = a03; + out[13] = a13; + out[14] = a23; + } else { + out[0] = a[0]; + out[1] = a[4]; + out[2] = a[8]; + out[3] = a[12]; + out[4] = a[1]; + out[5] = a[5]; + out[6] = a[9]; + out[7] = a[13]; + out[8] = a[2]; + out[9] = a[6]; + out[10] = a[10]; + out[11] = a[14]; + out[12] = a[3]; + out[13] = a[7]; + out[14] = a[11]; + out[15] = a[15]; + } + + return out; + }; + + /** + * Transpose the values of a mat4 using SIMD + * + * @param {mat4} out the receiving matrix + * @param {mat4} a the source matrix + * @returns {mat4} out + */ + mat4.SIMD.transpose = function(out, a) { + var a0, a1, a2, a3, + tmp01, tmp23, + out0, out1, out2, out3; + + a0 = SIMD.Float32x4.load(a, 0); + a1 = SIMD.Float32x4.load(a, 4); + a2 = SIMD.Float32x4.load(a, 8); + a3 = SIMD.Float32x4.load(a, 12); + + tmp01 = SIMD.Float32x4.shuffle(a0, a1, 0, 1, 4, 5); + tmp23 = SIMD.Float32x4.shuffle(a2, a3, 0, 1, 4, 5); + out0 = SIMD.Float32x4.shuffle(tmp01, tmp23, 0, 2, 4, 6); + out1 = SIMD.Float32x4.shuffle(tmp01, tmp23, 1, 3, 5, 7); + SIMD.Float32x4.store(out, 0, out0); + SIMD.Float32x4.store(out, 4, out1); + + tmp01 = SIMD.Float32x4.shuffle(a0, a1, 2, 3, 6, 7); + tmp23 = SIMD.Float32x4.shuffle(a2, a3, 2, 3, 6, 7); + out2 = SIMD.Float32x4.shuffle(tmp01, tmp23, 0, 2, 4, 6); + out3 = SIMD.Float32x4.shuffle(tmp01, tmp23, 1, 3, 5, 7); + SIMD.Float32x4.store(out, 8, out2); + SIMD.Float32x4.store(out, 12, out3); + + return out; + }; + + /** + * Transpse a mat4 using SIMD if available and enabled + * + * @param {mat4} out the receiving matrix + * @param {mat4} a the source matrix + * @returns {mat4} out + */ + mat4.transpose = glMatrix.USE_SIMD ? mat4.SIMD.transpose : mat4.scalar.transpose; + + /** + * Inverts a mat4 not using SIMD + * + * @param {mat4} out the receiving matrix + * @param {mat4} a the source matrix + * @returns {mat4} out + */ + mat4.scalar.invert = function(out, a) { + var a00 = a[0], a01 = a[1], a02 = a[2], a03 = a[3], + a10 = a[4], a11 = a[5], a12 = a[6], a13 = a[7], + a20 = a[8], a21 = a[9], a22 = a[10], a23 = a[11], + a30 = a[12], a31 = a[13], a32 = a[14], a33 = a[15], + + b00 = a00 * a11 - a01 * a10, + b01 = a00 * a12 - a02 * a10, + b02 = a00 * a13 - a03 * a10, + b03 = a01 * a12 - a02 * a11, + b04 = a01 * a13 - a03 * a11, + b05 = a02 * a13 - a03 * a12, + b06 = a20 * a31 - a21 * a30, + b07 = a20 * a32 - a22 * a30, + b08 = a20 * a33 - a23 * a30, + b09 = a21 * a32 - a22 * a31, + b10 = a21 * a33 - a23 * a31, + b11 = a22 * a33 - a23 * a32, + + // Calculate the determinant + det = b00 * b11 - b01 * b10 + b02 * b09 + b03 * b08 - b04 * b07 + b05 * b06; + + if (!det) { + return null; + } + det = 1.0 / det; + + out[0] = (a11 * b11 - a12 * b10 + a13 * b09) * det; + out[1] = (a02 * b10 - a01 * b11 - a03 * b09) * det; + out[2] = (a31 * b05 - a32 * b04 + a33 * b03) * det; + out[3] = (a22 * b04 - a21 * b05 - a23 * b03) * det; + out[4] = (a12 * b08 - a10 * b11 - a13 * b07) * det; + out[5] = (a00 * b11 - a02 * b08 + a03 * b07) * det; + out[6] = (a32 * b02 - a30 * b05 - a33 * b01) * det; + out[7] = (a20 * b05 - a22 * b02 + a23 * b01) * det; + out[8] = (a10 * b10 - a11 * b08 + a13 * b06) * det; + out[9] = (a01 * b08 - a00 * b10 - a03 * b06) * det; + out[10] = (a30 * b04 - a31 * b02 + a33 * b00) * det; + out[11] = (a21 * b02 - a20 * b04 - a23 * b00) * det; + out[12] = (a11 * b07 - a10 * b09 - a12 * b06) * det; + out[13] = (a00 * b09 - a01 * b07 + a02 * b06) * det; + out[14] = (a31 * b01 - a30 * b03 - a32 * b00) * det; + out[15] = (a20 * b03 - a21 * b01 + a22 * b00) * det; + + return out; + }; + + /** + * Inverts a mat4 using SIMD + * + * @param {mat4} out the receiving matrix + * @param {mat4} a the source matrix + * @returns {mat4} out + */ + mat4.SIMD.invert = function(out, a) { + var row0, row1, row2, row3, + tmp1, + minor0, minor1, minor2, minor3, + det, + a0 = SIMD.Float32x4.load(a, 0), + a1 = SIMD.Float32x4.load(a, 4), + a2 = SIMD.Float32x4.load(a, 8), + a3 = SIMD.Float32x4.load(a, 12); + + // Compute matrix adjugate + tmp1 = SIMD.Float32x4.shuffle(a0, a1, 0, 1, 4, 5); + row1 = SIMD.Float32x4.shuffle(a2, a3, 0, 1, 4, 5); + row0 = SIMD.Float32x4.shuffle(tmp1, row1, 0, 2, 4, 6); + row1 = SIMD.Float32x4.shuffle(row1, tmp1, 1, 3, 5, 7); + tmp1 = SIMD.Float32x4.shuffle(a0, a1, 2, 3, 6, 7); + row3 = SIMD.Float32x4.shuffle(a2, a3, 2, 3, 6, 7); + row2 = SIMD.Float32x4.shuffle(tmp1, row3, 0, 2, 4, 6); + row3 = SIMD.Float32x4.shuffle(row3, tmp1, 1, 3, 5, 7); + + tmp1 = SIMD.Float32x4.mul(row2, row3); + tmp1 = SIMD.Float32x4.swizzle(tmp1, 1, 0, 3, 2); + minor0 = SIMD.Float32x4.mul(row1, tmp1); + minor1 = SIMD.Float32x4.mul(row0, tmp1); + tmp1 = SIMD.Float32x4.swizzle(tmp1, 2, 3, 0, 1); + minor0 = SIMD.Float32x4.sub(SIMD.Float32x4.mul(row1, tmp1), minor0); + minor1 = SIMD.Float32x4.sub(SIMD.Float32x4.mul(row0, tmp1), minor1); + minor1 = SIMD.Float32x4.swizzle(minor1, 2, 3, 0, 1); + + tmp1 = SIMD.Float32x4.mul(row1, row2); + tmp1 = SIMD.Float32x4.swizzle(tmp1, 1, 0, 3, 2); + minor0 = SIMD.Float32x4.add(SIMD.Float32x4.mul(row3, tmp1), minor0); + minor3 = SIMD.Float32x4.mul(row0, tmp1); + tmp1 = SIMD.Float32x4.swizzle(tmp1, 2, 3, 0, 1); + minor0 = SIMD.Float32x4.sub(minor0, SIMD.Float32x4.mul(row3, tmp1)); + minor3 = SIMD.Float32x4.sub(SIMD.Float32x4.mul(row0, tmp1), minor3); + minor3 = SIMD.Float32x4.swizzle(minor3, 2, 3, 0, 1); + + tmp1 = SIMD.Float32x4.mul(SIMD.Float32x4.swizzle(row1, 2, 3, 0, 1), row3); + tmp1 = SIMD.Float32x4.swizzle(tmp1, 1, 0, 3, 2); + row2 = SIMD.Float32x4.swizzle(row2, 2, 3, 0, 1); + minor0 = SIMD.Float32x4.add(SIMD.Float32x4.mul(row2, tmp1), minor0); + minor2 = SIMD.Float32x4.mul(row0, tmp1); + tmp1 = SIMD.Float32x4.swizzle(tmp1, 2, 3, 0, 1); + minor0 = SIMD.Float32x4.sub(minor0, SIMD.Float32x4.mul(row2, tmp1)); + minor2 = SIMD.Float32x4.sub(SIMD.Float32x4.mul(row0, tmp1), minor2); + minor2 = SIMD.Float32x4.swizzle(minor2, 2, 3, 0, 1); + + tmp1 = SIMD.Float32x4.mul(row0, row1); + tmp1 = SIMD.Float32x4.swizzle(tmp1, 1, 0, 3, 2); + minor2 = SIMD.Float32x4.add(SIMD.Float32x4.mul(row3, tmp1), minor2); + minor3 = SIMD.Float32x4.sub(SIMD.Float32x4.mul(row2, tmp1), minor3); + tmp1 = SIMD.Float32x4.swizzle(tmp1, 2, 3, 0, 1); + minor2 = SIMD.Float32x4.sub(SIMD.Float32x4.mul(row3, tmp1), minor2); + minor3 = SIMD.Float32x4.sub(minor3, SIMD.Float32x4.mul(row2, tmp1)); + + tmp1 = SIMD.Float32x4.mul(row0, row3); + tmp1 = SIMD.Float32x4.swizzle(tmp1, 1, 0, 3, 2); + minor1 = SIMD.Float32x4.sub(minor1, SIMD.Float32x4.mul(row2, tmp1)); + minor2 = SIMD.Float32x4.add(SIMD.Float32x4.mul(row1, tmp1), minor2); + tmp1 = SIMD.Float32x4.swizzle(tmp1, 2, 3, 0, 1); + minor1 = SIMD.Float32x4.add(SIMD.Float32x4.mul(row2, tmp1), minor1); + minor2 = SIMD.Float32x4.sub(minor2, SIMD.Float32x4.mul(row1, tmp1)); + + tmp1 = SIMD.Float32x4.mul(row0, row2); + tmp1 = SIMD.Float32x4.swizzle(tmp1, 1, 0, 3, 2); + minor1 = SIMD.Float32x4.add(SIMD.Float32x4.mul(row3, tmp1), minor1); + minor3 = SIMD.Float32x4.sub(minor3, SIMD.Float32x4.mul(row1, tmp1)); + tmp1 = SIMD.Float32x4.swizzle(tmp1, 2, 3, 0, 1); + minor1 = SIMD.Float32x4.sub(minor1, SIMD.Float32x4.mul(row3, tmp1)); + minor3 = SIMD.Float32x4.add(SIMD.Float32x4.mul(row1, tmp1), minor3); + + // Compute matrix determinant + det = SIMD.Float32x4.mul(row0, minor0); + det = SIMD.Float32x4.add(SIMD.Float32x4.swizzle(det, 2, 3, 0, 1), det); + det = SIMD.Float32x4.add(SIMD.Float32x4.swizzle(det, 1, 0, 3, 2), det); + tmp1 = SIMD.Float32x4.reciprocalApproximation(det); + det = SIMD.Float32x4.sub( + SIMD.Float32x4.add(tmp1, tmp1), + SIMD.Float32x4.mul(det, SIMD.Float32x4.mul(tmp1, tmp1))); + det = SIMD.Float32x4.swizzle(det, 0, 0, 0, 0); + if (!det) { + return null; + } + + // Compute matrix inverse + SIMD.Float32x4.store(out, 0, SIMD.Float32x4.mul(det, minor0)); + SIMD.Float32x4.store(out, 4, SIMD.Float32x4.mul(det, minor1)); + SIMD.Float32x4.store(out, 8, SIMD.Float32x4.mul(det, minor2)); + SIMD.Float32x4.store(out, 12, SIMD.Float32x4.mul(det, minor3)); + return out; + } + + /** + * Inverts a mat4 using SIMD if available and enabled + * + * @param {mat4} out the receiving matrix + * @param {mat4} a the source matrix + * @returns {mat4} out + */ + mat4.invert = glMatrix.USE_SIMD ? mat4.SIMD.invert : mat4.scalar.invert; + + /** + * Calculates the adjugate of a mat4 not using SIMD + * + * @param {mat4} out the receiving matrix + * @param {mat4} a the source matrix + * @returns {mat4} out + */ + mat4.scalar.adjoint = function(out, a) { + var a00 = a[0], a01 = a[1], a02 = a[2], a03 = a[3], + a10 = a[4], a11 = a[5], a12 = a[6], a13 = a[7], + a20 = a[8], a21 = a[9], a22 = a[10], a23 = a[11], + a30 = a[12], a31 = a[13], a32 = a[14], a33 = a[15]; + + out[0] = (a11 * (a22 * a33 - a23 * a32) - a21 * (a12 * a33 - a13 * a32) + a31 * (a12 * a23 - a13 * a22)); + out[1] = -(a01 * (a22 * a33 - a23 * a32) - a21 * (a02 * a33 - a03 * a32) + a31 * (a02 * a23 - a03 * a22)); + out[2] = (a01 * (a12 * a33 - a13 * a32) - a11 * (a02 * a33 - a03 * a32) + a31 * (a02 * a13 - a03 * a12)); + out[3] = -(a01 * (a12 * a23 - a13 * a22) - a11 * (a02 * a23 - a03 * a22) + a21 * (a02 * a13 - a03 * a12)); + out[4] = -(a10 * (a22 * a33 - a23 * a32) - a20 * (a12 * a33 - a13 * a32) + a30 * (a12 * a23 - a13 * a22)); + out[5] = (a00 * (a22 * a33 - a23 * a32) - a20 * (a02 * a33 - a03 * a32) + a30 * (a02 * a23 - a03 * a22)); + out[6] = -(a00 * (a12 * a33 - a13 * a32) - a10 * (a02 * a33 - a03 * a32) + a30 * (a02 * a13 - a03 * a12)); + out[7] = (a00 * (a12 * a23 - a13 * a22) - a10 * (a02 * a23 - a03 * a22) + a20 * (a02 * a13 - a03 * a12)); + out[8] = (a10 * (a21 * a33 - a23 * a31) - a20 * (a11 * a33 - a13 * a31) + a30 * (a11 * a23 - a13 * a21)); + out[9] = -(a00 * (a21 * a33 - a23 * a31) - a20 * (a01 * a33 - a03 * a31) + a30 * (a01 * a23 - a03 * a21)); + out[10] = (a00 * (a11 * a33 - a13 * a31) - a10 * (a01 * a33 - a03 * a31) + a30 * (a01 * a13 - a03 * a11)); + out[11] = -(a00 * (a11 * a23 - a13 * a21) - a10 * (a01 * a23 - a03 * a21) + a20 * (a01 * a13 - a03 * a11)); + out[12] = -(a10 * (a21 * a32 - a22 * a31) - a20 * (a11 * a32 - a12 * a31) + a30 * (a11 * a22 - a12 * a21)); + out[13] = (a00 * (a21 * a32 - a22 * a31) - a20 * (a01 * a32 - a02 * a31) + a30 * (a01 * a22 - a02 * a21)); + out[14] = -(a00 * (a11 * a32 - a12 * a31) - a10 * (a01 * a32 - a02 * a31) + a30 * (a01 * a12 - a02 * a11)); + out[15] = (a00 * (a11 * a22 - a12 * a21) - a10 * (a01 * a22 - a02 * a21) + a20 * (a01 * a12 - a02 * a11)); + return out; + }; + + /** + * Calculates the adjugate of a mat4 using SIMD + * + * @param {mat4} out the receiving matrix + * @param {mat4} a the source matrix + * @returns {mat4} out + */ + mat4.SIMD.adjoint = function(out, a) { + var a0, a1, a2, a3; + var row0, row1, row2, row3; + var tmp1; + var minor0, minor1, minor2, minor3; + + a0 = SIMD.Float32x4.load(a, 0); + a1 = SIMD.Float32x4.load(a, 4); + a2 = SIMD.Float32x4.load(a, 8); + a3 = SIMD.Float32x4.load(a, 12); + + // Transpose the source matrix. Sort of. Not a true transpose operation + tmp1 = SIMD.Float32x4.shuffle(a0, a1, 0, 1, 4, 5); + row1 = SIMD.Float32x4.shuffle(a2, a3, 0, 1, 4, 5); + row0 = SIMD.Float32x4.shuffle(tmp1, row1, 0, 2, 4, 6); + row1 = SIMD.Float32x4.shuffle(row1, tmp1, 1, 3, 5, 7); + + tmp1 = SIMD.Float32x4.shuffle(a0, a1, 2, 3, 6, 7); + row3 = SIMD.Float32x4.shuffle(a2, a3, 2, 3, 6, 7); + row2 = SIMD.Float32x4.shuffle(tmp1, row3, 0, 2, 4, 6); + row3 = SIMD.Float32x4.shuffle(row3, tmp1, 1, 3, 5, 7); + + tmp1 = SIMD.Float32x4.mul(row2, row3); + tmp1 = SIMD.Float32x4.swizzle(tmp1, 1, 0, 3, 2); + minor0 = SIMD.Float32x4.mul(row1, tmp1); + minor1 = SIMD.Float32x4.mul(row0, tmp1); + tmp1 = SIMD.Float32x4.swizzle(tmp1, 2, 3, 0, 1); + minor0 = SIMD.Float32x4.sub(SIMD.Float32x4.mul(row1, tmp1), minor0); + minor1 = SIMD.Float32x4.sub(SIMD.Float32x4.mul(row0, tmp1), minor1); + minor1 = SIMD.Float32x4.swizzle(minor1, 2, 3, 0, 1); + + tmp1 = SIMD.Float32x4.mul(row1, row2); + tmp1 = SIMD.Float32x4.swizzle(tmp1, 1, 0, 3, 2); + minor0 = SIMD.Float32x4.add(SIMD.Float32x4.mul(row3, tmp1), minor0); + minor3 = SIMD.Float32x4.mul(row0, tmp1); + tmp1 = SIMD.Float32x4.swizzle(tmp1, 2, 3, 0, 1); + minor0 = SIMD.Float32x4.sub(minor0, SIMD.Float32x4.mul(row3, tmp1)); + minor3 = SIMD.Float32x4.sub(SIMD.Float32x4.mul(row0, tmp1), minor3); + minor3 = SIMD.Float32x4.swizzle(minor3, 2, 3, 0, 1); + + tmp1 = SIMD.Float32x4.mul(SIMD.Float32x4.swizzle(row1, 2, 3, 0, 1), row3); + tmp1 = SIMD.Float32x4.swizzle(tmp1, 1, 0, 3, 2); + row2 = SIMD.Float32x4.swizzle(row2, 2, 3, 0, 1); + minor0 = SIMD.Float32x4.add(SIMD.Float32x4.mul(row2, tmp1), minor0); + minor2 = SIMD.Float32x4.mul(row0, tmp1); + tmp1 = SIMD.Float32x4.swizzle(tmp1, 2, 3, 0, 1); + minor0 = SIMD.Float32x4.sub(minor0, SIMD.Float32x4.mul(row2, tmp1)); + minor2 = SIMD.Float32x4.sub(SIMD.Float32x4.mul(row0, tmp1), minor2); + minor2 = SIMD.Float32x4.swizzle(minor2, 2, 3, 0, 1); + + tmp1 = SIMD.Float32x4.mul(row0, row1); + tmp1 = SIMD.Float32x4.swizzle(tmp1, 1, 0, 3, 2); + minor2 = SIMD.Float32x4.add(SIMD.Float32x4.mul(row3, tmp1), minor2); + minor3 = SIMD.Float32x4.sub(SIMD.Float32x4.mul(row2, tmp1), minor3); + tmp1 = SIMD.Float32x4.swizzle(tmp1, 2, 3, 0, 1); + minor2 = SIMD.Float32x4.sub(SIMD.Float32x4.mul(row3, tmp1), minor2); + minor3 = SIMD.Float32x4.sub(minor3, SIMD.Float32x4.mul(row2, tmp1)); + + tmp1 = SIMD.Float32x4.mul(row0, row3); + tmp1 = SIMD.Float32x4.swizzle(tmp1, 1, 0, 3, 2); + minor1 = SIMD.Float32x4.sub(minor1, SIMD.Float32x4.mul(row2, tmp1)); + minor2 = SIMD.Float32x4.add(SIMD.Float32x4.mul(row1, tmp1), minor2); + tmp1 = SIMD.Float32x4.swizzle(tmp1, 2, 3, 0, 1); + minor1 = SIMD.Float32x4.add(SIMD.Float32x4.mul(row2, tmp1), minor1); + minor2 = SIMD.Float32x4.sub(minor2, SIMD.Float32x4.mul(row1, tmp1)); + + tmp1 = SIMD.Float32x4.mul(row0, row2); + tmp1 = SIMD.Float32x4.swizzle(tmp1, 1, 0, 3, 2); + minor1 = SIMD.Float32x4.add(SIMD.Float32x4.mul(row3, tmp1), minor1); + minor3 = SIMD.Float32x4.sub(minor3, SIMD.Float32x4.mul(row1, tmp1)); + tmp1 = SIMD.Float32x4.swizzle(tmp1, 2, 3, 0, 1); + minor1 = SIMD.Float32x4.sub(minor1, SIMD.Float32x4.mul(row3, tmp1)); + minor3 = SIMD.Float32x4.add(SIMD.Float32x4.mul(row1, tmp1), minor3); + + SIMD.Float32x4.store(out, 0, minor0); + SIMD.Float32x4.store(out, 4, minor1); + SIMD.Float32x4.store(out, 8, minor2); + SIMD.Float32x4.store(out, 12, minor3); + return out; + }; + + /** + * Calculates the adjugate of a mat4 using SIMD if available and enabled + * + * @param {mat4} out the receiving matrix + * @param {mat4} a the source matrix + * @returns {mat4} out + */ + mat4.adjoint = glMatrix.USE_SIMD ? mat4.SIMD.adjoint : mat4.scalar.adjoint; + + /** + * Calculates the determinant of a mat4 + * + * @param {mat4} a the source matrix + * @returns {Number} determinant of a + */ + mat4.determinant = function (a) { + var a00 = a[0], a01 = a[1], a02 = a[2], a03 = a[3], + a10 = a[4], a11 = a[5], a12 = a[6], a13 = a[7], + a20 = a[8], a21 = a[9], a22 = a[10], a23 = a[11], + a30 = a[12], a31 = a[13], a32 = a[14], a33 = a[15], + + b00 = a00 * a11 - a01 * a10, + b01 = a00 * a12 - a02 * a10, + b02 = a00 * a13 - a03 * a10, + b03 = a01 * a12 - a02 * a11, + b04 = a01 * a13 - a03 * a11, + b05 = a02 * a13 - a03 * a12, + b06 = a20 * a31 - a21 * a30, + b07 = a20 * a32 - a22 * a30, + b08 = a20 * a33 - a23 * a30, + b09 = a21 * a32 - a22 * a31, + b10 = a21 * a33 - a23 * a31, + b11 = a22 * a33 - a23 * a32; + + // Calculate the determinant + return b00 * b11 - b01 * b10 + b02 * b09 + b03 * b08 - b04 * b07 + b05 * b06; + }; + + /** + * Multiplies two mat4's explicitly using SIMD + * + * @param {mat4} out the receiving matrix + * @param {mat4} a the first operand, must be a Float32Array + * @param {mat4} b the second operand, must be a Float32Array + * @returns {mat4} out + */ + mat4.SIMD.multiply = function (out, a, b) { + var a0 = SIMD.Float32x4.load(a, 0); + var a1 = SIMD.Float32x4.load(a, 4); + var a2 = SIMD.Float32x4.load(a, 8); + var a3 = SIMD.Float32x4.load(a, 12); + + var b0 = SIMD.Float32x4.load(b, 0); + var out0 = SIMD.Float32x4.add( + SIMD.Float32x4.mul(SIMD.Float32x4.swizzle(b0, 0, 0, 0, 0), a0), + SIMD.Float32x4.add( + SIMD.Float32x4.mul(SIMD.Float32x4.swizzle(b0, 1, 1, 1, 1), a1), + SIMD.Float32x4.add( + SIMD.Float32x4.mul(SIMD.Float32x4.swizzle(b0, 2, 2, 2, 2), a2), + SIMD.Float32x4.mul(SIMD.Float32x4.swizzle(b0, 3, 3, 3, 3), a3)))); + SIMD.Float32x4.store(out, 0, out0); + + var b1 = SIMD.Float32x4.load(b, 4); + var out1 = SIMD.Float32x4.add( + SIMD.Float32x4.mul(SIMD.Float32x4.swizzle(b1, 0, 0, 0, 0), a0), + SIMD.Float32x4.add( + SIMD.Float32x4.mul(SIMD.Float32x4.swizzle(b1, 1, 1, 1, 1), a1), + SIMD.Float32x4.add( + SIMD.Float32x4.mul(SIMD.Float32x4.swizzle(b1, 2, 2, 2, 2), a2), + SIMD.Float32x4.mul(SIMD.Float32x4.swizzle(b1, 3, 3, 3, 3), a3)))); + SIMD.Float32x4.store(out, 4, out1); + + var b2 = SIMD.Float32x4.load(b, 8); + var out2 = SIMD.Float32x4.add( + SIMD.Float32x4.mul(SIMD.Float32x4.swizzle(b2, 0, 0, 0, 0), a0), + SIMD.Float32x4.add( + SIMD.Float32x4.mul(SIMD.Float32x4.swizzle(b2, 1, 1, 1, 1), a1), + SIMD.Float32x4.add( + SIMD.Float32x4.mul(SIMD.Float32x4.swizzle(b2, 2, 2, 2, 2), a2), + SIMD.Float32x4.mul(SIMD.Float32x4.swizzle(b2, 3, 3, 3, 3), a3)))); + SIMD.Float32x4.store(out, 8, out2); + + var b3 = SIMD.Float32x4.load(b, 12); + var out3 = SIMD.Float32x4.add( + SIMD.Float32x4.mul(SIMD.Float32x4.swizzle(b3, 0, 0, 0, 0), a0), + SIMD.Float32x4.add( + SIMD.Float32x4.mul(SIMD.Float32x4.swizzle(b3, 1, 1, 1, 1), a1), + SIMD.Float32x4.add( + SIMD.Float32x4.mul(SIMD.Float32x4.swizzle(b3, 2, 2, 2, 2), a2), + SIMD.Float32x4.mul(SIMD.Float32x4.swizzle(b3, 3, 3, 3, 3), a3)))); + SIMD.Float32x4.store(out, 12, out3); + + return out; + }; + + /** + * Multiplies two mat4's explicitly not using SIMD + * + * @param {mat4} out the receiving matrix + * @param {mat4} a the first operand + * @param {mat4} b the second operand + * @returns {mat4} out + */ + mat4.scalar.multiply = function (out, a, b) { + var a00 = a[0], a01 = a[1], a02 = a[2], a03 = a[3], + a10 = a[4], a11 = a[5], a12 = a[6], a13 = a[7], + a20 = a[8], a21 = a[9], a22 = a[10], a23 = a[11], + a30 = a[12], a31 = a[13], a32 = a[14], a33 = a[15]; + + // Cache only the current line of the second matrix + var b0 = b[0], b1 = b[1], b2 = b[2], b3 = b[3]; + out[0] = b0*a00 + b1*a10 + b2*a20 + b3*a30; + out[1] = b0*a01 + b1*a11 + b2*a21 + b3*a31; + out[2] = b0*a02 + b1*a12 + b2*a22 + b3*a32; + out[3] = b0*a03 + b1*a13 + b2*a23 + b3*a33; + + b0 = b[4]; b1 = b[5]; b2 = b[6]; b3 = b[7]; + out[4] = b0*a00 + b1*a10 + b2*a20 + b3*a30; + out[5] = b0*a01 + b1*a11 + b2*a21 + b3*a31; + out[6] = b0*a02 + b1*a12 + b2*a22 + b3*a32; + out[7] = b0*a03 + b1*a13 + b2*a23 + b3*a33; + + b0 = b[8]; b1 = b[9]; b2 = b[10]; b3 = b[11]; + out[8] = b0*a00 + b1*a10 + b2*a20 + b3*a30; + out[9] = b0*a01 + b1*a11 + b2*a21 + b3*a31; + out[10] = b0*a02 + b1*a12 + b2*a22 + b3*a32; + out[11] = b0*a03 + b1*a13 + b2*a23 + b3*a33; + + b0 = b[12]; b1 = b[13]; b2 = b[14]; b3 = b[15]; + out[12] = b0*a00 + b1*a10 + b2*a20 + b3*a30; + out[13] = b0*a01 + b1*a11 + b2*a21 + b3*a31; + out[14] = b0*a02 + b1*a12 + b2*a22 + b3*a32; + out[15] = b0*a03 + b1*a13 + b2*a23 + b3*a33; + return out; + }; + + /** + * Multiplies two mat4's using SIMD if available and enabled + * + * @param {mat4} out the receiving matrix + * @param {mat4} a the first operand + * @param {mat4} b the second operand + * @returns {mat4} out + */ + mat4.multiply = glMatrix.USE_SIMD ? mat4.SIMD.multiply : mat4.scalar.multiply; + + /** + * Alias for {@link mat4.multiply} + * @function + */ + mat4.mul = mat4.multiply; + + /** + * Translate a mat4 by the given vector not using SIMD + * + * @param {mat4} out the receiving matrix + * @param {mat4} a the matrix to translate + * @param {vec3} v vector to translate by + * @returns {mat4} out + */ + mat4.scalar.translate = function (out, a, v) { + var x = v[0], y = v[1], z = v[2], + a00, a01, a02, a03, + a10, a11, a12, a13, + a20, a21, a22, a23; + + if (a === out) { + out[12] = a[0] * x + a[4] * y + a[8] * z + a[12]; + out[13] = a[1] * x + a[5] * y + a[9] * z + a[13]; + out[14] = a[2] * x + a[6] * y + a[10] * z + a[14]; + out[15] = a[3] * x + a[7] * y + a[11] * z + a[15]; + } else { + a00 = a[0]; a01 = a[1]; a02 = a[2]; a03 = a[3]; + a10 = a[4]; a11 = a[5]; a12 = a[6]; a13 = a[7]; + a20 = a[8]; a21 = a[9]; a22 = a[10]; a23 = a[11]; + + out[0] = a00; out[1] = a01; out[2] = a02; out[3] = a03; + out[4] = a10; out[5] = a11; out[6] = a12; out[7] = a13; + out[8] = a20; out[9] = a21; out[10] = a22; out[11] = a23; + + out[12] = a00 * x + a10 * y + a20 * z + a[12]; + out[13] = a01 * x + a11 * y + a21 * z + a[13]; + out[14] = a02 * x + a12 * y + a22 * z + a[14]; + out[15] = a03 * x + a13 * y + a23 * z + a[15]; + } + + return out; + }; + + /** + * Translates a mat4 by the given vector using SIMD + * + * @param {mat4} out the receiving matrix + * @param {mat4} a the matrix to translate + * @param {vec3} v vector to translate by + * @returns {mat4} out + */ + mat4.SIMD.translate = function (out, a, v) { + var a0 = SIMD.Float32x4.load(a, 0), + a1 = SIMD.Float32x4.load(a, 4), + a2 = SIMD.Float32x4.load(a, 8), + a3 = SIMD.Float32x4.load(a, 12), + vec = SIMD.Float32x4(v[0], v[1], v[2] , 0); + + if (a !== out) { + out[0] = a[0]; out[1] = a[1]; out[2] = a[2]; out[3] = a[3]; + out[4] = a[4]; out[5] = a[5]; out[6] = a[6]; out[7] = a[7]; + out[8] = a[8]; out[9] = a[9]; out[10] = a[10]; out[11] = a[11]; + } + + a0 = SIMD.Float32x4.mul(a0, SIMD.Float32x4.swizzle(vec, 0, 0, 0, 0)); + a1 = SIMD.Float32x4.mul(a1, SIMD.Float32x4.swizzle(vec, 1, 1, 1, 1)); + a2 = SIMD.Float32x4.mul(a2, SIMD.Float32x4.swizzle(vec, 2, 2, 2, 2)); + + var t0 = SIMD.Float32x4.add(a0, SIMD.Float32x4.add(a1, SIMD.Float32x4.add(a2, a3))); + SIMD.Float32x4.store(out, 12, t0); + + return out; + }; + + /** + * Translates a mat4 by the given vector using SIMD if available and enabled + * + * @param {mat4} out the receiving matrix + * @param {mat4} a the matrix to translate + * @param {vec3} v vector to translate by + * @returns {mat4} out + */ + mat4.translate = glMatrix.USE_SIMD ? mat4.SIMD.translate : mat4.scalar.translate; + + /** + * Scales the mat4 by the dimensions in the given vec3 not using vectorization + * + * @param {mat4} out the receiving matrix + * @param {mat4} a the matrix to scale + * @param {vec3} v the vec3 to scale the matrix by + * @returns {mat4} out + **/ + mat4.scalar.scale = function(out, a, v) { + var x = v[0], y = v[1], z = v[2]; + + out[0] = a[0] * x; + out[1] = a[1] * x; + out[2] = a[2] * x; + out[3] = a[3] * x; + out[4] = a[4] * y; + out[5] = a[5] * y; + out[6] = a[6] * y; + out[7] = a[7] * y; + out[8] = a[8] * z; + out[9] = a[9] * z; + out[10] = a[10] * z; + out[11] = a[11] * z; + out[12] = a[12]; + out[13] = a[13]; + out[14] = a[14]; + out[15] = a[15]; + return out; + }; + + /** + * Scales the mat4 by the dimensions in the given vec3 using vectorization + * + * @param {mat4} out the receiving matrix + * @param {mat4} a the matrix to scale + * @param {vec3} v the vec3 to scale the matrix by + * @returns {mat4} out + **/ + mat4.SIMD.scale = function(out, a, v) { + var a0, a1, a2; + var vec = SIMD.Float32x4(v[0], v[1], v[2], 0); + + a0 = SIMD.Float32x4.load(a, 0); + SIMD.Float32x4.store( + out, 0, SIMD.Float32x4.mul(a0, SIMD.Float32x4.swizzle(vec, 0, 0, 0, 0))); + + a1 = SIMD.Float32x4.load(a, 4); + SIMD.Float32x4.store( + out, 4, SIMD.Float32x4.mul(a1, SIMD.Float32x4.swizzle(vec, 1, 1, 1, 1))); + + a2 = SIMD.Float32x4.load(a, 8); + SIMD.Float32x4.store( + out, 8, SIMD.Float32x4.mul(a2, SIMD.Float32x4.swizzle(vec, 2, 2, 2, 2))); + + out[12] = a[12]; + out[13] = a[13]; + out[14] = a[14]; + out[15] = a[15]; + return out; + }; + + /** + * Scales the mat4 by the dimensions in the given vec3 using SIMD if available and enabled + * + * @param {mat4} out the receiving matrix + * @param {mat4} a the matrix to scale + * @param {vec3} v the vec3 to scale the matrix by + * @returns {mat4} out + */ + mat4.scale = glMatrix.USE_SIMD ? mat4.SIMD.scale : mat4.scalar.scale; + + /** + * Rotates a mat4 by the given angle around the given axis + * + * @param {mat4} out the receiving matrix + * @param {mat4} a the matrix to rotate + * @param {Number} rad the angle to rotate the matrix by + * @param {vec3} axis the axis to rotate around + * @returns {mat4} out + */ + mat4.rotate = function (out, a, rad, axis) { + var x = axis[0], y = axis[1], z = axis[2], + len = Math.sqrt(x * x + y * y + z * z), + s, c, t, + a00, a01, a02, a03, + a10, a11, a12, a13, + a20, a21, a22, a23, + b00, b01, b02, + b10, b11, b12, + b20, b21, b22; + + if (Math.abs(len) < glMatrix.EPSILON) { return null; } + + len = 1 / len; + x *= len; + y *= len; + z *= len; + + s = Math.sin(rad); + c = Math.cos(rad); + t = 1 - c; + + a00 = a[0]; a01 = a[1]; a02 = a[2]; a03 = a[3]; + a10 = a[4]; a11 = a[5]; a12 = a[6]; a13 = a[7]; + a20 = a[8]; a21 = a[9]; a22 = a[10]; a23 = a[11]; + + // Construct the elements of the rotation matrix + b00 = x * x * t + c; b01 = y * x * t + z * s; b02 = z * x * t - y * s; + b10 = x * y * t - z * s; b11 = y * y * t + c; b12 = z * y * t + x * s; + b20 = x * z * t + y * s; b21 = y * z * t - x * s; b22 = z * z * t + c; + + // Perform rotation-specific matrix multiplication + out[0] = a00 * b00 + a10 * b01 + a20 * b02; + out[1] = a01 * b00 + a11 * b01 + a21 * b02; + out[2] = a02 * b00 + a12 * b01 + a22 * b02; + out[3] = a03 * b00 + a13 * b01 + a23 * b02; + out[4] = a00 * b10 + a10 * b11 + a20 * b12; + out[5] = a01 * b10 + a11 * b11 + a21 * b12; + out[6] = a02 * b10 + a12 * b11 + a22 * b12; + out[7] = a03 * b10 + a13 * b11 + a23 * b12; + out[8] = a00 * b20 + a10 * b21 + a20 * b22; + out[9] = a01 * b20 + a11 * b21 + a21 * b22; + out[10] = a02 * b20 + a12 * b21 + a22 * b22; + out[11] = a03 * b20 + a13 * b21 + a23 * b22; + + if (a !== out) { // If the source and destination differ, copy the unchanged last row + out[12] = a[12]; + out[13] = a[13]; + out[14] = a[14]; + out[15] = a[15]; + } + return out; + }; + + /** + * Rotates a matrix by the given angle around the X axis not using SIMD + * + * @param {mat4} out the receiving matrix + * @param {mat4} a the matrix to rotate + * @param {Number} rad the angle to rotate the matrix by + * @returns {mat4} out + */ + mat4.scalar.rotateX = function (out, a, rad) { + var s = Math.sin(rad), + c = Math.cos(rad), + a10 = a[4], + a11 = a[5], + a12 = a[6], + a13 = a[7], + a20 = a[8], + a21 = a[9], + a22 = a[10], + a23 = a[11]; + + if (a !== out) { // If the source and destination differ, copy the unchanged rows + out[0] = a[0]; + out[1] = a[1]; + out[2] = a[2]; + out[3] = a[3]; + out[12] = a[12]; + out[13] = a[13]; + out[14] = a[14]; + out[15] = a[15]; + } + + // Perform axis-specific matrix multiplication + out[4] = a10 * c + a20 * s; + out[5] = a11 * c + a21 * s; + out[6] = a12 * c + a22 * s; + out[7] = a13 * c + a23 * s; + out[8] = a20 * c - a10 * s; + out[9] = a21 * c - a11 * s; + out[10] = a22 * c - a12 * s; + out[11] = a23 * c - a13 * s; + return out; + }; + + /** + * Rotates a matrix by the given angle around the X axis using SIMD + * + * @param {mat4} out the receiving matrix + * @param {mat4} a the matrix to rotate + * @param {Number} rad the angle to rotate the matrix by + * @returns {mat4} out + */ + mat4.SIMD.rotateX = function (out, a, rad) { + var s = SIMD.Float32x4.splat(Math.sin(rad)), + c = SIMD.Float32x4.splat(Math.cos(rad)); + + if (a !== out) { // If the source and destination differ, copy the unchanged rows + out[0] = a[0]; + out[1] = a[1]; + out[2] = a[2]; + out[3] = a[3]; + out[12] = a[12]; + out[13] = a[13]; + out[14] = a[14]; + out[15] = a[15]; + } + + // Perform axis-specific matrix multiplication + var a_1 = SIMD.Float32x4.load(a, 4); + var a_2 = SIMD.Float32x4.load(a, 8); + SIMD.Float32x4.store(out, 4, + SIMD.Float32x4.add(SIMD.Float32x4.mul(a_1, c), SIMD.Float32x4.mul(a_2, s))); + SIMD.Float32x4.store(out, 8, + SIMD.Float32x4.sub(SIMD.Float32x4.mul(a_2, c), SIMD.Float32x4.mul(a_1, s))); + return out; + }; + + /** + * Rotates a matrix by the given angle around the X axis using SIMD if availabe and enabled + * + * @param {mat4} out the receiving matrix + * @param {mat4} a the matrix to rotate + * @param {Number} rad the angle to rotate the matrix by + * @returns {mat4} out + */ + mat4.rotateX = glMatrix.USE_SIMD ? mat4.SIMD.rotateX : mat4.scalar.rotateX; + + /** + * Rotates a matrix by the given angle around the Y axis not using SIMD + * + * @param {mat4} out the receiving matrix + * @param {mat4} a the matrix to rotate + * @param {Number} rad the angle to rotate the matrix by + * @returns {mat4} out + */ + mat4.scalar.rotateY = function (out, a, rad) { + var s = Math.sin(rad), + c = Math.cos(rad), + a00 = a[0], + a01 = a[1], + a02 = a[2], + a03 = a[3], + a20 = a[8], + a21 = a[9], + a22 = a[10], + a23 = a[11]; + + if (a !== out) { // If the source and destination differ, copy the unchanged rows + out[4] = a[4]; + out[5] = a[5]; + out[6] = a[6]; + out[7] = a[7]; + out[12] = a[12]; + out[13] = a[13]; + out[14] = a[14]; + out[15] = a[15]; + } + + // Perform axis-specific matrix multiplication + out[0] = a00 * c - a20 * s; + out[1] = a01 * c - a21 * s; + out[2] = a02 * c - a22 * s; + out[3] = a03 * c - a23 * s; + out[8] = a00 * s + a20 * c; + out[9] = a01 * s + a21 * c; + out[10] = a02 * s + a22 * c; + out[11] = a03 * s + a23 * c; + return out; + }; + + /** + * Rotates a matrix by the given angle around the Y axis using SIMD + * + * @param {mat4} out the receiving matrix + * @param {mat4} a the matrix to rotate + * @param {Number} rad the angle to rotate the matrix by + * @returns {mat4} out + */ + mat4.SIMD.rotateY = function (out, a, rad) { + var s = SIMD.Float32x4.splat(Math.sin(rad)), + c = SIMD.Float32x4.splat(Math.cos(rad)); + + if (a !== out) { // If the source and destination differ, copy the unchanged rows + out[4] = a[4]; + out[5] = a[5]; + out[6] = a[6]; + out[7] = a[7]; + out[12] = a[12]; + out[13] = a[13]; + out[14] = a[14]; + out[15] = a[15]; + } + + // Perform axis-specific matrix multiplication + var a_0 = SIMD.Float32x4.load(a, 0); + var a_2 = SIMD.Float32x4.load(a, 8); + SIMD.Float32x4.store(out, 0, + SIMD.Float32x4.sub(SIMD.Float32x4.mul(a_0, c), SIMD.Float32x4.mul(a_2, s))); + SIMD.Float32x4.store(out, 8, + SIMD.Float32x4.add(SIMD.Float32x4.mul(a_0, s), SIMD.Float32x4.mul(a_2, c))); + return out; + }; + + /** + * Rotates a matrix by the given angle around the Y axis if SIMD available and enabled + * + * @param {mat4} out the receiving matrix + * @param {mat4} a the matrix to rotate + * @param {Number} rad the angle to rotate the matrix by + * @returns {mat4} out + */ + mat4.rotateY = glMatrix.USE_SIMD ? mat4.SIMD.rotateY : mat4.scalar.rotateY; + + /** + * Rotates a matrix by the given angle around the Z axis not using SIMD + * + * @param {mat4} out the receiving matrix + * @param {mat4} a the matrix to rotate + * @param {Number} rad the angle to rotate the matrix by + * @returns {mat4} out + */ + mat4.scalar.rotateZ = function (out, a, rad) { + var s = Math.sin(rad), + c = Math.cos(rad), + a00 = a[0], + a01 = a[1], + a02 = a[2], + a03 = a[3], + a10 = a[4], + a11 = a[5], + a12 = a[6], + a13 = a[7]; + + if (a !== out) { // If the source and destination differ, copy the unchanged last row + out[8] = a[8]; + out[9] = a[9]; + out[10] = a[10]; + out[11] = a[11]; + out[12] = a[12]; + out[13] = a[13]; + out[14] = a[14]; + out[15] = a[15]; + } + + // Perform axis-specific matrix multiplication + out[0] = a00 * c + a10 * s; + out[1] = a01 * c + a11 * s; + out[2] = a02 * c + a12 * s; + out[3] = a03 * c + a13 * s; + out[4] = a10 * c - a00 * s; + out[5] = a11 * c - a01 * s; + out[6] = a12 * c - a02 * s; + out[7] = a13 * c - a03 * s; + return out; + }; + + /** + * Rotates a matrix by the given angle around the Z axis using SIMD + * + * @param {mat4} out the receiving matrix + * @param {mat4} a the matrix to rotate + * @param {Number} rad the angle to rotate the matrix by + * @returns {mat4} out + */ + mat4.SIMD.rotateZ = function (out, a, rad) { + var s = SIMD.Float32x4.splat(Math.sin(rad)), + c = SIMD.Float32x4.splat(Math.cos(rad)); + + if (a !== out) { // If the source and destination differ, copy the unchanged last row + out[8] = a[8]; + out[9] = a[9]; + out[10] = a[10]; + out[11] = a[11]; + out[12] = a[12]; + out[13] = a[13]; + out[14] = a[14]; + out[15] = a[15]; + } + + // Perform axis-specific matrix multiplication + var a_0 = SIMD.Float32x4.load(a, 0); + var a_1 = SIMD.Float32x4.load(a, 4); + SIMD.Float32x4.store(out, 0, + SIMD.Float32x4.add(SIMD.Float32x4.mul(a_0, c), SIMD.Float32x4.mul(a_1, s))); + SIMD.Float32x4.store(out, 4, + SIMD.Float32x4.sub(SIMD.Float32x4.mul(a_1, c), SIMD.Float32x4.mul(a_0, s))); + return out; + }; + + /** + * Rotates a matrix by the given angle around the Z axis if SIMD available and enabled + * + * @param {mat4} out the receiving matrix + * @param {mat4} a the matrix to rotate + * @param {Number} rad the angle to rotate the matrix by + * @returns {mat4} out + */ + mat4.rotateZ = glMatrix.USE_SIMD ? mat4.SIMD.rotateZ : mat4.scalar.rotateZ; + + /** + * Creates a matrix from a vector translation + * This is equivalent to (but much faster than): + * + * mat4.identity(dest); + * mat4.translate(dest, dest, vec); + * + * @param {mat4} out mat4 receiving operation result + * @param {vec3} v Translation vector + * @returns {mat4} out + */ + mat4.fromTranslation = function(out, v) { + out[0] = 1; + out[1] = 0; + out[2] = 0; + out[3] = 0; + out[4] = 0; + out[5] = 1; + out[6] = 0; + out[7] = 0; + out[8] = 0; + out[9] = 0; + out[10] = 1; + out[11] = 0; + out[12] = v[0]; + out[13] = v[1]; + out[14] = v[2]; + out[15] = 1; + return out; + } + + /** + * Creates a matrix from a vector scaling + * This is equivalent to (but much faster than): + * + * mat4.identity(dest); + * mat4.scale(dest, dest, vec); + * + * @param {mat4} out mat4 receiving operation result + * @param {vec3} v Scaling vector + * @returns {mat4} out + */ + mat4.fromScaling = function(out, v) { + out[0] = v[0]; + out[1] = 0; + out[2] = 0; + out[3] = 0; + out[4] = 0; + out[5] = v[1]; + out[6] = 0; + out[7] = 0; + out[8] = 0; + out[9] = 0; + out[10] = v[2]; + out[11] = 0; + out[12] = 0; + out[13] = 0; + out[14] = 0; + out[15] = 1; + return out; + } + + /** + * Creates a matrix from a given angle around a given axis + * This is equivalent to (but much faster than): + * + * mat4.identity(dest); + * mat4.rotate(dest, dest, rad, axis); + * + * @param {mat4} out mat4 receiving operation result + * @param {Number} rad the angle to rotate the matrix by + * @param {vec3} axis the axis to rotate around + * @returns {mat4} out + */ + mat4.fromRotation = function(out, rad, axis) { + var x = axis[0], y = axis[1], z = axis[2], + len = Math.sqrt(x * x + y * y + z * z), + s, c, t; + + if (Math.abs(len) < glMatrix.EPSILON) { return null; } + + len = 1 / len; + x *= len; + y *= len; + z *= len; + + s = Math.sin(rad); + c = Math.cos(rad); + t = 1 - c; + + // Perform rotation-specific matrix multiplication + out[0] = x * x * t + c; + out[1] = y * x * t + z * s; + out[2] = z * x * t - y * s; + out[3] = 0; + out[4] = x * y * t - z * s; + out[5] = y * y * t + c; + out[6] = z * y * t + x * s; + out[7] = 0; + out[8] = x * z * t + y * s; + out[9] = y * z * t - x * s; + out[10] = z * z * t + c; + out[11] = 0; + out[12] = 0; + out[13] = 0; + out[14] = 0; + out[15] = 1; + return out; + } + + /** + * Creates a matrix from the given angle around the X axis + * This is equivalent to (but much faster than): + * + * mat4.identity(dest); + * mat4.rotateX(dest, dest, rad); + * + * @param {mat4} out mat4 receiving operation result + * @param {Number} rad the angle to rotate the matrix by + * @returns {mat4} out + */ + mat4.fromXRotation = function(out, rad) { + var s = Math.sin(rad), + c = Math.cos(rad); + + // Perform axis-specific matrix multiplication + out[0] = 1; + out[1] = 0; + out[2] = 0; + out[3] = 0; + out[4] = 0; + out[5] = c; + out[6] = s; + out[7] = 0; + out[8] = 0; + out[9] = -s; + out[10] = c; + out[11] = 0; + out[12] = 0; + out[13] = 0; + out[14] = 0; + out[15] = 1; + return out; + } + + /** + * Creates a matrix from the given angle around the Y axis + * This is equivalent to (but much faster than): + * + * mat4.identity(dest); + * mat4.rotateY(dest, dest, rad); + * + * @param {mat4} out mat4 receiving operation result + * @param {Number} rad the angle to rotate the matrix by + * @returns {mat4} out + */ + mat4.fromYRotation = function(out, rad) { + var s = Math.sin(rad), + c = Math.cos(rad); + + // Perform axis-specific matrix multiplication + out[0] = c; + out[1] = 0; + out[2] = -s; + out[3] = 0; + out[4] = 0; + out[5] = 1; + out[6] = 0; + out[7] = 0; + out[8] = s; + out[9] = 0; + out[10] = c; + out[11] = 0; + out[12] = 0; + out[13] = 0; + out[14] = 0; + out[15] = 1; + return out; + } + + /** + * Creates a matrix from the given angle around the Z axis + * This is equivalent to (but much faster than): + * + * mat4.identity(dest); + * mat4.rotateZ(dest, dest, rad); + * + * @param {mat4} out mat4 receiving operation result + * @param {Number} rad the angle to rotate the matrix by + * @returns {mat4} out + */ + mat4.fromZRotation = function(out, rad) { + var s = Math.sin(rad), + c = Math.cos(rad); + + // Perform axis-specific matrix multiplication + out[0] = c; + out[1] = s; + out[2] = 0; + out[3] = 0; + out[4] = -s; + out[5] = c; + out[6] = 0; + out[7] = 0; + out[8] = 0; + out[9] = 0; + out[10] = 1; + out[11] = 0; + out[12] = 0; + out[13] = 0; + out[14] = 0; + out[15] = 1; + return out; + } + + /** + * Creates a matrix from a quaternion rotation and vector translation + * This is equivalent to (but much faster than): + * + * mat4.identity(dest); + * mat4.translate(dest, vec); + * var quatMat = mat4.create(); + * quat4.toMat4(quat, quatMat); + * mat4.multiply(dest, quatMat); + * + * @param {mat4} out mat4 receiving operation result + * @param {quat4} q Rotation quaternion + * @param {vec3} v Translation vector + * @returns {mat4} out + */ + mat4.fromRotationTranslation = function (out, q, v) { + // Quaternion math + var x = q[0], y = q[1], z = q[2], w = q[3], + x2 = x + x, + y2 = y + y, + z2 = z + z, + + xx = x * x2, + xy = x * y2, + xz = x * z2, + yy = y * y2, + yz = y * z2, + zz = z * z2, + wx = w * x2, + wy = w * y2, + wz = w * z2; + + out[0] = 1 - (yy + zz); + out[1] = xy + wz; + out[2] = xz - wy; + out[3] = 0; + out[4] = xy - wz; + out[5] = 1 - (xx + zz); + out[6] = yz + wx; + out[7] = 0; + out[8] = xz + wy; + out[9] = yz - wx; + out[10] = 1 - (xx + yy); + out[11] = 0; + out[12] = v[0]; + out[13] = v[1]; + out[14] = v[2]; + out[15] = 1; + + return out; + }; + + /** + * Returns the translation vector component of a transformation + * matrix. If a matrix is built with fromRotationTranslation, + * the returned vector will be the same as the translation vector + * originally supplied. + * @param {vec3} out Vector to receive translation component + * @param {mat4} mat Matrix to be decomposed (input) + * @return {vec3} out + */ + mat4.getTranslation = function (out, mat) { + out[0] = mat[12]; + out[1] = mat[13]; + out[2] = mat[14]; + + return out; + }; + + /** + * Returns a quaternion representing the rotational component + * of a transformation matrix. If a matrix is built with + * fromRotationTranslation, the returned quaternion will be the + * same as the quaternion originally supplied. + * @param {quat} out Quaternion to receive the rotation component + * @param {mat4} mat Matrix to be decomposed (input) + * @return {quat} out + */ + mat4.getRotation = function (out, mat) { + // Algorithm taken from http://www.euclideanspace.com/maths/geometry/rotations/conversions/matrixToQuaternion/index.htm + var trace = mat[0] + mat[5] + mat[10]; + var S = 0; + + if (trace > 0) { + S = Math.sqrt(trace + 1.0) * 2; + out[3] = 0.25 * S; + out[0] = (mat[6] - mat[9]) / S; + out[1] = (mat[8] - mat[2]) / S; + out[2] = (mat[1] - mat[4]) / S; + } else if ((mat[0] > mat[5])&(mat[0] > mat[10])) { + S = Math.sqrt(1.0 + mat[0] - mat[5] - mat[10]) * 2; + out[3] = (mat[6] - mat[9]) / S; + out[0] = 0.25 * S; + out[1] = (mat[1] + mat[4]) / S; + out[2] = (mat[8] + mat[2]) / S; + } else if (mat[5] > mat[10]) { + S = Math.sqrt(1.0 + mat[5] - mat[0] - mat[10]) * 2; + out[3] = (mat[8] - mat[2]) / S; + out[0] = (mat[1] + mat[4]) / S; + out[1] = 0.25 * S; + out[2] = (mat[6] + mat[9]) / S; + } else { + S = Math.sqrt(1.0 + mat[10] - mat[0] - mat[5]) * 2; + out[3] = (mat[1] - mat[4]) / S; + out[0] = (mat[8] + mat[2]) / S; + out[1] = (mat[6] + mat[9]) / S; + out[2] = 0.25 * S; + } + + return out; + }; + + /** + * Creates a matrix from a quaternion rotation, vector translation and vector scale + * This is equivalent to (but much faster than): + * + * mat4.identity(dest); + * mat4.translate(dest, vec); + * var quatMat = mat4.create(); + * quat4.toMat4(quat, quatMat); + * mat4.multiply(dest, quatMat); + * mat4.scale(dest, scale) + * + * @param {mat4} out mat4 receiving operation result + * @param {quat4} q Rotation quaternion + * @param {vec3} v Translation vector + * @param {vec3} s Scaling vector + * @returns {mat4} out + */ + mat4.fromRotationTranslationScale = function (out, q, v, s) { + // Quaternion math + var x = q[0], y = q[1], z = q[2], w = q[3], + x2 = x + x, + y2 = y + y, + z2 = z + z, + + xx = x * x2, + xy = x * y2, + xz = x * z2, + yy = y * y2, + yz = y * z2, + zz = z * z2, + wx = w * x2, + wy = w * y2, + wz = w * z2, + sx = s[0], + sy = s[1], + sz = s[2]; + + out[0] = (1 - (yy + zz)) * sx; + out[1] = (xy + wz) * sx; + out[2] = (xz - wy) * sx; + out[3] = 0; + out[4] = (xy - wz) * sy; + out[5] = (1 - (xx + zz)) * sy; + out[6] = (yz + wx) * sy; + out[7] = 0; + out[8] = (xz + wy) * sz; + out[9] = (yz - wx) * sz; + out[10] = (1 - (xx + yy)) * sz; + out[11] = 0; + out[12] = v[0]; + out[13] = v[1]; + out[14] = v[2]; + out[15] = 1; + + return out; + }; + + /** + * Creates a matrix from a quaternion rotation, vector translation and vector scale, rotating and scaling around the given origin + * This is equivalent to (but much faster than): + * + * mat4.identity(dest); + * mat4.translate(dest, vec); + * mat4.translate(dest, origin); + * var quatMat = mat4.create(); + * quat4.toMat4(quat, quatMat); + * mat4.multiply(dest, quatMat); + * mat4.scale(dest, scale) + * mat4.translate(dest, negativeOrigin); + * + * @param {mat4} out mat4 receiving operation result + * @param {quat4} q Rotation quaternion + * @param {vec3} v Translation vector + * @param {vec3} s Scaling vector + * @param {vec3} o The origin vector around which to scale and rotate + * @returns {mat4} out + */ + mat4.fromRotationTranslationScaleOrigin = function (out, q, v, s, o) { + // Quaternion math + var x = q[0], y = q[1], z = q[2], w = q[3], + x2 = x + x, + y2 = y + y, + z2 = z + z, + + xx = x * x2, + xy = x * y2, + xz = x * z2, + yy = y * y2, + yz = y * z2, + zz = z * z2, + wx = w * x2, + wy = w * y2, + wz = w * z2, + + sx = s[0], + sy = s[1], + sz = s[2], + + ox = o[0], + oy = o[1], + oz = o[2]; + + out[0] = (1 - (yy + zz)) * sx; + out[1] = (xy + wz) * sx; + out[2] = (xz - wy) * sx; + out[3] = 0; + out[4] = (xy - wz) * sy; + out[5] = (1 - (xx + zz)) * sy; + out[6] = (yz + wx) * sy; + out[7] = 0; + out[8] = (xz + wy) * sz; + out[9] = (yz - wx) * sz; + out[10] = (1 - (xx + yy)) * sz; + out[11] = 0; + out[12] = v[0] + ox - (out[0] * ox + out[4] * oy + out[8] * oz); + out[13] = v[1] + oy - (out[1] * ox + out[5] * oy + out[9] * oz); + out[14] = v[2] + oz - (out[2] * ox + out[6] * oy + out[10] * oz); + out[15] = 1; + + return out; + }; + + /** + * Calculates a 4x4 matrix from the given quaternion + * + * @param {mat4} out mat4 receiving operation result + * @param {quat} q Quaternion to create matrix from + * + * @returns {mat4} out + */ + mat4.fromQuat = function (out, q) { + var x = q[0], y = q[1], z = q[2], w = q[3], + x2 = x + x, + y2 = y + y, + z2 = z + z, + + xx = x * x2, + yx = y * x2, + yy = y * y2, + zx = z * x2, + zy = z * y2, + zz = z * z2, + wx = w * x2, + wy = w * y2, + wz = w * z2; + + out[0] = 1 - yy - zz; + out[1] = yx + wz; + out[2] = zx - wy; + out[3] = 0; + + out[4] = yx - wz; + out[5] = 1 - xx - zz; + out[6] = zy + wx; + out[7] = 0; + + out[8] = zx + wy; + out[9] = zy - wx; + out[10] = 1 - xx - yy; + out[11] = 0; + + out[12] = 0; + out[13] = 0; + out[14] = 0; + out[15] = 1; + + return out; + }; + + /** + * Generates a frustum matrix with the given bounds + * + * @param {mat4} out mat4 frustum matrix will be written into + * @param {Number} left Left bound of the frustum + * @param {Number} right Right bound of the frustum + * @param {Number} bottom Bottom bound of the frustum + * @param {Number} top Top bound of the frustum + * @param {Number} near Near bound of the frustum + * @param {Number} far Far bound of the frustum + * @returns {mat4} out + */ + mat4.frustum = function (out, left, right, bottom, top, near, far) { + var rl = 1 / (right - left), + tb = 1 / (top - bottom), + nf = 1 / (near - far); + out[0] = (near * 2) * rl; + out[1] = 0; + out[2] = 0; + out[3] = 0; + out[4] = 0; + out[5] = (near * 2) * tb; + out[6] = 0; + out[7] = 0; + out[8] = (right + left) * rl; + out[9] = (top + bottom) * tb; + out[10] = (far + near) * nf; + out[11] = -1; + out[12] = 0; + out[13] = 0; + out[14] = (far * near * 2) * nf; + out[15] = 0; + return out; + }; + + /** + * Generates a perspective projection matrix with the given bounds + * + * @param {mat4} out mat4 frustum matrix will be written into + * @param {number} fovy Vertical field of view in radians + * @param {number} aspect Aspect ratio. typically viewport width/height + * @param {number} near Near bound of the frustum + * @param {number} far Far bound of the frustum + * @returns {mat4} out + */ + mat4.perspective = function (out, fovy, aspect, near, far) { + var f = 1.0 / Math.tan(fovy / 2), + nf = 1 / (near - far); + out[0] = f / aspect; + out[1] = 0; + out[2] = 0; + out[3] = 0; + out[4] = 0; + out[5] = f; + out[6] = 0; + out[7] = 0; + out[8] = 0; + out[9] = 0; + out[10] = (far + near) * nf; + out[11] = -1; + out[12] = 0; + out[13] = 0; + out[14] = (2 * far * near) * nf; + out[15] = 0; + return out; + }; + + /** + * Generates a perspective projection matrix with the given field of view. + * This is primarily useful for generating projection matrices to be used + * with the still experiemental WebVR API. + * + * @param {mat4} out mat4 frustum matrix will be written into + * @param {Object} fov Object containing the following values: upDegrees, downDegrees, leftDegrees, rightDegrees + * @param {number} near Near bound of the frustum + * @param {number} far Far bound of the frustum + * @returns {mat4} out + */ + mat4.perspectiveFromFieldOfView = function (out, fov, near, far) { + var upTan = Math.tan(fov.upDegrees * Math.PI/180.0), + downTan = Math.tan(fov.downDegrees * Math.PI/180.0), + leftTan = Math.tan(fov.leftDegrees * Math.PI/180.0), + rightTan = Math.tan(fov.rightDegrees * Math.PI/180.0), + xScale = 2.0 / (leftTan + rightTan), + yScale = 2.0 / (upTan + downTan); + + out[0] = xScale; + out[1] = 0.0; + out[2] = 0.0; + out[3] = 0.0; + out[4] = 0.0; + out[5] = yScale; + out[6] = 0.0; + out[7] = 0.0; + out[8] = -((leftTan - rightTan) * xScale * 0.5); + out[9] = ((upTan - downTan) * yScale * 0.5); + out[10] = far / (near - far); + out[11] = -1.0; + out[12] = 0.0; + out[13] = 0.0; + out[14] = (far * near) / (near - far); + out[15] = 0.0; + return out; + } + + /** + * Generates a orthogonal projection matrix with the given bounds + * + * @param {mat4} out mat4 frustum matrix will be written into + * @param {number} left Left bound of the frustum + * @param {number} right Right bound of the frustum + * @param {number} bottom Bottom bound of the frustum + * @param {number} top Top bound of the frustum + * @param {number} near Near bound of the frustum + * @param {number} far Far bound of the frustum + * @returns {mat4} out + */ + mat4.ortho = function (out, left, right, bottom, top, near, far) { + var lr = 1 / (left - right), + bt = 1 / (bottom - top), + nf = 1 / (near - far); + out[0] = -2 * lr; + out[1] = 0; + out[2] = 0; + out[3] = 0; + out[4] = 0; + out[5] = -2 * bt; + out[6] = 0; + out[7] = 0; + out[8] = 0; + out[9] = 0; + out[10] = 2 * nf; + out[11] = 0; + out[12] = (left + right) * lr; + out[13] = (top + bottom) * bt; + out[14] = (far + near) * nf; + out[15] = 1; + return out; + }; + + /** + * Generates a look-at matrix with the given eye position, focal point, and up axis + * + * @param {mat4} out mat4 frustum matrix will be written into + * @param {vec3} eye Position of the viewer + * @param {vec3} center Point the viewer is looking at + * @param {vec3} up vec3 pointing up + * @returns {mat4} out + */ + mat4.lookAt = function (out, eye, center, up) { + var x0, x1, x2, y0, y1, y2, z0, z1, z2, len, + eyex = eye[0], + eyey = eye[1], + eyez = eye[2], + upx = up[0], + upy = up[1], + upz = up[2], + centerx = center[0], + centery = center[1], + centerz = center[2]; + + if (Math.abs(eyex - centerx) < glMatrix.EPSILON && + Math.abs(eyey - centery) < glMatrix.EPSILON && + Math.abs(eyez - centerz) < glMatrix.EPSILON) { + return mat4.identity(out); + } + + z0 = eyex - centerx; + z1 = eyey - centery; + z2 = eyez - centerz; + + len = 1 / Math.sqrt(z0 * z0 + z1 * z1 + z2 * z2); + z0 *= len; + z1 *= len; + z2 *= len; + + x0 = upy * z2 - upz * z1; + x1 = upz * z0 - upx * z2; + x2 = upx * z1 - upy * z0; + len = Math.sqrt(x0 * x0 + x1 * x1 + x2 * x2); + if (!len) { + x0 = 0; + x1 = 0; + x2 = 0; + } else { + len = 1 / len; + x0 *= len; + x1 *= len; + x2 *= len; + } + + y0 = z1 * x2 - z2 * x1; + y1 = z2 * x0 - z0 * x2; + y2 = z0 * x1 - z1 * x0; + + len = Math.sqrt(y0 * y0 + y1 * y1 + y2 * y2); + if (!len) { + y0 = 0; + y1 = 0; + y2 = 0; + } else { + len = 1 / len; + y0 *= len; + y1 *= len; + y2 *= len; + } + + out[0] = x0; + out[1] = y0; + out[2] = z0; + out[3] = 0; + out[4] = x1; + out[5] = y1; + out[6] = z1; + out[7] = 0; + out[8] = x2; + out[9] = y2; + out[10] = z2; + out[11] = 0; + out[12] = -(x0 * eyex + x1 * eyey + x2 * eyez); + out[13] = -(y0 * eyex + y1 * eyey + y2 * eyez); + out[14] = -(z0 * eyex + z1 * eyey + z2 * eyez); + out[15] = 1; + + return out; + }; + + /** + * Returns a string representation of a mat4 + * + * @param {mat4} a matrix to represent as a string + * @returns {String} string representation of the matrix + */ + mat4.str = function (a) { + return 'mat4(' + a[0] + ', ' + a[1] + ', ' + a[2] + ', ' + a[3] + ', ' + + a[4] + ', ' + a[5] + ', ' + a[6] + ', ' + a[7] + ', ' + + a[8] + ', ' + a[9] + ', ' + a[10] + ', ' + a[11] + ', ' + + a[12] + ', ' + a[13] + ', ' + a[14] + ', ' + a[15] + ')'; + }; + + /** + * Returns Frobenius norm of a mat4 + * + * @param {mat4} a the matrix to calculate Frobenius norm of + * @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[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) )) + }; + + /** + * Adds two mat4's + * + * @param {mat4} out the receiving matrix + * @param {mat4} a the first operand + * @param {mat4} b the second operand + * @returns {mat4} out + */ + mat4.add = function(out, a, b) { + out[0] = a[0] + b[0]; + out[1] = a[1] + b[1]; + out[2] = a[2] + b[2]; + out[3] = a[3] + b[3]; + out[4] = a[4] + b[4]; + out[5] = a[5] + b[5]; + out[6] = a[6] + b[6]; + out[7] = a[7] + b[7]; + out[8] = a[8] + b[8]; + out[9] = a[9] + b[9]; + out[10] = a[10] + b[10]; + out[11] = a[11] + b[11]; + out[12] = a[12] + b[12]; + out[13] = a[13] + b[13]; + out[14] = a[14] + b[14]; + out[15] = a[15] + b[15]; + return out; + }; + + /** + * Subtracts matrix b from matrix a + * + * @param {mat4} out the receiving matrix + * @param {mat4} a the first operand + * @param {mat4} b the second operand + * @returns {mat4} out + */ + mat4.subtract = function(out, a, b) { + out[0] = a[0] - b[0]; + out[1] = a[1] - b[1]; + out[2] = a[2] - b[2]; + out[3] = a[3] - b[3]; + out[4] = a[4] - b[4]; + out[5] = a[5] - b[5]; + out[6] = a[6] - b[6]; + out[7] = a[7] - b[7]; + out[8] = a[8] - b[8]; + out[9] = a[9] - b[9]; + out[10] = a[10] - b[10]; + out[11] = a[11] - b[11]; + out[12] = a[12] - b[12]; + out[13] = a[13] - b[13]; + out[14] = a[14] - b[14]; + out[15] = a[15] - b[15]; + return out; + }; + + /** + * Alias for {@link mat4.subtract} + * @function + */ + mat4.sub = mat4.subtract; + + /** + * Multiply each element of the matrix by a scalar. + * + * @param {mat4} out the receiving matrix + * @param {mat4} a the matrix to scale + * @param {Number} b amount to scale the matrix's elements by + * @returns {mat4} out + */ + mat4.multiplyScalar = function(out, a, b) { + out[0] = a[0] * b; + out[1] = a[1] * b; + out[2] = a[2] * b; + out[3] = a[3] * b; + out[4] = a[4] * b; + out[5] = a[5] * b; + out[6] = a[6] * b; + out[7] = a[7] * b; + out[8] = a[8] * b; + out[9] = a[9] * b; + out[10] = a[10] * b; + out[11] = a[11] * b; + out[12] = a[12] * b; + out[13] = a[13] * b; + out[14] = a[14] * b; + out[15] = a[15] * b; + return out; + }; + + /** + * Adds two mat4's after multiplying each element of the second operand by a scalar value. + * + * @param {mat4} out the receiving vector + * @param {mat4} a the first operand + * @param {mat4} b the second operand + * @param {Number} scale the amount to scale b's elements by before adding + * @returns {mat4} out + */ + mat4.multiplyScalarAndAdd = function(out, a, b, scale) { + out[0] = a[0] + (b[0] * scale); + out[1] = a[1] + (b[1] * scale); + out[2] = a[2] + (b[2] * scale); + out[3] = a[3] + (b[3] * scale); + out[4] = a[4] + (b[4] * scale); + out[5] = a[5] + (b[5] * scale); + out[6] = a[6] + (b[6] * scale); + out[7] = a[7] + (b[7] * scale); + out[8] = a[8] + (b[8] * scale); + out[9] = a[9] + (b[9] * scale); + out[10] = a[10] + (b[10] * scale); + out[11] = a[11] + (b[11] * scale); + out[12] = a[12] + (b[12] * scale); + out[13] = a[13] + (b[13] * scale); + out[14] = a[14] + (b[14] * scale); + out[15] = a[15] + (b[15] * scale); + return out; + }; + + /** + * Returns whether or not the matrices have exactly the same elements in the same position (when compared with ===) + * + * @param {mat4} a The first matrix. + * @param {mat4} b The second matrix. + * @returns {Boolean} True if the matrices are equal, false otherwise. + */ + mat4.exactEquals = function (a, b) { + return a[0] === b[0] && a[1] === b[1] && a[2] === b[2] && a[3] === b[3] && + a[4] === b[4] && a[5] === b[5] && a[6] === b[6] && a[7] === b[7] && + a[8] === b[8] && a[9] === b[9] && a[10] === b[10] && a[11] === b[11] && + a[12] === b[12] && a[13] === b[13] && a[14] === b[14] && a[15] === b[15]; + }; + + /** + * Returns whether or not the matrices have approximately the same elements in the same position. + * + * @param {mat4} a The first matrix. + * @param {mat4} b The second matrix. + * @returns {Boolean} True if the matrices are equal, false otherwise. + */ + mat4.equals = function (a, b) { + var a0 = a[0], a1 = a[1], a2 = a[2], a3 = a[3], + a4 = a[4], a5 = a[5], a6 = a[6], a7 = a[7], + a8 = a[8], a9 = a[9], a10 = a[10], a11 = a[11], + a12 = a[12], a13 = a[13], a14 = a[14], a15 = a[15]; + + var b0 = b[0], b1 = b[1], b2 = b[2], b3 = b[3], + b4 = b[4], b5 = b[5], b6 = b[6], b7 = b[7], + b8 = b[8], b9 = b[9], b10 = b[10], b11 = b[11], + b12 = b[12], b13 = b[13], b14 = b[14], b15 = b[15]; + + return (Math.abs(a0 - b0) <= glMatrix.EPSILON*Math.max(1.0, Math.abs(a0), Math.abs(b0)) && + Math.abs(a1 - b1) <= glMatrix.EPSILON*Math.max(1.0, Math.abs(a1), Math.abs(b1)) && + Math.abs(a2 - b2) <= glMatrix.EPSILON*Math.max(1.0, Math.abs(a2), Math.abs(b2)) && + Math.abs(a3 - b3) <= glMatrix.EPSILON*Math.max(1.0, Math.abs(a3), Math.abs(b3)) && + Math.abs(a4 - b4) <= glMatrix.EPSILON*Math.max(1.0, Math.abs(a4), Math.abs(b4)) && + Math.abs(a5 - b5) <= glMatrix.EPSILON*Math.max(1.0, Math.abs(a5), Math.abs(b5)) && + Math.abs(a6 - b6) <= glMatrix.EPSILON*Math.max(1.0, Math.abs(a6), Math.abs(b6)) && + Math.abs(a7 - b7) <= glMatrix.EPSILON*Math.max(1.0, Math.abs(a7), Math.abs(b7)) && + Math.abs(a8 - b8) <= glMatrix.EPSILON*Math.max(1.0, Math.abs(a8), Math.abs(b8)) && + Math.abs(a9 - b9) <= glMatrix.EPSILON*Math.max(1.0, Math.abs(a9), Math.abs(b9)) && + Math.abs(a10 - b10) <= glMatrix.EPSILON*Math.max(1.0, Math.abs(a10), Math.abs(b10)) && + Math.abs(a11 - b11) <= glMatrix.EPSILON*Math.max(1.0, Math.abs(a11), Math.abs(b11)) && + Math.abs(a12 - b12) <= glMatrix.EPSILON*Math.max(1.0, Math.abs(a12), Math.abs(b12)) && + Math.abs(a13 - b13) <= glMatrix.EPSILON*Math.max(1.0, Math.abs(a13), Math.abs(b13)) && + Math.abs(a14 - b14) <= glMatrix.EPSILON*Math.max(1.0, Math.abs(a14), Math.abs(b14)) && + Math.abs(a15 - b15) <= glMatrix.EPSILON*Math.max(1.0, Math.abs(a15), Math.abs(b15))); + }; + + + + module.exports = mat4; + + +/***/ }, +/* 6 */ +/***/ function(module, exports, __webpack_require__) { + + /* Copyright (c) 2015, Brandon Jones, Colin MacKenzie IV. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. */ + + var glMatrix = __webpack_require__(1); + var mat3 = __webpack_require__(4); + var vec3 = __webpack_require__(7); + var vec4 = __webpack_require__(8); + + /** + * @class Quaternion + * @name quat + */ + var quat = {}; + + /** + * Creates a new identity quat + * + * @returns {quat} a new quaternion + */ + quat.create = function() { + var out = new glMatrix.ARRAY_TYPE(4); + out[0] = 0; + out[1] = 0; + out[2] = 0; + out[3] = 1; + return out; + }; + + /** + * Sets a quaternion to represent the shortest rotation from one + * vector to another. + * + * Both vectors are assumed to be unit length. + * + * @param {quat} out the receiving quaternion. + * @param {vec3} a the initial vector + * @param {vec3} b the destination vector + * @returns {quat} out + */ + quat.rotationTo = (function() { + var tmpvec3 = vec3.create(); + var xUnitVec3 = vec3.fromValues(1,0,0); + var yUnitVec3 = vec3.fromValues(0,1,0); + + return function(out, a, b) { + var dot = vec3.dot(a, b); + if (dot < -0.999999) { + vec3.cross(tmpvec3, xUnitVec3, a); + if (vec3.length(tmpvec3) < 0.000001) + vec3.cross(tmpvec3, yUnitVec3, a); + vec3.normalize(tmpvec3, tmpvec3); + quat.setAxisAngle(out, tmpvec3, Math.PI); + return out; + } else if (dot > 0.999999) { + out[0] = 0; + out[1] = 0; + out[2] = 0; + out[3] = 1; + return out; + } else { + vec3.cross(tmpvec3, a, b); + out[0] = tmpvec3[0]; + out[1] = tmpvec3[1]; + out[2] = tmpvec3[2]; + out[3] = 1 + dot; + return quat.normalize(out, out); + } + }; + })(); + + /** + * Sets the specified quaternion with values corresponding to the given + * axes. Each axis is a vec3 and is expected to be unit length and + * perpendicular to all other specified axes. + * + * @param {vec3} view the vector representing the viewing direction + * @param {vec3} right the vector representing the local "right" direction + * @param {vec3} up the vector representing the local "up" direction + * @returns {quat} out + */ + quat.setAxes = (function() { + var matr = mat3.create(); + + return function(out, view, right, up) { + matr[0] = right[0]; + matr[3] = right[1]; + matr[6] = right[2]; + + matr[1] = up[0]; + matr[4] = up[1]; + matr[7] = up[2]; + + matr[2] = -view[0]; + matr[5] = -view[1]; + matr[8] = -view[2]; + + return quat.normalize(out, quat.fromMat3(out, matr)); + }; + })(); + + /** + * Creates a new quat initialized with values from an existing quaternion + * + * @param {quat} a quaternion to clone + * @returns {quat} a new quaternion + * @function + */ + quat.clone = vec4.clone; + + /** + * Creates a new quat initialized with the given values + * + * @param {Number} x X component + * @param {Number} y Y component + * @param {Number} z Z component + * @param {Number} w W component + * @returns {quat} a new quaternion + * @function + */ + quat.fromValues = vec4.fromValues; + + /** + * Copy the values from one quat to another + * + * @param {quat} out the receiving quaternion + * @param {quat} a the source quaternion + * @returns {quat} out + * @function + */ + quat.copy = vec4.copy; + + /** + * Set the components of a quat to the given values + * + * @param {quat} out the receiving quaternion + * @param {Number} x X component + * @param {Number} y Y component + * @param {Number} z Z component + * @param {Number} w W component + * @returns {quat} out + * @function + */ + quat.set = vec4.set; + + /** + * Set a quat to the identity quaternion + * + * @param {quat} out the receiving quaternion + * @returns {quat} out + */ + quat.identity = function(out) { + out[0] = 0; + out[1] = 0; + out[2] = 0; + out[3] = 1; + return out; + }; + + /** + * Sets a quat from the given angle and rotation axis, + * then returns it. + * + * @param {quat} out the receiving quaternion + * @param {vec3} axis the axis around which to rotate + * @param {Number} rad the angle in radians + * @returns {quat} out + **/ + quat.setAxisAngle = function(out, axis, rad) { + rad = rad * 0.5; + var s = Math.sin(rad); + out[0] = s * axis[0]; + out[1] = s * axis[1]; + out[2] = s * axis[2]; + out[3] = Math.cos(rad); + return out; + }; + + /** + * Gets the rotation axis and angle for a given + * quaternion. If a quaternion is created with + * setAxisAngle, this method will return the same + * values as providied in the original parameter list + * OR functionally equivalent values. + * Example: The quaternion formed by axis [0, 0, 1] and + * angle -90 is the same as the quaternion formed by + * [0, 0, 1] and 270. This method favors the latter. + * @param {vec3} out_axis Vector receiving the axis of rotation + * @param {quat} q Quaternion to be decomposed + * @return {Number} Angle, in radians, of the rotation + */ + quat.getAxisAngle = function(out_axis, q) { + var rad = Math.acos(q[3]) * 2.0; + var s = Math.sin(rad / 2.0); + if (s != 0.0) { + out_axis[0] = q[0] / s; + out_axis[1] = q[1] / s; + out_axis[2] = q[2] / s; + } else { + // If s is zero, return any axis (no rotation - axis does not matter) + out_axis[0] = 1; + out_axis[1] = 0; + out_axis[2] = 0; + } + return rad; + }; + + /** + * Adds two quat's + * + * @param {quat} out the receiving quaternion + * @param {quat} a the first operand + * @param {quat} b the second operand + * @returns {quat} out + * @function + */ + quat.add = vec4.add; + + /** + * Multiplies two quat's + * + * @param {quat} out the receiving quaternion + * @param {quat} a the first operand + * @param {quat} b the second operand + * @returns {quat} out + */ + quat.multiply = function(out, a, b) { + var ax = a[0], ay = a[1], az = a[2], aw = a[3], + bx = b[0], by = b[1], bz = b[2], bw = b[3]; + + out[0] = ax * bw + aw * bx + ay * bz - az * by; + out[1] = ay * bw + aw * by + az * bx - ax * bz; + out[2] = az * bw + aw * bz + ax * by - ay * bx; + out[3] = aw * bw - ax * bx - ay * by - az * bz; + return out; + }; + + /** + * Alias for {@link quat.multiply} + * @function + */ + quat.mul = quat.multiply; + + /** + * Scales a quat by a scalar number + * + * @param {quat} out the receiving vector + * @param {quat} a the vector to scale + * @param {Number} b amount to scale the vector by + * @returns {quat} out + * @function + */ + quat.scale = vec4.scale; + + /** + * Rotates a quaternion by the given angle about the X axis + * + * @param {quat} out quat receiving operation result + * @param {quat} a quat to rotate + * @param {number} rad angle (in radians) to rotate + * @returns {quat} out + */ + quat.rotateX = function (out, a, rad) { + rad *= 0.5; + + var ax = a[0], ay = a[1], az = a[2], aw = a[3], + bx = Math.sin(rad), bw = Math.cos(rad); + + out[0] = ax * bw + aw * bx; + out[1] = ay * bw + az * bx; + out[2] = az * bw - ay * bx; + out[3] = aw * bw - ax * bx; + return out; + }; + + /** + * Rotates a quaternion by the given angle about the Y axis + * + * @param {quat} out quat receiving operation result + * @param {quat} a quat to rotate + * @param {number} rad angle (in radians) to rotate + * @returns {quat} out + */ + quat.rotateY = function (out, a, rad) { + rad *= 0.5; + + var ax = a[0], ay = a[1], az = a[2], aw = a[3], + by = Math.sin(rad), bw = Math.cos(rad); + + out[0] = ax * bw - az * by; + out[1] = ay * bw + aw * by; + out[2] = az * bw + ax * by; + out[3] = aw * bw - ay * by; + return out; + }; + + /** + * Rotates a quaternion by the given angle about the Z axis + * + * @param {quat} out quat receiving operation result + * @param {quat} a quat to rotate + * @param {number} rad angle (in radians) to rotate + * @returns {quat} out + */ + quat.rotateZ = function (out, a, rad) { + rad *= 0.5; + + var ax = a[0], ay = a[1], az = a[2], aw = a[3], + bz = Math.sin(rad), bw = Math.cos(rad); + + out[0] = ax * bw + ay * bz; + out[1] = ay * bw - ax * bz; + out[2] = az * bw + aw * bz; + out[3] = aw * bw - az * bz; + return out; + }; + + /** + * Calculates the W component of a quat from the X, Y, and Z components. + * Assumes that quaternion is 1 unit in length. + * Any existing W component will be ignored. + * + * @param {quat} out the receiving quaternion + * @param {quat} a quat to calculate W component of + * @returns {quat} out + */ + quat.calculateW = function (out, a) { + var x = a[0], y = a[1], z = a[2]; + + out[0] = x; + out[1] = y; + out[2] = z; + out[3] = Math.sqrt(Math.abs(1.0 - x * x - y * y - z * z)); + return out; + }; + + /** + * Calculates the dot product of two quat's + * + * @param {quat} a the first operand + * @param {quat} b the second operand + * @returns {Number} dot product of a and b + * @function + */ + quat.dot = vec4.dot; + + /** + * Performs a linear interpolation between two quat's + * + * @param {quat} out the receiving quaternion + * @param {quat} a the first operand + * @param {quat} b the second operand + * @param {Number} t interpolation amount between the two inputs + * @returns {quat} out + * @function + */ + quat.lerp = vec4.lerp; + + /** + * Performs a spherical linear interpolation between two quat + * + * @param {quat} out the receiving quaternion + * @param {quat} a the first operand + * @param {quat} b the second operand + * @param {Number} t interpolation amount between the two inputs + * @returns {quat} out + */ + quat.slerp = function (out, a, b, t) { + // benchmarks: + // http://jsperf.com/quaternion-slerp-implementations + + var ax = a[0], ay = a[1], az = a[2], aw = a[3], + bx = b[0], by = b[1], bz = b[2], bw = b[3]; + + var omega, cosom, sinom, scale0, scale1; + + // calc cosine + cosom = ax * bx + ay * by + az * bz + aw * bw; + // adjust signs (if necessary) + if ( cosom < 0.0 ) { + cosom = -cosom; + bx = - bx; + by = - by; + bz = - bz; + bw = - bw; + } + // calculate coefficients + if ( (1.0 - cosom) > 0.000001 ) { + // standard case (slerp) + omega = Math.acos(cosom); + sinom = Math.sin(omega); + scale0 = Math.sin((1.0 - t) * omega) / sinom; + scale1 = Math.sin(t * omega) / sinom; + } else { + // "from" and "to" quaternions are very close + // ... so we can do a linear interpolation + scale0 = 1.0 - t; + scale1 = t; + } + // calculate final values + out[0] = scale0 * ax + scale1 * bx; + out[1] = scale0 * ay + scale1 * by; + out[2] = scale0 * az + scale1 * bz; + out[3] = scale0 * aw + scale1 * bw; + + return out; + }; + + /** + * Performs a spherical linear interpolation with two control points + * + * @param {quat} out the receiving quaternion + * @param {quat} a the first operand + * @param {quat} b the second operand + * @param {quat} c the third operand + * @param {quat} d the fourth operand + * @param {Number} t interpolation amount + * @returns {quat} out + */ + quat.sqlerp = (function () { + var temp1 = quat.create(); + var temp2 = quat.create(); + + return function (out, a, b, c, d, t) { + quat.slerp(temp1, a, d, t); + quat.slerp(temp2, b, c, t); + quat.slerp(out, temp1, temp2, 2 * t * (1 - t)); + + return out; + }; + }()); + + /** + * Calculates the inverse of a quat + * + * @param {quat} out the receiving quaternion + * @param {quat} a quat to calculate inverse of + * @returns {quat} out + */ + quat.invert = function(out, a) { + var a0 = a[0], a1 = a[1], a2 = a[2], a3 = a[3], + dot = a0*a0 + a1*a1 + a2*a2 + a3*a3, + invDot = dot ? 1.0/dot : 0; + + // TODO: Would be faster to return [0,0,0,0] immediately if dot == 0 + + out[0] = -a0*invDot; + out[1] = -a1*invDot; + out[2] = -a2*invDot; + out[3] = a3*invDot; + return out; + }; + + /** + * Calculates the conjugate of a quat + * If the quaternion is normalized, this function is faster than quat.inverse and produces the same result. + * + * @param {quat} out the receiving quaternion + * @param {quat} a quat to calculate conjugate of + * @returns {quat} out + */ + quat.conjugate = function (out, a) { + out[0] = -a[0]; + out[1] = -a[1]; + out[2] = -a[2]; + out[3] = a[3]; + return out; + }; + + /** + * Calculates the length of a quat + * + * @param {quat} a vector to calculate length of + * @returns {Number} length of a + * @function + */ + quat.length = vec4.length; + + /** + * Alias for {@link quat.length} + * @function + */ + quat.len = quat.length; + + /** + * Calculates the squared length of a quat + * + * @param {quat} a vector to calculate squared length of + * @returns {Number} squared length of a + * @function + */ + quat.squaredLength = vec4.squaredLength; + + /** + * Alias for {@link quat.squaredLength} + * @function + */ + quat.sqrLen = quat.squaredLength; + + /** + * Normalize a quat + * + * @param {quat} out the receiving quaternion + * @param {quat} a quaternion to normalize + * @returns {quat} out + * @function + */ + quat.normalize = vec4.normalize; + + /** + * Creates a quaternion from the given 3x3 rotation matrix. + * + * NOTE: The resultant quaternion is not normalized, so you should be sure + * to renormalize the quaternion yourself where necessary. + * + * @param {quat} out the receiving quaternion + * @param {mat3} m rotation matrix + * @returns {quat} out + * @function + */ + quat.fromMat3 = function(out, m) { + // Algorithm in Ken Shoemake's article in 1987 SIGGRAPH course notes + // article "Quaternion Calculus and Fast Animation". + var fTrace = m[0] + m[4] + m[8]; + var fRoot; + + if ( fTrace > 0.0 ) { + // |w| > 1/2, may as well choose w > 1/2 + fRoot = Math.sqrt(fTrace + 1.0); // 2w + out[3] = 0.5 * fRoot; + fRoot = 0.5/fRoot; // 1/(4w) + 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; + if ( m[4] > m[0] ) + i = 1; + if ( m[8] > m[i*3+i] ) + i = 2; + var j = (i+1)%3; + var k = (i+2)%3; + + 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[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; + } + + return out; + }; + + /** + * Returns a string representation of a quatenion + * + * @param {quat} a vector to represent as a string + * @returns {String} string representation of the vector + */ + quat.str = function (a) { + return 'quat(' + a[0] + ', ' + a[1] + ', ' + a[2] + ', ' + a[3] + ')'; + }; + + /** + * Returns whether or not the quaternions have exactly the same elements in the same position (when compared with ===) + * + * @param {quat} a The first quaternion. + * @param {quat} b The second quaternion. + * @returns {Boolean} True if the vectors are equal, false otherwise. + */ + quat.exactEquals = vec4.exactEquals; + + /** + * Returns whether or not the quaternions have approximately the same elements in the same position. + * + * @param {quat} a The first vector. + * @param {quat} b The second vector. + * @returns {Boolean} True if the vectors are equal, false otherwise. + */ + quat.equals = vec4.equals; + + module.exports = quat; + + +/***/ }, +/* 7 */ +/***/ function(module, exports, __webpack_require__) { + + /* Copyright (c) 2015, Brandon Jones, Colin MacKenzie IV. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. */ + + var glMatrix = __webpack_require__(1); + + /** + * @class 3 Dimensional Vector + * @name vec3 + */ + var vec3 = {}; + + /** + * Creates a new, empty vec3 + * + * @returns {vec3} a new 3D vector + */ + vec3.create = function() { + var out = new glMatrix.ARRAY_TYPE(3); + out[0] = 0; + out[1] = 0; + out[2] = 0; + return out; + }; + + /** + * Creates a new vec3 initialized with values from an existing vector + * + * @param {vec3} a vector to clone + * @returns {vec3} a new 3D vector + */ + vec3.clone = function(a) { + var out = new glMatrix.ARRAY_TYPE(3); + out[0] = a[0]; + out[1] = a[1]; + out[2] = a[2]; + return out; + }; + + /** + * Creates a new vec3 initialized with the given values + * + * @param {Number} x X component + * @param {Number} y Y component + * @param {Number} z Z component + * @returns {vec3} a new 3D vector + */ + vec3.fromValues = function(x, y, z) { + var out = new glMatrix.ARRAY_TYPE(3); + out[0] = x; + out[1] = y; + out[2] = z; + return out; + }; + + /** + * Copy the values from one vec3 to another + * + * @param {vec3} out the receiving vector + * @param {vec3} a the source vector + * @returns {vec3} out + */ + vec3.copy = function(out, a) { + out[0] = a[0]; + out[1] = a[1]; + out[2] = a[2]; + return out; + }; + + /** + * Set the components of a vec3 to the given values + * + * @param {vec3} out the receiving vector + * @param {Number} x X component + * @param {Number} y Y component + * @param {Number} z Z component + * @returns {vec3} out + */ + vec3.set = function(out, x, y, z) { + out[0] = x; + out[1] = y; + out[2] = z; + return out; + }; + + /** + * Adds two vec3's + * + * @param {vec3} out the receiving vector + * @param {vec3} a the first operand + * @param {vec3} b the second operand + * @returns {vec3} out + */ + vec3.add = function(out, a, b) { + out[0] = a[0] + b[0]; + out[1] = a[1] + b[1]; + out[2] = a[2] + b[2]; + return out; + }; + + /** + * Subtracts vector b from vector a + * + * @param {vec3} out the receiving vector + * @param {vec3} a the first operand + * @param {vec3} b the second operand + * @returns {vec3} out + */ + vec3.subtract = function(out, a, b) { + out[0] = a[0] - b[0]; + out[1] = a[1] - b[1]; + out[2] = a[2] - b[2]; + return out; + }; + + /** + * Alias for {@link vec3.subtract} + * @function + */ + vec3.sub = vec3.subtract; + + /** + * Multiplies two vec3's + * + * @param {vec3} out the receiving vector + * @param {vec3} a the first operand + * @param {vec3} b the second operand + * @returns {vec3} out + */ + vec3.multiply = function(out, a, b) { + out[0] = a[0] * b[0]; + out[1] = a[1] * b[1]; + out[2] = a[2] * b[2]; + return out; + }; + + /** + * Alias for {@link vec3.multiply} + * @function + */ + vec3.mul = vec3.multiply; + + /** + * Divides two vec3's + * + * @param {vec3} out the receiving vector + * @param {vec3} a the first operand + * @param {vec3} b the second operand + * @returns {vec3} out + */ + vec3.divide = function(out, a, b) { + out[0] = a[0] / b[0]; + out[1] = a[1] / b[1]; + out[2] = a[2] / b[2]; + return out; + }; + + /** + * Alias for {@link vec3.divide} + * @function + */ + vec3.div = vec3.divide; + + /** + * Math.ceil the components of a vec3 + * + * @param {vec3} out the receiving vector + * @param {vec3} a vector to ceil + * @returns {vec3} out + */ + vec3.ceil = function (out, a) { + out[0] = Math.ceil(a[0]); + out[1] = Math.ceil(a[1]); + out[2] = Math.ceil(a[2]); + return out; + }; + + /** + * Math.floor the components of a vec3 + * + * @param {vec3} out the receiving vector + * @param {vec3} a vector to floor + * @returns {vec3} out + */ + vec3.floor = function (out, a) { + out[0] = Math.floor(a[0]); + out[1] = Math.floor(a[1]); + out[2] = Math.floor(a[2]); + return out; + }; + + /** + * Returns the minimum of two vec3's + * + * @param {vec3} out the receiving vector + * @param {vec3} a the first operand + * @param {vec3} b the second operand + * @returns {vec3} out + */ + vec3.min = function(out, a, b) { + out[0] = Math.min(a[0], b[0]); + out[1] = Math.min(a[1], b[1]); + out[2] = Math.min(a[2], b[2]); + return out; + }; + + /** + * Returns the maximum of two vec3's + * + * @param {vec3} out the receiving vector + * @param {vec3} a the first operand + * @param {vec3} b the second operand + * @returns {vec3} out + */ + vec3.max = function(out, a, b) { + out[0] = Math.max(a[0], b[0]); + out[1] = Math.max(a[1], b[1]); + out[2] = Math.max(a[2], b[2]); + return out; + }; + + /** + * Math.round the components of a vec3 + * + * @param {vec3} out the receiving vector + * @param {vec3} a vector to round + * @returns {vec3} out + */ + vec3.round = function (out, a) { + out[0] = Math.round(a[0]); + out[1] = Math.round(a[1]); + out[2] = Math.round(a[2]); + return out; + }; + + /** + * Scales a vec3 by a scalar number + * + * @param {vec3} out the receiving vector + * @param {vec3} a the vector to scale + * @param {Number} b amount to scale the vector by + * @returns {vec3} out + */ + vec3.scale = function(out, a, b) { + out[0] = a[0] * b; + out[1] = a[1] * b; + out[2] = a[2] * b; + return out; + }; + + /** + * Adds two vec3's after scaling the second operand by a scalar value + * + * @param {vec3} out the receiving vector + * @param {vec3} a the first operand + * @param {vec3} b the second operand + * @param {Number} scale the amount to scale b by before adding + * @returns {vec3} out + */ + vec3.scaleAndAdd = function(out, a, b, scale) { + out[0] = a[0] + (b[0] * scale); + out[1] = a[1] + (b[1] * scale); + out[2] = a[2] + (b[2] * scale); + return out; + }; + + /** + * Calculates the euclidian distance between two vec3's + * + * @param {vec3} a the first operand + * @param {vec3} b the second operand + * @returns {Number} distance between a and b + */ + vec3.distance = function(a, b) { + var x = b[0] - a[0], + y = b[1] - a[1], + z = b[2] - a[2]; + return Math.sqrt(x*x + y*y + z*z); + }; + + /** + * Alias for {@link vec3.distance} + * @function + */ + vec3.dist = vec3.distance; + + /** + * Calculates the squared euclidian distance between two vec3's + * + * @param {vec3} a the first operand + * @param {vec3} b the second operand + * @returns {Number} squared distance between a and b + */ + vec3.squaredDistance = function(a, b) { + var x = b[0] - a[0], + y = b[1] - a[1], + z = b[2] - a[2]; + return x*x + y*y + z*z; + }; + + /** + * Alias for {@link vec3.squaredDistance} + * @function + */ + vec3.sqrDist = vec3.squaredDistance; + + /** + * Calculates the length of a vec3 + * + * @param {vec3} a vector to calculate length of + * @returns {Number} length of a + */ + vec3.length = function (a) { + var x = a[0], + y = a[1], + z = a[2]; + return Math.sqrt(x*x + y*y + z*z); + }; + + /** + * Alias for {@link vec3.length} + * @function + */ + vec3.len = vec3.length; + + /** + * Calculates the squared length of a vec3 + * + * @param {vec3} a vector to calculate squared length of + * @returns {Number} squared length of a + */ + vec3.squaredLength = function (a) { + var x = a[0], + y = a[1], + z = a[2]; + return x*x + y*y + z*z; + }; + + /** + * Alias for {@link vec3.squaredLength} + * @function + */ + vec3.sqrLen = vec3.squaredLength; + + /** + * Negates the components of a vec3 + * + * @param {vec3} out the receiving vector + * @param {vec3} a vector to negate + * @returns {vec3} out + */ + vec3.negate = function(out, a) { + out[0] = -a[0]; + out[1] = -a[1]; + out[2] = -a[2]; + 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 + * + * @param {vec3} out the receiving vector + * @param {vec3} a vector to normalize + * @returns {vec3} out + */ + vec3.normalize = function(out, a) { + var x = a[0], + y = a[1], + z = a[2]; + var len = x*x + y*y + z*z; + if (len > 0) { + //TODO: evaluate use of glm_invsqrt here? + len = 1 / Math.sqrt(len); + out[0] = a[0] * len; + out[1] = a[1] * len; + out[2] = a[2] * len; + } + return out; + }; + + /** + * Calculates the dot product of two vec3's + * + * @param {vec3} a the first operand + * @param {vec3} b the second operand + * @returns {Number} dot product of a and b + */ + vec3.dot = function (a, b) { + return a[0] * b[0] + a[1] * b[1] + a[2] * b[2]; + }; + + /** + * Computes the cross product of two vec3's + * + * @param {vec3} out the receiving vector + * @param {vec3} a the first operand + * @param {vec3} b the second operand + * @returns {vec3} out + */ + vec3.cross = function(out, a, b) { + var ax = a[0], ay = a[1], az = a[2], + bx = b[0], by = b[1], bz = b[2]; + + out[0] = ay * bz - az * by; + out[1] = az * bx - ax * bz; + out[2] = ax * by - ay * bx; + return out; + }; + + /** + * Performs a linear interpolation between two vec3's + * + * @param {vec3} out the receiving vector + * @param {vec3} a the first operand + * @param {vec3} b the second operand + * @param {Number} t interpolation amount between the two inputs + * @returns {vec3} out + */ + vec3.lerp = function (out, a, b, t) { + var ax = a[0], + ay = a[1], + az = a[2]; + out[0] = ax + t * (b[0] - ax); + out[1] = ay + t * (b[1] - ay); + out[2] = az + t * (b[2] - az); + return out; + }; + + /** + * Performs a hermite interpolation with two control points + * + * @param {vec3} out the receiving vector + * @param {vec3} a the first operand + * @param {vec3} b the second operand + * @param {vec3} c the third operand + * @param {vec3} d the fourth operand + * @param {Number} t interpolation amount between the two inputs + * @returns {vec3} out + */ + vec3.hermite = function (out, a, b, c, d, t) { + var factorTimes2 = t * t, + factor1 = factorTimes2 * (2 * t - 3) + 1, + factor2 = factorTimes2 * (t - 2) + t, + factor3 = factorTimes2 * (t - 1), + factor4 = factorTimes2 * (3 - 2 * t); + + out[0] = a[0] * factor1 + b[0] * factor2 + c[0] * factor3 + d[0] * factor4; + out[1] = a[1] * factor1 + b[1] * factor2 + c[1] * factor3 + d[1] * factor4; + out[2] = a[2] * factor1 + b[2] * factor2 + c[2] * factor3 + d[2] * factor4; + + return out; + }; + + /** + * Performs a bezier interpolation with two control points + * + * @param {vec3} out the receiving vector + * @param {vec3} a the first operand + * @param {vec3} b the second operand + * @param {vec3} c the third operand + * @param {vec3} d the fourth operand + * @param {Number} t interpolation amount between the two inputs + * @returns {vec3} out + */ + vec3.bezier = function (out, a, b, c, d, t) { + var inverseFactor = 1 - t, + inverseFactorTimesTwo = inverseFactor * inverseFactor, + factorTimes2 = t * t, + factor1 = inverseFactorTimesTwo * inverseFactor, + factor2 = 3 * t * inverseFactorTimesTwo, + factor3 = 3 * factorTimes2 * inverseFactor, + factor4 = factorTimes2 * t; + + out[0] = a[0] * factor1 + b[0] * factor2 + c[0] * factor3 + d[0] * factor4; + out[1] = a[1] * factor1 + b[1] * factor2 + c[1] * factor3 + d[1] * factor4; + out[2] = a[2] * factor1 + b[2] * factor2 + c[2] * factor3 + d[2] * factor4; + + return out; + }; + + /** + * Generates a random vector with the given scale + * + * @param {vec3} out the receiving vector + * @param {Number} [scale] Length of the resulting vector. If ommitted, a unit vector will be returned + * @returns {vec3} out + */ + vec3.random = function (out, scale) { + scale = scale || 1.0; + + var r = glMatrix.RANDOM() * 2.0 * Math.PI; + var z = (glMatrix.RANDOM() * 2.0) - 1.0; + var zScale = Math.sqrt(1.0-z*z) * scale; + + out[0] = Math.cos(r) * zScale; + out[1] = Math.sin(r) * zScale; + out[2] = z * scale; + return out; + }; + + /** + * Transforms the vec3 with a mat4. + * 4th vector component is implicitly '1' + * + * @param {vec3} out the receiving vector + * @param {vec3} a the vector to transform + * @param {mat4} m matrix to transform with + * @returns {vec3} out + */ + vec3.transformMat4 = function(out, a, m) { + 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; + }; + + /** + * Transforms the vec3 with a mat3. + * + * @param {vec3} out the receiving vector + * @param {vec3} a the vector to transform + * @param {mat4} m the 3x3 matrix to transform with + * @returns {vec3} out + */ + vec3.transformMat3 = function(out, a, m) { + var x = a[0], y = a[1], z = a[2]; + out[0] = x * m[0] + y * m[3] + z * m[6]; + out[1] = x * m[1] + y * m[4] + z * m[7]; + out[2] = x * m[2] + y * m[5] + z * m[8]; + return out; + }; + + /** + * Transforms the vec3 with a quat + * + * @param {vec3} out the receiving vector + * @param {vec3} a the vector to transform + * @param {quat} q quaternion to transform with + * @returns {vec3} out + */ + vec3.transformQuat = function(out, a, q) { + // benchmarks: http://jsperf.com/quaternion-transform-vec3-implementations + + var x = a[0], y = a[1], z = a[2], + qx = q[0], qy = q[1], qz = q[2], qw = q[3], + + // calculate quat * vec + ix = qw * x + qy * z - qz * y, + iy = qw * y + qz * x - qx * z, + iz = qw * z + qx * y - qy * x, + iw = -qx * x - qy * y - qz * z; + + // calculate result * inverse quat + out[0] = ix * qw + iw * -qx + iy * -qz - iz * -qy; + out[1] = iy * qw + iw * -qy + iz * -qx - ix * -qz; + out[2] = iz * qw + iw * -qz + ix * -qy - iy * -qx; + 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 + */ + vec3.rotateX = function(out, a, b, c){ + var p = [], r=[]; + //Translate point to the origin + p[0] = a[0] - b[0]; + p[1] = a[1] - b[1]; + p[2] = a[2] - b[2]; + + //perform rotation + r[0] = p[0]; + r[1] = p[1]*Math.cos(c) - p[2]*Math.sin(c); + r[2] = p[1]*Math.sin(c) + p[2]*Math.cos(c); + + //translate to correct position + out[0] = r[0] + b[0]; + out[1] = r[1] + b[1]; + out[2] = r[2] + b[2]; + + 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 + */ + vec3.rotateY = function(out, a, b, c){ + var p = [], r=[]; + //Translate point to the origin + p[0] = a[0] - b[0]; + p[1] = a[1] - b[1]; + p[2] = a[2] - b[2]; + + //perform rotation + r[0] = p[2]*Math.sin(c) + p[0]*Math.cos(c); + r[1] = p[1]; + r[2] = p[2]*Math.cos(c) - p[0]*Math.sin(c); + + //translate to correct position + out[0] = r[0] + b[0]; + out[1] = r[1] + b[1]; + out[2] = r[2] + b[2]; + + 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 + */ + vec3.rotateZ = function(out, a, b, c){ + var p = [], r=[]; + //Translate point to the origin + p[0] = a[0] - b[0]; + p[1] = a[1] - b[1]; + p[2] = a[2] - b[2]; + + //perform rotation + r[0] = p[0]*Math.cos(c) - p[1]*Math.sin(c); + r[1] = p[0]*Math.sin(c) + p[1]*Math.cos(c); + r[2] = p[2]; + + //translate to correct position + out[0] = r[0] + b[0]; + out[1] = r[1] + b[1]; + out[2] = r[2] + b[2]; + + return out; + }; + + /** + * Perform some operation over an array of vec3s. + * + * @param {Array} a the array of vectors to iterate over + * @param {Number} stride Number of elements between the start of each vec3. If 0 assumes tightly packed + * @param {Number} offset Number of elements to skip at the beginning of the array + * @param {Number} count Number of vec3s 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 + * @function + */ + vec3.forEach = (function() { + var vec = vec3.create(); + + return function(a, stride, offset, count, fn, arg) { + var i, l; + if(!stride) { + stride = 3; + } + + if(!offset) { + offset = 0; + } + + if(count) { + l = Math.min((count * stride) + offset, a.length); + } else { + l = a.length; + } + + for(i = offset; i < l; i += stride) { + vec[0] = a[i]; vec[1] = a[i+1]; vec[2] = a[i+2]; + fn(vec, vec, arg); + a[i] = vec[0]; a[i+1] = vec[1]; a[i+2] = vec[2]; + } + + return a; + }; + })(); + + /** + * 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 + * + * @param {vec3} a vector to represent as a string + * @returns {String} string representation of the vector + */ + vec3.str = function (a) { + return 'vec3(' + a[0] + ', ' + a[1] + ', ' + a[2] + ')'; + }; + + /** + * Returns whether or not the vectors have exactly the same elements in the same position (when compared with ===) + * + * @param {vec3} a The first vector. + * @param {vec3} b The second vector. + * @returns {Boolean} True if the vectors are equal, false otherwise. + */ + vec3.exactEquals = function (a, b) { + return a[0] === b[0] && a[1] === b[1] && a[2] === b[2]; + }; + + /** + * Returns whether or not the vectors have approximately the same elements in the same position. + * + * @param {vec3} a The first vector. + * @param {vec3} b The second vector. + * @returns {Boolean} True if the vectors are equal, false otherwise. + */ + vec3.equals = function (a, b) { + var a0 = a[0], a1 = a[1], a2 = a[2]; + var b0 = b[0], b1 = b[1], b2 = b[2]; + return (Math.abs(a0 - b0) <= glMatrix.EPSILON*Math.max(1.0, Math.abs(a0), Math.abs(b0)) && + Math.abs(a1 - b1) <= glMatrix.EPSILON*Math.max(1.0, Math.abs(a1), Math.abs(b1)) && + Math.abs(a2 - b2) <= glMatrix.EPSILON*Math.max(1.0, Math.abs(a2), Math.abs(b2))); + }; + + module.exports = vec3; + + +/***/ }, +/* 8 */ +/***/ function(module, exports, __webpack_require__) { + + /* Copyright (c) 2015, Brandon Jones, Colin MacKenzie IV. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. */ + + var glMatrix = __webpack_require__(1); + + /** + * @class 4 Dimensional Vector + * @name vec4 + */ + var vec4 = {}; + + /** + * Creates a new, empty vec4 + * + * @returns {vec4} a new 4D vector + */ + vec4.create = function() { + var out = new glMatrix.ARRAY_TYPE(4); + out[0] = 0; + out[1] = 0; + out[2] = 0; + out[3] = 0; + return out; + }; + + /** + * Creates a new vec4 initialized with values from an existing vector + * + * @param {vec4} a vector to clone + * @returns {vec4} a new 4D vector + */ + vec4.clone = function(a) { + var out = new glMatrix.ARRAY_TYPE(4); + out[0] = a[0]; + out[1] = a[1]; + out[2] = a[2]; + out[3] = a[3]; + return out; + }; + + /** + * Creates a new vec4 initialized with the given values + * + * @param {Number} x X component + * @param {Number} y Y component + * @param {Number} z Z component + * @param {Number} w W component + * @returns {vec4} a new 4D vector + */ + vec4.fromValues = function(x, y, z, w) { + var out = new glMatrix.ARRAY_TYPE(4); + out[0] = x; + out[1] = y; + out[2] = z; + out[3] = w; + return out; + }; + + /** + * Copy the values from one vec4 to another + * + * @param {vec4} out the receiving vector + * @param {vec4} a the source vector + * @returns {vec4} out + */ + vec4.copy = function(out, a) { + out[0] = a[0]; + out[1] = a[1]; + out[2] = a[2]; + out[3] = a[3]; + return out; + }; + + /** + * Set the components of a vec4 to the given values + * + * @param {vec4} out the receiving vector + * @param {Number} x X component + * @param {Number} y Y component + * @param {Number} z Z component + * @param {Number} w W component + * @returns {vec4} out + */ + vec4.set = function(out, x, y, z, w) { + out[0] = x; + out[1] = y; + out[2] = z; + out[3] = w; + return out; + }; + + /** + * Adds two vec4's + * + * @param {vec4} out the receiving vector + * @param {vec4} a the first operand + * @param {vec4} b the second operand + * @returns {vec4} out + */ + vec4.add = function(out, a, b) { + out[0] = a[0] + b[0]; + out[1] = a[1] + b[1]; + out[2] = a[2] + b[2]; + out[3] = a[3] + b[3]; + return out; + }; + + /** + * Subtracts vector b from vector a + * + * @param {vec4} out the receiving vector + * @param {vec4} a the first operand + * @param {vec4} b the second operand + * @returns {vec4} out + */ + vec4.subtract = function(out, a, b) { + out[0] = a[0] - b[0]; + out[1] = a[1] - b[1]; + out[2] = a[2] - b[2]; + out[3] = a[3] - b[3]; + return out; + }; + + /** + * Alias for {@link vec4.subtract} + * @function + */ + vec4.sub = vec4.subtract; + + /** + * Multiplies two vec4's + * + * @param {vec4} out the receiving vector + * @param {vec4} a the first operand + * @param {vec4} b the second operand + * @returns {vec4} out + */ + vec4.multiply = function(out, a, b) { + out[0] = a[0] * b[0]; + out[1] = a[1] * b[1]; + out[2] = a[2] * b[2]; + out[3] = a[3] * b[3]; + return out; + }; + + /** + * Alias for {@link vec4.multiply} + * @function + */ + vec4.mul = vec4.multiply; + + /** + * Divides two vec4's + * + * @param {vec4} out the receiving vector + * @param {vec4} a the first operand + * @param {vec4} b the second operand + * @returns {vec4} out + */ + vec4.divide = function(out, a, b) { + out[0] = a[0] / b[0]; + out[1] = a[1] / b[1]; + out[2] = a[2] / b[2]; + out[3] = a[3] / b[3]; + return out; + }; + + /** + * Alias for {@link vec4.divide} + * @function + */ + vec4.div = vec4.divide; + + /** + * Math.ceil the components of a vec4 + * + * @param {vec4} out the receiving vector + * @param {vec4} a vector to ceil + * @returns {vec4} out + */ + vec4.ceil = function (out, a) { + out[0] = Math.ceil(a[0]); + out[1] = Math.ceil(a[1]); + out[2] = Math.ceil(a[2]); + out[3] = Math.ceil(a[3]); + return out; + }; + + /** + * Math.floor the components of a vec4 + * + * @param {vec4} out the receiving vector + * @param {vec4} a vector to floor + * @returns {vec4} out + */ + vec4.floor = function (out, a) { + out[0] = Math.floor(a[0]); + out[1] = Math.floor(a[1]); + out[2] = Math.floor(a[2]); + out[3] = Math.floor(a[3]); + return out; + }; + + /** + * Returns the minimum of two vec4's + * + * @param {vec4} out the receiving vector + * @param {vec4} a the first operand + * @param {vec4} b the second operand + * @returns {vec4} out + */ + vec4.min = function(out, a, b) { + out[0] = Math.min(a[0], b[0]); + out[1] = Math.min(a[1], b[1]); + out[2] = Math.min(a[2], b[2]); + out[3] = Math.min(a[3], b[3]); + return out; + }; + + /** + * Returns the maximum of two vec4's + * + * @param {vec4} out the receiving vector + * @param {vec4} a the first operand + * @param {vec4} b the second operand + * @returns {vec4} out + */ + vec4.max = function(out, a, b) { + out[0] = Math.max(a[0], b[0]); + out[1] = Math.max(a[1], b[1]); + out[2] = Math.max(a[2], b[2]); + out[3] = Math.max(a[3], b[3]); + return out; + }; + + /** + * Math.round the components of a vec4 + * + * @param {vec4} out the receiving vector + * @param {vec4} a vector to round + * @returns {vec4} out + */ + vec4.round = function (out, a) { + out[0] = Math.round(a[0]); + out[1] = Math.round(a[1]); + out[2] = Math.round(a[2]); + out[3] = Math.round(a[3]); + return out; + }; + + /** + * Scales a vec4 by a scalar number + * + * @param {vec4} out the receiving vector + * @param {vec4} a the vector to scale + * @param {Number} b amount to scale the vector by + * @returns {vec4} out + */ + vec4.scale = function(out, a, b) { + out[0] = a[0] * b; + out[1] = a[1] * b; + out[2] = a[2] * b; + out[3] = a[3] * b; + return out; + }; + + /** + * Adds two vec4's after scaling the second operand by a scalar value + * + * @param {vec4} out the receiving vector + * @param {vec4} a the first operand + * @param {vec4} b the second operand + * @param {Number} scale the amount to scale b by before adding + * @returns {vec4} out + */ + vec4.scaleAndAdd = function(out, a, b, scale) { + out[0] = a[0] + (b[0] * scale); + out[1] = a[1] + (b[1] * scale); + out[2] = a[2] + (b[2] * scale); + out[3] = a[3] + (b[3] * scale); + return out; + }; + + /** + * Calculates the euclidian distance between two vec4's + * + * @param {vec4} a the first operand + * @param {vec4} b the second operand + * @returns {Number} distance between a and b + */ + vec4.distance = function(a, b) { + var x = b[0] - a[0], + y = b[1] - a[1], + z = b[2] - a[2], + w = b[3] - a[3]; + return Math.sqrt(x*x + y*y + z*z + w*w); + }; + + /** + * Alias for {@link vec4.distance} + * @function + */ + vec4.dist = vec4.distance; + + /** + * Calculates the squared euclidian distance between two vec4's + * + * @param {vec4} a the first operand + * @param {vec4} b the second operand + * @returns {Number} squared distance between a and b + */ + vec4.squaredDistance = function(a, b) { + var x = b[0] - a[0], + y = b[1] - a[1], + z = b[2] - a[2], + w = b[3] - a[3]; + return x*x + y*y + z*z + w*w; + }; + + /** + * Alias for {@link vec4.squaredDistance} + * @function + */ + vec4.sqrDist = vec4.squaredDistance; + + /** + * Calculates the length of a vec4 + * + * @param {vec4} a vector to calculate length of + * @returns {Number} length of a + */ + vec4.length = function (a) { + var x = a[0], + y = a[1], + z = a[2], + w = a[3]; + return Math.sqrt(x*x + y*y + z*z + w*w); + }; + + /** + * Alias for {@link vec4.length} + * @function + */ + vec4.len = vec4.length; + + /** + * Calculates the squared length of a vec4 + * + * @param {vec4} a vector to calculate squared length of + * @returns {Number} squared length of a + */ + vec4.squaredLength = function (a) { + var x = a[0], + y = a[1], + z = a[2], + w = a[3]; + return x*x + y*y + z*z + w*w; + }; + + /** + * Alias for {@link vec4.squaredLength} + * @function + */ + vec4.sqrLen = vec4.squaredLength; + + /** + * Negates the components of a vec4 + * + * @param {vec4} out the receiving vector + * @param {vec4} a vector to negate + * @returns {vec4} out + */ + vec4.negate = function(out, a) { + out[0] = -a[0]; + out[1] = -a[1]; + out[2] = -a[2]; + out[3] = -a[3]; + 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 + * + * @param {vec4} out the receiving vector + * @param {vec4} a vector to normalize + * @returns {vec4} out + */ + vec4.normalize = function(out, a) { + var x = a[0], + y = a[1], + z = a[2], + w = a[3]; + var len = x*x + y*y + z*z + w*w; + if (len > 0) { + len = 1 / Math.sqrt(len); + out[0] = x * len; + out[1] = y * len; + out[2] = z * len; + out[3] = w * len; + } + return out; + }; + + /** + * Calculates the dot product of two vec4's + * + * @param {vec4} a the first operand + * @param {vec4} b the second operand + * @returns {Number} dot product of a and b + */ + vec4.dot = function (a, b) { + return a[0] * b[0] + a[1] * b[1] + a[2] * b[2] + a[3] * b[3]; + }; + + /** + * Performs a linear interpolation between two vec4's + * + * @param {vec4} out the receiving vector + * @param {vec4} a the first operand + * @param {vec4} b the second operand + * @param {Number} t interpolation amount between the two inputs + * @returns {vec4} out + */ + vec4.lerp = function (out, a, b, t) { + var ax = a[0], + ay = a[1], + az = a[2], + aw = a[3]; + out[0] = ax + t * (b[0] - ax); + out[1] = ay + t * (b[1] - ay); + out[2] = az + t * (b[2] - az); + out[3] = aw + t * (b[3] - aw); + return out; + }; + + /** + * Generates a random vector with the given scale + * + * @param {vec4} out the receiving vector + * @param {Number} [scale] Length of the resulting vector. If ommitted, a unit vector will be returned + * @returns {vec4} out + */ + vec4.random = function (out, scale) { + scale = scale || 1.0; + + //TODO: This is a pretty awful way of doing this. Find something better. + out[0] = glMatrix.RANDOM(); + out[1] = glMatrix.RANDOM(); + out[2] = glMatrix.RANDOM(); + out[3] = glMatrix.RANDOM(); + vec4.normalize(out, out); + vec4.scale(out, out, scale); + return out; + }; + + /** + * Transforms the vec4 with a mat4. + * + * @param {vec4} out the receiving vector + * @param {vec4} a the vector to transform + * @param {mat4} m matrix to transform with + * @returns {vec4} out + */ + vec4.transformMat4 = function(out, a, m) { + var x = a[0], y = a[1], z = a[2], w = a[3]; + 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; + out[3] = m[3] * x + m[7] * y + m[11] * z + m[15] * w; + return out; + }; + + /** + * Transforms the vec4 with a quat + * + * @param {vec4} out the receiving vector + * @param {vec4} a the vector to transform + * @param {quat} q quaternion to transform with + * @returns {vec4} out + */ + vec4.transformQuat = function(out, a, q) { + var x = a[0], y = a[1], z = a[2], + qx = q[0], qy = q[1], qz = q[2], qw = q[3], + + // calculate quat * vec + ix = qw * x + qy * z - qz * y, + iy = qw * y + qz * x - qx * z, + iz = qw * z + qx * y - qy * x, + iw = -qx * x - qy * y - qz * z; + + // calculate result * inverse quat + out[0] = ix * qw + iw * -qx + iy * -qz - iz * -qy; + out[1] = iy * qw + iw * -qy + iz * -qx - ix * -qz; + out[2] = iz * qw + iw * -qz + ix * -qy - iy * -qx; + out[3] = a[3]; + return out; + }; + + /** + * Perform some operation over an array of vec4s. + * + * @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 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 + * @function + */ + vec4.forEach = (function() { + var vec = vec4.create(); + + return function(a, stride, offset, count, fn, arg) { + var i, l; + if(!stride) { + stride = 4; + } + + if(!offset) { + offset = 0; + } + + if(count) { + l = Math.min((count * stride) + offset, a.length); + } else { + l = a.length; + } + + for(i = offset; i < l; i += stride) { + vec[0] = a[i]; vec[1] = a[i+1]; vec[2] = a[i+2]; vec[3] = a[i+3]; + fn(vec, vec, arg); + a[i] = vec[0]; a[i+1] = vec[1]; a[i+2] = vec[2]; a[i+3] = vec[3]; + } + + return a; + }; + })(); + + /** + * Returns a string representation of a vector + * + * @param {vec4} a vector to represent as a string + * @returns {String} string representation of the vector + */ + vec4.str = function (a) { + return 'vec4(' + a[0] + ', ' + a[1] + ', ' + a[2] + ', ' + a[3] + ')'; + }; + + /** + * Returns whether or not the vectors have exactly the same elements in the same position (when compared with ===) + * + * @param {vec4} a The first vector. + * @param {vec4} b The second vector. + * @returns {Boolean} True if the vectors are equal, false otherwise. + */ + vec4.exactEquals = function (a, b) { + return a[0] === b[0] && a[1] === b[1] && a[2] === b[2] && a[3] === b[3]; + }; + + /** + * Returns whether or not the vectors have approximately the same elements in the same position. + * + * @param {vec4} a The first vector. + * @param {vec4} b The second vector. + * @returns {Boolean} True if the vectors are equal, false otherwise. + */ + vec4.equals = function (a, b) { + var a0 = a[0], a1 = a[1], a2 = a[2], a3 = a[3]; + var b0 = b[0], b1 = b[1], b2 = b[2], b3 = b[3]; + return (Math.abs(a0 - b0) <= glMatrix.EPSILON*Math.max(1.0, Math.abs(a0), Math.abs(b0)) && + Math.abs(a1 - b1) <= glMatrix.EPSILON*Math.max(1.0, Math.abs(a1), Math.abs(b1)) && + Math.abs(a2 - b2) <= glMatrix.EPSILON*Math.max(1.0, Math.abs(a2), Math.abs(b2)) && + Math.abs(a3 - b3) <= glMatrix.EPSILON*Math.max(1.0, Math.abs(a3), Math.abs(b3))); + }; + + module.exports = vec4; + + +/***/ }, +/* 9 */ +/***/ function(module, exports, __webpack_require__) { + + /* Copyright (c) 2015, Brandon Jones, Colin MacKenzie IV. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. */ + + var glMatrix = __webpack_require__(1); + + /** + * @class 2 Dimensional Vector + * @name vec2 + */ + var vec2 = {}; + + /** + * Creates a new, empty vec2 + * + * @returns {vec2} a new 2D vector + */ + vec2.create = function() { + var out = new glMatrix.ARRAY_TYPE(2); + out[0] = 0; + out[1] = 0; + return out; + }; + + /** + * Creates a new vec2 initialized with values from an existing vector + * + * @param {vec2} a vector to clone + * @returns {vec2} a new 2D vector + */ + vec2.clone = function(a) { + var out = new glMatrix.ARRAY_TYPE(2); + out[0] = a[0]; + out[1] = a[1]; + return out; + }; + + /** + * Creates a new vec2 initialized with the given values + * + * @param {Number} x X component + * @param {Number} y Y component + * @returns {vec2} a new 2D vector + */ + vec2.fromValues = function(x, y) { + var out = new glMatrix.ARRAY_TYPE(2); + out[0] = x; + out[1] = y; + return out; + }; + + /** + * Copy the values from one vec2 to another + * + * @param {vec2} out the receiving vector + * @param {vec2} a the source vector + * @returns {vec2} out + */ + vec2.copy = function(out, a) { + out[0] = a[0]; + out[1] = a[1]; + return out; + }; + + /** + * Set the components of a vec2 to the given values + * + * @param {vec2} out the receiving vector + * @param {Number} x X component + * @param {Number} y Y component + * @returns {vec2} out + */ + vec2.set = function(out, x, y) { + out[0] = x; + out[1] = y; + return out; + }; + + /** + * Adds two vec2's + * + * @param {vec2} out the receiving vector + * @param {vec2} a the first operand + * @param {vec2} b the second operand + * @returns {vec2} out + */ + vec2.add = function(out, a, b) { + out[0] = a[0] + b[0]; + out[1] = a[1] + b[1]; + return out; + }; + + /** + * Subtracts vector b from vector a + * + * @param {vec2} out the receiving vector + * @param {vec2} a the first operand + * @param {vec2} b the second operand + * @returns {vec2} out + */ + vec2.subtract = function(out, a, b) { + out[0] = a[0] - b[0]; + out[1] = a[1] - b[1]; + return out; + }; + + /** + * Alias for {@link vec2.subtract} + * @function + */ + vec2.sub = vec2.subtract; + + /** + * Multiplies two vec2's + * + * @param {vec2} out the receiving vector + * @param {vec2} a the first operand + * @param {vec2} b the second operand + * @returns {vec2} out + */ + vec2.multiply = function(out, a, b) { + out[0] = a[0] * b[0]; + out[1] = a[1] * b[1]; + return out; + }; + + /** + * Alias for {@link vec2.multiply} + * @function + */ + vec2.mul = vec2.multiply; + + /** + * Divides two vec2's + * + * @param {vec2} out the receiving vector + * @param {vec2} a the first operand + * @param {vec2} b the second operand + * @returns {vec2} out + */ + vec2.divide = function(out, a, b) { + out[0] = a[0] / b[0]; + out[1] = a[1] / b[1]; + return out; + }; + + /** + * Alias for {@link vec2.divide} + * @function + */ + vec2.div = vec2.divide; + + /** + * Math.ceil the components of a vec2 + * + * @param {vec2} out the receiving vector + * @param {vec2} a vector to ceil + * @returns {vec2} out + */ + vec2.ceil = function (out, a) { + out[0] = Math.ceil(a[0]); + out[1] = Math.ceil(a[1]); + return out; + }; + + /** + * Math.floor the components of a vec2 + * + * @param {vec2} out the receiving vector + * @param {vec2} a vector to floor + * @returns {vec2} out + */ + vec2.floor = function (out, a) { + out[0] = Math.floor(a[0]); + out[1] = Math.floor(a[1]); + return out; + }; + + /** + * Returns the minimum of two vec2's + * + * @param {vec2} out the receiving vector + * @param {vec2} a the first operand + * @param {vec2} b the second operand + * @returns {vec2} out + */ + vec2.min = function(out, a, b) { + out[0] = Math.min(a[0], b[0]); + out[1] = Math.min(a[1], b[1]); + return out; + }; + + /** + * Returns the maximum of two vec2's + * + * @param {vec2} out the receiving vector + * @param {vec2} a the first operand + * @param {vec2} b the second operand + * @returns {vec2} out + */ + vec2.max = function(out, a, b) { + out[0] = Math.max(a[0], b[0]); + out[1] = Math.max(a[1], b[1]); + return out; + }; + + /** + * Math.round the components of a vec2 + * + * @param {vec2} out the receiving vector + * @param {vec2} a vector to round + * @returns {vec2} out + */ + vec2.round = function (out, a) { + out[0] = Math.round(a[0]); + out[1] = Math.round(a[1]); + return out; + }; + + /** + * Scales a vec2 by a scalar number + * + * @param {vec2} out the receiving vector + * @param {vec2} a the vector to scale + * @param {Number} b amount to scale the vector by + * @returns {vec2} out + */ + vec2.scale = function(out, a, b) { + out[0] = a[0] * b; + out[1] = a[1] * b; + return out; + }; + + /** + * Adds two vec2's after scaling the second operand by a scalar value + * + * @param {vec2} out the receiving vector + * @param {vec2} a the first operand + * @param {vec2} b the second operand + * @param {Number} scale the amount to scale b by before adding + * @returns {vec2} out + */ + vec2.scaleAndAdd = function(out, a, b, scale) { + out[0] = a[0] + (b[0] * scale); + out[1] = a[1] + (b[1] * scale); + return out; + }; + + /** + * Calculates the euclidian distance between two vec2's + * + * @param {vec2} a the first operand + * @param {vec2} b the second operand + * @returns {Number} distance between a and b + */ + vec2.distance = function(a, b) { + var x = b[0] - a[0], + y = b[1] - a[1]; + return Math.sqrt(x*x + y*y); + }; + + /** + * Alias for {@link vec2.distance} + * @function + */ + vec2.dist = vec2.distance; + + /** + * Calculates the squared euclidian distance between two vec2's + * + * @param {vec2} a the first operand + * @param {vec2} b the second operand + * @returns {Number} squared distance between a and b + */ + vec2.squaredDistance = function(a, b) { + var x = b[0] - a[0], + y = b[1] - a[1]; + return x*x + y*y; + }; + + /** + * Alias for {@link vec2.squaredDistance} + * @function + */ + vec2.sqrDist = vec2.squaredDistance; + + /** + * Calculates the length of a vec2 + * + * @param {vec2} a vector to calculate length of + * @returns {Number} length of a + */ + vec2.length = function (a) { + var x = a[0], + y = a[1]; + return Math.sqrt(x*x + y*y); + }; + + /** + * Alias for {@link vec2.length} + * @function + */ + vec2.len = vec2.length; + + /** + * Calculates the squared length of a vec2 + * + * @param {vec2} a vector to calculate squared length of + * @returns {Number} squared length of a + */ + vec2.squaredLength = function (a) { + var x = a[0], + y = a[1]; + return x*x + y*y; + }; + + /** + * Alias for {@link vec2.squaredLength} + * @function + */ + vec2.sqrLen = vec2.squaredLength; + + /** + * Negates the components of a vec2 + * + * @param {vec2} out the receiving vector + * @param {vec2} a vector to negate + * @returns {vec2} out + */ + vec2.negate = function(out, a) { + out[0] = -a[0]; + out[1] = -a[1]; + 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 + * + * @param {vec2} out the receiving vector + * @param {vec2} a vector to normalize + * @returns {vec2} out + */ + vec2.normalize = function(out, a) { + var x = a[0], + y = a[1]; + var len = x*x + y*y; + if (len > 0) { + //TODO: evaluate use of glm_invsqrt here? + len = 1 / Math.sqrt(len); + out[0] = a[0] * len; + out[1] = a[1] * len; + } + return out; + }; + + /** + * Calculates the dot product of two vec2's + * + * @param {vec2} a the first operand + * @param {vec2} b the second operand + * @returns {Number} dot product of a and b + */ + vec2.dot = function (a, b) { + return a[0] * b[0] + a[1] * b[1]; + }; + + /** + * Computes the cross product of two vec2's + * Note that the cross product must by definition produce a 3D vector + * + * @param {vec3} out the receiving vector + * @param {vec2} a the first operand + * @param {vec2} b the second operand + * @returns {vec3} out + */ + vec2.cross = function(out, a, b) { + var z = a[0] * b[1] - a[1] * b[0]; + out[0] = out[1] = 0; + out[2] = z; + return out; + }; + + /** + * Performs a linear interpolation between two vec2's + * + * @param {vec2} out the receiving vector + * @param {vec2} a the first operand + * @param {vec2} b the second operand + * @param {Number} t interpolation amount between the two inputs + * @returns {vec2} out + */ + vec2.lerp = function (out, a, b, t) { + var ax = a[0], + ay = a[1]; + out[0] = ax + t * (b[0] - ax); + out[1] = ay + t * (b[1] - ay); + return out; + }; + + /** + * Generates a random vector with the given scale + * + * @param {vec2} out the receiving vector + * @param {Number} [scale] Length of the resulting vector. If ommitted, a unit vector will be returned + * @returns {vec2} out + */ + vec2.random = function (out, scale) { + scale = scale || 1.0; + var r = glMatrix.RANDOM() * 2.0 * Math.PI; + out[0] = Math.cos(r) * scale; + out[1] = Math.sin(r) * scale; + return out; + }; + + /** + * Transforms the vec2 with a mat2 + * + * @param {vec2} out the receiving vector + * @param {vec2} a the vector to transform + * @param {mat2} m matrix to transform with + * @returns {vec2} out + */ + vec2.transformMat2 = function(out, a, m) { + var x = a[0], + y = a[1]; + out[0] = m[0] * x + m[2] * y; + out[1] = m[1] * x + m[3] * y; + return out; + }; + + /** + * Transforms the vec2 with a mat2d + * + * @param {vec2} out the receiving vector + * @param {vec2} a the vector to transform + * @param {mat2d} m matrix to transform with + * @returns {vec2} out + */ + vec2.transformMat2d = function(out, a, m) { + var x = a[0], + y = a[1]; + out[0] = m[0] * x + m[2] * y + m[4]; + out[1] = m[1] * x + m[3] * y + m[5]; + return out; + }; + + /** + * Transforms the vec2 with a mat3 + * 3rd vector component is implicitly '1' + * + * @param {vec2} out the receiving vector + * @param {vec2} a the vector to transform + * @param {mat3} m matrix to transform with + * @returns {vec2} out + */ + vec2.transformMat3 = function(out, a, m) { + var x = a[0], + y = a[1]; + out[0] = m[0] * x + m[3] * y + m[6]; + out[1] = m[1] * x + m[4] * y + m[7]; + return out; + }; + + /** + * Transforms the vec2 with a mat4 + * 3rd vector component is implicitly '0' + * 4th vector component is implicitly '1' + * + * @param {vec2} out the receiving vector + * @param {vec2} a the vector to transform + * @param {mat4} m matrix to transform with + * @returns {vec2} out + */ + vec2.transformMat4 = function(out, a, m) { + var x = a[0], + y = a[1]; + out[0] = m[0] * x + m[4] * y + m[12]; + out[1] = m[1] * x + m[5] * y + m[13]; + return out; + }; + + /** + * Perform some operation over an array of vec2s. + * + * @param {Array} a the array of vectors to iterate over + * @param {Number} stride Number of elements between the start of each vec2. 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 {Function} fn Function to call for each vector in the array + * @param {Object} [arg] additional argument to pass to fn + * @returns {Array} a + * @function + */ + vec2.forEach = (function() { + var vec = vec2.create(); + + return function(a, stride, offset, count, fn, arg) { + var i, l; + if(!stride) { + stride = 2; + } + + if(!offset) { + offset = 0; + } + + if(count) { + l = Math.min((count * stride) + offset, a.length); + } else { + l = a.length; + } + + for(i = offset; i < l; i += stride) { + vec[0] = a[i]; vec[1] = a[i+1]; + fn(vec, vec, arg); + a[i] = vec[0]; a[i+1] = vec[1]; + } + + return a; + }; + })(); + + /** + * Returns a string representation of a vector + * + * @param {vec2} a vector to represent as a string + * @returns {String} string representation of the vector + */ + vec2.str = function (a) { + return 'vec2(' + a[0] + ', ' + a[1] + ')'; + }; + + /** + * Returns whether or not the vectors exactly have the same elements in the same position (when compared with ===) + * + * @param {vec2} a The first vector. + * @param {vec2} b The second vector. + * @returns {Boolean} True if the vectors are equal, false otherwise. + */ + vec2.exactEquals = function (a, b) { + return a[0] === b[0] && a[1] === b[1]; + }; + + /** + * Returns whether or not the vectors have approximately the same elements in the same position. + * + * @param {vec2} a The first vector. + * @param {vec2} b The second vector. + * @returns {Boolean} True if the vectors are equal, false otherwise. + */ + vec2.equals = function (a, b) { + var a0 = a[0], a1 = a[1]; + var b0 = b[0], b1 = b[1]; + return (Math.abs(a0 - b0) <= glMatrix.EPSILON*Math.max(1.0, Math.abs(a0), Math.abs(b0)) && + Math.abs(a1 - b1) <= glMatrix.EPSILON*Math.max(1.0, Math.abs(a1), Math.abs(b1))); + }; + + module.exports = vec2; + + +/***/ } +/******/ ]) +}); +; \ No newline at end of file diff --git a/client/public/index.html b/client/public/index.html index 12be089..94c2f16 100644 --- a/client/public/index.html +++ b/client/public/index.html @@ -9,6 +9,11 @@ + + + + + @@ -27,5 +32,67 @@ + + + + diff --git a/client/public/index.js b/client/public/index.js new file mode 100644 index 0000000..1db8424 --- /dev/null +++ b/client/public/index.js @@ -0,0 +1,125 @@ +function main() { + const canvas = document.querySelector('#webglviewer'); + const gl = canvas.getContext('webgl2'); + + // Only continue if WebGL is available and working + if (gl === null) { + alert('Unable to initialize WebGL. Your browser or machine may not support it.'); + return; + } + + // Set clear color to black, fully opaque + gl.clearColor(0.0, 0.0, 0.0, 1.0); + // Clear the color buffer with specified clear color + gl.clear(gl.COLOR_BUFFER_BIT); + gl.enable(gl.DEPTH_TEST); + + const vsSource = document.getElementById('vertex-draw').text.trim(); + const fsSource = document.getElementById('fragment-draw').text.trim(); + + const vertexShader = gl.createShader(gl.VERTEX_SHADER); + gl.shaderSource(vertexShader, vsSource); + gl.compileShader(vertexShader); + + if (!gl.getShaderParameter(vertexShader, gl.COMPILE_STATUS)) { + console.error(gl.getShaderInfoLog(vertexShader)); + } + + const fragmentShader = gl.createShader(gl.FRAGMENT_SHADER); + gl.shaderSource(fragmentShader, fsSource); + gl.compileShader(fragmentShader); + + if (!gl.getShaderParameter(fragmentShader, gl.COMPILE_STATUS)) { + console.error(gl.getShaderInfoLog(fragmentShader)); + } + + const program = gl.createProgram(); + gl.attachShader(program, vertexShader); + gl.attachShader(program, fragmentShader); + gl.linkProgram(program); + + if (!gl.getProgramParameter(program, gl.LINK_STATUS)) { + console.error(gl.getProgramInfoLog(program)); + } + + const sceneUniformsLocation = gl.getUniformBlockIndex(program, 'SceneUniforms'); + gl.uniformBlockBinding(program, sceneUniformsLocation, 0); + + const modelMatrixLocation = gl.getUniformLocation(program, 'uModel'); + + gl.useProgram(program); + + const box = utils.createBox({dimensions: [.5, .6, .5]}); + const numVertices = box.positions.length / 3; + + const cubeArray = gl.createVertexArray(); + gl.bindVertexArray(cubeArray); + + const positionBuffer = gl.createBuffer(); + gl.bindBuffer(gl.ARRAY_BUFFER, positionBuffer); + gl.bufferData(gl.ARRAY_BUFFER, box.positions, gl.STATIC_DRAW); + gl.vertexAttribPointer(0, 3, gl.FLOAT, false, 0, 0); + gl.enableVertexAttribArray(0); + + const uvBuffer = gl.createBuffer(); + gl.bindBuffer(gl.ARRAY_BUFFER, uvBuffer); + gl.bufferData(gl.ARRAY_BUFFER, box.uvs, gl.STATIC_DRAW); + gl.vertexAttribPointer(1, 2, gl.FLOAT, false, 0, 0); + gl.enableVertexAttribArray(1); + + const normalBuffer = gl.createBuffer(); + gl.bindBuffer(gl.ARRAY_BUFFER, normalBuffer); + gl.bufferData(gl.ARRAY_BUFFER, box.normals, gl.STATIC_DRAW); + gl.vertexAttribPointer(2, 3, gl.FLOAT, false, 0, 0); + gl.enableVertexAttribArray(2); + + + const projMatrix = mat4.create(); + mat4.perspective(projMatrix, Math.PI / 2, gl.drawingBufferWidth / gl.drawingBufferHeight, 0.1, 10.0); + + const viewMatrix = mat4.create(); + const eyePosition = vec3.fromValues(1, 1, 1); + mat4.lookAt(viewMatrix, eyePosition, vec3.fromValues(0, 0, 0), vec3.fromValues(0, 1, 0)); + + const viewProjMatrix = mat4.create(); + mat4.multiply(viewProjMatrix, projMatrix, viewMatrix); + + const lightPosition = vec3.fromValues(1, 1, 0.5); + + const modelMatrix = mat4.create(); + const rotateXMatrix = mat4.create(); + const rotateYMatrix = mat4.create(); + + const sceneUniformData = new Float32Array(24); + sceneUniformData.set(viewProjMatrix); + sceneUniformData.set(eyePosition, 16); + sceneUniformData.set(lightPosition, 20); + + const sceneUniformBuffer = gl.createBuffer(); + gl.bindBufferBase(gl.UNIFORM_BUFFER, 0, sceneUniformBuffer); + gl.bufferData(gl.UNIFORM_BUFFER, sceneUniformData, gl.STATIC_DRAW); + + let angleX = 0; + let angleY = 0; + + + function draw() { + angleX += 0.01; + angleY += 0.015; + + mat4.fromXRotation(rotateXMatrix, angleX); + mat4.fromYRotation(rotateYMatrix, angleY); + mat4.multiply(modelMatrix, rotateXMatrix, rotateYMatrix); + + gl.uniformMatrix4fv(modelMatrixLocation, false, modelMatrix); + + gl.clear(gl.COLOR_BUFFER_BIT); + gl.drawArrays(gl.TRIANGLES, 0, numVertices); + + requestAnimationFrame(draw); + } + + requestAnimationFrame(draw); +} + +window.onload = main; diff --git a/client/public/res/khronos_webgl.png b/client/public/res/khronos_webgl.png new file mode 100644 index 0000000..70bb043 Binary files /dev/null and b/client/public/res/khronos_webgl.png differ diff --git a/client/public/res/lego_stud.mtl b/client/public/res/lego_stud.mtl new file mode 100644 index 0000000..7d2a313 --- /dev/null +++ b/client/public/res/lego_stud.mtl @@ -0,0 +1,12 @@ +# Blender MTL File: 'None' +# Material Count: 1 + +newmtl Material.005 +Ns 225.000000 +Ka 1.000000 1.000000 1.000000 +Kd 0.800000 0.800000 0.800000 +Ks 0.500000 0.500000 0.500000 +Ke 0.000000 0.000000 0.000000 +Ni 1.450000 +d 1.000000 +illum 2 diff --git a/client/public/res/lego_stud.obj b/client/public/res/lego_stud.obj new file mode 100644 index 0000000..d03eda8 --- /dev/null +++ b/client/public/res/lego_stud.obj @@ -0,0 +1,1828 @@ +# Blender v3.0.1 OBJ File: '' +# www.blender.org +mtllib lego_stud.mtl +o Cylinder.001 +v 0.138972 0.159959 -0.074116 +v 0.151918 0.159959 -0.074119 +v 0.145746 0.159959 -0.074697 +v 0.156982 0.159959 -0.072438 +v 0.131933 0.159959 -0.072426 +v 0.160962 0.159959 -0.069734 +v 0.124708 0.159959 -0.069709 +v 0.163882 0.159959 -0.066087 +v 0.117373 0.159959 -0.066047 +v 0.165766 0.159959 -0.061577 +v 0.110009 0.159959 -0.061523 +v 0.166638 0.159959 -0.056285 +v 0.102694 0.159959 -0.056218 +v 0.136048 0.159959 -0.058725 +v 0.131358 0.159959 -0.058326 +v 0.140280 0.159959 -0.058326 +v 0.143815 0.159959 -0.057156 +v 0.126426 0.159959 -0.057156 +v 0.146648 0.159959 -0.055259 +v 0.121309 0.159959 -0.055259 +v 0.166522 0.159959 -0.050290 +v 0.095505 0.159959 -0.050215 +v 0.148774 0.159959 -0.052678 +v 0.116063 0.159959 -0.052678 +v 0.150191 0.159959 -0.049456 +v 0.110745 0.159959 -0.049456 +v 0.165443 0.159959 -0.043673 +v 0.088522 0.159959 -0.043594 +v 0.150894 0.159959 -0.045637 +v 0.105413 0.159959 -0.045637 +v 0.150878 0.159959 -0.041263 +v 0.100123 0.159959 -0.041263 +v 0.163424 0.159959 -0.036514 +v 0.081823 0.159959 -0.036439 +v 0.150140 0.159959 -0.036377 +v 0.094933 0.159959 -0.036377 +v 0.160490 0.159959 -0.028892 +v 0.075486 0.159959 -0.028830 +v 0.148675 0.159959 -0.031023 +v 0.089899 0.159959 -0.031023 +v 0.146480 0.159959 -0.025244 +v 0.085078 0.159959 -0.025244 +v 0.156664 0.159959 -0.020888 +v 0.069589 0.159959 -0.020851 +v 0.143549 0.159959 -0.019083 +v 0.080528 0.159959 -0.019083 +v 0.151972 0.159959 -0.012583 +v 0.064212 0.159959 -0.012583 +v 0.139879 0.159959 -0.012583 +v 0.076305 0.159959 -0.012583 +v 0.059630 0.159959 -0.004464 +v 0.072657 0.159959 -0.006120 +v 0.135679 0.159959 -0.006120 +v 0.146723 0.159959 -0.004501 +v 0.069741 0.159959 0.000017 +v 0.131142 0.159959 0.000017 +v 0.140942 0.159959 0.003357 +v 0.055871 0.159959 0.003418 +v 0.067552 0.159959 0.005782 +v 0.126328 0.159959 0.005782 +v 0.134701 0.159959 0.010899 +v 0.052964 0.159959 0.010974 +v 0.121294 0.159959 0.011132 +v 0.066087 0.159959 0.011132 +v 0.128074 0.159959 0.018034 +v 0.050940 0.159959 0.018113 +v 0.116098 0.159959 0.016021 +v 0.065343 0.159959 0.016021 +v 0.110796 0.159959 0.020404 +v 0.065315 0.159959 0.020404 +v 0.121136 0.159959 0.024671 +v 0.049828 0.159959 0.024747 +v 0.105448 0.159959 0.024236 +v 0.066001 0.159959 0.024236 +v 0.100110 0.159959 0.027473 +v 0.067398 0.159959 0.027473 +v 0.113962 0.159959 0.030720 +v 0.049658 0.159959 0.030786 +v 0.094840 0.159959 0.030068 +v 0.069501 0.159959 0.030068 +v 0.089696 0.159959 0.031978 +v 0.072307 0.159959 0.031978 +v 0.106623 0.159959 0.036088 +v 0.050459 0.159959 0.036142 +v 0.084735 0.159959 0.033156 +v 0.075814 0.159959 0.033156 +v 0.080016 0.159959 0.033559 +v 0.099196 0.159959 0.040684 +v 0.052262 0.159959 0.040724 +v 0.091754 0.159959 0.044418 +v 0.055095 0.159959 0.044443 +v 0.084371 0.159959 0.047198 +v 0.058989 0.159959 0.047211 +v 0.077121 0.159959 0.048933 +v 0.063974 0.159959 0.048936 +v 0.070079 0.159959 0.049532 +v 0.051316 0.159959 -0.074142 +v 0.060057 0.159959 -0.074647 +v 0.057747 0.159959 -0.074697 +v 0.062212 0.159959 -0.074489 +v 0.064237 0.159959 -0.074212 +v 0.066157 0.159959 -0.073803 +v 0.044533 0.159959 -0.072521 +v 0.067995 0.159959 -0.073252 +v 0.069775 0.159959 -0.072546 +v 0.071521 0.159959 -0.071673 +v 0.037480 0.159959 -0.069897 +v 0.073258 0.159959 -0.070622 +v 0.075009 0.159959 -0.069382 +v 0.030242 0.159959 -0.066337 +v 0.076799 0.159959 -0.067940 +v 0.078652 0.159959 -0.066284 +v 0.022903 0.159959 -0.061903 +v 0.080591 0.159959 -0.064404 +v 0.052521 0.159959 -0.058387 +v 0.054726 0.159959 -0.057965 +v 0.056831 0.159959 -0.057378 +v 0.058834 0.159959 -0.056625 +v 0.060734 0.159959 -0.055708 +v 0.062530 0.159959 -0.054629 +v 0.064222 0.159959 -0.053388 +v 0.065808 0.159959 -0.051987 +v 0.067287 0.159959 -0.050427 +v 0.068660 0.159959 -0.048709 +v 0.069923 0.159959 -0.046835 +v 0.015548 0.159959 -0.056662 +v 0.047810 0.159959 -0.058725 +v 0.050215 0.159959 -0.058640 +v 0.043219 0.159959 -0.058315 +v 0.038349 0.159959 -0.057118 +v 0.033263 0.159959 -0.055181 +v 0.008260 0.159959 -0.050678 +v 0.028023 0.159959 -0.052553 +v 0.022694 0.159959 -0.049282 +v 0.001124 0.159959 -0.044015 +v 0.017339 0.159959 -0.045415 +v 0.012021 0.159959 -0.041001 +v -0.005776 0.159959 -0.036738 +v 0.006803 0.159959 -0.036088 +v -0.012355 0.159959 -0.028913 +v 0.001748 0.159959 -0.030724 +v -0.003080 0.159959 -0.024956 +v -0.018531 0.159959 -0.020603 +v -0.007618 0.159959 -0.018834 +v -0.024218 0.159959 -0.011873 +v -0.011802 0.159959 -0.012405 +v -0.015512 0.159959 -0.005834 +v -0.029101 0.159959 -0.003209 +v 0.013364 0.159959 0.003922 +v 0.050264 0.159959 -0.011696 +v 0.022847 0.159959 -0.011696 +v 0.029049 0.159959 0.003922 +v 0.019123 0.159959 0.039593 +v -0.018456 0.159959 0.000366 +v -0.032981 0.159959 0.005000 +v -0.020637 0.159959 0.006157 +v 0.013963 0.159959 0.028768 +v -0.035863 0.159959 0.012695 +v -0.022060 0.159959 0.011500 +v -0.022730 0.159959 0.016358 +v -0.037755 0.159959 0.019822 +v -0.022649 0.159959 0.020693 +v -0.038663 0.159959 0.026322 +v -0.021824 0.159959 0.024465 +v -0.020258 0.159959 0.027637 +v -0.038594 0.159959 0.032140 +v -0.017954 0.159959 0.030171 +v 0.012157 0.159959 0.029421 +v 0.010360 0.159959 0.030047 +v 0.008576 0.159959 0.030639 +v -0.014918 0.159959 0.032028 +v 0.006806 0.159959 0.031193 +v 0.005050 0.159959 0.031702 +v 0.003312 0.159959 0.032162 +v -0.011154 0.159959 0.033170 +v -0.037555 0.159959 0.037218 +v 0.001592 0.159959 0.032566 +v -0.000107 0.159959 0.032909 +v -0.001784 0.159959 0.033185 +v -0.006666 0.159959 0.033559 +v -0.003438 0.159959 0.033389 +v -0.005065 0.159959 0.033516 +v -0.035552 0.159959 0.041499 +v 0.015415 0.159959 0.041280 +v 0.011881 0.159959 0.042794 +v -0.032592 0.159959 0.044928 +v 0.008501 0.159959 0.044141 +v 0.005258 0.159959 0.045325 +v -0.028683 0.159959 0.047448 +v 0.002132 0.159959 0.046351 +v -0.000895 0.159959 0.047224 +v -0.003843 0.159959 0.047950 +v -0.023829 0.159959 0.049001 +v -0.006729 0.159959 0.048533 +v -0.009573 0.159959 0.048977 +v -0.012394 0.159959 0.049288 +v -0.018040 0.159959 0.049532 +v -0.015210 0.159959 0.049472 +v -0.117401 0.159959 0.047934 +v -0.041662 0.159959 -0.057483 +v -0.043913 0.159959 -0.073100 +v 0.002421 0.159959 -0.073100 +v -0.007061 0.159959 -0.057483 +v -0.063859 0.159959 -0.020924 +v -0.073342 0.159959 -0.005307 +v -0.030456 0.159959 -0.020924 +v -0.039938 0.159959 -0.005307 +v -0.096185 0.159959 0.032317 +v -0.060507 0.159959 0.032317 +v -0.069989 0.159959 0.047934 +v -0.176187 0.159959 0.047934 +v -0.090965 0.159959 -0.073100 +v -0.102699 0.159959 -0.073100 +v -0.154971 0.159959 0.032317 +v -0.118095 0.159959 0.032317 +v -0.127578 0.159959 0.047934 +v -0.118095 0.159959 0.032317 +v -0.127578 0.159959 0.047934 +v -0.127578 0.152860 0.047934 +v -0.118095 0.152860 0.032317 +v -0.176187 0.159959 0.047934 +v -0.176187 0.152860 0.047934 +v -0.102699 0.159959 -0.073100 +v -0.102699 0.152860 -0.073100 +v -0.090965 0.159959 -0.073100 +v -0.090965 0.152860 -0.073100 +v -0.154971 0.159959 0.032317 +v -0.154971 0.152860 0.032317 +v -0.041662 0.159959 -0.057483 +v -0.063859 0.159959 -0.020924 +v -0.063859 0.152860 -0.020924 +v -0.041662 0.152860 -0.057483 +v -0.030456 0.159959 -0.020924 +v -0.030456 0.152860 -0.020924 +v -0.039938 0.159959 -0.005307 +v -0.039938 0.152860 -0.005307 +v -0.073342 0.159959 -0.005307 +v -0.073342 0.152860 -0.005307 +v -0.096185 0.159959 0.032317 +v -0.096185 0.152860 0.032317 +v -0.060507 0.159959 0.032317 +v -0.060507 0.152860 0.032317 +v -0.069989 0.159959 0.047934 +v -0.069989 0.152860 0.047934 +v -0.117401 0.159959 0.047934 +v -0.117401 0.152860 0.047934 +v -0.043913 0.159959 -0.073100 +v -0.043913 0.152860 -0.073100 +v 0.002421 0.159959 -0.073100 +v 0.002421 0.152860 -0.073100 +v -0.007061 0.159959 -0.057483 +v -0.007061 0.152860 -0.057483 +v 0.015415 0.159959 0.041280 +v 0.011881 0.159959 0.042794 +v 0.011881 0.152860 0.042794 +v 0.015415 0.152860 0.041280 +v 0.008501 0.159959 0.044141 +v 0.008501 0.152860 0.044141 +v 0.005258 0.159959 0.045325 +v 0.005258 0.152860 0.045325 +v 0.002132 0.159959 0.046351 +v 0.002132 0.152860 0.046351 +v -0.000895 0.159959 0.047224 +v -0.000895 0.152860 0.047224 +v -0.003843 0.159959 0.047950 +v -0.003843 0.152860 0.047950 +v -0.006729 0.159959 0.048533 +v -0.006729 0.152860 0.048533 +v -0.009573 0.159959 0.048977 +v -0.009573 0.152860 0.048977 +v -0.012394 0.159959 0.049288 +v -0.012394 0.152860 0.049288 +v -0.015210 0.159959 0.049472 +v -0.015210 0.152860 0.049472 +v -0.018040 0.159959 0.049532 +v -0.018040 0.152860 0.049532 +v -0.023829 0.159959 0.049001 +v -0.023829 0.152860 0.049001 +v -0.028683 0.159959 0.047448 +v -0.028683 0.152860 0.047448 +v -0.032592 0.159959 0.044928 +v -0.032592 0.152860 0.044928 +v -0.035552 0.159959 0.041499 +v -0.035552 0.152860 0.041499 +v -0.037555 0.159959 0.037218 +v -0.037555 0.152860 0.037218 +v -0.038594 0.159959 0.032140 +v -0.038594 0.152860 0.032140 +v -0.038663 0.159959 0.026322 +v -0.038663 0.152860 0.026322 +v -0.037755 0.159959 0.019822 +v -0.037755 0.152860 0.019822 +v -0.035863 0.159959 0.012695 +v -0.035863 0.152860 0.012695 +v -0.032981 0.159959 0.005000 +v -0.032981 0.152860 0.005000 +v -0.029101 0.159959 -0.003209 +v -0.029101 0.152860 -0.003209 +v -0.024218 0.159959 -0.011873 +v -0.024218 0.152860 -0.011873 +v -0.018531 0.159959 -0.020603 +v -0.018531 0.152860 -0.020603 +v -0.012355 0.159959 -0.028913 +v -0.012355 0.152860 -0.028913 +v -0.005776 0.159959 -0.036738 +v -0.005776 0.152860 -0.036738 +v 0.001124 0.159959 -0.044015 +v 0.001124 0.152860 -0.044015 +v 0.008260 0.159959 -0.050678 +v 0.008260 0.152860 -0.050678 +v 0.015548 0.159959 -0.056662 +v 0.015548 0.152860 -0.056662 +v 0.022903 0.159959 -0.061903 +v 0.022903 0.152860 -0.061903 +v 0.030242 0.159959 -0.066337 +v 0.030242 0.152860 -0.066337 +v 0.037480 0.159959 -0.069897 +v 0.037480 0.152860 -0.069897 +v 0.044533 0.159959 -0.072521 +v 0.044533 0.152860 -0.072521 +v 0.051316 0.159959 -0.074142 +v 0.051316 0.152860 -0.074142 +v 0.057747 0.159959 -0.074697 +v 0.057747 0.152860 -0.074697 +v 0.060057 0.159959 -0.074647 +v 0.060057 0.152860 -0.074647 +v 0.062212 0.159959 -0.074489 +v 0.062212 0.152860 -0.074489 +v 0.064237 0.159959 -0.074212 +v 0.064237 0.152860 -0.074212 +v 0.066157 0.159959 -0.073803 +v 0.066157 0.152860 -0.073803 +v 0.067995 0.159959 -0.073252 +v 0.067995 0.152860 -0.073252 +v 0.069775 0.159959 -0.072546 +v 0.069775 0.152860 -0.072546 +v 0.071521 0.159959 -0.071673 +v 0.071521 0.152860 -0.071673 +v 0.073258 0.159959 -0.070622 +v 0.073258 0.152860 -0.070622 +v 0.075009 0.159959 -0.069382 +v 0.075009 0.152860 -0.069382 +v 0.076799 0.159959 -0.067940 +v 0.076799 0.152860 -0.067940 +v 0.078652 0.159959 -0.066284 +v 0.078652 0.152860 -0.066284 +v 0.080591 0.159959 -0.064404 +v 0.080591 0.152860 -0.064404 +v 0.069923 0.159959 -0.046835 +v 0.069923 0.152860 -0.046835 +v 0.068660 0.159959 -0.048709 +v 0.068660 0.152860 -0.048709 +v 0.067287 0.159959 -0.050427 +v 0.067287 0.152860 -0.050427 +v 0.065808 0.159959 -0.051987 +v 0.065808 0.152860 -0.051987 +v 0.064222 0.159959 -0.053388 +v 0.064222 0.152860 -0.053388 +v 0.062530 0.159959 -0.054629 +v 0.062530 0.152860 -0.054629 +v 0.060734 0.159959 -0.055708 +v 0.060734 0.152860 -0.055708 +v 0.058834 0.159959 -0.056625 +v 0.058834 0.152860 -0.056625 +v 0.056831 0.159959 -0.057378 +v 0.056831 0.152860 -0.057378 +v 0.054726 0.159959 -0.057965 +v 0.054726 0.152860 -0.057965 +v 0.052521 0.159959 -0.058387 +v 0.052521 0.152860 -0.058387 +v 0.050215 0.159959 -0.058640 +v 0.050215 0.152860 -0.058640 +v 0.047810 0.159959 -0.058725 +v 0.047810 0.152860 -0.058725 +v 0.043219 0.159959 -0.058315 +v 0.043219 0.152860 -0.058315 +v 0.038349 0.159959 -0.057118 +v 0.038349 0.152860 -0.057118 +v 0.033263 0.159959 -0.055181 +v 0.033263 0.152860 -0.055181 +v 0.028023 0.159959 -0.052553 +v 0.028023 0.152860 -0.052553 +v 0.022694 0.159959 -0.049282 +v 0.022694 0.152860 -0.049282 +v 0.017339 0.159959 -0.045415 +v 0.017339 0.152860 -0.045415 +v 0.012021 0.159959 -0.041001 +v 0.012021 0.152860 -0.041001 +v 0.006803 0.159959 -0.036088 +v 0.006803 0.152860 -0.036088 +v 0.001748 0.159959 -0.030724 +v 0.001748 0.152860 -0.030724 +v -0.003080 0.159959 -0.024956 +v -0.003080 0.152860 -0.024956 +v -0.007618 0.159959 -0.018834 +v -0.007618 0.152860 -0.018834 +v -0.011802 0.159959 -0.012405 +v -0.011802 0.152860 -0.012405 +v -0.015512 0.159959 -0.005834 +v -0.015512 0.152860 -0.005834 +v -0.018456 0.159959 0.000366 +v -0.018456 0.152860 0.000366 +v -0.020637 0.159959 0.006157 +v -0.020637 0.152860 0.006157 +v -0.022060 0.159959 0.011500 +v -0.022060 0.152860 0.011500 +v -0.022730 0.159959 0.016358 +v -0.022730 0.152860 0.016358 +v -0.022649 0.159959 0.020693 +v -0.022649 0.152860 0.020693 +v -0.021824 0.159959 0.024465 +v -0.021824 0.152860 0.024465 +v -0.020258 0.159959 0.027637 +v -0.020258 0.152860 0.027637 +v -0.017954 0.159959 0.030171 +v -0.017954 0.152860 0.030171 +v -0.014918 0.159959 0.032028 +v -0.014918 0.152860 0.032028 +v -0.011154 0.159959 0.033170 +v -0.011154 0.152860 0.033170 +v -0.006666 0.159959 0.033559 +v -0.006666 0.152860 0.033559 +v -0.005065 0.159959 0.033516 +v -0.005065 0.152860 0.033516 +v -0.003438 0.159959 0.033389 +v -0.003438 0.152860 0.033389 +v -0.001784 0.159959 0.033185 +v -0.001784 0.152860 0.033185 +v -0.000107 0.159959 0.032909 +v -0.000107 0.152860 0.032909 +v 0.001592 0.159959 0.032566 +v 0.001592 0.152860 0.032566 +v 0.003312 0.159959 0.032162 +v 0.003312 0.152860 0.032162 +v 0.005050 0.159959 0.031702 +v 0.005050 0.152860 0.031702 +v 0.006806 0.159959 0.031193 +v 0.006806 0.152860 0.031193 +v 0.008576 0.159959 0.030639 +v 0.008576 0.152860 0.030639 +v 0.010360 0.159959 0.030047 +v 0.010360 0.152860 0.030047 +v 0.012157 0.159959 0.029421 +v 0.012157 0.152860 0.029421 +v 0.013963 0.159959 0.028768 +v 0.013963 0.152860 0.028768 +v 0.029049 0.159959 0.003922 +v 0.029049 0.152860 0.003922 +v 0.013364 0.159959 0.003922 +v 0.013364 0.152860 0.003922 +v 0.022847 0.159959 -0.011696 +v 0.022847 0.152860 -0.011696 +v 0.050264 0.159959 -0.011696 +v 0.050264 0.152860 -0.011696 +v 0.019123 0.159959 0.039593 +v 0.019123 0.152860 0.039593 +v 0.151918 0.159959 -0.074119 +v 0.156982 0.159959 -0.072438 +v 0.156982 0.152860 -0.072438 +v 0.151918 0.152860 -0.074119 +v 0.160962 0.159959 -0.069734 +v 0.160962 0.152860 -0.069734 +v 0.163882 0.159959 -0.066087 +v 0.163882 0.152860 -0.066087 +v 0.165766 0.159959 -0.061577 +v 0.165766 0.152860 -0.061577 +v 0.166638 0.159959 -0.056285 +v 0.166638 0.152860 -0.056285 +v 0.166522 0.159959 -0.050290 +v 0.166522 0.152860 -0.050290 +v 0.165443 0.159959 -0.043673 +v 0.165443 0.152860 -0.043673 +v 0.163424 0.159959 -0.036514 +v 0.163424 0.152860 -0.036514 +v 0.160490 0.159959 -0.028892 +v 0.160490 0.152860 -0.028892 +v 0.156664 0.159959 -0.020888 +v 0.156664 0.152860 -0.020888 +v 0.151972 0.159959 -0.012583 +v 0.151972 0.152860 -0.012583 +v 0.146723 0.159959 -0.004501 +v 0.146723 0.152860 -0.004501 +v 0.140942 0.159959 0.003357 +v 0.140942 0.152860 0.003357 +v 0.134701 0.159959 0.010899 +v 0.134701 0.152860 0.010899 +v 0.128074 0.159959 0.018034 +v 0.128074 0.152860 0.018034 +v 0.121136 0.159959 0.024671 +v 0.121136 0.152860 0.024671 +v 0.113962 0.159959 0.030720 +v 0.113962 0.152860 0.030720 +v 0.106623 0.159959 0.036088 +v 0.106623 0.152860 0.036088 +v 0.099196 0.159959 0.040684 +v 0.099196 0.152860 0.040684 +v 0.091754 0.159959 0.044418 +v 0.091754 0.152860 0.044418 +v 0.084371 0.159959 0.047198 +v 0.084371 0.152860 0.047198 +v 0.077121 0.159959 0.048933 +v 0.077121 0.152860 0.048933 +v 0.070079 0.159959 0.049532 +v 0.070079 0.152860 0.049532 +v 0.063974 0.159959 0.048936 +v 0.063974 0.152860 0.048936 +v 0.058989 0.159959 0.047211 +v 0.058989 0.152860 0.047211 +v 0.055095 0.159959 0.044443 +v 0.055095 0.152860 0.044443 +v 0.052262 0.159959 0.040724 +v 0.052262 0.152860 0.040724 +v 0.050459 0.159959 0.036142 +v 0.050459 0.152860 0.036142 +v 0.049658 0.159959 0.030786 +v 0.049658 0.152860 0.030786 +v 0.049828 0.159959 0.024747 +v 0.049828 0.152860 0.024747 +v 0.050940 0.159959 0.018113 +v 0.050940 0.152860 0.018113 +v 0.052964 0.159959 0.010974 +v 0.052964 0.152860 0.010974 +v 0.055871 0.159959 0.003418 +v 0.055871 0.152860 0.003418 +v 0.059630 0.159959 -0.004464 +v 0.059630 0.152860 -0.004464 +v 0.064212 0.159959 -0.012583 +v 0.064212 0.152860 -0.012583 +v 0.069589 0.159959 -0.020851 +v 0.069589 0.152860 -0.020851 +v 0.075486 0.159959 -0.028830 +v 0.075486 0.152860 -0.028830 +v 0.081823 0.159959 -0.036439 +v 0.081823 0.152860 -0.036439 +v 0.088522 0.159959 -0.043594 +v 0.088522 0.152860 -0.043594 +v 0.095505 0.159959 -0.050215 +v 0.095505 0.152860 -0.050215 +v 0.102694 0.159959 -0.056218 +v 0.102694 0.152860 -0.056218 +v 0.110009 0.159959 -0.061523 +v 0.110009 0.152860 -0.061523 +v 0.117373 0.159959 -0.066047 +v 0.117373 0.152860 -0.066047 +v 0.124708 0.159959 -0.069709 +v 0.124708 0.152860 -0.069709 +v 0.131933 0.159959 -0.072426 +v 0.131933 0.152860 -0.072426 +v 0.138972 0.159959 -0.074116 +v 0.138972 0.152860 -0.074116 +v 0.145746 0.159959 -0.074697 +v 0.145746 0.152860 -0.074697 +v 0.084735 0.159959 0.033156 +v 0.089696 0.159959 0.031978 +v 0.089696 0.152860 0.031978 +v 0.084735 0.152860 0.033156 +v 0.094840 0.159959 0.030068 +v 0.094840 0.152860 0.030068 +v 0.100110 0.159959 0.027473 +v 0.100110 0.152860 0.027473 +v 0.105448 0.159959 0.024236 +v 0.105448 0.152860 0.024236 +v 0.110796 0.159959 0.020404 +v 0.110796 0.152860 0.020404 +v 0.116098 0.159959 0.016021 +v 0.116098 0.152860 0.016021 +v 0.121294 0.159959 0.011132 +v 0.121294 0.152860 0.011132 +v 0.126328 0.159959 0.005782 +v 0.126328 0.152860 0.005782 +v 0.131142 0.159959 0.000017 +v 0.131142 0.152860 0.000017 +v 0.135679 0.159959 -0.006120 +v 0.135679 0.152860 -0.006120 +v 0.139879 0.159959 -0.012583 +v 0.139879 0.152860 -0.012583 +v 0.143549 0.159959 -0.019083 +v 0.143549 0.152860 -0.019083 +v 0.146480 0.159959 -0.025244 +v 0.146480 0.152860 -0.025244 +v 0.148675 0.159959 -0.031023 +v 0.148675 0.152860 -0.031023 +v 0.150140 0.159959 -0.036377 +v 0.150140 0.152860 -0.036377 +v 0.150878 0.159959 -0.041263 +v 0.150878 0.152860 -0.041263 +v 0.150894 0.159959 -0.045637 +v 0.150894 0.152860 -0.045637 +v 0.150191 0.159959 -0.049456 +v 0.150191 0.152860 -0.049456 +v 0.148774 0.159959 -0.052678 +v 0.148774 0.152860 -0.052678 +v 0.146648 0.159959 -0.055259 +v 0.146648 0.152860 -0.055259 +v 0.143815 0.159959 -0.057156 +v 0.143815 0.152860 -0.057156 +v 0.140280 0.159959 -0.058326 +v 0.140280 0.152860 -0.058326 +v 0.136048 0.159959 -0.058725 +v 0.136048 0.152860 -0.058725 +v 0.131358 0.159959 -0.058326 +v 0.131358 0.152860 -0.058326 +v 0.126426 0.159959 -0.057156 +v 0.126426 0.152860 -0.057156 +v 0.121309 0.159959 -0.055259 +v 0.121309 0.152860 -0.055259 +v 0.116063 0.159959 -0.052678 +v 0.116063 0.152860 -0.052678 +v 0.110745 0.159959 -0.049456 +v 0.110745 0.152860 -0.049456 +v 0.105413 0.159959 -0.045637 +v 0.105413 0.152860 -0.045637 +v 0.100123 0.159959 -0.041263 +v 0.100123 0.152860 -0.041263 +v 0.094933 0.159959 -0.036377 +v 0.094933 0.152860 -0.036377 +v 0.089899 0.159959 -0.031023 +v 0.089899 0.152860 -0.031023 +v 0.085078 0.159959 -0.025244 +v 0.085078 0.152860 -0.025244 +v 0.080528 0.159959 -0.019083 +v 0.080528 0.152860 -0.019083 +v 0.076305 0.159959 -0.012583 +v 0.076305 0.152860 -0.012583 +v 0.072657 0.159959 -0.006120 +v 0.072657 0.152860 -0.006120 +v 0.069741 0.159959 0.000017 +v 0.069741 0.152860 0.000017 +v 0.067552 0.159959 0.005782 +v 0.067552 0.152860 0.005782 +v 0.066087 0.159959 0.011132 +v 0.066087 0.152860 0.011132 +v 0.065343 0.159959 0.016021 +v 0.065343 0.152860 0.016021 +v 0.065315 0.159959 0.020404 +v 0.065315 0.152860 0.020404 +v 0.066001 0.159959 0.024236 +v 0.066001 0.152860 0.024236 +v 0.067398 0.159959 0.027473 +v 0.067398 0.152860 0.027473 +v 0.069501 0.159959 0.030068 +v 0.069501 0.152860 0.030068 +v 0.072307 0.159959 0.031978 +v 0.072307 0.152860 0.031978 +v 0.075814 0.159959 0.033156 +v 0.075814 0.152860 0.033156 +v 0.080016 0.159959 0.033559 +v 0.080016 0.152860 0.033559 +v 0.004632 0.000011 0.225947 +v 0.004632 0.144213 0.225947 +v -0.039651 0.144213 0.221586 +v -0.039651 0.000011 0.221586 +v 0.048915 0.000011 0.221586 +v 0.048915 0.144213 0.221586 +v -0.082232 0.000011 0.208669 +v -0.082232 0.144213 0.208669 +v -0.121475 0.144213 0.187693 +v -0.121475 0.000011 0.187693 +v -0.155871 0.144213 0.159464 +v -0.155871 0.000011 0.159464 +v -0.184100 0.144213 0.125068 +v -0.184100 0.000011 0.125068 +v -0.205076 0.144213 0.085825 +v -0.205076 0.000011 0.085825 +v -0.217993 0.144213 0.043244 +v -0.217993 0.000011 0.043244 +v -0.222354 0.144213 -0.001039 +v -0.222354 0.000011 -0.001039 +v -0.217993 0.144213 -0.045322 +v -0.217993 0.000011 -0.045322 +v -0.205076 0.144213 -0.087903 +v -0.205076 0.000011 -0.087903 +v -0.184100 0.144213 -0.127146 +v -0.184100 0.000011 -0.127146 +v -0.155871 0.144213 -0.161543 +v -0.155871 0.000011 -0.161543 +v -0.121475 0.144213 -0.189771 +v -0.121475 0.000011 -0.189771 +v -0.082232 0.144213 -0.210747 +v -0.082232 0.000011 -0.210747 +v -0.039651 0.144213 -0.223664 +v -0.039651 0.000011 -0.223664 +v 0.004632 0.144213 -0.228025 +v 0.004632 0.000011 -0.228025 +v 0.048915 0.144213 -0.223664 +v 0.048915 0.000011 -0.223664 +v 0.091496 0.144213 -0.210747 +v 0.091496 0.000011 -0.210747 +v 0.130739 0.144213 -0.189771 +v 0.130739 0.000011 -0.189771 +v 0.165136 0.144213 -0.161542 +v 0.165136 0.000011 -0.161542 +v 0.193364 0.144213 -0.127146 +v 0.193364 0.000011 -0.127146 +v 0.214340 0.144213 -0.087903 +v 0.214340 0.000011 -0.087903 +v 0.227257 0.144213 -0.045322 +v 0.227257 0.000011 -0.045322 +v 0.231618 0.144213 -0.001039 +v 0.231618 0.000011 -0.001039 +v 0.227257 0.144213 0.043244 +v 0.227257 0.000011 0.043244 +v 0.214340 0.144213 0.085825 +v 0.214340 0.000011 0.085825 +v 0.193364 0.144213 0.125068 +v 0.193364 0.000011 0.125068 +v 0.165135 0.144213 0.159465 +v 0.165135 0.000011 0.159465 +v 0.130738 0.144213 0.187693 +v 0.130738 0.000011 0.187693 +v 0.091496 0.144213 0.208669 +v 0.091496 0.000011 0.208669 +v -0.037997 0.152650 0.213271 +v 0.004632 0.152650 0.217469 +v 0.047261 0.152650 0.213271 +v 0.088251 0.152650 0.200837 +v 0.126029 0.152650 0.180644 +v 0.159141 0.152650 0.153470 +v 0.186315 0.152650 0.120358 +v 0.206507 0.152650 0.082581 +v 0.218942 0.152650 0.041590 +v 0.223140 0.152650 -0.001039 +v 0.218942 0.152650 -0.043668 +v 0.206508 0.152650 -0.084659 +v 0.186315 0.152650 -0.122436 +v 0.159141 0.152650 -0.155548 +v 0.126029 0.152650 -0.182722 +v 0.088252 0.152650 -0.202914 +v 0.047261 0.152650 -0.215349 +v 0.004632 0.152650 -0.219547 +v -0.037997 0.152650 -0.215349 +v -0.078988 0.152650 -0.202915 +v -0.116765 0.152650 -0.182722 +v -0.149877 0.152650 -0.155548 +v -0.177051 0.152650 -0.122436 +v -0.197243 0.152650 -0.084659 +v -0.209678 0.152650 -0.043668 +v -0.213876 0.152650 -0.001039 +v -0.209678 0.152650 0.041590 +v -0.197243 0.152650 0.082581 +v -0.177051 0.152650 0.120358 +v -0.149877 0.152650 0.153470 +v -0.116765 0.152650 0.180644 +v -0.078987 0.152650 0.200836 +vn 0.0000 1.0000 -0.0000 +vn 0.0000 1.0000 -0.0003 +vn -0.0000 1.0000 0.0020 +vn 0.0000 1.0000 -0.0005 +vn -0.0000 1.0000 -0.0004 +vn -0.0000 1.0000 0.0003 +vn 0.0000 1.0000 0.0014 +vn 0.8548 0.0000 0.5190 +vn 0.0000 0.0000 1.0000 +vn -0.8548 0.0000 -0.5190 +vn 0.0000 0.0000 -1.0000 +vn 0.3938 0.0000 0.9192 +vn 0.3702 0.0000 0.9289 +vn 0.3430 0.0000 0.9394 +vn 0.3118 0.0000 0.9501 +vn 0.2771 0.0000 0.9608 +vn 0.2391 0.0000 0.9710 +vn 0.1980 0.0000 0.9802 +vn 0.1542 0.0000 0.9880 +vn 0.1543 0.0000 0.9880 +vn 0.1096 0.0000 0.9940 +vn 0.0647 -0.0000 0.9979 +vn 0.0212 0.0000 0.9998 +vn -0.0913 0.0000 0.9958 +vn -0.3047 0.0000 0.9524 +vn -0.5418 0.0000 0.8405 +vn -0.7570 0.0000 0.6535 +vn -0.9058 0.0000 0.4238 +vn -0.9797 0.0000 0.2005 +vn -0.9999 0.0000 0.0119 +vn -0.9904 0.0000 -0.1384 +vn -0.9665 0.0000 -0.2566 +vn -0.9365 -0.0000 -0.3507 +vn -0.9041 0.0000 -0.4273 +vn -0.8712 -0.0000 -0.4910 +vn -0.8379 0.0000 -0.5458 +vn -0.8026 0.0000 -0.5965 +vn -0.7654 0.0000 -0.6435 +vn -0.7257 0.0000 -0.6881 +vn -0.6825 0.0000 -0.7309 +vn -0.6346 0.0000 -0.7729 +vn -0.5803 0.0000 -0.8144 +vn -0.5171 0.0000 -0.8559 +vn -0.4414 0.0000 -0.8973 +vn -0.3487 0.0000 -0.9372 +vn -0.2324 0.0000 -0.9726 +vn -0.0860 0.0000 -0.9963 +vn 0.0216 0.0000 -0.9998 +vn 0.0731 0.0000 -0.9973 +vn 0.1355 0.0000 -0.9908 +vn 0.2083 0.0000 -0.9781 +vn 0.2084 0.0000 -0.9781 +vn 0.2871 0.0000 -0.9579 +vn 0.3687 0.0000 -0.9295 +vn 0.4472 0.0000 -0.8944 +vn 0.5177 0.0000 -0.8556 +vn 0.5779 0.0000 -0.8161 +vn 0.6273 0.0000 -0.7788 +vn 0.6664 0.0000 -0.7456 +vn 0.6961 0.0000 -0.7180 +vn -0.8292 0.0000 0.5589 +vn -0.7812 0.0000 0.6243 +vn -0.7257 0.0000 0.6880 +vn -0.6620 0.0000 0.7495 +vn -0.5914 0.0000 0.8063 +vn -0.5914 0.0000 0.8064 +vn -0.5150 0.0000 0.8572 +vn -0.4347 0.0000 0.9006 +vn -0.3519 0.0000 0.9360 +vn -0.2686 0.0000 0.9633 +vn -0.2686 0.0000 0.9632 +vn -0.1880 0.0000 0.9822 +vn -0.1091 0.0000 0.9940 +vn -0.0353 0.0000 0.9994 +vn 0.0890 0.0000 0.9960 +vn 0.2387 0.0000 0.9711 +vn 0.3559 0.0000 0.9345 +vn 0.4483 0.0000 0.8939 +vn 0.5231 0.0000 0.8523 +vn 0.5854 0.0000 0.8107 +vn 0.6387 0.0000 0.7695 +vn 0.6855 0.0000 0.7281 +vn 0.7278 -0.0000 0.6858 +vn 0.7668 -0.0000 0.6419 +vn 0.8034 -0.0000 0.5955 +vn 0.8381 -0.0000 0.5455 +vn 0.8708 -0.0000 0.4917 +vn 0.9033 -0.0000 0.4289 +vn 0.9358 -0.0000 0.3524 +vn 0.9663 -0.0000 0.2574 +vn 0.9906 -0.0000 0.1366 +vn 0.9998 -0.0000 -0.0187 +vn 0.9769 -0.0000 -0.2136 +vn 0.8967 0.0000 -0.4427 +vn 0.7399 0.0000 -0.6727 +vn 0.5218 0.0000 -0.8531 +vn 0.2903 0.0000 -0.9569 +vn 0.0864 0.0000 -0.9963 +vn -0.0269 0.0000 -0.9996 +vn -0.0778 0.0000 -0.9970 +vn -0.1224 0.0000 -0.9925 +vn -0.1624 0.0000 -0.9867 +vn -0.1979 0.0000 -0.9802 +vn -0.2287 0.0000 -0.9735 +vn -0.2554 -0.0000 -0.9668 +vn -0.2787 0.0000 -0.9604 +vn -0.2987 0.0000 -0.9543 +vn -0.3150 0.0000 -0.9491 +vn -0.3345 0.0000 -0.9424 +vn -0.3290 0.0000 -0.9443 +vn -0.3400 0.0000 -0.9404 +vn 0.4141 0.0000 0.9102 +vn 0.3150 0.0000 -0.9491 +vn 0.5620 0.0000 -0.8272 +vn 0.5620 0.0000 -0.8271 +vn 0.7806 0.0000 -0.6250 +vn 0.9227 0.0000 -0.3855 +vn 0.9867 0.0000 -0.1626 +vn 0.9998 0.0000 0.0193 +vn 0.9870 0.0000 0.1609 +vn 0.9625 0.0000 0.2714 +vn 0.9332 0.0000 0.3592 +vn 0.9022 0.0000 0.4313 +vn 0.8707 -0.0000 0.4919 +vn 0.8386 0.0000 0.5447 +vn 0.8055 -0.0000 0.5926 +vn 0.7704 -0.0000 0.6375 +vn 0.7327 -0.0000 0.6805 +vn 0.6913 -0.0000 0.7226 +vn 0.6446 0.0000 0.7645 +vn 0.5904 0.0000 0.8071 +vn 0.5262 0.0000 0.8504 +vn 0.5262 0.0000 0.8503 +vn 0.4485 0.0000 0.8938 +vn 0.3524 0.0000 0.9359 +vn 0.2327 0.0000 0.9725 +vn 0.0848 0.0000 0.9964 +vn -0.0967 0.0000 0.9953 +vn -0.3270 0.0000 0.9450 +vn -0.5794 0.0000 0.8151 +vn -0.7955 0.0000 0.6060 +vn -0.9305 0.0000 0.3662 +vn -0.9890 -0.0000 0.1479 +vn -0.9996 -0.0000 -0.0281 +vn -0.9862 -0.0000 -0.1653 +vn -0.9621 -0.0000 -0.2728 +vn -0.9333 0.0000 -0.3591 +vn -0.9026 0.0000 -0.4305 +vn -0.8709 -0.0000 -0.4915 +vn -0.8383 -0.0000 -0.5452 +vn -0.8042 -0.0000 -0.5944 +vn -0.7684 -0.0000 -0.6400 +vn -0.7300 0.0000 -0.6835 +vn -0.6881 0.0000 -0.7257 +vn -0.6410 0.0000 -0.7676 +vn -0.6409 0.0000 -0.7676 +vn -0.5871 0.0000 -0.8095 +vn -0.5235 0.0000 -0.8521 +vn -0.4467 0.0000 -0.8947 +vn -0.3520 0.0000 -0.9360 +vn -0.2335 0.0000 -0.9724 +vn -0.0855 0.0000 -0.9963 +vn 0.0932 0.0000 -0.9956 +vn -0.2310 0.0000 -0.9729 +vn -0.3481 0.0000 -0.9375 +vn -0.4418 -0.0000 -0.8971 +vn -0.5185 0.0000 -0.8551 +vn -0.5824 0.0000 -0.8129 +vn -0.6371 0.0000 -0.7707 +vn -0.6853 0.0000 -0.7283 +vn -0.7283 0.0000 -0.6853 +vn -0.7676 -0.0000 -0.6410 +vn -0.8041 0.0000 -0.5945 +vn -0.8385 -0.0000 -0.5449 +vn -0.8708 0.0000 -0.4917 +vn -0.9030 0.0000 -0.4296 +vn -0.9348 0.0000 -0.3551 +vn -0.9645 0.0000 -0.2639 +vn -0.9888 0.0000 -0.1494 +vn -1.0000 0.0000 -0.0037 +vn -0.9835 0.0000 0.1810 +vn -0.9154 0.0000 0.4026 +vn -0.7719 0.0000 0.6358 +vn -0.5564 0.0000 0.8309 +vn -0.3142 0.0000 0.9494 +vn -0.0939 0.0000 0.9956 +vn 0.2308 0.0000 0.9730 +vn 0.3476 0.0000 0.9376 +vn 0.4415 0.0000 0.8973 +vn 0.5182 0.0000 0.8553 +vn 0.5823 0.0000 0.8130 +vn 0.6372 0.0000 0.7707 +vn 0.7285 0.0000 0.6850 +vn 0.7679 0.0000 0.6406 +vn 0.8044 0.0000 0.5941 +vn 0.8386 -0.0000 0.5448 +vn 0.8708 -0.0000 0.4916 +vn 0.9032 -0.0000 0.4292 +vn 0.9349 0.0000 0.3550 +vn 0.9645 -0.0000 0.2641 +vn 0.9886 -0.0000 0.1504 +vn 1.0000 0.0000 0.0064 +vn 0.9843 -0.0000 -0.1762 +vn 0.9181 -0.0000 -0.3963 +vn 0.7769 0.0000 -0.6296 +vn 0.5627 0.0000 -0.8267 +vn 0.3184 0.0000 -0.9480 +vn 0.0955 0.0000 -0.9954 +vn -0.0851 0.0000 -0.9964 +vn -0.0980 -0.0000 0.9952 +vn 0.0980 -0.0000 0.9952 +vn -0.4714 -0.0000 0.8819 +vn -0.6344 -0.0000 0.7730 +vn -0.7730 -0.0000 0.6344 +vn -0.8819 -0.0000 0.4714 +vn -0.9569 -0.0000 0.2903 +vn -0.9952 0.0000 0.0980 +vn -0.9952 0.0000 -0.0980 +vn -0.9569 0.0000 -0.2903 +vn -0.8819 0.0000 -0.4714 +vn -0.7730 0.0000 -0.6344 +vn -0.6344 0.0000 -0.7730 +vn -0.4714 0.0000 -0.8819 +vn -0.2903 0.0000 -0.9569 +vn -0.0980 0.0000 -0.9952 +vn 0.0980 0.0000 -0.9952 +vn 0.4714 0.0000 -0.8819 +vn 0.6344 0.0000 -0.7730 +vn 0.7730 0.0000 -0.6344 +vn 0.8819 0.0000 -0.4714 +vn 0.9569 0.0000 -0.2903 +vn 0.9952 0.0000 -0.0980 +vn 0.9952 0.0000 0.0980 +vn 0.9569 0.0000 0.2903 +vn 0.8819 0.0000 0.4714 +vn 0.7730 -0.0000 0.6344 +vn 0.6344 -0.0000 0.7730 +vn 0.4714 -0.0000 0.8819 +vn 0.2903 -0.0000 0.9569 +vn -0.2903 -0.0000 0.9569 +vn -0.0693 0.7071 0.7037 +vn -0.2053 0.7071 0.6766 +vn -0.3333 0.7071 0.6236 +vn -0.4486 0.7071 0.5466 +vn -0.5466 0.7071 0.4486 +vn -0.6236 0.7071 0.3333 +vn -0.6766 0.7071 0.2053 +vn -0.6767 0.7071 0.2053 +vn -0.7037 0.7071 0.0693 +vn -0.7037 0.7071 -0.0693 +vn -0.6766 0.7071 -0.2053 +vn -0.6767 0.7071 -0.2053 +vn -0.6236 0.7071 -0.3333 +vn -0.5466 0.7071 -0.4486 +vn -0.4486 0.7071 -0.5466 +vn -0.3333 0.7071 -0.6236 +vn -0.2053 0.7071 -0.6767 +vn -0.0693 0.7071 -0.7037 +vn 0.0693 0.7071 -0.7037 +vn 0.2053 0.7071 -0.6766 +vn 0.2053 0.7071 -0.6767 +vn 0.3333 0.7071 -0.6236 +vn 0.4486 0.7071 -0.5466 +vn 0.5466 0.7071 -0.4486 +vn 0.6236 0.7071 -0.3333 +vn 0.6767 0.7071 -0.2053 +vn 0.7037 0.7071 -0.0693 +vn 0.7037 0.7071 0.0693 +vn 0.6766 0.7071 0.2053 +vn 0.6767 0.7071 0.2053 +vn 0.6236 0.7071 0.3333 +vn 0.5466 0.7071 0.4486 +vn 0.4486 0.7071 0.5466 +vn 0.3333 0.7071 0.6236 +vn 0.2053 0.7071 0.6767 +vn 0.0693 0.7071 0.7037 +vn 0.3429 0.0000 0.9394 +vn -0.2053 0.7071 0.6767 +usemtl Material.005 +s 1 +f 1//1 2//1 3//2 +f 1//1 4//1 2//1 +f 5//1 4//1 1//1 +f 5//1 6//1 4//1 +f 7//1 6//1 5//1 +f 7//1 8//1 6//1 +f 9//1 8//1 7//1 +f 9//1 10//1 8//1 +f 11//1 10//1 9//1 +f 11//1 12//1 10//1 +f 13//1 14//1 11//1 +f 14//1 12//1 11//1 +f 13//1 15//3 14//1 +f 16//3 12//1 14//1 +f 17//1 12//1 16//3 +f 13//1 18//1 15//3 +f 19//1 12//1 17//1 +f 13//1 20//1 18//1 +f 19//1 21//1 12//1 +f 22//1 20//1 13//1 +f 23//1 21//1 19//1 +f 22//1 24//1 20//1 +f 25//1 21//1 23//1 +f 22//1 26//1 24//1 +f 25//1 27//1 21//1 +f 28//1 26//1 22//1 +f 29//1 27//1 25//1 +f 28//1 30//1 26//1 +f 31//1 27//1 29//1 +f 28//1 32//1 30//1 +f 31//1 33//1 27//1 +f 34//1 32//1 28//1 +f 35//1 33//1 31//1 +f 34//1 36//1 32//1 +f 35//1 37//1 33//1 +f 38//1 36//1 34//1 +f 39//1 37//1 35//1 +f 38//1 40//1 36//1 +f 41//1 37//1 39//1 +f 38//1 42//1 40//1 +f 41//1 43//1 37//1 +f 44//1 42//1 38//1 +f 45//1 43//1 41//1 +f 44//1 46//1 42//1 +f 45//1 47//1 43//1 +f 48//1 46//1 44//1 +f 49//1 47//1 45//1 +f 48//1 50//1 46//1 +f 51//1 50//1 48//1 +f 51//1 52//1 50//1 +f 53//1 47//1 49//1 +f 53//1 54//1 47//1 +f 51//1 55//1 52//1 +f 56//1 54//1 53//1 +f 56//1 57//1 54//1 +f 58//1 55//1 51//1 +f 58//1 59//1 55//1 +f 60//1 57//1 56//1 +f 60//1 61//1 57//1 +f 62//1 59//1 58//1 +f 63//1 61//1 60//1 +f 62//1 64//1 59//1 +f 63//1 65//1 61//1 +f 66//1 64//1 62//1 +f 67//1 65//1 63//1 +f 66//1 68//1 64//1 +f 69//1 65//1 67//1 +f 66//1 70//1 68//1 +f 69//1 71//1 65//1 +f 72//1 70//1 66//1 +f 73//1 71//1 69//1 +f 72//1 74//1 70//1 +f 75//1 71//1 73//1 +f 72//1 76//1 74//1 +f 75//1 77//1 71//1 +f 78//1 76//1 72//1 +f 79//1 77//1 75//1 +f 78//1 80//1 76//1 +f 81//1 77//1 79//1 +f 78//1 82//1 80//1 +f 81//1 83//1 77//1 +f 84//1 82//1 78//1 +f 85//1 83//1 81//1 +f 84//1 86//1 82//1 +f 87//1 83//1 85//1 +f 84//1 87//1 86//1 +f 84//1 83//1 87//1 +f 84//1 88//1 83//1 +f 89//1 88//1 84//1 +f 89//1 90//1 88//1 +f 91//1 90//1 89//1 +f 91//1 92//1 90//1 +f 93//1 92//1 91//1 +f 93//1 94//1 92//1 +f 95//1 94//1 93//1 +f 95//1 96//1 94//1 +f 97//1 98//4 99//5 +f 97//1 100//6 98//4 +f 97//1 101//1 100//6 +f 97//1 102//1 101//1 +f 103//1 102//1 97//1 +f 103//1 104//1 102//1 +f 103//1 105//1 104//1 +f 103//1 106//1 105//1 +f 107//1 106//1 103//1 +f 107//1 108//1 106//1 +f 107//1 109//1 108//1 +f 110//1 109//1 107//1 +f 110//1 111//1 109//1 +f 110//1 112//1 111//1 +f 113//1 112//1 110//1 +f 113//1 114//1 112//1 +f 113//1 115//1 114//1 +f 115//1 116//1 114//1 +f 116//1 117//1 114//1 +f 117//1 118//1 114//1 +f 118//1 119//1 114//1 +f 119//1 120//1 114//1 +f 120//1 121//1 114//1 +f 121//1 122//1 114//1 +f 122//1 123//1 114//1 +f 123//1 124//1 114//1 +f 124//1 125//1 114//1 +f 126//1 127//4 113//1 +f 127//4 128//4 113//1 +f 128//4 115//1 113//1 +f 126//1 129//4 127//4 +f 126//1 130//1 129//4 +f 126//1 131//1 130//1 +f 132//1 131//1 126//1 +f 132//1 133//1 131//1 +f 132//1 134//1 133//1 +f 135//1 134//1 132//1 +f 135//1 136//1 134//1 +f 135//1 137//1 136//1 +f 138//1 137//1 135//1 +f 138//1 139//1 137//1 +f 140//1 139//1 138//1 +f 140//1 141//1 139//1 +f 140//1 142//1 141//1 +f 143//1 142//1 140//1 +f 143//1 144//1 142//1 +f 145//1 144//1 143//1 +f 145//1 146//1 144//1 +f 145//1 147//1 146//1 +f 148//1 147//1 145//1 +f 149//1 150//1 151//1 +f 149//1 152//1 150//1 +f 152//1 153//1 150//1 +f 148//1 154//1 147//1 +f 155//1 154//1 148//1 +f 155//1 156//1 154//1 +f 157//1 153//1 152//1 +f 158//1 156//1 155//1 +f 158//1 159//1 156//1 +f 158//1 160//1 159//1 +f 161//1 160//1 158//1 +f 161//1 162//1 160//1 +f 163//1 162//1 161//1 +f 163//1 164//1 162//1 +f 163//1 165//1 164//1 +f 166//1 165//1 163//1 +f 166//1 167//1 165//1 +f 168//1 153//1 157//1 +f 169//1 153//1 168//1 +f 170//1 153//1 169//1 +f 166//1 171//1 167//1 +f 172//1 153//1 170//1 +f 173//1 153//1 172//1 +f 174//1 153//1 173//1 +f 166//1 175//1 171//1 +f 176//1 175//1 166//1 +f 177//1 153//1 174//1 +f 178//1 153//1 177//1 +f 179//1 153//1 178//1 +f 176//1 180//1 175//1 +f 181//1 153//1 179//1 +f 182//1 153//1 181//1 +f 180//1 153//1 182//1 +f 176//1 153//1 180//1 +f 183//1 153//1 176//1 +f 183//1 184//1 153//1 +f 183//1 185//1 184//1 +f 186//1 185//1 183//1 +f 186//1 187//1 185//1 +f 186//1 188//1 187//1 +f 189//1 188//1 186//1 +f 189//1 190//1 188//1 +f 189//1 191//1 190//1 +f 189//1 192//1 191//1 +f 193//1 192//1 189//1 +f 193//1 194//1 192//1 +f 193//1 195//1 194//1 +f 193//1 196//1 195//1 +f 197//1 196//1 193//1 +f 197//1 198//7 196//1 +f 199//1 200//1 201//1 +f 200//1 202//1 201//1 +f 200//1 203//1 202//1 +f 199//1 204//1 200//1 +f 199//1 205//1 204//1 +f 205//1 206//1 204//1 +f 205//1 207//1 206//1 +f 199//1 208//1 205//1 +f 199//1 209//1 208//1 +f 199//1 210//1 209//1 +f 211//1 212//1 213//1 +f 211//1 214//1 212//1 +f 211//1 215//1 214//1 +f 211//1 216//1 215//1 +f 218//8 220//8 217//8 +f 221//9 219//9 218//9 +f 223//10 222//10 221//10 +f 225//11 224//11 223//11 +f 227//8 226//8 225//8 +f 217//11 228//11 227//11 +f 230//8 232//8 229//8 +f 233//11 231//11 230//11 +f 235//8 234//8 233//8 +f 237//9 236//9 235//9 +f 239//8 238//8 237//8 +f 241//11 240//11 239//11 +f 243//8 242//8 241//8 +f 245//9 244//9 243//9 +f 247//10 246//10 245//10 +f 249//11 248//11 247//11 +f 251//8 250//8 249//8 +f 229//9 252//9 251//9 +f 254//12 256//12 253//12 +f 257//13 255//13 254//13 +f 259//14 258//14 257//14 +f 261//15 260//15 259//15 +f 263//16 262//16 261//16 +f 265//17 264//17 263//17 +f 267//18 266//18 265//18 +f 269//19 268//20 267//19 +f 271//21 270//21 269//21 +f 273//22 272//22 271//22 +f 275//23 274//23 273//23 +f 277//24 276//24 275//24 +f 279//25 278//25 277//25 +f 281//26 280//26 279//26 +f 283//27 282//27 281//27 +f 285//28 284//28 283//28 +f 287//29 286//29 285//29 +f 289//30 288//30 287//30 +f 291//31 290//31 289//31 +f 293//32 292//32 291//32 +f 295//33 294//33 293//33 +f 297//34 296//34 295//34 +f 299//35 298//35 297//35 +f 301//36 300//36 299//36 +f 303//37 302//37 301//37 +f 305//38 304//38 303//38 +f 307//39 306//39 305//39 +f 309//40 308//40 307//40 +f 311//41 310//41 309//41 +f 313//42 312//42 311//42 +f 315//43 314//43 313//43 +f 317//44 316//44 315//44 +f 319//45 318//45 317//45 +f 321//46 320//46 319//46 +f 323//47 322//47 321//47 +f 325//48 324//48 323//48 +f 327//49 326//49 325//49 +f 329//50 328//50 327//50 +f 331//51 330//52 329//51 +f 333//53 332//53 331//53 +f 335//54 334//54 333//54 +f 337//55 336//55 335//55 +f 339//56 338//56 337//56 +f 341//57 340//57 339//57 +f 343//58 342//58 341//58 +f 345//59 344//59 343//59 +f 347//60 346//60 345//60 +f 349//8 348//8 347//8 +f 351//61 350//61 349//61 +f 353//62 352//62 351//62 +f 355//63 354//63 353//63 +f 357//64 356//64 355//64 +f 359//65 358//66 357//65 +f 361//67 360//67 359//67 +f 363//68 362//68 361//68 +f 365//69 364//69 363//69 +f 367//70 366//71 365//70 +f 369//72 368//72 367//72 +f 371//73 370//73 369//73 +f 373//74 372//74 371//74 +f 375//75 374//75 373//75 +f 377//76 376//76 375//76 +f 379//77 378//77 377//77 +f 381//78 380//78 379//78 +f 383//79 382//79 381//79 +f 385//80 384//80 383//80 +f 387//81 386//81 385//81 +f 389//82 388//82 387//82 +f 391//83 390//83 389//83 +f 393//84 392//84 391//84 +f 395//85 394//85 393//85 +f 397//86 396//86 395//86 +f 399//87 398//87 397//87 +f 401//88 400//88 399//88 +f 403//89 402//89 401//89 +f 405//90 404//90 403//90 +f 407//91 406//91 405//91 +f 409//92 408//92 407//92 +f 411//93 410//93 409//93 +f 413//94 412//94 411//94 +f 415//95 414//95 413//95 +f 417//96 416//96 415//96 +f 419//97 418//97 417//97 +f 421//98 420//98 419//98 +f 423//99 422//99 421//99 +f 425//100 424//100 423//100 +f 427//101 426//101 425//101 +f 429//102 428//102 427//102 +f 431//103 430//103 429//103 +f 433//104 432//104 431//104 +f 435//105 434//105 433//105 +f 437//106 436//106 435//106 +f 439//107 438//107 437//107 +f 441//108 440//108 439//108 +f 443//109 442//110 441//110 +f 445//111 444//109 443//109 +f 447//10 446//10 445//10 +f 449//9 448//9 447//9 +f 451//10 450//10 449//10 +f 453//11 452//11 451//11 +f 455//8 454//8 453//8 +f 253//112 456//112 455//112 +f 458//113 460//113 457//113 +f 461//114 459//114 458//115 +f 463//116 462//116 461//116 +f 465//117 464//117 463//117 +f 467//118 466//118 465//118 +f 469//119 468//119 467//119 +f 471//120 470//120 469//120 +f 473//121 472//121 471//121 +f 475//122 474//122 473//122 +f 477//123 476//123 475//123 +f 479//124 478//124 477//124 +f 481//125 480//125 479//125 +f 483//126 482//126 481//126 +f 485//127 484//127 483//127 +f 487//128 486//128 485//128 +f 489//129 488//129 487//129 +f 491//130 490//130 489//130 +f 493//131 492//131 491//131 +f 495//132 494//132 493//133 +f 497//134 496//134 495//134 +f 499//135 498//135 497//135 +f 501//136 500//136 499//136 +f 503//137 502//137 501//137 +f 505//138 504//138 503//138 +f 507//139 506//139 505//139 +f 509//140 508//140 507//140 +f 511//141 510//141 509//141 +f 513//142 512//142 511//142 +f 515//143 514//143 513//143 +f 517//144 516//144 515//144 +f 519//145 518//145 517//145 +f 521//146 520//146 519//146 +f 523//147 522//147 521//147 +f 525//148 524//148 523//148 +f 527//149 526//149 525//149 +f 529//150 528//150 527//150 +f 531//151 530//151 529//151 +f 533//152 532//152 531//152 +f 535//153 534//153 533//153 +f 537//154 536//154 535//154 +f 539//155 538//155 537//156 +f 541//157 540//157 539//157 +f 543//158 542//158 541//158 +f 545//159 544//159 543//159 +f 547//160 546//160 545//160 +f 549//161 548//161 547//161 +f 551//162 550//162 549//162 +f 457//163 552//163 551//163 +f 554//164 556//164 553//164 +f 557//165 555//165 554//165 +f 559//166 558//166 557//166 +f 561//167 560//167 559//167 +f 563//168 562//168 561//168 +f 565//169 564//169 563//169 +f 567//170 566//170 565//170 +f 569//171 568//171 567//171 +f 571//172 570//172 569//172 +f 573//173 572//173 571//173 +f 575//174 574//174 573//174 +f 577//175 576//175 575//175 +f 579//176 578//176 577//176 +f 581//177 580//177 579//177 +f 583//178 582//178 581//178 +f 585//179 584//179 583//179 +f 587//180 586//180 585//180 +f 589//181 588//181 587//181 +f 591//182 590//182 589//182 +f 593//183 592//183 591//183 +f 595//184 594//184 593//184 +f 597//185 596//185 595//185 +f 599//186 598//186 597//186 +f 601//137 600//137 599//137 +f 603//187 602//187 601//187 +f 605//188 604//188 603//188 +f 607//189 606//189 605//189 +f 609//190 608//190 607//190 +f 611//191 610//191 609//191 +f 613//192 612//192 611//192 +f 615//82 614//82 613//82 +f 617//193 616//193 615//193 +f 619//194 618//194 617//194 +f 621//195 620//195 619//195 +f 623//196 622//196 621//196 +f 625//197 624//197 623//197 +f 627//198 626//198 625//198 +f 629//199 628//199 627//199 +f 631//200 630//200 629//200 +f 633//201 632//201 631//201 +f 635//202 634//202 633//202 +f 637//203 636//203 635//203 +f 639//204 638//204 637//204 +f 641//205 640//205 639//205 +f 643//206 642//206 641//206 +f 645//207 644//207 643//207 +f 647//208 646//208 645//208 +f 553//209 648//209 647//209 +f 650//210 652//210 649//210 +f 654//211 649//211 653//211 +f 656//212 658//212 655//212 +f 657//213 660//213 658//213 +f 659//214 662//214 660//214 +f 661//215 664//215 662//215 +f 663//216 666//216 664//216 +f 665//217 668//217 666//217 +f 667//218 670//218 668//218 +f 669//219 672//219 670//219 +f 671//220 674//220 672//220 +f 673//221 676//221 674//221 +f 675//222 678//222 676//222 +f 677//223 680//223 678//223 +f 679//224 682//224 680//224 +f 681//225 684//225 682//225 +f 683//226 686//226 684//226 +f 685//97 688//97 686//97 +f 687//227 690//227 688//227 +f 689//228 692//228 690//228 +f 691//229 694//229 692//229 +f 693//230 696//230 694//230 +f 695//231 698//231 696//231 +f 697//232 700//232 698//232 +f 699//233 702//233 700//233 +f 701//234 704//234 702//234 +f 703//235 706//235 704//235 +f 705//236 708//236 706//236 +f 707//237 710//237 708//237 +f 709//238 712//238 710//238 +f 711//239 653//239 712//239 +f 651//240 655//240 652//240 +f 728//1 736//1 744//1 +f 650//241 713//241 651//241 +f 651//242 744//242 656//242 +f 656//243 743//243 657//243 +f 659//244 743//244 742//244 +f 659//245 741//245 661//245 +f 661//246 740//246 663//246 +f 663//247 739//248 665//248 +f 667//249 739//249 738//249 +f 667//250 737//250 669//250 +f 671//251 737//252 736//251 +f 673//253 736//253 735//253 +f 673//254 734//254 675//254 +f 675//255 733//255 677//255 +f 677//256 732//256 679//256 +f 679//257 731//257 681//257 +f 683//258 731//258 730//258 +f 683//259 729//259 685//259 +f 687//260 729//261 728//260 +f 689//262 728//262 727//262 +f 689//263 726//263 691//263 +f 691//264 725//264 693//264 +f 693//265 724//265 695//265 +f 695//266 723//266 697//266 +f 699//267 723//267 722//267 +f 699//268 721//268 701//268 +f 703//269 721//270 720//269 +f 705//271 720//271 719//271 +f 705//272 718//272 707//272 +f 707//273 717//273 709//273 +f 709//274 716//274 711//274 +f 654//275 716//275 715//275 +f 650//276 715//276 714//276 +f 218//8 219//8 220//8 +f 221//9 222//9 219//9 +f 223//10 224//10 222//10 +f 225//11 226//11 224//11 +f 227//8 228//8 226//8 +f 217//11 220//11 228//11 +f 230//8 231//8 232//8 +f 233//11 234//11 231//11 +f 235//8 236//8 234//8 +f 237//9 238//9 236//9 +f 239//8 240//8 238//8 +f 241//11 242//11 240//11 +f 243//8 244//8 242//8 +f 245//9 246//9 244//9 +f 247//10 248//10 246//10 +f 249//11 250//11 248//11 +f 251//8 252//8 250//8 +f 229//9 232//9 252//9 +f 254//12 255//12 256//12 +f 257//13 258//13 255//13 +f 259//14 260//277 258//14 +f 261//15 262//15 260//15 +f 263//16 264//16 262//16 +f 265//17 266//17 264//17 +f 267//18 268//18 266//18 +f 269//19 270//20 268//20 +f 271//21 272//21 270//21 +f 273//22 274//22 272//22 +f 275//23 276//23 274//23 +f 277//24 278//24 276//24 +f 279//25 280//25 278//25 +f 281//26 282//26 280//26 +f 283//27 284//27 282//27 +f 285//28 286//28 284//28 +f 287//29 288//29 286//29 +f 289//30 290//30 288//30 +f 291//31 292//31 290//31 +f 293//32 294//32 292//32 +f 295//33 296//33 294//33 +f 297//34 298//34 296//34 +f 299//35 300//35 298//35 +f 301//36 302//36 300//36 +f 303//37 304//37 302//37 +f 305//38 306//38 304//38 +f 307//39 308//39 306//39 +f 309//40 310//40 308//40 +f 311//41 312//41 310//41 +f 313//42 314//42 312//42 +f 315//43 316//43 314//43 +f 317//44 318//44 316//44 +f 319//45 320//45 318//45 +f 321//46 322//46 320//46 +f 323//47 324//47 322//47 +f 325//48 326//48 324//48 +f 327//49 328//49 326//49 +f 329//50 330//50 328//50 +f 331//51 332//52 330//52 +f 333//53 334//53 332//53 +f 335//54 336//54 334//54 +f 337//55 338//55 336//55 +f 339//56 340//56 338//56 +f 341//57 342//57 340//57 +f 343//58 344//58 342//58 +f 345//59 346//59 344//59 +f 347//60 348//60 346//60 +f 349//8 350//8 348//8 +f 351//61 352//61 350//61 +f 353//62 354//62 352//62 +f 355//63 356//63 354//63 +f 357//64 358//64 356//64 +f 359//65 360//66 358//66 +f 361//67 362//67 360//67 +f 363//68 364//68 362//68 +f 365//69 366//69 364//69 +f 367//70 368//71 366//71 +f 369//72 370//72 368//72 +f 371//73 372//73 370//73 +f 373//74 374//74 372//74 +f 375//75 376//75 374//75 +f 377//76 378//76 376//76 +f 379//77 380//77 378//77 +f 381//78 382//78 380//78 +f 383//79 384//79 382//79 +f 385//80 386//80 384//80 +f 387//81 388//81 386//81 +f 389//82 390//82 388//82 +f 391//83 392//83 390//83 +f 393//84 394//84 392//84 +f 395//85 396//85 394//85 +f 397//86 398//86 396//86 +f 399//87 400//87 398//87 +f 401//88 402//88 400//88 +f 403//89 404//89 402//89 +f 405//90 406//90 404//90 +f 407//91 408//91 406//91 +f 409//92 410//92 408//92 +f 411//93 412//93 410//93 +f 413//94 414//94 412//94 +f 415//95 416//95 414//95 +f 417//96 418//96 416//96 +f 419//97 420//97 418//97 +f 421//98 422//98 420//98 +f 423//99 424//99 422//99 +f 425//100 426//100 424//100 +f 427//101 428//101 426//101 +f 429//102 430//102 428//102 +f 431//103 432//103 430//103 +f 433//104 434//104 432//104 +f 435//105 436//105 434//105 +f 437//106 438//106 436//106 +f 439//107 440//107 438//107 +f 441//108 442//108 440//108 +f 443//109 444//109 442//110 +f 445//111 446//111 444//109 +f 447//10 448//10 446//10 +f 449//9 450//9 448//9 +f 451//10 452//10 450//10 +f 453//11 454//11 452//11 +f 455//8 456//8 454//8 +f 253//112 256//112 456//112 +f 458//113 459//113 460//113 +f 461//114 462//114 459//114 +f 463//116 464//116 462//116 +f 465//117 466//117 464//117 +f 467//118 468//118 466//118 +f 469//119 470//119 468//119 +f 471//120 472//120 470//120 +f 473//121 474//121 472//121 +f 475//122 476//122 474//122 +f 477//123 478//123 476//123 +f 479//124 480//124 478//124 +f 481//125 482//125 480//125 +f 483//126 484//126 482//126 +f 485//127 486//127 484//127 +f 487//128 488//128 486//128 +f 489//129 490//129 488//129 +f 491//130 492//130 490//130 +f 493//131 494//131 492//131 +f 495//132 496//132 494//132 +f 497//134 498//134 496//134 +f 499//135 500//135 498//135 +f 501//136 502//136 500//136 +f 503//137 504//137 502//137 +f 505//138 506//138 504//138 +f 507//139 508//139 506//139 +f 509//140 510//140 508//140 +f 511//141 512//141 510//141 +f 513//142 514//142 512//142 +f 515//143 516//143 514//143 +f 517//144 518//144 516//144 +f 519//145 520//145 518//145 +f 521//146 522//146 520//146 +f 523//147 524//147 522//147 +f 525//148 526//148 524//148 +f 527//149 528//149 526//149 +f 529//150 530//150 528//150 +f 531//151 532//151 530//151 +f 533//152 534//152 532//152 +f 535//153 536//153 534//153 +f 537//154 538//154 536//154 +f 539//155 540//155 538//155 +f 541//157 542//157 540//157 +f 543//158 544//158 542//158 +f 545//159 546//159 544//159 +f 547//160 548//160 546//160 +f 549//161 550//161 548//161 +f 551//162 552//162 550//162 +f 457//163 460//163 552//163 +f 554//164 555//164 556//164 +f 557//165 558//165 555//165 +f 559//166 560//166 558//166 +f 561//167 562//167 560//167 +f 563//168 564//168 562//168 +f 565//169 566//169 564//169 +f 567//170 568//170 566//170 +f 569//171 570//171 568//171 +f 571//172 572//172 570//172 +f 573//173 574//173 572//173 +f 575//174 576//174 574//174 +f 577//175 578//175 576//175 +f 579//176 580//176 578//176 +f 581//177 582//177 580//177 +f 583//178 584//178 582//178 +f 585//179 586//179 584//179 +f 587//180 588//180 586//180 +f 589//181 590//181 588//181 +f 591//182 592//182 590//182 +f 593//183 594//183 592//183 +f 595//184 596//184 594//184 +f 597//185 598//185 596//185 +f 599//186 600//186 598//186 +f 601//137 602//137 600//137 +f 603//187 604//187 602//187 +f 605//188 606//188 604//188 +f 607//189 608//189 606//189 +f 609//190 610//190 608//190 +f 611//191 612//191 610//191 +f 613//192 614//192 612//192 +f 615//82 616//82 614//82 +f 617//193 618//193 616//193 +f 619//194 620//194 618//194 +f 621//195 622//195 620//195 +f 623//196 624//196 622//196 +f 625//197 626//197 624//197 +f 627//198 628//198 626//198 +f 629//199 630//199 628//199 +f 631//200 632//200 630//200 +f 633//201 634//201 632//201 +f 635//202 636//202 634//202 +f 637//203 638//203 636//203 +f 639//204 640//204 638//204 +f 641//205 642//205 640//205 +f 643//206 644//206 642//206 +f 645//207 646//207 644//207 +f 647//208 648//208 646//208 +f 553//209 556//209 648//209 +f 650//210 651//210 652//210 +f 654//211 650//211 649//211 +f 656//212 657//212 658//212 +f 657//213 659//213 660//213 +f 659//214 661//214 662//214 +f 661//215 663//215 664//215 +f 663//216 665//216 666//216 +f 665//217 667//217 668//217 +f 667//218 669//218 670//218 +f 669//219 671//219 672//219 +f 671//220 673//220 674//220 +f 673//221 675//221 676//221 +f 675//222 677//222 678//222 +f 677//223 679//223 680//223 +f 679//224 681//224 682//224 +f 681//225 683//225 684//225 +f 683//226 685//226 686//226 +f 685//97 687//97 688//97 +f 687//227 689//227 690//227 +f 689//228 691//228 692//228 +f 691//229 693//229 694//229 +f 693//230 695//230 696//230 +f 695//231 697//231 698//231 +f 697//232 699//232 700//232 +f 699//233 701//233 702//233 +f 701//234 703//234 704//234 +f 703//235 705//235 706//235 +f 705//236 707//236 708//236 +f 707//237 709//237 710//237 +f 709//238 711//238 712//238 +f 711//239 654//239 653//239 +f 651//240 656//240 655//240 +f 744//1 713//1 714//1 +f 714//1 715//1 716//1 +f 716//1 717//1 720//1 +f 717//1 718//1 720//1 +f 718//1 719//1 720//1 +f 720//1 721//1 722//1 +f 722//1 723//1 724//1 +f 724//1 725//1 728//1 +f 725//1 726//1 728//1 +f 726//1 727//1 728//1 +f 728//1 729//1 730//1 +f 730//1 731//1 732//1 +f 732//1 733//1 736//1 +f 733//1 734//1 736//1 +f 734//1 735//1 736//1 +f 736//1 737//1 738//1 +f 738//1 739//1 740//1 +f 740//1 741//1 744//1 +f 741//1 742//1 744//1 +f 742//1 743//1 744//1 +f 744//1 714//1 720//1 +f 714//1 716//1 720//1 +f 720//1 722//1 728//1 +f 722//1 724//1 728//1 +f 728//1 730//1 736//1 +f 730//1 732//1 736//1 +f 736//1 738//1 744//1 +f 738//1 740//1 744//1 +f 744//1 720//1 728//1 +f 650//241 714//241 713//241 +f 651//242 713//278 744//242 +f 656//243 744//243 743//243 +f 659//244 657//244 743//244 +f 659//245 742//245 741//245 +f 661//246 741//246 740//246 +f 663//247 740//247 739//248 +f 667//249 665//249 739//249 +f 667//250 738//250 737//250 +f 671//251 669//252 737//252 +f 673//253 671//253 736//253 +f 673//254 735//254 734//254 +f 675//255 734//255 733//255 +f 677//256 733//256 732//256 +f 679//257 732//257 731//257 +f 683//258 681//258 731//258 +f 683//259 730//259 729//259 +f 687//260 685//261 729//261 +f 689//262 687//262 728//262 +f 689//263 727//263 726//263 +f 691//264 726//264 725//264 +f 693//265 725//265 724//265 +f 695//266 724//266 723//266 +f 699//267 697//267 723//267 +f 699//268 722//268 721//268 +f 703//269 701//270 721//270 +f 705//271 703//271 720//271 +f 705//272 719//272 718//272 +f 707//273 718//273 717//273 +f 709//274 717//274 716//274 +f 654//275 711//275 716//275 +f 650//276 654//276 715//276 diff --git a/client/public/utils.js b/client/public/utils.js new file mode 100644 index 0000000..a8eb08f --- /dev/null +++ b/client/public/utils.js @@ -0,0 +1,374 @@ +/////////////////////////////////////////////////////////////////////////////////// +// The MIT License (MIT) +// +// Copyright (c) 2017 Tarek Sherif +// +// Permission is hereby granted, free of charge, to any person obtaining a copy of +// this software and associated documentation files (the "Software"), to deal in +// the Software without restriction, including without limitation the rights to +// use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of +// the Software, and to permit persons to whom the Software is furnished to do so, +// subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in all +// copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS +// FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR +// COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER +// IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN +// CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +/////////////////////////////////////////////////////////////////////////////////// + +(function() { + var translateMat = mat4.create(); + var rotateXMat = mat4.create(); + var rotateYMat = mat4.create(); + var rotateZMat = mat4.create(); + var scaleMat = mat4.create(); + + var zeros = [0, 0, 0]; + var ones = [1, 1, 1]; + + window.utils = { + xformMatrix: function xformMatrix(xform, translate, rotate, scale) { + translate = translate || zeros; + rotate = rotate || zeros; + scale = scale || ones; + + mat4.fromTranslation(translateMat, translate); + mat4.fromXRotation(rotateXMat, rotate[0]); + mat4.fromYRotation(rotateYMat, rotate[1]); + mat4.fromZRotation(rotateZMat, rotate[2]); + mat4.fromScaling(scaleMat, scale); + + mat4.multiply(xform, rotateXMat, scaleMat); + mat4.multiply(xform, rotateYMat, xform); + mat4.multiply(xform, rotateZMat, xform); + mat4.multiply(xform, translateMat, xform); + }, + + loadCubemapImages: function loadCubeMapImages(urls, ok) { + var numImages = 6; + + var negX = new Image(); + var posX = new Image(); + var negY = new Image(); + var posY = new Image(); + var negZ = new Image(); + var posZ = new Image(); + + function onload() { + if (--numImages === 0) { + ok(negX, posX, negY, posY, negZ, posZ); + } + } + + negX.onload = onload; + posX.onload = onload; + negY.onload = onload; + posY.onload = onload; + negZ.onload = onload; + posZ.onload = onload; + + negX.src = urls.negX; + posX.src = urls.posX; + negY.src = urls.negY; + posY.src = urls.posY; + negZ.src = urls.negZ; + posZ.src = urls.posZ; + }, + + createBox: function createBox(options) { + options = options || {}; + + var dimensions = options.dimensions || [1, 1, 1]; + var position = options.position || [-dimensions[0] / 2, -dimensions[1] / 2, -dimensions[2] / 2]; + var x = position[0]; + var y = position[1]; + var z = position[2]; + var width = dimensions[0]; + var height = dimensions[1]; + var depth = dimensions[2]; + + var fbl = {x: x, y: y, z: z + depth}; + var fbr = {x: x + width, y: y, z: z + depth}; + var ftl = {x: x, y: y + height, z: z + depth}; + var ftr = {x: x + width, y: y + height, z: z + depth}; + var bbl = {x: x, y: y, z: z }; + var bbr = {x: x + width, y: y, z: z }; + var btl = {x: x, y: y + height, z: z }; + var btr = {x: x + width, y: y + height, z: z }; + + var positions = new Float32Array([ + //front + fbl.x, fbl.y, fbl.z, + fbr.x, fbr.y, fbr.z, + ftl.x, ftl.y, ftl.z, + ftl.x, ftl.y, ftl.z, + fbr.x, fbr.y, fbr.z, + ftr.x, ftr.y, ftr.z, + + //right + fbr.x, fbr.y, fbr.z, + bbr.x, bbr.y, bbr.z, + ftr.x, ftr.y, ftr.z, + ftr.x, ftr.y, ftr.z, + bbr.x, bbr.y, bbr.z, + btr.x, btr.y, btr.z, + + //back + fbr.x, bbr.y, bbr.z, + bbl.x, bbl.y, bbl.z, + btr.x, btr.y, btr.z, + btr.x, btr.y, btr.z, + bbl.x, bbl.y, bbl.z, + btl.x, btl.y, btl.z, + + //left + bbl.x, bbl.y, bbl.z, + fbl.x, fbl.y, fbl.z, + btl.x, btl.y, btl.z, + btl.x, btl.y, btl.z, + fbl.x, fbl.y, fbl.z, + ftl.x, ftl.y, ftl.z, + + //top + ftl.x, ftl.y, ftl.z, + ftr.x, ftr.y, ftr.z, + btl.x, btl.y, btl.z, + btl.x, btl.y, btl.z, + ftr.x, ftr.y, ftr.z, + btr.x, btr.y, btr.z, + + //bottom + bbl.x, bbl.y, bbl.z, + bbr.x, bbr.y, bbr.z, + fbl.x, fbl.y, fbl.z, + fbl.x, fbl.y, fbl.z, + bbr.x, bbr.y, bbr.z, + fbr.x, fbr.y, fbr.z, + ]); + + var uvs = new Float32Array([ + //front + 0, 0, + 1, 0, + 0, 1, + 0, 1, + 1, 0, + 1, 1, + + //right + 0, 0, + 1, 0, + 0, 1, + 0, 1, + 1, 0, + 1, 1, + + //back + 0, 0, + 1, 0, + 0, 1, + 0, 1, + 1, 0, + 1, 1, + + //left + 0, 0, + 1, 0, + 0, 1, + 0, 1, + 1, 0, + 1, 1, + + //top + 0, 0, + 1, 0, + 0, 1, + 0, 1, + 1, 0, + 1, 1, + + //bottom + 0, 0, + 1, 0, + 0, 1, + 0, 1, + 1, 0, + 1, 1 + ]); + + var normals = new Float32Array(positions.length); + var i, count; + var ni; + + for (i = 0, count = positions.length / 3; i < count; i++) { + ni = i * 3; + + normals[ni] = parseInt(i / 6, 10) === 1 ? 1 : + parseInt(i / 6, 10) === 3 ? -1 : 0; + + normals[ni+1] = parseInt(i / 6, 10) === 4 ? 1 : + parseInt(i / 6, 10) === 5 ? -1 : 0; + + normals[ni+2] = parseInt(i / 6, 10) === 0 ? 1 : + parseInt(i / 6, 10) === 2 ? -1 : 0; + + } + + return { + positions: positions, + normals: normals, + uvs: uvs + }; + + }, + + createSphere: function createSphere(options) { + options = options || {}; + + var long_bands = options.long_bands || 32; + var lat_bands = options.lat_bands || 32; + var radius = options.radius || 1; + var lat_step = Math.PI / lat_bands; + var long_step = 2 * Math.PI / long_bands; + var num_positions = long_bands * lat_bands * 4; + var num_indices = long_bands * lat_bands * 6; + var lat_angle, long_angle; + var positions = new Float32Array(num_positions * 3); + var normals = new Float32Array(num_positions * 3); + var uvs = new Float32Array(num_positions * 2); + var indices = new Uint16Array(num_indices); + var x1, x2, x3, x4, + y1, y2, + z1, z2, z3, z4, + u1, u2, + v1, v2; + var i, j; + var k = 0, l = 0; + var vi, ti; + + for (i = 0; i < lat_bands; i++) { + lat_angle = i * lat_step; + y1 = Math.cos(lat_angle); + y2 = Math.cos(lat_angle + lat_step); + for (j = 0; j < long_bands; j++) { + long_angle = j * long_step; + x1 = Math.sin(lat_angle) * Math.cos(long_angle); + x2 = Math.sin(lat_angle) * Math.cos(long_angle + long_step); + x3 = Math.sin(lat_angle + lat_step) * Math.cos(long_angle); + x4 = Math.sin(lat_angle + lat_step) * Math.cos(long_angle + long_step); + z1 = Math.sin(lat_angle) * Math.sin(long_angle); + z2 = Math.sin(lat_angle) * Math.sin(long_angle + long_step); + z3 = Math.sin(lat_angle + lat_step) * Math.sin(long_angle); + z4 = Math.sin(lat_angle + lat_step) * Math.sin(long_angle + long_step); + u1 = 1 - j / long_bands; + u2 = 1 - (j + 1) / long_bands; + v1 = 1 - i / lat_bands; + v2 = 1 - (i + 1) / lat_bands; + vi = k * 3; + ti = k * 2; + + positions[vi] = x1 * radius; + positions[vi+1] = y1 * radius; + positions[vi+2] = z1 * radius; //v0 + + positions[vi+3] = x2 * radius; + positions[vi+4] = y1 * radius; + positions[vi+5] = z2 * radius; //v1 + + positions[vi+6] = x3 * radius; + positions[vi+7] = y2 * radius; + positions[vi+8] = z3 * radius; // v2 + + + positions[vi+9] = x4 * radius; + positions[vi+10] = y2 * radius; + positions[vi+11] = z4 * radius; // v3 + + normals[vi] = x1; + normals[vi+1] = y1; + normals[vi+2] = z1; + + normals[vi+3] = x2; + normals[vi+4] = y1; + normals[vi+5] = z2; + + normals[vi+6] = x3; + normals[vi+7] = y2; + normals[vi+8] = z3; + + normals[vi+9] = x4; + normals[vi+10] = y2; + normals[vi+11] = z4; + + uvs[ti] = u1; + uvs[ti+1] = v1; + + uvs[ti+2] = u2; + uvs[ti+3] = v1; + + uvs[ti+4] = u1; + uvs[ti+5] = v2; + + uvs[ti+6] = u2; + uvs[ti+7] = v2; + + indices[l ] = k; + indices[l + 1] = k + 1; + indices[l + 2] = k + 2; + indices[l + 3] = k + 2; + indices[l + 4] = k + 1; + indices[l + 5] = k + 3; + + k += 4; + l += 6; + } + } + + return { + positions: positions, + normals: normals, + uvs: uvs, + indices: indices + }; + }, + + computeBoundingBox: function (position, options) { + options = options || {}; + var geo = options.geo || false; + + var res = { + min: vec3.create(), + max: vec3.create() + }; + vec3.set(res.min, Number.POSITIVE_INFINITY, Number.POSITIVE_INFINITY, Number.POSITIVE_INFINITY); + vec3.set(res.max, Number.NEGATIVE_INFINITY, Number.NEGATIVE_INFINITY, Number.NEGATIVE_INFINITY); + for ( var i = 0, len = position.length; i < len; i+=3 ) { + res.min[0] = Math.min(position[i], res.min[0]); + res.max[0] = Math.max(position[i], res.max[0]); + res.min[1] = Math.min(position[i], res.min[1]); + res.max[1] = Math.max(position[i], res.max[1]); + res.min[2] = Math.min(position[i], res.min[2]); + res.max[2] = Math.max(position[i], res.max[2]); + } + + if (geo) { + var size = vec3.create(); + vec3.subtract(size, res.max, res.min); + res.geo = utils.createBox({ + position: res.min, + width: size[0], + height: size[1], + depth: size[2] + }); + } + + return res; + } + } + +})(); \ No newline at end of file diff --git a/docs/API.md b/docs/API.md index 8c2b127..96c7d1d 100644 --- a/docs/API.md +++ b/docs/API.md @@ -10,6 +10,7 @@ automatically every request | Type | Route | Queries | Auth? | Notes | | --- | --- | --- | -- | --- | +| GET | /api/search/ | query, page | no | | | GET | /api/bricks/ | query, page | no | | | GET | /api/sets/ | query, page | no | | | GET | /api/brick/:id/ | | no | | @@ -23,6 +24,19 @@ automatically every request | POST | /api/auth/basket/:id | | yes | manipulate basket content | | DEL | /api/auth/basket/:id | quantity | yes | if no id, delete whole | +## Query structure + +### /api/search/ +### /api/bricks/ +### /api/sets/ +### /api/brick/:id/ +### /api/set/:id/ +### /api/cdn/:id/ +### /api/auth/login/ +### /api/auth/signup/ +### /api/auth/orders/ +### /api/auth/basket/ + ## Response Structure ```js diff --git a/src/index.js b/src/index.js index e005720..5d60d43 100644 --- a/src/index.js +++ b/src/index.js @@ -11,8 +11,8 @@ async function main() { logLevel: process.env.LOG_LEVEL, logToConsole: process.env.LOG_CONSOLE, logFile: process.env.LOG_FILE, - networkHost: process.env.LOG_NET_HOST, - networkPort: process.env.LOG_NET_PORT, + // networkHost: process.env.LOG_NET_HOST, + // networkPort: process.env.LOG_NET_PORT, }); Logger.Info('Pre-Init Complete');