} batches - Accumulator render batches and/or child Tw2BatchAccumulators
- * @property {function} _sortMethod - An optional method to sort batches before rendering them
- * @class
- */
-var Tw2BatchAccumulator = exports.Tw2BatchAccumulator = function () {
- function Tw2BatchAccumulator() {
- var sorting = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : null;
+ function ErrGeometryMeshElementComponentsMissing(data) {
+ _classCallCheck(this, ErrGeometryMeshElementComponentsMissing);
- _classCallCheck(this, Tw2BatchAccumulator);
+ return _possibleConstructorReturn(this, _getPrototypeOf(ErrGeometryMeshElementComponentsMissing).call(this, data, 'Input geometry mesh elements do not have the required number of components'));
+ }
- this.batches = [];
- this._sortMethod = sorting;
- }
+ return ErrGeometryMeshElementComponentsMissing;
+}(Tw2Error);
+/**
+ * Throws when a geometry mesh has an invalid bone name for a model
+ */
- /**
- * Commits a batch
- * @param {Tw2BatchAccumulator|Tw2RenderBatch} batch
- */
+let ErrGeometryMeshBoneNameInvalid =
+/*#__PURE__*/
+function (_Tw2Error10) {
+ _inherits(ErrGeometryMeshBoneNameInvalid, _Tw2Error10);
+ function ErrGeometryMeshBoneNameInvalid(data) {
+ _classCallCheck(this, ErrGeometryMeshBoneNameInvalid);
- _createClass(Tw2BatchAccumulator, [{
- key: 'Commit',
- value: function Commit(batch) {
- this.batches.push(batch);
- }
+ return _possibleConstructorReturn(this, _getPrototypeOf(ErrGeometryMeshBoneNameInvalid).call(this, data, 'Geometry mesh has invalid bone name for model'));
+ }
- /**
- * Clears any accumulated render batches
- */
+ return ErrGeometryMeshBoneNameInvalid;
+}(Tw2Error);
+/**
+ * Throws when there is an error binding a geometry mesh to an effect
+ */
- }, {
- key: 'Clear',
- value: function Clear() {
- this.batches = [];
- }
+let ErrGeometryMeshEffectBinding =
+/*#__PURE__*/
+function (_Tw2Error11) {
+ _inherits(ErrGeometryMeshEffectBinding, _Tw2Error11);
- /**
- * Renders the accumulated render batches
- * @param {string} [technique] - technique name
- */
+ function ErrGeometryMeshEffectBinding(data) {
+ _classCallCheck(this, ErrGeometryMeshEffectBinding);
- }, {
- key: 'Render',
- value: function Render() {
- var technique = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 'Main';
+ return _possibleConstructorReturn(this, _getPrototypeOf(ErrGeometryMeshEffectBinding).call(this, data, 'Error binding geometry mesh to effect'));
+ }
- if (this._sortMethod) {
- this.batches.sort(this._sortMethod);
- }
+ return ErrGeometryMeshEffectBinding;
+}(Tw2Error);
+/**
+ * Throws when a geometry mesh has an invalid file type
+ */
- for (var i = 0; i < this.batches.length; ++i) {
- if (this.batches[i] instanceof Tw2BatchAccumulator) {
- this.batches[i].Render(technique);
- } else {
- if (this.batches[i].renderMode !== _Tw2Device.device.RM_ANY) {
- _Tw2Device.device.SetStandardStates(this.batches[i].renderMode);
- }
+let ErrGeometryFileType =
+/*#__PURE__*/
+function (_Tw2Error12) {
+ _inherits(ErrGeometryFileType, _Tw2Error12);
- _Tw2Device.device.perObjectData = this.batches[i].perObjectData;
- this.batches[i].Commit(technique);
- }
- }
- }
- }]);
+ function ErrGeometryFileType(data) {
+ _classCallCheck(this, ErrGeometryFileType);
- return Tw2BatchAccumulator;
-}();
+ return _possibleConstructorReturn(this, _getPrototypeOf(ErrGeometryFileType).call(this, data, 'Invalid geometry file type (%fileType%)'));
+ }
-/***/ }),
-/* 66 */
-/***/ (function(module, exports, __webpack_require__) {
+ return ErrGeometryFileType;
+}(Tw2Error);
+/**
+ * Throws when a resource path has an unregistered prefix
+ */
-"use strict";
+let ErrResourcePrefixUnregistered =
+/*#__PURE__*/
+function (_Tw2Error13) {
+ _inherits(ErrResourcePrefixUnregistered, _Tw2Error13);
+ function ErrResourcePrefixUnregistered(data) {
+ _classCallCheck(this, ErrResourcePrefixUnregistered);
-Object.defineProperty(exports, "__esModule", {
- value: true
-});
-exports.vec2 = undefined;
+ return _possibleConstructorReturn(this, _getPrototypeOf(ErrResourcePrefixUnregistered).call(this, data, 'Unregistered resource prefix (%prefix%)'));
+ }
-var _glMatrix = __webpack_require__(11);
+ return ErrResourcePrefixUnregistered;
+}(Tw2Error);
+/**
+ * Throws when a resource path has no prefix
+ */
-exports.vec2 = _glMatrix.vec2;
+let ErrResourcePrefixUndefined =
+/*#__PURE__*/
+function (_Tw2Error14) {
+ _inherits(ErrResourcePrefixUndefined, _Tw2Error14);
-/***/ }),
-/* 67 */
-/***/ (function(module, __webpack_exports__, __webpack_require__) {
+ function ErrResourcePrefixUndefined(data) {
+ _classCallCheck(this, ErrResourcePrefixUndefined);
-"use strict";
-Object.defineProperty(__webpack_exports__, "__esModule", { value: true });
-/* harmony export (immutable) */ __webpack_exports__["create"] = create;
-/* harmony export (immutable) */ __webpack_exports__["clone"] = clone;
-/* harmony export (immutable) */ __webpack_exports__["copy"] = copy;
-/* harmony export (immutable) */ __webpack_exports__["identity"] = identity;
-/* harmony export (immutable) */ __webpack_exports__["fromValues"] = fromValues;
-/* harmony export (immutable) */ __webpack_exports__["set"] = set;
-/* harmony export (immutable) */ __webpack_exports__["transpose"] = transpose;
-/* harmony export (immutable) */ __webpack_exports__["invert"] = invert;
-/* harmony export (immutable) */ __webpack_exports__["adjoint"] = adjoint;
-/* harmony export (immutable) */ __webpack_exports__["determinant"] = determinant;
-/* harmony export (immutable) */ __webpack_exports__["multiply"] = multiply;
-/* harmony export (immutable) */ __webpack_exports__["rotate"] = rotate;
-/* harmony export (immutable) */ __webpack_exports__["scale"] = scale;
-/* harmony export (immutable) */ __webpack_exports__["fromRotation"] = fromRotation;
-/* harmony export (immutable) */ __webpack_exports__["fromScaling"] = fromScaling;
-/* harmony export (immutable) */ __webpack_exports__["str"] = str;
-/* harmony export (immutable) */ __webpack_exports__["frob"] = frob;
-/* harmony export (immutable) */ __webpack_exports__["LDU"] = LDU;
-/* harmony export (immutable) */ __webpack_exports__["add"] = add;
-/* harmony export (immutable) */ __webpack_exports__["subtract"] = subtract;
-/* harmony export (immutable) */ __webpack_exports__["exactEquals"] = exactEquals;
-/* harmony export (immutable) */ __webpack_exports__["equals"] = equals;
-/* harmony export (immutable) */ __webpack_exports__["multiplyScalar"] = multiplyScalar;
-/* harmony export (immutable) */ __webpack_exports__["multiplyScalarAndAdd"] = multiplyScalarAndAdd;
-/* harmony import */ var __WEBPACK_IMPORTED_MODULE_0__common__ = __webpack_require__(5);
-/* 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. */
-
-
-
-/**
- * 2x2 Matrix
- * @module mat2
- */
-
-/**
- * Creates a new identity mat2
- *
- * @returns {mat2} a new 2x2 matrix
- */
-function create() {
- let out = new __WEBPACK_IMPORTED_MODULE_0__common__["ARRAY_TYPE"](4);
- out[0] = 1;
- out[1] = 0;
- out[2] = 0;
- out[3] = 1;
- return out;
-}
+ return _possibleConstructorReturn(this, _getPrototypeOf(ErrResourcePrefixUndefined).call(this, data, 'Undefined resource prefix'));
+ }
+ return ErrResourcePrefixUndefined;
+}(Tw2Error);
/**
- * Creates a new mat2 initialized with values from an existing matrix
- *
- * @param {mat2} a matrix to clone
- * @returns {mat2} a new 2x2 matrix
+ * Throws when a resource path has an unregistered file extension
*/
-function clone(a) {
- let out = new __WEBPACK_IMPORTED_MODULE_0__common__["ARRAY_TYPE"](4);
- out[0] = a[0];
- out[1] = a[1];
- out[2] = a[2];
- out[3] = a[3];
- return out;
-}
+let ErrResourceExtensionUnregistered =
+/*#__PURE__*/
+function (_Tw2Error15) {
+ _inherits(ErrResourceExtensionUnregistered, _Tw2Error15);
+
+ function ErrResourceExtensionUnregistered(data) {
+ _classCallCheck(this, ErrResourceExtensionUnregistered);
+
+ return _possibleConstructorReturn(this, _getPrototypeOf(ErrResourceExtensionUnregistered).call(this, data, 'Unregistered resource extension (%extension%)'));
+ }
+
+ return ErrResourceExtensionUnregistered;
+}(Tw2Error);
/**
- * Copy the values from one mat2 to another
- *
- * @param {mat2} out the receiving matrix
- * @param {mat2} a the source matrix
- * @returns {mat2} out
+ * Throws when a resource path has no file extension
*/
-function copy(out, a) {
- out[0] = a[0];
- out[1] = a[1];
- out[2] = a[2];
- out[3] = a[3];
- return out;
-}
+let ErrResourceExtensionUndefined =
+/*#__PURE__*/
+function (_Tw2Error16) {
+ _inherits(ErrResourceExtensionUndefined, _Tw2Error16);
+
+ function ErrResourceExtensionUndefined(data) {
+ _classCallCheck(this, ErrResourceExtensionUndefined);
+
+ return _possibleConstructorReturn(this, _getPrototypeOf(ErrResourceExtensionUndefined).call(this, data, 'Undefined resource extension'));
+ }
+
+ return ErrResourceExtensionUndefined;
+}(Tw2Error);
/**
- * Set a mat2 to the identity matrix
- *
- * @param {mat2} out the receiving matrix
- * @returns {mat2} out
+ * Throws in invalid resource formats
*/
-function identity(out) {
- out[0] = 1;
- out[1] = 0;
- out[2] = 0;
- out[3] = 1;
- return out;
-}
+let ErrResourceFormat =
+/*#__PURE__*/
+function (_Tw2Error17) {
+ _inherits(ErrResourceFormat, _Tw2Error17);
+
+ function ErrResourceFormat(data) {
+ _classCallCheck(this, ErrResourceFormat);
+
+ return _possibleConstructorReturn(this, _getPrototypeOf(ErrResourceFormat).call(this, data, 'Invalid resource format'));
+ }
+
+ return ErrResourceFormat;
+}(Tw2Error);
/**
- * 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
+ * Throws when an effect has an invalid shader version
*/
-function fromValues(m00, m01, m10, m11) {
- let out = new __WEBPACK_IMPORTED_MODULE_0__common__["ARRAY_TYPE"](4);
- out[0] = m00;
- out[1] = m01;
- out[2] = m10;
- out[3] = m11;
- return out;
-}
+let ErrShaderVersion =
+/*#__PURE__*/
+function (_Tw2Error18) {
+ _inherits(ErrShaderVersion, _Tw2Error18);
+
+ function ErrShaderVersion(data) {
+ _classCallCheck(this, ErrShaderVersion);
+
+ return _possibleConstructorReturn(this, _getPrototypeOf(ErrShaderVersion).call(this, data, 'Invalid version of effect file (%version%)'));
+ }
+
+ return ErrShaderVersion;
+}(Tw2Error);
/**
- * 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
+ * Throws when an effect has no header
*/
-function set(out, m00, m01, m10, m11) {
- out[0] = m00;
- out[1] = m01;
- out[2] = m10;
- out[3] = m11;
- return out;
-}
+let ErrShaderHeaderSize =
+/*#__PURE__*/
+function (_Tw2Error19) {
+ _inherits(ErrShaderHeaderSize, _Tw2Error19);
+
+ function ErrShaderHeaderSize(data) {
+ _classCallCheck(this, ErrShaderHeaderSize);
+
+ return _possibleConstructorReturn(this, _getPrototypeOf(ErrShaderHeaderSize).call(this, data, 'Effect file contains no compiled effects'));
+ }
+
+ return ErrShaderHeaderSize;
+}(Tw2Error);
/**
- * Transpose the values of a mat2
- *
- * @param {mat2} out the receiving matrix
- * @param {mat2} a the source matrix
- * @returns {mat2} out
+ * Throws when a shader has an invalid permutation value
*/
-function transpose(out, a) {
- // If we are transposing ourselves we can skip a few steps but have to cache
- // some values
- if (out === a) {
- let 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;
-}
+let ErrShaderPermutationValue =
+/*#__PURE__*/
+function (_Tw2Error20) {
+ _inherits(ErrShaderPermutationValue, _Tw2Error20);
+ function ErrShaderPermutationValue(data) {
+ _classCallCheck(this, ErrShaderPermutationValue);
+
+ return _possibleConstructorReturn(this, _getPrototypeOf(ErrShaderPermutationValue).call(this, data, 'Invalid shader permutation value'));
+ }
+
+ return ErrShaderPermutationValue;
+}(Tw2Error);
/**
- * Inverts a mat2
- *
- * @param {mat2} out the receiving matrix
- * @param {mat2} a the source matrix
- * @returns {mat2} out
+ * Throws when a shader cannot compile
*/
-function invert(out, a) {
- let a0 = a[0], a1 = a[1], a2 = a[2], a3 = a[3];
- // Calculate the determinant
- let det = a0 * a3 - a2 * a1;
+let ErrShaderCompile =
+/*#__PURE__*/
+function (_Tw2Error21) {
+ _inherits(ErrShaderCompile, _Tw2Error21);
- if (!det) {
- return null;
+ function ErrShaderCompile(data) {
+ _classCallCheck(this, ErrShaderCompile);
+
+ return _possibleConstructorReturn(this, _getPrototypeOf(ErrShaderCompile).call(this, data, 'Error compiling %shaderType% shader (%infoLog%)'));
}
- det = 1.0 / det;
- out[0] = a3 * det;
- out[1] = -a1 * det;
- out[2] = -a2 * det;
- out[3] = a0 * det;
+ return ErrShaderCompile;
+}(Tw2Error);
+/**
+ * Throws when unable to link a vertex shader and fragment shader
+ */
+
+let ErrShaderLink =
+/*#__PURE__*/
+function (_Tw2Error22) {
+ _inherits(ErrShaderLink, _Tw2Error22);
- return out;
-}
+ function ErrShaderLink(data) {
+ _classCallCheck(this, ErrShaderLink);
+
+ return _possibleConstructorReturn(this, _getPrototypeOf(ErrShaderLink).call(this, data, 'Error linking shaders'));
+ }
+ return ErrShaderLink;
+}(Tw2Error);
/**
- * Calculates the adjugate of a mat2
- *
- * @param {mat2} out the receiving matrix
- * @param {mat2} a the source matrix
- * @returns {mat2} out
+ * Throws on invalid raw data declaration types
*/
-function adjoint(out, a) {
- // Caching this value is nessecary if out == a
- let a0 = a[0];
- out[0] = a[3];
- out[1] = -a[1];
- out[2] = -a[2];
- out[3] = a0;
- return out;
-}
+let ErrDeclarationValueType =
+/*#__PURE__*/
+function (_Tw2Error23) {
+ _inherits(ErrDeclarationValueType, _Tw2Error23);
+
+ function ErrDeclarationValueType(data) {
+ _classCallCheck(this, ErrDeclarationValueType);
+ return _possibleConstructorReturn(this, _getPrototypeOf(ErrDeclarationValueType).call(this, data, 'Invalid declaration value type (%declaration%:%valueType%)'));
+ }
+
+ return ErrDeclarationValueType;
+}(Tw2Error);
/**
- * Calculates the determinant of a mat2
- *
- * @param {mat2} a the source matrix
- * @returns {Number} determinant of a
+ * Throws when a class can only be instantiated once
*/
-function determinant(a) {
- return a[0] * a[3] - a[2] * a[1];
-}
+let ErrSingletonInstantiation =
+/*#__PURE__*/
+function (_Tw2Error24) {
+ _inherits(ErrSingletonInstantiation, _Tw2Error24);
+
+ function ErrSingletonInstantiation(data) {
+ _classCallCheck(this, ErrSingletonInstantiation);
+
+ return _possibleConstructorReturn(this, _getPrototypeOf(ErrSingletonInstantiation).call(this, data, 'Multiple class instantiations not yet supported'));
+ }
+
+ return ErrSingletonInstantiation;
+}(Tw2Error);
/**
- * 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
+ * Throws when an abstract classes' method is not implemented directly on a child class
*/
-function multiply(out, a, b) {
- let a0 = a[0], a1 = a[1], a2 = a[2], a3 = a[3];
- let 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;
-}
+let ErrAbstractClassMethod =
+/*#__PURE__*/
+function (_Tw2Error25) {
+ _inherits(ErrAbstractClassMethod, _Tw2Error25);
+
+ function ErrAbstractClassMethod(data) {
+ _classCallCheck(this, ErrAbstractClassMethod);
+
+ return _possibleConstructorReturn(this, _getPrototypeOf(ErrAbstractClassMethod).call(this, data, 'Abstract class method not implemented directly on child class'));
+ }
+
+ return ErrAbstractClassMethod;
+}(Tw2Error);
/**
- * 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
+ * Throws when a feature is not implemented
*/
-function rotate(out, a, rad) {
- let a0 = a[0], a1 = a[1], a2 = a[2], a3 = a[3];
- let s = Math.sin(rad);
- let 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
- **/
-function scale(out, a, v) {
- let a0 = a[0], a1 = a[1], a2 = a[2], a3 = a[3];
- let v0 = v[0], v1 = v[1];
- out[0] = a0 * v0;
- out[1] = a1 * v0;
- out[2] = a2 * v1;
- out[3] = a3 * v1;
- return out;
-}
+let ErrFeatureNotImplemented =
+/*#__PURE__*/
+function (_Tw2Error26) {
+ _inherits(ErrFeatureNotImplemented, _Tw2Error26);
+
+ function ErrFeatureNotImplemented(data) {
+ _classCallCheck(this, ErrFeatureNotImplemented);
+
+ return _possibleConstructorReturn(this, _getPrototypeOf(ErrFeatureNotImplemented).call(this, data, '%feature=Feature% not implemented'));
+ }
+ return ErrFeatureNotImplemented;
+}(Tw2Error);
/**
- * 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
+ * Throws when an index is out of bounds
*/
-function fromRotation(out, rad) {
- let s = Math.sin(rad);
- let c = Math.cos(rad);
- out[0] = c;
- out[1] = s;
- out[2] = -s;
- out[3] = c;
- return out;
-}
+let ErrIndexBounds =
+/*#__PURE__*/
+function (_Tw2Error27) {
+ _inherits(ErrIndexBounds, _Tw2Error27);
+
+ function ErrIndexBounds(data) {
+ _classCallCheck(this, ErrIndexBounds);
+
+ return _possibleConstructorReturn(this, _getPrototypeOf(ErrIndexBounds).call(this, data, 'Array index out of bounds'));
+ }
+
+ return ErrIndexBounds;
+}(Tw2Error);
+
+/***/ }),
+/* 3 */
+/***/ (function(module, __webpack_exports__, __webpack_require__) {
+
+"use strict";
+__webpack_require__.r(__webpack_exports__);
+
+// CONCATENATED MODULE: ./global/util/type.js
+const type_toString = Object.prototype.toString;
/**
- * 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
+ * Checks if a value is an array
+ * @param {*} a
+ * @returns {boolean}
*/
-function fromScaling(out, v) {
- out[0] = v[0];
- out[1] = 0;
- out[2] = 0;
- out[3] = v[1];
- return out;
-}
+const isArray = Array.isArray;
/**
- * Returns a string representation of a mat2
- *
- * @param {mat2} a matrix to represent as a string
- * @returns {String} string representation of the matrix
+ * Checks if a value is an array or a typed array
+ * @param {*} a
+ * @returns {boolean}
*/
-function str(a) {
- return 'mat2(' + a[0] + ', ' + a[1] + ', ' + a[2] + ', ' + a[3] + ')';
-}
+function isArrayLike(a) {
+ return a ? isArray(a) || isTyped(a) : false;
+}
/**
- * Returns Frobenius norm of a mat2
- *
- * @param {mat2} a the matrix to calculate Frobenius norm of
- * @returns {Number} Frobenius norm
+ * Checks if a value is a boolean
+ * @param {*} a
+ * @returns {boolean}
*/
-function frob(a) {
- return(Math.sqrt(Math.pow(a[0], 2) + Math.pow(a[1], 2) + Math.pow(a[2], 2) + Math.pow(a[3], 2)))
-}
+function isBoolean(a) {
+ return isTag(a, '[object Boolean]');
+}
/**
- * 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
+ * Checks if a value is an html canvas element
+ * @param {*} a
+ * @returns {boolean}
*/
-function LDU(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];
+function isCanvas(a) {
+ return !!(a && a instanceof HTMLCanvasElement);
}
-
/**
- * 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
+ * Checks if a value is a descriptor
+ * @author jay phelps
+ * @param {*} a
+ * @returns {boolean}
*/
-function add(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;
-}
+function isDescriptor(a) {
+ if (!a || !a.hasOwnProperty) {
+ return false;
+ }
+
+ const keys = ['value', 'initializer', 'get', 'set'];
+
+ for (let i = 0, l = keys.length; i < l; i++) {
+ if (a.hasOwnProperty(keys[i])) {
+ return true;
+ }
+ }
+
+ return false;
+}
/**
- * 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
+ * Checks if a value is a valid sof DNA string
+ * @param {*} a
*/
-function subtract(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;
-}
+function isDNA(a) {
+ return isString(a) && a.match(/(\w|\d|[-_])+:(\w|\d|[-_])+:(\w|\d|[-_])+/);
+}
/**
- * 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.
+ * Checks if a value is an error
+ * @param {*} a
+ * @returns {boolean}
*/
-function exactEquals(a, b) {
- return a[0] === b[0] && a[1] === b[1] && a[2] === b[2] && a[3] === b[3];
-}
+function isError(a) {
+ return !!(a && a instanceof Error || a.constructor.category === 'error');
+}
/**
- * 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.
+ * Checks if a value is a number
+ * @param {*} a
+ * @returns {boolean}
*/
-function equals(a, b) {
- let a0 = a[0], a1 = a[1], a2 = a[2], a3 = a[3];
- let b0 = b[0], b1 = b[1], b2 = b[2], b3 = b[3];
- return (Math.abs(a0 - b0) <= __WEBPACK_IMPORTED_MODULE_0__common__["EPSILON"]*Math.max(1.0, Math.abs(a0), Math.abs(b0)) &&
- Math.abs(a1 - b1) <= __WEBPACK_IMPORTED_MODULE_0__common__["EPSILON"]*Math.max(1.0, Math.abs(a1), Math.abs(b1)) &&
- Math.abs(a2 - b2) <= __WEBPACK_IMPORTED_MODULE_0__common__["EPSILON"]*Math.max(1.0, Math.abs(a2), Math.abs(b2)) &&
- Math.abs(a3 - b3) <= __WEBPACK_IMPORTED_MODULE_0__common__["EPSILON"]*Math.max(1.0, Math.abs(a3), Math.abs(b3)));
-}
+function isNumber(a) {
+ return isTag(a, '[object Number]');
+}
/**
- * 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
+ * Checks if a value is a function
+ * @param {*} a
+ * @returns {boolean}
*/
-function multiplyScalar(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;
-}
+function isFunction(a) {
+ return typeof a === 'function';
+}
/**
- * 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
+ * Checks if a value is null or undefined
+ * @param {*} a
+ * @returns {boolean}
*/
-function multiplyScalarAndAdd(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;
+
+function isNoU(a) {
+ return a == null;
}
+/**
+ * Checks if a value is null
+ * @param {*} a
+ * @returns {boolean}
+ */
+function isNull(a) {
+ return a === null;
+}
/**
- * Alias for {@link mat2.multiply}
- * @function
+ * Checks if a value is an object and not null
+ * @param {*} a
+ * @returns {boolean}
*/
-const mul = multiply;
-/* harmony export (immutable) */ __webpack_exports__["mul"] = mul;
+function isObject(a) {
+ const type = typeof a;
+ return a !== null && (type === 'object' || type === 'function');
+}
+/**
+ * Checks if a value has the type object, and is not null
+ * @param {*} a
+ * @returns {boolean}
+ */
+function isObjectLike(a) {
+ return a !== null && typeof a === 'object';
+}
/**
- * Alias for {@link mat2.subtract}
- * @function
+ * Checks if a value is a plain object
+ * @author lodash
+ * @param {*} a
+ * @returns {boolean}
*/
-const sub = subtract;
-/* harmony export (immutable) */ __webpack_exports__["sub"] = sub;
+function isPlain(a) {
+ if (!isObject(a) || !isTag(a, '[object Object]')) {
+ return false;
+ }
+
+ if (Object.getPrototypeOf(a) === null) {
+ return true;
+ }
+ let proto = a;
-/***/ }),
-/* 68 */
-/***/ (function(module, __webpack_exports__, __webpack_require__) {
+ while (Object.getPrototypeOf(proto) !== null) {
+ proto = Object.getPrototypeOf(proto);
+ }
-"use strict";
-Object.defineProperty(__webpack_exports__, "__esModule", { value: true });
-/* harmony export (immutable) */ __webpack_exports__["create"] = create;
-/* harmony export (immutable) */ __webpack_exports__["clone"] = clone;
-/* harmony export (immutable) */ __webpack_exports__["copy"] = copy;
-/* harmony export (immutable) */ __webpack_exports__["identity"] = identity;
-/* harmony export (immutable) */ __webpack_exports__["fromValues"] = fromValues;
-/* harmony export (immutable) */ __webpack_exports__["set"] = set;
-/* harmony export (immutable) */ __webpack_exports__["invert"] = invert;
-/* harmony export (immutable) */ __webpack_exports__["determinant"] = determinant;
-/* harmony export (immutable) */ __webpack_exports__["multiply"] = multiply;
-/* harmony export (immutable) */ __webpack_exports__["rotate"] = rotate;
-/* harmony export (immutable) */ __webpack_exports__["scale"] = scale;
-/* harmony export (immutable) */ __webpack_exports__["translate"] = translate;
-/* harmony export (immutable) */ __webpack_exports__["fromRotation"] = fromRotation;
-/* harmony export (immutable) */ __webpack_exports__["fromScaling"] = fromScaling;
-/* harmony export (immutable) */ __webpack_exports__["fromTranslation"] = fromTranslation;
-/* harmony export (immutable) */ __webpack_exports__["str"] = str;
-/* harmony export (immutable) */ __webpack_exports__["frob"] = frob;
-/* harmony export (immutable) */ __webpack_exports__["add"] = add;
-/* harmony export (immutable) */ __webpack_exports__["subtract"] = subtract;
-/* harmony export (immutable) */ __webpack_exports__["multiplyScalar"] = multiplyScalar;
-/* harmony export (immutable) */ __webpack_exports__["multiplyScalarAndAdd"] = multiplyScalarAndAdd;
-/* harmony export (immutable) */ __webpack_exports__["exactEquals"] = exactEquals;
-/* harmony export (immutable) */ __webpack_exports__["equals"] = equals;
-/* harmony import */ var __WEBPACK_IMPORTED_MODULE_0__common__ = __webpack_require__(5);
-/* 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. */
-
-
-
-/**
- * 2x3 Matrix
- * @module 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.
- */
-
-/**
- * Creates a new identity mat2d
- *
- * @returns {mat2d} a new 2x3 matrix
- */
-function create() {
- let out = new __WEBPACK_IMPORTED_MODULE_0__common__["ARRAY_TYPE"](6);
- out[0] = 1;
- out[1] = 0;
- out[2] = 0;
- out[3] = 1;
- out[4] = 0;
- out[5] = 0;
- return out;
+ return Object.getPrototypeOf(a) === proto;
}
-
/**
- * Creates a new mat2d initialized with values from an existing matrix
- *
- * @param {mat2d} a matrix to clone
- * @returns {mat2d} a new 2x3 matrix
+ * Checks if a value is a primary type
+ * @param {*} a
+ * @returns {boolean}
*/
-function clone(a) {
- let out = new __WEBPACK_IMPORTED_MODULE_0__common__["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;
-}
+function isPrimary(a) {
+ return isBoolean(a) || isNumber(a) || isString(a);
+}
/**
- * Copy the values from one mat2d to another
- *
- * @param {mat2d} out the receiving matrix
- * @param {mat2d} a the source matrix
- * @returns {mat2d} out
+ * Checks if a value is a string
+ * @param {*} a
+ * @returns {boolean}
*/
-function copy(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;
-}
+function isString(a) {
+ return isTag(a, '[object String]');
+}
/**
- * Set a mat2d to the identity matrix
- *
- * @param {mat2d} out the receiving matrix
- * @returns {mat2d} out
+ * Checks if a value is a symbol
+ * @param {*} a
+ * @returns {boolean}
*/
-function identity(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
- */
-function fromValues(a, b, c, d, tx, ty) {
- let out = new __WEBPACK_IMPORTED_MODULE_0__common__["ARRAY_TYPE"](6);
- out[0] = a;
- out[1] = b;
- out[2] = c;
- out[3] = d;
- out[4] = tx;
- out[5] = ty;
- return out;
+function isSymbol(a) {
+ return typeof a === 'symbol' || isTag(a, '[object Symbol]');
}
+/**
+ * Checks if a value has a given tag
+ * @param {*} a
+ * @param {string} tag
+ * @returns {boolean}
+ */
+function isTag(a, tag) {
+ return type_toString.call(a) === tag;
+}
/**
- * 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
- */
-function set(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;
+ * Checks if a value is a typed array
+ * @param {*} a
+ * @returns {boolean}
+ */
+
+function isTyped(a) {
+ return a ? !!(a.buffer instanceof ArrayBuffer && a.BYTES_PER_ELEMENT) : false;
}
+/**
+ * Checks if a value is undefined
+ * @param {*} a
+ * @returns {boolean}
+ */
+function isUndefined(a) {
+ return a === undefined;
+}
/**
- * Inverts a mat2d
- *
- * @param {mat2d} out the receiving matrix
- * @param {mat2d} a the source matrix
- * @returns {mat2d} out
+ * Checks if a value is arraylike and only contains numbers
+ * @param {*} a
+ * @returns {boolean}
*/
-function invert(out, a) {
- let aa = a[0], ab = a[1], ac = a[2], ad = a[3];
- let atx = a[4], aty = a[5];
- let det = aa * ad - ab * ac;
- if(!det){
- return null;
+function isVector(a) {
+ if (!a) {
+ return false;
}
- 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;
+ if (isTyped(a)) {
+ return true;
+ }
+
+ if (isArray(a)) {
+ for (let i = 0; i < a.length; i++) {
+ if (!isNumber(a[i])) return false;
+ }
+
+ return true;
+ }
}
+// CONCATENATED MODULE: ./global/util/arr.js
/**
- * Calculates the determinant of a mat2d
- *
- * @param {mat2d} a the source matrix
- * @returns {Number} determinant of a
+ * Adds arguments to an array if they don't already exist in it
+ * @param {Array} arr
+ * @param args
+ * @returns {boolean} true if something was added
*/
-function determinant(a) {
- return a[0] * a[3] - a[1] * a[2];
-}
+function addToArray(arr) {
+ let added = false;
+
+ for (let i = 0; i < (arguments.length <= 1 ? 0 : arguments.length - 1); i++) {
+ if (arr.indexOf(i + 1 < 1 || arguments.length <= i + 1 ? undefined : arguments[i + 1]) === -1) {
+ arr.push(i + 1 < 1 || arguments.length <= i + 1 ? undefined : arguments[i + 1]);
+ added = true;
+ }
+ }
+
+ return added;
+}
/**
- * 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
+ * Calls a function with arguments for each child in an array where that function exists
+ * @param {Array} arr
+ * @param {string} func
+ * @param args
*/
-function multiply(out, a, b) {
- let a0 = a[0], a1 = a[1], a2 = a[2], a3 = a[3], a4 = a[4], a5 = a[5];
- let 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;
-}
+function perArrayChild(arr, func) {
+ const len = arr.length;
+
+ for (var _len = arguments.length, args = new Array(_len > 2 ? _len - 2 : 0), _key = 2; _key < _len; _key++) {
+ args[_key - 2] = arguments[_key];
+ }
+
+ for (let i = 0; i < len; i++) {
+ if (func in arr) arr[i][func](...args);
+ }
+}
/**
- * 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
+ * Removes arguments from an array if they exist in it
+ * @param {Array} arr
+ * @param args
+ * @returns {boolean} true if something was removed
*/
-function rotate(out, a, rad) {
- let a0 = a[0], a1 = a[1], a2 = a[2], a3 = a[3], a4 = a[4], a5 = a[5];
- let s = Math.sin(rad);
- let 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
- **/
-function scale(out, a, v) {
- let a0 = a[0], a1 = a[1], a2 = a[2], a3 = a[3], a4 = a[4], a5 = a[5];
- let 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;
-}
+function removeFromArray(arr) {
+ let removed = false;
-/**
- * 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
- **/
-function translate(out, a, v) {
- let a0 = a[0], a1 = a[1], a2 = a[2], a3 = a[3], a4 = a[4], a5 = a[5];
- let 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;
-}
+ for (let i = 0; i < (arguments.length <= 1 ? 0 : arguments.length - 1); i++) {
+ const index = arr.indexOf(i + 1 < 1 || arguments.length <= i + 1 ? undefined : arguments[i + 1]);
+
+ if (index !== -1) {
+ arr.splice(index, 1);
+ removed = true;
+ }
+ }
+ return removed;
+}
/**
- * 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
+ * Returns a value if it is an array, or a new array with the object in it
+ * @param {*} a
+ * @returns {Array}
*/
-function fromRotation(out, rad) {
- let 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;
-}
+function toArray(a) {
+ return isArray(a) ? a : [a];
+}
/**
- * 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
+ * Returns an array containing only unique numbers
+ * @param {*} a
+ * @returns {Array}
*/
-function fromScaling(out, v) {
- out[0] = v[0];
- out[1] = 0;
- out[2] = 0;
- out[3] = v[1];
- out[4] = 0;
- out[5] = 0;
- return out;
+
+function toUniqueArray(a) {
+ return Array.from(new Set(toArray(a)));
}
+// CONCATENATED MODULE: ./global/util/obj.js
+
/**
- * Creates a matrix from a vector translation
- * This is equivalent to (but much faster than):
+ * Assigns property values if they exist in a source object
+ * - Typed arrays are cloned/ copied to ensure no pass-by-reference errors
*
- * mat2d.identity(dest);
- * mat2d.translate(dest, dest, vec);
- *
- * @param {mat2d} out mat2d receiving operation result
- * @param {vec2} v Translation vector
- * @returns {mat2d} out
+ * @param {*} dest
+ * @param {*} src
+ * @param {string|string[]} attrs
*/
-function fromTranslation(out, v) {
- out[0] = 1;
- out[1] = 0;
- out[2] = 0;
- out[3] = 1;
- out[4] = v[0];
- out[5] = v[1];
- return out;
-}
+function assignIfExists(dest, src, attrs) {
+ if (!src) return;
+ attrs = toArray(attrs);
+
+ for (let i = 0; i < attrs.length; i++) {
+ const attr = attrs[i];
+
+ if (src[attr] !== undefined) {
+ if (isArrayLike(dest[attr])) {
+ if (isTyped(dest[attr])) {
+ if (dest[attr].length !== src[attr].length) {
+ const Constructor = dest[attr].constructor;
+ dest[attr] = new Constructor(src[attr]);
+ } else {
+ dest[attr].set(src[attr]);
+ }
+ } else {
+ dest[attr] = dest[attr].splice(dest[attr].length, 0);
+
+ for (let i = 0; i < src[attr].length; i++) {
+ dest[attr].push(src[attr][i]);
+ }
+ }
+ } else if (isTyped(src[attr])) {
+ const Constructor = src[attr].constructor;
+ dest[attr] = new Constructor(src[attr]);
+ } else {
+ dest[attr] = src[attr];
+ }
+ }
+ }
+}
/**
- * Returns a string representation of a mat2d
- *
- * @param {mat2d} a matrix to represent as a string
- * @returns {String} string representation of the matrix
+ * Gets a source's property value if it exists else returns a default value
+ * @param {*} src
+ * @param {string|string[]} prop
+ * @param {*} [defaultValue]
+ * @returns {*}
*/
-function str(a) {
- return 'mat2d(' + a[0] + ', ' + a[1] + ', ' + a[2] + ', ' +
- a[3] + ', ' + a[4] + ', ' + a[5] + ')';
+
+function get(src, prop, defaultValue) {
+ if (!isArray(prop)) {
+ return prop in src ? src[prop] : defaultValue;
+ }
+
+ for (let i = 0; i < prop.length; i++) {
+ if (prop[i] in src) {
+ return src[prop[i]];
+ }
+ }
+
+ return defaultValue;
}
+/**
+ * Returns a string from a string template and a given object's properties
+ * - templates are surrounded by %'s (ie. %propertyName%)
+ * - default values are optionally identified with an = (ie. %propertyName=defaultValue%)
+ * @param {string} str
+ * @param {{}} [obj={}]
+ * @returns {string}
+ *
+ * @example
+ * const message = "%feature=Feature% not supported";
+ * const message2 = "%feature% not supported";
+ * let str1 = template(message, { feature: "Dynamic resource paths" })
+ * let str2 = template(message);
+ * let str3 = template(message2);
+ * > str1 === "Dynamic resource paths not supported"
+ * > str2 === "Feature not supported"
+ * > str3 === "undefined not supported"
+ */
+
+function template(str) {
+ let obj = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
+ const literals = str.match(/%([^%]+)?%/g) || [];
+
+ for (let i = 0; i < literals.length; i++) {
+ const literal = literals[i],
+ split = literal.substring(1, literal.length - 1).split('='),
+ value = split[0] in obj ? obj[split[0]] : split[1];
+ str = str.replace(literal, value);
+ }
+ return str;
+}
+// CONCATENATED MODULE: ./global/util/uuid.js
/**
- * Returns Frobenius norm of a mat2d
- *
- * @param {mat2d} a the matrix to calculate Frobenius norm of
- * @returns {Number} Frobenius norm
+ * Identifies if UUIDs should be used for ID generation
+ * @type {?boolean}
*/
-function frob(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))
-}
-
+let USE_UUID = null;
/**
- * 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
+ * Internal object count
+ * @type {number}
*/
-function add(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;
-}
+let OBJECT_COUNT = 0;
/**
- * 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
+ * Stores uuid scratch
+ * @type {?Array}
*/
-function subtract(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;
+
+let LUT = null;
+/**
+ * Generates a UUID
+ * @author Three.js
+ * @returns {string}
+ */
+
+function generateUUID() {
+ const d0 = Math.random() * 0xffffffff | 0,
+ d1 = Math.random() * 0xffffffff | 0,
+ d2 = Math.random() * 0xffffffff | 0,
+ d3 = Math.random() * 0xffffffff | 0;
+ return LUT[d0 & 0xff] + LUT[d0 >> 8 & 0xff] + LUT[d0 >> 16 & 0xff] + LUT[d0 >> 24 & 0xff] + '-' + LUT[d1 & 0xff] + LUT[d1 >> 8 & 0xff] + '-' + LUT[d1 >> 16 & 0x0f | 0x40] + LUT[d1 >> 24 & 0xff] + '-' + LUT[d2 & 0x3f | 0x80] + LUT[d2 >> 8 & 0xff] + '-' + LUT[d2 >> 16 & 0xff] + LUT[d2 >> 24 & 0xff] + LUT[d3 & 0xff] + LUT[d3 >> 8 & 0xff] + LUT[d3 >> 16 & 0xff] + LUT[d3 >> 24 & 0xff];
}
+/**
+ * Enables UUID's for ID generation
+ * @param {boolean} bool
+ * @throws When generateID has already been used and trying to set a different ID type
+ */
+
+
+function enableUUID(bool) {
+ if (bool === USE_UUID) {
+ return;
+ }
+
+ if (USE_UUID !== null) {
+ throw new Error('Cannot change id generation type once set');
+ }
+
+ if (bool) {
+ LUT = [];
+ for (let i = 0; i < 256; i++) {
+ LUT[i] = (i < 16 ? '0' : '') + i.toString(16).toUpperCase();
+ }
+ }
+
+ USE_UUID = bool;
+}
/**
- * 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
+ * Generates an id
+ * - Defaults to Object IDs
+ * @returns {string|number}
*/
-function multiplyScalar(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;
+
+function generateID() {
+ if (USE_UUID === null) {
+ USE_UUID = false;
+ }
+
+ return USE_UUID ? generateUUID() : OBJECT_COUNT++;
+}
+// CONCATENATED MODULE: ./global/util/url.js
+const url = {},
+ query = window.location.search.substring(1),
+ split = query.split('&');
+
+for (let i = 0; i < split.length; i++) {
+ const result = split[i].split('='),
+ key = result[0].toLowerCase(),
+ value = unescape(result[1]);
+
+ if (key) {
+ let v = value.toLowerCase();
+ url[key] = v === 'true' ? true : v === 'false' ? false : value;
+ }
}
+/**
+ * Gets the url as an object
+ * @returns {*}
+ */
+
+function getURL() {
+ return Object.assign({}, url);
+}
/**
- * 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
+ * Gets a string from the url, returning a default value if not found
+ * @param {string} key
+ * @param {string} defaultValue
+ * @returns {string}
*/
-function multiplyScalarAndAdd(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;
+
+function getURLString(key, defaultValue) {
+ key = key.toLowerCase();
+ return key in url ? url[key] : defaultValue;
}
+/**
+ * Gets an integer from the url, returning a default value if not found
+ * @param {string} key
+ * @param {number} defaultValue
+ * @returns {number}
+ */
+function getURLInteger(key, defaultValue) {
+ key = key.toLowerCase();
+ return key in url ? parseInt(url[key], 10) : defaultValue;
+}
/**
- * 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.
+ * Gets a float from the url, returning a default value if not found
+ * @param {string} key
+ * @param {number} defaultValue
+ * @returns {number}
*/
-function exactEquals(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];
+
+function getURLFloat(key, defaultValue) {
+ key = key.toLowerCase();
+ return key in url ? parseFloat(url[key]) : defaultValue;
+}
+/**
+ * Gets a boolean from the url, returning a default value if not found
+ * @param {string} key
+ * @param {boolean} defaultValue
+ * @returns {boolean}
+ */
+
+function getURLBoolean(key, defaultValue) {
+ key = key.toLowerCase();
+ return key in url ? url[key] : defaultValue;
}
+// CONCATENATED MODULE: ./global/util/index.js
+/* concated harmony reexport addToArray */__webpack_require__.d(__webpack_exports__, "addToArray", function() { return addToArray; });
+/* concated harmony reexport perArrayChild */__webpack_require__.d(__webpack_exports__, "perArrayChild", function() { return perArrayChild; });
+/* concated harmony reexport removeFromArray */__webpack_require__.d(__webpack_exports__, "removeFromArray", function() { return removeFromArray; });
+/* concated harmony reexport toArray */__webpack_require__.d(__webpack_exports__, "toArray", function() { return toArray; });
+/* concated harmony reexport toUniqueArray */__webpack_require__.d(__webpack_exports__, "toUniqueArray", function() { return toUniqueArray; });
+/* concated harmony reexport assignIfExists */__webpack_require__.d(__webpack_exports__, "assignIfExists", function() { return assignIfExists; });
+/* concated harmony reexport get */__webpack_require__.d(__webpack_exports__, "get", function() { return get; });
+/* concated harmony reexport template */__webpack_require__.d(__webpack_exports__, "template", function() { return template; });
+/* concated harmony reexport isArray */__webpack_require__.d(__webpack_exports__, "isArray", function() { return isArray; });
+/* concated harmony reexport isArrayLike */__webpack_require__.d(__webpack_exports__, "isArrayLike", function() { return isArrayLike; });
+/* concated harmony reexport isBoolean */__webpack_require__.d(__webpack_exports__, "isBoolean", function() { return isBoolean; });
+/* concated harmony reexport isCanvas */__webpack_require__.d(__webpack_exports__, "isCanvas", function() { return isCanvas; });
+/* concated harmony reexport isDescriptor */__webpack_require__.d(__webpack_exports__, "isDescriptor", function() { return isDescriptor; });
+/* concated harmony reexport isDNA */__webpack_require__.d(__webpack_exports__, "isDNA", function() { return isDNA; });
+/* concated harmony reexport isError */__webpack_require__.d(__webpack_exports__, "isError", function() { return isError; });
+/* concated harmony reexport isNumber */__webpack_require__.d(__webpack_exports__, "isNumber", function() { return isNumber; });
+/* concated harmony reexport isFunction */__webpack_require__.d(__webpack_exports__, "isFunction", function() { return isFunction; });
+/* concated harmony reexport isNoU */__webpack_require__.d(__webpack_exports__, "isNoU", function() { return isNoU; });
+/* concated harmony reexport isNull */__webpack_require__.d(__webpack_exports__, "isNull", function() { return isNull; });
+/* concated harmony reexport isObject */__webpack_require__.d(__webpack_exports__, "isObject", function() { return isObject; });
+/* concated harmony reexport isObjectLike */__webpack_require__.d(__webpack_exports__, "isObjectLike", function() { return isObjectLike; });
+/* concated harmony reexport isPlain */__webpack_require__.d(__webpack_exports__, "isPlain", function() { return isPlain; });
+/* concated harmony reexport isPrimary */__webpack_require__.d(__webpack_exports__, "isPrimary", function() { return isPrimary; });
+/* concated harmony reexport isString */__webpack_require__.d(__webpack_exports__, "isString", function() { return isString; });
+/* concated harmony reexport isSymbol */__webpack_require__.d(__webpack_exports__, "isSymbol", function() { return isSymbol; });
+/* concated harmony reexport isTag */__webpack_require__.d(__webpack_exports__, "isTag", function() { return isTag; });
+/* concated harmony reexport isTyped */__webpack_require__.d(__webpack_exports__, "isTyped", function() { return isTyped; });
+/* concated harmony reexport isUndefined */__webpack_require__.d(__webpack_exports__, "isUndefined", function() { return isUndefined; });
+/* concated harmony reexport isVector */__webpack_require__.d(__webpack_exports__, "isVector", function() { return isVector; });
+/* concated harmony reexport enableUUID */__webpack_require__.d(__webpack_exports__, "enableUUID", function() { return enableUUID; });
+/* concated harmony reexport generateID */__webpack_require__.d(__webpack_exports__, "generateID", function() { return generateID; });
+/* concated harmony reexport getURL */__webpack_require__.d(__webpack_exports__, "getURL", function() { return getURL; });
+/* concated harmony reexport getURLString */__webpack_require__.d(__webpack_exports__, "getURLString", function() { return getURLString; });
+/* concated harmony reexport getURLInteger */__webpack_require__.d(__webpack_exports__, "getURLInteger", function() { return getURLInteger; });
+/* concated harmony reexport getURLFloat */__webpack_require__.d(__webpack_exports__, "getURLFloat", function() { return getURLFloat; });
+/* concated harmony reexport getURLBoolean */__webpack_require__.d(__webpack_exports__, "getURLBoolean", function() { return getURLBoolean; });
+
+
+
+
+
+/***/ }),
+/* 4 */
+/***/ (function(module, __webpack_exports__, __webpack_require__) {
+
+"use strict";
+__webpack_require__.r(__webpack_exports__);
+var mat3_namespaceObject = {};
+__webpack_require__.r(mat3_namespaceObject);
+__webpack_require__.d(mat3_namespaceObject, "create", function() { return create; });
+__webpack_require__.d(mat3_namespaceObject, "fromMat4", function() { return fromMat4; });
+__webpack_require__.d(mat3_namespaceObject, "clone", function() { return clone; });
+__webpack_require__.d(mat3_namespaceObject, "copy", function() { return copy; });
+__webpack_require__.d(mat3_namespaceObject, "fromValues", function() { return fromValues; });
+__webpack_require__.d(mat3_namespaceObject, "set", function() { return set; });
+__webpack_require__.d(mat3_namespaceObject, "identity", function() { return identity; });
+__webpack_require__.d(mat3_namespaceObject, "transpose", function() { return transpose; });
+__webpack_require__.d(mat3_namespaceObject, "invert", function() { return invert; });
+__webpack_require__.d(mat3_namespaceObject, "adjoint", function() { return adjoint; });
+__webpack_require__.d(mat3_namespaceObject, "determinant", function() { return determinant; });
+__webpack_require__.d(mat3_namespaceObject, "multiply", function() { return multiply; });
+__webpack_require__.d(mat3_namespaceObject, "translate", function() { return translate; });
+__webpack_require__.d(mat3_namespaceObject, "rotate", function() { return rotate; });
+__webpack_require__.d(mat3_namespaceObject, "scale", function() { return mat3_scale; });
+__webpack_require__.d(mat3_namespaceObject, "fromTranslation", function() { return fromTranslation; });
+__webpack_require__.d(mat3_namespaceObject, "fromRotation", function() { return fromRotation; });
+__webpack_require__.d(mat3_namespaceObject, "fromScaling", function() { return fromScaling; });
+__webpack_require__.d(mat3_namespaceObject, "fromMat2d", function() { return fromMat2d; });
+__webpack_require__.d(mat3_namespaceObject, "fromQuat", function() { return fromQuat; });
+__webpack_require__.d(mat3_namespaceObject, "normalFromMat4", function() { return normalFromMat4; });
+__webpack_require__.d(mat3_namespaceObject, "projection", function() { return projection; });
+__webpack_require__.d(mat3_namespaceObject, "str", function() { return str; });
+__webpack_require__.d(mat3_namespaceObject, "frob", function() { return frob; });
+__webpack_require__.d(mat3_namespaceObject, "add", function() { return add; });
+__webpack_require__.d(mat3_namespaceObject, "subtract", function() { return subtract; });
+__webpack_require__.d(mat3_namespaceObject, "multiplyScalar", function() { return multiplyScalar; });
+__webpack_require__.d(mat3_namespaceObject, "multiplyScalarAndAdd", function() { return multiplyScalarAndAdd; });
+__webpack_require__.d(mat3_namespaceObject, "exactEquals", function() { return exactEquals; });
+__webpack_require__.d(mat3_namespaceObject, "equals", function() { return mat3_equals; });
+__webpack_require__.d(mat3_namespaceObject, "mul", function() { return mul; });
+__webpack_require__.d(mat3_namespaceObject, "sub", function() { return sub; });
+var mat4_namespaceObject = {};
+__webpack_require__.r(mat4_namespaceObject);
+__webpack_require__.d(mat4_namespaceObject, "create", function() { return mat4_create; });
+__webpack_require__.d(mat4_namespaceObject, "clone", function() { return mat4_clone; });
+__webpack_require__.d(mat4_namespaceObject, "copy", function() { return mat4_copy; });
+__webpack_require__.d(mat4_namespaceObject, "fromValues", function() { return mat4_fromValues; });
+__webpack_require__.d(mat4_namespaceObject, "set", function() { return mat4_set; });
+__webpack_require__.d(mat4_namespaceObject, "identity", function() { return mat4_identity; });
+__webpack_require__.d(mat4_namespaceObject, "transpose", function() { return mat4_transpose; });
+__webpack_require__.d(mat4_namespaceObject, "invert", function() { return mat4_invert; });
+__webpack_require__.d(mat4_namespaceObject, "adjoint", function() { return mat4_adjoint; });
+__webpack_require__.d(mat4_namespaceObject, "determinant", function() { return mat4_determinant; });
+__webpack_require__.d(mat4_namespaceObject, "multiply", function() { return mat4_multiply; });
+__webpack_require__.d(mat4_namespaceObject, "translate", function() { return mat4_translate; });
+__webpack_require__.d(mat4_namespaceObject, "scale", function() { return mat4_scale; });
+__webpack_require__.d(mat4_namespaceObject, "rotate", function() { return mat4_rotate; });
+__webpack_require__.d(mat4_namespaceObject, "rotateX", function() { return rotateX; });
+__webpack_require__.d(mat4_namespaceObject, "rotateY", function() { return rotateY; });
+__webpack_require__.d(mat4_namespaceObject, "rotateZ", function() { return rotateZ; });
+__webpack_require__.d(mat4_namespaceObject, "fromTranslation", function() { return mat4_fromTranslation; });
+__webpack_require__.d(mat4_namespaceObject, "fromScaling", function() { return mat4_fromScaling; });
+__webpack_require__.d(mat4_namespaceObject, "fromRotation", function() { return mat4_fromRotation; });
+__webpack_require__.d(mat4_namespaceObject, "fromXRotation", function() { return fromXRotation; });
+__webpack_require__.d(mat4_namespaceObject, "fromYRotation", function() { return fromYRotation; });
+__webpack_require__.d(mat4_namespaceObject, "fromZRotation", function() { return fromZRotation; });
+__webpack_require__.d(mat4_namespaceObject, "fromRotationTranslation", function() { return fromRotationTranslation; });
+__webpack_require__.d(mat4_namespaceObject, "fromQuat2", function() { return fromQuat2; });
+__webpack_require__.d(mat4_namespaceObject, "getTranslation", function() { return getTranslation; });
+__webpack_require__.d(mat4_namespaceObject, "getScaling", function() { return getScaling; });
+__webpack_require__.d(mat4_namespaceObject, "getRotation", function() { return getRotation; });
+__webpack_require__.d(mat4_namespaceObject, "fromRotationTranslationScale", function() { return fromRotationTranslationScale; });
+__webpack_require__.d(mat4_namespaceObject, "fromRotationTranslationScaleOrigin", function() { return fromRotationTranslationScaleOrigin; });
+__webpack_require__.d(mat4_namespaceObject, "fromQuat", function() { return mat4_fromQuat; });
+__webpack_require__.d(mat4_namespaceObject, "frustum", function() { return frustum; });
+__webpack_require__.d(mat4_namespaceObject, "perspective", function() { return perspective; });
+__webpack_require__.d(mat4_namespaceObject, "perspectiveFromFieldOfView", function() { return perspectiveFromFieldOfView; });
+__webpack_require__.d(mat4_namespaceObject, "ortho", function() { return ortho; });
+__webpack_require__.d(mat4_namespaceObject, "lookAt", function() { return lookAt; });
+__webpack_require__.d(mat4_namespaceObject, "targetTo", function() { return targetTo; });
+__webpack_require__.d(mat4_namespaceObject, "str", function() { return mat4_str; });
+__webpack_require__.d(mat4_namespaceObject, "frob", function() { return mat4_frob; });
+__webpack_require__.d(mat4_namespaceObject, "add", function() { return mat4_add; });
+__webpack_require__.d(mat4_namespaceObject, "subtract", function() { return mat4_subtract; });
+__webpack_require__.d(mat4_namespaceObject, "multiplyScalar", function() { return mat4_multiplyScalar; });
+__webpack_require__.d(mat4_namespaceObject, "multiplyScalarAndAdd", function() { return mat4_multiplyScalarAndAdd; });
+__webpack_require__.d(mat4_namespaceObject, "exactEquals", function() { return mat4_exactEquals; });
+__webpack_require__.d(mat4_namespaceObject, "equals", function() { return mat4_equals; });
+__webpack_require__.d(mat4_namespaceObject, "mul", function() { return mat4_mul; });
+__webpack_require__.d(mat4_namespaceObject, "sub", function() { return mat4_sub; });
+var vec3_namespaceObject = {};
+__webpack_require__.r(vec3_namespaceObject);
+__webpack_require__.d(vec3_namespaceObject, "create", function() { return vec3_create; });
+__webpack_require__.d(vec3_namespaceObject, "clone", function() { return vec3_clone; });
+__webpack_require__.d(vec3_namespaceObject, "length", function() { return vec3_length; });
+__webpack_require__.d(vec3_namespaceObject, "fromValues", function() { return vec3_fromValues; });
+__webpack_require__.d(vec3_namespaceObject, "copy", function() { return vec3_copy; });
+__webpack_require__.d(vec3_namespaceObject, "set", function() { return vec3_set; });
+__webpack_require__.d(vec3_namespaceObject, "add", function() { return vec3_add; });
+__webpack_require__.d(vec3_namespaceObject, "subtract", function() { return vec3_subtract; });
+__webpack_require__.d(vec3_namespaceObject, "multiply", function() { return vec3_multiply; });
+__webpack_require__.d(vec3_namespaceObject, "divide", function() { return divide; });
+__webpack_require__.d(vec3_namespaceObject, "ceil", function() { return ceil; });
+__webpack_require__.d(vec3_namespaceObject, "floor", function() { return floor; });
+__webpack_require__.d(vec3_namespaceObject, "min", function() { return min; });
+__webpack_require__.d(vec3_namespaceObject, "max", function() { return max; });
+__webpack_require__.d(vec3_namespaceObject, "round", function() { return round; });
+__webpack_require__.d(vec3_namespaceObject, "scale", function() { return vec3_scale; });
+__webpack_require__.d(vec3_namespaceObject, "scaleAndAdd", function() { return scaleAndAdd; });
+__webpack_require__.d(vec3_namespaceObject, "distance", function() { return distance; });
+__webpack_require__.d(vec3_namespaceObject, "squaredDistance", function() { return squaredDistance; });
+__webpack_require__.d(vec3_namespaceObject, "squaredLength", function() { return squaredLength; });
+__webpack_require__.d(vec3_namespaceObject, "negate", function() { return negate; });
+__webpack_require__.d(vec3_namespaceObject, "inverse", function() { return inverse; });
+__webpack_require__.d(vec3_namespaceObject, "normalize", function() { return normalize; });
+__webpack_require__.d(vec3_namespaceObject, "dot", function() { return vec3_dot; });
+__webpack_require__.d(vec3_namespaceObject, "cross", function() { return cross; });
+__webpack_require__.d(vec3_namespaceObject, "lerp", function() { return lerp; });
+__webpack_require__.d(vec3_namespaceObject, "hermite", function() { return hermite; });
+__webpack_require__.d(vec3_namespaceObject, "bezier", function() { return bezier; });
+__webpack_require__.d(vec3_namespaceObject, "random", function() { return random; });
+__webpack_require__.d(vec3_namespaceObject, "transformMat4", function() { return transformMat4; });
+__webpack_require__.d(vec3_namespaceObject, "transformMat3", function() { return transformMat3; });
+__webpack_require__.d(vec3_namespaceObject, "transformQuat", function() { return transformQuat; });
+__webpack_require__.d(vec3_namespaceObject, "rotateX", function() { return vec3_rotateX; });
+__webpack_require__.d(vec3_namespaceObject, "rotateY", function() { return vec3_rotateY; });
+__webpack_require__.d(vec3_namespaceObject, "rotateZ", function() { return vec3_rotateZ; });
+__webpack_require__.d(vec3_namespaceObject, "angle", function() { return angle; });
+__webpack_require__.d(vec3_namespaceObject, "str", function() { return vec3_str; });
+__webpack_require__.d(vec3_namespaceObject, "exactEquals", function() { return vec3_exactEquals; });
+__webpack_require__.d(vec3_namespaceObject, "equals", function() { return vec3_equals; });
+__webpack_require__.d(vec3_namespaceObject, "sub", function() { return vec3_sub; });
+__webpack_require__.d(vec3_namespaceObject, "mul", function() { return vec3_mul; });
+__webpack_require__.d(vec3_namespaceObject, "div", function() { return div; });
+__webpack_require__.d(vec3_namespaceObject, "dist", function() { return dist; });
+__webpack_require__.d(vec3_namespaceObject, "sqrDist", function() { return sqrDist; });
+__webpack_require__.d(vec3_namespaceObject, "len", function() { return vec3_len; });
+__webpack_require__.d(vec3_namespaceObject, "sqrLen", function() { return sqrLen; });
+__webpack_require__.d(vec3_namespaceObject, "forEach", function() { return forEach; });
+var vec4_namespaceObject = {};
+__webpack_require__.r(vec4_namespaceObject);
+__webpack_require__.d(vec4_namespaceObject, "create", function() { return vec4_create; });
+__webpack_require__.d(vec4_namespaceObject, "clone", function() { return vec4_clone; });
+__webpack_require__.d(vec4_namespaceObject, "fromValues", function() { return vec4_fromValues; });
+__webpack_require__.d(vec4_namespaceObject, "copy", function() { return vec4_copy; });
+__webpack_require__.d(vec4_namespaceObject, "set", function() { return vec4_set; });
+__webpack_require__.d(vec4_namespaceObject, "add", function() { return vec4_add; });
+__webpack_require__.d(vec4_namespaceObject, "subtract", function() { return vec4_subtract; });
+__webpack_require__.d(vec4_namespaceObject, "multiply", function() { return vec4_multiply; });
+__webpack_require__.d(vec4_namespaceObject, "divide", function() { return vec4_divide; });
+__webpack_require__.d(vec4_namespaceObject, "ceil", function() { return vec4_ceil; });
+__webpack_require__.d(vec4_namespaceObject, "floor", function() { return vec4_floor; });
+__webpack_require__.d(vec4_namespaceObject, "min", function() { return vec4_min; });
+__webpack_require__.d(vec4_namespaceObject, "max", function() { return vec4_max; });
+__webpack_require__.d(vec4_namespaceObject, "round", function() { return vec4_round; });
+__webpack_require__.d(vec4_namespaceObject, "scale", function() { return vec4_scale; });
+__webpack_require__.d(vec4_namespaceObject, "scaleAndAdd", function() { return vec4_scaleAndAdd; });
+__webpack_require__.d(vec4_namespaceObject, "distance", function() { return vec4_distance; });
+__webpack_require__.d(vec4_namespaceObject, "squaredDistance", function() { return vec4_squaredDistance; });
+__webpack_require__.d(vec4_namespaceObject, "length", function() { return vec4_length; });
+__webpack_require__.d(vec4_namespaceObject, "squaredLength", function() { return vec4_squaredLength; });
+__webpack_require__.d(vec4_namespaceObject, "negate", function() { return vec4_negate; });
+__webpack_require__.d(vec4_namespaceObject, "inverse", function() { return vec4_inverse; });
+__webpack_require__.d(vec4_namespaceObject, "normalize", function() { return vec4_normalize; });
+__webpack_require__.d(vec4_namespaceObject, "dot", function() { return vec4_dot; });
+__webpack_require__.d(vec4_namespaceObject, "lerp", function() { return vec4_lerp; });
+__webpack_require__.d(vec4_namespaceObject, "random", function() { return vec4_random; });
+__webpack_require__.d(vec4_namespaceObject, "transformMat4", function() { return vec4_transformMat4; });
+__webpack_require__.d(vec4_namespaceObject, "transformQuat", function() { return vec4_transformQuat; });
+__webpack_require__.d(vec4_namespaceObject, "str", function() { return vec4_str; });
+__webpack_require__.d(vec4_namespaceObject, "exactEquals", function() { return vec4_exactEquals; });
+__webpack_require__.d(vec4_namespaceObject, "equals", function() { return vec4_equals; });
+__webpack_require__.d(vec4_namespaceObject, "sub", function() { return vec4_sub; });
+__webpack_require__.d(vec4_namespaceObject, "mul", function() { return vec4_mul; });
+__webpack_require__.d(vec4_namespaceObject, "div", function() { return vec4_div; });
+__webpack_require__.d(vec4_namespaceObject, "dist", function() { return vec4_dist; });
+__webpack_require__.d(vec4_namespaceObject, "sqrDist", function() { return vec4_sqrDist; });
+__webpack_require__.d(vec4_namespaceObject, "len", function() { return vec4_len; });
+__webpack_require__.d(vec4_namespaceObject, "sqrLen", function() { return vec4_sqrLen; });
+__webpack_require__.d(vec4_namespaceObject, "forEach", function() { return vec4_forEach; });
+var quat_namespaceObject = {};
+__webpack_require__.r(quat_namespaceObject);
+__webpack_require__.d(quat_namespaceObject, "create", function() { return quat_create; });
+__webpack_require__.d(quat_namespaceObject, "identity", function() { return quat_identity; });
+__webpack_require__.d(quat_namespaceObject, "setAxisAngle", function() { return setAxisAngle; });
+__webpack_require__.d(quat_namespaceObject, "getAxisAngle", function() { return getAxisAngle; });
+__webpack_require__.d(quat_namespaceObject, "multiply", function() { return quat_multiply; });
+__webpack_require__.d(quat_namespaceObject, "rotateX", function() { return quat_rotateX; });
+__webpack_require__.d(quat_namespaceObject, "rotateY", function() { return quat_rotateY; });
+__webpack_require__.d(quat_namespaceObject, "rotateZ", function() { return quat_rotateZ; });
+__webpack_require__.d(quat_namespaceObject, "calculateW", function() { return calculateW; });
+__webpack_require__.d(quat_namespaceObject, "slerp", function() { return slerp; });
+__webpack_require__.d(quat_namespaceObject, "random", function() { return quat_random; });
+__webpack_require__.d(quat_namespaceObject, "invert", function() { return quat_invert; });
+__webpack_require__.d(quat_namespaceObject, "conjugate", function() { return conjugate; });
+__webpack_require__.d(quat_namespaceObject, "fromMat3", function() { return fromMat3; });
+__webpack_require__.d(quat_namespaceObject, "fromEuler", function() { return fromEuler; });
+__webpack_require__.d(quat_namespaceObject, "str", function() { return quat_str; });
+__webpack_require__.d(quat_namespaceObject, "clone", function() { return quat_clone; });
+__webpack_require__.d(quat_namespaceObject, "fromValues", function() { return quat_fromValues; });
+__webpack_require__.d(quat_namespaceObject, "copy", function() { return quat_copy; });
+__webpack_require__.d(quat_namespaceObject, "set", function() { return quat_set; });
+__webpack_require__.d(quat_namespaceObject, "add", function() { return quat_add; });
+__webpack_require__.d(quat_namespaceObject, "mul", function() { return quat_mul; });
+__webpack_require__.d(quat_namespaceObject, "scale", function() { return quat_scale; });
+__webpack_require__.d(quat_namespaceObject, "dot", function() { return quat_dot; });
+__webpack_require__.d(quat_namespaceObject, "lerp", function() { return quat_lerp; });
+__webpack_require__.d(quat_namespaceObject, "length", function() { return quat_length; });
+__webpack_require__.d(quat_namespaceObject, "len", function() { return quat_len; });
+__webpack_require__.d(quat_namespaceObject, "squaredLength", function() { return quat_squaredLength; });
+__webpack_require__.d(quat_namespaceObject, "sqrLen", function() { return quat_sqrLen; });
+__webpack_require__.d(quat_namespaceObject, "normalize", function() { return quat_normalize; });
+__webpack_require__.d(quat_namespaceObject, "exactEquals", function() { return quat_exactEquals; });
+__webpack_require__.d(quat_namespaceObject, "equals", function() { return quat_equals; });
+__webpack_require__.d(quat_namespaceObject, "rotationTo", function() { return rotationTo; });
+__webpack_require__.d(quat_namespaceObject, "sqlerp", function() { return sqlerp; });
+__webpack_require__.d(quat_namespaceObject, "setAxes", function() { return setAxes; });
+var vec2_namespaceObject = {};
+__webpack_require__.r(vec2_namespaceObject);
+__webpack_require__.d(vec2_namespaceObject, "create", function() { return vec2_create; });
+__webpack_require__.d(vec2_namespaceObject, "clone", function() { return vec2_clone; });
+__webpack_require__.d(vec2_namespaceObject, "fromValues", function() { return vec2_fromValues; });
+__webpack_require__.d(vec2_namespaceObject, "copy", function() { return vec2_copy; });
+__webpack_require__.d(vec2_namespaceObject, "set", function() { return vec2_set; });
+__webpack_require__.d(vec2_namespaceObject, "add", function() { return vec2_add; });
+__webpack_require__.d(vec2_namespaceObject, "subtract", function() { return vec2_subtract; });
+__webpack_require__.d(vec2_namespaceObject, "multiply", function() { return vec2_multiply; });
+__webpack_require__.d(vec2_namespaceObject, "divide", function() { return vec2_divide; });
+__webpack_require__.d(vec2_namespaceObject, "ceil", function() { return vec2_ceil; });
+__webpack_require__.d(vec2_namespaceObject, "floor", function() { return vec2_floor; });
+__webpack_require__.d(vec2_namespaceObject, "min", function() { return vec2_min; });
+__webpack_require__.d(vec2_namespaceObject, "max", function() { return vec2_max; });
+__webpack_require__.d(vec2_namespaceObject, "round", function() { return vec2_round; });
+__webpack_require__.d(vec2_namespaceObject, "scale", function() { return vec2_scale; });
+__webpack_require__.d(vec2_namespaceObject, "scaleAndAdd", function() { return vec2_scaleAndAdd; });
+__webpack_require__.d(vec2_namespaceObject, "distance", function() { return vec2_distance; });
+__webpack_require__.d(vec2_namespaceObject, "squaredDistance", function() { return vec2_squaredDistance; });
+__webpack_require__.d(vec2_namespaceObject, "length", function() { return vec2_length; });
+__webpack_require__.d(vec2_namespaceObject, "squaredLength", function() { return vec2_squaredLength; });
+__webpack_require__.d(vec2_namespaceObject, "negate", function() { return vec2_negate; });
+__webpack_require__.d(vec2_namespaceObject, "inverse", function() { return vec2_inverse; });
+__webpack_require__.d(vec2_namespaceObject, "normalize", function() { return vec2_normalize; });
+__webpack_require__.d(vec2_namespaceObject, "dot", function() { return vec2_dot; });
+__webpack_require__.d(vec2_namespaceObject, "cross", function() { return vec2_cross; });
+__webpack_require__.d(vec2_namespaceObject, "lerp", function() { return vec2_lerp; });
+__webpack_require__.d(vec2_namespaceObject, "random", function() { return vec2_random; });
+__webpack_require__.d(vec2_namespaceObject, "transformMat2", function() { return transformMat2; });
+__webpack_require__.d(vec2_namespaceObject, "transformMat2d", function() { return transformMat2d; });
+__webpack_require__.d(vec2_namespaceObject, "transformMat3", function() { return vec2_transformMat3; });
+__webpack_require__.d(vec2_namespaceObject, "transformMat4", function() { return vec2_transformMat4; });
+__webpack_require__.d(vec2_namespaceObject, "rotate", function() { return vec2_rotate; });
+__webpack_require__.d(vec2_namespaceObject, "angle", function() { return vec2_angle; });
+__webpack_require__.d(vec2_namespaceObject, "str", function() { return vec2_str; });
+__webpack_require__.d(vec2_namespaceObject, "exactEquals", function() { return vec2_exactEquals; });
+__webpack_require__.d(vec2_namespaceObject, "equals", function() { return vec2_equals; });
+__webpack_require__.d(vec2_namespaceObject, "len", function() { return vec2_len; });
+__webpack_require__.d(vec2_namespaceObject, "sub", function() { return vec2_sub; });
+__webpack_require__.d(vec2_namespaceObject, "mul", function() { return vec2_mul; });
+__webpack_require__.d(vec2_namespaceObject, "div", function() { return vec2_div; });
+__webpack_require__.d(vec2_namespaceObject, "dist", function() { return vec2_dist; });
+__webpack_require__.d(vec2_namespaceObject, "sqrDist", function() { return vec2_sqrDist; });
+__webpack_require__.d(vec2_namespaceObject, "sqrLen", function() { return vec2_sqrLen; });
+__webpack_require__.d(vec2_namespaceObject, "forEach", function() { return vec2_forEach; });
+
+// CONCATENATED MODULE: ./global/math/num.js
+const num = {};
+/**
+ * biCumulative
+ *
+ * @param {number} t
+ * @param {number} order
+ * @returns {number}
+ */
+
+num.biCumulative = function (t, order) {
+ if (order === 1) {
+ const some = 1.0 - t;
+ return 1.0 - some * some * some;
+ } else if (order === 2) {
+ return 3.0 * t * t - 2.0 * t * t * t;
+ } else {
+ return t * t * t;
+ }
+};
/**
- * Returns whether or not the matrices have approximately the same elements in the same position.
+ * Converts a Dword to Float
+ * @param value
+ * @return {Number}
+ */
+
+
+num.dwordToFloat = function (value) {
+ const b4 = value & 0xff,
+ b3 = (value & 0xff00) >> 8,
+ b2 = (value & 0xff0000) >> 16,
+ b1 = (value & 0xff000000) >> 24,
+ sign = 1 - 2 * (b1 >> 7),
+ // sign = bit 0
+ exp = (b1 << 1 & 0xff | b2 >> 7) - 127,
+ // exponent = bits 1..8
+ sig = (b2 & 0x7f) << 16 | b3 << 8 | b4; // significand = bits 9..31
+
+ if (sig === 0 && exp === -127) return 0.0;
+ return sign * (1 + sig * Math.pow(2, -23)) * Math.pow(2, exp);
+};
+/**
+ * Exponential decay
*
- * @param {mat2d} a The first matrix.
- * @param {mat2d} b The second matrix.
- * @returns {Boolean} True if the matrices are equal, false otherwise.
+ * @param {number} omega0
+ * @param {number} torque
+ * @param {number} I - inertia
+ * @param {number} d - drag
+ * @param {number} time - time
+ * @returns {number}
*/
-function equals(a, b) {
- let a0 = a[0], a1 = a[1], a2 = a[2], a3 = a[3], a4 = a[4], a5 = a[5];
- let b0 = b[0], b1 = b[1], b2 = b[2], b3 = b[3], b4 = b[4], b5 = b[5];
- return (Math.abs(a0 - b0) <= __WEBPACK_IMPORTED_MODULE_0__common__["EPSILON"]*Math.max(1.0, Math.abs(a0), Math.abs(b0)) &&
- Math.abs(a1 - b1) <= __WEBPACK_IMPORTED_MODULE_0__common__["EPSILON"]*Math.max(1.0, Math.abs(a1), Math.abs(b1)) &&
- Math.abs(a2 - b2) <= __WEBPACK_IMPORTED_MODULE_0__common__["EPSILON"]*Math.max(1.0, Math.abs(a2), Math.abs(b2)) &&
- Math.abs(a3 - b3) <= __WEBPACK_IMPORTED_MODULE_0__common__["EPSILON"]*Math.max(1.0, Math.abs(a3), Math.abs(b3)) &&
- Math.abs(a4 - b4) <= __WEBPACK_IMPORTED_MODULE_0__common__["EPSILON"]*Math.max(1.0, Math.abs(a4), Math.abs(b4)) &&
- Math.abs(a5 - b5) <= __WEBPACK_IMPORTED_MODULE_0__common__["EPSILON"]*Math.max(1.0, Math.abs(a5), Math.abs(b5)));
-}
+
+num.exponentialDecay = function (omega0, torque, I, d, time) {
+ return torque * time / d + I * (omega0 * d - torque) / (d * d) * (1.0 - Math.pow(Math.E, -d * time / I));
+};
/**
- * Alias for {@link mat2d.multiply}
- * @function
+ * Gets a value from a half float
+ * @author Babylon
+ * @param {number} a
+ * @returns {number}
*/
-const mul = multiply;
-/* harmony export (immutable) */ __webpack_exports__["mul"] = mul;
+num.fromHalfFloat = function (a) {
+ const s = (a & 0x8000) >> 15,
+ e = (a & 0x7C00) >> 10,
+ f = a & 0x03FF;
+
+ if (e === 0) {
+ return (s ? -1 : 1) * Math.pow(2, -14) * (f / Math.pow(2, 10));
+ } else if (e === 0x1F) {
+ return f ? NaN : (s ? -1 : 1) * Infinity;
+ }
+
+ return (s ? -1 : 1) * Math.pow(2, e - 15) * (1 + f / Math.pow(2, 10));
+};
/**
- * Alias for {@link mat2d.subtract}
- * @function
+ * Gets long word order
+ * @author Babylon
+ * @param {number} a
+ * @returns {number}
*/
-const sub = subtract;
-/* harmony export (immutable) */ __webpack_exports__["sub"] = sub;
+num.getLongWordOrder = function (a) {
+ return a === 0 || a === 255 || a === -16777216 ? 0 : 1 + num.getLongWordOrder(a >> 8);
+};
+/**
+ * Gets the log2 of a number
+ * @param {number} a
+ * @returns {number}
+ */
-/***/ }),
-/* 69 */
-/***/ (function(module, __webpack_exports__, __webpack_require__) {
-"use strict";
-Object.defineProperty(__webpack_exports__, "__esModule", { value: true });
-/* harmony export (immutable) */ __webpack_exports__["create"] = create;
-/* harmony export (immutable) */ __webpack_exports__["clone"] = clone;
-/* harmony export (immutable) */ __webpack_exports__["copy"] = copy;
-/* harmony export (immutable) */ __webpack_exports__["fromValues"] = fromValues;
-/* harmony export (immutable) */ __webpack_exports__["set"] = set;
-/* harmony export (immutable) */ __webpack_exports__["identity"] = identity;
-/* harmony export (immutable) */ __webpack_exports__["transpose"] = transpose;
-/* harmony export (immutable) */ __webpack_exports__["invert"] = invert;
-/* harmony export (immutable) */ __webpack_exports__["adjoint"] = adjoint;
-/* harmony export (immutable) */ __webpack_exports__["determinant"] = determinant;
-/* harmony export (immutable) */ __webpack_exports__["multiply"] = multiply;
-/* harmony export (immutable) */ __webpack_exports__["translate"] = translate;
-/* harmony export (immutable) */ __webpack_exports__["scale"] = scale;
-/* harmony export (immutable) */ __webpack_exports__["rotate"] = rotate;
-/* harmony export (immutable) */ __webpack_exports__["rotateX"] = rotateX;
-/* harmony export (immutable) */ __webpack_exports__["rotateY"] = rotateY;
-/* harmony export (immutable) */ __webpack_exports__["rotateZ"] = rotateZ;
-/* harmony export (immutable) */ __webpack_exports__["fromTranslation"] = fromTranslation;
-/* harmony export (immutable) */ __webpack_exports__["fromScaling"] = fromScaling;
-/* harmony export (immutable) */ __webpack_exports__["fromRotation"] = fromRotation;
-/* harmony export (immutable) */ __webpack_exports__["fromXRotation"] = fromXRotation;
-/* harmony export (immutable) */ __webpack_exports__["fromYRotation"] = fromYRotation;
-/* harmony export (immutable) */ __webpack_exports__["fromZRotation"] = fromZRotation;
-/* harmony export (immutable) */ __webpack_exports__["fromRotationTranslation"] = fromRotationTranslation;
-/* harmony export (immutable) */ __webpack_exports__["getTranslation"] = getTranslation;
-/* harmony export (immutable) */ __webpack_exports__["getScaling"] = getScaling;
-/* harmony export (immutable) */ __webpack_exports__["getRotation"] = getRotation;
-/* harmony export (immutable) */ __webpack_exports__["fromRotationTranslationScale"] = fromRotationTranslationScale;
-/* harmony export (immutable) */ __webpack_exports__["fromRotationTranslationScaleOrigin"] = fromRotationTranslationScaleOrigin;
-/* harmony export (immutable) */ __webpack_exports__["fromQuat"] = fromQuat;
-/* harmony export (immutable) */ __webpack_exports__["frustum"] = frustum;
-/* harmony export (immutable) */ __webpack_exports__["perspective"] = perspective;
-/* harmony export (immutable) */ __webpack_exports__["perspectiveFromFieldOfView"] = perspectiveFromFieldOfView;
-/* harmony export (immutable) */ __webpack_exports__["ortho"] = ortho;
-/* harmony export (immutable) */ __webpack_exports__["lookAt"] = lookAt;
-/* harmony export (immutable) */ __webpack_exports__["targetTo"] = targetTo;
-/* harmony export (immutable) */ __webpack_exports__["str"] = str;
-/* harmony export (immutable) */ __webpack_exports__["frob"] = frob;
-/* harmony export (immutable) */ __webpack_exports__["add"] = add;
-/* harmony export (immutable) */ __webpack_exports__["subtract"] = subtract;
-/* harmony export (immutable) */ __webpack_exports__["multiplyScalar"] = multiplyScalar;
-/* harmony export (immutable) */ __webpack_exports__["multiplyScalarAndAdd"] = multiplyScalarAndAdd;
-/* harmony export (immutable) */ __webpack_exports__["exactEquals"] = exactEquals;
-/* harmony export (immutable) */ __webpack_exports__["equals"] = equals;
-/* harmony import */ var __WEBPACK_IMPORTED_MODULE_0__common__ = __webpack_require__(5);
-/* 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. */
-
-
-
-/**
- * 4x4 Matrix
- * @module mat4
+num.log2 = function (a) {
+ return Math.log(a) * Math.LOG2E;
+};
+/**
+ * Converts a number to a half float
+ * @author http://stackoverflow.com/questions/32633585/how-do-you-convert-to-half-floats-in-javascript
+ * @param {number} a
+ * @returns {number}
*/
+
+num.toHalfFloat = function () {
+ let floatView, int32View;
+ return function (a) {
+ if (!floatView) {
+ floatView = new Float32Array(1);
+ int32View = new Int32Array(floatView.buffer);
+ }
+
+ floatView[0] = a;
+ const x = int32View[0];
+ let bits = x >> 16 & 0x8000;
+ /* Get the sign */
+
+ let m = x >> 12 & 0x07ff;
+ /* Keep one extra bit for rounding */
+
+ let e = x >> 23 & 0xff;
+ /* Using int is faster here */
+
+ /* If zero, or denormal, or exponent underflows too much for a denormal half, return signed zero. */
+
+ if (e < 103) {
+ return bits;
+ }
+ /* If NaN, return NaN. If Inf or exponent overflow, return Inf. */
+
+
+ if (e > 142) {
+ bits |= 0x7c00;
+ /* If exponent was 0xff and one mantissa bit was set, it means NaN,
+ * not Inf, so make sure we set one mantissa bit too. */
+
+ bits |= (e === 255 ? 0 : 1) && x & 0x007fffff;
+ return bits;
+ }
+ /* If exponent underflows but not too much, return a denormal */
+
+
+ if (e < 113) {
+ m |= 0x0800;
+ /* Extra rounding may overflow and set mantissa to 0 and exponent to 1, which is OK. */
+
+ bits |= (m >> 114 - e) + (m >> 113 - e & 1);
+ return bits;
+ }
+
+ bits |= e - 112 << 10 | m >> 1;
+ /* Extra rounding. An overflow will set mantissa to 0 and increment the exponent, which is OK. */
+
+ bits += m & 1;
+ return bits;
+ };
+}();
+// CONCATENATED MODULE: ../node_modules/gl-matrix/lib/gl-matrix/common.js
/**
- * Creates a new identity mat4
+ * Common utilities
+ * @module glMatrix
+ */
+
+// Configuration Constants
+var EPSILON = 0.000001;
+var ARRAY_TYPE = typeof Float32Array !== 'undefined' ? Float32Array : Array;
+var RANDOM = Math.random;
+
+/**
+ * Sets the type of array used when creating new vectors and matrices
*
- * @returns {mat4} a new 4x4 matrix
+ * @param {Type} type Array type, such as Float32Array or Array
+ */
+function setMatrixArrayType(type) {
+ ARRAY_TYPE = type;
+}
+
+var degree = Math.PI / 180;
+
+/**
+ * Convert Degree To Radian
+ *
+ * @param {Number} a Angle in Degrees
+ */
+function toRadian(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.
+ */
+function equals(a, b) {
+ return Math.abs(a - b) <= EPSILON * Math.max(1.0, Math.abs(a), Math.abs(b));
+}
+// CONCATENATED MODULE: ../node_modules/gl-matrix/lib/gl-matrix/mat3.js
+
+
+/**
+ * 3x3 Matrix
+ * @module mat3
+ */
+
+/**
+ * Creates a new identity mat3
+ *
+ * @returns {mat3} a new 3x3 matrix
*/
function create() {
- let out = new __WEBPACK_IMPORTED_MODULE_0__common__["ARRAY_TYPE"](16);
+ var out = new ARRAY_TYPE(9);
+ if (ARRAY_TYPE != Float32Array) {
+ out[1] = 0;
+ out[2] = 0;
+ out[3] = 0;
+ out[5] = 0;
+ out[6] = 0;
+ out[7] = 0;
+ }
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;
+ out[4] = 1;
+ out[8] = 1;
return out;
}
/**
- * Creates a new mat4 initialized with values from an existing matrix
+ * Copies the upper-left 3x3 values into the given mat3.
*
- * @param {mat4} a matrix to clone
- * @returns {mat4} a new 4x4 matrix
+ * @param {mat3} out the receiving 3x3 matrix
+ * @param {mat4} a the source 4x4 matrix
+ * @returns {mat3} out
+ */
+function fromMat4(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
*/
function clone(a) {
- let out = new __WEBPACK_IMPORTED_MODULE_0__common__["ARRAY_TYPE"](16);
+ var out = new ARRAY_TYPE(9);
out[0] = a[0];
out[1] = a[1];
out[2] = a[2];
@@ -14419,22 +12995,15 @@ function clone(a) {
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
+ * Copy the values from one mat3 to another
*
- * @param {mat4} out the receiving matrix
- * @param {mat4} a the source matrix
- * @returns {mat4} out
+ * @param {mat3} out the receiving matrix
+ * @param {mat3} a the source matrix
+ * @returns {mat3} out
*/
function copy(out, a) {
out[0] = a[0];
@@ -14446,618 +13015,399 @@ function copy(out, a) {
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
+ * 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} 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
+ * @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
*/
-function fromValues(m00, m01, m02, m03, m10, m11, m12, m13, m20, m21, m22, m23, m30, m31, m32, m33) {
- let out = new __WEBPACK_IMPORTED_MODULE_0__common__["ARRAY_TYPE"](16);
+function fromValues(m00, m01, m02, m10, m11, m12, m20, m21, m22) {
+ var out = new ARRAY_TYPE(9);
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;
+ 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 mat4 to the given values
+ * Set the components of a mat3 to the given values
*
- * @param {mat4} out the receiving matrix
+ * @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} 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
+ * @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
*/
-function set(out, m00, m01, m02, m03, m10, m11, m12, m13, m20, m21, m22, m23, m30, m31, m32, m33) {
+function set(out, m00, m01, m02, m10, m11, m12, m20, m21, m22) {
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;
+ out[3] = m10;
+ out[4] = m11;
+ out[5] = m12;
+ out[6] = m20;
+ out[7] = m21;
+ out[8] = m22;
return out;
}
-
/**
- * Set a mat4 to the identity matrix
+ * Set a mat3 to the identity matrix
*
- * @param {mat4} out the receiving matrix
- * @returns {mat4} out
+ * @param {mat3} out the receiving matrix
+ * @returns {mat3} out
*/
function identity(out) {
out[0] = 1;
out[1] = 0;
out[2] = 0;
out[3] = 0;
- out[4] = 0;
- out[5] = 1;
+ out[4] = 1;
+ out[5] = 0;
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;
+ out[8] = 1;
return out;
}
/**
- * Transpose the values of a mat4
+ * Transpose the values of a mat3
*
- * @param {mat4} out the receiving matrix
- * @param {mat4} a the source matrix
- * @returns {mat4} out
+ * @param {mat3} out the receiving matrix
+ * @param {mat3} a the source matrix
+ * @returns {mat3} out
*/
function transpose(out, a) {
// If we are transposing ourselves we can skip a few steps but have to cache some values
if (out === a) {
- let a01 = a[1], a02 = a[2], a03 = a[3];
- let a12 = a[6], a13 = a[7];
- let 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;
+ 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[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];
+ 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 mat4
+ * Inverts a mat3
*
- * @param {mat4} out the receiving matrix
- * @param {mat4} a the source matrix
- * @returns {mat4} out
+ * @param {mat3} out the receiving matrix
+ * @param {mat3} a the source matrix
+ * @returns {mat3} out
*/
function invert(out, a) {
- let a00 = a[0], a01 = a[1], a02 = a[2], a03 = a[3];
- let a10 = a[4], a11 = a[5], a12 = a[6], a13 = a[7];
- let a20 = a[8], a21 = a[9], a22 = a[10], a23 = a[11];
- let a30 = a[12], a31 = a[13], a32 = a[14], a33 = a[15];
-
- let b00 = a00 * a11 - a01 * a10;
- let b01 = a00 * a12 - a02 * a10;
- let b02 = a00 * a13 - a03 * a10;
- let b03 = a01 * a12 - a02 * a11;
- let b04 = a01 * a13 - a03 * a11;
- let b05 = a02 * a13 - a03 * a12;
- let b06 = a20 * a31 - a21 * a30;
- let b07 = a20 * a32 - a22 * a30;
- let b08 = a20 * a33 - a23 * a30;
- let b09 = a21 * a32 - a22 * a31;
- let b10 = a21 * a33 - a23 * a31;
- let b11 = a22 * a33 - a23 * a32;
+ var a00 = a[0],
+ a01 = a[1],
+ a02 = a[2];
+ var a10 = a[3],
+ a11 = a[4],
+ a12 = a[5];
+ var a20 = a[6],
+ a21 = a[7],
+ a22 = a[8];
+
+ var b01 = a22 * a11 - a12 * a21;
+ var b11 = -a22 * a10 + a12 * a20;
+ var b21 = a21 * a10 - a11 * a20;
// Calculate the determinant
- let det = b00 * b11 - b01 * b10 + b02 * b09 + b03 * b08 - b04 * b07 + b05 * b06;
+ var det = a00 * b01 + a01 * b11 + a02 * b21;
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;
-
+ 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 mat4
+ * Calculates the adjugate of a mat3
*
- * @param {mat4} out the receiving matrix
- * @param {mat4} a the source matrix
- * @returns {mat4} out
+ * @param {mat3} out the receiving matrix
+ * @param {mat3} a the source matrix
+ * @returns {mat3} out
*/
function adjoint(out, a) {
- let a00 = a[0], a01 = a[1], a02 = a[2], a03 = a[3];
- let a10 = a[4], a11 = a[5], a12 = a[6], a13 = a[7];
- let a20 = a[8], a21 = a[9], a22 = a[10], a23 = a[11];
- let 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));
+ var a00 = a[0],
+ a01 = a[1],
+ a02 = a[2];
+ var a10 = a[3],
+ a11 = a[4],
+ a12 = a[5];
+ var 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 mat4
+ * Calculates the determinant of a mat3
*
- * @param {mat4} a the source matrix
+ * @param {mat3} a the source matrix
* @returns {Number} determinant of a
*/
function determinant(a) {
- let a00 = a[0], a01 = a[1], a02 = a[2], a03 = a[3];
- let a10 = a[4], a11 = a[5], a12 = a[6], a13 = a[7];
- let a20 = a[8], a21 = a[9], a22 = a[10], a23 = a[11];
- let a30 = a[12], a31 = a[13], a32 = a[14], a33 = a[15];
-
- let b00 = a00 * a11 - a01 * a10;
- let b01 = a00 * a12 - a02 * a10;
- let b02 = a00 * a13 - a03 * a10;
- let b03 = a01 * a12 - a02 * a11;
- let b04 = a01 * a13 - a03 * a11;
- let b05 = a02 * a13 - a03 * a12;
- let b06 = a20 * a31 - a21 * a30;
- let b07 = a20 * a32 - a22 * a30;
- let b08 = a20 * a33 - a23 * a30;
- let b09 = a21 * a32 - a22 * a31;
- let b10 = a21 * a33 - a23 * a31;
- let b11 = a22 * a33 - a23 * a32;
+ var a00 = a[0],
+ a01 = a[1],
+ a02 = a[2];
+ var a10 = a[3],
+ a11 = a[4],
+ a12 = a[5];
+ var a20 = a[6],
+ a21 = a[7],
+ a22 = a[8];
- // Calculate the determinant
- return b00 * b11 - b01 * b10 + b02 * b09 + b03 * b08 - b04 * b07 + b05 * b06;
+ return a00 * (a22 * a11 - a12 * a21) + a01 * (-a22 * a10 + a12 * a20) + a02 * (a21 * a10 - a11 * a20);
}
/**
- * Multiplies two mat4s
+ * Multiplies two mat3's
*
- * @param {mat4} out the receiving matrix
- * @param {mat4} a the first operand
- * @param {mat4} b the second operand
- * @returns {mat4} out
+ * @param {mat3} out the receiving matrix
+ * @param {mat3} a the first operand
+ * @param {mat3} b the second operand
+ * @returns {mat3} out
*/
function multiply(out, a, b) {
- let a00 = a[0], a01 = a[1], a02 = a[2], a03 = a[3];
- let a10 = a[4], a11 = a[5], a12 = a[6], a13 = a[7];
- let a20 = a[8], a21 = a[9], a22 = a[10], a23 = a[11];
- let a30 = a[12], a31 = a[13], a32 = a[14], a33 = a[15];
+ var a00 = a[0],
+ a01 = a[1],
+ a02 = a[2];
+ var a10 = a[3],
+ a11 = a[4],
+ a12 = a[5];
+ var a20 = a[6],
+ a21 = a[7],
+ a22 = a[8];
+
+ var b00 = b[0],
+ b01 = b[1],
+ b02 = b[2];
+ var b10 = b[3],
+ b11 = b[4],
+ b12 = b[5];
+ var b20 = b[6],
+ b21 = b[7],
+ b22 = b[8];
- // Cache only the current line of the second matrix
- let 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;
+ 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;
}
/**
- * Translate a mat4 by the given vector
+ * Translate a mat3 by the given vector
*
- * @param {mat4} out the receiving matrix
- * @param {mat4} a the matrix to translate
- * @param {vec3} v vector to translate by
- * @returns {mat4} out
+ * @param {mat3} out the receiving matrix
+ * @param {mat3} a the matrix to translate
+ * @param {vec2} v vector to translate by
+ * @returns {mat3} out
*/
function translate(out, a, v) {
- let x = v[0], y = v[1], z = v[2];
- let a00, a01, a02, a03;
- let a10, a11, a12, a13;
- let 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];
+ 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] = 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[0] = a00;
+ out[1] = a01;
+ out[2] = a02;
- 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];
- }
+ 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;
}
/**
- * Scales the mat4 by the dimensions in the given vec3 not using vectorization
+ * Rotates a mat3 by the given angle
*
- * @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
- **/
-function scale(out, a, v) {
- let 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;
-}
-
-/**
- * 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 {mat3} out the receiving matrix
+ * @param {mat3} 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
+ * @returns {mat3} out
*/
-function rotate(out, a, rad, axis) {
- let x = axis[0], y = axis[1], z = axis[2];
- let len = Math.sqrt(x * x + y * y + z * z);
- let s, c, t;
- let a00, a01, a02, a03;
- let a10, a11, a12, a13;
- let a20, a21, a22, a23;
- let b00, b01, b02;
- let b10, b11, b12;
- let b20, b21, b22;
-
- if (Math.abs(len) < __WEBPACK_IMPORTED_MODULE_0__common__["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];
+function rotate(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);
- // 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;
+ out[0] = c * a00 + s * a10;
+ out[1] = c * a01 + s * a11;
+ out[2] = c * a02 + s * a12;
- // 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;
+ out[3] = c * a10 - s * a00;
+ out[4] = c * a11 - s * a01;
+ out[5] = c * a12 - s * a02;
- 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];
- }
+ out[6] = a20;
+ out[7] = a21;
+ out[8] = a22;
return out;
-}
+};
/**
- * Rotates a matrix by the given angle around the X axis
+ * Scales the mat3 by the dimensions in the given vec2
*
- * @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
- */
-function rotateX(out, a, rad) {
- let s = Math.sin(rad);
- let c = Math.cos(rad);
- let a10 = a[4];
- let a11 = a[5];
- let a12 = a[6];
- let a13 = a[7];
- let a20 = a[8];
- let a21 = a[9];
- let a22 = a[10];
- let 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];
- }
+ * @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
+ **/
+function mat3_scale(out, a, v) {
+ var x = v[0],
+ y = v[1];
- // 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;
-}
+ out[0] = x * a[0];
+ out[1] = x * a[1];
+ out[2] = x * a[2];
-/**
- * Rotates a matrix by the given angle around the Y axis
- *
- * @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
- */
-function rotateY(out, a, rad) {
- let s = Math.sin(rad);
- let c = Math.cos(rad);
- let a00 = a[0];
- let a01 = a[1];
- let a02 = a[2];
- let a03 = a[3];
- let a20 = a[8];
- let a21 = a[9];
- let a22 = a[10];
- let 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];
- }
+ out[3] = y * a[3];
+ out[4] = y * a[4];
+ out[5] = y * a[5];
- // 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;
+ out[6] = a[6];
+ out[7] = a[7];
+ out[8] = a[8];
return out;
}
/**
- * Rotates a matrix by the given angle around the Z axis
+ * Creates a matrix from a vector translation
+ * This is equivalent to (but much faster than):
*
- * @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
+ * mat3.identity(dest);
+ * mat3.translate(dest, dest, vec);
+ *
+ * @param {mat3} out mat3 receiving operation result
+ * @param {vec2} v Translation vector
+ * @returns {mat3} out
*/
-function rotateZ(out, a, rad) {
- let s = Math.sin(rad);
- let c = Math.cos(rad);
- let a00 = a[0];
- let a01 = a[1];
- let a02 = a[2];
- let a03 = a[3];
- let a10 = a[4];
- let a11 = a[5];
- let a12 = a[6];
- let 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;
+function fromTranslation(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 vector translation
+ * Creates a matrix from a given angle
* This is equivalent to (but much faster than):
*
- * mat4.identity(dest);
- * mat4.translate(dest, dest, vec);
+ * mat3.identity(dest);
+ * mat3.rotate(dest, dest, rad);
*
- * @param {mat4} out mat4 receiving operation result
- * @param {vec3} v Translation vector
- * @returns {mat4} out
+ * @param {mat3} out mat3 receiving operation result
+ * @param {Number} rad the angle to rotate the matrix by
+ * @returns {mat3} out
*/
-function fromTranslation(out, v) {
- out[0] = 1;
- out[1] = 0;
+function fromRotation(out, rad) {
+ var s = Math.sin(rad),
+ c = Math.cos(rad);
+
+ out[0] = c;
+ out[1] = s;
out[2] = 0;
- out[3] = 0;
- out[4] = 0;
- out[5] = 1;
+
+ out[3] = -s;
+ out[4] = c;
+ out[5] = 0;
+
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;
+ out[8] = 1;
return out;
}
@@ -15065,27210 +13415,29669 @@ function fromTranslation(out, v) {
* Creates a matrix from a vector scaling
* This is equivalent to (but much faster than):
*
- * mat4.identity(dest);
- * mat4.scale(dest, dest, vec);
+ * mat3.identity(dest);
+ * mat3.scale(dest, dest, vec);
*
- * @param {mat4} out mat4 receiving operation result
- * @param {vec3} v Scaling vector
- * @returns {mat4} out
+ * @param {mat3} out mat3 receiving operation result
+ * @param {vec2} v Scaling vector
+ * @returns {mat3} out
*/
function fromScaling(out, v) {
out[0] = v[0];
out[1] = 0;
out[2] = 0;
+
out[3] = 0;
- out[4] = 0;
- out[5] = v[1];
+ out[4] = v[1];
+ out[5] = 0;
+
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;
+ out[8] = 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);
+ * Copies the values from a mat2d into a mat3
*
- * @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
- */
-function fromRotation(out, rad, axis) {
- let x = axis[0], y = axis[1], z = axis[2];
- let len = Math.sqrt(x * x + y * y + z * z);
- let s, c, t;
-
- if (Math.abs(len) < __WEBPACK_IMPORTED_MODULE_0__common__["EPSILON"]) { return null; }
+ * @param {mat3} out the receiving matrix
+ * @param {mat2d} a the matrix to copy
+ * @returns {mat3} out
+ **/
+function fromMat2d(out, a) {
+ out[0] = a[0];
+ out[1] = a[1];
+ out[2] = 0;
- len = 1 / len;
- x *= len;
- y *= len;
- z *= len;
-
- s = Math.sin(rad);
- c = Math.cos(rad);
- t = 1 - c;
+ out[3] = a[2];
+ out[4] = a[3];
+ out[5] = 0;
- // 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;
+ out[6] = a[4];
+ out[7] = a[5];
+ out[8] = 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
- */
-function fromXRotation(out, rad) {
- let s = Math.sin(rad);
- let c = Math.cos(rad);
+* 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
+*/
+function fromQuat(out, q) {
+ var x = q[0],
+ y = q[1],
+ z = q[2],
+ w = q[3];
+ var x2 = x + x;
+ var y2 = y + y;
+ var z2 = z + z;
+
+ var xx = x * x2;
+ var yx = y * x2;
+ var yy = y * y2;
+ var zx = z * x2;
+ var zy = z * y2;
+ var zz = z * z2;
+ var wx = w * x2;
+ var wy = w * y2;
+ var 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;
- // 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
- */
-function fromYRotation(out, rad) {
- let s = Math.sin(rad);
- let c = Math.cos(rad);
+* 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
+*/
+function normalFromMat4(out, a) {
+ var a00 = a[0],
+ a01 = a[1],
+ a02 = a[2],
+ a03 = a[3];
+ var a10 = a[4],
+ a11 = a[5],
+ a12 = a[6],
+ a13 = a[7];
+ var a20 = a[8],
+ a21 = a[9],
+ a22 = a[10],
+ a23 = a[11];
+ var a30 = a[12],
+ a31 = a[13],
+ a32 = a[14],
+ a33 = a[15];
+
+ var b00 = a00 * a11 - a01 * a10;
+ var b01 = a00 * a12 - a02 * a10;
+ var b02 = a00 * a13 - a03 * a10;
+ var b03 = a01 * a12 - a02 * a11;
+ var b04 = a01 * a13 - a03 * a11;
+ var b05 = a02 * a13 - a03 * a12;
+ var b06 = a20 * a31 - a21 * a30;
+ var b07 = a20 * a32 - a22 * a30;
+ var b08 = a20 * a33 - a23 * a30;
+ var b09 = a21 * a32 - a22 * a31;
+ var b10 = a21 * a33 - a23 * a31;
+ var b11 = a22 * a33 - a23 * a32;
+
+ // Calculate the determinant
+ var 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;
- // 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);
+ * Generates a 2D projection matrix with the given bounds
*
- * @param {mat4} out mat4 receiving operation result
- * @param {Number} rad the angle to rotate the matrix by
- * @returns {mat4} out
+ * @param {mat3} out mat3 frustum matrix will be written into
+ * @param {number} width Width of your gl context
+ * @param {number} height Height of gl context
+ * @returns {mat3} out
*/
-function fromZRotation(out, rad) {
- let s = Math.sin(rad);
- let 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;
+function projection(out, width, height) {
+ out[0] = 2 / width;
+ out[1] = 0;
+ out[2] = 0;
+ out[3] = 0;
+ out[4] = -2 / height;
+ out[5] = 0;
+ out[6] = -1;
+ out[7] = 1;
+ out[8] = 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);
- * let quatMat = mat4.create();
- * quat4.toMat4(quat, quatMat);
- * mat4.multiply(dest, quatMat);
+ * Returns a string representation of a mat3
*
- * @param {mat4} out mat4 receiving operation result
- * @param {quat4} q Rotation quaternion
- * @param {vec3} v Translation vector
- * @returns {mat4} out
+ * @param {mat3} a matrix to represent as a string
+ * @returns {String} string representation of the matrix
*/
-function fromRotationTranslation(out, q, v) {
- // Quaternion math
- let x = q[0], y = q[1], z = q[2], w = q[3];
- let x2 = x + x;
- let y2 = y + y;
- let z2 = z + z;
-
- let xx = x * x2;
- let xy = x * y2;
- let xz = x * z2;
- let yy = y * y2;
- let yz = y * z2;
- let zz = z * z2;
- let wx = w * x2;
- let wy = w * y2;
- let 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;
+function str(a) {
+ return 'mat3(' + a[0] + ', ' + a[1] + ', ' + a[2] + ', ' + a[3] + ', ' + a[4] + ', ' + a[5] + ', ' + a[6] + ', ' + a[7] + ', ' + a[8] + ')';
}
/**
- * 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
+ * Returns Frobenius norm of a mat3
+ *
+ * @param {mat3} a the matrix to calculate Frobenius norm of
+ * @returns {Number} Frobenius norm
*/
-function getTranslation(out, mat) {
- out[0] = mat[12];
- out[1] = mat[13];
- out[2] = mat[14];
-
- return out;
+function frob(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));
}
/**
- * Returns the scaling factor component of a transformation
- * matrix. If a matrix is built with fromRotationTranslationScale
- * with a normalized Quaternion paramter, the returned vector will be
- * the same as the scaling vector
- * originally supplied.
- * @param {vec3} out Vector to receive scaling factor component
- * @param {mat4} mat Matrix to be decomposed (input)
- * @return {vec3} out
+ * 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
*/
-function getScaling(out, mat) {
- let m11 = mat[0];
- let m12 = mat[1];
- let m13 = mat[2];
- let m21 = mat[4];
- let m22 = mat[5];
- let m23 = mat[6];
- let m31 = mat[8];
- let m32 = mat[9];
- let m33 = mat[10];
-
- out[0] = Math.sqrt(m11 * m11 + m12 * m12 + m13 * m13);
- out[1] = Math.sqrt(m21 * m21 + m22 * m22 + m23 * m23);
- out[2] = Math.sqrt(m31 * m31 + m32 * m32 + m33 * m33);
-
+function add(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;
}
/**
- * 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
- */
-function getRotation(out, mat) {
- // Algorithm taken from http://www.euclideanspace.com/maths/geometry/rotations/conversions/matrixToQuaternion/index.htm
- let trace = mat[0] + mat[5] + mat[10];
- let 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;
- }
-
+ * 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
+ */
+function subtract(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;
}
/**
- * 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);
- * let quatMat = mat4.create();
- * quat4.toMat4(quat, quatMat);
- * mat4.multiply(dest, quatMat);
- * mat4.scale(dest, scale)
+ * Multiply each element of the matrix by a scalar.
*
- * @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
+ * @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
*/
-function fromRotationTranslationScale(out, q, v, s) {
- // Quaternion math
- let x = q[0], y = q[1], z = q[2], w = q[3];
- let x2 = x + x;
- let y2 = y + y;
- let z2 = z + z;
-
- let xx = x * x2;
- let xy = x * y2;
- let xz = x * z2;
- let yy = y * y2;
- let yz = y * z2;
- let zz = z * z2;
- let wx = w * x2;
- let wy = w * y2;
- let wz = w * z2;
- let sx = s[0];
- let sy = s[1];
- let 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;
-
+function multiplyScalar(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;
}
/**
- * 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);
- * let quatMat = mat4.create();
- * quat4.toMat4(quat, quatMat);
- * mat4.multiply(dest, quatMat);
- * mat4.scale(dest, scale)
- * mat4.translate(dest, negativeOrigin);
+ * Adds two mat3's after multiplying each element of the second operand by a scalar value.
*
- * @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
+ * @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
*/
-function fromRotationTranslationScaleOrigin(out, q, v, s, o) {
- // Quaternion math
- let x = q[0], y = q[1], z = q[2], w = q[3];
- let x2 = x + x;
- let y2 = y + y;
- let z2 = z + z;
-
- let xx = x * x2;
- let xy = x * y2;
- let xz = x * z2;
- let yy = y * y2;
- let yz = y * z2;
- let zz = z * z2;
- let wx = w * x2;
- let wy = w * y2;
- let wz = w * z2;
-
- let sx = s[0];
- let sy = s[1];
- let sz = s[2];
-
- let ox = o[0];
- let oy = o[1];
- let 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;
-
+function multiplyScalarAndAdd(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;
}
/**
- * Calculates a 4x4 matrix from the given quaternion
- *
- * @param {mat4} out mat4 receiving operation result
- * @param {quat} q Quaternion to create matrix from
+ * Returns whether or not the matrices have exactly the same elements in the same position (when compared with ===)
*
- * @returns {mat4} out
+ * @param {mat3} a The first matrix.
+ * @param {mat3} b The second matrix.
+ * @returns {Boolean} True if the matrices are equal, false otherwise.
*/
-function fromQuat(out, q) {
- let x = q[0], y = q[1], z = q[2], w = q[3];
- let x2 = x + x;
- let y2 = y + y;
- let z2 = z + z;
-
- let xx = x * x2;
- let yx = y * x2;
- let yy = y * y2;
- let zx = z * x2;
- let zy = z * y2;
- let zz = z * z2;
- let wx = w * x2;
- let wy = w * y2;
- let wz = w * z2;
+function exactEquals(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];
+}
- out[0] = 1 - yy - zz;
- out[1] = yx + wz;
- out[2] = zx - wy;
- out[3] = 0;
+/**
+ * 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.
+ */
+function mat3_equals(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 = b[6],
+ b7 = b[7],
+ b8 = b[8];
+ return Math.abs(a0 - b0) <= EPSILON * Math.max(1.0, Math.abs(a0), Math.abs(b0)) && Math.abs(a1 - b1) <= EPSILON * Math.max(1.0, Math.abs(a1), Math.abs(b1)) && Math.abs(a2 - b2) <= EPSILON * Math.max(1.0, Math.abs(a2), Math.abs(b2)) && Math.abs(a3 - b3) <= EPSILON * Math.max(1.0, Math.abs(a3), Math.abs(b3)) && Math.abs(a4 - b4) <= EPSILON * Math.max(1.0, Math.abs(a4), Math.abs(b4)) && Math.abs(a5 - b5) <= EPSILON * Math.max(1.0, Math.abs(a5), Math.abs(b5)) && Math.abs(a6 - b6) <= EPSILON * Math.max(1.0, Math.abs(a6), Math.abs(b6)) && Math.abs(a7 - b7) <= EPSILON * Math.max(1.0, Math.abs(a7), Math.abs(b7)) && Math.abs(a8 - b8) <= EPSILON * Math.max(1.0, Math.abs(a8), Math.abs(b8));
+}
- out[4] = yx - wz;
- out[5] = 1 - xx - zz;
- out[6] = zy + wx;
- out[7] = 0;
+/**
+ * Alias for {@link mat3.multiply}
+ * @function
+ */
+var mul = multiply;
- out[8] = zx + wy;
- out[9] = zy - wx;
- out[10] = 1 - xx - yy;
- out[11] = 0;
+/**
+ * Alias for {@link mat3.subtract}
+ * @function
+ */
+var sub = subtract;
+// CONCATENATED MODULE: ../node_modules/gl-matrix/lib/gl-matrix/mat4.js
- out[12] = 0;
- out[13] = 0;
- out[14] = 0;
- out[15] = 1;
- return out;
-}
+/**
+ * 4x4 Matrix
Format: column-major, when typed out it looks like row-major
The matrices are being post multiplied.
+ * @module mat4
+ */
/**
- * Generates a frustum matrix with the given bounds
+ * Creates a new identity mat4
*
- * @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
+ * @returns {mat4} a new 4x4 matrix
*/
-function frustum(out, left, right, bottom, top, near, far) {
- let rl = 1 / (right - left);
- let tb = 1 / (top - bottom);
- let 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;
+function mat4_create() {
+ var out = new ARRAY_TYPE(16);
+ if (ARRAY_TYPE != Float32Array) {
+ out[1] = 0;
+ out[2] = 0;
+ out[3] = 0;
+ out[4] = 0;
+ out[6] = 0;
+ out[7] = 0;
+ out[8] = 0;
+ out[9] = 0;
+ out[11] = 0;
+ out[12] = 0;
+ out[13] = 0;
+ out[14] = 0;
+ }
+ out[0] = 1;
+ out[5] = 1;
+ out[10] = 1;
+ out[15] = 1;
return out;
}
/**
- * Generates a perspective projection matrix with the given bounds
+ * Creates a new mat4 initialized with values from an existing matrix
*
- * @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
+ * @param {mat4} a matrix to clone
+ * @returns {mat4} a new 4x4 matrix
*/
-function perspective(out, fovy, aspect, near, far) {
- let f = 1.0 / Math.tan(fovy / 2);
- let 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;
+function mat4_clone(a) {
+ var out = new 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;
}
/**
- * 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.
+ * Copy the values from one mat4 to another
*
- * @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
+ * @param {mat4} out the receiving matrix
+ * @param {mat4} a the source matrix
* @returns {mat4} out
*/
-function perspectiveFromFieldOfView(out, fov, near, far) {
- let upTan = Math.tan(fov.upDegrees * Math.PI/180.0);
- let downTan = Math.tan(fov.downDegrees * Math.PI/180.0);
- let leftTan = Math.tan(fov.leftDegrees * Math.PI/180.0);
- let rightTan = Math.tan(fov.rightDegrees * Math.PI/180.0);
- let xScale = 2.0 / (leftTan + rightTan);
- let yScale = 2.0 / (upTan + downTan);
+function mat4_copy(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;
+}
- 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;
+/**
+ * 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
+ */
+function mat4_fromValues(m00, m01, m02, m03, m10, m11, m12, m13, m20, m21, m22, m23, m30, m31, m32, m33) {
+ var out = new 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;
}
/**
- * Generates a orthogonal projection matrix with the given bounds
+ * Set the components of a mat4 to the given values
*
- * @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
+ * @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
*/
-function ortho(out, left, right, bottom, top, near, far) {
- let lr = 1 / (left - right);
- let bt = 1 / (bottom - top);
- let nf = 1 / (near - far);
- out[0] = -2 * lr;
+function mat4_set(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
+ */
+function mat4_identity(out) {
+ out[0] = 1;
out[1] = 0;
out[2] = 0;
out[3] = 0;
out[4] = 0;
- out[5] = -2 * bt;
+ out[5] = 1;
out[6] = 0;
out[7] = 0;
out[8] = 0;
out[9] = 0;
- out[10] = 2 * nf;
+ out[10] = 1;
out[11] = 0;
- out[12] = (left + right) * lr;
- out[13] = (top + bottom) * bt;
- out[14] = (far + near) * nf;
+ out[12] = 0;
+ out[13] = 0;
+ out[14] = 0;
out[15] = 1;
return out;
}
/**
- * Generates a look-at matrix with the given eye position, focal point, and up axis
+ * Transpose the values of a mat4
*
- * @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
+ * @param {mat4} out the receiving matrix
+ * @param {mat4} a the source matrix
* @returns {mat4} out
*/
-function lookAt(out, eye, center, up) {
- let x0, x1, x2, y0, y1, y2, z0, z1, z2, len;
- let eyex = eye[0];
- let eyey = eye[1];
- let eyez = eye[2];
- let upx = up[0];
- let upy = up[1];
- let upz = up[2];
- let centerx = center[0];
- let centery = center[1];
- let centerz = center[2];
-
- if (Math.abs(eyex - centerx) < __WEBPACK_IMPORTED_MODULE_0__common__["EPSILON"] &&
- Math.abs(eyey - centery) < __WEBPACK_IMPORTED_MODULE_0__common__["EPSILON"] &&
- Math.abs(eyez - centerz) < __WEBPACK_IMPORTED_MODULE_0__common__["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;
+function mat4_transpose(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];
+ var a12 = a[6],
+ a13 = a[7];
+ var a23 = a[11];
- len = Math.sqrt(y0 * y0 + y1 * y1 + y2 * y2);
- if (!len) {
- y0 = 0;
- y1 = 0;
- y2 = 0;
+ 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 {
- len = 1 / len;
- y0 *= len;
- y1 *= len;
- y2 *= len;
+ 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];
}
- 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;
}
/**
- * Generates a matrix that makes something look at something else.
+ * Inverts a mat4
*
- * @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
+ * @param {mat4} out the receiving matrix
+ * @param {mat4} a the source matrix
* @returns {mat4} out
*/
-function targetTo(out, eye, target, up) {
- let eyex = eye[0],
- eyey = eye[1],
- eyez = eye[2],
- upx = up[0],
- upy = up[1],
- upz = up[2];
+function mat4_invert(out, a) {
+ var a00 = a[0],
+ a01 = a[1],
+ a02 = a[2],
+ a03 = a[3];
+ var a10 = a[4],
+ a11 = a[5],
+ a12 = a[6],
+ a13 = a[7];
+ var a20 = a[8],
+ a21 = a[9],
+ a22 = a[10],
+ a23 = a[11];
+ var a30 = a[12],
+ a31 = a[13],
+ a32 = a[14],
+ a33 = a[15];
+
+ var b00 = a00 * a11 - a01 * a10;
+ var b01 = a00 * a12 - a02 * a10;
+ var b02 = a00 * a13 - a03 * a10;
+ var b03 = a01 * a12 - a02 * a11;
+ var b04 = a01 * a13 - a03 * a11;
+ var b05 = a02 * a13 - a03 * a12;
+ var b06 = a20 * a31 - a21 * a30;
+ var b07 = a20 * a32 - a22 * a30;
+ var b08 = a20 * a33 - a23 * a30;
+ var b09 = a21 * a32 - a22 * a31;
+ var b10 = a21 * a33 - a23 * a31;
+ var b11 = a22 * a33 - a23 * a32;
- let z0 = eyex - target[0],
- z1 = eyey - target[1],
- z2 = eyez - target[2];
+ // Calculate the determinant
+ var det = b00 * b11 - b01 * b10 + b02 * b09 + b03 * b08 - b04 * b07 + b05 * b06;
- let len = z0*z0 + z1*z1 + z2*z2;
- if (len > 0) {
- len = 1 / Math.sqrt(len);
- z0 *= len;
- z1 *= len;
- z2 *= len;
+ if (!det) {
+ return null;
}
+ det = 1.0 / det;
- let x0 = upy * z2 - upz * z1,
- x1 = upz * z0 - upx * z2,
- x2 = upx * z1 - upy * z0;
+ 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;
- out[0] = x0;
- out[1] = x1;
- out[2] = x2;
- out[3] = 0;
- out[4] = z1 * x2 - z2 * x1;
- out[5] = z2 * x0 - z0 * x2;
- out[6] = z0 * x1 - z1 * x0;
- out[7] = 0;
- out[8] = z0;
- out[9] = z1;
- out[10] = z2;
- out[11] = 0;
- out[12] = eyex;
- out[13] = eyey;
- out[14] = eyez;
- out[15] = 1;
return out;
-};
+}
/**
- * Returns a string representation of a mat4
+ * Calculates the adjugate of a mat4
*
- * @param {mat4} a matrix to represent as a string
- * @returns {String} string representation of the matrix
+ * @param {mat4} out the receiving matrix
+ * @param {mat4} a the source matrix
+ * @returns {mat4} out
*/
-function str(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] + ')';
+function mat4_adjoint(out, a) {
+ var a00 = a[0],
+ a01 = a[1],
+ a02 = a[2],
+ a03 = a[3];
+ var a10 = a[4],
+ a11 = a[5],
+ a12 = a[6],
+ a13 = a[7];
+ var a20 = a[8],
+ a21 = a[9],
+ a22 = a[10],
+ a23 = a[11];
+ var 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;
}
/**
- * Returns Frobenius norm of a mat4
+ * Calculates the determinant of a mat4
*
- * @param {mat4} a the matrix to calculate Frobenius norm of
- * @returns {Number} Frobenius norm
+ * @param {mat4} a the source matrix
+ * @returns {Number} determinant of a
*/
-function frob(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) ))
+function mat4_determinant(a) {
+ var a00 = a[0],
+ a01 = a[1],
+ a02 = a[2],
+ a03 = a[3];
+ var a10 = a[4],
+ a11 = a[5],
+ a12 = a[6],
+ a13 = a[7];
+ var a20 = a[8],
+ a21 = a[9],
+ a22 = a[10],
+ a23 = a[11];
+ var a30 = a[12],
+ a31 = a[13],
+ a32 = a[14],
+ a33 = a[15];
+
+ var b00 = a00 * a11 - a01 * a10;
+ var b01 = a00 * a12 - a02 * a10;
+ var b02 = a00 * a13 - a03 * a10;
+ var b03 = a01 * a12 - a02 * a11;
+ var b04 = a01 * a13 - a03 * a11;
+ var b05 = a02 * a13 - a03 * a12;
+ var b06 = a20 * a31 - a21 * a30;
+ var b07 = a20 * a32 - a22 * a30;
+ var b08 = a20 * a33 - a23 * a30;
+ var b09 = a21 * a32 - a22 * a31;
+ var b10 = a21 * a33 - a23 * a31;
+ var b11 = a22 * a33 - a23 * a32;
+
+ // Calculate the determinant
+ return b00 * b11 - b01 * b10 + b02 * b09 + b03 * b08 - b04 * b07 + b05 * b06;
}
/**
- * Adds two mat4's
+ * Multiplies two mat4s
*
* @param {mat4} out the receiving matrix
* @param {mat4} a the first operand
* @param {mat4} b the second operand
* @returns {mat4} out
*/
-function add(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];
+function mat4_multiply(out, a, b) {
+ var a00 = a[0],
+ a01 = a[1],
+ a02 = a[2],
+ a03 = a[3];
+ var a10 = a[4],
+ a11 = a[5],
+ a12 = a[6],
+ a13 = a[7];
+ var a20 = a[8],
+ a21 = a[9],
+ a22 = a[10],
+ a23 = a[11];
+ var 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;
}
/**
- * Subtracts matrix b from matrix a
+ * Translate a mat4 by the given vector
*
* @param {mat4} out the receiving matrix
- * @param {mat4} a the first operand
- * @param {mat4} b the second operand
+ * @param {mat4} a the matrix to translate
+ * @param {vec3} v vector to translate by
* @returns {mat4} out
*/
-function subtract(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];
+function mat4_translate(out, a, v) {
+ var x = v[0],
+ y = v[1],
+ z = v[2];
+ var a00 = void 0,
+ a01 = void 0,
+ a02 = void 0,
+ a03 = void 0;
+ var a10 = void 0,
+ a11 = void 0,
+ a12 = void 0,
+ a13 = void 0;
+ var a20 = void 0,
+ a21 = void 0,
+ a22 = void 0,
+ a23 = void 0;
+
+ 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;
}
/**
- * Multiply each element of the matrix by a scalar.
+ * 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 {Number} b amount to scale the matrix's elements by
+ * @param {vec3} v the vec3 to scale the matrix by
* @returns {mat4} out
- */
-function multiplyScalar(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;
+ **/
+function mat4_scale(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;
}
/**
- * Adds two mat4's after multiplying each element of the second operand by a scalar value.
+ * Rotates a mat4 by the given angle around the given axis
*
- * @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
+ * @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
*/
-function multiplyScalarAndAdd(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);
+function mat4_rotate(out, a, rad, axis) {
+ var x = axis[0],
+ y = axis[1],
+ z = axis[2];
+ var len = Math.sqrt(x * x + y * y + z * z);
+ var s = void 0,
+ c = void 0,
+ t = void 0;
+ var a00 = void 0,
+ a01 = void 0,
+ a02 = void 0,
+ a03 = void 0;
+ var a10 = void 0,
+ a11 = void 0,
+ a12 = void 0,
+ a13 = void 0;
+ var a20 = void 0,
+ a21 = void 0,
+ a22 = void 0,
+ a23 = void 0;
+ var b00 = void 0,
+ b01 = void 0,
+ b02 = void 0;
+ var b10 = void 0,
+ b11 = void 0,
+ b12 = void 0;
+ var b20 = void 0,
+ b21 = void 0,
+ b22 = void 0;
+
+ if (len < 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;
}
/**
- * Returns whether or not the matrices have exactly the same elements in the same position (when compared with ===)
+ * Rotates a matrix by the given angle around the X axis
*
- * @param {mat4} a The first matrix.
- * @param {mat4} b The second matrix.
- * @returns {Boolean} True if the matrices are equal, false otherwise.
+ * @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
*/
-function exactEquals(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];
+function rotateX(out, a, rad) {
+ var s = Math.sin(rad);
+ var c = Math.cos(rad);
+ var a10 = a[4];
+ var a11 = a[5];
+ var a12 = a[6];
+ var a13 = a[7];
+ var a20 = a[8];
+ var a21 = a[9];
+ var a22 = a[10];
+ var 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;
}
/**
- * Returns whether or not the matrices have approximately the same elements in the same position.
+ * Rotates a matrix by the given angle around the Y axis
*
- * @param {mat4} a The first matrix.
- * @param {mat4} b The second matrix.
- * @returns {Boolean} True if the matrices are equal, false otherwise.
+ * @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
*/
-function equals(a, b) {
- let a0 = a[0], a1 = a[1], a2 = a[2], a3 = a[3];
- let a4 = a[4], a5 = a[5], a6 = a[6], a7 = a[7];
- let a8 = a[8], a9 = a[9], a10 = a[10], a11 = a[11];
- let a12 = a[12], a13 = a[13], a14 = a[14], a15 = a[15];
-
- let b0 = b[0], b1 = b[1], b2 = b[2], b3 = b[3];
- let b4 = b[4], b5 = b[5], b6 = b[6], b7 = b[7];
- let b8 = b[8], b9 = b[9], b10 = b[10], b11 = b[11];
- let b12 = b[12], b13 = b[13], b14 = b[14], b15 = b[15];
-
- return (Math.abs(a0 - b0) <= __WEBPACK_IMPORTED_MODULE_0__common__["EPSILON"]*Math.max(1.0, Math.abs(a0), Math.abs(b0)) &&
- Math.abs(a1 - b1) <= __WEBPACK_IMPORTED_MODULE_0__common__["EPSILON"]*Math.max(1.0, Math.abs(a1), Math.abs(b1)) &&
- Math.abs(a2 - b2) <= __WEBPACK_IMPORTED_MODULE_0__common__["EPSILON"]*Math.max(1.0, Math.abs(a2), Math.abs(b2)) &&
- Math.abs(a3 - b3) <= __WEBPACK_IMPORTED_MODULE_0__common__["EPSILON"]*Math.max(1.0, Math.abs(a3), Math.abs(b3)) &&
- Math.abs(a4 - b4) <= __WEBPACK_IMPORTED_MODULE_0__common__["EPSILON"]*Math.max(1.0, Math.abs(a4), Math.abs(b4)) &&
- Math.abs(a5 - b5) <= __WEBPACK_IMPORTED_MODULE_0__common__["EPSILON"]*Math.max(1.0, Math.abs(a5), Math.abs(b5)) &&
- Math.abs(a6 - b6) <= __WEBPACK_IMPORTED_MODULE_0__common__["EPSILON"]*Math.max(1.0, Math.abs(a6), Math.abs(b6)) &&
- Math.abs(a7 - b7) <= __WEBPACK_IMPORTED_MODULE_0__common__["EPSILON"]*Math.max(1.0, Math.abs(a7), Math.abs(b7)) &&
- Math.abs(a8 - b8) <= __WEBPACK_IMPORTED_MODULE_0__common__["EPSILON"]*Math.max(1.0, Math.abs(a8), Math.abs(b8)) &&
- Math.abs(a9 - b9) <= __WEBPACK_IMPORTED_MODULE_0__common__["EPSILON"]*Math.max(1.0, Math.abs(a9), Math.abs(b9)) &&
- Math.abs(a10 - b10) <= __WEBPACK_IMPORTED_MODULE_0__common__["EPSILON"]*Math.max(1.0, Math.abs(a10), Math.abs(b10)) &&
- Math.abs(a11 - b11) <= __WEBPACK_IMPORTED_MODULE_0__common__["EPSILON"]*Math.max(1.0, Math.abs(a11), Math.abs(b11)) &&
- Math.abs(a12 - b12) <= __WEBPACK_IMPORTED_MODULE_0__common__["EPSILON"]*Math.max(1.0, Math.abs(a12), Math.abs(b12)) &&
- Math.abs(a13 - b13) <= __WEBPACK_IMPORTED_MODULE_0__common__["EPSILON"]*Math.max(1.0, Math.abs(a13), Math.abs(b13)) &&
- Math.abs(a14 - b14) <= __WEBPACK_IMPORTED_MODULE_0__common__["EPSILON"]*Math.max(1.0, Math.abs(a14), Math.abs(b14)) &&
- Math.abs(a15 - b15) <= __WEBPACK_IMPORTED_MODULE_0__common__["EPSILON"]*Math.max(1.0, Math.abs(a15), Math.abs(b15)));
-}
-
-/**
- * Alias for {@link mat4.multiply}
- * @function
- */
-const mul = multiply;
-/* harmony export (immutable) */ __webpack_exports__["mul"] = mul;
+function rotateY(out, a, rad) {
+ var s = Math.sin(rad);
+ var c = Math.cos(rad);
+ var a00 = a[0];
+ var a01 = a[1];
+ var a02 = a[2];
+ var a03 = a[3];
+ var a20 = a[8];
+ var a21 = a[9];
+ var a22 = a[10];
+ var 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;
+}
/**
- * Alias for {@link mat4.subtract}
- * @function
+ * Rotates a matrix by the given angle around the Z axis
+ *
+ * @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
*/
-const sub = subtract;
-/* harmony export (immutable) */ __webpack_exports__["sub"] = sub;
-
-
-
-/***/ }),
-/* 70 */
-/***/ (function(module, __webpack_exports__, __webpack_require__) {
-
-"use strict";
-Object.defineProperty(__webpack_exports__, "__esModule", { value: true });
-/* harmony export (immutable) */ __webpack_exports__["create"] = create;
-/* harmony export (immutable) */ __webpack_exports__["identity"] = identity;
-/* harmony export (immutable) */ __webpack_exports__["setAxisAngle"] = setAxisAngle;
-/* harmony export (immutable) */ __webpack_exports__["getAxisAngle"] = getAxisAngle;
-/* harmony export (immutable) */ __webpack_exports__["multiply"] = multiply;
-/* harmony export (immutable) */ __webpack_exports__["rotateX"] = rotateX;
-/* harmony export (immutable) */ __webpack_exports__["rotateY"] = rotateY;
-/* harmony export (immutable) */ __webpack_exports__["rotateZ"] = rotateZ;
-/* harmony export (immutable) */ __webpack_exports__["calculateW"] = calculateW;
-/* harmony export (immutable) */ __webpack_exports__["slerp"] = slerp;
-/* harmony export (immutable) */ __webpack_exports__["invert"] = invert;
-/* harmony export (immutable) */ __webpack_exports__["conjugate"] = conjugate;
-/* harmony export (immutable) */ __webpack_exports__["fromMat3"] = fromMat3;
-/* harmony export (immutable) */ __webpack_exports__["fromEuler"] = fromEuler;
-/* harmony export (immutable) */ __webpack_exports__["str"] = str;
-/* harmony import */ var __WEBPACK_IMPORTED_MODULE_0__common__ = __webpack_require__(5);
-/* harmony import */ var __WEBPACK_IMPORTED_MODULE_1__mat3__ = __webpack_require__(31);
-/* harmony import */ var __WEBPACK_IMPORTED_MODULE_2__vec3__ = __webpack_require__(32);
-/* harmony import */ var __WEBPACK_IMPORTED_MODULE_3__vec4__ = __webpack_require__(33);
-/* 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 rotateZ(out, a, rad) {
+ var s = Math.sin(rad);
+ var c = Math.cos(rad);
+ var a00 = a[0];
+ var a01 = a[1];
+ var a02 = a[2];
+ var a03 = a[3];
+ var a10 = a[4];
+ var a11 = a[5];
+ var a12 = a[6];
+ var 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];
+ }
-/**
- * Quaternion
- * @module quat
- */
+ // 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;
+}
/**
- * Creates a new identity quat
+ * Creates a matrix from a vector translation
+ * This is equivalent to (but much faster than):
*
- * @returns {quat} a new quaternion
+ * mat4.identity(dest);
+ * mat4.translate(dest, dest, vec);
+ *
+ * @param {mat4} out mat4 receiving operation result
+ * @param {vec3} v Translation vector
+ * @returns {mat4} out
*/
-function create() {
- let out = new __WEBPACK_IMPORTED_MODULE_0__common__["ARRAY_TYPE"](4);
- out[0] = 0;
+function mat4_fromTranslation(out, v) {
+ out[0] = 1;
out[1] = 0;
out[2] = 0;
- out[3] = 1;
+ 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;
}
/**
- * Set a quat to the identity quaternion
+ * Creates a matrix from a vector scaling
+ * This is equivalent to (but much faster than):
*
- * @param {quat} out the receiving quaternion
- * @returns {quat} out
+ * mat4.identity(dest);
+ * mat4.scale(dest, dest, vec);
+ *
+ * @param {mat4} out mat4 receiving operation result
+ * @param {vec3} v Scaling vector
+ * @returns {mat4} out
*/
-function identity(out) {
- out[0] = 0;
+function mat4_fromScaling(out, v) {
+ out[0] = v[0];
out[1] = 0;
out[2] = 0;
- out[3] = 1;
+ 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;
}
/**
- * Sets a quat from the given angle and rotation axis,
- * then returns it.
+ * Creates a matrix from a given angle around a given axis
+ * This is equivalent to (but much faster than):
*
- * @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
- **/
-function setAxisAngle(out, axis, rad) {
- rad = rad * 0.5;
- let 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
+ * 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
*/
-function getAxisAngle(out_axis, q) {
- let rad = Math.acos(q[3]) * 2.0;
- let 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;
+function mat4_fromRotation(out, rad, axis) {
+ var x = axis[0],
+ y = axis[1],
+ z = axis[2];
+ var len = Math.sqrt(x * x + y * y + z * z);
+ var s = void 0,
+ c = void 0,
+ t = void 0;
+
+ if (len < EPSILON) {
+ return null;
}
- return rad;
-}
-/**
- * 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
- */
-function multiply(out, a, b) {
- let ax = a[0], ay = a[1], az = a[2], aw = a[3];
- let bx = b[0], by = b[1], bz = b[2], bw = b[3];
+ len = 1 / len;
+ x *= len;
+ y *= len;
+ z *= len;
- 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;
+ 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;
}
/**
- * Rotates a quaternion by the given angle about the X axis
+ * Creates a matrix from the given angle around the X axis
+ * This is equivalent to (but much faster than):
*
- * @param {quat} out quat receiving operation result
- * @param {quat} a quat to rotate
- * @param {number} rad angle (in radians) to rotate
- * @returns {quat} out
+ * 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
*/
-function rotateX(out, a, rad) {
- rad *= 0.5;
-
- let ax = a[0], ay = a[1], az = a[2], aw = a[3];
- let bx = Math.sin(rad), bw = Math.cos(rad);
+function fromXRotation(out, rad) {
+ var s = Math.sin(rad);
+ var c = 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;
+ // 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;
}
/**
- * Rotates a quaternion by the given angle about the Y axis
+ * Creates a matrix from the given angle around the Y axis
+ * This is equivalent to (but much faster than):
*
- * @param {quat} out quat receiving operation result
- * @param {quat} a quat to rotate
- * @param {number} rad angle (in radians) to rotate
- * @returns {quat} out
+ * 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
*/
-function rotateY(out, a, rad) {
- rad *= 0.5;
+function fromYRotation(out, rad) {
+ var s = Math.sin(rad);
+ var c = Math.cos(rad);
- let ax = a[0], ay = a[1], az = a[2], aw = a[3];
- let 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;
+ // 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;
}
/**
- * Rotates a quaternion by the given angle about the Z axis
+ * Creates a matrix from the given angle around the Z axis
+ * This is equivalent to (but much faster than):
*
- * @param {quat} out quat receiving operation result
- * @param {quat} a quat to rotate
- * @param {number} rad angle (in radians) to rotate
- * @returns {quat} out
+ * 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
*/
-function rotateZ(out, a, rad) {
- rad *= 0.5;
-
- let ax = a[0], ay = a[1], az = a[2], aw = a[3];
- let bz = Math.sin(rad), bw = Math.cos(rad);
+function fromZRotation(out, rad) {
+ var s = Math.sin(rad);
+ var c = 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;
+ // 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;
}
/**
- * 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.
+ * Creates a matrix from a quaternion rotation and vector translation
+ * This is equivalent to (but much faster than):
*
- * @param {quat} out the receiving quaternion
- * @param {quat} a quat to calculate W component of
- * @returns {quat} out
+ * mat4.identity(dest);
+ * mat4.translate(dest, vec);
+ * let 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
*/
-function calculateW(out, a) {
- let x = a[0], y = a[1], z = a[2];
+function fromRotationTranslation(out, q, v) {
+ // Quaternion math
+ var x = q[0],
+ y = q[1],
+ z = q[2],
+ w = q[3];
+ var x2 = x + x;
+ var y2 = y + y;
+ var z2 = z + z;
+
+ var xx = x * x2;
+ var xy = x * y2;
+ var xz = x * z2;
+ var yy = y * y2;
+ var yz = y * z2;
+ var zz = z * z2;
+ var wx = w * x2;
+ var wy = w * y2;
+ var 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;
- 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;
}
/**
- * 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
- */
-function slerp(out, a, b, t) {
- // benchmarks:
- // http://jsperf.com/quaternion-slerp-implementations
- let ax = a[0], ay = a[1], az = a[2], aw = a[3];
- let bx = b[0], by = b[1], bz = b[2], bw = b[3];
-
- let 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;
+ * Creates a new mat4 from a dual quat.
+ *
+ * @param {mat4} out Matrix
+ * @param {quat2} a Dual Quaternion
+ * @returns {mat4} mat4 receiving operation result
+ */
+function fromQuat2(out, a) {
+ var translation = new ARRAY_TYPE(3);
+ var bx = -a[0],
+ by = -a[1],
+ bz = -a[2],
+ bw = a[3],
+ ax = a[4],
+ ay = a[5],
+ az = a[6],
+ aw = a[7];
+
+ var magnitude = bx * bx + by * by + bz * bz + bw * bw;
+ //Only scale if it makes sense
+ if (magnitude > 0) {
+ translation[0] = (ax * bw + aw * bx + ay * bz - az * by) * 2 / magnitude;
+ translation[1] = (ay * bw + aw * by + az * bx - ax * bz) * 2 / magnitude;
+ translation[2] = (az * bw + aw * bz + ax * by - ay * bx) * 2 / magnitude;
} else {
- // "from" and "to" quaternions are very close
- // ... so we can do a linear interpolation
- scale0 = 1.0 - t;
- scale1 = t;
+ translation[0] = (ax * bw + aw * bx + ay * bz - az * by) * 2;
+ translation[1] = (ay * bw + aw * by + az * bx - ax * bz) * 2;
+ translation[2] = (az * bw + aw * bz + ax * by - ay * bx) * 2;
}
- // 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;
-
+ fromRotationTranslation(out, a, translation);
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
+ * 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
*/
-function invert(out, a) {
- let a0 = a[0], a1 = a[1], a2 = a[2], a3 = a[3];
- let dot = a0*a0 + a1*a1 + a2*a2 + a3*a3;
- let invDot = dot ? 1.0/dot : 0;
-
- // TODO: Would be faster to return [0,0,0,0] immediately if dot == 0
+function getTranslation(out, mat) {
+ out[0] = mat[12];
+ out[1] = mat[13];
+ out[2] = mat[14];
- 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
+ * Returns the scaling factor component of a transformation
+ * matrix. If a matrix is built with fromRotationTranslationScale
+ * with a normalized Quaternion paramter, the returned vector will be
+ * the same as the scaling vector
+ * originally supplied.
+ * @param {vec3} out Vector to receive scaling factor component
+ * @param {mat4} mat Matrix to be decomposed (input)
+ * @return {vec3} out
*/
-function conjugate(out, a) {
- out[0] = -a[0];
- out[1] = -a[1];
- out[2] = -a[2];
- out[3] = a[3];
+function getScaling(out, mat) {
+ var m11 = mat[0];
+ var m12 = mat[1];
+ var m13 = mat[2];
+ var m21 = mat[4];
+ var m22 = mat[5];
+ var m23 = mat[6];
+ var m31 = mat[8];
+ var m32 = mat[9];
+ var m33 = mat[10];
+
+ out[0] = Math.sqrt(m11 * m11 + m12 * m12 + m13 * m13);
+ out[1] = Math.sqrt(m21 * m21 + m22 * m22 + m23 * m23);
+ out[2] = Math.sqrt(m31 * m31 + m32 * m32 + m33 * m33);
+
return out;
}
/**
- * 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
+ * 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
*/
-function fromMat3(out, m) {
- // Algorithm in Ken Shoemake's article in 1987 SIGGRAPH course notes
- // article "Quaternion Calculus and Fast Animation".
- let fTrace = m[0] + m[4] + m[8];
- let fRoot;
+function getRotation(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 ( 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;
+ 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 {
- // |w| <= 1/2
- let i = 0;
- if ( m[4] > m[0] )
- i = 1;
- if ( m[8] > m[i*3+i] )
- i = 2;
- let j = (i+1)%3;
- let 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;
+ 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 quaternion from the given euler angle x, y, z.
+ * Creates a matrix from a quaternion rotation, vector translation and vector scale
+ * This is equivalent to (but much faster than):
*
- * @param {quat} out the receiving quaternion
- * @param {x} Angle to rotate around X axis in degrees.
- * @param {y} Angle to rotate around Y axis in degrees.
- * @param {z} Angle to rotate around Z axis in degrees.
- * @returns {quat} out
- * @function
- */
-function fromEuler(out, x, y, z) {
- let halfToRad = 0.5 * Math.PI / 180.0;
- x *= halfToRad;
- y *= halfToRad;
- z *= halfToRad;
-
- let sx = Math.sin(x);
- let cx = Math.cos(x);
- let sy = Math.sin(y);
- let cy = Math.cos(y);
- let sz = Math.sin(z);
- let cz = Math.cos(z);
-
- out[0] = sx * cy * cz - cx * sy * sz;
- out[1] = cx * sy * cz + sx * cy * sz;
- out[2] = cx * cy * sz - sx * sy * cz;
- out[3] = cx * cy * cz + sx * sy * sz;
-
- return out;
-}
-
-/**
- * Returns a string representation of a quatenion
+ * mat4.identity(dest);
+ * mat4.translate(dest, vec);
+ * let quatMat = mat4.create();
+ * quat4.toMat4(quat, quatMat);
+ * mat4.multiply(dest, quatMat);
+ * mat4.scale(dest, scale)
*
- * @param {quat} a vector to represent as a string
- * @returns {String} string representation of the vector
+ * @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
*/
-function str(a) {
- return 'quat(' + a[0] + ', ' + a[1] + ', ' + a[2] + ', ' + a[3] + ')';
-}
+function fromRotationTranslationScale(out, q, v, s) {
+ // Quaternion math
+ var x = q[0],
+ y = q[1],
+ z = q[2],
+ w = q[3];
+ var x2 = x + x;
+ var y2 = y + y;
+ var z2 = z + z;
+
+ var xx = x * x2;
+ var xy = x * y2;
+ var xz = x * z2;
+ var yy = y * y2;
+ var yz = y * z2;
+ var zz = z * z2;
+ var wx = w * x2;
+ var wy = w * y2;
+ var wz = w * z2;
+ var sx = s[0];
+ var sy = s[1];
+ var sz = s[2];
-/**
- * Creates a new quat initialized with values from an existing quaternion
- *
- * @param {quat} a quaternion to clone
- * @returns {quat} a new quaternion
- * @function
- */
-const clone = __WEBPACK_IMPORTED_MODULE_3__vec4__["clone"];
-/* harmony export (immutable) */ __webpack_exports__["clone"] = clone;
+ 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 new quat initialized with the given values
+ * 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):
*
- * @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
- */
-const fromValues = __WEBPACK_IMPORTED_MODULE_3__vec4__["fromValues"];
-/* harmony export (immutable) */ __webpack_exports__["fromValues"] = fromValues;
-
-
-/**
- * Copy the values from one quat to another
+ * mat4.identity(dest);
+ * mat4.translate(dest, vec);
+ * mat4.translate(dest, origin);
+ * let quatMat = mat4.create();
+ * quat4.toMat4(quat, quatMat);
+ * mat4.multiply(dest, quatMat);
+ * mat4.scale(dest, scale)
+ * mat4.translate(dest, negativeOrigin);
*
- * @param {quat} out the receiving quaternion
- * @param {quat} a the source quaternion
- * @returns {quat} out
- * @function
+ * @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
*/
-const copy = __WEBPACK_IMPORTED_MODULE_3__vec4__["copy"];
-/* harmony export (immutable) */ __webpack_exports__["copy"] = copy;
+function fromRotationTranslationScaleOrigin(out, q, v, s, o) {
+ // Quaternion math
+ var x = q[0],
+ y = q[1],
+ z = q[2],
+ w = q[3];
+ var x2 = x + x;
+ var y2 = y + y;
+ var z2 = z + z;
+
+ var xx = x * x2;
+ var xy = x * y2;
+ var xz = x * z2;
+ var yy = y * y2;
+ var yz = y * z2;
+ var zz = z * z2;
+ var wx = w * x2;
+ var wy = w * y2;
+ var wz = w * z2;
+
+ var sx = s[0];
+ var sy = s[1];
+ var sz = s[2];
+
+ var ox = o[0];
+ var oy = o[1];
+ var oz = o[2];
+
+ var out0 = (1 - (yy + zz)) * sx;
+ var out1 = (xy + wz) * sx;
+ var out2 = (xz - wy) * sx;
+ var out4 = (xy - wz) * sy;
+ var out5 = (1 - (xx + zz)) * sy;
+ var out6 = (yz + wx) * sy;
+ var out8 = (xz + wy) * sz;
+ var out9 = (yz - wx) * sz;
+ var out10 = (1 - (xx + yy)) * sz;
+
+ out[0] = out0;
+ out[1] = out1;
+ out[2] = out2;
+ out[3] = 0;
+ out[4] = out4;
+ out[5] = out5;
+ out[6] = out6;
+ out[7] = 0;
+ out[8] = out8;
+ out[9] = out9;
+ out[10] = out10;
+ out[11] = 0;
+ out[12] = v[0] + ox - (out0 * ox + out4 * oy + out8 * oz);
+ out[13] = v[1] + oy - (out1 * ox + out5 * oy + out9 * oz);
+ out[14] = v[2] + oz - (out2 * ox + out6 * oy + out10 * oz);
+ out[15] = 1;
+ return out;
+}
/**
- * Set the components of a quat to the given values
+ * Calculates a 4x4 matrix from the given quaternion
*
- * @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
- */
-const set = __WEBPACK_IMPORTED_MODULE_3__vec4__["set"];
-/* harmony export (immutable) */ __webpack_exports__["set"] = set;
-
-
-/**
- * Adds two quat's
+ * @param {mat4} out mat4 receiving operation result
+ * @param {quat} q Quaternion to create matrix from
*
- * @param {quat} out the receiving quaternion
- * @param {quat} a the first operand
- * @param {quat} b the second operand
- * @returns {quat} out
- * @function
+ * @returns {mat4} out
*/
-const add = __WEBPACK_IMPORTED_MODULE_3__vec4__["add"];
-/* harmony export (immutable) */ __webpack_exports__["add"] = add;
+function mat4_fromQuat(out, q) {
+ var x = q[0],
+ y = q[1],
+ z = q[2],
+ w = q[3];
+ var x2 = x + x;
+ var y2 = y + y;
+ var z2 = z + z;
+
+ var xx = x * x2;
+ var yx = y * x2;
+ var yy = y * y2;
+ var zx = z * x2;
+ var zy = z * y2;
+ var zz = z * z2;
+ var wx = w * x2;
+ var wy = w * y2;
+ var wz = w * z2;
+ out[0] = 1 - yy - zz;
+ out[1] = yx + wz;
+ out[2] = zx - wy;
+ out[3] = 0;
-/**
- * Alias for {@link quat.multiply}
- * @function
- */
-const mul = multiply;
-/* harmony export (immutable) */ __webpack_exports__["mul"] = mul;
+ 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;
-/**
- * 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
- */
-const scale = __WEBPACK_IMPORTED_MODULE_3__vec4__["scale"];
-/* harmony export (immutable) */ __webpack_exports__["scale"] = scale;
+ out[12] = 0;
+ out[13] = 0;
+ out[14] = 0;
+ out[15] = 1;
+ return out;
+}
/**
- * Calculates the dot product of two quat's
+ * Generates a frustum matrix with the given bounds
*
- * @param {quat} a the first operand
- * @param {quat} b the second operand
- * @returns {Number} dot product of a and b
- * @function
+ * @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
*/
-const dot = __WEBPACK_IMPORTED_MODULE_3__vec4__["dot"];
-/* harmony export (immutable) */ __webpack_exports__["dot"] = dot;
-
+function frustum(out, left, right, bottom, top, near, far) {
+ var rl = 1 / (right - left);
+ var tb = 1 / (top - bottom);
+ var 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;
+}
/**
- * Performs a linear interpolation between two quat's
+ * Generates a perspective projection matrix with the given bounds.
+ * Passing null/undefined/no value for far will generate infinite projection matrix.
*
- * @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
+ * @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, can be null or Infinity
+ * @returns {mat4} out
*/
-const lerp = __WEBPACK_IMPORTED_MODULE_3__vec4__["lerp"];
-/* harmony export (immutable) */ __webpack_exports__["lerp"] = lerp;
-
+function perspective(out, fovy, aspect, near, far) {
+ var f = 1.0 / Math.tan(fovy / 2),
+ nf = void 0;
+ 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[11] = -1;
+ out[12] = 0;
+ out[13] = 0;
+ out[15] = 0;
+ if (far != null && far !== Infinity) {
+ nf = 1 / (near - far);
+ out[10] = (far + near) * nf;
+ out[14] = 2 * far * near * nf;
+ } else {
+ out[10] = -1;
+ out[14] = -2 * near;
+ }
+ return out;
+}
/**
- * Calculates the length of a quat
+ * 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 {quat} a vector to calculate length of
- * @returns {Number} length of a
+ * @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
*/
-const length = __WEBPACK_IMPORTED_MODULE_3__vec4__["length"];
-/* harmony export (immutable) */ __webpack_exports__["length"] = length;
+function perspectiveFromFieldOfView(out, fov, near, far) {
+ var upTan = Math.tan(fov.upDegrees * Math.PI / 180.0);
+ var downTan = Math.tan(fov.downDegrees * Math.PI / 180.0);
+ var leftTan = Math.tan(fov.leftDegrees * Math.PI / 180.0);
+ var rightTan = Math.tan(fov.rightDegrees * Math.PI / 180.0);
+ var xScale = 2.0 / (leftTan + rightTan);
+ var 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;
+}
/**
- * Alias for {@link quat.length}
- * @function
+ * 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
*/
-const len = length;
-/* harmony export (immutable) */ __webpack_exports__["len"] = len;
-
+function ortho(out, left, right, bottom, top, near, far) {
+ var lr = 1 / (left - right);
+ var bt = 1 / (bottom - top);
+ var 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;
+}
/**
- * Calculates the squared length of a quat
+ * Generates a look-at matrix with the given eye position, focal point, and up axis.
+ * If you want a matrix that actually makes an object look at another object, you should use targetTo instead.
*
- * @param {quat} a vector to calculate squared length of
- * @returns {Number} squared length of a
- * @function
+ * @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
*/
-const squaredLength = __WEBPACK_IMPORTED_MODULE_3__vec4__["squaredLength"];
-/* harmony export (immutable) */ __webpack_exports__["squaredLength"] = squaredLength;
-
-
-/**
- * Alias for {@link quat.squaredLength}
- * @function
- */
-const sqrLen = squaredLength;
-/* harmony export (immutable) */ __webpack_exports__["sqrLen"] = sqrLen;
+function lookAt(out, eye, center, up) {
+ var x0 = void 0,
+ x1 = void 0,
+ x2 = void 0,
+ y0 = void 0,
+ y1 = void 0,
+ y2 = void 0,
+ z0 = void 0,
+ z1 = void 0,
+ z2 = void 0,
+ len = void 0;
+ var eyex = eye[0];
+ var eyey = eye[1];
+ var eyez = eye[2];
+ var upx = up[0];
+ var upy = up[1];
+ var upz = up[2];
+ var centerx = center[0];
+ var centery = center[1];
+ var centerz = center[2];
+
+ if (Math.abs(eyex - centerx) < EPSILON && Math.abs(eyey - centery) < EPSILON && Math.abs(eyez - centerz) < EPSILON) {
+ return mat4_identity(out);
+ }
+ z0 = eyex - centerx;
+ z1 = eyey - centery;
+ z2 = eyez - centerz;
-/**
- * Normalize a quat
- *
- * @param {quat} out the receiving quaternion
- * @param {quat} a quaternion to normalize
- * @returns {quat} out
- * @function
- */
-const normalize = __WEBPACK_IMPORTED_MODULE_3__vec4__["normalize"];
-/* harmony export (immutable) */ __webpack_exports__["normalize"] = normalize;
+ 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;
+ }
-/**
- * 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.
- */
-const exactEquals = __WEBPACK_IMPORTED_MODULE_3__vec4__["exactEquals"];
-/* harmony export (immutable) */ __webpack_exports__["exactEquals"] = exactEquals;
+ 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;
+ }
-/**
- * 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.
- */
-const equals = __WEBPACK_IMPORTED_MODULE_3__vec4__["equals"];
-/* harmony export (immutable) */ __webpack_exports__["equals"] = equals;
+ 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;
+}
/**
- * Sets a quaternion to represent the shortest rotation from one
- * vector to another.
- *
- * Both vectors are assumed to be unit length.
+ * Generates a matrix that makes something look at something else.
*
- * @param {quat} out the receiving quaternion.
- * @param {vec3} a the initial vector
- * @param {vec3} b the destination vector
- * @returns {quat} out
+ * @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
*/
-const rotationTo = (function() {
- let tmpvec3 = __WEBPACK_IMPORTED_MODULE_2__vec3__["create"]();
- let xUnitVec3 = __WEBPACK_IMPORTED_MODULE_2__vec3__["fromValues"](1,0,0);
- let yUnitVec3 = __WEBPACK_IMPORTED_MODULE_2__vec3__["fromValues"](0,1,0);
-
- return function(out, a, b) {
- let dot = __WEBPACK_IMPORTED_MODULE_2__vec3__["dot"](a, b);
- if (dot < -0.999999) {
- __WEBPACK_IMPORTED_MODULE_2__vec3__["cross"](tmpvec3, xUnitVec3, a);
- if (__WEBPACK_IMPORTED_MODULE_2__vec3__["len"](tmpvec3) < 0.000001)
- __WEBPACK_IMPORTED_MODULE_2__vec3__["cross"](tmpvec3, yUnitVec3, a);
- __WEBPACK_IMPORTED_MODULE_2__vec3__["normalize"](tmpvec3, tmpvec3);
- 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 {
- __WEBPACK_IMPORTED_MODULE_2__vec3__["cross"](tmpvec3, a, b);
- out[0] = tmpvec3[0];
- out[1] = tmpvec3[1];
- out[2] = tmpvec3[2];
- out[3] = 1 + dot;
- return normalize(out, out);
- }
- };
-})();
-/* harmony export (immutable) */ __webpack_exports__["rotationTo"] = rotationTo;
+function targetTo(out, eye, target, up) {
+ var eyex = eye[0],
+ eyey = eye[1],
+ eyez = eye[2],
+ upx = up[0],
+ upy = up[1],
+ upz = up[2];
+ var z0 = eyex - target[0],
+ z1 = eyey - target[1],
+ z2 = eyez - target[2];
-/**
- * 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
- */
-const sqlerp = (function () {
- let temp1 = create();
- let temp2 = create();
+ var len = z0 * z0 + z1 * z1 + z2 * z2;
+ if (len > 0) {
+ len = 1 / Math.sqrt(len);
+ z0 *= len;
+ z1 *= len;
+ z2 *= len;
+ }
- return function (out, a, b, c, d, t) {
- slerp(temp1, a, d, t);
- slerp(temp2, b, c, t);
- slerp(out, temp1, temp2, 2 * t * (1 - t));
+ var x0 = upy * z2 - upz * z1,
+ x1 = upz * z0 - upx * z2,
+ x2 = upx * z1 - upy * z0;
- return out;
- };
-}());
-/* harmony export (immutable) */ __webpack_exports__["sqlerp"] = sqlerp;
+ len = x0 * x0 + x1 * x1 + x2 * x2;
+ if (len > 0) {
+ len = 1 / Math.sqrt(len);
+ x0 *= len;
+ x1 *= len;
+ x2 *= len;
+ }
+ out[0] = x0;
+ out[1] = x1;
+ out[2] = x2;
+ out[3] = 0;
+ out[4] = z1 * x2 - z2 * x1;
+ out[5] = z2 * x0 - z0 * x2;
+ out[6] = z0 * x1 - z1 * x0;
+ out[7] = 0;
+ out[8] = z0;
+ out[9] = z1;
+ out[10] = z2;
+ out[11] = 0;
+ out[12] = eyex;
+ out[13] = eyey;
+ out[14] = eyez;
+ out[15] = 1;
+ return 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.
+ * Returns a string representation of a mat4
*
- * @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
- */
-const setAxes = (function() {
- let matr = __WEBPACK_IMPORTED_MODULE_1__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 normalize(out, fromMat3(out, matr));
- };
-})();
-/* harmony export (immutable) */ __webpack_exports__["setAxes"] = setAxes;
-
-
-
-/***/ }),
-/* 71 */
-/***/ (function(module, __webpack_exports__, __webpack_require__) {
-
-"use strict";
-Object.defineProperty(__webpack_exports__, "__esModule", { value: true });
-/* harmony export (immutable) */ __webpack_exports__["create"] = create;
-/* harmony export (immutable) */ __webpack_exports__["clone"] = clone;
-/* harmony export (immutable) */ __webpack_exports__["fromValues"] = fromValues;
-/* harmony export (immutable) */ __webpack_exports__["copy"] = copy;
-/* harmony export (immutable) */ __webpack_exports__["set"] = set;
-/* harmony export (immutable) */ __webpack_exports__["add"] = add;
-/* harmony export (immutable) */ __webpack_exports__["subtract"] = subtract;
-/* harmony export (immutable) */ __webpack_exports__["multiply"] = multiply;
-/* harmony export (immutable) */ __webpack_exports__["divide"] = divide;
-/* harmony export (immutable) */ __webpack_exports__["ceil"] = ceil;
-/* harmony export (immutable) */ __webpack_exports__["floor"] = floor;
-/* harmony export (immutable) */ __webpack_exports__["min"] = min;
-/* harmony export (immutable) */ __webpack_exports__["max"] = max;
-/* harmony export (immutable) */ __webpack_exports__["round"] = round;
-/* harmony export (immutable) */ __webpack_exports__["scale"] = scale;
-/* harmony export (immutable) */ __webpack_exports__["scaleAndAdd"] = scaleAndAdd;
-/* harmony export (immutable) */ __webpack_exports__["distance"] = distance;
-/* harmony export (immutable) */ __webpack_exports__["squaredDistance"] = squaredDistance;
-/* harmony export (immutable) */ __webpack_exports__["length"] = length;
-/* harmony export (immutable) */ __webpack_exports__["squaredLength"] = squaredLength;
-/* harmony export (immutable) */ __webpack_exports__["negate"] = negate;
-/* harmony export (immutable) */ __webpack_exports__["inverse"] = inverse;
-/* harmony export (immutable) */ __webpack_exports__["normalize"] = normalize;
-/* harmony export (immutable) */ __webpack_exports__["dot"] = dot;
-/* harmony export (immutable) */ __webpack_exports__["cross"] = cross;
-/* harmony export (immutable) */ __webpack_exports__["lerp"] = lerp;
-/* harmony export (immutable) */ __webpack_exports__["random"] = random;
-/* harmony export (immutable) */ __webpack_exports__["transformMat2"] = transformMat2;
-/* harmony export (immutable) */ __webpack_exports__["transformMat2d"] = transformMat2d;
-/* harmony export (immutable) */ __webpack_exports__["transformMat3"] = transformMat3;
-/* harmony export (immutable) */ __webpack_exports__["transformMat4"] = transformMat4;
-/* harmony export (immutable) */ __webpack_exports__["str"] = str;
-/* harmony export (immutable) */ __webpack_exports__["exactEquals"] = exactEquals;
-/* harmony export (immutable) */ __webpack_exports__["equals"] = equals;
-/* harmony import */ var __WEBPACK_IMPORTED_MODULE_0__common__ = __webpack_require__(5);
-/* 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. */
-
-
-
-/**
- * 2 Dimensional Vector
- * @module vec2
+ * @param {mat4} a matrix to represent as a string
+ * @returns {String} string representation of the matrix
*/
+function mat4_str(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] + ')';
+}
/**
- * Creates a new, empty vec2
+ * Returns Frobenius norm of a mat4
*
- * @returns {vec2} a new 2D vector
+ * @param {mat4} a the matrix to calculate Frobenius norm of
+ * @returns {Number} Frobenius norm
*/
-function create() {
- let out = new __WEBPACK_IMPORTED_MODULE_0__common__["ARRAY_TYPE"](2);
- out[0] = 0;
- out[1] = 0;
- return out;
+function mat4_frob(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));
}
/**
- * Creates a new vec2 initialized with values from an existing vector
+ * Adds two mat4's
*
- * @param {vec2} a vector to clone
- * @returns {vec2} a new 2D vector
+ * @param {mat4} out the receiving matrix
+ * @param {mat4} a the first operand
+ * @param {mat4} b the second operand
+ * @returns {mat4} out
*/
-function clone(a) {
- let out = new __WEBPACK_IMPORTED_MODULE_0__common__["ARRAY_TYPE"](2);
- out[0] = a[0];
- out[1] = a[1];
+function mat4_add(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;
}
/**
- * Creates a new vec2 initialized with the given values
+ * Subtracts matrix b from matrix a
*
- * @param {Number} x X component
- * @param {Number} y Y component
- * @returns {vec2} a new 2D vector
+ * @param {mat4} out the receiving matrix
+ * @param {mat4} a the first operand
+ * @param {mat4} b the second operand
+ * @returns {mat4} out
*/
-function fromValues(x, y) {
- let out = new __WEBPACK_IMPORTED_MODULE_0__common__["ARRAY_TYPE"](2);
- out[0] = x;
- out[1] = y;
+function mat4_subtract(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;
}
/**
- * Copy the values from one vec2 to another
+ * Multiply each element of the matrix by a scalar.
*
- * @param {vec2} out the receiving vector
- * @param {vec2} a the source vector
- * @returns {vec2} out
+ * @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
*/
-function copy(out, a) {
+function mat4_multiplyScalar(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
+ */
+function mat4_multiplyScalarAndAdd(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.
+ */
+function mat4_exactEquals(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.
+ */
+function mat4_equals(a, b) {
+ var a0 = a[0],
+ a1 = a[1],
+ a2 = a[2],
+ a3 = a[3];
+ var a4 = a[4],
+ a5 = a[5],
+ a6 = a[6],
+ a7 = a[7];
+ var a8 = a[8],
+ a9 = a[9],
+ a10 = a[10],
+ a11 = a[11];
+ var 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];
+ var b4 = b[4],
+ b5 = b[5],
+ b6 = b[6],
+ b7 = b[7];
+ var b8 = b[8],
+ b9 = b[9],
+ b10 = b[10],
+ b11 = b[11];
+ var b12 = b[12],
+ b13 = b[13],
+ b14 = b[14],
+ b15 = b[15];
+
+ return Math.abs(a0 - b0) <= EPSILON * Math.max(1.0, Math.abs(a0), Math.abs(b0)) && Math.abs(a1 - b1) <= EPSILON * Math.max(1.0, Math.abs(a1), Math.abs(b1)) && Math.abs(a2 - b2) <= EPSILON * Math.max(1.0, Math.abs(a2), Math.abs(b2)) && Math.abs(a3 - b3) <= EPSILON * Math.max(1.0, Math.abs(a3), Math.abs(b3)) && Math.abs(a4 - b4) <= EPSILON * Math.max(1.0, Math.abs(a4), Math.abs(b4)) && Math.abs(a5 - b5) <= EPSILON * Math.max(1.0, Math.abs(a5), Math.abs(b5)) && Math.abs(a6 - b6) <= EPSILON * Math.max(1.0, Math.abs(a6), Math.abs(b6)) && Math.abs(a7 - b7) <= EPSILON * Math.max(1.0, Math.abs(a7), Math.abs(b7)) && Math.abs(a8 - b8) <= EPSILON * Math.max(1.0, Math.abs(a8), Math.abs(b8)) && Math.abs(a9 - b9) <= EPSILON * Math.max(1.0, Math.abs(a9), Math.abs(b9)) && Math.abs(a10 - b10) <= EPSILON * Math.max(1.0, Math.abs(a10), Math.abs(b10)) && Math.abs(a11 - b11) <= EPSILON * Math.max(1.0, Math.abs(a11), Math.abs(b11)) && Math.abs(a12 - b12) <= EPSILON * Math.max(1.0, Math.abs(a12), Math.abs(b12)) && Math.abs(a13 - b13) <= EPSILON * Math.max(1.0, Math.abs(a13), Math.abs(b13)) && Math.abs(a14 - b14) <= EPSILON * Math.max(1.0, Math.abs(a14), Math.abs(b14)) && Math.abs(a15 - b15) <= EPSILON * Math.max(1.0, Math.abs(a15), Math.abs(b15));
+}
+
+/**
+ * Alias for {@link mat4.multiply}
+ * @function
+ */
+var mat4_mul = mat4_multiply;
+
+/**
+ * Alias for {@link mat4.subtract}
+ * @function
+ */
+var mat4_sub = mat4_subtract;
+// CONCATENATED MODULE: ../node_modules/gl-matrix/lib/gl-matrix/vec3.js
+
+
+/**
+ * 3 Dimensional Vector
+ * @module vec3
+ */
+
+/**
+ * Creates a new, empty vec3
+ *
+ * @returns {vec3} a new 3D vector
+ */
+function vec3_create() {
+ var out = new ARRAY_TYPE(3);
+ if (ARRAY_TYPE != Float32Array) {
+ 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
+ */
+function vec3_clone(a) {
+ var out = new ARRAY_TYPE(3);
out[0] = a[0];
out[1] = a[1];
+ out[2] = a[2];
return out;
}
/**
- * Set the components of a vec2 to the given values
+ * Calculates the length of a vec3
+ *
+ * @param {vec3} a vector to calculate length of
+ * @returns {Number} length of a
+ */
+function vec3_length(a) {
+ var x = a[0];
+ var y = a[1];
+ var z = a[2];
+ return Math.sqrt(x * x + y * y + z * z);
+}
+
+/**
+ * Creates a new vec3 initialized with the given values
*
- * @param {vec2} out the receiving vector
* @param {Number} x X component
* @param {Number} y Y component
- * @returns {vec2} out
+ * @param {Number} z Z component
+ * @returns {vec3} a new 3D vector
*/
-function set(out, x, y) {
+function vec3_fromValues(x, y, z) {
+ var out = new ARRAY_TYPE(3);
out[0] = x;
out[1] = y;
+ out[2] = z;
return out;
}
/**
- * Adds two vec2's
+ * Copy the values from one vec3 to another
*
- * @param {vec2} out the receiving vector
- * @param {vec2} a the first operand
- * @param {vec2} b the second operand
- * @returns {vec2} out
+ * @param {vec3} out the receiving vector
+ * @param {vec3} a the source vector
+ * @returns {vec3} out
*/
-function add(out, a, b) {
+function vec3_copy(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
+ */
+function vec3_set(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
+ */
+function vec3_add(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 {vec2} out the receiving vector
- * @param {vec2} a the first operand
- * @param {vec2} b the second operand
- * @returns {vec2} out
+ * @param {vec3} out the receiving vector
+ * @param {vec3} a the first operand
+ * @param {vec3} b the second operand
+ * @returns {vec3} out
*/
-function subtract(out, a, b) {
+function vec3_subtract(out, a, b) {
out[0] = a[0] - b[0];
out[1] = a[1] - b[1];
+ out[2] = a[2] - b[2];
return out;
}
/**
- * Multiplies two vec2's
+ * Multiplies two vec3's
*
- * @param {vec2} out the receiving vector
- * @param {vec2} a the first operand
- * @param {vec2} b the second operand
- * @returns {vec2} out
+ * @param {vec3} out the receiving vector
+ * @param {vec3} a the first operand
+ * @param {vec3} b the second operand
+ * @returns {vec3} out
*/
-function multiply(out, a, b) {
+function vec3_multiply(out, a, b) {
out[0] = a[0] * b[0];
out[1] = a[1] * b[1];
+ out[2] = a[2] * b[2];
return out;
-};
+}
/**
- * Divides two vec2's
+ * Divides two vec3's
*
- * @param {vec2} out the receiving vector
- * @param {vec2} a the first operand
- * @param {vec2} b the second operand
- * @returns {vec2} out
+ * @param {vec3} out the receiving vector
+ * @param {vec3} a the first operand
+ * @param {vec3} b the second operand
+ * @returns {vec3} out
*/
function divide(out, a, b) {
out[0] = a[0] / b[0];
out[1] = a[1] / b[1];
+ out[2] = a[2] / b[2];
return out;
-};
+}
/**
- * Math.ceil the components of a vec2
+ * Math.ceil the components of a vec3
*
- * @param {vec2} out the receiving vector
- * @param {vec2} a vector to ceil
- * @returns {vec2} out
+ * @param {vec3} out the receiving vector
+ * @param {vec3} a vector to ceil
+ * @returns {vec3} out
*/
function ceil(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 vec2
+ * Math.floor the components of a vec3
*
- * @param {vec2} out the receiving vector
- * @param {vec2} a vector to floor
- * @returns {vec2} out
+ * @param {vec3} out the receiving vector
+ * @param {vec3} a vector to floor
+ * @returns {vec3} out
*/
function floor(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 vec2's
+ * Returns the minimum of two vec3's
*
- * @param {vec2} out the receiving vector
- * @param {vec2} a the first operand
- * @param {vec2} b the second operand
- * @returns {vec2} out
+ * @param {vec3} out the receiving vector
+ * @param {vec3} a the first operand
+ * @param {vec3} b the second operand
+ * @returns {vec3} out
*/
function min(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 vec2's
+ * Returns the maximum of two vec3's
*
- * @param {vec2} out the receiving vector
- * @param {vec2} a the first operand
- * @param {vec2} b the second operand
- * @returns {vec2} out
+ * @param {vec3} out the receiving vector
+ * @param {vec3} a the first operand
+ * @param {vec3} b the second operand
+ * @returns {vec3} out
*/
function max(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 vec2
+ * Math.round the components of a vec3
*
- * @param {vec2} out the receiving vector
- * @param {vec2} a vector to round
- * @returns {vec2} out
- */
-function round (out, a) {
- out[0] = Math.round(a[0]);
+ * @param {vec3} out the receiving vector
+ * @param {vec3} a vector to round
+ * @returns {vec3} out
+ */
+function round(out, a) {
+ out[0] = Math.round(a[0]);
out[1] = Math.round(a[1]);
+ out[2] = Math.round(a[2]);
return out;
-};
+}
/**
- * Scales a vec2 by a scalar number
+ * Scales a vec3 by a scalar number
*
- * @param {vec2} out the receiving vector
- * @param {vec2} a the vector to scale
+ * @param {vec3} out the receiving vector
+ * @param {vec3} a the vector to scale
* @param {Number} b amount to scale the vector by
- * @returns {vec2} out
+ * @returns {vec3} out
*/
-function scale(out, a, b) {
+function vec3_scale(out, a, b) {
out[0] = a[0] * b;
out[1] = a[1] * b;
+ out[2] = a[2] * b;
return out;
-};
+}
/**
- * Adds two vec2's after scaling the second operand by a scalar value
+ * Adds two vec3'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 {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 {vec2} out
+ * @returns {vec3} out
*/
function scaleAndAdd(out, a, b, scale) {
- out[0] = a[0] + (b[0] * scale);
- out[1] = a[1] + (b[1] * 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 vec2's
+ * Calculates the euclidian distance between two vec3's
*
- * @param {vec2} a the first operand
- * @param {vec2} b the second operand
+ * @param {vec3} a the first operand
+ * @param {vec3} b the second operand
* @returns {Number} distance between a and b
*/
function distance(a, b) {
- var x = b[0] - a[0],
- y = b[1] - a[1];
- return Math.sqrt(x*x + y*y);
-};
+ var x = b[0] - a[0];
+ var y = b[1] - a[1];
+ var z = b[2] - a[2];
+ return Math.sqrt(x * x + y * y + z * z);
+}
/**
- * Calculates the squared euclidian distance between two vec2's
+ * Calculates the squared euclidian distance between two vec3's
*
- * @param {vec2} a the first operand
- * @param {vec2} b the second operand
+ * @param {vec3} a the first operand
+ * @param {vec3} b the second operand
* @returns {Number} squared distance between a and b
*/
function squaredDistance(a, b) {
- var x = b[0] - a[0],
- y = b[1] - a[1];
- return x*x + y*y;
-};
-
-/**
- * Calculates the length of a vec2
- *
- * @param {vec2} a vector to calculate length of
- * @returns {Number} length of a
- */
-function length(a) {
- var x = a[0],
- y = a[1];
- return Math.sqrt(x*x + y*y);
-};
+ var x = b[0] - a[0];
+ var y = b[1] - a[1];
+ var z = b[2] - a[2];
+ return x * x + y * y + z * z;
+}
/**
- * Calculates the squared length of a vec2
+ * Calculates the squared length of a vec3
*
- * @param {vec2} a vector to calculate squared length of
+ * @param {vec3} a vector to calculate squared length of
* @returns {Number} squared length of a
*/
-function squaredLength (a) {
- var x = a[0],
- y = a[1];
- return x*x + y*y;
-};
+function squaredLength(a) {
+ var x = a[0];
+ var y = a[1];
+ var z = a[2];
+ return x * x + y * y + z * z;
+}
/**
- * Negates the components of a vec2
+ * Negates the components of a vec3
*
- * @param {vec2} out the receiving vector
- * @param {vec2} a vector to negate
- * @returns {vec2} out
+ * @param {vec3} out the receiving vector
+ * @param {vec3} a vector to negate
+ * @returns {vec3} out
*/
function negate(out, a) {
out[0] = -a[0];
out[1] = -a[1];
+ out[2] = -a[2];
return out;
-};
+}
/**
- * Returns the inverse of the components of a vec2
+ * Returns the inverse of the components of a vec3
*
- * @param {vec2} out the receiving vector
- * @param {vec2} a vector to invert
- * @returns {vec2} out
+ * @param {vec3} out the receiving vector
+ * @param {vec3} a vector to invert
+ * @returns {vec3} out
*/
function inverse(out, a) {
out[0] = 1.0 / a[0];
out[1] = 1.0 / a[1];
+ out[2] = 1.0 / a[2];
return out;
-};
+}
/**
- * Normalize a vec2
+ * Normalize a vec3
*
- * @param {vec2} out the receiving vector
- * @param {vec2} a vector to normalize
- * @returns {vec2} out
+ * @param {vec3} out the receiving vector
+ * @param {vec3} a vector to normalize
+ * @returns {vec3} out
*/
function normalize(out, a) {
- var x = a[0],
- y = a[1];
- var len = x*x + y*y;
+ var x = a[0];
+ var y = a[1];
+ var 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 vec2's
+ * Calculates the dot product of two vec3's
*
- * @param {vec2} a the first operand
- * @param {vec2} b the second operand
+ * @param {vec3} a the first operand
+ * @param {vec3} b the second operand
* @returns {Number} dot product of a and b
*/
-function dot(a, b) {
- return a[0] * b[0] + a[1] * b[1];
-};
+function vec3_dot(a, b) {
+ return a[0] * b[0] + a[1] * b[1] + a[2] * b[2];
+}
/**
- * Computes the cross product of two vec2's
- * Note that the cross product must by definition produce a 3D vector
+ * Computes the cross product of two vec3's
*
* @param {vec3} out the receiving vector
- * @param {vec2} a the first operand
- * @param {vec2} b the second operand
+ * @param {vec3} a the first operand
+ * @param {vec3} b the second operand
* @returns {vec3} out
*/
function cross(out, a, b) {
- var z = a[0] * b[1] - a[1] * b[0];
- out[0] = out[1] = 0;
- out[2] = z;
+ var ax = a[0],
+ ay = a[1],
+ az = a[2];
+ var 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 vec2's
+ * Performs a linear interpolation between two vec3'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
+ * @param {vec3} out the receiving vector
+ * @param {vec3} a the first operand
+ * @param {vec3} b the second operand
+ * @param {Number} t interpolation amount, in the range [0-1], between the two inputs
+ * @returns {vec3} out
*/
function lerp(out, a, b, t) {
- var ax = a[0],
- ay = a[1];
+ var ax = a[0];
+ var ay = a[1];
+ var 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;
-};
+}
/**
- * Generates a random vector with the given scale
+ * Performs a hermite interpolation with two control points
*
- * @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
+ * @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, in the range [0-1], between the two inputs
+ * @returns {vec3} out
*/
-function random(out, scale) {
- scale = scale || 1.0;
- var r = __WEBPACK_IMPORTED_MODULE_0__common__["RANDOM"]() * 2.0 * Math.PI;
- out[0] = Math.cos(r) * scale;
- out[1] = Math.sin(r) * scale;
+function hermite(out, a, b, c, d, t) {
+ var factorTimes2 = t * t;
+ var factor1 = factorTimes2 * (2 * t - 3) + 1;
+ var factor2 = factorTimes2 * (t - 2) + t;
+ var factor3 = factorTimes2 * (t - 1);
+ var 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;
-};
+}
/**
- * Transforms the vec2 with a mat2
+ * Performs a bezier interpolation with two control points
*
- * @param {vec2} out the receiving vector
- * @param {vec2} a the vector to transform
- * @param {mat2} m matrix to transform with
- * @returns {vec2} out
+ * @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, in the range [0-1], between the two inputs
+ * @returns {vec3} out
*/
-function transformMat2(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;
+function bezier(out, a, b, c, d, t) {
+ var inverseFactor = 1 - t;
+ var inverseFactorTimesTwo = inverseFactor * inverseFactor;
+ var factorTimes2 = t * t;
+ var factor1 = inverseFactorTimesTwo * inverseFactor;
+ var factor2 = 3 * t * inverseFactorTimesTwo;
+ var factor3 = 3 * factorTimes2 * inverseFactor;
+ var 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;
-};
+}
/**
- * Transforms the vec2 with a mat2d
+ * Generates a random vector with the given scale
*
- * @param {vec2} out the receiving vector
- * @param {vec2} a the vector to transform
- * @param {mat2d} m matrix to transform with
- * @returns {vec2} out
+ * @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
*/
-function transformMat2d(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];
+function random(out, scale) {
+ scale = scale || 1.0;
+
+ var r = RANDOM() * 2.0 * Math.PI;
+ var z = 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 vec2 with a mat3
- * 3rd vector component is implicitly '1'
+ * Transforms the vec3 with a mat4.
+ * 4th 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
+ * @param {vec3} out the receiving vector
+ * @param {vec3} a the vector to transform
+ * @param {mat4} m matrix to transform with
+ * @returns {vec3} out
*/
-function transformMat3(out, a, m) {
+function transformMat4(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];
+ y = a[1],
+ z = a[2];
+ var 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 vec2 with a mat4
- * 3rd vector component is implicitly '0'
- * 4th vector component is implicitly '1'
+ * Transforms the vec3 with a mat3.
*
- * @param {vec2} out the receiving vector
- * @param {vec2} a the vector to transform
- * @param {mat4} m matrix to transform with
- * @returns {vec2} out
+ * @param {vec3} out the receiving vector
+ * @param {vec3} a the vector to transform
+ * @param {mat3} m the 3x3 matrix to transform with
+ * @returns {vec3} out
*/
-function transformMat4(out, a, m) {
- let x = a[0];
- let y = a[1];
- out[0] = m[0] * x + m[4] * y + m[12];
- out[1] = m[1] * x + m[5] * y + m[13];
+function transformMat3(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;
}
/**
- * Returns a string representation of a vector
+ * Transforms the vec3 with a quat
+ * Can also be used for dual quaternions. (Multiply it with the real part)
*
- * @param {vec2} a vector to represent as a string
+ * @param {vec3} out the receiving vector
+ * @param {vec3} a the vector to transform
+ * @param {quat} q quaternion to transform with
+ * @returns {vec3} out
+ */
+function transformQuat(out, a, q) {
+ // benchmarks: https://jsperf.com/quaternion-transform-vec3-implementations-fixed
+ var qx = q[0],
+ qy = q[1],
+ qz = q[2],
+ qw = q[3];
+ var x = a[0],
+ y = a[1],
+ z = a[2];
+ // var qvec = [qx, qy, qz];
+ // var uv = vec3.cross([], qvec, a);
+ var uvx = qy * z - qz * y,
+ uvy = qz * x - qx * z,
+ uvz = qx * y - qy * x;
+ // var uuv = vec3.cross([], qvec, uv);
+ var uuvx = qy * uvz - qz * uvy,
+ uuvy = qz * uvx - qx * uvz,
+ uuvz = qx * uvy - qy * uvx;
+ // vec3.scale(uv, uv, 2 * w);
+ var w2 = qw * 2;
+ uvx *= w2;
+ uvy *= w2;
+ uvz *= w2;
+ // vec3.scale(uuv, uuv, 2);
+ uuvx *= 2;
+ uuvy *= 2;
+ uuvz *= 2;
+ // return vec3.add(out, a, vec3.add(out, uv, uuv));
+ out[0] = x + uvx + uuvx;
+ out[1] = y + uvy + uuvy;
+ out[2] = z + uvz + uuvz;
+ 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
+ */
+function vec3_rotateX(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
+ */
+function vec3_rotateY(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
+ */
+function vec3_rotateZ(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;
+}
+
+/**
+ * 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
+ */
+function angle(a, b) {
+ var tempA = vec3_fromValues(a[0], a[1], a[2]);
+ var tempB = vec3_fromValues(b[0], b[1], b[2]);
+
+ normalize(tempA, tempA);
+ normalize(tempB, tempB);
+
+ var cosine = vec3_dot(tempA, tempB);
+
+ if (cosine > 1.0) {
+ return 0;
+ } else if (cosine < -1.0) {
+ return Math.PI;
+ } 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
*/
-function str(a) {
- return 'vec2(' + a[0] + ', ' + a[1] + ')';
+function vec3_str(a) {
+ return 'vec3(' + a[0] + ', ' + a[1] + ', ' + a[2] + ')';
}
/**
- * Returns whether or not the vectors exactly have the same elements in the same position (when compared with ===)
+ * Returns whether or not the vectors have exactly the same elements in the same position (when compared with ===)
*
- * @param {vec2} a The first vector.
- * @param {vec2} b The second vector.
+ * @param {vec3} a The first vector.
+ * @param {vec3} b The second vector.
* @returns {Boolean} True if the vectors are equal, false otherwise.
*/
-function exactEquals(a, b) {
- return a[0] === b[0] && a[1] === b[1];
+function vec3_exactEquals(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 {vec2} a The first vector.
- * @param {vec2} b The second vector.
+ * @param {vec3} a The first vector.
+ * @param {vec3} b The second vector.
* @returns {Boolean} True if the vectors are equal, false otherwise.
*/
-function equals(a, b) {
- let a0 = a[0], a1 = a[1];
- let b0 = b[0], b1 = b[1];
- return (Math.abs(a0 - b0) <= __WEBPACK_IMPORTED_MODULE_0__common__["EPSILON"]*Math.max(1.0, Math.abs(a0), Math.abs(b0)) &&
- Math.abs(a1 - b1) <= __WEBPACK_IMPORTED_MODULE_0__common__["EPSILON"]*Math.max(1.0, Math.abs(a1), Math.abs(b1)));
+function vec3_equals(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) <= EPSILON * Math.max(1.0, Math.abs(a0), Math.abs(b0)) && Math.abs(a1 - b1) <= EPSILON * Math.max(1.0, Math.abs(a1), Math.abs(b1)) && Math.abs(a2 - b2) <= EPSILON * Math.max(1.0, Math.abs(a2), Math.abs(b2));
}
/**
- * Alias for {@link vec2.length}
+ * Alias for {@link vec3.subtract}
* @function
*/
-const len = length;
-/* harmony export (immutable) */ __webpack_exports__["len"] = len;
-
+var vec3_sub = vec3_subtract;
/**
- * Alias for {@link vec2.subtract}
+ * Alias for {@link vec3.multiply}
* @function
*/
-const sub = subtract;
-/* harmony export (immutable) */ __webpack_exports__["sub"] = sub;
-
+var vec3_mul = vec3_multiply;
/**
- * Alias for {@link vec2.multiply}
+ * Alias for {@link vec3.divide}
* @function
*/
-const mul = multiply;
-/* harmony export (immutable) */ __webpack_exports__["mul"] = mul;
-
+var div = divide;
/**
- * Alias for {@link vec2.divide}
+ * Alias for {@link vec3.distance}
* @function
*/
-const div = divide;
-/* harmony export (immutable) */ __webpack_exports__["div"] = div;
-
+var dist = distance;
/**
- * Alias for {@link vec2.distance}
+ * Alias for {@link vec3.squaredDistance}
* @function
*/
-const dist = distance;
-/* harmony export (immutable) */ __webpack_exports__["dist"] = dist;
-
+var sqrDist = squaredDistance;
/**
- * Alias for {@link vec2.squaredDistance}
+ * Alias for {@link vec3.length}
* @function
*/
-const sqrDist = squaredDistance;
-/* harmony export (immutable) */ __webpack_exports__["sqrDist"] = sqrDist;
-
+var vec3_len = vec3_length;
/**
- * Alias for {@link vec2.squaredLength}
+ * Alias for {@link vec3.squaredLength}
* @function
*/
-const sqrLen = squaredLength;
-/* harmony export (immutable) */ __webpack_exports__["sqrLen"] = sqrLen;
-
+var sqrLen = squaredLength;
/**
- * Perform some operation over an array of vec2s.
+ * 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 vec2. If 0 assumes tightly packed
+ * @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 vec2s to iterate over. If 0 iterates over entire 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
*/
-const forEach = (function() {
- let vec = create();
+var forEach = function () {
+ var vec = vec3_create();
- return function(a, stride, offset, count, fn, arg) {
- let i, l;
- if(!stride) {
- stride = 2;
+ return function (a, stride, offset, count, fn, arg) {
+ var i = void 0,
+ l = void 0;
+ if (!stride) {
+ stride = 3;
}
- if(!offset) {
+ if (!offset) {
offset = 0;
}
- if(count) {
- l = Math.min((count * stride) + offset, a.length);
+ 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];
+ 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] = vec[0];a[i + 1] = vec[1];a[i + 2] = vec[2];
}
return a;
};
-})();
-/* harmony export (immutable) */ __webpack_exports__["forEach"] = forEach;
+}();
+// CONCATENATED MODULE: ../node_modules/gl-matrix/lib/gl-matrix/vec4.js
+/**
+ * 4 Dimensional Vector
+ * @module vec4
+ */
-/***/ }),
-/* 72 */
-/***/ (function(module, exports, __webpack_require__) {
+/**
+ * Creates a new, empty vec4
+ *
+ * @returns {vec4} a new 4D vector
+ */
+function vec4_create() {
+ var out = new ARRAY_TYPE(4);
+ if (ARRAY_TYPE != Float32Array) {
+ out[0] = 0;
+ out[1] = 0;
+ out[2] = 0;
+ out[3] = 0;
+ }
+ return out;
+}
-"use strict";
+/**
+ * Creates a new vec4 initialized with values from an existing vector
+ *
+ * @param {vec4} a vector to clone
+ * @returns {vec4} a new 4D vector
+ */
+function vec4_clone(a) {
+ var out = new 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
+ */
+function vec4_fromValues(x, y, z, w) {
+ var out = new ARRAY_TYPE(4);
+ out[0] = x;
+ out[1] = y;
+ out[2] = z;
+ out[3] = w;
+ return out;
+}
-Object.defineProperty(exports, "__esModule", {
- value: true
-});
-exports.quat = undefined;
+/**
+ * Copy the values from one vec4 to another
+ *
+ * @param {vec4} out the receiving vector
+ * @param {vec4} a the source vector
+ * @returns {vec4} out
+ */
+function vec4_copy(out, a) {
+ out[0] = a[0];
+ out[1] = a[1];
+ out[2] = a[2];
+ out[3] = a[3];
+ return out;
+}
-var _glMatrix = __webpack_require__(11);
+/**
+ * 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
+ */
+function vec4_set(out, x, y, z, w) {
+ out[0] = x;
+ out[1] = y;
+ out[2] = z;
+ out[3] = w;
+ return out;
+}
-exports.quat = _glMatrix.quat;
+/**
+ * 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
+ */
+function vec4_add(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;
+}
-/**
- * QuaternionExp
- *
- * @param {quat} out
- * @param {quat|vec3} a
- * @returns {quat}
+/**
+ * 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
*/
+function vec4_subtract(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;
+}
-_glMatrix.quat.exp = function (out, a) {
- var norm = Math.sqrt(a[0] * a[0] + a[1] * a[1] + a[2] * a[2]);
- if (norm) {
- out[0] = Math.sin(norm) * a[0] / norm;
- out[1] = Math.sin(norm) * a[1] / norm;
- out[2] = Math.sin(norm) * a[2] / norm;
- out[3] = Math.cos(norm);
- } else {
- out[0] = 0.0;
- out[1] = 0.0;
- out[2] = 0.0;
- out[3] = 1.0;
- }
- return out;
-};
-
-/**
- * QuaternionLn
- *
- * @param {quat} out
- * @param {quat} q
- * @returns {quat}
- */
-_glMatrix.quat.ln = function (out, q) {
- var norm = _glMatrix.quat.length(q);
- if (norm > 1.0001 || norm < 0.99999) {
- out[0] = q[0];
- out[1] = q[1];
- out[2] = q[2];
- out[3] = 0.0;
- } else {
- norm = Math.sqrt(q[0] * q[0] + q[1] * q[1] + q[2] * q[2]);
- if (norm) {
- var theta = Math.atan2(norm, q[3]) / norm;
- out[0] = theta * q[0];
- out[1] = theta * q[1];
- out[2] = theta * q[2];
- out[3] = 0.0;
- } else {
- out[0] = 0.0;
- out[1] = 0.0;
- out[2] = 0.0;
- out[3] = 0.0;
- }
- }
- return out;
-};
-
-/**
- * QuaternionPow
- *
- * @param {quat} out
- * @param {quat} inq
- * @param {number} exponent
- * @returns {quat}
- */
-_glMatrix.quat.pow = function (out, inq, exponent) {
- if (exponent === 1) {
- return _glMatrix.quat.copy(out, inq);
- }
-
- _glMatrix.quat.ln(out, inq);
- out[0] *= exponent;
- out[1] *= exponent;
- out[2] *= exponent;
- out[3] *= exponent;
- _glMatrix.quat.exp(out, out);
- return out;
-};
-
-/***/ }),
-/* 73 */
-/***/ (function(module, exports, __webpack_require__) {
-
-"use strict";
-
-
-Object.defineProperty(exports, "__esModule", {
- value: true
-});
-exports.mat3 = undefined;
-
-var _glMatrix = __webpack_require__(11);
-
-exports.mat3 = _glMatrix.mat3;
-
-/***/ }),
-/* 74 */
-/***/ (function(module, exports, __webpack_require__) {
-
-"use strict";
-
+/**
+ * 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
+ */
+function vec4_multiply(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;
+}
-Object.defineProperty(exports, "__esModule", {
- value: true
-});
-exports.mat4 = undefined;
+/**
+ * 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
+ */
+function vec4_divide(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;
+}
-var _glMatrix = __webpack_require__(11);
+/**
+ * Math.ceil the components of a vec4
+ *
+ * @param {vec4} out the receiving vector
+ * @param {vec4} a vector to ceil
+ * @returns {vec4} out
+ */
+function vec4_ceil(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;
+}
-exports.mat4 = _glMatrix.mat4;
+/**
+ * Math.floor the components of a vec4
+ *
+ * @param {vec4} out the receiving vector
+ * @param {vec4} a vector to floor
+ * @returns {vec4} out
+ */
+function vec4_floor(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;
+}
-/**
- * arcFromForward
- * @param {mat4} out
- * @param {vec3} v
- * @return {mat4} 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
*/
+function vec4_min(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;
+}
-_glMatrix.mat4.arcFromForward = function () {
- var vec3_0 = void 0;
+/**
+ * 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
+ */
+function vec4_max(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;
+}
- return function arcFromForward(out, v) {
- if (!vec3_0) vec3_0 = _glMatrix.vec3.create();
+/**
+ * Math.round the components of a vec4
+ *
+ * @param {vec4} out the receiving vector
+ * @param {vec4} a vector to round
+ * @returns {vec4} out
+ */
+function vec4_round(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;
+}
- var norm = _glMatrix.vec3.normalize(vec3_0, v);
- _glMatrix.mat4.identity(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
+ */
+function vec4_scale(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;
+}
- if (norm[2] < -0.99999) {
- 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
+ */
+function vec4_scaleAndAdd(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;
+}
- if (norm[2] > 0.99999) {
- out[5] = -1.0;
- out[10] = -1.0;
- 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
+ */
+function vec4_distance(a, b) {
+ var x = b[0] - a[0];
+ var y = b[1] - a[1];
+ var z = b[2] - a[2];
+ var w = b[3] - a[3];
+ return Math.sqrt(x * x + y * y + z * z + w * w);
+}
- var h = (1 + norm[2]) / (norm[0] * norm[0] + norm[1] * norm[1]);
- out[0] = h * norm[1] * norm[1] - norm[2];
- out[1] = -h * norm[0] * norm[1];
- out[2] = norm[0];
+/**
+ * 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
+ */
+function vec4_squaredDistance(a, b) {
+ var x = b[0] - a[0];
+ var y = b[1] - a[1];
+ var z = b[2] - a[2];
+ var w = b[3] - a[3];
+ return x * x + y * y + z * z + w * w;
+}
- out[4] = out[1];
- out[5] = h * norm[0] * norm[0] - norm[2];
- out[6] = norm[1];
+/**
+ * Calculates the length of a vec4
+ *
+ * @param {vec4} a vector to calculate length of
+ * @returns {Number} length of a
+ */
+function vec4_length(a) {
+ var x = a[0];
+ var y = a[1];
+ var z = a[2];
+ var w = a[3];
+ return Math.sqrt(x * x + y * y + z * z + w * w);
+}
- out[8] = -norm[0];
- out[9] = -norm[1];
- out[10] = -norm[2];
+/**
+ * Calculates the squared length of a vec4
+ *
+ * @param {vec4} a vector to calculate squared length of
+ * @returns {Number} squared length of a
+ */
+function vec4_squaredLength(a) {
+ var x = a[0];
+ var y = a[1];
+ var z = a[2];
+ var w = a[3];
+ return x * x + y * y + z * z + w * w;
+}
- return out;
- };
-}();
+/**
+ * Negates the components of a vec4
+ *
+ * @param {vec4} out the receiving vector
+ * @param {vec4} a vector to negate
+ * @returns {vec4} out
+ */
+function vec4_negate(out, a) {
+ out[0] = -a[0];
+ out[1] = -a[1];
+ out[2] = -a[2];
+ out[3] = -a[3];
+ return out;
+}
-/**
- * Copies the translation component from one mat4 to another
- * @param {mat4} out
- * @param {mat4} a
- * @returns {mat4} 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
*/
-_glMatrix.mat4.copyTranslation = function (out, a) {
- out[12] = a[12];
- out[13] = a[13];
- out[14] = a[14];
- return out;
-};
+function vec4_inverse(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;
+}
-/**
- * Sets a mat4 from a mat4
- * @param {mat4} out
- * @param {mat3} m
- * @returns {mat4} out
- */
-_glMatrix.mat4.fromMat3 = function (out, m) {
- out[0] = m[0];
- out[1] = m[1];
- out[2] = m[2];
- out[4] = m[3];
- out[5] = m[4];
- out[6] = m[5];
- out[8] = m[6];
- out[9] = m[7];
- out[10] = m[8];
- out[3] = out[7] = out[11] = out[12] = out[13] = out[14] = 0;
- out[15] = 1;
- return out;
-};
+/**
+ * Normalize a vec4
+ *
+ * @param {vec4} out the receiving vector
+ * @param {vec4} a vector to normalize
+ * @returns {vec4} out
+ */
+function vec4_normalize(out, a) {
+ var x = a[0];
+ var y = a[1];
+ var z = a[2];
+ var 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;
+}
-/**
- * Generates a look-at matrix with the given eye position, focal point, and up axis from a left handed coordinate system
- *
- * @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
+/**
+ * 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
*/
-_glMatrix.mat4.lookAtGL = function () {
- var vec3_0 = void 0,
- vec3_1 = void 0,
- vec3_2 = void 0;
+function vec4_dot(a, b) {
+ return a[0] * b[0] + a[1] * b[1] + a[2] * b[2] + a[3] * b[3];
+}
- return function lookAtGL(out, eye, center, up) {
- if (!vec3_0) {
- vec3_0 = _glMatrix.vec3.create();
- vec3_1 = _glMatrix.vec3.create();
- vec3_2 = _glMatrix.vec3.create();
- }
+/**
+ * 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, in the range [0-1], between the two inputs
+ * @returns {vec4} out
+ */
+function vec4_lerp(out, a, b, t) {
+ var ax = a[0];
+ var ay = a[1];
+ var az = a[2];
+ var 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;
+}
- _glMatrix.vec3.subtract(vec3_2, eye, center);
-
- if (_glMatrix.vec3.squaredLength(vec3_2) === 0) {
- vec3_2[2] = 1;
- }
-
- _glMatrix.vec3.normalize(vec3_2, vec3_2);
- _glMatrix.vec3.cross(vec3_0, up, vec3_2);
-
- if (_glMatrix.vec3.squaredLength(vec3_0) === 0) {
- vec3_2[2] += 0.0001;
- _glMatrix.vec3.cross(vec3_0, up, vec3_2);
- }
-
- _glMatrix.vec3.normalize(vec3_0, vec3_0);
- _glMatrix.vec3.cross(vec3_1, vec3_2, vec3_0);
-
- out[0] = vec3_0[0];
- out[1] = vec3_0[1];
- out[2] = vec3_0[2];
-
- out[4] = vec3_1[0];
- out[5] = vec3_1[1];
- out[6] = vec3_1[2];
-
- out[8] = vec3_2[0];
- out[9] = vec3_2[1];
- out[10] = vec3_2[2];
-
- 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
+ */
+function vec4_random(out, scale) {
+ scale = scale || 1.0;
-/**
- * Sets a left handed co-ordinate system perspective from a right handed co-ordinate system
- * @param {mat4} out - receiving mat4
- * @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 - receiving mat4
- */
-_glMatrix.mat4.perspectiveGL = function (out, fovY, aspect, near, far) {
- var fH = Math.tan(fovY / 360 * Math.PI) * near;
- var fW = fH * aspect;
- _glMatrix.mat4.frustum(out, -fW, fW, -fH, fH, near, far);
- return out;
-};
+ // Marsaglia, George. Choosing a Point from the Surface of a
+ // Sphere. Ann. Math. Statist. 43 (1972), no. 2, 645--646.
+ // http://projecteuclid.org/euclid.aoms/1177692644;
+ var v1, v2, v3, v4;
+ var s1, s2;
+ do {
+ v1 = RANDOM() * 2 - 1;
+ v2 = RANDOM() * 2 - 1;
+ s1 = v1 * v1 + v2 * v2;
+ } while (s1 >= 1);
+ do {
+ v3 = RANDOM() * 2 - 1;
+ v4 = RANDOM() * 2 - 1;
+ s2 = v3 * v3 + v4 * v4;
+ } while (s2 >= 1);
+
+ var d = Math.sqrt((1 - s1) / s2);
+ out[0] = scale * v1;
+ out[1] = scale * v2;
+ out[2] = scale * v3 * d;
+ out[3] = scale * v4 * d;
+ return out;
+}
-/**
- * Sets the translation component of a mat4 from a vec3
- * @param {mat4} out
- * @param {vec3} v
- * @returns {mat4} 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
*/
-_glMatrix.mat4.setTranslation = function (out, v) {
- out[12] = v[0];
- out[13] = v[1];
- out[14] = v[2];
- return out;
-};
-
-/**
- * Sets the translation component of a mat4 from values
- * @param {mat4} out
- * @param {number} x
- * @param {number} y
- * @param {number} z
- * @returns {mat4} out
- */
-_glMatrix.mat4.setTranslationFromValues = function (out, x, y, z) {
- out[12] = x;
- out[13] = y;
- out[14] = z;
- return out;
-};
+function vec4_transformMat4(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;
+}
-/***/ }),
-/* 75 */
-/***/ (function(module, exports, __webpack_require__) {
+/**
+ * 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
+ */
+function vec4_transformQuat(out, a, q) {
+ var x = a[0],
+ y = a[1],
+ z = a[2];
+ var qx = q[0],
+ qy = q[1],
+ qz = q[2],
+ qw = q[3];
-"use strict";
+ // calculate quat * vec
+ var ix = qw * x + qy * z - qz * y;
+ var iy = qw * y + qz * x - qx * z;
+ var iz = qw * z + qx * y - qy * x;
+ var 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;
+}
-Object.defineProperty(exports, "__esModule", {
- value: true
-});
-exports.noise = undefined;
+/**
+ * Returns a string representation of a vector
+ *
+ * @param {vec4} a vector to represent as a string
+ * @returns {String} string representation of the vector
+ */
+function vec4_str(a) {
+ return 'vec4(' + a[0] + ', ' + a[1] + ', ' + a[2] + ', ' + a[3] + ')';
+}
-var _vec = __webpack_require__(34);
+/**
+ * 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.
+ */
+function vec4_exactEquals(a, b) {
+ return a[0] === b[0] && a[1] === b[1] && a[2] === b[2] && a[3] === b[3];
+}
-var _vec2 = __webpack_require__(35);
+/**
+ * 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.
+ */
+function vec4_equals(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) <= EPSILON * Math.max(1.0, Math.abs(a0), Math.abs(b0)) && Math.abs(a1 - b1) <= EPSILON * Math.max(1.0, Math.abs(a1), Math.abs(b1)) && Math.abs(a2 - b2) <= EPSILON * Math.max(1.0, Math.abs(a2), Math.abs(b2)) && Math.abs(a3 - b3) <= EPSILON * Math.max(1.0, Math.abs(a3), Math.abs(b3));
+}
-var noise = exports.noise = {};
+/**
+ * Alias for {@link vec4.subtract}
+ * @function
+ */
+var vec4_sub = vec4_subtract;
-/**
- * Generates turbulent noise
- *
- * @param {vec4} out
- * @param {number} pos_0
- * @param {number} pos_1
- * @param {number} pos_2
- * @param {number} pos_3
- * @param {number} power
- * @returns {vec4} out
+/**
+ * Alias for {@link vec4.multiply}
+ * @function
*/
-noise.turbulence = function () {
- var s_noiseLookup = [],
- s_permutations = [],
- s_globalNoiseTemps = [];
+var vec4_mul = vec4_multiply;
- var s_initialized = false;
+/**
+ * Alias for {@link vec4.divide}
+ * @function
+ */
+var vec4_div = vec4_divide;
- /**
- * Initializes noise
- */
- function initialize() {
- for (var _i = 0; _i < 256; _i++) {
- s_noiseLookup[_i] = _vec2.vec4.fromValues(Math.random() - 0.5, Math.random() - 0.5, Math.random() - 0.5, Math.random() - 0.5);
- s_permutations[_i] = _i;
- }
+/**
+ * Alias for {@link vec4.distance}
+ * @function
+ */
+var vec4_dist = vec4_distance;
- var i = 256;
- while (--i) {
- var tmp = s_permutations[i],
- index = Math.floor(Math.random() * 256);
+/**
+ * Alias for {@link vec4.squaredDistance}
+ * @function
+ */
+var vec4_sqrDist = vec4_squaredDistance;
- s_permutations[i] = s_permutations[index];
- s_permutations[index] = tmp;
- }
+/**
+ * Alias for {@link vec4.length}
+ * @function
+ */
+var vec4_len = vec4_length;
- for (var _i2 = 0; _i2 < 256; _i2++) {
- s_permutations[256 + _i2] = s_permutations[_i2];
- s_noiseLookup[256 + _i2] = s_noiseLookup[_i2];
- s_noiseLookup[256 * 2 + _i2] = s_noiseLookup[_i2];
- }
+/**
+ * Alias for {@link vec4.squaredLength}
+ * @function
+ */
+var vec4_sqrLen = vec4_squaredLength;
- for (var _i3 = 0; _i3 < 15; ++_i3) {
- s_globalNoiseTemps[_i3] = _vec.vec3.create();
- }
+/**
+ * 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
+ */
+var vec4_forEach = function () {
+ var vec = vec4_create();
- s_initialized = true;
+ return function (a, stride, offset, count, fn, arg) {
+ var i = void 0,
+ l = void 0;
+ if (!stride) {
+ stride = 4;
}
- return function turbulence(out, pos_0, pos_1, pos_2, pos_3, power) {
- if (!s_initialized) initialize();
-
- pos_0 += 4096;
- pos_1 += 4096;
- pos_2 += 4096;
- pos_3 += 4096;
+ if (!offset) {
+ offset = 0;
+ }
- var a_0 = Math.floor(pos_0),
- a_1 = Math.floor(pos_1),
- a_2 = Math.floor(pos_2),
- a_3 = Math.floor(pos_3);
+ if (count) {
+ l = Math.min(count * stride + offset, a.length);
+ } else {
+ l = a.length;
+ }
- var t_0 = pos_0 - a_0,
- t_1 = pos_1 - a_1,
- t_2 = pos_2 - a_2,
- t_3 = pos_3 - a_3;
+ 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];
+ }
- a_0 &= 255;
- a_1 &= 255;
- a_2 &= 255;
- a_3 &= 255;
+ return a;
+ };
+}();
+// CONCATENATED MODULE: ../node_modules/gl-matrix/lib/gl-matrix/quat.js
- var b_0 = a_0 + 1,
- b_1 = a_1 + 1,
- b_2 = a_2 + 1,
- b_3 = a_3 + 1;
- var i = s_permutations[a_0],
- j = s_permutations[b_0];
- var b00 = s_permutations[i + a_1],
- b10 = s_permutations[j + a_1],
- b01 = s_permutations[i + b_1],
- b11 = s_permutations[j + b_1];
- var c00 = _vec.vec3.lerp(s_globalNoiseTemps[0], s_noiseLookup[b00 + a_2 + a_3], s_noiseLookup[b10 + a_2 + a_3], t_0);
- var c10 = _vec.vec3.lerp(s_globalNoiseTemps[1], s_noiseLookup[b01 + a_2 + a_3], s_noiseLookup[b11 + a_2 + a_3], t_0);
- var c01 = _vec.vec3.lerp(s_globalNoiseTemps[2], s_noiseLookup[b00 + b_2 + a_3], s_noiseLookup[b10 + b_2 + a_3], t_0);
- var c11 = _vec.vec3.lerp(s_globalNoiseTemps[3], s_noiseLookup[b00 + b_2 + a_3], s_noiseLookup[b10 + b_2 + a_3], t_0);
- var c0 = _vec.vec3.lerp(s_globalNoiseTemps[4], c00, c10, t_1);
- var c1 = _vec.vec3.lerp(s_globalNoiseTemps[5], c01, c11, t_1);
- var c = _vec.vec3.lerp(s_globalNoiseTemps[6], c0, c1, t_2);
- c00 = _vec.vec3.lerp(s_globalNoiseTemps[7], s_noiseLookup[b00 + a_2 + b_3], s_noiseLookup[b10 + a_2 + b_3], t_0);
- c10 = _vec.vec3.lerp(s_globalNoiseTemps[8], s_noiseLookup[b01 + a_2 + b_3], s_noiseLookup[b11 + a_2 + b_3], t_0);
- c01 = _vec.vec3.lerp(s_globalNoiseTemps[9], s_noiseLookup[b00 + b_2 + b_3], s_noiseLookup[b10 + b_2 + b_3], t_0);
- c11 = _vec.vec3.lerp(s_globalNoiseTemps[10], s_noiseLookup[b00 + b_2 + b_3], s_noiseLookup[b10 + b_2 + b_3], t_0);
- c0 = _vec.vec3.lerp(s_globalNoiseTemps[11], c00, c10, t_1);
- c1 = _vec.vec3.lerp(s_globalNoiseTemps[12], c01, c11, t_1);
- var d = _vec.vec3.lerp(s_globalNoiseTemps[13], c0, c1, t_2);
- var r = _vec.vec3.lerp(s_globalNoiseTemps[14], c, d, t_3);
+/**
+ * Quaternion
+ * @module quat
+ */
- out[0] += r[0] * power;
- out[1] += r[1] * power;
- out[2] += r[2] * power;
- return out;
- };
-}();
+/**
+ * Creates a new identity quat
+ *
+ * @returns {quat} a new quaternion
+ */
+function quat_create() {
+ var out = new ARRAY_TYPE(4);
+ if (ARRAY_TYPE != Float32Array) {
+ out[0] = 0;
+ out[1] = 0;
+ out[2] = 0;
+ }
+ out[3] = 1;
+ return out;
+}
-/**
- * Perlin_noise1
- *
- * @param {number} a
- * @returns {number}
+/**
+ * Set a quat to the identity quaternion
+ *
+ * @param {quat} out the receiving quaternion
+ * @returns {quat} out
*/
-noise.perlin1 = function () {
- var p_initialized = false,
- p_B = 0x100,
- p_BM = 0xff,
- p_N = 0x1000,
- p_p = null,
- p_g1 = null;
+function quat_identity(out) {
+ out[0] = 0;
+ out[1] = 0;
+ out[2] = 0;
+ out[3] = 1;
+ return out;
+}
- /**
- * Initializes Perlin Noise
- */
- function initialize() {
- p_p = new Array(p_B + p_B + 2);
- p_g1 = new Array(p_B + p_B + 2);
+/**
+ * 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
+ **/
+function setAxisAngle(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;
+}
- var i = 0,
- j = 0,
- k = 0;
+/**
+ * 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
+ */
+function getAxisAngle(out_axis, q) {
+ var rad = Math.acos(q[3]) * 2.0;
+ var s = Math.sin(rad / 2.0);
+ if (s > EPSILON) {
+ 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;
+}
- for (i = 0; i < p_B; i++) {
- p_p[i] = i;
- p_g1[i] = Math.random() * 2 - 1;
- }
+/**
+ * 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
+ */
+function quat_multiply(out, a, b) {
+ var ax = a[0],
+ ay = a[1],
+ az = a[2],
+ aw = a[3];
+ var bx = b[0],
+ by = b[1],
+ bz = b[2],
+ bw = b[3];
- while (--i) {
- k = p_p[i];
- p_p[i] = p_p[j = Math.floor(Math.random() * p_B)];
- p_p[j] = k;
- }
+ 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;
+}
- for (i = 0; i < p_B + 2; i++) {
- p_p[p_B + i] = p_p[i];
- p_g1[p_B + i] = p_g1[i];
- }
+/**
+ * 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
+ */
+function quat_rotateX(out, a, rad) {
+ rad *= 0.5;
- p_initialized = true;
- }
+ var ax = a[0],
+ ay = a[1],
+ az = a[2],
+ aw = a[3];
+ var bx = Math.sin(rad),
+ bw = Math.cos(rad);
- return function perlin1(a) {
- if (!p_initialized) initialize();
+ 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;
+}
- var t = a + p_N,
- bx0 = Math.floor(t) & p_BM,
- bx1 = bx0 + 1 & p_BM,
- rx0 = t - Math.floor(t),
- rx1 = rx0 - 1;
-
- var sx = rx0 * rx0 * (3.0 - 2.0 * rx0),
- u = rx0 * p_g1[p_p[bx0]],
- v = rx1 * p_g1[p_p[bx1]];
-
- return u + sx * (v - u);
- };
-}();
-
-/**
- * PerlinNoise1D
- *
- * @param x
- * @param alpha
- * @param beta
- * @param n
- * @returns {number}
+/**
+ * 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
*/
-noise.perlin1D = function (x, alpha, beta, n) {
- var sum = 0,
- p = x,
- scale = 1;
-
- for (var i = 0; i < n; ++i) {
- sum += noise.perlin1(p) / scale;
- scale *= alpha;
- p *= beta;
- }
- return sum;
-};
-
-/***/ }),
-/* 76 */
-/***/ (function(module, exports, __webpack_require__) {
+function quat_rotateY(out, a, rad) {
+ rad *= 0.5;
-"use strict";
+ var ax = a[0],
+ ay = a[1],
+ az = a[2],
+ aw = a[3];
+ var 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;
+}
-Object.defineProperty(exports, "__esModule", {
- value: true
-});
-var curve = exports.curve = {};
-
-/**
- * Evaluates a curve
- *
- * @param {{}|Tw2GeometryCurve} curve
- * @param {Array} curve.knots
- * @param {number} curve.degree
- * @param {Array} curve.controls
- * @param {number} curve.dimension
- * @param {number} time
- * @param {*} value
- * @param {boolean} cycle
- * @param {number} duration
+/**
+ * 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
*/
-curve.evaluate = function (curve, time, value, cycle, duration) {
- var count = curve.knots.length;
- var knot = count - 1;
- var t = 0;
- for (var i = 0; i < curve.knots.length; ++i) {
- if (curve.knots[i] > time) {
- knot = i;
- break;
- }
- }
-
- if (curve.degree === 0) {
- for (var _i = 0; _i < curve.dimension; ++_i) {
- value[_i] = curve.controls[knot * curve.dimension + _i];
- }
- } else if (curve.degree === 1) {
- var knot0 = cycle ? (knot + count - 1) % count : knot === 0 ? 0 : knot - 1;
- var dt = curve.knots[knot] - curve.knots[knot0];
-
- if (dt < 0) {
- dt += duration;
- }
-
- if (dt > 0) {
- t = (time - curve.knots[curve.knots.length - 1]) / dt;
- }
-
- for (var _i2 = 0; _i2 < curve.dimension; ++_i2) {
- value[_i2] = curve.controls[knot0 * curve.dimension + _i2] * (1 - t) + curve.controls[knot * curve.dimension + _i2] * t;
- }
- } else {
- var k_2 = cycle ? (knot + count - 2) % count : knot === 0 ? 0 : knot - 2;
- var k_1 = cycle ? (knot + count - 1) % count : knot === 0 ? 0 : knot - 1;
-
- var p1 = k_2 * curve.dimension;
- var p2 = k_1 * curve.dimension;
- var p3 = knot * curve.dimension;
-
- var ti_2 = curve.knots[k_2];
- var ti_1 = curve.knots[k_1];
- var ti = curve.knots[knot];
- var ti1 = curve.knots[(knot + 1) % count];
-
- if (ti_2 > ti) {
- ti += duration;
- ti1 += duration;
- time += duration;
- }
-
- if (ti_1 > ti) {
- ti += duration;
- ti1 += duration;
- time += duration;
- }
-
- if (ti1 < ti) {
- ti1 += duration;
- }
-
- var tmti_1 = time - ti_1;
- var tmti_2 = time - ti_2;
- var dL0 = ti - ti_1;
- var dL1_1 = ti - ti_2;
- var dL1_2 = ti1 - ti_1;
-
- var L0 = tmti_1 / dL0;
- var L1_1 = tmti_2 / dL1_1;
- var L1_2 = tmti_1 / dL1_2;
+function quat_rotateZ(out, a, rad) {
+ rad *= 0.5;
- var ci_2 = L1_1 + L0 - L0 * L1_1;
- var ci = L0 * L1_2;
- var ci_1 = ci_2 - ci;
- ci_2 = 1 - ci_2;
+ var ax = a[0],
+ ay = a[1],
+ az = a[2],
+ aw = a[3];
+ var bz = Math.sin(rad),
+ bw = Math.cos(rad);
- for (var _i3 = 0; _i3 < curve.dimension; ++_i3) {
- value[_i3] = ci_2 * curve.controls[p1 + _i3] + ci_1 * curve.controls[p2 + _i3] + ci * curve.controls[p3 + _i3];
- }
- }
-};
+ 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;
+}
-/**
- * ag_horner1
- *
- * @param P
- * @param deg
- * @param s
- * @returns {*}
+/**
+ * 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
*/
-curve.ag_horner1 = function (P, deg, s) {
- var h = P[deg];
- while (--deg >= 0) {
- h = s * h + P[deg];
- }return h;
-};
+function calculateW(out, a) {
+ var x = a[0],
+ y = a[1],
+ z = a[2];
-/**
- * ag_zeroin2
- *
- * @param a
- * @param b
- * @param fa
- * @param fb
- * @param tol
- * @param pars
- * @returns {*}
- */
-curve.ag_zeroin2 = function (a, b, fa, fb, tol, pars) {
- var test = void 0;
- var c = void 0,
- d = void 0,
- e = void 0,
- fc = void 0,
- del = void 0,
- m = void 0,
- machtol = void 0,
- p = void 0,
- q = void 0,
- r = void 0,
- s = void 0;
-
- /* initialization */
- machtol = 1.192092896e-07;
- var label1 = true;
-
- /* start iteration */
- while (true) {
- if (label1) {
- c = a;
- fc = fa;
- d = b - a;
- e = d;
- }
-
- if (Math.abs(fc) < Math.abs(fb)) {
- a = b;
- b = c;
- c = a;
- fa = fb;
- fb = fc;
- fc = fa;
- }
- label1 = false;
-
- /* convergence test */
- del = 2.0 * machtol * Math.abs(b) + 0.5 * tol;
- m = 0.5 * (c - b);
- test = Math.abs(m) > del && fb !== 0.0;
- if (test) {
- if (Math.abs(e) < del || Math.abs(fa) <= Math.abs(fb)) {
- /* bisection */
- d = m;
- e = d;
- } else {
- s = fb / fa;
- if (a === c) {
- /* linear interpolation */
- p = 2.0 * m * s;
- q = 1.0 - s;
- } else {
- /* inverse quadratic interpolation */
- q = fa / fc;
- r = fb / fc;
- p = s * (2.0 * m * q * (q - r) - (b - a) * (r - 1.0));
- q = (q - 1.0) * (r - 1.0) * (s - 1.0);
- }
- /* adjust the sign */
- if (p > 0.0) q = -q;else p = -p;
- /* check if interpolation is acceptable */
- s = e;
- e = d;
- if (2.0 * p < 3.0 * m * q - Math.abs(del * q) && p < Math.abs(0.5 * s * q)) {
- d = p / q;
- } else {
- d = m;
- e = d;
- }
- }
- /* complete step */
- a = b;
- fa = fb;
- if (Math.abs(d) > del) b += d;else if (m > 0.0) b += del;else b -= del;
- fb = curve.ag_horner1(pars.p, pars.deg, b);
- if (fb * (fc / Math.abs(fc)) > 0.0) {
- label1 = true;
- }
- } else {
- break;
- }
- }
- return b;
-};
+ 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;
+}
-/**
- * ag_zeroin
- *
- * @param a
- * @param b
- * @param tol
- * @param pars
- * @returns {*}
+/**
+ * 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, in the range [0-1], between the two inputs
+ * @returns {quat} out
*/
-curve.ag_zeroin = function (a, b, tol, pars) {
- var fa = void 0,
- fb = void 0;
-
- fa = curve.ag_horner1(pars.p, pars.deg, a);
- if (Math.abs(fa) < 1.192092896e-07) return a;
+function slerp(out, a, b, t) {
+ // benchmarks:
+ // http://jsperf.com/quaternion-slerp-implementations
+ var ax = a[0],
+ ay = a[1],
+ az = a[2],
+ aw = a[3];
+ var bx = b[0],
+ by = b[1],
+ bz = b[2],
+ bw = b[3];
+
+ var omega = void 0,
+ cosom = void 0,
+ sinom = void 0,
+ scale0 = void 0,
+ scale1 = void 0;
- fb = curve.ag_horner1(pars.p, pars.deg, b);
- if (Math.abs(fb) < 1.192092896e-07) return b;
+ // 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 > EPSILON) {
+ // 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 curve.ag_zeroin2(a, b, fa, fb, tol, pars);
-};
+ return out;
+}
-/**
- * polyZeroes
- *
- * @param Poly
- * @param deg
- * @param a
- * @param a_closed
- * @param b
- * @param b_closed
- * @param Roots
- * @returns {*}
+/**
+ * Generates a random quaternion
+ *
+ * @param {quat} out the receiving quaternion
+ * @returns {quat} out
*/
-curve.polyZeroes = function (Poly, deg, a, a_closed, b, b_closed, Roots) {
- var i = void 0,
- left_ok = void 0,
- right_ok = void 0,
- nr = void 0,
- ndr = void 0,
- skip = void 0;
-
- var e = void 0,
- f = void 0,
- s = void 0,
- pe = void 0,
- ps = void 0,
- tol = void 0,
- p = void 0,
- p_x = new Array(22),
- d = void 0,
- d_x = new Array(22),
- dr = void 0,
- dr_x = new Array(22);
-
- var ply = {
- p: [],
- deg: 0
- };
-
- e = pe = 0.0;
- f = 0.0;
-
- for (i = 0; i < deg + 1; ++i) {
- f += Math.abs(Poly[i]);
- }
- tol = (Math.abs(a) + Math.abs(b)) * (deg + 1) * 1.192092896e-07;
-
- /* Zero polynomial to tolerance? */
- if (f <= tol) return -1;
-
- p = p_x;
- d = d_x;
- dr = dr_x;
- for (i = 0; i < deg + 1; ++i) {
- p[i] = 1.0 / f * Poly[i];
- }
-
- /* determine true degree */
- while (Math.abs(p[deg]) < tol) {
- deg--;
- } /* Identically zero poly already caught so constant fn !== 0 */
- nr = 0;
- if (deg === 0) return nr;
-
- /* check for linear case */
- if (deg === 1) {
- Roots[0] = -p[0] / p[1];
- left_ok = a_closed ? a < Roots[0] + tol : a < Roots[0] - tol;
- right_ok = b_closed ? b > Roots[0] - tol : b > Roots[0] + tol;
- nr = left_ok && right_ok ? 1 : 0;
- if (nr) {
- if (a_closed && Roots[0] < a) Roots[0] = a;else if (b_closed && Roots[0] > b) Roots[0] = b;
- }
- return nr;
- }
- /* handle non-linear case */
- else {
- ply.p = p;
- ply.deg = deg;
-
- /* compute derivative */
- for (i = 1; i <= deg; i++) {
- d[i - 1] = i * p[i];
- } /* find roots of derivative */
- ndr = curve.polyZeroes(d, deg - 1, a, 0, b, 0, dr);
- if (ndr.length === 0) return 0;
-
- /* find roots between roots of the derivative */
- for (i = skip = 0; i <= ndr; i++) {
- if (nr > deg) return nr;
- if (i === 0) {
- s = a;
- ps = curve.ag_horner1(p, deg, s);
- if (Math.abs(ps) <= tol && a_closed) Roots[nr++] = a;
- } else {
- s = e;
- ps = pe;
- }
- if (i === ndr) {
- e = b;
- skip = 0;
- } else e = dr[i];
- pe = curve.ag_horner1(p, deg, e);
- if (skip) skip = 0;else {
- if (Math.abs(pe) < tol) {
- if (i !== ndr || b_closed) {
- Roots[nr++] = e;
- skip = 1;
- }
- } else if (ps < 0 && pe > 0 || ps > 0 && pe < 0) {
- Roots[nr++] = curve.ag_zeroin(s, e, 0.0, ply);
- if (nr > 1 && Roots[nr - 2] >= Roots[nr - 1] - tol) {
- Roots[nr - 2] = (Roots[nr - 2] + Roots[nr - 1]) * 0.5;
- nr--;
- }
- }
- }
- }
- }
-
- return nr;
-};
-
-/***/ }),
-/* 77 */
-/***/ (function(module, exports, __webpack_require__) {
-
-"use strict";
+function quat_random(out) {
+ // Implementation of http://planning.cs.uiuc.edu/node198.html
+ // TODO: Calling random 3 times is probably not the fastest solution
+ var u1 = RANDOM();
+ var u2 = RANDOM();
+ var u3 = RANDOM();
+ var sqrt1MinusU1 = Math.sqrt(1 - u1);
+ var sqrtU1 = Math.sqrt(u1);
-Object.defineProperty(exports, "__esModule", {
- value: true
-});
-var util = exports.util = {};
+ out[0] = sqrt1MinusU1 * Math.sin(2.0 * Math.PI * u2);
+ out[1] = sqrt1MinusU1 * Math.cos(2.0 * Math.PI * u2);
+ out[2] = sqrtU1 * Math.sin(2.0 * Math.PI * u3);
+ out[3] = sqrtU1 * Math.cos(2.0 * Math.PI * u3);
+ return out;
+}
-/**
- * Adds arguments to an array if they don't already exist in it
- * @param {Array} arr
- * @param args
- * @returns {boolean} true if something was added
+/**
+ * Calculates the inverse of a quat
+ *
+ * @param {quat} out the receiving quaternion
+ * @param {quat} a quat to calculate inverse of
+ * @returns {quat} out
*/
-util.addToArray = function (arr) {
- var added = false;
-
- for (var _len = arguments.length, args = Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
- args[_key - 1] = arguments[_key];
- }
+function quat_invert(out, a) {
+ var a0 = a[0],
+ a1 = a[1],
+ a2 = a[2],
+ a3 = a[3];
+ var dot = a0 * a0 + a1 * a1 + a2 * a2 + a3 * a3;
+ var invDot = dot ? 1.0 / dot : 0;
- for (var i = 0; i < args.length; i++) {
- if (arr.indexOf(args[i]) !== -1) {
- arr.push(args[i]);
- added = true;
- }
- }
- return added;
-};
+ // TODO: Would be faster to return [0,0,0,0] immediately if dot == 0
-/**
- * Assigns property values if they exist in a source object
- * - Typed arrays are cloned/ copied to ensure no pass-by-reference errors
- *
- * @param {*} dest
- * @param {*} src
- * @param {string|string[]} attrs
- */
-util.assignIfExists = function (dest, src, attrs) {
- if (!src) return;
-
- attrs = util.toArray(attrs);
- for (var i = 0; i < attrs.length; i++) {
- var attr = attrs[i];
- if (src[attr] !== undefined) {
- if (util.isTyped(dest[attr])) {
- if (dest[attr].length !== src[attr].length) {
- dest[attr] = new dest[attr]['constructor'](src[attr]);
- } else {
- dest[attr].set(src[attr]);
- }
- } else if (util.isTyped(src[attr])) {
- dest[attr] = new src[attr]['constructor'](src[attr]);
- } else {
- dest[attr] = src[attr];
- }
- }
- }
-};
+ out[0] = -a0 * invDot;
+ out[1] = -a1 * invDot;
+ out[2] = -a2 * invDot;
+ out[3] = a3 * invDot;
+ return out;
+}
-/**
- * Identifies if UUIDs should be used for ID generation
- * @type {?boolean}
+/**
+ * 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
*/
-var USE_UUID = null;
+function conjugate(out, a) {
+ out[0] = -a[0];
+ out[1] = -a[1];
+ out[2] = -a[2];
+ out[3] = a[3];
+ return out;
+}
-/**
- * Generates an object id
- * @returns {number}
- * @private
+/**
+ * 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
*/
-var _generateObjectID = function () {
- var OBJECT_COUNT = 0;
- return function _generateObjectID() {
- return OBJECT_COUNT++;
- };
-}();
+function fromMat3(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 = void 0;
-/**
- * Generates a UUID
- * @author Three.js
- * @returns {string}
- * @private
- */
-var _generateUUID = function () {
- var lut = [];
- for (var i = 0; i < 256; i++) {
- lut[i] = (i < 16 ? '0' : '') + i.toString(16).toUpperCase();
- }
+ 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;
- return function _generateUUID() {
- var d0 = Math.random() * 0xffffffff | 0,
- d1 = Math.random() * 0xffffffff | 0,
- d2 = Math.random() * 0xffffffff | 0,
- d3 = Math.random() * 0xffffffff | 0;
+ 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 lut[d0 & 0xff] + lut[d0 >> 8 & 0xff] + lut[d0 >> 16 & 0xff] + lut[d0 >> 24 & 0xff] + '-' + lut[d1 & 0xff] + lut[d1 >> 8 & 0xff] + '-' + lut[d1 >> 16 & 0x0f | 0x40] + lut[d1 >> 24 & 0xff] + '-' + lut[d2 & 0x3f | 0x80] + lut[d2 >> 8 & 0xff] + '-' + lut[d2 >> 16 & 0xff] + lut[d2 >> 24 & 0xff] + lut[d3 & 0xff] + lut[d3 >> 8 & 0xff] + lut[d3 >> 16 & 0xff] + lut[d3 >> 24 & 0xff];
- };
-}();
+ return out;
+}
-/**
- * Enables UUID's for ID generation
- * @param {boolean} bool
- * @throws When generateID have already been used and trying to set a different ID type
+/**
+ * Creates a quaternion from the given euler angle x, y, z.
+ *
+ * @param {quat} out the receiving quaternion
+ * @param {x} Angle to rotate around X axis in degrees.
+ * @param {y} Angle to rotate around Y axis in degrees.
+ * @param {z} Angle to rotate around Z axis in degrees.
+ * @returns {quat} out
+ * @function
*/
-util.enableUUID = function (bool) {
- if (USE_UUID !== null && bool !== USE_UUID) {
- throw new Error('Cannot change id generation type once used');
- }
- USE_UUID = bool;
-};
+function fromEuler(out, x, y, z) {
+ var halfToRad = 0.5 * Math.PI / 180.0;
+ x *= halfToRad;
+ y *= halfToRad;
+ z *= halfToRad;
+
+ var sx = Math.sin(x);
+ var cx = Math.cos(x);
+ var sy = Math.sin(y);
+ var cy = Math.cos(y);
+ var sz = Math.sin(z);
+ var cz = Math.cos(z);
+
+ out[0] = sx * cy * cz - cx * sy * sz;
+ out[1] = cx * sy * cz + sx * cy * sz;
+ out[2] = cx * cy * sz - sx * sy * cz;
+ out[3] = cx * cy * cz + sx * sy * sz;
-/**
- * Generates an id
- * - Defaults to Object IDs
- * @returns {string|number}
- */
-util.generateID = function () {
- if (USE_UUID === null) USE_UUID = false;
- return USE_UUID ? _generateUUID() : _generateObjectID();
-};
+ return out;
+}
-/**
- * Gets a source's property value if it exists else returns a default value
- * @param {*} src
- * @param {string} prop
- * @param {*} defaultValue
- * @returns {*}
+/**
+ * Returns a string representation of a quatenion
+ *
+ * @param {quat} a vector to represent as a string
+ * @returns {String} string representation of the vector
*/
-util.get = function (src, prop, defaultValue) {
- return src && prop in src ? src[prop] : defaultValue;
-};
+function quat_str(a) {
+ return 'quat(' + a[0] + ', ' + a[1] + ', ' + a[2] + ', ' + a[3] + ')';
+}
-/**
- * Checks if a value is an array
- * @param {*} a
- * @returns {boolean}
+/**
+ * Creates a new quat initialized with values from an existing quaternion
+ *
+ * @param {quat} a quaternion to clone
+ * @returns {quat} a new quaternion
+ * @function
*/
-util.isArray = Array.isArray;
+var quat_clone = vec4_clone;
-/**
- * Checks if a value is array like
- * @param {*} a
- * @returns {boolean}
+/**
+ * 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
*/
-util.isArrayLike = function (a) {
- return a ? util.isArray(a) || util.isTyped(a) : false;
-};
+var quat_fromValues = vec4_fromValues;
-/**
- * Checks if a value is a vector
- * @param {*} a
- * @returns {boolean}
+/**
+ * Copy the values from one quat to another
+ *
+ * @param {quat} out the receiving quaternion
+ * @param {quat} a the source quaternion
+ * @returns {quat} out
+ * @function
*/
-util.isVector = function (a) {
- if (a) {
- if (util.isTyped(a)) {
- return true;
- }
-
- if (util.isArray(a)) {
- for (var i = 0; i < a.length; i++) {
- if (typeof a[i] !== 'number') return false;
- }
- return true;
- }
- }
- return false;
-};
+var quat_copy = vec4_copy;
-/**
- * Checks if a value is a typed array
- * @param {*} a
- * @returns {boolean}
+/**
+ * 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
*/
-util.isTyped = function (a) {
- return a ? !!(a.buffer instanceof ArrayBuffer && a.BYTES_PER_ELEMENT) : false;
-};
+var quat_set = vec4_set;
-/**
- * Calls a function with arguments for each child in an array where that function exists
- * @param {Array} arr
- * @param {string} func
- * @param args
+/**
+ * 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
*/
-util.perArrayChild = function (arr, func) {
- var len = arr.length;
-
- for (var _len2 = arguments.length, args = Array(_len2 > 2 ? _len2 - 2 : 0), _key2 = 2; _key2 < _len2; _key2++) {
- args[_key2 - 2] = arguments[_key2];
- }
-
- for (var i = 0; i < len; i++) {
- var _arr$i;
-
- if (func in arr) (_arr$i = arr[i])[func].apply(_arr$i, args);
- }
-};
+var quat_add = vec4_add;
-/**
- * Removes arguments from an array if they exist in it
- * @param {Array} arr
- * @param args
- * @returns {boolean} true if something was removed
+/**
+ * Alias for {@link quat.multiply}
+ * @function
*/
-util.removeFromArray = function (arr) {
- var removed = false;
+var quat_mul = quat_multiply;
- for (var _len3 = arguments.length, args = Array(_len3 > 1 ? _len3 - 1 : 0), _key3 = 1; _key3 < _len3; _key3++) {
- args[_key3 - 1] = arguments[_key3];
- }
+/**
+ * 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
+ */
+var quat_scale = vec4_scale;
- for (var i = 0; i < args.length; i++) {
- var index = arr.indexOf(args[i]);
- if (index !== -1) {
- arr.splice(index, 1);
- removed = true;
- }
- }
- return removed;
-};
+/**
+ * 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
+ */
+var quat_dot = vec4_dot;
-/**
- * Returns a value if it is an array, or a new array with the object in it
- * @param {*} a
- * @returns {Array}
+/**
+ * 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, in the range [0-1], between the two inputs
+ * @returns {quat} out
+ * @function
*/
-util.toArray = function (a) {
- return Array.isArray(a) ? a : [a];
-};
+var quat_lerp = vec4_lerp;
-/***/ }),
-/* 78 */
-/***/ (function(module, exports, __webpack_require__) {
+/**
+ * Calculates the length of a quat
+ *
+ * @param {quat} a vector to calculate length of
+ * @returns {Number} length of a
+ */
+var quat_length = vec4_length;
-"use strict";
+/**
+ * Alias for {@link quat.length}
+ * @function
+ */
+var 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
+ */
+var quat_squaredLength = vec4_squaredLength;
-Object.defineProperty(exports, "__esModule", {
- value: true
-});
-exports.Tw2MotherLode = undefined;
+/**
+ * Alias for {@link quat.squaredLength}
+ * @function
+ */
+var quat_sqrLen = quat_squaredLength;
-var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
+/**
+ * Normalize a quat
+ *
+ * @param {quat} out the receiving quaternion
+ * @param {quat} a quaternion to normalize
+ * @returns {quat} out
+ * @function
+ */
+var quat_normalize = vec4_normalize;
-var _Tw2Logger = __webpack_require__(4);
+/**
+ * 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.
+ */
+var quat_exactEquals = vec4_exactEquals;
-function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
+/**
+ * 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.
+ */
+var quat_equals = vec4_equals;
-/**
- * Manages loaded resources
- *
- * @property {Object} _loadedObjects - loaded resources
- * @property {{string:Array}} _errors - Not implemented yet
- * @class
+/**
+ * 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
*/
-var Tw2MotherLode = exports.Tw2MotherLode = function () {
- function Tw2MotherLode() {
- _classCallCheck(this, Tw2MotherLode);
+var rotationTo = function () {
+ var tmpvec3 = vec3_create();
+ var xUnitVec3 = vec3_fromValues(1, 0, 0);
+ var yUnitVec3 = vec3_fromValues(0, 1, 0);
- this._loadedObjects = {};
- this._errors = {};
+ return function (out, a, b) {
+ var dot = vec3_dot(a, b);
+ if (dot < -0.999999) {
+ cross(tmpvec3, xUnitVec3, a);
+ if (vec3_len(tmpvec3) < 0.000001) cross(tmpvec3, yUnitVec3, a);
+ normalize(tmpvec3, tmpvec3);
+ 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 {
+ 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);
}
+ };
+}();
- /**
- * Adds an error log for a given path
- * @param {string} path
- * @param {eventLog} log
- */
-
-
- _createClass(Tw2MotherLode, [{
- key: 'AddError',
- value: function AddError(path, log) {
- this._errors[path] = this._errors[path] || [];
- if (!this._errors[path].includes(log)) {
- this._errors[path].push(log);
- }
- }
-
- /**
- * Gets a path's error logs
- * @param {string} path
- * @returns {?Array}
- */
-
- }, {
- key: 'GetErrors',
- value: function GetErrors(path) {
- return path && path in this._errors ? Object.assign([], this._errors[path]) : null;
- }
-
- /**
- * Finds a loaded object by it's file path
- * @param {string} path
- * @returns {Tw2LoadingObject}
- */
-
- }, {
- key: 'Find',
- value: function Find(path) {
- if (path in this._loadedObjects) {
- return this._loadedObjects[path];
- }
- return null;
- }
-
- /**
- * Adds a loaded object
- * @param {string} path
- * @param {Tw2LoadingObject} obj
- */
-
- }, {
- key: 'Add',
- value: function Add(path, obj) {
- this._loadedObjects[path] = obj;
- }
+/**
+ * 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, in the range [0-1], between the two inputs
+ * @returns {quat} out
+ */
+var sqlerp = function () {
+ var temp1 = quat_create();
+ var temp2 = quat_create();
- /**
- * Removes a loaded object by it's file path
- * @param {string} path
- */
+ return function (out, a, b, c, d, t) {
+ slerp(temp1, a, d, t);
+ slerp(temp2, b, c, t);
+ slerp(out, temp1, temp2, 2 * t * (1 - t));
- }, {
- key: 'Remove',
- value: function Remove(path) {
- delete this._loadedObjects[path];
- }
+ return out;
+ };
+}();
- /**
- * Clears the loaded object object
- */
+/**
+ * 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
+ */
+var setAxes = function () {
+ var matr = create();
- }, {
- key: 'Clear',
- value: function Clear() {
- this._loadedObjects = {};
- }
+ return function (out, view, right, up) {
+ matr[0] = right[0];
+ matr[3] = right[1];
+ matr[6] = right[2];
- /**
- * Unloads all loaded objects and then clears the loadedObject object
- */
+ matr[1] = up[0];
+ matr[4] = up[1];
+ matr[7] = up[2];
- }, {
- key: 'UnloadAndClear',
- value: function UnloadAndClear() {
- for (var path in this._loadedObjects) {
- if (this._loadedObjects.hasOwnProperty(path)) {
- this._loadedObjects[path].Unload();
- }
- }
- this._loadedObjects = {};
- }
-
- /**
- * Purges inactive loaded objects (resources that have been loaded but are not being actively used)
- * - Loaded objects can flagged with `doNotPurge` to ensure they are never removed
- * - Resource auto purging can be managed in `ccpwgl` or `ccpwgl_int.resMan` - {@link Tw2ResMan}
- * ccpwgl.setResourceUnloadPolicy()
- * ccpwgl_int.resMan.autoPurgeResources=true
- * ccpwgl_int.resMan.purgeTime=30
- * @param {Number} curFrame - the current frame count
- * @param {Number} frameLimit - how many frames the object can stay alive for before being purged
- * @param {Number} frameDistance - how long the resource has been alive for
- */
-
- }, {
- key: 'PurgeInactive',
- value: function PurgeInactive(curFrame, frameLimit, frameDistance) {
- for (var path in this._loadedObjects) {
- if (this._loadedObjects.hasOwnProperty(path)) {
- var res = this._loadedObjects[path];
- if (!res.doNotPurge) {
- if (res._isPurged) {
- _Tw2Logger.logger.log('res.event', {
- msg: 'Unloaded ',
- path: res.path,
- type: 'purged'
- });
-
- delete this._loadedObjects[path];
- }
- if (res._isGood && (curFrame - res.activeFrame) % frameLimit >= frameDistance) {
- if (res.Unload()) {
- _Tw2Logger.logger.log('res.event', {
- msg: 'Unloaded ',
- path: res.path,
- type: 'unused'
- });
- delete this._loadedObjects[path];
- }
- }
- }
- }
- }
- }
- }]);
+ matr[2] = -view[0];
+ matr[5] = -view[1];
+ matr[8] = -view[2];
- return Tw2MotherLode;
+ return quat_normalize(out, fromMat3(out, matr));
+ };
}();
+// CONCATENATED MODULE: ../node_modules/gl-matrix/lib/gl-matrix/vec2.js
-/***/ }),
-/* 79 */
-/***/ (function(module, exports, __webpack_require__) {
-
-"use strict";
+/**
+ * 2 Dimensional Vector
+ * @module vec2
+ */
-Object.defineProperty(exports, "__esModule", {
- value: true
-});
-exports.Tw2SamplerOverride = undefined;
+/**
+ * Creates a new, empty vec2
+ *
+ * @returns {vec2} a new 2D vector
+ */
+function vec2_create() {
+ var out = new ARRAY_TYPE(2);
+ if (ARRAY_TYPE != Float32Array) {
+ out[0] = 0;
+ out[1] = 0;
+ }
+ return out;
+}
-var _Tw2Device = __webpack_require__(2);
+/**
+ * Creates a new vec2 initialized with values from an existing vector
+ *
+ * @param {vec2} a vector to clone
+ * @returns {vec2} a new 2D vector
+ */
+function vec2_clone(a) {
+ var out = new ARRAY_TYPE(2);
+ out[0] = a[0];
+ out[1] = a[1];
+ return out;
+}
-var _Tw2SamplerState = __webpack_require__(42);
+/**
+ * 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
+ */
+function vec2_fromValues(x, y) {
+ var out = new ARRAY_TYPE(2);
+ out[0] = x;
+ out[1] = y;
+ return out;
+}
-function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
-
-/**
- * Tw2SamplerOverride
- *
- * @property {number} addressU
- * @property {number} addressV
- * @property {number} addressW
- * @property {number} filter
- * @property {number} mipFilter
- * @property {number} lodBias
- * @property {number} maxMipLevel
- * @property {number} maxAnisotropy
- * @class
- */
-var Tw2SamplerOverride = exports.Tw2SamplerOverride = function Tw2SamplerOverride() {
- _classCallCheck(this, Tw2SamplerOverride);
-
- this.name = '';
- this.addressU = 0;
- this.addressV = 0;
- this.addressW = 0;
- this.filter = 0;
- this.mipFilter = 0;
- this.lodBias = 0;
- this.maxMipLevel = 0;
- this.maxAnisotropy = 0;
-
- var sampler = null;
-
- /**
- * Gets the sampler
- * @param originalSampler
- * @returns {Tw2SamplerState}
- */
- this.GetSampler = function (originalSampler) {
- if (!sampler) {
- sampler = new _Tw2SamplerState.Tw2SamplerState();
- sampler.registerIndex = originalSampler.registerIndex;
- sampler.name = originalSampler.name;
-
- if (this.filter === 1) {
- switch (this.mipFilter) {
- case 0:
- sampler.minFilter = _Tw2Device.device.gl.NEAREST;
- break;
-
- case 1:
- sampler.minFilter = _Tw2Device.device.gl.NEAREST_MIPMAP_NEAREST;
- break;
-
- default:
- sampler.minFilter = _Tw2Device.device.gl.NEAREST_MIPMAP_LINEAR;
- }
-
- sampler.minFilterNoMips = _Tw2Device.device.gl.NEAREST;
- } else {
- switch (this.mipFilter) {
- case 0:
- sampler.minFilter = _Tw2Device.device.gl.LINEAR;
- break;
+/**
+ * Copy the values from one vec2 to another
+ *
+ * @param {vec2} out the receiving vector
+ * @param {vec2} a the source vector
+ * @returns {vec2} out
+ */
+function vec2_copy(out, a) {
+ out[0] = a[0];
+ out[1] = a[1];
+ return out;
+}
- case 1:
- sampler.minFilter = _Tw2Device.device.gl.LINEAR_MIPMAP_NEAREST;
- break;
+/**
+ * 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
+ */
+function vec2_set(out, x, y) {
+ out[0] = x;
+ out[1] = y;
+ return out;
+}
- default:
- sampler.minFilter = _Tw2Device.device.gl.LINEAR_MIPMAP_LINEAR;
- }
+/**
+ * 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
+ */
+function vec2_add(out, a, b) {
+ out[0] = a[0] + b[0];
+ out[1] = a[1] + b[1];
+ return out;
+}
- sampler.minFilterNoMips = _Tw2Device.device.gl.LINEAR;
- }
+/**
+ * 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
+ */
+function vec2_subtract(out, a, b) {
+ out[0] = a[0] - b[0];
+ out[1] = a[1] - b[1];
+ return out;
+}
- if (this.filter === 3 || this.mipFilter === 3) {
- sampler.anisotropy = Math.max(this.maxAnisotropy, 1);
- }
+/**
+ * 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
+ */
+function vec2_multiply(out, a, b) {
+ out[0] = a[0] * b[0];
+ out[1] = a[1] * b[1];
+ return out;
+}
- sampler.magFilter = this.filter === 1 ? _Tw2Device.device.gl.NEAREST : _Tw2Device.device.gl.LINEAR;
- sampler.addressU = _Tw2Device.device.wrapModes[this.addressU];
- sampler.addressV = _Tw2Device.device.wrapModes[this.addressV];
- sampler.addressW = _Tw2Device.device.wrapModes[this.addressW];
- sampler.samplerType = originalSampler.samplerType;
- sampler.isVolume = originalSampler.isVolume;
- sampler.ComputeHash();
- }
+/**
+ * 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
+ */
+function vec2_divide(out, a, b) {
+ out[0] = a[0] / b[0];
+ out[1] = a[1] / b[1];
+ return out;
+}
- return sampler;
- };
-};
+/**
+ * Math.ceil the components of a vec2
+ *
+ * @param {vec2} out the receiving vector
+ * @param {vec2} a vector to ceil
+ * @returns {vec2} out
+ */
+function vec2_ceil(out, a) {
+ out[0] = Math.ceil(a[0]);
+ out[1] = Math.ceil(a[1]);
+ return out;
+}
-/***/ }),
-/* 80 */
-/***/ (function(module, exports, __webpack_require__) {
+/**
+ * Math.floor the components of a vec2
+ *
+ * @param {vec2} out the receiving vector
+ * @param {vec2} a vector to floor
+ * @returns {vec2} out
+ */
+function vec2_floor(out, a) {
+ out[0] = Math.floor(a[0]);
+ out[1] = Math.floor(a[1]);
+ return out;
+}
-"use strict";
+/**
+ * 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
+ */
+function vec2_min(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
+ */
+function vec2_max(out, a, b) {
+ out[0] = Math.max(a[0], b[0]);
+ out[1] = Math.max(a[1], b[1]);
+ return out;
+}
-Object.defineProperty(exports, "__esModule", {
- value: true
-});
-exports.Tw2VertexDeclaration = undefined;
+/**
+ * Math.round the components of a vec2
+ *
+ * @param {vec2} out the receiving vector
+ * @param {vec2} a vector to round
+ * @returns {vec2} out
+ */
+function vec2_round(out, a) {
+ out[0] = Math.round(a[0]);
+ out[1] = Math.round(a[1]);
+ return out;
+}
-var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
+/**
+ * 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
+ */
+function vec2_scale(out, a, b) {
+ out[0] = a[0] * b;
+ out[1] = a[1] * b;
+ return out;
+}
-var _Tw2Device = __webpack_require__(2);
+/**
+ * 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
+ */
+function vec2_scaleAndAdd(out, a, b, scale) {
+ out[0] = a[0] + b[0] * scale;
+ out[1] = a[1] + b[1] * scale;
+ return out;
+}
-var _Tw2VertexElement = __webpack_require__(43);
+/**
+ * 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
+ */
+function vec2_distance(a, b) {
+ var x = b[0] - a[0],
+ y = b[1] - a[1];
+ return Math.sqrt(x * x + y * y);
+}
-function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
+/**
+ * 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
+ */
+function vec2_squaredDistance(a, b) {
+ var x = b[0] - a[0],
+ y = b[1] - a[1];
+ return x * x + y * y;
+}
-/**
- * Tw2VertexDeclaration
- *
- * @param {Array} [declarations]
- * @param {number} [stride]
- * @property {Array.} elements
- * @property {Array.} _elementsSorted
- * @class
+/**
+ * Calculates the length of a vec2
+ *
+ * @param {vec2} a vector to calculate length of
+ * @returns {Number} length of a
*/
-var Tw2VertexDeclaration = exports.Tw2VertexDeclaration = function () {
- function Tw2VertexDeclaration(declarations, stride) {
- _classCallCheck(this, Tw2VertexDeclaration);
+function vec2_length(a) {
+ var x = a[0],
+ y = a[1];
+ return Math.sqrt(x * x + y * y);
+}
- this.elements = [];
- this._elementsSorted = [];
+/**
+ * Calculates the squared length of a vec2
+ *
+ * @param {vec2} a vector to calculate squared length of
+ * @returns {Number} squared length of a
+ */
+function vec2_squaredLength(a) {
+ var x = a[0],
+ y = a[1];
+ return x * x + y * y;
+}
- if (stride !== undefined) {
- this.stride = stride;
- }
+/**
+ * Negates the components of a vec2
+ *
+ * @param {vec2} out the receiving vector
+ * @param {vec2} a vector to negate
+ * @returns {vec2} out
+ */
+function vec2_negate(out, a) {
+ out[0] = -a[0];
+ out[1] = -a[1];
+ return out;
+}
- if (declarations) {
- this.DeclareFromObject(declarations);
- }
- }
+/**
+ * Returns the inverse of the components of a vec2
+ *
+ * @param {vec2} out the receiving vector
+ * @param {vec2} a vector to invert
+ * @returns {vec2} out
+ */
+function vec2_inverse(out, a) {
+ out[0] = 1.0 / a[0];
+ out[1] = 1.0 / a[1];
+ return out;
+}
- /**
- * Re-sorts elements
- */
+/**
+ * Normalize a vec2
+ *
+ * @param {vec2} out the receiving vector
+ * @param {vec2} a vector to normalize
+ * @returns {vec2} out
+ */
+function vec2_normalize(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
+ */
+function vec2_dot(a, b) {
+ return a[0] * b[0] + a[1] * b[1];
+}
- _createClass(Tw2VertexDeclaration, [{
- key: 'RebuildHash',
- value: function RebuildHash() {
- this._elementsSorted = [];
- for (var i = 0; i < this.elements.length; ++i) {
- this._elementsSorted[i] = this.elements[i];
- }
- this._elementsSorted.sort(Tw2VertexDeclaration.CompareDeclarationElements);
- }
-
- /**
- * Finds an element by it's usage type and usage index
- * @param {number} usage
- * @param {number} usageIndex
- * @returns {Tw2VertexElement|null}
- */
-
- }, {
- key: 'FindUsage',
- value: function FindUsage(usage, usageIndex) {
- for (var i = 0; i < this._elementsSorted.length; ++i) {
- var e = this._elementsSorted[i];
- if (e.usage === usage) {
- if (e.usageIndex === usageIndex) {
- return e;
- } else if (e.usageIndex > usageIndex) {
- return null;
- }
- }
-
- if (e.usage > usage) {
- return null;
- }
- }
- return null;
- }
-
- /**
- * SetDeclaration
- * @param {Tw2VertexDeclaration} inputDecl
- * @param {number} stride
- * @returns {boolean}
- */
-
- }, {
- key: 'SetDeclaration',
- value: function SetDeclaration(inputDecl, stride) {
- var index = 0;
- for (var i = 0; i < inputDecl._elementsSorted.length; ++i) {
- var el = inputDecl._elementsSorted[i];
- if (el.location < 0) continue;
-
- while (true) {
- if (index >= this._elementsSorted.length) {
- _Tw2Device.device.gl.disableVertexAttribArray(el.location);
- _Tw2Device.device.gl.vertexAttrib4f(el.location, 0, 0, 0, 0);
- break;
- }
-
- var input = this._elementsSorted[index],
- cmp = Tw2VertexDeclaration.CompareDeclarationElements(input, el);
-
- if (cmp > 0) {
- _Tw2Device.device.gl.disableVertexAttribArray(el.location);
- _Tw2Device.device.gl.vertexAttrib4f(el.location, 0, 0, 0, 0);
- break;
- }
+/**
+ * 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
+ */
+function vec2_cross(out, a, b) {
+ var z = a[0] * b[1] - a[1] * b[0];
+ out[0] = out[1] = 0;
+ out[2] = z;
+ return out;
+}
- if (cmp === 0) {
- if (input.customSetter) {
- input.customSetter(el);
- } else {
- _Tw2Device.device.gl.enableVertexAttribArray(el.location);
- _Tw2Device.device.gl.vertexAttribPointer(el.location, input.elements, input.type, false, stride, input.offset);
- }
- break;
- }
- index++;
- }
- }
- return true;
- }
-
- /**
- * SetPartialDeclaration
- * @param {Tw2VertexDeclaration} inputDecl
- * @param {number} stride
- * @param {number} [usageOffset=0]
- * @param {number} [divisor=0]
- * @returns {Array} ResetData
- */
-
- }, {
- key: 'SetPartialDeclaration',
- value: function SetPartialDeclaration(inputDecl, stride) {
- var usageOffset = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 0;
- var divisor = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 0;
-
- var resetData = [];
-
- var index = 0;
- for (var i = 0; i < inputDecl._elementsSorted.length; ++i) {
- var el = inputDecl._elementsSorted[i];
- if (el.location < 0) continue;
-
- while (true) {
- var input = this._elementsSorted[index],
- cmp = Tw2VertexDeclaration.CompareDeclarationElements(input, el, usageOffset);
-
- if (cmp === 0) {
- if (input.customSetter) {
- input.customSetter(el);
- } else {
- _Tw2Device.device.gl.enableVertexAttribArray(el.location);
- _Tw2Device.device.gl.vertexAttribPointer(el.location, input.elements, input.type, false, stride, input.offset);
- _Tw2Device.device.ext.vertexAttribDivisor(el.location, divisor);
-
- if (divisor) {
- resetData.push(el.location);
- }
- }
- break;
- } else if (cmp > 0) {
- if (!divisor) {
- _Tw2Device.device.gl.disableVertexAttribArray(el.location);
- _Tw2Device.device.gl.vertexAttrib4f(el.location, 0, 0, 0, 0);
- }
- break;
- }
+/**
+ * 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, in the range [0-1], between the two inputs
+ * @returns {vec2} out
+ */
+function vec2_lerp(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;
+}
- index++;
- if (index >= this._elementsSorted.length) {
- if (!divisor) {
- _Tw2Device.device.gl.disableVertexAttribArray(el.location);
- _Tw2Device.device.gl.vertexAttrib4f(el.location, 0, 0, 0, 0);
- }
- return resetData;
- }
- }
- }
- return resetData;
- }
+/**
+ * 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
+ */
+function vec2_random(out, scale) {
+ scale = scale || 1.0;
+ var r = RANDOM() * 2.0 * Math.PI;
+ out[0] = Math.cos(r) * scale;
+ out[1] = Math.sin(r) * scale;
+ return out;
+}
- /**
- * ResetInstanceDivisors
- * @param {Array} resetData
- */
+/**
+ * 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
+ */
+function transformMat2(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;
+}
- }, {
- key: 'ResetInstanceDivisors',
- value: function ResetInstanceDivisors(resetData) {
- if (resetData) {
- for (var i = 0; i < resetData.length; ++i) {
- _Tw2Device.device.ext.vertexAttribDivisor(resetData[i], 0);
- }
- }
- }
+/**
+ * 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
+ */
+function transformMat2d(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;
+}
- /**
- * Sets vertex declarations from an array of arrays, or an array of objects
- * @param {Array|Array