How to use out method in stryker-parent

Best JavaScript code snippet using stryker-parent

gl-matrix-3.3.0.js

Source:gl-matrix-3.3.0.js Github

copy

Full Screen

1/*!2@fileoverview gl-matrix - High performance matrix and vector operations3@author Brandon Jones4@author Colin MacKenzie IV5@version 3.3.06Copyright (c) 2015-2020, Brandon Jones, Colin MacKenzie IV.7Permission is hereby granted, free of charge, to any person obtaining a copy8of this software and associated documentation files (the "Software"), to deal9in the Software without restriction, including without limitation the rights10to use, copy, modify, merge, publish, distribute, sublicense, and/or sell11copies of the Software, and to permit persons to whom the Software is12furnished to do so, subject to the following conditions:13The above copyright notice and this permission notice shall be included in14all copies or substantial portions of the Software.15THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR16IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,17FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE18AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER19LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,20OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN21THE SOFTWARE.22*/23(function (global, factory) {24 typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :25 typeof define === 'function' && define.amd ? define(['exports'], factory) :26 (global = global || self, factory(global.glMatrix = {}));27}(this, (function (exports) { 'use strict';28 /**29 * Common utilities30 * @module glMatrix31 */32 // Configuration Constants33 var EPSILON = 0.000001;34 var ARRAY_TYPE = typeof Float32Array !== 'undefined' ? Float32Array : Array;35 var RANDOM = Math.random;36 /**37 * Sets the type of array used when creating new vectors and matrices38 *39 * @param {Float32ArrayConstructor | ArrayConstructor} type Array type, such as Float32Array or Array40 */41 function setMatrixArrayType(type) {42 ARRAY_TYPE = type;43 }44 var degree = Math.PI / 180;45 /**46 * Convert Degree To Radian47 *48 * @param {Number} a Angle in Degrees49 */50 function toRadian(a) {51 return a * degree;52 }53 /**54 * Tests whether or not the arguments have approximately the same value, within an absolute55 * or relative tolerance of glMatrix.EPSILON (an absolute tolerance is used for values less56 * than or equal to 1.0, and a relative tolerance is used for larger values)57 *58 * @param {Number} a The first number to test.59 * @param {Number} b The second number to test.60 * @returns {Boolean} True if the numbers are approximately equal, false otherwise.61 */62 function equals(a, b) {63 return Math.abs(a - b) <= EPSILON * Math.max(1.0, Math.abs(a), Math.abs(b));64 }65 if (!Math.hypot) Math.hypot = function () {66 var y = 0,67 i = arguments.length;68 while (i--) {69 y += arguments[i] * arguments[i];70 }71 return Math.sqrt(y);72 };73 var common = /*#__PURE__*/Object.freeze({74 __proto__: null,75 EPSILON: EPSILON,76 get ARRAY_TYPE () { return ARRAY_TYPE; },77 RANDOM: RANDOM,78 setMatrixArrayType: setMatrixArrayType,79 toRadian: toRadian,80 equals: equals81 });82 /**83 * 2x2 Matrix84 * @module mat285 */86 /**87 * Creates a new identity mat288 *89 * @returns {mat2} a new 2x2 matrix90 */91 function create() {92 var out = new ARRAY_TYPE(4);93 if (ARRAY_TYPE != Float32Array) {94 out[1] = 0;95 out[2] = 0;96 }97 out[0] = 1;98 out[3] = 1;99 return out;100 }101 /**102 * Creates a new mat2 initialized with values from an existing matrix103 *104 * @param {ReadonlyMat2} a matrix to clone105 * @returns {mat2} a new 2x2 matrix106 */107 function clone(a) {108 var out = new ARRAY_TYPE(4);109 out[0] = a[0];110 out[1] = a[1];111 out[2] = a[2];112 out[3] = a[3];113 return out;114 }115 /**116 * Copy the values from one mat2 to another117 *118 * @param {mat2} out the receiving matrix119 * @param {ReadonlyMat2} a the source matrix120 * @returns {mat2} out121 */122 function copy(out, a) {123 out[0] = a[0];124 out[1] = a[1];125 out[2] = a[2];126 out[3] = a[3];127 return out;128 }129 /**130 * Set a mat2 to the identity matrix131 *132 * @param {mat2} out the receiving matrix133 * @returns {mat2} out134 */135 function identity(out) {136 out[0] = 1;137 out[1] = 0;138 out[2] = 0;139 out[3] = 1;140 return out;141 }142 /**143 * Create a new mat2 with the given values144 *145 * @param {Number} m00 Component in column 0, row 0 position (index 0)146 * @param {Number} m01 Component in column 0, row 1 position (index 1)147 * @param {Number} m10 Component in column 1, row 0 position (index 2)148 * @param {Number} m11 Component in column 1, row 1 position (index 3)149 * @returns {mat2} out A new 2x2 matrix150 */151 function fromValues(m00, m01, m10, m11) {152 var out = new ARRAY_TYPE(4);153 out[0] = m00;154 out[1] = m01;155 out[2] = m10;156 out[3] = m11;157 return out;158 }159 /**160 * Set the components of a mat2 to the given values161 *162 * @param {mat2} out the receiving matrix163 * @param {Number} m00 Component in column 0, row 0 position (index 0)164 * @param {Number} m01 Component in column 0, row 1 position (index 1)165 * @param {Number} m10 Component in column 1, row 0 position (index 2)166 * @param {Number} m11 Component in column 1, row 1 position (index 3)167 * @returns {mat2} out168 */169 function set(out, m00, m01, m10, m11) {170 out[0] = m00;171 out[1] = m01;172 out[2] = m10;173 out[3] = m11;174 return out;175 }176 /**177 * Transpose the values of a mat2178 *179 * @param {mat2} out the receiving matrix180 * @param {ReadonlyMat2} a the source matrix181 * @returns {mat2} out182 */183 function transpose(out, a) {184 // If we are transposing ourselves we can skip a few steps but have to cache185 // some values186 if (out === a) {187 var a1 = a[1];188 out[1] = a[2];189 out[2] = a1;190 } else {191 out[0] = a[0];192 out[1] = a[2];193 out[2] = a[1];194 out[3] = a[3];195 }196 return out;197 }198 /**199 * Inverts a mat2200 *201 * @param {mat2} out the receiving matrix202 * @param {ReadonlyMat2} a the source matrix203 * @returns {mat2} out204 */205 function invert(out, a) {206 var a0 = a[0],207 a1 = a[1],208 a2 = a[2],209 a3 = a[3]; // Calculate the determinant210 var det = a0 * a3 - a2 * a1;211 if (!det) {212 return null;213 }214 det = 1.0 / det;215 out[0] = a3 * det;216 out[1] = -a1 * det;217 out[2] = -a2 * det;218 out[3] = a0 * det;219 return out;220 }221 /**222 * Calculates the adjugate of a mat2223 *224 * @param {mat2} out the receiving matrix225 * @param {ReadonlyMat2} a the source matrix226 * @returns {mat2} out227 */228 function adjoint(out, a) {229 // Caching this value is nessecary if out == a230 var a0 = a[0];231 out[0] = a[3];232 out[1] = -a[1];233 out[2] = -a[2];234 out[3] = a0;235 return out;236 }237 /**238 * Calculates the determinant of a mat2239 *240 * @param {ReadonlyMat2} a the source matrix241 * @returns {Number} determinant of a242 */243 function determinant(a) {244 return a[0] * a[3] - a[2] * a[1];245 }246 /**247 * Multiplies two mat2's248 *249 * @param {mat2} out the receiving matrix250 * @param {ReadonlyMat2} a the first operand251 * @param {ReadonlyMat2} b the second operand252 * @returns {mat2} out253 */254 function multiply(out, a, b) {255 var a0 = a[0],256 a1 = a[1],257 a2 = a[2],258 a3 = a[3];259 var b0 = b[0],260 b1 = b[1],261 b2 = b[2],262 b3 = b[3];263 out[0] = a0 * b0 + a2 * b1;264 out[1] = a1 * b0 + a3 * b1;265 out[2] = a0 * b2 + a2 * b3;266 out[3] = a1 * b2 + a3 * b3;267 return out;268 }269 /**270 * Rotates a mat2 by the given angle271 *272 * @param {mat2} out the receiving matrix273 * @param {ReadonlyMat2} a the matrix to rotate274 * @param {Number} rad the angle to rotate the matrix by275 * @returns {mat2} out276 */277 function rotate(out, a, rad) {278 var a0 = a[0],279 a1 = a[1],280 a2 = a[2],281 a3 = a[3];282 var s = Math.sin(rad);283 var c = Math.cos(rad);284 out[0] = a0 * c + a2 * s;285 out[1] = a1 * c + a3 * s;286 out[2] = a0 * -s + a2 * c;287 out[3] = a1 * -s + a3 * c;288 return out;289 }290 /**291 * Scales the mat2 by the dimensions in the given vec2292 *293 * @param {mat2} out the receiving matrix294 * @param {ReadonlyMat2} a the matrix to rotate295 * @param {ReadonlyVec2} v the vec2 to scale the matrix by296 * @returns {mat2} out297 **/298 function scale(out, a, v) {299 var a0 = a[0],300 a1 = a[1],301 a2 = a[2],302 a3 = a[3];303 var v0 = v[0],304 v1 = v[1];305 out[0] = a0 * v0;306 out[1] = a1 * v0;307 out[2] = a2 * v1;308 out[3] = a3 * v1;309 return out;310 }311 /**312 * Creates a matrix from a given angle313 * This is equivalent to (but much faster than):314 *315 * mat2.identity(dest);316 * mat2.rotate(dest, dest, rad);317 *318 * @param {mat2} out mat2 receiving operation result319 * @param {Number} rad the angle to rotate the matrix by320 * @returns {mat2} out321 */322 function fromRotation(out, rad) {323 var s = Math.sin(rad);324 var c = Math.cos(rad);325 out[0] = c;326 out[1] = s;327 out[2] = -s;328 out[3] = c;329 return out;330 }331 /**332 * Creates a matrix from a vector scaling333 * This is equivalent to (but much faster than):334 *335 * mat2.identity(dest);336 * mat2.scale(dest, dest, vec);337 *338 * @param {mat2} out mat2 receiving operation result339 * @param {ReadonlyVec2} v Scaling vector340 * @returns {mat2} out341 */342 function fromScaling(out, v) {343 out[0] = v[0];344 out[1] = 0;345 out[2] = 0;346 out[3] = v[1];347 return out;348 }349 /**350 * Returns a string representation of a mat2351 *352 * @param {ReadonlyMat2} a matrix to represent as a string353 * @returns {String} string representation of the matrix354 */355 function str(a) {356 return "mat2(" + a[0] + ", " + a[1] + ", " + a[2] + ", " + a[3] + ")";357 }358 /**359 * Returns Frobenius norm of a mat2360 *361 * @param {ReadonlyMat2} a the matrix to calculate Frobenius norm of362 * @returns {Number} Frobenius norm363 */364 function frob(a) {365 return Math.hypot(a[0], a[1], a[2], a[3]);366 }367 /**368 * Returns L, D and U matrices (Lower triangular, Diagonal and Upper triangular) by factorizing the input matrix369 * @param {ReadonlyMat2} L the lower triangular matrix370 * @param {ReadonlyMat2} D the diagonal matrix371 * @param {ReadonlyMat2} U the upper triangular matrix372 * @param {ReadonlyMat2} a the input matrix to factorize373 */374 function LDU(L, D, U, a) {375 L[2] = a[2] / a[0];376 U[0] = a[0];377 U[1] = a[1];378 U[3] = a[3] - L[2] * U[1];379 return [L, D, U];380 }381 /**382 * Adds two mat2's383 *384 * @param {mat2} out the receiving matrix385 * @param {ReadonlyMat2} a the first operand386 * @param {ReadonlyMat2} b the second operand387 * @returns {mat2} out388 */389 function add(out, a, b) {390 out[0] = a[0] + b[0];391 out[1] = a[1] + b[1];392 out[2] = a[2] + b[2];393 out[3] = a[3] + b[3];394 return out;395 }396 /**397 * Subtracts matrix b from matrix a398 *399 * @param {mat2} out the receiving matrix400 * @param {ReadonlyMat2} a the first operand401 * @param {ReadonlyMat2} b the second operand402 * @returns {mat2} out403 */404 function subtract(out, a, b) {405 out[0] = a[0] - b[0];406 out[1] = a[1] - b[1];407 out[2] = a[2] - b[2];408 out[3] = a[3] - b[3];409 return out;410 }411 /**412 * Returns whether or not the matrices have exactly the same elements in the same position (when compared with ===)413 *414 * @param {ReadonlyMat2} a The first matrix.415 * @param {ReadonlyMat2} b The second matrix.416 * @returns {Boolean} True if the matrices are equal, false otherwise.417 */418 function exactEquals(a, b) {419 return a[0] === b[0] && a[1] === b[1] && a[2] === b[2] && a[3] === b[3];420 }421 /**422 * Returns whether or not the matrices have approximately the same elements in the same position.423 *424 * @param {ReadonlyMat2} a The first matrix.425 * @param {ReadonlyMat2} b The second matrix.426 * @returns {Boolean} True if the matrices are equal, false otherwise.427 */428 function equals$1(a, b) {429 var a0 = a[0],430 a1 = a[1],431 a2 = a[2],432 a3 = a[3];433 var b0 = b[0],434 b1 = b[1],435 b2 = b[2],436 b3 = b[3];437 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));438 }439 /**440 * Multiply each element of the matrix by a scalar.441 *442 * @param {mat2} out the receiving matrix443 * @param {ReadonlyMat2} a the matrix to scale444 * @param {Number} b amount to scale the matrix's elements by445 * @returns {mat2} out446 */447 function multiplyScalar(out, a, b) {448 out[0] = a[0] * b;449 out[1] = a[1] * b;450 out[2] = a[2] * b;451 out[3] = a[3] * b;452 return out;453 }454 /**455 * Adds two mat2's after multiplying each element of the second operand by a scalar value.456 *457 * @param {mat2} out the receiving vector458 * @param {ReadonlyMat2} a the first operand459 * @param {ReadonlyMat2} b the second operand460 * @param {Number} scale the amount to scale b's elements by before adding461 * @returns {mat2} out462 */463 function multiplyScalarAndAdd(out, a, b, scale) {464 out[0] = a[0] + b[0] * scale;465 out[1] = a[1] + b[1] * scale;466 out[2] = a[2] + b[2] * scale;467 out[3] = a[3] + b[3] * scale;468 return out;469 }470 /**471 * Alias for {@link mat2.multiply}472 * @function473 */474 var mul = multiply;475 /**476 * Alias for {@link mat2.subtract}477 * @function478 */479 var sub = subtract;480 var mat2 = /*#__PURE__*/Object.freeze({481 __proto__: null,482 create: create,483 clone: clone,484 copy: copy,485 identity: identity,486 fromValues: fromValues,487 set: set,488 transpose: transpose,489 invert: invert,490 adjoint: adjoint,491 determinant: determinant,492 multiply: multiply,493 rotate: rotate,494 scale: scale,495 fromRotation: fromRotation,496 fromScaling: fromScaling,497 str: str,498 frob: frob,499 LDU: LDU,500 add: add,501 subtract: subtract,502 exactEquals: exactEquals,503 equals: equals$1,504 multiplyScalar: multiplyScalar,505 multiplyScalarAndAdd: multiplyScalarAndAdd,506 mul: mul,507 sub: sub508 });509 /**510 * 2x3 Matrix511 * @module mat2d512 * @description513 * A mat2d contains six elements defined as:514 * <pre>515 * [a, b,516 * c, d,517 * tx, ty]518 * </pre>519 * This is a short form for the 3x3 matrix:520 * <pre>521 * [a, b, 0,522 * c, d, 0,523 * tx, ty, 1]524 * </pre>525 * The last column is ignored so the array is shorter and operations are faster.526 */527 /**528 * Creates a new identity mat2d529 *530 * @returns {mat2d} a new 2x3 matrix531 */532 function create$1() {533 var out = new ARRAY_TYPE(6);534 if (ARRAY_TYPE != Float32Array) {535 out[1] = 0;536 out[2] = 0;537 out[4] = 0;538 out[5] = 0;539 }540 out[0] = 1;541 out[3] = 1;542 return out;543 }544 /**545 * Creates a new mat2d initialized with values from an existing matrix546 *547 * @param {ReadonlyMat2d} a matrix to clone548 * @returns {mat2d} a new 2x3 matrix549 */550 function clone$1(a) {551 var out = new ARRAY_TYPE(6);552 out[0] = a[0];553 out[1] = a[1];554 out[2] = a[2];555 out[3] = a[3];556 out[4] = a[4];557 out[5] = a[5];558 return out;559 }560 /**561 * Copy the values from one mat2d to another562 *563 * @param {mat2d} out the receiving matrix564 * @param {ReadonlyMat2d} a the source matrix565 * @returns {mat2d} out566 */567 function copy$1(out, a) {568 out[0] = a[0];569 out[1] = a[1];570 out[2] = a[2];571 out[3] = a[3];572 out[4] = a[4];573 out[5] = a[5];574 return out;575 }576 /**577 * Set a mat2d to the identity matrix578 *579 * @param {mat2d} out the receiving matrix580 * @returns {mat2d} out581 */582 function identity$1(out) {583 out[0] = 1;584 out[1] = 0;585 out[2] = 0;586 out[3] = 1;587 out[4] = 0;588 out[5] = 0;589 return out;590 }591 /**592 * Create a new mat2d with the given values593 *594 * @param {Number} a Component A (index 0)595 * @param {Number} b Component B (index 1)596 * @param {Number} c Component C (index 2)597 * @param {Number} d Component D (index 3)598 * @param {Number} tx Component TX (index 4)599 * @param {Number} ty Component TY (index 5)600 * @returns {mat2d} A new mat2d601 */602 function fromValues$1(a, b, c, d, tx, ty) {603 var out = new ARRAY_TYPE(6);604 out[0] = a;605 out[1] = b;606 out[2] = c;607 out[3] = d;608 out[4] = tx;609 out[5] = ty;610 return out;611 }612 /**613 * Set the components of a mat2d to the given values614 *615 * @param {mat2d} out the receiving matrix616 * @param {Number} a Component A (index 0)617 * @param {Number} b Component B (index 1)618 * @param {Number} c Component C (index 2)619 * @param {Number} d Component D (index 3)620 * @param {Number} tx Component TX (index 4)621 * @param {Number} ty Component TY (index 5)622 * @returns {mat2d} out623 */624 function set$1(out, a, b, c, d, tx, ty) {625 out[0] = a;626 out[1] = b;627 out[2] = c;628 out[3] = d;629 out[4] = tx;630 out[5] = ty;631 return out;632 }633 /**634 * Inverts a mat2d635 *636 * @param {mat2d} out the receiving matrix637 * @param {ReadonlyMat2d} a the source matrix638 * @returns {mat2d} out639 */640 function invert$1(out, a) {641 var aa = a[0],642 ab = a[1],643 ac = a[2],644 ad = a[3];645 var atx = a[4],646 aty = a[5];647 var det = aa * ad - ab * ac;648 if (!det) {649 return null;650 }651 det = 1.0 / det;652 out[0] = ad * det;653 out[1] = -ab * det;654 out[2] = -ac * det;655 out[3] = aa * det;656 out[4] = (ac * aty - ad * atx) * det;657 out[5] = (ab * atx - aa * aty) * det;658 return out;659 }660 /**661 * Calculates the determinant of a mat2d662 *663 * @param {ReadonlyMat2d} a the source matrix664 * @returns {Number} determinant of a665 */666 function determinant$1(a) {667 return a[0] * a[3] - a[1] * a[2];668 }669 /**670 * Multiplies two mat2d's671 *672 * @param {mat2d} out the receiving matrix673 * @param {ReadonlyMat2d} a the first operand674 * @param {ReadonlyMat2d} b the second operand675 * @returns {mat2d} out676 */677 function multiply$1(out, a, b) {678 var a0 = a[0],679 a1 = a[1],680 a2 = a[2],681 a3 = a[3],682 a4 = a[4],683 a5 = a[5];684 var b0 = b[0],685 b1 = b[1],686 b2 = b[2],687 b3 = b[3],688 b4 = b[4],689 b5 = b[5];690 out[0] = a0 * b0 + a2 * b1;691 out[1] = a1 * b0 + a3 * b1;692 out[2] = a0 * b2 + a2 * b3;693 out[3] = a1 * b2 + a3 * b3;694 out[4] = a0 * b4 + a2 * b5 + a4;695 out[5] = a1 * b4 + a3 * b5 + a5;696 return out;697 }698 /**699 * Rotates a mat2d by the given angle700 *701 * @param {mat2d} out the receiving matrix702 * @param {ReadonlyMat2d} a the matrix to rotate703 * @param {Number} rad the angle to rotate the matrix by704 * @returns {mat2d} out705 */706 function rotate$1(out, a, rad) {707 var a0 = a[0],708 a1 = a[1],709 a2 = a[2],710 a3 = a[3],711 a4 = a[4],712 a5 = a[5];713 var s = Math.sin(rad);714 var c = Math.cos(rad);715 out[0] = a0 * c + a2 * s;716 out[1] = a1 * c + a3 * s;717 out[2] = a0 * -s + a2 * c;718 out[3] = a1 * -s + a3 * c;719 out[4] = a4;720 out[5] = a5;721 return out;722 }723 /**724 * Scales the mat2d by the dimensions in the given vec2725 *726 * @param {mat2d} out the receiving matrix727 * @param {ReadonlyMat2d} a the matrix to translate728 * @param {ReadonlyVec2} v the vec2 to scale the matrix by729 * @returns {mat2d} out730 **/731 function scale$1(out, a, v) {732 var a0 = a[0],733 a1 = a[1],734 a2 = a[2],735 a3 = a[3],736 a4 = a[4],737 a5 = a[5];738 var v0 = v[0],739 v1 = v[1];740 out[0] = a0 * v0;741 out[1] = a1 * v0;742 out[2] = a2 * v1;743 out[3] = a3 * v1;744 out[4] = a4;745 out[5] = a5;746 return out;747 }748 /**749 * Translates the mat2d by the dimensions in the given vec2750 *751 * @param {mat2d} out the receiving matrix752 * @param {ReadonlyMat2d} a the matrix to translate753 * @param {ReadonlyVec2} v the vec2 to translate the matrix by754 * @returns {mat2d} out755 **/756 function translate(out, a, v) {757 var a0 = a[0],758 a1 = a[1],759 a2 = a[2],760 a3 = a[3],761 a4 = a[4],762 a5 = a[5];763 var v0 = v[0],764 v1 = v[1];765 out[0] = a0;766 out[1] = a1;767 out[2] = a2;768 out[3] = a3;769 out[4] = a0 * v0 + a2 * v1 + a4;770 out[5] = a1 * v0 + a3 * v1 + a5;771 return out;772 }773 /**774 * Creates a matrix from a given angle775 * This is equivalent to (but much faster than):776 *777 * mat2d.identity(dest);778 * mat2d.rotate(dest, dest, rad);779 *780 * @param {mat2d} out mat2d receiving operation result781 * @param {Number} rad the angle to rotate the matrix by782 * @returns {mat2d} out783 */784 function fromRotation$1(out, rad) {785 var s = Math.sin(rad),786 c = Math.cos(rad);787 out[0] = c;788 out[1] = s;789 out[2] = -s;790 out[3] = c;791 out[4] = 0;792 out[5] = 0;793 return out;794 }795 /**796 * Creates a matrix from a vector scaling797 * This is equivalent to (but much faster than):798 *799 * mat2d.identity(dest);800 * mat2d.scale(dest, dest, vec);801 *802 * @param {mat2d} out mat2d receiving operation result803 * @param {ReadonlyVec2} v Scaling vector804 * @returns {mat2d} out805 */806 function fromScaling$1(out, v) {807 out[0] = v[0];808 out[1] = 0;809 out[2] = 0;810 out[3] = v[1];811 out[4] = 0;812 out[5] = 0;813 return out;814 }815 /**816 * Creates a matrix from a vector translation817 * This is equivalent to (but much faster than):818 *819 * mat2d.identity(dest);820 * mat2d.translate(dest, dest, vec);821 *822 * @param {mat2d} out mat2d receiving operation result823 * @param {ReadonlyVec2} v Translation vector824 * @returns {mat2d} out825 */826 function fromTranslation(out, v) {827 out[0] = 1;828 out[1] = 0;829 out[2] = 0;830 out[3] = 1;831 out[4] = v[0];832 out[5] = v[1];833 return out;834 }835 /**836 * Returns a string representation of a mat2d837 *838 * @param {ReadonlyMat2d} a matrix to represent as a string839 * @returns {String} string representation of the matrix840 */841 function str$1(a) {842 return "mat2d(" + a[0] + ", " + a[1] + ", " + a[2] + ", " + a[3] + ", " + a[4] + ", " + a[5] + ")";843 }844 /**845 * Returns Frobenius norm of a mat2d846 *847 * @param {ReadonlyMat2d} a the matrix to calculate Frobenius norm of848 * @returns {Number} Frobenius norm849 */850 function frob$1(a) {851 return Math.hypot(a[0], a[1], a[2], a[3], a[4], a[5], 1);852 }853 /**854 * Adds two mat2d's855 *856 * @param {mat2d} out the receiving matrix857 * @param {ReadonlyMat2d} a the first operand858 * @param {ReadonlyMat2d} b the second operand859 * @returns {mat2d} out860 */861 function add$1(out, a, b) {862 out[0] = a[0] + b[0];863 out[1] = a[1] + b[1];864 out[2] = a[2] + b[2];865 out[3] = a[3] + b[3];866 out[4] = a[4] + b[4];867 out[5] = a[5] + b[5];868 return out;869 }870 /**871 * Subtracts matrix b from matrix a872 *873 * @param {mat2d} out the receiving matrix874 * @param {ReadonlyMat2d} a the first operand875 * @param {ReadonlyMat2d} b the second operand876 * @returns {mat2d} out877 */878 function subtract$1(out, a, b) {879 out[0] = a[0] - b[0];880 out[1] = a[1] - b[1];881 out[2] = a[2] - b[2];882 out[3] = a[3] - b[3];883 out[4] = a[4] - b[4];884 out[5] = a[5] - b[5];885 return out;886 }887 /**888 * Multiply each element of the matrix by a scalar.889 *890 * @param {mat2d} out the receiving matrix891 * @param {ReadonlyMat2d} a the matrix to scale892 * @param {Number} b amount to scale the matrix's elements by893 * @returns {mat2d} out894 */895 function multiplyScalar$1(out, a, b) {896 out[0] = a[0] * b;897 out[1] = a[1] * b;898 out[2] = a[2] * b;899 out[3] = a[3] * b;900 out[4] = a[4] * b;901 out[5] = a[5] * b;902 return out;903 }904 /**905 * Adds two mat2d's after multiplying each element of the second operand by a scalar value.906 *907 * @param {mat2d} out the receiving vector908 * @param {ReadonlyMat2d} a the first operand909 * @param {ReadonlyMat2d} b the second operand910 * @param {Number} scale the amount to scale b's elements by before adding911 * @returns {mat2d} out912 */913 function multiplyScalarAndAdd$1(out, a, b, scale) {914 out[0] = a[0] + b[0] * scale;915 out[1] = a[1] + b[1] * scale;916 out[2] = a[2] + b[2] * scale;917 out[3] = a[3] + b[3] * scale;918 out[4] = a[4] + b[4] * scale;919 out[5] = a[5] + b[5] * scale;920 return out;921 }922 /**923 * Returns whether or not the matrices have exactly the same elements in the same position (when compared with ===)924 *925 * @param {ReadonlyMat2d} a The first matrix.926 * @param {ReadonlyMat2d} b The second matrix.927 * @returns {Boolean} True if the matrices are equal, false otherwise.928 */929 function exactEquals$1(a, b) {930 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];931 }932 /**933 * Returns whether or not the matrices have approximately the same elements in the same position.934 *935 * @param {ReadonlyMat2d} a The first matrix.936 * @param {ReadonlyMat2d} b The second matrix.937 * @returns {Boolean} True if the matrices are equal, false otherwise.938 */939 function equals$2(a, b) {940 var a0 = a[0],941 a1 = a[1],942 a2 = a[2],943 a3 = a[3],944 a4 = a[4],945 a5 = a[5];946 var b0 = b[0],947 b1 = b[1],948 b2 = b[2],949 b3 = b[3],950 b4 = b[4],951 b5 = b[5];952 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));953 }954 /**955 * Alias for {@link mat2d.multiply}956 * @function957 */958 var mul$1 = multiply$1;959 /**960 * Alias for {@link mat2d.subtract}961 * @function962 */963 var sub$1 = subtract$1;964 var mat2d = /*#__PURE__*/Object.freeze({965 __proto__: null,966 create: create$1,967 clone: clone$1,968 copy: copy$1,969 identity: identity$1,970 fromValues: fromValues$1,971 set: set$1,972 invert: invert$1,973 determinant: determinant$1,974 multiply: multiply$1,975 rotate: rotate$1,976 scale: scale$1,977 translate: translate,978 fromRotation: fromRotation$1,979 fromScaling: fromScaling$1,980 fromTranslation: fromTranslation,981 str: str$1,982 frob: frob$1,983 add: add$1,984 subtract: subtract$1,985 multiplyScalar: multiplyScalar$1,986 multiplyScalarAndAdd: multiplyScalarAndAdd$1,987 exactEquals: exactEquals$1,988 equals: equals$2,989 mul: mul$1,990 sub: sub$1991 });992 /**993 * 3x3 Matrix994 * @module mat3995 */996 /**997 * Creates a new identity mat3998 *999 * @returns {mat3} a new 3x3 matrix1000 */1001 function create$2() {1002 var out = new ARRAY_TYPE(9);1003 if (ARRAY_TYPE != Float32Array) {1004 out[1] = 0;1005 out[2] = 0;1006 out[3] = 0;1007 out[5] = 0;1008 out[6] = 0;1009 out[7] = 0;1010 }1011 out[0] = 1;1012 out[4] = 1;1013 out[8] = 1;1014 return out;1015 }1016 /**1017 * Copies the upper-left 3x3 values into the given mat3.1018 *1019 * @param {mat3} out the receiving 3x3 matrix1020 * @param {ReadonlyMat4} a the source 4x4 matrix1021 * @returns {mat3} out1022 */1023 function fromMat4(out, a) {1024 out[0] = a[0];1025 out[1] = a[1];1026 out[2] = a[2];1027 out[3] = a[4];1028 out[4] = a[5];1029 out[5] = a[6];1030 out[6] = a[8];1031 out[7] = a[9];1032 out[8] = a[10];1033 return out;1034 }1035 /**1036 * Creates a new mat3 initialized with values from an existing matrix1037 *1038 * @param {ReadonlyMat3} a matrix to clone1039 * @returns {mat3} a new 3x3 matrix1040 */1041 function clone$2(a) {1042 var out = new ARRAY_TYPE(9);1043 out[0] = a[0];1044 out[1] = a[1];1045 out[2] = a[2];1046 out[3] = a[3];1047 out[4] = a[4];1048 out[5] = a[5];1049 out[6] = a[6];1050 out[7] = a[7];1051 out[8] = a[8];1052 return out;1053 }1054 /**1055 * Copy the values from one mat3 to another1056 *1057 * @param {mat3} out the receiving matrix1058 * @param {ReadonlyMat3} a the source matrix1059 * @returns {mat3} out1060 */1061 function copy$2(out, a) {1062 out[0] = a[0];1063 out[1] = a[1];1064 out[2] = a[2];1065 out[3] = a[3];1066 out[4] = a[4];1067 out[5] = a[5];1068 out[6] = a[6];1069 out[7] = a[7];1070 out[8] = a[8];1071 return out;1072 }1073 /**1074 * Create a new mat3 with the given values1075 *1076 * @param {Number} m00 Component in column 0, row 0 position (index 0)1077 * @param {Number} m01 Component in column 0, row 1 position (index 1)1078 * @param {Number} m02 Component in column 0, row 2 position (index 2)1079 * @param {Number} m10 Component in column 1, row 0 position (index 3)1080 * @param {Number} m11 Component in column 1, row 1 position (index 4)1081 * @param {Number} m12 Component in column 1, row 2 position (index 5)1082 * @param {Number} m20 Component in column 2, row 0 position (index 6)1083 * @param {Number} m21 Component in column 2, row 1 position (index 7)1084 * @param {Number} m22 Component in column 2, row 2 position (index 8)1085 * @returns {mat3} A new mat31086 */1087 function fromValues$2(m00, m01, m02, m10, m11, m12, m20, m21, m22) {1088 var out = new ARRAY_TYPE(9);1089 out[0] = m00;1090 out[1] = m01;1091 out[2] = m02;1092 out[3] = m10;1093 out[4] = m11;1094 out[5] = m12;1095 out[6] = m20;1096 out[7] = m21;1097 out[8] = m22;1098 return out;1099 }1100 /**1101 * Set the components of a mat3 to the given values1102 *1103 * @param {mat3} out the receiving matrix1104 * @param {Number} m00 Component in column 0, row 0 position (index 0)1105 * @param {Number} m01 Component in column 0, row 1 position (index 1)1106 * @param {Number} m02 Component in column 0, row 2 position (index 2)1107 * @param {Number} m10 Component in column 1, row 0 position (index 3)1108 * @param {Number} m11 Component in column 1, row 1 position (index 4)1109 * @param {Number} m12 Component in column 1, row 2 position (index 5)1110 * @param {Number} m20 Component in column 2, row 0 position (index 6)1111 * @param {Number} m21 Component in column 2, row 1 position (index 7)1112 * @param {Number} m22 Component in column 2, row 2 position (index 8)1113 * @returns {mat3} out1114 */1115 function set$2(out, m00, m01, m02, m10, m11, m12, m20, m21, m22) {1116 out[0] = m00;1117 out[1] = m01;1118 out[2] = m02;1119 out[3] = m10;1120 out[4] = m11;1121 out[5] = m12;1122 out[6] = m20;1123 out[7] = m21;1124 out[8] = m22;1125 return out;1126 }1127 /**1128 * Set a mat3 to the identity matrix1129 *1130 * @param {mat3} out the receiving matrix1131 * @returns {mat3} out1132 */1133 function identity$2(out) {1134 out[0] = 1;1135 out[1] = 0;1136 out[2] = 0;1137 out[3] = 0;1138 out[4] = 1;1139 out[5] = 0;1140 out[6] = 0;1141 out[7] = 0;1142 out[8] = 1;1143 return out;1144 }1145 /**1146 * Transpose the values of a mat31147 *1148 * @param {mat3} out the receiving matrix1149 * @param {ReadonlyMat3} a the source matrix1150 * @returns {mat3} out1151 */1152 function transpose$1(out, a) {1153 // If we are transposing ourselves we can skip a few steps but have to cache some values1154 if (out === a) {1155 var a01 = a[1],1156 a02 = a[2],1157 a12 = a[5];1158 out[1] = a[3];1159 out[2] = a[6];1160 out[3] = a01;1161 out[5] = a[7];1162 out[6] = a02;1163 out[7] = a12;1164 } else {1165 out[0] = a[0];1166 out[1] = a[3];1167 out[2] = a[6];1168 out[3] = a[1];1169 out[4] = a[4];1170 out[5] = a[7];1171 out[6] = a[2];1172 out[7] = a[5];1173 out[8] = a[8];1174 }1175 return out;1176 }1177 /**1178 * Inverts a mat31179 *1180 * @param {mat3} out the receiving matrix1181 * @param {ReadonlyMat3} a the source matrix1182 * @returns {mat3} out1183 */1184 function invert$2(out, a) {1185 var a00 = a[0],1186 a01 = a[1],1187 a02 = a[2];1188 var a10 = a[3],1189 a11 = a[4],1190 a12 = a[5];1191 var a20 = a[6],1192 a21 = a[7],1193 a22 = a[8];1194 var b01 = a22 * a11 - a12 * a21;1195 var b11 = -a22 * a10 + a12 * a20;1196 var b21 = a21 * a10 - a11 * a20; // Calculate the determinant1197 var det = a00 * b01 + a01 * b11 + a02 * b21;1198 if (!det) {1199 return null;1200 }1201 det = 1.0 / det;1202 out[0] = b01 * det;1203 out[1] = (-a22 * a01 + a02 * a21) * det;1204 out[2] = (a12 * a01 - a02 * a11) * det;1205 out[3] = b11 * det;1206 out[4] = (a22 * a00 - a02 * a20) * det;1207 out[5] = (-a12 * a00 + a02 * a10) * det;1208 out[6] = b21 * det;1209 out[7] = (-a21 * a00 + a01 * a20) * det;1210 out[8] = (a11 * a00 - a01 * a10) * det;1211 return out;1212 }1213 /**1214 * Calculates the adjugate of a mat31215 *1216 * @param {mat3} out the receiving matrix1217 * @param {ReadonlyMat3} a the source matrix1218 * @returns {mat3} out1219 */1220 function adjoint$1(out, a) {1221 var a00 = a[0],1222 a01 = a[1],1223 a02 = a[2];1224 var a10 = a[3],1225 a11 = a[4],1226 a12 = a[5];1227 var a20 = a[6],1228 a21 = a[7],1229 a22 = a[8];1230 out[0] = a11 * a22 - a12 * a21;1231 out[1] = a02 * a21 - a01 * a22;1232 out[2] = a01 * a12 - a02 * a11;1233 out[3] = a12 * a20 - a10 * a22;1234 out[4] = a00 * a22 - a02 * a20;1235 out[5] = a02 * a10 - a00 * a12;1236 out[6] = a10 * a21 - a11 * a20;1237 out[7] = a01 * a20 - a00 * a21;1238 out[8] = a00 * a11 - a01 * a10;1239 return out;1240 }1241 /**1242 * Calculates the determinant of a mat31243 *1244 * @param {ReadonlyMat3} a the source matrix1245 * @returns {Number} determinant of a1246 */1247 function determinant$2(a) {1248 var a00 = a[0],1249 a01 = a[1],1250 a02 = a[2];1251 var a10 = a[3],1252 a11 = a[4],1253 a12 = a[5];1254 var a20 = a[6],1255 a21 = a[7],1256 a22 = a[8];1257 return a00 * (a22 * a11 - a12 * a21) + a01 * (-a22 * a10 + a12 * a20) + a02 * (a21 * a10 - a11 * a20);1258 }1259 /**1260 * Multiplies two mat3's1261 *1262 * @param {mat3} out the receiving matrix1263 * @param {ReadonlyMat3} a the first operand1264 * @param {ReadonlyMat3} b the second operand1265 * @returns {mat3} out1266 */1267 function multiply$2(out, a, b) {1268 var a00 = a[0],1269 a01 = a[1],1270 a02 = a[2];1271 var a10 = a[3],1272 a11 = a[4],1273 a12 = a[5];1274 var a20 = a[6],1275 a21 = a[7],1276 a22 = a[8];1277 var b00 = b[0],1278 b01 = b[1],1279 b02 = b[2];1280 var b10 = b[3],1281 b11 = b[4],1282 b12 = b[5];1283 var b20 = b[6],1284 b21 = b[7],1285 b22 = b[8];1286 out[0] = b00 * a00 + b01 * a10 + b02 * a20;1287 out[1] = b00 * a01 + b01 * a11 + b02 * a21;1288 out[2] = b00 * a02 + b01 * a12 + b02 * a22;1289 out[3] = b10 * a00 + b11 * a10 + b12 * a20;1290 out[4] = b10 * a01 + b11 * a11 + b12 * a21;1291 out[5] = b10 * a02 + b11 * a12 + b12 * a22;1292 out[6] = b20 * a00 + b21 * a10 + b22 * a20;1293 out[7] = b20 * a01 + b21 * a11 + b22 * a21;1294 out[8] = b20 * a02 + b21 * a12 + b22 * a22;1295 return out;1296 }1297 /**1298 * Translate a mat3 by the given vector1299 *1300 * @param {mat3} out the receiving matrix1301 * @param {ReadonlyMat3} a the matrix to translate1302 * @param {ReadonlyVec2} v vector to translate by1303 * @returns {mat3} out1304 */1305 function translate$1(out, a, v) {1306 var a00 = a[0],1307 a01 = a[1],1308 a02 = a[2],1309 a10 = a[3],1310 a11 = a[4],1311 a12 = a[5],1312 a20 = a[6],1313 a21 = a[7],1314 a22 = a[8],1315 x = v[0],1316 y = v[1];1317 out[0] = a00;1318 out[1] = a01;1319 out[2] = a02;1320 out[3] = a10;1321 out[4] = a11;1322 out[5] = a12;1323 out[6] = x * a00 + y * a10 + a20;1324 out[7] = x * a01 + y * a11 + a21;1325 out[8] = x * a02 + y * a12 + a22;1326 return out;1327 }1328 /**1329 * Rotates a mat3 by the given angle1330 *1331 * @param {mat3} out the receiving matrix1332 * @param {ReadonlyMat3} a the matrix to rotate1333 * @param {Number} rad the angle to rotate the matrix by1334 * @returns {mat3} out1335 */1336 function rotate$2(out, a, rad) {1337 var a00 = a[0],1338 a01 = a[1],1339 a02 = a[2],1340 a10 = a[3],1341 a11 = a[4],1342 a12 = a[5],1343 a20 = a[6],1344 a21 = a[7],1345 a22 = a[8],1346 s = Math.sin(rad),1347 c = Math.cos(rad);1348 out[0] = c * a00 + s * a10;1349 out[1] = c * a01 + s * a11;1350 out[2] = c * a02 + s * a12;1351 out[3] = c * a10 - s * a00;1352 out[4] = c * a11 - s * a01;1353 out[5] = c * a12 - s * a02;1354 out[6] = a20;1355 out[7] = a21;1356 out[8] = a22;1357 return out;1358 }1359 /**1360 * Scales the mat3 by the dimensions in the given vec21361 *1362 * @param {mat3} out the receiving matrix1363 * @param {ReadonlyMat3} a the matrix to rotate1364 * @param {ReadonlyVec2} v the vec2 to scale the matrix by1365 * @returns {mat3} out1366 **/1367 function scale$2(out, a, v) {1368 var x = v[0],1369 y = v[1];1370 out[0] = x * a[0];1371 out[1] = x * a[1];1372 out[2] = x * a[2];1373 out[3] = y * a[3];1374 out[4] = y * a[4];1375 out[5] = y * a[5];1376 out[6] = a[6];1377 out[7] = a[7];1378 out[8] = a[8];1379 return out;1380 }1381 /**1382 * Creates a matrix from a vector translation1383 * This is equivalent to (but much faster than):1384 *1385 * mat3.identity(dest);1386 * mat3.translate(dest, dest, vec);1387 *1388 * @param {mat3} out mat3 receiving operation result1389 * @param {ReadonlyVec2} v Translation vector1390 * @returns {mat3} out1391 */1392 function fromTranslation$1(out, v) {1393 out[0] = 1;1394 out[1] = 0;1395 out[2] = 0;1396 out[3] = 0;1397 out[4] = 1;1398 out[5] = 0;1399 out[6] = v[0];1400 out[7] = v[1];1401 out[8] = 1;1402 return out;1403 }1404 /**1405 * Creates a matrix from a given angle1406 * This is equivalent to (but much faster than):1407 *1408 * mat3.identity(dest);1409 * mat3.rotate(dest, dest, rad);1410 *1411 * @param {mat3} out mat3 receiving operation result1412 * @param {Number} rad the angle to rotate the matrix by1413 * @returns {mat3} out1414 */1415 function fromRotation$2(out, rad) {1416 var s = Math.sin(rad),1417 c = Math.cos(rad);1418 out[0] = c;1419 out[1] = s;1420 out[2] = 0;1421 out[3] = -s;1422 out[4] = c;1423 out[5] = 0;1424 out[6] = 0;1425 out[7] = 0;1426 out[8] = 1;1427 return out;1428 }1429 /**1430 * Creates a matrix from a vector scaling1431 * This is equivalent to (but much faster than):1432 *1433 * mat3.identity(dest);1434 * mat3.scale(dest, dest, vec);1435 *1436 * @param {mat3} out mat3 receiving operation result1437 * @param {ReadonlyVec2} v Scaling vector1438 * @returns {mat3} out1439 */1440 function fromScaling$2(out, v) {1441 out[0] = v[0];1442 out[1] = 0;1443 out[2] = 0;1444 out[3] = 0;1445 out[4] = v[1];1446 out[5] = 0;1447 out[6] = 0;1448 out[7] = 0;1449 out[8] = 1;1450 return out;1451 }1452 /**1453 * Copies the values from a mat2d into a mat31454 *1455 * @param {mat3} out the receiving matrix1456 * @param {ReadonlyMat2d} a the matrix to copy1457 * @returns {mat3} out1458 **/1459 function fromMat2d(out, a) {1460 out[0] = a[0];1461 out[1] = a[1];1462 out[2] = 0;1463 out[3] = a[2];1464 out[4] = a[3];1465 out[5] = 0;1466 out[6] = a[4];1467 out[7] = a[5];1468 out[8] = 1;1469 return out;1470 }1471 /**1472 * Calculates a 3x3 matrix from the given quaternion1473 *1474 * @param {mat3} out mat3 receiving operation result1475 * @param {ReadonlyQuat} q Quaternion to create matrix from1476 *1477 * @returns {mat3} out1478 */1479 function fromQuat(out, q) {1480 var x = q[0],1481 y = q[1],1482 z = q[2],1483 w = q[3];1484 var x2 = x + x;1485 var y2 = y + y;1486 var z2 = z + z;1487 var xx = x * x2;1488 var yx = y * x2;1489 var yy = y * y2;1490 var zx = z * x2;1491 var zy = z * y2;1492 var zz = z * z2;1493 var wx = w * x2;1494 var wy = w * y2;1495 var wz = w * z2;1496 out[0] = 1 - yy - zz;1497 out[3] = yx - wz;1498 out[6] = zx + wy;1499 out[1] = yx + wz;1500 out[4] = 1 - xx - zz;1501 out[7] = zy - wx;1502 out[2] = zx - wy;1503 out[5] = zy + wx;1504 out[8] = 1 - xx - yy;1505 return out;1506 }1507 /**1508 * Calculates a 3x3 normal matrix (transpose inverse) from the 4x4 matrix1509 *1510 * @param {mat3} out mat3 receiving operation result1511 * @param {ReadonlyMat4} a Mat4 to derive the normal matrix from1512 *1513 * @returns {mat3} out1514 */1515 function normalFromMat4(out, a) {1516 var a00 = a[0],1517 a01 = a[1],1518 a02 = a[2],1519 a03 = a[3];1520 var a10 = a[4],1521 a11 = a[5],1522 a12 = a[6],1523 a13 = a[7];1524 var a20 = a[8],1525 a21 = a[9],1526 a22 = a[10],1527 a23 = a[11];1528 var a30 = a[12],1529 a31 = a[13],1530 a32 = a[14],1531 a33 = a[15];1532 var b00 = a00 * a11 - a01 * a10;1533 var b01 = a00 * a12 - a02 * a10;1534 var b02 = a00 * a13 - a03 * a10;1535 var b03 = a01 * a12 - a02 * a11;1536 var b04 = a01 * a13 - a03 * a11;1537 var b05 = a02 * a13 - a03 * a12;1538 var b06 = a20 * a31 - a21 * a30;1539 var b07 = a20 * a32 - a22 * a30;1540 var b08 = a20 * a33 - a23 * a30;1541 var b09 = a21 * a32 - a22 * a31;1542 var b10 = a21 * a33 - a23 * a31;1543 var b11 = a22 * a33 - a23 * a32; // Calculate the determinant1544 var det = b00 * b11 - b01 * b10 + b02 * b09 + b03 * b08 - b04 * b07 + b05 * b06;1545 if (!det) {1546 return null;1547 }1548 det = 1.0 / det;1549 out[0] = (a11 * b11 - a12 * b10 + a13 * b09) * det;1550 out[1] = (a12 * b08 - a10 * b11 - a13 * b07) * det;1551 out[2] = (a10 * b10 - a11 * b08 + a13 * b06) * det;1552 out[3] = (a02 * b10 - a01 * b11 - a03 * b09) * det;1553 out[4] = (a00 * b11 - a02 * b08 + a03 * b07) * det;1554 out[5] = (a01 * b08 - a00 * b10 - a03 * b06) * det;1555 out[6] = (a31 * b05 - a32 * b04 + a33 * b03) * det;1556 out[7] = (a32 * b02 - a30 * b05 - a33 * b01) * det;1557 out[8] = (a30 * b04 - a31 * b02 + a33 * b00) * det;1558 return out;1559 }1560 /**1561 * Generates a 2D projection matrix with the given bounds1562 *1563 * @param {mat3} out mat3 frustum matrix will be written into1564 * @param {number} width Width of your gl context1565 * @param {number} height Height of gl context1566 * @returns {mat3} out1567 */1568 function projection(out, width, height) {1569 out[0] = 2 / width;1570 out[1] = 0;1571 out[2] = 0;1572 out[3] = 0;1573 out[4] = -2 / height;1574 out[5] = 0;1575 out[6] = -1;1576 out[7] = 1;1577 out[8] = 1;1578 return out;1579 }1580 /**1581 * Returns a string representation of a mat31582 *1583 * @param {ReadonlyMat3} a matrix to represent as a string1584 * @returns {String} string representation of the matrix1585 */1586 function str$2(a) {1587 return "mat3(" + a[0] + ", " + a[1] + ", " + a[2] + ", " + a[3] + ", " + a[4] + ", " + a[5] + ", " + a[6] + ", " + a[7] + ", " + a[8] + ")";1588 }1589 /**1590 * Returns Frobenius norm of a mat31591 *1592 * @param {ReadonlyMat3} a the matrix to calculate Frobenius norm of1593 * @returns {Number} Frobenius norm1594 */1595 function frob$2(a) {1596 return Math.hypot(a[0], a[1], a[2], a[3], a[4], a[5], a[6], a[7], a[8]);1597 }1598 /**1599 * Adds two mat3's1600 *1601 * @param {mat3} out the receiving matrix1602 * @param {ReadonlyMat3} a the first operand1603 * @param {ReadonlyMat3} b the second operand1604 * @returns {mat3} out1605 */1606 function add$2(out, a, b) {1607 out[0] = a[0] + b[0];1608 out[1] = a[1] + b[1];1609 out[2] = a[2] + b[2];1610 out[3] = a[3] + b[3];1611 out[4] = a[4] + b[4];1612 out[5] = a[5] + b[5];1613 out[6] = a[6] + b[6];1614 out[7] = a[7] + b[7];1615 out[8] = a[8] + b[8];1616 return out;1617 }1618 /**1619 * Subtracts matrix b from matrix a1620 *1621 * @param {mat3} out the receiving matrix1622 * @param {ReadonlyMat3} a the first operand1623 * @param {ReadonlyMat3} b the second operand1624 * @returns {mat3} out1625 */1626 function subtract$2(out, a, b) {1627 out[0] = a[0] - b[0];1628 out[1] = a[1] - b[1];1629 out[2] = a[2] - b[2];1630 out[3] = a[3] - b[3];1631 out[4] = a[4] - b[4];1632 out[5] = a[5] - b[5];1633 out[6] = a[6] - b[6];1634 out[7] = a[7] - b[7];1635 out[8] = a[8] - b[8];1636 return out;1637 }1638 /**1639 * Multiply each element of the matrix by a scalar.1640 *1641 * @param {mat3} out the receiving matrix1642 * @param {ReadonlyMat3} a the matrix to scale1643 * @param {Number} b amount to scale the matrix's elements by1644 * @returns {mat3} out1645 */1646 function multiplyScalar$2(out, a, b) {1647 out[0] = a[0] * b;1648 out[1] = a[1] * b;1649 out[2] = a[2] * b;1650 out[3] = a[3] * b;1651 out[4] = a[4] * b;1652 out[5] = a[5] * b;1653 out[6] = a[6] * b;1654 out[7] = a[7] * b;1655 out[8] = a[8] * b;1656 return out;1657 }1658 /**1659 * Adds two mat3's after multiplying each element of the second operand by a scalar value.1660 *1661 * @param {mat3} out the receiving vector1662 * @param {ReadonlyMat3} a the first operand1663 * @param {ReadonlyMat3} b the second operand1664 * @param {Number} scale the amount to scale b's elements by before adding1665 * @returns {mat3} out1666 */1667 function multiplyScalarAndAdd$2(out, a, b, scale) {1668 out[0] = a[0] + b[0] * scale;1669 out[1] = a[1] + b[1] * scale;1670 out[2] = a[2] + b[2] * scale;1671 out[3] = a[3] + b[3] * scale;1672 out[4] = a[4] + b[4] * scale;1673 out[5] = a[5] + b[5] * scale;1674 out[6] = a[6] + b[6] * scale;1675 out[7] = a[7] + b[7] * scale;1676 out[8] = a[8] + b[8] * scale;1677 return out;1678 }1679 /**1680 * Returns whether or not the matrices have exactly the same elements in the same position (when compared with ===)1681 *1682 * @param {ReadonlyMat3} a The first matrix.1683 * @param {ReadonlyMat3} b The second matrix.1684 * @returns {Boolean} True if the matrices are equal, false otherwise.1685 */1686 function exactEquals$2(a, b) {1687 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];1688 }1689 /**1690 * Returns whether or not the matrices have approximately the same elements in the same position.1691 *1692 * @param {ReadonlyMat3} a The first matrix.1693 * @param {ReadonlyMat3} b The second matrix.1694 * @returns {Boolean} True if the matrices are equal, false otherwise.1695 */1696 function equals$3(a, b) {1697 var a0 = a[0],1698 a1 = a[1],1699 a2 = a[2],1700 a3 = a[3],1701 a4 = a[4],1702 a5 = a[5],1703 a6 = a[6],1704 a7 = a[7],1705 a8 = a[8];1706 var b0 = b[0],1707 b1 = b[1],1708 b2 = b[2],1709 b3 = b[3],1710 b4 = b[4],1711 b5 = b[5],1712 b6 = b[6],1713 b7 = b[7],1714 b8 = b[8];1715 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));1716 }1717 /**1718 * Alias for {@link mat3.multiply}1719 * @function1720 */1721 var mul$2 = multiply$2;1722 /**1723 * Alias for {@link mat3.subtract}1724 * @function1725 */1726 var sub$2 = subtract$2;1727 var mat3 = /*#__PURE__*/Object.freeze({1728 __proto__: null,1729 create: create$2,1730 fromMat4: fromMat4,1731 clone: clone$2,1732 copy: copy$2,1733 fromValues: fromValues$2,1734 set: set$2,1735 identity: identity$2,1736 transpose: transpose$1,1737 invert: invert$2,1738 adjoint: adjoint$1,1739 determinant: determinant$2,1740 multiply: multiply$2,1741 translate: translate$1,1742 rotate: rotate$2,1743 scale: scale$2,1744 fromTranslation: fromTranslation$1,1745 fromRotation: fromRotation$2,1746 fromScaling: fromScaling$2,1747 fromMat2d: fromMat2d,1748 fromQuat: fromQuat,1749 normalFromMat4: normalFromMat4,1750 projection: projection,1751 str: str$2,1752 frob: frob$2,1753 add: add$2,1754 subtract: subtract$2,1755 multiplyScalar: multiplyScalar$2,1756 multiplyScalarAndAdd: multiplyScalarAndAdd$2,1757 exactEquals: exactEquals$2,1758 equals: equals$3,1759 mul: mul$2,1760 sub: sub$21761 });1762 /**1763 * 4x4 Matrix<br>Format: column-major, when typed out it looks like row-major<br>The matrices are being post multiplied.1764 * @module mat41765 */1766 /**1767 * Creates a new identity mat41768 *1769 * @returns {mat4} a new 4x4 matrix1770 */1771 function create$3() {1772 var out = new ARRAY_TYPE(16);1773 if (ARRAY_TYPE != Float32Array) {1774 out[1] = 0;1775 out[2] = 0;1776 out[3] = 0;1777 out[4] = 0;1778 out[6] = 0;1779 out[7] = 0;1780 out[8] = 0;1781 out[9] = 0;1782 out[11] = 0;1783 out[12] = 0;1784 out[13] = 0;1785 out[14] = 0;1786 }1787 out[0] = 1;1788 out[5] = 1;1789 out[10] = 1;1790 out[15] = 1;1791 return out;1792 }1793 /**1794 * Creates a new mat4 initialized with values from an existing matrix1795 *1796 * @param {ReadonlyMat4} a matrix to clone1797 * @returns {mat4} a new 4x4 matrix1798 */1799 function clone$3(a) {1800 var out = new ARRAY_TYPE(16);1801 out[0] = a[0];1802 out[1] = a[1];1803 out[2] = a[2];1804 out[3] = a[3];1805 out[4] = a[4];1806 out[5] = a[5];1807 out[6] = a[6];1808 out[7] = a[7];1809 out[8] = a[8];1810 out[9] = a[9];1811 out[10] = a[10];1812 out[11] = a[11];1813 out[12] = a[12];1814 out[13] = a[13];1815 out[14] = a[14];1816 out[15] = a[15];1817 return out;1818 }1819 /**1820 * Copy the values from one mat4 to another1821 *1822 * @param {mat4} out the receiving matrix1823 * @param {ReadonlyMat4} a the source matrix1824 * @returns {mat4} out1825 */1826 function copy$3(out, a) {1827 out[0] = a[0];1828 out[1] = a[1];1829 out[2] = a[2];1830 out[3] = a[3];1831 out[4] = a[4];1832 out[5] = a[5];1833 out[6] = a[6];1834 out[7] = a[7];1835 out[8] = a[8];1836 out[9] = a[9];1837 out[10] = a[10];1838 out[11] = a[11];1839 out[12] = a[12];1840 out[13] = a[13];1841 out[14] = a[14];1842 out[15] = a[15];1843 return out;1844 }1845 /**1846 * Create a new mat4 with the given values1847 *1848 * @param {Number} m00 Component in column 0, row 0 position (index 0)1849 * @param {Number} m01 Component in column 0, row 1 position (index 1)1850 * @param {Number} m02 Component in column 0, row 2 position (index 2)1851 * @param {Number} m03 Component in column 0, row 3 position (index 3)1852 * @param {Number} m10 Component in column 1, row 0 position (index 4)1853 * @param {Number} m11 Component in column 1, row 1 position (index 5)1854 * @param {Number} m12 Component in column 1, row 2 position (index 6)1855 * @param {Number} m13 Component in column 1, row 3 position (index 7)1856 * @param {Number} m20 Component in column 2, row 0 position (index 8)1857 * @param {Number} m21 Component in column 2, row 1 position (index 9)1858 * @param {Number} m22 Component in column 2, row 2 position (index 10)1859 * @param {Number} m23 Component in column 2, row 3 position (index 11)1860 * @param {Number} m30 Component in column 3, row 0 position (index 12)1861 * @param {Number} m31 Component in column 3, row 1 position (index 13)1862 * @param {Number} m32 Component in column 3, row 2 position (index 14)1863 * @param {Number} m33 Component in column 3, row 3 position (index 15)1864 * @returns {mat4} A new mat41865 */1866 function fromValues$3(m00, m01, m02, m03, m10, m11, m12, m13, m20, m21, m22, m23, m30, m31, m32, m33) {1867 var out = new ARRAY_TYPE(16);1868 out[0] = m00;1869 out[1] = m01;1870 out[2] = m02;1871 out[3] = m03;1872 out[4] = m10;1873 out[5] = m11;1874 out[6] = m12;1875 out[7] = m13;1876 out[8] = m20;1877 out[9] = m21;1878 out[10] = m22;1879 out[11] = m23;1880 out[12] = m30;1881 out[13] = m31;1882 out[14] = m32;1883 out[15] = m33;1884 return out;1885 }1886 /**1887 * Set the components of a mat4 to the given values1888 *1889 * @param {mat4} out the receiving matrix1890 * @param {Number} m00 Component in column 0, row 0 position (index 0)1891 * @param {Number} m01 Component in column 0, row 1 position (index 1)1892 * @param {Number} m02 Component in column 0, row 2 position (index 2)1893 * @param {Number} m03 Component in column 0, row 3 position (index 3)1894 * @param {Number} m10 Component in column 1, row 0 position (index 4)1895 * @param {Number} m11 Component in column 1, row 1 position (index 5)1896 * @param {Number} m12 Component in column 1, row 2 position (index 6)1897 * @param {Number} m13 Component in column 1, row 3 position (index 7)1898 * @param {Number} m20 Component in column 2, row 0 position (index 8)1899 * @param {Number} m21 Component in column 2, row 1 position (index 9)1900 * @param {Number} m22 Component in column 2, row 2 position (index 10)1901 * @param {Number} m23 Component in column 2, row 3 position (index 11)1902 * @param {Number} m30 Component in column 3, row 0 position (index 12)1903 * @param {Number} m31 Component in column 3, row 1 position (index 13)1904 * @param {Number} m32 Component in column 3, row 2 position (index 14)1905 * @param {Number} m33 Component in column 3, row 3 position (index 15)1906 * @returns {mat4} out1907 */1908 function set$3(out, m00, m01, m02, m03, m10, m11, m12, m13, m20, m21, m22, m23, m30, m31, m32, m33) {1909 out[0] = m00;1910 out[1] = m01;1911 out[2] = m02;1912 out[3] = m03;1913 out[4] = m10;1914 out[5] = m11;1915 out[6] = m12;1916 out[7] = m13;1917 out[8] = m20;1918 out[9] = m21;1919 out[10] = m22;1920 out[11] = m23;1921 out[12] = m30;1922 out[13] = m31;1923 out[14] = m32;1924 out[15] = m33;1925 return out;1926 }1927 /**1928 * Set a mat4 to the identity matrix1929 *1930 * @param {mat4} out the receiving matrix1931 * @returns {mat4} out1932 */1933 function identity$3(out) {1934 out[0] = 1;1935 out[1] = 0;1936 out[2] = 0;1937 out[3] = 0;1938 out[4] = 0;1939 out[5] = 1;1940 out[6] = 0;1941 out[7] = 0;1942 out[8] = 0;1943 out[9] = 0;1944 out[10] = 1;1945 out[11] = 0;1946 out[12] = 0;1947 out[13] = 0;1948 out[14] = 0;1949 out[15] = 1;1950 return out;1951 }1952 /**1953 * Transpose the values of a mat41954 *1955 * @param {mat4} out the receiving matrix1956 * @param {ReadonlyMat4} a the source matrix1957 * @returns {mat4} out1958 */1959 function transpose$2(out, a) {1960 // If we are transposing ourselves we can skip a few steps but have to cache some values1961 if (out === a) {1962 var a01 = a[1],1963 a02 = a[2],1964 a03 = a[3];1965 var a12 = a[6],1966 a13 = a[7];1967 var a23 = a[11];1968 out[1] = a[4];1969 out[2] = a[8];1970 out[3] = a[12];1971 out[4] = a01;1972 out[6] = a[9];1973 out[7] = a[13];1974 out[8] = a02;1975 out[9] = a12;1976 out[11] = a[14];1977 out[12] = a03;1978 out[13] = a13;1979 out[14] = a23;1980 } else {1981 out[0] = a[0];1982 out[1] = a[4];1983 out[2] = a[8];1984 out[3] = a[12];1985 out[4] = a[1];1986 out[5] = a[5];1987 out[6] = a[9];1988 out[7] = a[13];1989 out[8] = a[2];1990 out[9] = a[6];1991 out[10] = a[10];1992 out[11] = a[14];1993 out[12] = a[3];1994 out[13] = a[7];1995 out[14] = a[11];1996 out[15] = a[15];1997 }1998 return out;1999 }2000 /**2001 * Inverts a mat42002 *2003 * @param {mat4} out the receiving matrix2004 * @param {ReadonlyMat4} a the source matrix2005 * @returns {mat4} out2006 */2007 function invert$3(out, a) {2008 var a00 = a[0],2009 a01 = a[1],2010 a02 = a[2],2011 a03 = a[3];2012 var a10 = a[4],2013 a11 = a[5],2014 a12 = a[6],2015 a13 = a[7];2016 var a20 = a[8],2017 a21 = a[9],2018 a22 = a[10],2019 a23 = a[11];2020 var a30 = a[12],2021 a31 = a[13],2022 a32 = a[14],2023 a33 = a[15];2024 var b00 = a00 * a11 - a01 * a10;2025 var b01 = a00 * a12 - a02 * a10;2026 var b02 = a00 * a13 - a03 * a10;2027 var b03 = a01 * a12 - a02 * a11;2028 var b04 = a01 * a13 - a03 * a11;2029 var b05 = a02 * a13 - a03 * a12;2030 var b06 = a20 * a31 - a21 * a30;2031 var b07 = a20 * a32 - a22 * a30;2032 var b08 = a20 * a33 - a23 * a30;2033 var b09 = a21 * a32 - a22 * a31;2034 var b10 = a21 * a33 - a23 * a31;2035 var b11 = a22 * a33 - a23 * a32; // Calculate the determinant2036 var det = b00 * b11 - b01 * b10 + b02 * b09 + b03 * b08 - b04 * b07 + b05 * b06;2037 if (!det) {2038 return null;2039 }2040 det = 1.0 / det;2041 out[0] = (a11 * b11 - a12 * b10 + a13 * b09) * det;2042 out[1] = (a02 * b10 - a01 * b11 - a03 * b09) * det;2043 out[2] = (a31 * b05 - a32 * b04 + a33 * b03) * det;2044 out[3] = (a22 * b04 - a21 * b05 - a23 * b03) * det;2045 out[4] = (a12 * b08 - a10 * b11 - a13 * b07) * det;2046 out[5] = (a00 * b11 - a02 * b08 + a03 * b07) * det;2047 out[6] = (a32 * b02 - a30 * b05 - a33 * b01) * det;2048 out[7] = (a20 * b05 - a22 * b02 + a23 * b01) * det;2049 out[8] = (a10 * b10 - a11 * b08 + a13 * b06) * det;2050 out[9] = (a01 * b08 - a00 * b10 - a03 * b06) * det;2051 out[10] = (a30 * b04 - a31 * b02 + a33 * b00) * det;2052 out[11] = (a21 * b02 - a20 * b04 - a23 * b00) * det;2053 out[12] = (a11 * b07 - a10 * b09 - a12 * b06) * det;2054 out[13] = (a00 * b09 - a01 * b07 + a02 * b06) * det;2055 out[14] = (a31 * b01 - a30 * b03 - a32 * b00) * det;2056 out[15] = (a20 * b03 - a21 * b01 + a22 * b00) * det;2057 return out;2058 }2059 /**2060 * Calculates the adjugate of a mat42061 *2062 * @param {mat4} out the receiving matrix2063 * @param {ReadonlyMat4} a the source matrix2064 * @returns {mat4} out2065 */2066 function adjoint$2(out, a) {2067 var a00 = a[0],2068 a01 = a[1],2069 a02 = a[2],2070 a03 = a[3];2071 var a10 = a[4],2072 a11 = a[5],2073 a12 = a[6],2074 a13 = a[7];2075 var a20 = a[8],2076 a21 = a[9],2077 a22 = a[10],2078 a23 = a[11];2079 var a30 = a[12],2080 a31 = a[13],2081 a32 = a[14],2082 a33 = a[15];2083 out[0] = a11 * (a22 * a33 - a23 * a32) - a21 * (a12 * a33 - a13 * a32) + a31 * (a12 * a23 - a13 * a22);2084 out[1] = -(a01 * (a22 * a33 - a23 * a32) - a21 * (a02 * a33 - a03 * a32) + a31 * (a02 * a23 - a03 * a22));2085 out[2] = a01 * (a12 * a33 - a13 * a32) - a11 * (a02 * a33 - a03 * a32) + a31 * (a02 * a13 - a03 * a12);2086 out[3] = -(a01 * (a12 * a23 - a13 * a22) - a11 * (a02 * a23 - a03 * a22) + a21 * (a02 * a13 - a03 * a12));2087 out[4] = -(a10 * (a22 * a33 - a23 * a32) - a20 * (a12 * a33 - a13 * a32) + a30 * (a12 * a23 - a13 * a22));2088 out[5] = a00 * (a22 * a33 - a23 * a32) - a20 * (a02 * a33 - a03 * a32) + a30 * (a02 * a23 - a03 * a22);2089 out[6] = -(a00 * (a12 * a33 - a13 * a32) - a10 * (a02 * a33 - a03 * a32) + a30 * (a02 * a13 - a03 * a12));2090 out[7] = a00 * (a12 * a23 - a13 * a22) - a10 * (a02 * a23 - a03 * a22) + a20 * (a02 * a13 - a03 * a12);2091 out[8] = a10 * (a21 * a33 - a23 * a31) - a20 * (a11 * a33 - a13 * a31) + a30 * (a11 * a23 - a13 * a21);2092 out[9] = -(a00 * (a21 * a33 - a23 * a31) - a20 * (a01 * a33 - a03 * a31) + a30 * (a01 * a23 - a03 * a21));2093 out[10] = a00 * (a11 * a33 - a13 * a31) - a10 * (a01 * a33 - a03 * a31) + a30 * (a01 * a13 - a03 * a11);2094 out[11] = -(a00 * (a11 * a23 - a13 * a21) - a10 * (a01 * a23 - a03 * a21) + a20 * (a01 * a13 - a03 * a11));2095 out[12] = -(a10 * (a21 * a32 - a22 * a31) - a20 * (a11 * a32 - a12 * a31) + a30 * (a11 * a22 - a12 * a21));2096 out[13] = a00 * (a21 * a32 - a22 * a31) - a20 * (a01 * a32 - a02 * a31) + a30 * (a01 * a22 - a02 * a21);2097 out[14] = -(a00 * (a11 * a32 - a12 * a31) - a10 * (a01 * a32 - a02 * a31) + a30 * (a01 * a12 - a02 * a11));2098 out[15] = a00 * (a11 * a22 - a12 * a21) - a10 * (a01 * a22 - a02 * a21) + a20 * (a01 * a12 - a02 * a11);2099 return out;2100 }2101 /**2102 * Calculates the determinant of a mat42103 *2104 * @param {ReadonlyMat4} a the source matrix2105 * @returns {Number} determinant of a2106 */2107 function determinant$3(a) {2108 var a00 = a[0],2109 a01 = a[1],2110 a02 = a[2],2111 a03 = a[3];2112 var a10 = a[4],2113 a11 = a[5],2114 a12 = a[6],2115 a13 = a[7];2116 var a20 = a[8],2117 a21 = a[9],2118 a22 = a[10],2119 a23 = a[11];2120 var a30 = a[12],2121 a31 = a[13],2122 a32 = a[14],2123 a33 = a[15];2124 var b00 = a00 * a11 - a01 * a10;2125 var b01 = a00 * a12 - a02 * a10;2126 var b02 = a00 * a13 - a03 * a10;2127 var b03 = a01 * a12 - a02 * a11;2128 var b04 = a01 * a13 - a03 * a11;2129 var b05 = a02 * a13 - a03 * a12;2130 var b06 = a20 * a31 - a21 * a30;2131 var b07 = a20 * a32 - a22 * a30;2132 var b08 = a20 * a33 - a23 * a30;2133 var b09 = a21 * a32 - a22 * a31;2134 var b10 = a21 * a33 - a23 * a31;2135 var b11 = a22 * a33 - a23 * a32; // Calculate the determinant2136 return b00 * b11 - b01 * b10 + b02 * b09 + b03 * b08 - b04 * b07 + b05 * b06;2137 }2138 /**2139 * Multiplies two mat4s2140 *2141 * @param {mat4} out the receiving matrix2142 * @param {ReadonlyMat4} a the first operand2143 * @param {ReadonlyMat4} b the second operand2144 * @returns {mat4} out2145 */2146 function multiply$3(out, a, b) {2147 var a00 = a[0],2148 a01 = a[1],2149 a02 = a[2],2150 a03 = a[3];2151 var a10 = a[4],2152 a11 = a[5],2153 a12 = a[6],2154 a13 = a[7];2155 var a20 = a[8],2156 a21 = a[9],2157 a22 = a[10],2158 a23 = a[11];2159 var a30 = a[12],2160 a31 = a[13],2161 a32 = a[14],2162 a33 = a[15]; // Cache only the current line of the second matrix2163 var b0 = b[0],2164 b1 = b[1],2165 b2 = b[2],2166 b3 = b[3];2167 out[0] = b0 * a00 + b1 * a10 + b2 * a20 + b3 * a30;2168 out[1] = b0 * a01 + b1 * a11 + b2 * a21 + b3 * a31;2169 out[2] = b0 * a02 + b1 * a12 + b2 * a22 + b3 * a32;2170 out[3] = b0 * a03 + b1 * a13 + b2 * a23 + b3 * a33;2171 b0 = b[4];2172 b1 = b[5];2173 b2 = b[6];2174 b3 = b[7];2175 out[4] = b0 * a00 + b1 * a10 + b2 * a20 + b3 * a30;2176 out[5] = b0 * a01 + b1 * a11 + b2 * a21 + b3 * a31;2177 out[6] = b0 * a02 + b1 * a12 + b2 * a22 + b3 * a32;2178 out[7] = b0 * a03 + b1 * a13 + b2 * a23 + b3 * a33;2179 b0 = b[8];2180 b1 = b[9];2181 b2 = b[10];2182 b3 = b[11];2183 out[8] = b0 * a00 + b1 * a10 + b2 * a20 + b3 * a30;2184 out[9] = b0 * a01 + b1 * a11 + b2 * a21 + b3 * a31;2185 out[10] = b0 * a02 + b1 * a12 + b2 * a22 + b3 * a32;2186 out[11] = b0 * a03 + b1 * a13 + b2 * a23 + b3 * a33;2187 b0 = b[12];2188 b1 = b[13];2189 b2 = b[14];2190 b3 = b[15];2191 out[12] = b0 * a00 + b1 * a10 + b2 * a20 + b3 * a30;2192 out[13] = b0 * a01 + b1 * a11 + b2 * a21 + b3 * a31;2193 out[14] = b0 * a02 + b1 * a12 + b2 * a22 + b3 * a32;2194 out[15] = b0 * a03 + b1 * a13 + b2 * a23 + b3 * a33;2195 return out;2196 }2197 /**2198 * Translate a mat4 by the given vector2199 *2200 * @param {mat4} out the receiving matrix2201 * @param {ReadonlyMat4} a the matrix to translate2202 * @param {ReadonlyVec3} v vector to translate by2203 * @returns {mat4} out2204 */2205 function translate$2(out, a, v) {2206 var x = v[0],2207 y = v[1],2208 z = v[2];2209 var a00, a01, a02, a03;2210 var a10, a11, a12, a13;2211 var a20, a21, a22, a23;2212 if (a === out) {2213 out[12] = a[0] * x + a[4] * y + a[8] * z + a[12];2214 out[13] = a[1] * x + a[5] * y + a[9] * z + a[13];2215 out[14] = a[2] * x + a[6] * y + a[10] * z + a[14];2216 out[15] = a[3] * x + a[7] * y + a[11] * z + a[15];2217 } else {2218 a00 = a[0];2219 a01 = a[1];2220 a02 = a[2];2221 a03 = a[3];2222 a10 = a[4];2223 a11 = a[5];2224 a12 = a[6];2225 a13 = a[7];2226 a20 = a[8];2227 a21 = a[9];2228 a22 = a[10];2229 a23 = a[11];2230 out[0] = a00;2231 out[1] = a01;2232 out[2] = a02;2233 out[3] = a03;2234 out[4] = a10;2235 out[5] = a11;2236 out[6] = a12;2237 out[7] = a13;2238 out[8] = a20;2239 out[9] = a21;2240 out[10] = a22;2241 out[11] = a23;2242 out[12] = a00 * x + a10 * y + a20 * z + a[12];2243 out[13] = a01 * x + a11 * y + a21 * z + a[13];2244 out[14] = a02 * x + a12 * y + a22 * z + a[14];2245 out[15] = a03 * x + a13 * y + a23 * z + a[15];2246 }2247 return out;2248 }2249 /**2250 * Scales the mat4 by the dimensions in the given vec3 not using vectorization2251 *2252 * @param {mat4} out the receiving matrix2253 * @param {ReadonlyMat4} a the matrix to scale2254 * @param {ReadonlyVec3} v the vec3 to scale the matrix by2255 * @returns {mat4} out2256 **/2257 function scale$3(out, a, v) {2258 var x = v[0],2259 y = v[1],2260 z = v[2];2261 out[0] = a[0] * x;2262 out[1] = a[1] * x;2263 out[2] = a[2] * x;2264 out[3] = a[3] * x;2265 out[4] = a[4] * y;2266 out[5] = a[5] * y;2267 out[6] = a[6] * y;2268 out[7] = a[7] * y;2269 out[8] = a[8] * z;2270 out[9] = a[9] * z;2271 out[10] = a[10] * z;2272 out[11] = a[11] * z;2273 out[12] = a[12];2274 out[13] = a[13];2275 out[14] = a[14];2276 out[15] = a[15];2277 return out;2278 }2279 /**2280 * Rotates a mat4 by the given angle around the given axis2281 *2282 * @param {mat4} out the receiving matrix2283 * @param {ReadonlyMat4} a the matrix to rotate2284 * @param {Number} rad the angle to rotate the matrix by2285 * @param {ReadonlyVec3} axis the axis to rotate around2286 * @returns {mat4} out2287 */2288 function rotate$3(out, a, rad, axis) {2289 var x = axis[0],2290 y = axis[1],2291 z = axis[2];2292 var len = Math.hypot(x, y, z);2293 var s, c, t;2294 var a00, a01, a02, a03;2295 var a10, a11, a12, a13;2296 var a20, a21, a22, a23;2297 var b00, b01, b02;2298 var b10, b11, b12;2299 var b20, b21, b22;2300 if (len < EPSILON) {2301 return null;2302 }2303 len = 1 / len;2304 x *= len;2305 y *= len;2306 z *= len;2307 s = Math.sin(rad);2308 c = Math.cos(rad);2309 t = 1 - c;2310 a00 = a[0];2311 a01 = a[1];2312 a02 = a[2];2313 a03 = a[3];2314 a10 = a[4];2315 a11 = a[5];2316 a12 = a[6];2317 a13 = a[7];2318 a20 = a[8];2319 a21 = a[9];2320 a22 = a[10];2321 a23 = a[11]; // Construct the elements of the rotation matrix2322 b00 = x * x * t + c;2323 b01 = y * x * t + z * s;2324 b02 = z * x * t - y * s;2325 b10 = x * y * t - z * s;2326 b11 = y * y * t + c;2327 b12 = z * y * t + x * s;2328 b20 = x * z * t + y * s;2329 b21 = y * z * t - x * s;2330 b22 = z * z * t + c; // Perform rotation-specific matrix multiplication2331 out[0] = a00 * b00 + a10 * b01 + a20 * b02;2332 out[1] = a01 * b00 + a11 * b01 + a21 * b02;2333 out[2] = a02 * b00 + a12 * b01 + a22 * b02;2334 out[3] = a03 * b00 + a13 * b01 + a23 * b02;2335 out[4] = a00 * b10 + a10 * b11 + a20 * b12;2336 out[5] = a01 * b10 + a11 * b11 + a21 * b12;2337 out[6] = a02 * b10 + a12 * b11 + a22 * b12;2338 out[7] = a03 * b10 + a13 * b11 + a23 * b12;2339 out[8] = a00 * b20 + a10 * b21 + a20 * b22;2340 out[9] = a01 * b20 + a11 * b21 + a21 * b22;2341 out[10] = a02 * b20 + a12 * b21 + a22 * b22;2342 out[11] = a03 * b20 + a13 * b21 + a23 * b22;2343 if (a !== out) {2344 // If the source and destination differ, copy the unchanged last row2345 out[12] = a[12];2346 out[13] = a[13];2347 out[14] = a[14];2348 out[15] = a[15];2349 }2350 return out;2351 }2352 /**2353 * Rotates a matrix by the given angle around the X axis2354 *2355 * @param {mat4} out the receiving matrix2356 * @param {ReadonlyMat4} a the matrix to rotate2357 * @param {Number} rad the angle to rotate the matrix by2358 * @returns {mat4} out2359 */2360 function rotateX(out, a, rad) {2361 var s = Math.sin(rad);2362 var c = Math.cos(rad);2363 var a10 = a[4];2364 var a11 = a[5];2365 var a12 = a[6];2366 var a13 = a[7];2367 var a20 = a[8];2368 var a21 = a[9];2369 var a22 = a[10];2370 var a23 = a[11];2371 if (a !== out) {2372 // If the source and destination differ, copy the unchanged rows2373 out[0] = a[0];2374 out[1] = a[1];2375 out[2] = a[2];2376 out[3] = a[3];2377 out[12] = a[12];2378 out[13] = a[13];2379 out[14] = a[14];2380 out[15] = a[15];2381 } // Perform axis-specific matrix multiplication2382 out[4] = a10 * c + a20 * s;2383 out[5] = a11 * c + a21 * s;2384 out[6] = a12 * c + a22 * s;2385 out[7] = a13 * c + a23 * s;2386 out[8] = a20 * c - a10 * s;2387 out[9] = a21 * c - a11 * s;2388 out[10] = a22 * c - a12 * s;2389 out[11] = a23 * c - a13 * s;2390 return out;2391 }2392 /**2393 * Rotates a matrix by the given angle around the Y axis2394 *2395 * @param {mat4} out the receiving matrix2396 * @param {ReadonlyMat4} a the matrix to rotate2397 * @param {Number} rad the angle to rotate the matrix by2398 * @returns {mat4} out2399 */2400 function rotateY(out, a, rad) {2401 var s = Math.sin(rad);2402 var c = Math.cos(rad);2403 var a00 = a[0];2404 var a01 = a[1];2405 var a02 = a[2];2406 var a03 = a[3];2407 var a20 = a[8];2408 var a21 = a[9];2409 var a22 = a[10];2410 var a23 = a[11];2411 if (a !== out) {2412 // If the source and destination differ, copy the unchanged rows2413 out[4] = a[4];2414 out[5] = a[5];2415 out[6] = a[6];2416 out[7] = a[7];2417 out[12] = a[12];2418 out[13] = a[13];2419 out[14] = a[14];2420 out[15] = a[15];2421 } // Perform axis-specific matrix multiplication2422 out[0] = a00 * c - a20 * s;2423 out[1] = a01 * c - a21 * s;2424 out[2] = a02 * c - a22 * s;2425 out[3] = a03 * c - a23 * s;2426 out[8] = a00 * s + a20 * c;2427 out[9] = a01 * s + a21 * c;2428 out[10] = a02 * s + a22 * c;2429 out[11] = a03 * s + a23 * c;2430 return out;2431 }2432 /**2433 * Rotates a matrix by the given angle around the Z axis2434 *2435 * @param {mat4} out the receiving matrix2436 * @param {ReadonlyMat4} a the matrix to rotate2437 * @param {Number} rad the angle to rotate the matrix by2438 * @returns {mat4} out2439 */2440 function rotateZ(out, a, rad) {2441 var s = Math.sin(rad);2442 var c = Math.cos(rad);2443 var a00 = a[0];2444 var a01 = a[1];2445 var a02 = a[2];2446 var a03 = a[3];2447 var a10 = a[4];2448 var a11 = a[5];2449 var a12 = a[6];2450 var a13 = a[7];2451 if (a !== out) {2452 // If the source and destination differ, copy the unchanged last row2453 out[8] = a[8];2454 out[9] = a[9];2455 out[10] = a[10];2456 out[11] = a[11];2457 out[12] = a[12];2458 out[13] = a[13];2459 out[14] = a[14];2460 out[15] = a[15];2461 } // Perform axis-specific matrix multiplication2462 out[0] = a00 * c + a10 * s;2463 out[1] = a01 * c + a11 * s;2464 out[2] = a02 * c + a12 * s;2465 out[3] = a03 * c + a13 * s;2466 out[4] = a10 * c - a00 * s;2467 out[5] = a11 * c - a01 * s;2468 out[6] = a12 * c - a02 * s;2469 out[7] = a13 * c - a03 * s;2470 return out;2471 }2472 /**2473 * Creates a matrix from a vector translation2474 * This is equivalent to (but much faster than):2475 *2476 * mat4.identity(dest);2477 * mat4.translate(dest, dest, vec);2478 *2479 * @param {mat4} out mat4 receiving operation result2480 * @param {ReadonlyVec3} v Translation vector2481 * @returns {mat4} out2482 */2483 function fromTranslation$2(out, v) {2484 out[0] = 1;2485 out[1] = 0;2486 out[2] = 0;2487 out[3] = 0;2488 out[4] = 0;2489 out[5] = 1;2490 out[6] = 0;2491 out[7] = 0;2492 out[8] = 0;2493 out[9] = 0;2494 out[10] = 1;2495 out[11] = 0;2496 out[12] = v[0];2497 out[13] = v[1];2498 out[14] = v[2];2499 out[15] = 1;2500 return out;2501 }2502 /**2503 * Creates a matrix from a vector scaling2504 * This is equivalent to (but much faster than):2505 *2506 * mat4.identity(dest);2507 * mat4.scale(dest, dest, vec);2508 *2509 * @param {mat4} out mat4 receiving operation result2510 * @param {ReadonlyVec3} v Scaling vector2511 * @returns {mat4} out2512 */2513 function fromScaling$3(out, v) {2514 out[0] = v[0];2515 out[1] = 0;2516 out[2] = 0;2517 out[3] = 0;2518 out[4] = 0;2519 out[5] = v[1];2520 out[6] = 0;2521 out[7] = 0;2522 out[8] = 0;2523 out[9] = 0;2524 out[10] = v[2];2525 out[11] = 0;2526 out[12] = 0;2527 out[13] = 0;2528 out[14] = 0;2529 out[15] = 1;2530 return out;2531 }2532 /**2533 * Creates a matrix from a given angle around a given axis2534 * This is equivalent to (but much faster than):2535 *2536 * mat4.identity(dest);2537 * mat4.rotate(dest, dest, rad, axis);2538 *2539 * @param {mat4} out mat4 receiving operation result2540 * @param {Number} rad the angle to rotate the matrix by2541 * @param {ReadonlyVec3} axis the axis to rotate around2542 * @returns {mat4} out2543 */2544 function fromRotation$3(out, rad, axis) {2545 var x = axis[0],2546 y = axis[1],2547 z = axis[2];2548 var len = Math.hypot(x, y, z);2549 var s, c, t;2550 if (len < EPSILON) {2551 return null;2552 }2553 len = 1 / len;2554 x *= len;2555 y *= len;2556 z *= len;2557 s = Math.sin(rad);2558 c = Math.cos(rad);2559 t = 1 - c; // Perform rotation-specific matrix multiplication2560 out[0] = x * x * t + c;2561 out[1] = y * x * t + z * s;2562 out[2] = z * x * t - y * s;2563 out[3] = 0;2564 out[4] = x * y * t - z * s;2565 out[5] = y * y * t + c;2566 out[6] = z * y * t + x * s;2567 out[7] = 0;2568 out[8] = x * z * t + y * s;2569 out[9] = y * z * t - x * s;2570 out[10] = z * z * t + c;2571 out[11] = 0;2572 out[12] = 0;2573 out[13] = 0;2574 out[14] = 0;2575 out[15] = 1;2576 return out;2577 }2578 /**2579 * Creates a matrix from the given angle around the X axis2580 * This is equivalent to (but much faster than):2581 *2582 * mat4.identity(dest);2583 * mat4.rotateX(dest, dest, rad);2584 *2585 * @param {mat4} out mat4 receiving operation result2586 * @param {Number} rad the angle to rotate the matrix by2587 * @returns {mat4} out2588 */2589 function fromXRotation(out, rad) {2590 var s = Math.sin(rad);2591 var c = Math.cos(rad); // Perform axis-specific matrix multiplication2592 out[0] = 1;2593 out[1] = 0;2594 out[2] = 0;2595 out[3] = 0;2596 out[4] = 0;2597 out[5] = c;2598 out[6] = s;2599 out[7] = 0;2600 out[8] = 0;2601 out[9] = -s;2602 out[10] = c;2603 out[11] = 0;2604 out[12] = 0;2605 out[13] = 0;2606 out[14] = 0;2607 out[15] = 1;2608 return out;2609 }2610 /**2611 * Creates a matrix from the given angle around the Y axis2612 * This is equivalent to (but much faster than):2613 *2614 * mat4.identity(dest);2615 * mat4.rotateY(dest, dest, rad);2616 *2617 * @param {mat4} out mat4 receiving operation result2618 * @param {Number} rad the angle to rotate the matrix by2619 * @returns {mat4} out2620 */2621 function fromYRotation(out, rad) {2622 var s = Math.sin(rad);2623 var c = Math.cos(rad); // Perform axis-specific matrix multiplication2624 out[0] = c;2625 out[1] = 0;2626 out[2] = -s;2627 out[3] = 0;2628 out[4] = 0;2629 out[5] = 1;2630 out[6] = 0;2631 out[7] = 0;2632 out[8] = s;2633 out[9] = 0;2634 out[10] = c;2635 out[11] = 0;2636 out[12] = 0;2637 out[13] = 0;2638 out[14] = 0;2639 out[15] = 1;2640 return out;2641 }2642 /**2643 * Creates a matrix from the given angle around the Z axis2644 * This is equivalent to (but much faster than):2645 *2646 * mat4.identity(dest);2647 * mat4.rotateZ(dest, dest, rad);2648 *2649 * @param {mat4} out mat4 receiving operation result2650 * @param {Number} rad the angle to rotate the matrix by2651 * @returns {mat4} out2652 */2653 function fromZRotation(out, rad) {2654 var s = Math.sin(rad);2655 var c = Math.cos(rad); // Perform axis-specific matrix multiplication2656 out[0] = c;2657 out[1] = s;2658 out[2] = 0;2659 out[3] = 0;2660 out[4] = -s;2661 out[5] = c;2662 out[6] = 0;2663 out[7] = 0;2664 out[8] = 0;2665 out[9] = 0;2666 out[10] = 1;2667 out[11] = 0;2668 out[12] = 0;2669 out[13] = 0;2670 out[14] = 0;2671 out[15] = 1;2672 return out;2673 }2674 /**2675 * Creates a matrix from a quaternion rotation and vector translation2676 * This is equivalent to (but much faster than):2677 *2678 * mat4.identity(dest);2679 * mat4.translate(dest, vec);2680 * let quatMat = mat4.create();2681 * quat4.toMat4(quat, quatMat);2682 * mat4.multiply(dest, quatMat);2683 *2684 * @param {mat4} out mat4 receiving operation result2685 * @param {quat4} q Rotation quaternion2686 * @param {ReadonlyVec3} v Translation vector2687 * @returns {mat4} out2688 */2689 function fromRotationTranslation(out, q, v) {2690 // Quaternion math2691 var x = q[0],2692 y = q[1],2693 z = q[2],2694 w = q[3];2695 var x2 = x + x;2696 var y2 = y + y;2697 var z2 = z + z;2698 var xx = x * x2;2699 var xy = x * y2;2700 var xz = x * z2;2701 var yy = y * y2;2702 var yz = y * z2;2703 var zz = z * z2;2704 var wx = w * x2;2705 var wy = w * y2;2706 var wz = w * z2;2707 out[0] = 1 - (yy + zz);2708 out[1] = xy + wz;2709 out[2] = xz - wy;2710 out[3] = 0;2711 out[4] = xy - wz;2712 out[5] = 1 - (xx + zz);2713 out[6] = yz + wx;2714 out[7] = 0;2715 out[8] = xz + wy;2716 out[9] = yz - wx;2717 out[10] = 1 - (xx + yy);2718 out[11] = 0;2719 out[12] = v[0];2720 out[13] = v[1];2721 out[14] = v[2];2722 out[15] = 1;2723 return out;2724 }2725 /**2726 * Creates a new mat4 from a dual quat.2727 *2728 * @param {mat4} out Matrix2729 * @param {ReadonlyQuat2} a Dual Quaternion2730 * @returns {mat4} mat4 receiving operation result2731 */2732 function fromQuat2(out, a) {2733 var translation = new ARRAY_TYPE(3);2734 var bx = -a[0],2735 by = -a[1],2736 bz = -a[2],2737 bw = a[3],2738 ax = a[4],2739 ay = a[5],2740 az = a[6],2741 aw = a[7];2742 var magnitude = bx * bx + by * by + bz * bz + bw * bw; //Only scale if it makes sense2743 if (magnitude > 0) {2744 translation[0] = (ax * bw + aw * bx + ay * bz - az * by) * 2 / magnitude;2745 translation[1] = (ay * bw + aw * by + az * bx - ax * bz) * 2 / magnitude;2746 translation[2] = (az * bw + aw * bz + ax * by - ay * bx) * 2 / magnitude;2747 } else {2748 translation[0] = (ax * bw + aw * bx + ay * bz - az * by) * 2;2749 translation[1] = (ay * bw + aw * by + az * bx - ax * bz) * 2;2750 translation[2] = (az * bw + aw * bz + ax * by - ay * bx) * 2;2751 }2752 fromRotationTranslation(out, a, translation);2753 return out;2754 }2755 /**2756 * Returns the translation vector component of a transformation2757 * matrix. If a matrix is built with fromRotationTranslation,2758 * the returned vector will be the same as the translation vector2759 * originally supplied.2760 * @param {vec3} out Vector to receive translation component2761 * @param {ReadonlyMat4} mat Matrix to be decomposed (input)2762 * @return {vec3} out2763 */2764 function getTranslation(out, mat) {2765 out[0] = mat[12];2766 out[1] = mat[13];2767 out[2] = mat[14];2768 return out;2769 }2770 /**2771 * Returns the scaling factor component of a transformation2772 * matrix. If a matrix is built with fromRotationTranslationScale2773 * with a normalized Quaternion paramter, the returned vector will be2774 * the same as the scaling vector2775 * originally supplied.2776 * @param {vec3} out Vector to receive scaling factor component2777 * @param {ReadonlyMat4} mat Matrix to be decomposed (input)2778 * @return {vec3} out2779 */2780 function getScaling(out, mat) {2781 var m11 = mat[0];2782 var m12 = mat[1];2783 var m13 = mat[2];2784 var m21 = mat[4];2785 var m22 = mat[5];2786 var m23 = mat[6];2787 var m31 = mat[8];2788 var m32 = mat[9];2789 var m33 = mat[10];2790 out[0] = Math.hypot(m11, m12, m13);2791 out[1] = Math.hypot(m21, m22, m23);2792 out[2] = Math.hypot(m31, m32, m33);2793 return out;2794 }2795 /**2796 * Returns a quaternion representing the rotational component2797 * of a transformation matrix. If a matrix is built with2798 * fromRotationTranslation, the returned quaternion will be the2799 * same as the quaternion originally supplied.2800 * @param {quat} out Quaternion to receive the rotation component2801 * @param {ReadonlyMat4} mat Matrix to be decomposed (input)2802 * @return {quat} out2803 */2804 function getRotation(out, mat) {2805 var scaling = new ARRAY_TYPE(3);2806 getScaling(scaling, mat);2807 var is1 = 1 / scaling[0];2808 var is2 = 1 / scaling[1];2809 var is3 = 1 / scaling[2];2810 var sm11 = mat[0] * is1;2811 var sm12 = mat[1] * is2;2812 var sm13 = mat[2] * is3;2813 var sm21 = mat[4] * is1;2814 var sm22 = mat[5] * is2;2815 var sm23 = mat[6] * is3;2816 var sm31 = mat[8] * is1;2817 var sm32 = mat[9] * is2;2818 var sm33 = mat[10] * is3;2819 var trace = sm11 + sm22 + sm33;2820 var S = 0;2821 if (trace > 0) {2822 S = Math.sqrt(trace + 1.0) * 2;2823 out[3] = 0.25 * S;2824 out[0] = (sm23 - sm32) / S;2825 out[1] = (sm31 - sm13) / S;2826 out[2] = (sm12 - sm21) / S;2827 } else if (sm11 > sm22 && sm11 > sm33) {2828 S = Math.sqrt(1.0 + sm11 - sm22 - sm33) * 2;2829 out[3] = (sm23 - sm32) / S;2830 out[0] = 0.25 * S;2831 out[1] = (sm12 + sm21) / S;2832 out[2] = (sm31 + sm13) / S;2833 } else if (sm22 > sm33) {2834 S = Math.sqrt(1.0 + sm22 - sm11 - sm33) * 2;2835 out[3] = (sm31 - sm13) / S;2836 out[0] = (sm12 + sm21) / S;2837 out[1] = 0.25 * S;2838 out[2] = (sm23 + sm32) / S;2839 } else {2840 S = Math.sqrt(1.0 + sm33 - sm11 - sm22) * 2;2841 out[3] = (sm12 - sm21) / S;2842 out[0] = (sm31 + sm13) / S;2843 out[1] = (sm23 + sm32) / S;2844 out[2] = 0.25 * S;2845 }2846 return out;2847 }2848 /**2849 * Creates a matrix from a quaternion rotation, vector translation and vector scale2850 * This is equivalent to (but much faster than):2851 *2852 * mat4.identity(dest);2853 * mat4.translate(dest, vec);2854 * let quatMat = mat4.create();2855 * quat4.toMat4(quat, quatMat);2856 * mat4.multiply(dest, quatMat);2857 * mat4.scale(dest, scale)2858 *2859 * @param {mat4} out mat4 receiving operation result2860 * @param {quat4} q Rotation quaternion2861 * @param {ReadonlyVec3} v Translation vector2862 * @param {ReadonlyVec3} s Scaling vector2863 * @returns {mat4} out2864 */2865 function fromRotationTranslationScale(out, q, v, s) {2866 // Quaternion math2867 var x = q[0],2868 y = q[1],2869 z = q[2],2870 w = q[3];2871 var x2 = x + x;2872 var y2 = y + y;2873 var z2 = z + z;2874 var xx = x * x2;2875 var xy = x * y2;2876 var xz = x * z2;2877 var yy = y * y2;2878 var yz = y * z2;2879 var zz = z * z2;2880 var wx = w * x2;2881 var wy = w * y2;2882 var wz = w * z2;2883 var sx = s[0];2884 var sy = s[1];2885 var sz = s[2];2886 out[0] = (1 - (yy + zz)) * sx;2887 out[1] = (xy + wz) * sx;2888 out[2] = (xz - wy) * sx;2889 out[3] = 0;2890 out[4] = (xy - wz) * sy;2891 out[5] = (1 - (xx + zz)) * sy;2892 out[6] = (yz + wx) * sy;2893 out[7] = 0;2894 out[8] = (xz + wy) * sz;2895 out[9] = (yz - wx) * sz;2896 out[10] = (1 - (xx + yy)) * sz;2897 out[11] = 0;2898 out[12] = v[0];2899 out[13] = v[1];2900 out[14] = v[2];2901 out[15] = 1;2902 return out;2903 }2904 /**2905 * Creates a matrix from a quaternion rotation, vector translation and vector scale, rotating and scaling around the given origin2906 * This is equivalent to (but much faster than):2907 *2908 * mat4.identity(dest);2909 * mat4.translate(dest, vec);2910 * mat4.translate(dest, origin);2911 * let quatMat = mat4.create();2912 * quat4.toMat4(quat, quatMat);2913 * mat4.multiply(dest, quatMat);2914 * mat4.scale(dest, scale)2915 * mat4.translate(dest, negativeOrigin);2916 *2917 * @param {mat4} out mat4 receiving operation result2918 * @param {quat4} q Rotation quaternion2919 * @param {ReadonlyVec3} v Translation vector2920 * @param {ReadonlyVec3} s Scaling vector2921 * @param {ReadonlyVec3} o The origin vector around which to scale and rotate2922 * @returns {mat4} out2923 */2924 function fromRotationTranslationScaleOrigin(out, q, v, s, o) {2925 // Quaternion math2926 var x = q[0],2927 y = q[1],2928 z = q[2],2929 w = q[3];2930 var x2 = x + x;2931 var y2 = y + y;2932 var z2 = z + z;2933 var xx = x * x2;2934 var xy = x * y2;2935 var xz = x * z2;2936 var yy = y * y2;2937 var yz = y * z2;2938 var zz = z * z2;2939 var wx = w * x2;2940 var wy = w * y2;2941 var wz = w * z2;2942 var sx = s[0];2943 var sy = s[1];2944 var sz = s[2];2945 var ox = o[0];2946 var oy = o[1];2947 var oz = o[2];2948 var out0 = (1 - (yy + zz)) * sx;2949 var out1 = (xy + wz) * sx;2950 var out2 = (xz - wy) * sx;2951 var out4 = (xy - wz) * sy;2952 var out5 = (1 - (xx + zz)) * sy;2953 var out6 = (yz + wx) * sy;2954 var out8 = (xz + wy) * sz;2955 var out9 = (yz - wx) * sz;2956 var out10 = (1 - (xx + yy)) * sz;2957 out[0] = out0;2958 out[1] = out1;2959 out[2] = out2;2960 out[3] = 0;2961 out[4] = out4;2962 out[5] = out5;2963 out[6] = out6;2964 out[7] = 0;2965 out[8] = out8;2966 out[9] = out9;2967 out[10] = out10;2968 out[11] = 0;2969 out[12] = v[0] + ox - (out0 * ox + out4 * oy + out8 * oz);2970 out[13] = v[1] + oy - (out1 * ox + out5 * oy + out9 * oz);2971 out[14] = v[2] + oz - (out2 * ox + out6 * oy + out10 * oz);2972 out[15] = 1;2973 return out;2974 }2975 /**2976 * Calculates a 4x4 matrix from the given quaternion2977 *2978 * @param {mat4} out mat4 receiving operation result2979 * @param {ReadonlyQuat} q Quaternion to create matrix from2980 *2981 * @returns {mat4} out2982 */2983 function fromQuat$1(out, q) {2984 var x = q[0],2985 y = q[1],2986 z = q[2],2987 w = q[3];2988 var x2 = x + x;2989 var y2 = y + y;2990 var z2 = z + z;2991 var xx = x * x2;2992 var yx = y * x2;2993 var yy = y * y2;2994 var zx = z * x2;2995 var zy = z * y2;2996 var zz = z * z2;2997 var wx = w * x2;2998 var wy = w * y2;2999 var wz = w * z2;3000 out[0] = 1 - yy - zz;3001 out[1] = yx + wz;3002 out[2] = zx - wy;3003 out[3] = 0;3004 out[4] = yx - wz;3005 out[5] = 1 - xx - zz;3006 out[6] = zy + wx;3007 out[7] = 0;3008 out[8] = zx + wy;3009 out[9] = zy - wx;3010 out[10] = 1 - xx - yy;3011 out[11] = 0;3012 out[12] = 0;3013 out[13] = 0;3014 out[14] = 0;3015 out[15] = 1;3016 return out;3017 }3018 /**3019 * Generates a frustum matrix with the given bounds3020 *3021 * @param {mat4} out mat4 frustum matrix will be written into3022 * @param {Number} left Left bound of the frustum3023 * @param {Number} right Right bound of the frustum3024 * @param {Number} bottom Bottom bound of the frustum3025 * @param {Number} top Top bound of the frustum3026 * @param {Number} near Near bound of the frustum3027 * @param {Number} far Far bound of the frustum3028 * @returns {mat4} out3029 */3030 function frustum(out, left, right, bottom, top, near, far) {3031 var rl = 1 / (right - left);3032 var tb = 1 / (top - bottom);3033 var nf = 1 / (near - far);3034 out[0] = near * 2 * rl;3035 out[1] = 0;3036 out[2] = 0;3037 out[3] = 0;3038 out[4] = 0;3039 out[5] = near * 2 * tb;3040 out[6] = 0;3041 out[7] = 0;3042 out[8] = (right + left) * rl;3043 out[9] = (top + bottom) * tb;3044 out[10] = (far + near) * nf;3045 out[11] = -1;3046 out[12] = 0;3047 out[13] = 0;3048 out[14] = far * near * 2 * nf;3049 out[15] = 0;3050 return out;3051 }3052 /**3053 * Generates a perspective projection matrix with the given bounds.3054 * Passing null/undefined/no value for far will generate infinite projection matrix.3055 *3056 * @param {mat4} out mat4 frustum matrix will be written into3057 * @param {number} fovy Vertical field of view in radians3058 * @param {number} aspect Aspect ratio. typically viewport width/height3059 * @param {number} near Near bound of the frustum3060 * @param {number} far Far bound of the frustum, can be null or Infinity3061 * @returns {mat4} out3062 */3063 function perspective(out, fovy, aspect, near, far) {3064 var f = 1.0 / Math.tan(fovy / 2),3065 nf;3066 out[0] = f / aspect;3067 out[1] = 0;3068 out[2] = 0;3069 out[3] = 0;3070 out[4] = 0;3071 out[5] = f;3072 out[6] = 0;3073 out[7] = 0;3074 out[8] = 0;3075 out[9] = 0;3076 out[11] = -1;3077 out[12] = 0;3078 out[13] = 0;3079 out[15] = 0;3080 if (far != null && far !== Infinity) {3081 nf = 1 / (near - far);3082 out[10] = (far + near) * nf;3083 out[14] = 2 * far * near * nf;3084 } else {3085 out[10] = -1;3086 out[14] = -2 * near;3087 }3088 //out[10] = -out[10];3089 //out[14] = -out[14];3090 return out;3091 }3092 /**3093 * Generates a perspective projection matrix with the given field of view.3094 * This is primarily useful for generating projection matrices to be used3095 * with the still experiemental WebVR API.3096 *3097 * @param {mat4} out mat4 frustum matrix will be written into3098 * @param {Object} fov Object containing the following values: upDegrees, downDegrees, leftDegrees, rightDegrees3099 * @param {number} near Near bound of the frustum3100 * @param {number} far Far bound of the frustum3101 * @returns {mat4} out3102 */3103 function perspectiveFromFieldOfView(out, fov, near, far) {3104 var upTan = Math.tan(fov.upDegrees * Math.PI / 180.0);3105 var downTan = Math.tan(fov.downDegrees * Math.PI / 180.0);3106 var leftTan = Math.tan(fov.leftDegrees * Math.PI / 180.0);3107 var rightTan = Math.tan(fov.rightDegrees * Math.PI / 180.0);3108 var xScale = 2.0 / (leftTan + rightTan);3109 var yScale = 2.0 / (upTan + downTan);3110 out[0] = xScale;3111 out[1] = 0.0;3112 out[2] = 0.0;3113 out[3] = 0.0;3114 out[4] = 0.0;3115 out[5] = yScale;3116 out[6] = 0.0;3117 out[7] = 0.0;3118 out[8] = -((leftTan - rightTan) * xScale * 0.5);3119 out[9] = (upTan - downTan) * yScale * 0.5;3120 out[10] = far / (near - far);3121 out[11] = -1.0;3122 out[12] = 0.0;3123 out[13] = 0.0;3124 out[14] = far * near / (near - far);3125 out[15] = 0.0;3126 return out;3127 }3128 /**3129 * Generates a orthogonal projection matrix with the given bounds3130 *3131 * @param {mat4} out mat4 frustum matrix will be written into3132 * @param {number} left Left bound of the frustum3133 * @param {number} right Right bound of the frustum3134 * @param {number} bottom Bottom bound of the frustum3135 * @param {number} top Top bound of the frustum3136 * @param {number} near Near bound of the frustum3137 * @param {number} far Far bound of the frustum3138 * @returns {mat4} out3139 */3140 function ortho(out, left, right, bottom, top, near, far) {3141 var lr = 1 / (left - right);3142 var bt = 1 / (bottom - top);3143 var nf = 1 / (near - far);3144 out[0] = -2 * lr;3145 out[1] = 0;3146 out[2] = 0;3147 out[3] = 0;3148 out[4] = 0;3149 out[5] = -2 * bt;3150 out[6] = 0;3151 out[7] = 0;3152 out[8] = 0;3153 out[9] = 0;3154 out[10] = 2 * nf;3155 out[11] = 0;3156 out[12] = (left + right) * lr;3157 out[13] = (top + bottom) * bt;3158 out[14] = (far + near) * nf;3159 out[15] = 1;3160 return out;3161 }3162 /**3163 * Generates a look-at matrix with the given eye position, focal point, and up axis.3164 * If you want a matrix that actually makes an object look at another object, you should use targetTo instead.3165 *3166 * @param {mat4} out mat4 frustum matrix will be written into3167 * @param {ReadonlyVec3} eye Position of the viewer3168 * @param {ReadonlyVec3} center Point the viewer is looking at3169 * @param {ReadonlyVec3} up vec3 pointing up3170 * @returns {mat4} out3171 */3172 function lookAt(out, eye, center, up) {3173 var x0, x1, x2, y0, y1, y2, z0, z1, z2, len;3174 var eyex = eye[0];3175 var eyey = eye[1];3176 var eyez = eye[2];3177 var upx = up[0];3178 var upy = up[1];3179 var upz = up[2];3180 var centerx = center[0];3181 var centery = center[1];3182 var centerz = center[2];3183 if (Math.abs(eyex - centerx) < EPSILON && Math.abs(eyey - centery) < EPSILON && Math.abs(eyez - centerz) < EPSILON) {3184 return identity$3(out);3185 }3186 z0 = eyex - centerx;3187 z1 = eyey - centery;3188 z2 = eyez - centerz;3189 len = 1 / Math.hypot(z0, z1, z2);3190 z0 *= len;3191 z1 *= len;3192 z2 *= len;3193 x0 = upy * z2 - upz * z1;3194 x1 = upz * z0 - upx * z2;3195 x2 = upx * z1 - upy * z0;3196 len = Math.hypot(x0, x1, x2);3197 if (!len) {3198 x0 = 0;3199 x1 = 0;3200 x2 = 0;3201 } else {3202 len = 1 / len;3203 x0 *= len;3204 x1 *= len;3205 x2 *= len;3206 }3207 y0 = z1 * x2 - z2 * x1;3208 y1 = z2 * x0 - z0 * x2;3209 y2 = z0 * x1 - z1 * x0;3210 len = Math.hypot(y0, y1, y2);3211 if (!len) {3212 y0 = 0;3213 y1 = 0;3214 y2 = 0;3215 } else {3216 len = 1 / len;3217 y0 *= len;3218 y1 *= len;3219 y2 *= len;3220 }3221 out[0] = x0;3222 out[1] = y0;3223 out[2] = z0;3224 out[3] = 0;3225 out[4] = x1;3226 out[5] = y1;3227 out[6] = z1;3228 out[7] = 0;3229 out[8] = x2;3230 out[9] = y2;3231 out[10] = z2;3232 out[11] = 0;3233 out[12] = -(x0 * eyex + x1 * eyey + x2 * eyez);3234 out[13] = -(y0 * eyex + y1 * eyey + y2 * eyez);3235 out[14] = -(z0 * eyex + z1 * eyey + z2 * eyez);3236 out[15] = 1;3237 return out;3238 }3239 /**3240 * Generates a matrix that makes something look at something else.3241 *3242 * @param {mat4} out mat4 frustum matrix will be written into3243 * @param {ReadonlyVec3} eye Position of the viewer3244 * @param {ReadonlyVec3} center Point the viewer is looking at3245 * @param {ReadonlyVec3} up vec3 pointing up3246 * @returns {mat4} out3247 */3248 function targetTo(out, eye, target, up) {3249 var eyex = eye[0],3250 eyey = eye[1],3251 eyez = eye[2],3252 upx = up[0],3253 upy = up[1],3254 upz = up[2];3255 var z0 = eyex - target[0],3256 z1 = eyey - target[1],3257 z2 = eyez - target[2];3258 var len = z0 * z0 + z1 * z1 + z2 * z2;3259 if (len > 0) {3260 len = 1 / Math.sqrt(len);3261 z0 *= len;3262 z1 *= len;3263 z2 *= len;3264 }3265 var x0 = upy * z2 - upz * z1,3266 x1 = upz * z0 - upx * z2,3267 x2 = upx * z1 - upy * z0;3268 len = x0 * x0 + x1 * x1 + x2 * x2;3269 if (len > 0) {3270 len = 1 / Math.sqrt(len);3271 x0 *= len;3272 x1 *= len;3273 x2 *= len;3274 }3275 out[0] = x0;3276 out[1] = x1;3277 out[2] = x2;3278 out[3] = 0;3279 out[4] = z1 * x2 - z2 * x1;3280 out[5] = z2 * x0 - z0 * x2;3281 out[6] = z0 * x1 - z1 * x0;3282 out[7] = 0;3283 out[8] = z0;3284 out[9] = z1;3285 out[10] = z2;3286 out[11] = 0;3287 out[12] = eyex;3288 out[13] = eyey;3289 out[14] = eyez;3290 out[15] = 1;3291 return out;3292 }3293 /**3294 * Returns a string representation of a mat43295 *3296 * @param {ReadonlyMat4} a matrix to represent as a string3297 * @returns {String} string representation of the matrix3298 */3299 function str$3(a) {3300 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] + ")";3301 }3302 /**3303 * Returns Frobenius norm of a mat43304 *3305 * @param {ReadonlyMat4} a the matrix to calculate Frobenius norm of3306 * @returns {Number} Frobenius norm3307 */3308 function frob$3(a) {3309 return Math.hypot(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]);3310 }3311 /**3312 * Adds two mat4's3313 *3314 * @param {mat4} out the receiving matrix3315 * @param {ReadonlyMat4} a the first operand3316 * @param {ReadonlyMat4} b the second operand3317 * @returns {mat4} out3318 */3319 function add$3(out, a, b) {3320 out[0] = a[0] + b[0];3321 out[1] = a[1] + b[1];3322 out[2] = a[2] + b[2];3323 out[3] = a[3] + b[3];3324 out[4] = a[4] + b[4];3325 out[5] = a[5] + b[5];3326 out[6] = a[6] + b[6];3327 out[7] = a[7] + b[7];3328 out[8] = a[8] + b[8];3329 out[9] = a[9] + b[9];3330 out[10] = a[10] + b[10];3331 out[11] = a[11] + b[11];3332 out[12] = a[12] + b[12];3333 out[13] = a[13] + b[13];3334 out[14] = a[14] + b[14];3335 out[15] = a[15] + b[15];3336 return out;3337 }3338 /**3339 * Subtracts matrix b from matrix a3340 *3341 * @param {mat4} out the receiving matrix3342 * @param {ReadonlyMat4} a the first operand3343 * @param {ReadonlyMat4} b the second operand3344 * @returns {mat4} out3345 */3346 function subtract$3(out, a, b) {3347 out[0] = a[0] - b[0];3348 out[1] = a[1] - b[1];3349 out[2] = a[2] - b[2];3350 out[3] = a[3] - b[3];3351 out[4] = a[4] - b[4];3352 out[5] = a[5] - b[5];3353 out[6] = a[6] - b[6];3354 out[7] = a[7] - b[7];3355 out[8] = a[8] - b[8];3356 out[9] = a[9] - b[9];3357 out[10] = a[10] - b[10];3358 out[11] = a[11] - b[11];3359 out[12] = a[12] - b[12];3360 out[13] = a[13] - b[13];3361 out[14] = a[14] - b[14];3362 out[15] = a[15] - b[15];3363 return out;3364 }3365 /**3366 * Multiply each element of the matrix by a scalar.3367 *3368 * @param {mat4} out the receiving matrix3369 * @param {ReadonlyMat4} a the matrix to scale3370 * @param {Number} b amount to scale the matrix's elements by3371 * @returns {mat4} out3372 */3373 function multiplyScalar$3(out, a, b) {3374 out[0] = a[0] * b;3375 out[1] = a[1] * b;3376 out[2] = a[2] * b;3377 out[3] = a[3] * b;3378 out[4] = a[4] * b;3379 out[5] = a[5] * b;3380 out[6] = a[6] * b;3381 out[7] = a[7] * b;3382 out[8] = a[8] * b;3383 out[9] = a[9] * b;3384 out[10] = a[10] * b;3385 out[11] = a[11] * b;3386 out[12] = a[12] * b;3387 out[13] = a[13] * b;3388 out[14] = a[14] * b;3389 out[15] = a[15] * b;3390 return out;3391 }3392 /**3393 * Adds two mat4's after multiplying each element of the second operand by a scalar value.3394 *3395 * @param {mat4} out the receiving vector3396 * @param {ReadonlyMat4} a the first operand3397 * @param {ReadonlyMat4} b the second operand3398 * @param {Number} scale the amount to scale b's elements by before adding3399 * @returns {mat4} out3400 */3401 function multiplyScalarAndAdd$3(out, a, b, scale) {3402 out[0] = a[0] + b[0] * scale;3403 out[1] = a[1] + b[1] * scale;3404 out[2] = a[2] + b[2] * scale;3405 out[3] = a[3] + b[3] * scale;3406 out[4] = a[4] + b[4] * scale;3407 out[5] = a[5] + b[5] * scale;3408 out[6] = a[6] + b[6] * scale;3409 out[7] = a[7] + b[7] * scale;3410 out[8] = a[8] + b[8] * scale;3411 out[9] = a[9] + b[9] * scale;3412 out[10] = a[10] + b[10] * scale;3413 out[11] = a[11] + b[11] * scale;3414 out[12] = a[12] + b[12] * scale;3415 out[13] = a[13] + b[13] * scale;3416 out[14] = a[14] + b[14] * scale;3417 out[15] = a[15] + b[15] * scale;3418 return out;3419 }3420 /**3421 * Returns whether or not the matrices have exactly the same elements in the same position (when compared with ===)3422 *3423 * @param {ReadonlyMat4} a The first matrix.3424 * @param {ReadonlyMat4} b The second matrix.3425 * @returns {Boolean} True if the matrices are equal, false otherwise.3426 */3427 function exactEquals$3(a, b) {3428 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];3429 }3430 /**3431 * Returns whether or not the matrices have approximately the same elements in the same position.3432 *3433 * @param {ReadonlyMat4} a The first matrix.3434 * @param {ReadonlyMat4} b The second matrix.3435 * @returns {Boolean} True if the matrices are equal, false otherwise.3436 */3437 function equals$4(a, b) {3438 var a0 = a[0],3439 a1 = a[1],3440 a2 = a[2],3441 a3 = a[3];3442 var a4 = a[4],3443 a5 = a[5],3444 a6 = a[6],3445 a7 = a[7];3446 var a8 = a[8],3447 a9 = a[9],3448 a10 = a[10],3449 a11 = a[11];3450 var a12 = a[12],3451 a13 = a[13],3452 a14 = a[14],3453 a15 = a[15];3454 var b0 = b[0],3455 b1 = b[1],3456 b2 = b[2],3457 b3 = b[3];3458 var b4 = b[4],3459 b5 = b[5],3460 b6 = b[6],3461 b7 = b[7];3462 var b8 = b[8],3463 b9 = b[9],3464 b10 = b[10],3465 b11 = b[11];3466 var b12 = b[12],3467 b13 = b[13],3468 b14 = b[14],3469 b15 = b[15];3470 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));3471 }3472 /**3473 * Alias for {@link mat4.multiply}3474 * @function3475 */3476 var mul$3 = multiply$3;3477 /**3478 * Alias for {@link mat4.subtract}3479 * @function3480 */3481 var sub$3 = subtract$3;3482 var mat4 = /*#__PURE__*/Object.freeze({3483 __proto__: null,3484 create: create$3,3485 clone: clone$3,3486 copy: copy$3,3487 fromValues: fromValues$3,3488 set: set$3,3489 identity: identity$3,3490 transpose: transpose$2,3491 invert: invert$3,3492 adjoint: adjoint$2,3493 determinant: determinant$3,3494 multiply: multiply$3,3495 translate: translate$2,3496 scale: scale$3,3497 rotate: rotate$3,3498 rotateX: rotateX,3499 rotateY: rotateY,3500 rotateZ: rotateZ,3501 fromTranslation: fromTranslation$2,3502 fromScaling: fromScaling$3,3503 fromRotation: fromRotation$3,3504 fromXRotation: fromXRotation,3505 fromYRotation: fromYRotation,3506 fromZRotation: fromZRotation,3507 fromRotationTranslation: fromRotationTranslation,3508 fromQuat2: fromQuat2,3509 getTranslation: getTranslation,3510 getScaling: getScaling,3511 getRotation: getRotation,3512 fromRotationTranslationScale: fromRotationTranslationScale,3513 fromRotationTranslationScaleOrigin: fromRotationTranslationScaleOrigin,3514 fromQuat: fromQuat$1,3515 frustum: frustum,3516 perspective: perspective,3517 perspectiveFromFieldOfView: perspectiveFromFieldOfView,3518 ortho: ortho,3519 lookAt: lookAt,3520 targetTo: targetTo,3521 str: str$3,3522 frob: frob$3,3523 add: add$3,3524 subtract: subtract$3,3525 multiplyScalar: multiplyScalar$3,3526 multiplyScalarAndAdd: multiplyScalarAndAdd$3,3527 exactEquals: exactEquals$3,3528 equals: equals$4,3529 mul: mul$3,3530 sub: sub$33531 });3532 /**3533 * 3 Dimensional Vector3534 * @module vec33535 */3536 /**3537 * Creates a new, empty vec33538 *3539 * @returns {vec3} a new 3D vector3540 */3541 function create$4() {3542 var out = new ARRAY_TYPE(3);3543 if (ARRAY_TYPE != Float32Array) {3544 out[0] = 0;3545 out[1] = 0;3546 out[2] = 0;3547 }3548 return out;3549 }3550 /**3551 * Creates a new vec3 initialized with values from an existing vector3552 *3553 * @param {ReadonlyVec3} a vector to clone3554 * @returns {vec3} a new 3D vector3555 */3556 function clone$4(a) {3557 var out = new ARRAY_TYPE(3);3558 out[0] = a[0];3559 out[1] = a[1];3560 out[2] = a[2];3561 return out;3562 }3563 /**3564 * Calculates the length of a vec33565 *3566 * @param {ReadonlyVec3} a vector to calculate length of3567 * @returns {Number} length of a3568 */3569 function length(a) {3570 var x = a[0];3571 var y = a[1];3572 var z = a[2];3573 return Math.hypot(x, y, z);3574 }3575 /**3576 * Creates a new vec3 initialized with the given values3577 *3578 * @param {Number} x X component3579 * @param {Number} y Y component3580 * @param {Number} z Z component3581 * @returns {vec3} a new 3D vector3582 */3583 function fromValues$4(x, y, z) {3584 var out = new ARRAY_TYPE(3);3585 out[0] = x;3586 out[1] = y;3587 out[2] = z;3588 return out;3589 }3590 /**3591 * Copy the values from one vec3 to another3592 *3593 * @param {vec3} out the receiving vector3594 * @param {ReadonlyVec3} a the source vector3595 * @returns {vec3} out3596 */3597 function copy$4(out, a) {3598 out[0] = a[0];3599 out[1] = a[1];3600 out[2] = a[2];3601 return out;3602 }3603 /**3604 * Set the components of a vec3 to the given values3605 *3606 * @param {vec3} out the receiving vector3607 * @param {Number} x X component3608 * @param {Number} y Y component3609 * @param {Number} z Z component3610 * @returns {vec3} out3611 */3612 function set$4(out, x, y, z) {3613 out[0] = x;3614 out[1] = y;3615 out[2] = z;3616 return out;3617 }3618 /**3619 * Adds two vec3's3620 *3621 * @param {vec3} out the receiving vector3622 * @param {ReadonlyVec3} a the first operand3623 * @param {ReadonlyVec3} b the second operand3624 * @returns {vec3} out3625 */3626 function add$4(out, a, b) {3627 out[0] = a[0] + b[0];3628 out[1] = a[1] + b[1];3629 out[2] = a[2] + b[2];3630 return out;3631 }3632 /**3633 * Subtracts vector b from vector a3634 *3635 * @param {vec3} out the receiving vector3636 * @param {ReadonlyVec3} a the first operand3637 * @param {ReadonlyVec3} b the second operand3638 * @returns {vec3} out3639 */3640 function subtract$4(out, a, b) {3641 out[0] = a[0] - b[0];3642 out[1] = a[1] - b[1];3643 out[2] = a[2] - b[2];3644 return out;3645 }3646 /**3647 * Multiplies two vec3's3648 *3649 * @param {vec3} out the receiving vector3650 * @param {ReadonlyVec3} a the first operand3651 * @param {ReadonlyVec3} b the second operand3652 * @returns {vec3} out3653 */3654 function multiply$4(out, a, b) {3655 out[0] = a[0] * b[0];3656 out[1] = a[1] * b[1];3657 out[2] = a[2] * b[2];3658 return out;3659 }3660 /**3661 * Divides two vec3's3662 *3663 * @param {vec3} out the receiving vector3664 * @param {ReadonlyVec3} a the first operand3665 * @param {ReadonlyVec3} b the second operand3666 * @returns {vec3} out3667 */3668 function divide(out, a, b) {3669 out[0] = a[0] / b[0];3670 out[1] = a[1] / b[1];3671 out[2] = a[2] / b[2];3672 return out;3673 }3674 /**3675 * Math.ceil the components of a vec33676 *3677 * @param {vec3} out the receiving vector3678 * @param {ReadonlyVec3} a vector to ceil3679 * @returns {vec3} out3680 */3681 function ceil(out, a) {3682 out[0] = Math.ceil(a[0]);3683 out[1] = Math.ceil(a[1]);3684 out[2] = Math.ceil(a[2]);3685 return out;3686 }3687 /**3688 * Math.floor the components of a vec33689 *3690 * @param {vec3} out the receiving vector3691 * @param {ReadonlyVec3} a vector to floor3692 * @returns {vec3} out3693 */3694 function floor(out, a) {3695 out[0] = Math.floor(a[0]);3696 out[1] = Math.floor(a[1]);3697 out[2] = Math.floor(a[2]);3698 return out;3699 }3700 /**3701 * Returns the minimum of two vec3's3702 *3703 * @param {vec3} out the receiving vector3704 * @param {ReadonlyVec3} a the first operand3705 * @param {ReadonlyVec3} b the second operand3706 * @returns {vec3} out3707 */3708 function min(out, a, b) {3709 out[0] = Math.min(a[0], b[0]);3710 out[1] = Math.min(a[1], b[1]);3711 out[2] = Math.min(a[2], b[2]);3712 return out;3713 }3714 /**3715 * Returns the maximum of two vec3's3716 *3717 * @param {vec3} out the receiving vector3718 * @param {ReadonlyVec3} a the first operand3719 * @param {ReadonlyVec3} b the second operand3720 * @returns {vec3} out3721 */3722 function max(out, a, b) {3723 out[0] = Math.max(a[0], b[0]);3724 out[1] = Math.max(a[1], b[1]);3725 out[2] = Math.max(a[2], b[2]);3726 return out;3727 }3728 /**3729 * Math.round the components of a vec33730 *3731 * @param {vec3} out the receiving vector3732 * @param {ReadonlyVec3} a vector to round3733 * @returns {vec3} out3734 */3735 function round(out, a) {3736 out[0] = Math.round(a[0]);3737 out[1] = Math.round(a[1]);3738 out[2] = Math.round(a[2]);3739 return out;3740 }3741 /**3742 * Scales a vec3 by a scalar number3743 *3744 * @param {vec3} out the receiving vector3745 * @param {ReadonlyVec3} a the vector to scale3746 * @param {Number} b amount to scale the vector by3747 * @returns {vec3} out3748 */3749 function scale$4(out, a, b) {3750 out[0] = a[0] * b;3751 out[1] = a[1] * b;3752 out[2] = a[2] * b;3753 return out;3754 }3755 /**3756 * Adds two vec3's after scaling the second operand by a scalar value3757 *3758 * @param {vec3} out the receiving vector3759 * @param {ReadonlyVec3} a the first operand3760 * @param {ReadonlyVec3} b the second operand3761 * @param {Number} scale the amount to scale b by before adding3762 * @returns {vec3} out3763 */3764 function scaleAndAdd(out, a, b, scale) {3765 out[0] = a[0] + b[0] * scale;3766 out[1] = a[1] + b[1] * scale;3767 out[2] = a[2] + b[2] * scale;3768 return out;3769 }3770 /**3771 * Calculates the euclidian distance between two vec3's3772 *3773 * @param {ReadonlyVec3} a the first operand3774 * @param {ReadonlyVec3} b the second operand3775 * @returns {Number} distance between a and b3776 */3777 function distance(a, b) {3778 var x = b[0] - a[0];3779 var y = b[1] - a[1];3780 var z = b[2] - a[2];3781 return Math.hypot(x, y, z);3782 }3783 /**3784 * Calculates the squared euclidian distance between two vec3's3785 *3786 * @param {ReadonlyVec3} a the first operand3787 * @param {ReadonlyVec3} b the second operand3788 * @returns {Number} squared distance between a and b3789 */3790 function squaredDistance(a, b) {3791 var x = b[0] - a[0];3792 var y = b[1] - a[1];3793 var z = b[2] - a[2];3794 return x * x + y * y + z * z;3795 }3796 /**3797 * Calculates the squared length of a vec33798 *3799 * @param {ReadonlyVec3} a vector to calculate squared length of3800 * @returns {Number} squared length of a3801 */3802 function squaredLength(a) {3803 var x = a[0];3804 var y = a[1];3805 var z = a[2];3806 return x * x + y * y + z * z;3807 }3808 /**3809 * Negates the components of a vec33810 *3811 * @param {vec3} out the receiving vector3812 * @param {ReadonlyVec3} a vector to negate3813 * @returns {vec3} out3814 */3815 function negate(out, a) {3816 out[0] = -a[0];3817 out[1] = -a[1];3818 out[2] = -a[2];3819 return out;3820 }3821 /**3822 * Returns the inverse of the components of a vec33823 *3824 * @param {vec3} out the receiving vector3825 * @param {ReadonlyVec3} a vector to invert3826 * @returns {vec3} out3827 */3828 function inverse(out, a) {3829 out[0] = 1.0 / a[0];3830 out[1] = 1.0 / a[1];3831 out[2] = 1.0 / a[2];3832 return out;3833 }3834 /**3835 * Normalize a vec33836 *3837 * @param {vec3} out the receiving vector3838 * @param {ReadonlyVec3} a vector to normalize3839 * @returns {vec3} out3840 */3841 function normalize(out, a) {3842 var x = a[0];3843 var y = a[1];3844 var z = a[2];3845 var len = x * x + y * y + z * z;3846 if (len > 0) {3847 //TODO: evaluate use of glm_invsqrt here?3848 len = 1 / Math.sqrt(len);3849 }3850 out[0] = a[0] * len;3851 out[1] = a[1] * len;3852 out[2] = a[2] * len;3853 return out;3854 }3855 /**3856 * Calculates the dot product of two vec3's3857 *3858 * @param {ReadonlyVec3} a the first operand3859 * @param {ReadonlyVec3} b the second operand3860 * @returns {Number} dot product of a and b3861 */3862 function dot(a, b) {3863 return a[0] * b[0] + a[1] * b[1] + a[2] * b[2];3864 }3865 /**3866 * Computes the cross product of two vec3's3867 *3868 * @param {vec3} out the receiving vector3869 * @param {ReadonlyVec3} a the first operand3870 * @param {ReadonlyVec3} b the second operand3871 * @returns {vec3} out3872 */3873 function cross(out, a, b) {3874 var ax = a[0],3875 ay = a[1],3876 az = a[2];3877 var bx = b[0],3878 by = b[1],3879 bz = b[2];3880 out[0] = ay * bz - az * by;3881 out[1] = az * bx - ax * bz;3882 out[2] = ax * by - ay * bx;3883 return out;3884 }3885 /**3886 * Performs a linear interpolation between two vec3's3887 *3888 * @param {vec3} out the receiving vector3889 * @param {ReadonlyVec3} a the first operand3890 * @param {ReadonlyVec3} b the second operand3891 * @param {Number} t interpolation amount, in the range [0-1], between the two inputs3892 * @returns {vec3} out3893 */3894 function lerp(out, a, b, t) {3895 var ax = a[0];3896 var ay = a[1];3897 var az = a[2];3898 out[0] = ax + t * (b[0] - ax);3899 out[1] = ay + t * (b[1] - ay);3900 out[2] = az + t * (b[2] - az);3901 return out;3902 }3903 /**3904 * Performs a hermite interpolation with two control points3905 *3906 * @param {vec3} out the receiving vector3907 * @param {ReadonlyVec3} a the first operand3908 * @param {ReadonlyVec3} b the second operand3909 * @param {ReadonlyVec3} c the third operand3910 * @param {ReadonlyVec3} d the fourth operand3911 * @param {Number} t interpolation amount, in the range [0-1], between the two inputs3912 * @returns {vec3} out3913 */3914 function hermite(out, a, b, c, d, t) {3915 var factorTimes2 = t * t;3916 var factor1 = factorTimes2 * (2 * t - 3) + 1;3917 var factor2 = factorTimes2 * (t - 2) + t;3918 var factor3 = factorTimes2 * (t - 1);3919 var factor4 = factorTimes2 * (3 - 2 * t);3920 out[0] = a[0] * factor1 + b[0] * factor2 + c[0] * factor3 + d[0] * factor4;3921 out[1] = a[1] * factor1 + b[1] * factor2 + c[1] * factor3 + d[1] * factor4;3922 out[2] = a[2] * factor1 + b[2] * factor2 + c[2] * factor3 + d[2] * factor4;3923 return out;3924 }3925 /**3926 * Performs a bezier interpolation with two control points3927 *3928 * @param {vec3} out the receiving vector3929 * @param {ReadonlyVec3} a the first operand3930 * @param {ReadonlyVec3} b the second operand3931 * @param {ReadonlyVec3} c the third operand3932 * @param {ReadonlyVec3} d the fourth operand3933 * @param {Number} t interpolation amount, in the range [0-1], between the two inputs3934 * @returns {vec3} out3935 */3936 function bezier(out, a, b, c, d, t) {3937 var inverseFactor = 1 - t;3938 var inverseFactorTimesTwo = inverseFactor * inverseFactor;3939 var factorTimes2 = t * t;3940 var factor1 = inverseFactorTimesTwo * inverseFactor;3941 var factor2 = 3 * t * inverseFactorTimesTwo;3942 var factor3 = 3 * factorTimes2 * inverseFactor;3943 var factor4 = factorTimes2 * t;3944 out[0] = a[0] * factor1 + b[0] * factor2 + c[0] * factor3 + d[0] * factor4;3945 out[1] = a[1] * factor1 + b[1] * factor2 + c[1] * factor3 + d[1] * factor4;3946 out[2] = a[2] * factor1 + b[2] * factor2 + c[2] * factor3 + d[2] * factor4;3947 return out;3948 }3949 /**3950 * Generates a random vector with the given scale3951 *3952 * @param {vec3} out the receiving vector3953 * @param {Number} [scale] Length of the resulting vector. If ommitted, a unit vector will be returned3954 * @returns {vec3} out3955 */3956 function random(out, scale) {3957 scale = scale || 1.0;3958 var r = RANDOM() * 2.0 * Math.PI;3959 var z = RANDOM() * 2.0 - 1.0;3960 var zScale = Math.sqrt(1.0 - z * z) * scale;3961 out[0] = Math.cos(r) * zScale;3962 out[1] = Math.sin(r) * zScale;3963 out[2] = z * scale;3964 return out;3965 }3966 /**3967 * Transforms the vec3 with a mat4.3968 * 4th vector component is implicitly '1'3969 *3970 * @param {vec3} out the receiving vector3971 * @param {ReadonlyVec3} a the vector to transform3972 * @param {ReadonlyMat4} m matrix to transform with3973 * @returns {vec3} out3974 */3975 function transformMat4(out, a, m) {3976 var x = a[0],3977 y = a[1],3978 z = a[2];3979 var w = m[3] * x + m[7] * y + m[11] * z + m[15];3980 w = w || 1.0;3981 out[0] = (m[0] * x + m[4] * y + m[8] * z + m[12]) / w;3982 out[1] = (m[1] * x + m[5] * y + m[9] * z + m[13]) / w;3983 out[2] = (m[2] * x + m[6] * y + m[10] * z + m[14]) / w;3984 return out;3985 }3986 /**3987 * Transforms the vec3 with a mat3.3988 *3989 * @param {vec3} out the receiving vector3990 * @param {ReadonlyVec3} a the vector to transform3991 * @param {ReadonlyMat3} m the 3x3 matrix to transform with3992 * @returns {vec3} out3993 */3994 function transformMat3(out, a, m) {3995 var x = a[0],3996 y = a[1],3997 z = a[2];3998 out[0] = x * m[0] + y * m[3] + z * m[6];3999 out[1] = x * m[1] + y * m[4] + z * m[7];4000 out[2] = x * m[2] + y * m[5] + z * m[8];4001 return out;4002 }4003 /**4004 * Transforms the vec3 with a quat4005 * Can also be used for dual quaternions. (Multiply it with the real part)4006 *4007 * @param {vec3} out the receiving vector4008 * @param {ReadonlyVec3} a the vector to transform4009 * @param {ReadonlyQuat} q quaternion to transform with4010 * @returns {vec3} out4011 */4012 function transformQuat(out, a, q) {4013 // benchmarks: https://jsperf.com/quaternion-transform-vec3-implementations-fixed4014 var qx = q[0],4015 qy = q[1],4016 qz = q[2],4017 qw = q[3];4018 var x = a[0],4019 y = a[1],4020 z = a[2]; // var qvec = [qx, qy, qz];4021 // var uv = vec3.cross([], qvec, a);4022 var uvx = qy * z - qz * y,4023 uvy = qz * x - qx * z,4024 uvz = qx * y - qy * x; // var uuv = vec3.cross([], qvec, uv);4025 var uuvx = qy * uvz - qz * uvy,4026 uuvy = qz * uvx - qx * uvz,4027 uuvz = qx * uvy - qy * uvx; // vec3.scale(uv, uv, 2 * w);4028 var w2 = qw * 2;4029 uvx *= w2;4030 uvy *= w2;4031 uvz *= w2; // vec3.scale(uuv, uuv, 2);4032 uuvx *= 2;4033 uuvy *= 2;4034 uuvz *= 2; // return vec3.add(out, a, vec3.add(out, uv, uuv));4035 out[0] = x + uvx + uuvx;4036 out[1] = y + uvy + uuvy;4037 out[2] = z + uvz + uuvz;4038 return out;4039 }4040 /**4041 * Rotate a 3D vector around the x-axis4042 * @param {vec3} out The receiving vec34043 * @param {ReadonlyVec3} a The vec3 point to rotate4044 * @param {ReadonlyVec3} b The origin of the rotation4045 * @param {Number} rad The angle of rotation in radians4046 * @returns {vec3} out4047 */4048 function rotateX$1(out, a, b, rad) {4049 var p = [],4050 r = []; //Translate point to the origin4051 p[0] = a[0] - b[0];4052 p[1] = a[1] - b[1];4053 p[2] = a[2] - b[2]; //perform rotation4054 r[0] = p[0];4055 r[1] = p[1] * Math.cos(rad) - p[2] * Math.sin(rad);4056 r[2] = p[1] * Math.sin(rad) + p[2] * Math.cos(rad); //translate to correct position4057 out[0] = r[0] + b[0];4058 out[1] = r[1] + b[1];4059 out[2] = r[2] + b[2];4060 return out;4061 }4062 /**4063 * Rotate a 3D vector around the y-axis4064 * @param {vec3} out The receiving vec34065 * @param {ReadonlyVec3} a The vec3 point to rotate4066 * @param {ReadonlyVec3} b The origin of the rotation4067 * @param {Number} rad The angle of rotation in radians4068 * @returns {vec3} out4069 */4070 function rotateY$1(out, a, b, rad) {4071 var p = [],4072 r = []; //Translate point to the origin4073 p[0] = a[0] - b[0];4074 p[1] = a[1] - b[1];4075 p[2] = a[2] - b[2]; //perform rotation4076 r[0] = p[2] * Math.sin(rad) + p[0] * Math.cos(rad);4077 r[1] = p[1];4078 r[2] = p[2] * Math.cos(rad) - p[0] * Math.sin(rad); //translate to correct position4079 out[0] = r[0] + b[0];4080 out[1] = r[1] + b[1];4081 out[2] = r[2] + b[2];4082 return out;4083 }4084 /**4085 * Rotate a 3D vector around the z-axis4086 * @param {vec3} out The receiving vec34087 * @param {ReadonlyVec3} a The vec3 point to rotate4088 * @param {ReadonlyVec3} b The origin of the rotation4089 * @param {Number} rad The angle of rotation in radians4090 * @returns {vec3} out4091 */4092 function rotateZ$1(out, a, b, rad) {4093 var p = [],4094 r = []; //Translate point to the origin4095 p[0] = a[0] - b[0];4096 p[1] = a[1] - b[1];4097 p[2] = a[2] - b[2]; //perform rotation4098 r[0] = p[0] * Math.cos(rad) - p[1] * Math.sin(rad);4099 r[1] = p[0] * Math.sin(rad) + p[1] * Math.cos(rad);4100 r[2] = p[2]; //translate to correct position4101 out[0] = r[0] + b[0];4102 out[1] = r[1] + b[1];4103 out[2] = r[2] + b[2];4104 return out;4105 }4106 /**4107 * Get the angle between two 3D vectors4108 * @param {ReadonlyVec3} a The first operand4109 * @param {ReadonlyVec3} b The second operand4110 * @returns {Number} The angle in radians4111 */4112 function angle(a, b) {4113 var ax = a[0],4114 ay = a[1],4115 az = a[2],4116 bx = b[0],4117 by = b[1],4118 bz = b[2],4119 mag1 = Math.sqrt(ax * ax + ay * ay + az * az),4120 mag2 = Math.sqrt(bx * bx + by * by + bz * bz),4121 mag = mag1 * mag2,4122 cosine = mag && dot(a, b) / mag;4123 return Math.acos(Math.min(Math.max(cosine, -1), 1));4124 }4125 /**4126 * Set the components of a vec3 to zero4127 *4128 * @param {vec3} out the receiving vector4129 * @returns {vec3} out4130 */4131 function zero(out) {4132 out[0] = 0.0;4133 out[1] = 0.0;4134 out[2] = 0.0;4135 return out;4136 }4137 /**4138 * Returns a string representation of a vector4139 *4140 * @param {ReadonlyVec3} a vector to represent as a string4141 * @returns {String} string representation of the vector4142 */4143 function str$4(a) {4144 return "vec3(" + a[0] + ", " + a[1] + ", " + a[2] + ")";4145 }4146 /**4147 * Returns whether or not the vectors have exactly the same elements in the same position (when compared with ===)4148 *4149 * @param {ReadonlyVec3} a The first vector.4150 * @param {ReadonlyVec3} b The second vector.4151 * @returns {Boolean} True if the vectors are equal, false otherwise.4152 */4153 function exactEquals$4(a, b) {4154 return a[0] === b[0] && a[1] === b[1] && a[2] === b[2];4155 }4156 /**4157 * Returns whether or not the vectors have approximately the same elements in the same position.4158 *4159 * @param {ReadonlyVec3} a The first vector.4160 * @param {ReadonlyVec3} b The second vector.4161 * @returns {Boolean} True if the vectors are equal, false otherwise.4162 */4163 function equals$5(a, b) {4164 var a0 = a[0],4165 a1 = a[1],4166 a2 = a[2];4167 var b0 = b[0],4168 b1 = b[1],4169 b2 = b[2];4170 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));4171 }4172 /**4173 * Alias for {@link vec3.subtract}4174 * @function4175 */4176 var sub$4 = subtract$4;4177 /**4178 * Alias for {@link vec3.multiply}4179 * @function4180 */4181 var mul$4 = multiply$4;4182 /**4183 * Alias for {@link vec3.divide}4184 * @function4185 */4186 var div = divide;4187 /**4188 * Alias for {@link vec3.distance}4189 * @function4190 */4191 var dist = distance;4192 /**4193 * Alias for {@link vec3.squaredDistance}4194 * @function4195 */4196 var sqrDist = squaredDistance;4197 /**4198 * Alias for {@link vec3.length}4199 * @function4200 */4201 var len = length;4202 /**4203 * Alias for {@link vec3.squaredLength}4204 * @function4205 */4206 var sqrLen = squaredLength;4207 /**4208 * Perform some operation over an array of vec3s.4209 *4210 * @param {Array} a the array of vectors to iterate over4211 * @param {Number} stride Number of elements between the start of each vec3. If 0 assumes tightly packed4212 * @param {Number} offset Number of elements to skip at the beginning of the array4213 * @param {Number} count Number of vec3s to iterate over. If 0 iterates over entire array4214 * @param {Function} fn Function to call for each vector in the array4215 * @param {Object} [arg] additional argument to pass to fn4216 * @returns {Array} a4217 * @function4218 */4219 var forEach = function () {4220 var vec = create$4();4221 return function (a, stride, offset, count, fn, arg) {4222 var i, l;4223 if (!stride) {4224 stride = 3;4225 }4226 if (!offset) {4227 offset = 0;4228 }4229 if (count) {4230 l = Math.min(count * stride + offset, a.length);4231 } else {4232 l = a.length;4233 }4234 for (i = offset; i < l; i += stride) {4235 vec[0] = a[i];4236 vec[1] = a[i + 1];4237 vec[2] = a[i + 2];4238 fn(vec, vec, arg);4239 a[i] = vec[0];4240 a[i + 1] = vec[1];4241 a[i + 2] = vec[2];4242 }4243 return a;4244 };4245 }();4246 var vec3 = /*#__PURE__*/Object.freeze({4247 __proto__: null,4248 create: create$4,4249 clone: clone$4,4250 length: length,4251 fromValues: fromValues$4,4252 copy: copy$4,4253 set: set$4,4254 add: add$4,4255 subtract: subtract$4,4256 multiply: multiply$4,4257 divide: divide,4258 ceil: ceil,4259 floor: floor,4260 min: min,4261 max: max,4262 round: round,4263 scale: scale$4,4264 scaleAndAdd: scaleAndAdd,4265 distance: distance,4266 squaredDistance: squaredDistance,4267 squaredLength: squaredLength,4268 negate: negate,4269 inverse: inverse,4270 normalize: normalize,4271 dot: dot,4272 cross: cross,4273 lerp: lerp,4274 hermite: hermite,4275 bezier: bezier,4276 random: random,4277 transformMat4: transformMat4,4278 transformMat3: transformMat3,4279 transformQuat: transformQuat,4280 rotateX: rotateX$1,4281 rotateY: rotateY$1,4282 rotateZ: rotateZ$1,4283 angle: angle,4284 zero: zero,4285 str: str$4,4286 exactEquals: exactEquals$4,4287 equals: equals$5,4288 sub: sub$4,4289 mul: mul$4,4290 div: div,4291 dist: dist,4292 sqrDist: sqrDist,4293 len: len,4294 sqrLen: sqrLen,4295 forEach: forEach4296 });4297 /**4298 * 4 Dimensional Vector4299 * @module vec44300 */4301 /**4302 * Creates a new, empty vec44303 *4304 * @returns {vec4} a new 4D vector4305 */4306 function create$5() {4307 var out = new ARRAY_TYPE(4);4308 if (ARRAY_TYPE != Float32Array) {4309 out[0] = 0;4310 out[1] = 0;4311 out[2] = 0;4312 out[3] = 0;4313 }4314 return out;4315 }4316 /**4317 * Creates a new vec4 initialized with values from an existing vector4318 *4319 * @param {ReadonlyVec4} a vector to clone4320 * @returns {vec4} a new 4D vector4321 */4322 function clone$5(a) {4323 var out = new ARRAY_TYPE(4);4324 out[0] = a[0];4325 out[1] = a[1];4326 out[2] = a[2];4327 out[3] = a[3];4328 return out;4329 }4330 /**4331 * Creates a new vec4 initialized with the given values4332 *4333 * @param {Number} x X component4334 * @param {Number} y Y component4335 * @param {Number} z Z component4336 * @param {Number} w W component4337 * @returns {vec4} a new 4D vector4338 */4339 function fromValues$5(x, y, z, w) {4340 var out = new ARRAY_TYPE(4);4341 out[0] = x;4342 out[1] = y;4343 out[2] = z;4344 out[3] = w;4345 return out;4346 }4347 /**4348 * Copy the values from one vec4 to another4349 *4350 * @param {vec4} out the receiving vector4351 * @param {ReadonlyVec4} a the source vector4352 * @returns {vec4} out4353 */4354 function copy$5(out, a) {4355 out[0] = a[0];4356 out[1] = a[1];4357 out[2] = a[2];4358 out[3] = a[3];4359 return out;4360 }4361 /**4362 * Set the components of a vec4 to the given values4363 *4364 * @param {vec4} out the receiving vector4365 * @param {Number} x X component4366 * @param {Number} y Y component4367 * @param {Number} z Z component4368 * @param {Number} w W component4369 * @returns {vec4} out4370 */4371 function set$5(out, x, y, z, w) {4372 out[0] = x;4373 out[1] = y;4374 out[2] = z;4375 out[3] = w;4376 return out;4377 }4378 /**4379 * Adds two vec4's4380 *4381 * @param {vec4} out the receiving vector4382 * @param {ReadonlyVec4} a the first operand4383 * @param {ReadonlyVec4} b the second operand4384 * @returns {vec4} out4385 */4386 function add$5(out, a, b) {4387 out[0] = a[0] + b[0];4388 out[1] = a[1] + b[1];4389 out[2] = a[2] + b[2];4390 out[3] = a[3] + b[3];4391 return out;4392 }4393 /**4394 * Subtracts vector b from vector a4395 *4396 * @param {vec4} out the receiving vector4397 * @param {ReadonlyVec4} a the first operand4398 * @param {ReadonlyVec4} b the second operand4399 * @returns {vec4} out4400 */4401 function subtract$5(out, a, b) {4402 out[0] = a[0] - b[0];4403 out[1] = a[1] - b[1];4404 out[2] = a[2] - b[2];4405 out[3] = a[3] - b[3];4406 return out;4407 }4408 /**4409 * Multiplies two vec4's4410 *4411 * @param {vec4} out the receiving vector4412 * @param {ReadonlyVec4} a the first operand4413 * @param {ReadonlyVec4} b the second operand4414 * @returns {vec4} out4415 */4416 function multiply$5(out, a, b) {4417 out[0] = a[0] * b[0];4418 out[1] = a[1] * b[1];4419 out[2] = a[2] * b[2];4420 out[3] = a[3] * b[3];4421 return out;4422 }4423 /**4424 * Divides two vec4's4425 *4426 * @param {vec4} out the receiving vector4427 * @param {ReadonlyVec4} a the first operand4428 * @param {ReadonlyVec4} b the second operand4429 * @returns {vec4} out4430 */4431 function divide$1(out, a, b) {4432 out[0] = a[0] / b[0];4433 out[1] = a[1] / b[1];4434 out[2] = a[2] / b[2];4435 out[3] = a[3] / b[3];4436 return out;4437 }4438 /**4439 * Math.ceil the components of a vec44440 *4441 * @param {vec4} out the receiving vector4442 * @param {ReadonlyVec4} a vector to ceil4443 * @returns {vec4} out4444 */4445 function ceil$1(out, a) {4446 out[0] = Math.ceil(a[0]);4447 out[1] = Math.ceil(a[1]);4448 out[2] = Math.ceil(a[2]);4449 out[3] = Math.ceil(a[3]);4450 return out;4451 }4452 /**4453 * Math.floor the components of a vec44454 *4455 * @param {vec4} out the receiving vector4456 * @param {ReadonlyVec4} a vector to floor4457 * @returns {vec4} out4458 */4459 function floor$1(out, a) {4460 out[0] = Math.floor(a[0]);4461 out[1] = Math.floor(a[1]);4462 out[2] = Math.floor(a[2]);4463 out[3] = Math.floor(a[3]);4464 return out;4465 }4466 /**4467 * Returns the minimum of two vec4's4468 *4469 * @param {vec4} out the receiving vector4470 * @param {ReadonlyVec4} a the first operand4471 * @param {ReadonlyVec4} b the second operand4472 * @returns {vec4} out4473 */4474 function min$1(out, a, b) {4475 out[0] = Math.min(a[0], b[0]);4476 out[1] = Math.min(a[1], b[1]);4477 out[2] = Math.min(a[2], b[2]);4478 out[3] = Math.min(a[3], b[3]);4479 return out;4480 }4481 /**4482 * Returns the maximum of two vec4's4483 *4484 * @param {vec4} out the receiving vector4485 * @param {ReadonlyVec4} a the first operand4486 * @param {ReadonlyVec4} b the second operand4487 * @returns {vec4} out4488 */4489 function max$1(out, a, b) {4490 out[0] = Math.max(a[0], b[0]);4491 out[1] = Math.max(a[1], b[1]);4492 out[2] = Math.max(a[2], b[2]);4493 out[3] = Math.max(a[3], b[3]);4494 return out;4495 }4496 /**4497 * Math.round the components of a vec44498 *4499 * @param {vec4} out the receiving vector4500 * @param {ReadonlyVec4} a vector to round4501 * @returns {vec4} out4502 */4503 function round$1(out, a) {4504 out[0] = Math.round(a[0]);4505 out[1] = Math.round(a[1]);4506 out[2] = Math.round(a[2]);4507 out[3] = Math.round(a[3]);4508 return out;4509 }4510 /**4511 * Scales a vec4 by a scalar number4512 *4513 * @param {vec4} out the receiving vector4514 * @param {ReadonlyVec4} a the vector to scale4515 * @param {Number} b amount to scale the vector by4516 * @returns {vec4} out4517 */4518 function scale$5(out, a, b) {4519 out[0] = a[0] * b;4520 out[1] = a[1] * b;4521 out[2] = a[2] * b;4522 out[3] = a[3] * b;4523 return out;4524 }4525 /**4526 * Adds two vec4's after scaling the second operand by a scalar value4527 *4528 * @param {vec4} out the receiving vector4529 * @param {ReadonlyVec4} a the first operand4530 * @param {ReadonlyVec4} b the second operand4531 * @param {Number} scale the amount to scale b by before adding4532 * @returns {vec4} out4533 */4534 function scaleAndAdd$1(out, a, b, scale) {4535 out[0] = a[0] + b[0] * scale;4536 out[1] = a[1] + b[1] * scale;4537 out[2] = a[2] + b[2] * scale;4538 out[3] = a[3] + b[3] * scale;4539 return out;4540 }4541 /**4542 * Calculates the euclidian distance between two vec4's4543 *4544 * @param {ReadonlyVec4} a the first operand4545 * @param {ReadonlyVec4} b the second operand4546 * @returns {Number} distance between a and b4547 */4548 function distance$1(a, b) {4549 var x = b[0] - a[0];4550 var y = b[1] - a[1];4551 var z = b[2] - a[2];4552 var w = b[3] - a[3];4553 return Math.hypot(x, y, z, w);4554 }4555 /**4556 * Calculates the squared euclidian distance between two vec4's4557 *4558 * @param {ReadonlyVec4} a the first operand4559 * @param {ReadonlyVec4} b the second operand4560 * @returns {Number} squared distance between a and b4561 */4562 function squaredDistance$1(a, b) {4563 var x = b[0] - a[0];4564 var y = b[1] - a[1];4565 var z = b[2] - a[2];4566 var w = b[3] - a[3];4567 return x * x + y * y + z * z + w * w;4568 }4569 /**4570 * Calculates the length of a vec44571 *4572 * @param {ReadonlyVec4} a vector to calculate length of4573 * @returns {Number} length of a4574 */4575 function length$1(a) {4576 var x = a[0];4577 var y = a[1];4578 var z = a[2];4579 var w = a[3];4580 return Math.hypot(x, y, z, w);4581 }4582 /**4583 * Calculates the squared length of a vec44584 *4585 * @param {ReadonlyVec4} a vector to calculate squared length of4586 * @returns {Number} squared length of a4587 */4588 function squaredLength$1(a) {4589 var x = a[0];4590 var y = a[1];4591 var z = a[2];4592 var w = a[3];4593 return x * x + y * y + z * z + w * w;4594 }4595 /**4596 * Negates the components of a vec44597 *4598 * @param {vec4} out the receiving vector4599 * @param {ReadonlyVec4} a vector to negate4600 * @returns {vec4} out4601 */4602 function negate$1(out, a) {4603 out[0] = -a[0];4604 out[1] = -a[1];4605 out[2] = -a[2];4606 out[3] = -a[3];4607 return out;4608 }4609 /**4610 * Returns the inverse of the components of a vec44611 *4612 * @param {vec4} out the receiving vector4613 * @param {ReadonlyVec4} a vector to invert4614 * @returns {vec4} out4615 */4616 function inverse$1(out, a) {4617 out[0] = 1.0 / a[0];4618 out[1] = 1.0 / a[1];4619 out[2] = 1.0 / a[2];4620 out[3] = 1.0 / a[3];4621 return out;4622 }4623 /**4624 * Normalize a vec44625 *4626 * @param {vec4} out the receiving vector4627 * @param {ReadonlyVec4} a vector to normalize4628 * @returns {vec4} out4629 */4630 function normalize$1(out, a) {4631 var x = a[0];4632 var y = a[1];4633 var z = a[2];4634 var w = a[3];4635 var len = x * x + y * y + z * z + w * w;4636 if (len > 0) {4637 len = 1 / Math.sqrt(len);4638 }4639 out[0] = x * len;4640 out[1] = y * len;4641 out[2] = z * len;4642 out[3] = w * len;4643 return out;4644 }4645 /**4646 * Calculates the dot product of two vec4's4647 *4648 * @param {ReadonlyVec4} a the first operand4649 * @param {ReadonlyVec4} b the second operand4650 * @returns {Number} dot product of a and b4651 */4652 function dot$1(a, b) {4653 return a[0] * b[0] + a[1] * b[1] + a[2] * b[2] + a[3] * b[3];4654 }4655 /**4656 * Returns the cross-product of three vectors in a 4-dimensional space4657 *4658 * @param {ReadonlyVec4} result the receiving vector4659 * @param {ReadonlyVec4} U the first vector4660 * @param {ReadonlyVec4} V the second vector4661 * @param {ReadonlyVec4} W the third vector4662 * @returns {vec4} result4663 */4664 function cross$1(out, u, v, w) {4665 var A = v[0] * w[1] - v[1] * w[0],4666 B = v[0] * w[2] - v[2] * w[0],4667 C = v[0] * w[3] - v[3] * w[0],4668 D = v[1] * w[2] - v[2] * w[1],4669 E = v[1] * w[3] - v[3] * w[1],4670 F = v[2] * w[3] - v[3] * w[2];4671 var G = u[0];4672 var H = u[1];4673 var I = u[2];4674 var J = u[3];4675 out[0] = H * F - I * E + J * D;4676 out[1] = -(G * F) + I * C - J * B;4677 out[2] = G * E - H * C + J * A;4678 out[3] = -(G * D) + H * B - I * A;4679 return out;4680 }4681 /**4682 * Performs a linear interpolation between two vec4's4683 *4684 * @param {vec4} out the receiving vector4685 * @param {ReadonlyVec4} a the first operand4686 * @param {ReadonlyVec4} b the second operand4687 * @param {Number} t interpolation amount, in the range [0-1], between the two inputs4688 * @returns {vec4} out4689 */4690 function lerp$1(out, a, b, t) {4691 var ax = a[0];4692 var ay = a[1];4693 var az = a[2];4694 var aw = a[3];4695 out[0] = ax + t * (b[0] - ax);4696 out[1] = ay + t * (b[1] - ay);4697 out[2] = az + t * (b[2] - az);4698 out[3] = aw + t * (b[3] - aw);4699 return out;4700 }4701 /**4702 * Generates a random vector with the given scale4703 *4704 * @param {vec4} out the receiving vector4705 * @param {Number} [scale] Length of the resulting vector. If ommitted, a unit vector will be returned4706 * @returns {vec4} out4707 */4708 function random$1(out, scale) {4709 scale = scale || 1.0; // Marsaglia, George. Choosing a Point from the Surface of a4710 // Sphere. Ann. Math. Statist. 43 (1972), no. 2, 645--646.4711 // http://projecteuclid.org/euclid.aoms/1177692644;4712 var v1, v2, v3, v4;4713 var s1, s2;4714 do {4715 v1 = RANDOM() * 2 - 1;4716 v2 = RANDOM() * 2 - 1;4717 s1 = v1 * v1 + v2 * v2;4718 } while (s1 >= 1);4719 do {4720 v3 = RANDOM() * 2 - 1;4721 v4 = RANDOM() * 2 - 1;4722 s2 = v3 * v3 + v4 * v4;4723 } while (s2 >= 1);4724 var d = Math.sqrt((1 - s1) / s2);4725 out[0] = scale * v1;4726 out[1] = scale * v2;4727 out[2] = scale * v3 * d;4728 out[3] = scale * v4 * d;4729 return out;4730 }4731 /**4732 * Transforms the vec4 with a mat4.4733 *4734 * @param {vec4} out the receiving vector4735 * @param {ReadonlyVec4} a the vector to transform4736 * @param {ReadonlyMat4} m matrix to transform with4737 * @returns {vec4} out4738 */4739 function transformMat4$1(out, a, m) {4740 var x = a[0],4741 y = a[1],4742 z = a[2],4743 w = a[3];4744 out[0] = m[0] * x + m[4] * y + m[8] * z + m[12] * w;4745 out[1] = m[1] * x + m[5] * y + m[9] * z + m[13] * w;4746 out[2] = m[2] * x + m[6] * y + m[10] * z + m[14] * w;4747 out[3] = m[3] * x + m[7] * y + m[11] * z + m[15] * w;4748 return out;4749 }4750 /**4751 * Transforms the vec4 with a quat4752 *4753 * @param {vec4} out the receiving vector4754 * @param {ReadonlyVec4} a the vector to transform4755 * @param {ReadonlyQuat} q quaternion to transform with4756 * @returns {vec4} out4757 */4758 function transformQuat$1(out, a, q) {4759 var x = a[0],4760 y = a[1],4761 z = a[2];4762 var qx = q[0],4763 qy = q[1],4764 qz = q[2],4765 qw = q[3]; // calculate quat * vec4766 var ix = qw * x + qy * z - qz * y;4767 var iy = qw * y + qz * x - qx * z;4768 var iz = qw * z + qx * y - qy * x;4769 var iw = -qx * x - qy * y - qz * z; // calculate result * inverse quat4770 out[0] = ix * qw + iw * -qx + iy * -qz - iz * -qy;4771 out[1] = iy * qw + iw * -qy + iz * -qx - ix * -qz;4772 out[2] = iz * qw + iw * -qz + ix * -qy - iy * -qx;4773 out[3] = a[3];4774 return out;4775 }4776 /**4777 * Set the components of a vec4 to zero4778 *4779 * @param {vec4} out the receiving vector4780 * @returns {vec4} out4781 */4782 function zero$1(out) {4783 out[0] = 0.0;4784 out[1] = 0.0;4785 out[2] = 0.0;4786 out[3] = 0.0;4787 return out;4788 }4789 /**4790 * Returns a string representation of a vector4791 *4792 * @param {ReadonlyVec4} a vector to represent as a string4793 * @returns {String} string representation of the vector4794 */4795 function str$5(a) {4796 return "vec4(" + a[0] + ", " + a[1] + ", " + a[2] + ", " + a[3] + ")";4797 }4798 /**4799 * Returns whether or not the vectors have exactly the same elements in the same position (when compared with ===)4800 *4801 * @param {ReadonlyVec4} a The first vector.4802 * @param {ReadonlyVec4} b The second vector.4803 * @returns {Boolean} True if the vectors are equal, false otherwise.4804 */4805 function exactEquals$5(a, b) {4806 return a[0] === b[0] && a[1] === b[1] && a[2] === b[2] && a[3] === b[3];4807 }4808 /**4809 * Returns whether or not the vectors have approximately the same elements in the same position.4810 *4811 * @param {ReadonlyVec4} a The first vector.4812 * @param {ReadonlyVec4} b The second vector.4813 * @returns {Boolean} True if the vectors are equal, false otherwise.4814 */4815 function equals$6(a, b) {4816 var a0 = a[0],4817 a1 = a[1],4818 a2 = a[2],4819 a3 = a[3];4820 var b0 = b[0],4821 b1 = b[1],4822 b2 = b[2],4823 b3 = b[3];4824 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));4825 }4826 /**4827 * Alias for {@link vec4.subtract}4828 * @function4829 */4830 var sub$5 = subtract$5;4831 /**4832 * Alias for {@link vec4.multiply}4833 * @function4834 */4835 var mul$5 = multiply$5;4836 /**4837 * Alias for {@link vec4.divide}4838 * @function4839 */4840 var div$1 = divide$1;4841 /**4842 * Alias for {@link vec4.distance}4843 * @function4844 */4845 var dist$1 = distance$1;4846 /**4847 * Alias for {@link vec4.squaredDistance}4848 * @function4849 */4850 var sqrDist$1 = squaredDistance$1;4851 /**4852 * Alias for {@link vec4.length}4853 * @function4854 */4855 var len$1 = length$1;4856 /**4857 * Alias for {@link vec4.squaredLength}4858 * @function4859 */4860 var sqrLen$1 = squaredLength$1;4861 /**4862 * Perform some operation over an array of vec4s.4863 *4864 * @param {Array} a the array of vectors to iterate over4865 * @param {Number} stride Number of elements between the start of each vec4. If 0 assumes tightly packed4866 * @param {Number} offset Number of elements to skip at the beginning of the array4867 * @param {Number} count Number of vec4s to iterate over. If 0 iterates over entire array4868 * @param {Function} fn Function to call for each vector in the array4869 * @param {Object} [arg] additional argument to pass to fn4870 * @returns {Array} a4871 * @function4872 */4873 var forEach$1 = function () {4874 var vec = create$5();4875 return function (a, stride, offset, count, fn, arg) {4876 var i, l;4877 if (!stride) {4878 stride = 4;4879 }4880 if (!offset) {4881 offset = 0;4882 }4883 if (count) {4884 l = Math.min(count * stride + offset, a.length);4885 } else {4886 l = a.length;4887 }4888 for (i = offset; i < l; i += stride) {4889 vec[0] = a[i];4890 vec[1] = a[i + 1];4891 vec[2] = a[i + 2];4892 vec[3] = a[i + 3];4893 fn(vec, vec, arg);4894 a[i] = vec[0];4895 a[i + 1] = vec[1];4896 a[i + 2] = vec[2];4897 a[i + 3] = vec[3];4898 }4899 return a;4900 };4901 }();4902 var vec4 = /*#__PURE__*/Object.freeze({4903 __proto__: null,4904 create: create$5,4905 clone: clone$5,4906 fromValues: fromValues$5,4907 copy: copy$5,4908 set: set$5,4909 add: add$5,4910 subtract: subtract$5,4911 multiply: multiply$5,4912 divide: divide$1,4913 ceil: ceil$1,4914 floor: floor$1,4915 min: min$1,4916 max: max$1,4917 round: round$1,4918 scale: scale$5,4919 scaleAndAdd: scaleAndAdd$1,4920 distance: distance$1,4921 squaredDistance: squaredDistance$1,4922 length: length$1,4923 squaredLength: squaredLength$1,4924 negate: negate$1,4925 inverse: inverse$1,4926 normalize: normalize$1,4927 dot: dot$1,4928 cross: cross$1,4929 lerp: lerp$1,4930 random: random$1,4931 transformMat4: transformMat4$1,4932 transformQuat: transformQuat$1,4933 zero: zero$1,4934 str: str$5,4935 exactEquals: exactEquals$5,4936 equals: equals$6,4937 sub: sub$5,4938 mul: mul$5,4939 div: div$1,4940 dist: dist$1,4941 sqrDist: sqrDist$1,4942 len: len$1,4943 sqrLen: sqrLen$1,4944 forEach: forEach$14945 });4946 /**4947 * Quaternion4948 * @module quat4949 */4950 /**4951 * Creates a new identity quat4952 *4953 * @returns {quat} a new quaternion4954 */4955 function create$6() {4956 var out = new ARRAY_TYPE(4);4957 if (ARRAY_TYPE != Float32Array) {4958 out[0] = 0;4959 out[1] = 0;4960 out[2] = 0;4961 }4962 out[3] = 1;4963 return out;4964 }4965 /**4966 * Set a quat to the identity quaternion4967 *4968 * @param {quat} out the receiving quaternion4969 * @returns {quat} out4970 */4971 function identity$4(out) {4972 out[0] = 0;4973 out[1] = 0;4974 out[2] = 0;4975 out[3] = 1;4976 return out;4977 }4978 /**4979 * Sets a quat from the given angle and rotation axis,4980 * then returns it.4981 *4982 * @param {quat} out the receiving quaternion4983 * @param {ReadonlyVec3} axis the axis around which to rotate4984 * @param {Number} rad the angle in radians4985 * @returns {quat} out4986 **/4987 function setAxisAngle(out, axis, rad) {4988 rad = rad * 0.5;4989 var s = Math.sin(rad);4990 out[0] = s * axis[0];4991 out[1] = s * axis[1];4992 out[2] = s * axis[2];4993 out[3] = Math.cos(rad);4994 return out;4995 }4996 /**4997 * Gets the rotation axis and angle for a given4998 * quaternion. If a quaternion is created with4999 * setAxisAngle, this method will return the same5000 * values as providied in the original parameter list5001 * OR functionally equivalent values.5002 * Example: The quaternion formed by axis [0, 0, 1] and5003 * angle -90 is the same as the quaternion formed by5004 * [0, 0, 1] and 270. This method favors the latter.5005 * @param {vec3} out_axis Vector receiving the axis of rotation5006 * @param {ReadonlyQuat} q Quaternion to be decomposed5007 * @return {Number} Angle, in radians, of the rotation5008 */5009 function getAxisAngle(out_axis, q) {5010 var rad = Math.acos(q[3]) * 2.0;5011 var s = Math.sin(rad / 2.0);5012 if (s > EPSILON) {5013 out_axis[0] = q[0] / s;5014 out_axis[1] = q[1] / s;5015 out_axis[2] = q[2] / s;5016 } else {5017 // If s is zero, return any axis (no rotation - axis does not matter)5018 out_axis[0] = 1;5019 out_axis[1] = 0;5020 out_axis[2] = 0;5021 }5022 return rad;5023 }5024 /**5025 * Gets the angular distance between two unit quaternions5026 *5027 * @param {ReadonlyQuat} a Origin unit quaternion5028 * @param {ReadonlyQuat} b Destination unit quaternion5029 * @return {Number} Angle, in radians, between the two quaternions5030 */5031 function getAngle(a, b) {5032 var dotproduct = dot$2(a, b);5033 return Math.acos(2 * dotproduct * dotproduct - 1);5034 }5035 /**5036 * Multiplies two quat's5037 *5038 * @param {quat} out the receiving quaternion5039 * @param {ReadonlyQuat} a the first operand5040 * @param {ReadonlyQuat} b the second operand5041 * @returns {quat} out5042 */5043 function multiply$6(out, a, b) {5044 var ax = a[0],5045 ay = a[1],5046 az = a[2],5047 aw = a[3];5048 var bx = b[0],5049 by = b[1],5050 bz = b[2],5051 bw = b[3];5052 out[0] = ax * bw + aw * bx + ay * bz - az * by;5053 out[1] = ay * bw + aw * by + az * bx - ax * bz;5054 out[2] = az * bw + aw * bz + ax * by - ay * bx;5055 out[3] = aw * bw - ax * bx - ay * by - az * bz;5056 return out;5057 }5058 /**5059 * Rotates a quaternion by the given angle about the X axis5060 *5061 * @param {quat} out quat receiving operation result5062 * @param {ReadonlyQuat} a quat to rotate5063 * @param {number} rad angle (in radians) to rotate5064 * @returns {quat} out5065 */5066 function rotateX$2(out, a, rad) {5067 rad *= 0.5;5068 var ax = a[0],5069 ay = a[1],5070 az = a[2],5071 aw = a[3];5072 var bx = Math.sin(rad),5073 bw = Math.cos(rad);5074 out[0] = ax * bw + aw * bx;5075 out[1] = ay * bw + az * bx;5076 out[2] = az * bw - ay * bx;5077 out[3] = aw * bw - ax * bx;5078 return out;5079 }5080 /**5081 * Rotates a quaternion by the given angle about the Y axis5082 *5083 * @param {quat} out quat receiving operation result5084 * @param {ReadonlyQuat} a quat to rotate5085 * @param {number} rad angle (in radians) to rotate5086 * @returns {quat} out5087 */5088 function rotateY$2(out, a, rad) {5089 rad *= 0.5;5090 var ax = a[0],5091 ay = a[1],5092 az = a[2],5093 aw = a[3];5094 var by = Math.sin(rad),5095 bw = Math.cos(rad);5096 out[0] = ax * bw - az * by;5097 out[1] = ay * bw + aw * by;5098 out[2] = az * bw + ax * by;5099 out[3] = aw * bw - ay * by;5100 return out;5101 }5102 /**5103 * Rotates a quaternion by the given angle about the Z axis5104 *5105 * @param {quat} out quat receiving operation result5106 * @param {ReadonlyQuat} a quat to rotate5107 * @param {number} rad angle (in radians) to rotate5108 * @returns {quat} out5109 */5110 function rotateZ$2(out, a, rad) {5111 rad *= 0.5;5112 var ax = a[0],5113 ay = a[1],5114 az = a[2],5115 aw = a[3];5116 var bz = Math.sin(rad),5117 bw = Math.cos(rad);5118 out[0] = ax * bw + ay * bz;5119 out[1] = ay * bw - ax * bz;5120 out[2] = az * bw + aw * bz;5121 out[3] = aw * bw - az * bz;5122 return out;5123 }5124 /**5125 * Calculates the W component of a quat from the X, Y, and Z components.5126 * Assumes that quaternion is 1 unit in length.5127 * Any existing W component will be ignored.5128 *5129 * @param {quat} out the receiving quaternion5130 * @param {ReadonlyQuat} a quat to calculate W component of5131 * @returns {quat} out5132 */5133 function calculateW(out, a) {5134 var x = a[0],5135 y = a[1],5136 z = a[2];5137 out[0] = x;5138 out[1] = y;5139 out[2] = z;5140 out[3] = Math.sqrt(Math.abs(1.0 - x * x - y * y - z * z));5141 return out;5142 }5143 /**5144 * Calculate the exponential of a unit quaternion.5145 *5146 * @param {quat} out the receiving quaternion5147 * @param {ReadonlyQuat} a quat to calculate the exponential of5148 * @returns {quat} out5149 */5150 function exp(out, a) {5151 var x = a[0],5152 y = a[1],5153 z = a[2],5154 w = a[3];5155 var r = Math.sqrt(x * x + y * y + z * z);5156 var et = Math.exp(w);5157 var s = r > 0 ? et * Math.sin(r) / r : 0;5158 out[0] = x * s;5159 out[1] = y * s;5160 out[2] = z * s;5161 out[3] = et * Math.cos(r);5162 return out;5163 }5164 /**5165 * Calculate the natural logarithm of a unit quaternion.5166 *5167 * @param {quat} out the receiving quaternion5168 * @param {ReadonlyQuat} a quat to calculate the exponential of5169 * @returns {quat} out5170 */5171 function ln(out, a) {5172 var x = a[0],5173 y = a[1],5174 z = a[2],5175 w = a[3];5176 var r = Math.sqrt(x * x + y * y + z * z);5177 var t = r > 0 ? Math.atan2(r, w) / r : 0;5178 out[0] = x * t;5179 out[1] = y * t;5180 out[2] = z * t;5181 out[3] = 0.5 * Math.log(x * x + y * y + z * z + w * w);5182 return out;5183 }5184 /**5185 * Calculate the scalar power of a unit quaternion.5186 *5187 * @param {quat} out the receiving quaternion5188 * @param {ReadonlyQuat} a quat to calculate the exponential of5189 * @param {Number} b amount to scale the quaternion by5190 * @returns {quat} out5191 */5192 function pow(out, a, b) {5193 ln(out, a);5194 scale$6(out, out, b);5195 exp(out, out);5196 return out;5197 }5198 /**5199 * Performs a spherical linear interpolation between two quat5200 *5201 * @param {quat} out the receiving quaternion5202 * @param {ReadonlyQuat} a the first operand5203 * @param {ReadonlyQuat} b the second operand5204 * @param {Number} t interpolation amount, in the range [0-1], between the two inputs5205 * @returns {quat} out5206 */5207 function slerp(out, a, b, t) {5208 // benchmarks:5209 // http://jsperf.com/quaternion-slerp-implementations5210 var ax = a[0],5211 ay = a[1],5212 az = a[2],5213 aw = a[3];5214 var bx = b[0],5215 by = b[1],5216 bz = b[2],5217 bw = b[3];5218 var omega, cosom, sinom, scale0, scale1; // calc cosine5219 cosom = ax * bx + ay * by + az * bz + aw * bw; // adjust signs (if necessary)5220 if (cosom < 0.0) {5221 cosom = -cosom;5222 bx = -bx;5223 by = -by;5224 bz = -bz;5225 bw = -bw;5226 } // calculate coefficients5227 if (1.0 - cosom > EPSILON) {5228 // standard case (slerp)5229 omega = Math.acos(cosom);5230 sinom = Math.sin(omega);5231 scale0 = Math.sin((1.0 - t) * omega) / sinom;5232 scale1 = Math.sin(t * omega) / sinom;5233 } else {5234 // "from" and "to" quaternions are very close5235 // ... so we can do a linear interpolation5236 scale0 = 1.0 - t;5237 scale1 = t;5238 } // calculate final values5239 out[0] = scale0 * ax + scale1 * bx;5240 out[1] = scale0 * ay + scale1 * by;5241 out[2] = scale0 * az + scale1 * bz;5242 out[3] = scale0 * aw + scale1 * bw;5243 return out;5244 }5245 /**5246 * Generates a random unit quaternion5247 *5248 * @param {quat} out the receiving quaternion5249 * @returns {quat} out5250 */5251 function random$2(out) {5252 // Implementation of http://planning.cs.uiuc.edu/node198.html5253 // TODO: Calling random 3 times is probably not the fastest solution5254 var u1 = RANDOM();5255 var u2 = RANDOM();5256 var u3 = RANDOM();5257 var sqrt1MinusU1 = Math.sqrt(1 - u1);5258 var sqrtU1 = Math.sqrt(u1);5259 out[0] = sqrt1MinusU1 * Math.sin(2.0 * Math.PI * u2);5260 out[1] = sqrt1MinusU1 * Math.cos(2.0 * Math.PI * u2);5261 out[2] = sqrtU1 * Math.sin(2.0 * Math.PI * u3);5262 out[3] = sqrtU1 * Math.cos(2.0 * Math.PI * u3);5263 return out;5264 }5265 /**5266 * Calculates the inverse of a quat5267 *5268 * @param {quat} out the receiving quaternion5269 * @param {ReadonlyQuat} a quat to calculate inverse of5270 * @returns {quat} out5271 */5272 function invert$4(out, a) {5273 var a0 = a[0],5274 a1 = a[1],5275 a2 = a[2],5276 a3 = a[3];5277 var dot = a0 * a0 + a1 * a1 + a2 * a2 + a3 * a3;5278 var invDot = dot ? 1.0 / dot : 0; // TODO: Would be faster to return [0,0,0,0] immediately if dot == 05279 out[0] = -a0 * invDot;5280 out[1] = -a1 * invDot;5281 out[2] = -a2 * invDot;5282 out[3] = a3 * invDot;5283 return out;5284 }5285 /**5286 * Calculates the conjugate of a quat5287 * If the quaternion is normalized, this function is faster than quat.inverse and produces the same result.5288 *5289 * @param {quat} out the receiving quaternion5290 * @param {ReadonlyQuat} a quat to calculate conjugate of5291 * @returns {quat} out5292 */5293 function conjugate(out, a) {5294 out[0] = -a[0];5295 out[1] = -a[1];5296 out[2] = -a[2];5297 out[3] = a[3];5298 return out;5299 }5300 /**5301 * Creates a quaternion from the given 3x3 rotation matrix.5302 *5303 * NOTE: The resultant quaternion is not normalized, so you should be sure5304 * to renormalize the quaternion yourself where necessary.5305 *5306 * @param {quat} out the receiving quaternion5307 * @param {ReadonlyMat3} m rotation matrix5308 * @returns {quat} out5309 * @function5310 */5311 function fromMat3(out, m) {5312 // Algorithm in Ken Shoemake's article in 1987 SIGGRAPH course notes5313 // article "Quaternion Calculus and Fast Animation".5314 var fTrace = m[0] + m[4] + m[8];5315 var fRoot;5316 if (fTrace > 0.0) {5317 // |w| > 1/2, may as well choose w > 1/25318 fRoot = Math.sqrt(fTrace + 1.0); // 2w5319 out[3] = 0.5 * fRoot;5320 fRoot = 0.5 / fRoot; // 1/(4w)5321 out[0] = (m[5] - m[7]) * fRoot;5322 out[1] = (m[6] - m[2]) * fRoot;5323 out[2] = (m[1] - m[3]) * fRoot;5324 } else {5325 // |w| <= 1/25326 var i = 0;5327 if (m[4] > m[0]) i = 1;5328 if (m[8] > m[i * 3 + i]) i = 2;5329 var j = (i + 1) % 3;5330 var k = (i + 2) % 3;5331 fRoot = Math.sqrt(m[i * 3 + i] - m[j * 3 + j] - m[k * 3 + k] + 1.0);5332 out[i] = 0.5 * fRoot;5333 fRoot = 0.5 / fRoot;5334 out[3] = (m[j * 3 + k] - m[k * 3 + j]) * fRoot;5335 out[j] = (m[j * 3 + i] + m[i * 3 + j]) * fRoot;5336 out[k] = (m[k * 3 + i] + m[i * 3 + k]) * fRoot;5337 }5338 return out;5339 }5340 /**5341 * Creates a quaternion from the given euler angle x, y, z.5342 *5343 * @param {quat} out the receiving quaternion5344 * @param {x} Angle to rotate around X axis in degrees.5345 * @param {y} Angle to rotate around Y axis in degrees.5346 * @param {z} Angle to rotate around Z axis in degrees.5347 * @returns {quat} out5348 * @function5349 */5350 function fromEuler(out, x, y, z) {5351 var halfToRad = 0.5 * Math.PI / 180.0;5352 x *= halfToRad;5353 y *= halfToRad;5354 z *= halfToRad;5355 var sx = Math.sin(x);5356 var cx = Math.cos(x);5357 var sy = Math.sin(y);5358 var cy = Math.cos(y);5359 var sz = Math.sin(z);5360 var cz = Math.cos(z);5361 out[0] = sx * cy * cz - cx * sy * sz;5362 out[1] = cx * sy * cz + sx * cy * sz;5363 out[2] = cx * cy * sz - sx * sy * cz;5364 out[3] = cx * cy * cz + sx * sy * sz;5365 return out;5366 }5367 /**5368 * Returns a string representation of a quatenion5369 *5370 * @param {ReadonlyQuat} a vector to represent as a string5371 * @returns {String} string representation of the vector5372 */5373 function str$6(a) {5374 return "quat(" + a[0] + ", " + a[1] + ", " + a[2] + ", " + a[3] + ")";5375 }5376 /**5377 * Creates a new quat initialized with values from an existing quaternion5378 *5379 * @param {ReadonlyQuat} a quaternion to clone5380 * @returns {quat} a new quaternion5381 * @function5382 */5383 var clone$6 = clone$5;5384 /**5385 * Creates a new quat initialized with the given values5386 *5387 * @param {Number} x X component5388 * @param {Number} y Y component5389 * @param {Number} z Z component5390 * @param {Number} w W component5391 * @returns {quat} a new quaternion5392 * @function5393 */5394 var fromValues$6 = fromValues$5;5395 /**5396 * Copy the values from one quat to another5397 *5398 * @param {quat} out the receiving quaternion5399 * @param {ReadonlyQuat} a the source quaternion5400 * @returns {quat} out5401 * @function5402 */5403 var copy$6 = copy$5;5404 /**5405 * Set the components of a quat to the given values5406 *5407 * @param {quat} out the receiving quaternion5408 * @param {Number} x X component5409 * @param {Number} y Y component5410 * @param {Number} z Z component5411 * @param {Number} w W component5412 * @returns {quat} out5413 * @function5414 */5415 var set$6 = set$5;5416 /**5417 * Adds two quat's5418 *5419 * @param {quat} out the receiving quaternion5420 * @param {ReadonlyQuat} a the first operand5421 * @param {ReadonlyQuat} b the second operand5422 * @returns {quat} out5423 * @function5424 */5425 var add$6 = add$5;5426 /**5427 * Alias for {@link quat.multiply}5428 * @function5429 */5430 var mul$6 = multiply$6;5431 /**5432 * Scales a quat by a scalar number5433 *5434 * @param {quat} out the receiving vector5435 * @param {ReadonlyQuat} a the vector to scale5436 * @param {Number} b amount to scale the vector by5437 * @returns {quat} out5438 * @function5439 */5440 var scale$6 = scale$5;5441 /**5442 * Calculates the dot product of two quat's5443 *5444 * @param {ReadonlyQuat} a the first operand5445 * @param {ReadonlyQuat} b the second operand5446 * @returns {Number} dot product of a and b5447 * @function5448 */5449 var dot$2 = dot$1;5450 /**5451 * Performs a linear interpolation between two quat's5452 *5453 * @param {quat} out the receiving quaternion5454 * @param {ReadonlyQuat} a the first operand5455 * @param {ReadonlyQuat} b the second operand5456 * @param {Number} t interpolation amount, in the range [0-1], between the two inputs5457 * @returns {quat} out5458 * @function5459 */5460 var lerp$2 = lerp$1;5461 /**5462 * Calculates the length of a quat5463 *5464 * @param {ReadonlyQuat} a vector to calculate length of5465 * @returns {Number} length of a5466 */5467 var length$2 = length$1;5468 /**5469 * Alias for {@link quat.length}5470 * @function5471 */5472 var len$2 = length$2;5473 /**5474 * Calculates the squared length of a quat5475 *5476 * @param {ReadonlyQuat} a vector to calculate squared length of5477 * @returns {Number} squared length of a5478 * @function5479 */5480 var squaredLength$2 = squaredLength$1;5481 /**5482 * Alias for {@link quat.squaredLength}5483 * @function5484 */5485 var sqrLen$2 = squaredLength$2;5486 /**5487 * Normalize a quat5488 *5489 * @param {quat} out the receiving quaternion5490 * @param {ReadonlyQuat} a quaternion to normalize5491 * @returns {quat} out5492 * @function5493 */5494 var normalize$2 = normalize$1;5495 /**5496 * Returns whether or not the quaternions have exactly the same elements in the same position (when compared with ===)5497 *5498 * @param {ReadonlyQuat} a The first quaternion.5499 * @param {ReadonlyQuat} b The second quaternion.5500 * @returns {Boolean} True if the vectors are equal, false otherwise.5501 */5502 var exactEquals$6 = exactEquals$5;5503 /**5504 * Returns whether or not the quaternions have approximately the same elements in the same position.5505 *5506 * @param {ReadonlyQuat} a The first vector.5507 * @param {ReadonlyQuat} b The second vector.5508 * @returns {Boolean} True if the vectors are equal, false otherwise.5509 */5510 var equals$7 = equals$6;5511 /**5512 * Sets a quaternion to represent the shortest rotation from one5513 * vector to another.5514 *5515 * Both vectors are assumed to be unit length.5516 *5517 * @param {quat} out the receiving quaternion.5518 * @param {ReadonlyVec3} a the initial vector5519 * @param {ReadonlyVec3} b the destination vector5520 * @returns {quat} out5521 */5522 var rotationTo = function () {5523 var tmpvec3 = create$4();5524 var xUnitVec3 = fromValues$4(1, 0, 0);5525 var yUnitVec3 = fromValues$4(0, 1, 0);5526 return function (out, a, b) {5527 var dot$1 = dot(a, b);5528 if (dot$1 < -0.999999) {5529 cross(tmpvec3, xUnitVec3, a);5530 if (len(tmpvec3) < 0.000001) cross(tmpvec3, yUnitVec3, a);5531 normalize(tmpvec3, tmpvec3);5532 setAxisAngle(out, tmpvec3, Math.PI);5533 return out;5534 } else if (dot$1 > 0.999999) {5535 out[0] = 0;5536 out[1] = 0;5537 out[2] = 0;5538 out[3] = 1;5539 return out;5540 } else {5541 cross(tmpvec3, a, b);5542 out[0] = tmpvec3[0];5543 out[1] = tmpvec3[1];5544 out[2] = tmpvec3[2];5545 out[3] = 1 + dot$1;5546 return normalize$2(out, out);5547 }5548 };5549 }();5550 /**5551 * Performs a spherical linear interpolation with two control points5552 *5553 * @param {quat} out the receiving quaternion5554 * @param {ReadonlyQuat} a the first operand5555 * @param {ReadonlyQuat} b the second operand5556 * @param {ReadonlyQuat} c the third operand5557 * @param {ReadonlyQuat} d the fourth operand5558 * @param {Number} t interpolation amount, in the range [0-1], between the two inputs5559 * @returns {quat} out5560 */5561 var sqlerp = function () {5562 var temp1 = create$6();5563 var temp2 = create$6();5564 return function (out, a, b, c, d, t) {5565 slerp(temp1, a, d, t);5566 slerp(temp2, b, c, t);5567 slerp(out, temp1, temp2, 2 * t * (1 - t));5568 return out;5569 };5570 }();5571 /**5572 * Sets the specified quaternion with values corresponding to the given5573 * axes. Each axis is a vec3 and is expected to be unit length and5574 * perpendicular to all other specified axes.5575 *5576 * @param {ReadonlyVec3} view the vector representing the viewing direction5577 * @param {ReadonlyVec3} right the vector representing the local "right" direction5578 * @param {ReadonlyVec3} up the vector representing the local "up" direction5579 * @returns {quat} out5580 */5581 var setAxes = function () {5582 var matr = create$2();5583 return function (out, view, right, up) {5584 matr[0] = right[0];5585 matr[3] = right[1];5586 matr[6] = right[2];5587 matr[1] = up[0];5588 matr[4] = up[1];5589 matr[7] = up[2];5590 matr[2] = -view[0];5591 matr[5] = -view[1];5592 matr[8] = -view[2];5593 return normalize$2(out, fromMat3(out, matr));5594 };5595 }();5596 var quat = /*#__PURE__*/Object.freeze({5597 __proto__: null,5598 create: create$6,5599 identity: identity$4,5600 setAxisAngle: setAxisAngle,5601 getAxisAngle: getAxisAngle,5602 getAngle: getAngle,5603 multiply: multiply$6,5604 rotateX: rotateX$2,5605 rotateY: rotateY$2,5606 rotateZ: rotateZ$2,5607 calculateW: calculateW,5608 exp: exp,5609 ln: ln,5610 pow: pow,5611 slerp: slerp,5612 random: random$2,5613 invert: invert$4,5614 conjugate: conjugate,5615 fromMat3: fromMat3,5616 fromEuler: fromEuler,5617 str: str$6,5618 clone: clone$6,5619 fromValues: fromValues$6,5620 copy: copy$6,5621 set: set$6,5622 add: add$6,5623 mul: mul$6,5624 scale: scale$6,5625 dot: dot$2,5626 lerp: lerp$2,5627 length: length$2,5628 len: len$2,5629 squaredLength: squaredLength$2,5630 sqrLen: sqrLen$2,5631 normalize: normalize$2,5632 exactEquals: exactEquals$6,5633 equals: equals$7,5634 rotationTo: rotationTo,5635 sqlerp: sqlerp,5636 setAxes: setAxes5637 });5638 /**5639 * Dual Quaternion<br>5640 * Format: [real, dual]<br>5641 * Quaternion format: XYZW<br>5642 * Make sure to have normalized dual quaternions, otherwise the functions may not work as intended.<br>5643 * @module quat25644 */5645 /**5646 * Creates a new identity dual quat5647 *5648 * @returns {quat2} a new dual quaternion [real -> rotation, dual -> translation]5649 */5650 function create$7() {5651 var dq = new ARRAY_TYPE(8);5652 if (ARRAY_TYPE != Float32Array) {5653 dq[0] = 0;5654 dq[1] = 0;5655 dq[2] = 0;5656 dq[4] = 0;5657 dq[5] = 0;5658 dq[6] = 0;5659 dq[7] = 0;5660 }5661 dq[3] = 1;5662 return dq;5663 }5664 /**5665 * Creates a new quat initialized with values from an existing quaternion5666 *5667 * @param {ReadonlyQuat2} a dual quaternion to clone5668 * @returns {quat2} new dual quaternion5669 * @function5670 */5671 function clone$7(a) {5672 var dq = new ARRAY_TYPE(8);5673 dq[0] = a[0];5674 dq[1] = a[1];5675 dq[2] = a[2];5676 dq[3] = a[3];5677 dq[4] = a[4];5678 dq[5] = a[5];5679 dq[6] = a[6];5680 dq[7] = a[7];5681 return dq;5682 }5683 /**5684 * Creates a new dual quat initialized with the given values5685 *5686 * @param {Number} x1 X component5687 * @param {Number} y1 Y component5688 * @param {Number} z1 Z component5689 * @param {Number} w1 W component5690 * @param {Number} x2 X component5691 * @param {Number} y2 Y component5692 * @param {Number} z2 Z component5693 * @param {Number} w2 W component5694 * @returns {quat2} new dual quaternion5695 * @function5696 */5697 function fromValues$7(x1, y1, z1, w1, x2, y2, z2, w2) {5698 var dq = new ARRAY_TYPE(8);5699 dq[0] = x1;5700 dq[1] = y1;5701 dq[2] = z1;5702 dq[3] = w1;5703 dq[4] = x2;5704 dq[5] = y2;5705 dq[6] = z2;5706 dq[7] = w2;5707 return dq;5708 }5709 /**5710 * Creates a new dual quat from the given values (quat and translation)5711 *5712 * @param {Number} x1 X component5713 * @param {Number} y1 Y component5714 * @param {Number} z1 Z component5715 * @param {Number} w1 W component5716 * @param {Number} x2 X component (translation)5717 * @param {Number} y2 Y component (translation)5718 * @param {Number} z2 Z component (translation)5719 * @returns {quat2} new dual quaternion5720 * @function5721 */5722 function fromRotationTranslationValues(x1, y1, z1, w1, x2, y2, z2) {5723 var dq = new ARRAY_TYPE(8);5724 dq[0] = x1;5725 dq[1] = y1;5726 dq[2] = z1;5727 dq[3] = w1;5728 var ax = x2 * 0.5,5729 ay = y2 * 0.5,5730 az = z2 * 0.5;5731 dq[4] = ax * w1 + ay * z1 - az * y1;5732 dq[5] = ay * w1 + az * x1 - ax * z1;5733 dq[6] = az * w1 + ax * y1 - ay * x1;5734 dq[7] = -ax * x1 - ay * y1 - az * z1;5735 return dq;5736 }5737 /**5738 * Creates a dual quat from a quaternion and a translation5739 *5740 * @param {ReadonlyQuat2} dual quaternion receiving operation result5741 * @param {ReadonlyQuat} q a normalized quaternion5742 * @param {ReadonlyVec3} t tranlation vector5743 * @returns {quat2} dual quaternion receiving operation result5744 * @function5745 */5746 function fromRotationTranslation$1(out, q, t) {5747 var ax = t[0] * 0.5,5748 ay = t[1] * 0.5,5749 az = t[2] * 0.5,5750 bx = q[0],5751 by = q[1],5752 bz = q[2],5753 bw = q[3];5754 out[0] = bx;5755 out[1] = by;5756 out[2] = bz;5757 out[3] = bw;5758 out[4] = ax * bw + ay * bz - az * by;5759 out[5] = ay * bw + az * bx - ax * bz;5760 out[6] = az * bw + ax * by - ay * bx;5761 out[7] = -ax * bx - ay * by - az * bz;5762 return out;5763 }5764 /**5765 * Creates a dual quat from a translation5766 *5767 * @param {ReadonlyQuat2} dual quaternion receiving operation result5768 * @param {ReadonlyVec3} t translation vector5769 * @returns {quat2} dual quaternion receiving operation result5770 * @function5771 */5772 function fromTranslation$3(out, t) {5773 out[0] = 0;5774 out[1] = 0;5775 out[2] = 0;5776 out[3] = 1;5777 out[4] = t[0] * 0.5;5778 out[5] = t[1] * 0.5;5779 out[6] = t[2] * 0.5;5780 out[7] = 0;5781 return out;5782 }5783 /**5784 * Creates a dual quat from a quaternion5785 *5786 * @param {ReadonlyQuat2} dual quaternion receiving operation result5787 * @param {ReadonlyQuat} q the quaternion5788 * @returns {quat2} dual quaternion receiving operation result5789 * @function5790 */5791 function fromRotation$4(out, q) {5792 out[0] = q[0];5793 out[1] = q[1];5794 out[2] = q[2];5795 out[3] = q[3];5796 out[4] = 0;5797 out[5] = 0;5798 out[6] = 0;5799 out[7] = 0;5800 return out;5801 }5802 /**5803 * Creates a new dual quat from a matrix (4x4)5804 *5805 * @param {quat2} out the dual quaternion5806 * @param {ReadonlyMat4} a the matrix5807 * @returns {quat2} dual quat receiving operation result5808 * @function5809 */5810 function fromMat4$1(out, a) {5811 //TODO Optimize this5812 var outer = create$6();5813 getRotation(outer, a);5814 var t = new ARRAY_TYPE(3);5815 getTranslation(t, a);5816 fromRotationTranslation$1(out, outer, t);5817 return out;5818 }5819 /**5820 * Copy the values from one dual quat to another5821 *5822 * @param {quat2} out the receiving dual quaternion5823 * @param {ReadonlyQuat2} a the source dual quaternion5824 * @returns {quat2} out5825 * @function5826 */5827 function copy$7(out, a) {5828 out[0] = a[0];5829 out[1] = a[1];5830 out[2] = a[2];5831 out[3] = a[3];5832 out[4] = a[4];5833 out[5] = a[5];5834 out[6] = a[6];5835 out[7] = a[7];5836 return out;5837 }5838 /**5839 * Set a dual quat to the identity dual quaternion5840 *5841 * @param {quat2} out the receiving quaternion5842 * @returns {quat2} out5843 */5844 function identity$5(out) {5845 out[0] = 0;5846 out[1] = 0;5847 out[2] = 0;5848 out[3] = 1;5849 out[4] = 0;5850 out[5] = 0;5851 out[6] = 0;5852 out[7] = 0;5853 return out;5854 }5855 /**5856 * Set the components of a dual quat to the given values5857 *5858 * @param {quat2} out the receiving quaternion5859 * @param {Number} x1 X component5860 * @param {Number} y1 Y component5861 * @param {Number} z1 Z component5862 * @param {Number} w1 W component5863 * @param {Number} x2 X component5864 * @param {Number} y2 Y component5865 * @param {Number} z2 Z component5866 * @param {Number} w2 W component5867 * @returns {quat2} out5868 * @function5869 */5870 function set$7(out, x1, y1, z1, w1, x2, y2, z2, w2) {5871 out[0] = x1;5872 out[1] = y1;5873 out[2] = z1;5874 out[3] = w1;5875 out[4] = x2;5876 out[5] = y2;5877 out[6] = z2;5878 out[7] = w2;5879 return out;5880 }5881 /**5882 * Gets the real part of a dual quat5883 * @param {quat} out real part5884 * @param {ReadonlyQuat2} a Dual Quaternion5885 * @return {quat} real part5886 */5887 var getReal = copy$6;5888 /**5889 * Gets the dual part of a dual quat5890 * @param {quat} out dual part5891 * @param {ReadonlyQuat2} a Dual Quaternion5892 * @return {quat} dual part5893 */5894 function getDual(out, a) {5895 out[0] = a[4];5896 out[1] = a[5];5897 out[2] = a[6];5898 out[3] = a[7];5899 return out;5900 }5901 /**5902 * Set the real component of a dual quat to the given quaternion5903 *5904 * @param {quat2} out the receiving quaternion5905 * @param {ReadonlyQuat} q a quaternion representing the real part5906 * @returns {quat2} out5907 * @function5908 */5909 var setReal = copy$6;5910 /**5911 * Set the dual component of a dual quat to the given quaternion5912 *5913 * @param {quat2} out the receiving quaternion5914 * @param {ReadonlyQuat} q a quaternion representing the dual part5915 * @returns {quat2} out5916 * @function5917 */5918 function setDual(out, q) {5919 out[4] = q[0];5920 out[5] = q[1];5921 out[6] = q[2];5922 out[7] = q[3];5923 return out;5924 }5925 /**5926 * Gets the translation of a normalized dual quat5927 * @param {vec3} out translation5928 * @param {ReadonlyQuat2} a Dual Quaternion to be decomposed5929 * @return {vec3} translation5930 */5931 function getTranslation$1(out, a) {5932 var ax = a[4],5933 ay = a[5],5934 az = a[6],5935 aw = a[7],5936 bx = -a[0],5937 by = -a[1],5938 bz = -a[2],5939 bw = a[3];5940 out[0] = (ax * bw + aw * bx + ay * bz - az * by) * 2;5941 out[1] = (ay * bw + aw * by + az * bx - ax * bz) * 2;5942 out[2] = (az * bw + aw * bz + ax * by - ay * bx) * 2;5943 return out;5944 }5945 /**5946 * Translates a dual quat by the given vector5947 *5948 * @param {quat2} out the receiving dual quaternion5949 * @param {ReadonlyQuat2} a the dual quaternion to translate5950 * @param {ReadonlyVec3} v vector to translate by5951 * @returns {quat2} out5952 */5953 function translate$3(out, a, v) {5954 var ax1 = a[0],5955 ay1 = a[1],5956 az1 = a[2],5957 aw1 = a[3],5958 bx1 = v[0] * 0.5,5959 by1 = v[1] * 0.5,5960 bz1 = v[2] * 0.5,5961 ax2 = a[4],5962 ay2 = a[5],5963 az2 = a[6],5964 aw2 = a[7];5965 out[0] = ax1;5966 out[1] = ay1;5967 out[2] = az1;5968 out[3] = aw1;5969 out[4] = aw1 * bx1 + ay1 * bz1 - az1 * by1 + ax2;5970 out[5] = aw1 * by1 + az1 * bx1 - ax1 * bz1 + ay2;5971 out[6] = aw1 * bz1 + ax1 * by1 - ay1 * bx1 + az2;5972 out[7] = -ax1 * bx1 - ay1 * by1 - az1 * bz1 + aw2;5973 return out;5974 }5975 /**5976 * Rotates a dual quat around the X axis5977 *5978 * @param {quat2} out the receiving dual quaternion5979 * @param {ReadonlyQuat2} a the dual quaternion to rotate5980 * @param {number} rad how far should the rotation be5981 * @returns {quat2} out5982 */5983 function rotateX$3(out, a, rad) {5984 var bx = -a[0],5985 by = -a[1],5986 bz = -a[2],5987 bw = a[3],5988 ax = a[4],5989 ay = a[5],5990 az = a[6],5991 aw = a[7],5992 ax1 = ax * bw + aw * bx + ay * bz - az * by,5993 ay1 = ay * bw + aw * by + az * bx - ax * bz,5994 az1 = az * bw + aw * bz + ax * by - ay * bx,5995 aw1 = aw * bw - ax * bx - ay * by - az * bz;5996 rotateX$2(out, a, rad);5997 bx = out[0];5998 by = out[1];5999 bz = out[2];6000 bw = out[3];6001 out[4] = ax1 * bw + aw1 * bx + ay1 * bz - az1 * by;6002 out[5] = ay1 * bw + aw1 * by + az1 * bx - ax1 * bz;6003 out[6] = az1 * bw + aw1 * bz + ax1 * by - ay1 * bx;6004 out[7] = aw1 * bw - ax1 * bx - ay1 * by - az1 * bz;6005 return out;6006 }6007 /**6008 * Rotates a dual quat around the Y axis6009 *6010 * @param {quat2} out the receiving dual quaternion6011 * @param {ReadonlyQuat2} a the dual quaternion to rotate6012 * @param {number} rad how far should the rotation be6013 * @returns {quat2} out6014 */6015 function rotateY$3(out, a, rad) {6016 var bx = -a[0],6017 by = -a[1],6018 bz = -a[2],6019 bw = a[3],6020 ax = a[4],6021 ay = a[5],6022 az = a[6],6023 aw = a[7],6024 ax1 = ax * bw + aw * bx + ay * bz - az * by,6025 ay1 = ay * bw + aw * by + az * bx - ax * bz,6026 az1 = az * bw + aw * bz + ax * by - ay * bx,6027 aw1 = aw * bw - ax * bx - ay * by - az * bz;6028 rotateY$2(out, a, rad);6029 bx = out[0];6030 by = out[1];6031 bz = out[2];6032 bw = out[3];6033 out[4] = ax1 * bw + aw1 * bx + ay1 * bz - az1 * by;6034 out[5] = ay1 * bw + aw1 * by + az1 * bx - ax1 * bz;6035 out[6] = az1 * bw + aw1 * bz + ax1 * by - ay1 * bx;6036 out[7] = aw1 * bw - ax1 * bx - ay1 * by - az1 * bz;6037 return out;6038 }6039 /**6040 * Rotates a dual quat around the Z axis6041 *6042 * @param {quat2} out the receiving dual quaternion6043 * @param {ReadonlyQuat2} a the dual quaternion to rotate6044 * @param {number} rad how far should the rotation be6045 * @returns {quat2} out6046 */6047 function rotateZ$3(out, a, rad) {6048 var bx = -a[0],6049 by = -a[1],6050 bz = -a[2],6051 bw = a[3],6052 ax = a[4],6053 ay = a[5],6054 az = a[6],6055 aw = a[7],6056 ax1 = ax * bw + aw * bx + ay * bz - az * by,6057 ay1 = ay * bw + aw * by + az * bx - ax * bz,6058 az1 = az * bw + aw * bz + ax * by - ay * bx,6059 aw1 = aw * bw - ax * bx - ay * by - az * bz;6060 rotateZ$2(out, a, rad);6061 bx = out[0];6062 by = out[1];6063 bz = out[2];6064 bw = out[3];6065 out[4] = ax1 * bw + aw1 * bx + ay1 * bz - az1 * by;6066 out[5] = ay1 * bw + aw1 * by + az1 * bx - ax1 * bz;6067 out[6] = az1 * bw + aw1 * bz + ax1 * by - ay1 * bx;6068 out[7] = aw1 * bw - ax1 * bx - ay1 * by - az1 * bz;6069 return out;6070 }6071 /**6072 * Rotates a dual quat by a given quaternion (a * q)6073 *6074 * @param {quat2} out the receiving dual quaternion6075 * @param {ReadonlyQuat2} a the dual quaternion to rotate6076 * @param {ReadonlyQuat} q quaternion to rotate by6077 * @returns {quat2} out6078 */6079 function rotateByQuatAppend(out, a, q) {6080 var qx = q[0],6081 qy = q[1],6082 qz = q[2],6083 qw = q[3],6084 ax = a[0],6085 ay = a[1],6086 az = a[2],6087 aw = a[3];6088 out[0] = ax * qw + aw * qx + ay * qz - az * qy;6089 out[1] = ay * qw + aw * qy + az * qx - ax * qz;6090 out[2] = az * qw + aw * qz + ax * qy - ay * qx;6091 out[3] = aw * qw - ax * qx - ay * qy - az * qz;6092 ax = a[4];6093 ay = a[5];6094 az = a[6];6095 aw = a[7];6096 out[4] = ax * qw + aw * qx + ay * qz - az * qy;6097 out[5] = ay * qw + aw * qy + az * qx - ax * qz;6098 out[6] = az * qw + aw * qz + ax * qy - ay * qx;6099 out[7] = aw * qw - ax * qx - ay * qy - az * qz;6100 return out;6101 }6102 /**6103 * Rotates a dual quat by a given quaternion (q * a)6104 *6105 * @param {quat2} out the receiving dual quaternion6106 * @param {ReadonlyQuat} q quaternion to rotate by6107 * @param {ReadonlyQuat2} a the dual quaternion to rotate6108 * @returns {quat2} out6109 */6110 function rotateByQuatPrepend(out, q, a) {6111 var qx = q[0],6112 qy = q[1],6113 qz = q[2],6114 qw = q[3],6115 bx = a[0],6116 by = a[1],6117 bz = a[2],6118 bw = a[3];6119 out[0] = qx * bw + qw * bx + qy * bz - qz * by;6120 out[1] = qy * bw + qw * by + qz * bx - qx * bz;6121 out[2] = qz * bw + qw * bz + qx * by - qy * bx;6122 out[3] = qw * bw - qx * bx - qy * by - qz * bz;6123 bx = a[4];6124 by = a[5];6125 bz = a[6];6126 bw = a[7];6127 out[4] = qx * bw + qw * bx + qy * bz - qz * by;6128 out[5] = qy * bw + qw * by + qz * bx - qx * bz;6129 out[6] = qz * bw + qw * bz + qx * by - qy * bx;6130 out[7] = qw * bw - qx * bx - qy * by - qz * bz;6131 return out;6132 }6133 /**6134 * Rotates a dual quat around a given axis. Does the normalisation automatically6135 *6136 * @param {quat2} out the receiving dual quaternion6137 * @param {ReadonlyQuat2} a the dual quaternion to rotate6138 * @param {ReadonlyVec3} axis the axis to rotate around6139 * @param {Number} rad how far the rotation should be6140 * @returns {quat2} out6141 */6142 function rotateAroundAxis(out, a, axis, rad) {6143 //Special case for rad = 06144 if (Math.abs(rad) < EPSILON) {6145 return copy$7(out, a);6146 }6147 var axisLength = Math.hypot(axis[0], axis[1], axis[2]);6148 rad = rad * 0.5;6149 var s = Math.sin(rad);6150 var bx = s * axis[0] / axisLength;6151 var by = s * axis[1] / axisLength;6152 var bz = s * axis[2] / axisLength;6153 var bw = Math.cos(rad);6154 var ax1 = a[0],6155 ay1 = a[1],6156 az1 = a[2],6157 aw1 = a[3];6158 out[0] = ax1 * bw + aw1 * bx + ay1 * bz - az1 * by;6159 out[1] = ay1 * bw + aw1 * by + az1 * bx - ax1 * bz;6160 out[2] = az1 * bw + aw1 * bz + ax1 * by - ay1 * bx;6161 out[3] = aw1 * bw - ax1 * bx - ay1 * by - az1 * bz;6162 var ax = a[4],6163 ay = a[5],6164 az = a[6],6165 aw = a[7];6166 out[4] = ax * bw + aw * bx + ay * bz - az * by;6167 out[5] = ay * bw + aw * by + az * bx - ax * bz;6168 out[6] = az * bw + aw * bz + ax * by - ay * bx;6169 out[7] = aw * bw - ax * bx - ay * by - az * bz;6170 return out;6171 }6172 /**6173 * Adds two dual quat's6174 *6175 * @param {quat2} out the receiving dual quaternion6176 * @param {ReadonlyQuat2} a the first operand6177 * @param {ReadonlyQuat2} b the second operand6178 * @returns {quat2} out6179 * @function6180 */6181 function add$7(out, a, b) {6182 out[0] = a[0] + b[0];6183 out[1] = a[1] + b[1];6184 out[2] = a[2] + b[2];6185 out[3] = a[3] + b[3];6186 out[4] = a[4] + b[4];6187 out[5] = a[5] + b[5];6188 out[6] = a[6] + b[6];6189 out[7] = a[7] + b[7];6190 return out;6191 }6192 /**6193 * Multiplies two dual quat's6194 *6195 * @param {quat2} out the receiving dual quaternion6196 * @param {ReadonlyQuat2} a the first operand6197 * @param {ReadonlyQuat2} b the second operand6198 * @returns {quat2} out6199 */6200 function multiply$7(out, a, b) {6201 var ax0 = a[0],6202 ay0 = a[1],6203 az0 = a[2],6204 aw0 = a[3],6205 bx1 = b[4],6206 by1 = b[5],6207 bz1 = b[6],6208 bw1 = b[7],6209 ax1 = a[4],6210 ay1 = a[5],6211 az1 = a[6],6212 aw1 = a[7],6213 bx0 = b[0],6214 by0 = b[1],6215 bz0 = b[2],6216 bw0 = b[3];6217 out[0] = ax0 * bw0 + aw0 * bx0 + ay0 * bz0 - az0 * by0;6218 out[1] = ay0 * bw0 + aw0 * by0 + az0 * bx0 - ax0 * bz0;6219 out[2] = az0 * bw0 + aw0 * bz0 + ax0 * by0 - ay0 * bx0;6220 out[3] = aw0 * bw0 - ax0 * bx0 - ay0 * by0 - az0 * bz0;6221 out[4] = ax0 * bw1 + aw0 * bx1 + ay0 * bz1 - az0 * by1 + ax1 * bw0 + aw1 * bx0 + ay1 * bz0 - az1 * by0;6222 out[5] = ay0 * bw1 + aw0 * by1 + az0 * bx1 - ax0 * bz1 + ay1 * bw0 + aw1 * by0 + az1 * bx0 - ax1 * bz0;6223 out[6] = az0 * bw1 + aw0 * bz1 + ax0 * by1 - ay0 * bx1 + az1 * bw0 + aw1 * bz0 + ax1 * by0 - ay1 * bx0;6224 out[7] = aw0 * bw1 - ax0 * bx1 - ay0 * by1 - az0 * bz1 + aw1 * bw0 - ax1 * bx0 - ay1 * by0 - az1 * bz0;6225 return out;6226 }6227 /**6228 * Alias for {@link quat2.multiply}6229 * @function6230 */6231 var mul$7 = multiply$7;6232 /**6233 * Scales a dual quat by a scalar number6234 *6235 * @param {quat2} out the receiving dual quat6236 * @param {ReadonlyQuat2} a the dual quat to scale6237 * @param {Number} b amount to scale the dual quat by6238 * @returns {quat2} out6239 * @function6240 */6241 function scale$7(out, a, b) {6242 out[0] = a[0] * b;6243 out[1] = a[1] * b;6244 out[2] = a[2] * b;6245 out[3] = a[3] * b;6246 out[4] = a[4] * b;6247 out[5] = a[5] * b;6248 out[6] = a[6] * b;6249 out[7] = a[7] * b;6250 return out;6251 }6252 /**6253 * Calculates the dot product of two dual quat's (The dot product of the real parts)6254 *6255 * @param {ReadonlyQuat2} a the first operand6256 * @param {ReadonlyQuat2} b the second operand6257 * @returns {Number} dot product of a and b6258 * @function6259 */6260 var dot$3 = dot$2;6261 /**6262 * Performs a linear interpolation between two dual quats's6263 * NOTE: The resulting dual quaternions won't always be normalized (The error is most noticeable when t = 0.5)6264 *6265 * @param {quat2} out the receiving dual quat6266 * @param {ReadonlyQuat2} a the first operand6267 * @param {ReadonlyQuat2} b the second operand6268 * @param {Number} t interpolation amount, in the range [0-1], between the two inputs6269 * @returns {quat2} out6270 */6271 function lerp$3(out, a, b, t) {6272 var mt = 1 - t;6273 if (dot$3(a, b) < 0) t = -t;6274 out[0] = a[0] * mt + b[0] * t;6275 out[1] = a[1] * mt + b[1] * t;6276 out[2] = a[2] * mt + b[2] * t;6277 out[3] = a[3] * mt + b[3] * t;6278 out[4] = a[4] * mt + b[4] * t;6279 out[5] = a[5] * mt + b[5] * t;6280 out[6] = a[6] * mt + b[6] * t;6281 out[7] = a[7] * mt + b[7] * t;6282 return out;6283 }6284 /**6285 * Calculates the inverse of a dual quat. If they are normalized, conjugate is cheaper6286 *6287 * @param {quat2} out the receiving dual quaternion6288 * @param {ReadonlyQuat2} a dual quat to calculate inverse of6289 * @returns {quat2} out6290 */6291 function invert$5(out, a) {6292 var sqlen = squaredLength$3(a);6293 out[0] = -a[0] / sqlen;6294 out[1] = -a[1] / sqlen;6295 out[2] = -a[2] / sqlen;6296 out[3] = a[3] / sqlen;6297 out[4] = -a[4] / sqlen;6298 out[5] = -a[5] / sqlen;6299 out[6] = -a[6] / sqlen;6300 out[7] = a[7] / sqlen;6301 return out;6302 }6303 /**6304 * Calculates the conjugate of a dual quat6305 * If the dual quaternion is normalized, this function is faster than quat2.inverse and produces the same result.6306 *6307 * @param {quat2} out the receiving quaternion6308 * @param {ReadonlyQuat2} a quat to calculate conjugate of6309 * @returns {quat2} out6310 */6311 function conjugate$1(out, a) {6312 out[0] = -a[0];6313 out[1] = -a[1];6314 out[2] = -a[2];6315 out[3] = a[3];6316 out[4] = -a[4];6317 out[5] = -a[5];6318 out[6] = -a[6];6319 out[7] = a[7];6320 return out;6321 }6322 /**6323 * Calculates the length of a dual quat6324 *6325 * @param {ReadonlyQuat2} a dual quat to calculate length of6326 * @returns {Number} length of a6327 * @function6328 */6329 var length$3 = length$2;6330 /**6331 * Alias for {@link quat2.length}6332 * @function6333 */6334 var len$3 = length$3;6335 /**6336 * Calculates the squared length of a dual quat6337 *6338 * @param {ReadonlyQuat2} a dual quat to calculate squared length of6339 * @returns {Number} squared length of a6340 * @function6341 */6342 var squaredLength$3 = squaredLength$2;6343 /**6344 * Alias for {@link quat2.squaredLength}6345 * @function6346 */6347 var sqrLen$3 = squaredLength$3;6348 /**6349 * Normalize a dual quat6350 *6351 * @param {quat2} out the receiving dual quaternion6352 * @param {ReadonlyQuat2} a dual quaternion to normalize6353 * @returns {quat2} out6354 * @function6355 */6356 function normalize$3(out, a) {6357 var magnitude = squaredLength$3(a);6358 if (magnitude > 0) {6359 magnitude = Math.sqrt(magnitude);6360 var a0 = a[0] / magnitude;6361 var a1 = a[1] / magnitude;6362 var a2 = a[2] / magnitude;6363 var a3 = a[3] / magnitude;6364 var b0 = a[4];6365 var b1 = a[5];6366 var b2 = a[6];6367 var b3 = a[7];6368 var a_dot_b = a0 * b0 + a1 * b1 + a2 * b2 + a3 * b3;6369 out[0] = a0;6370 out[1] = a1;6371 out[2] = a2;6372 out[3] = a3;6373 out[4] = (b0 - a0 * a_dot_b) / magnitude;6374 out[5] = (b1 - a1 * a_dot_b) / magnitude;6375 out[6] = (b2 - a2 * a_dot_b) / magnitude;6376 out[7] = (b3 - a3 * a_dot_b) / magnitude;6377 }6378 return out;6379 }6380 /**6381 * Returns a string representation of a dual quatenion6382 *6383 * @param {ReadonlyQuat2} a dual quaternion to represent as a string6384 * @returns {String} string representation of the dual quat6385 */6386 function str$7(a) {6387 return "quat2(" + a[0] + ", " + a[1] + ", " + a[2] + ", " + a[3] + ", " + a[4] + ", " + a[5] + ", " + a[6] + ", " + a[7] + ")";6388 }6389 /**6390 * Returns whether or not the dual quaternions have exactly the same elements in the same position (when compared with ===)6391 *6392 * @param {ReadonlyQuat2} a the first dual quaternion.6393 * @param {ReadonlyQuat2} b the second dual quaternion.6394 * @returns {Boolean} true if the dual quaternions are equal, false otherwise.6395 */6396 function exactEquals$7(a, b) {6397 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];6398 }6399 /**6400 * Returns whether or not the dual quaternions have approximately the same elements in the same position.6401 *6402 * @param {ReadonlyQuat2} a the first dual quat.6403 * @param {ReadonlyQuat2} b the second dual quat.6404 * @returns {Boolean} true if the dual quats are equal, false otherwise.6405 */6406 function equals$8(a, b) {6407 var a0 = a[0],6408 a1 = a[1],6409 a2 = a[2],6410 a3 = a[3],6411 a4 = a[4],6412 a5 = a[5],6413 a6 = a[6],6414 a7 = a[7];6415 var b0 = b[0],6416 b1 = b[1],6417 b2 = b[2],6418 b3 = b[3],6419 b4 = b[4],6420 b5 = b[5],6421 b6 = b[6],6422 b7 = b[7];6423 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));6424 }6425 var quat2 = /*#__PURE__*/Object.freeze({6426 __proto__: null,6427 create: create$7,6428 clone: clone$7,6429 fromValues: fromValues$7,6430 fromRotationTranslationValues: fromRotationTranslationValues,6431 fromRotationTranslation: fromRotationTranslation$1,6432 fromTranslation: fromTranslation$3,6433 fromRotation: fromRotation$4,6434 fromMat4: fromMat4$1,6435 copy: copy$7,6436 identity: identity$5,6437 set: set$7,6438 getReal: getReal,6439 getDual: getDual,6440 setReal: setReal,6441 setDual: setDual,6442 getTranslation: getTranslation$1,6443 translate: translate$3,6444 rotateX: rotateX$3,6445 rotateY: rotateY$3,6446 rotateZ: rotateZ$3,6447 rotateByQuatAppend: rotateByQuatAppend,6448 rotateByQuatPrepend: rotateByQuatPrepend,6449 rotateAroundAxis: rotateAroundAxis,6450 add: add$7,6451 multiply: multiply$7,6452 mul: mul$7,6453 scale: scale$7,6454 dot: dot$3,6455 lerp: lerp$3,6456 invert: invert$5,6457 conjugate: conjugate$1,6458 length: length$3,6459 len: len$3,6460 squaredLength: squaredLength$3,6461 sqrLen: sqrLen$3,6462 normalize: normalize$3,6463 str: str$7,6464 exactEquals: exactEquals$7,6465 equals: equals$86466 });6467 /**6468 * 2 Dimensional Vector6469 * @module vec26470 */6471 /**6472 * Creates a new, empty vec26473 *6474 * @returns {vec2} a new 2D vector6475 */6476 function create$8() {6477 var out = new ARRAY_TYPE(2);6478 if (ARRAY_TYPE != Float32Array) {6479 out[0] = 0;6480 out[1] = 0;6481 }6482 return out;6483 }6484 /**6485 * Creates a new vec2 initialized with values from an existing vector6486 *6487 * @param {ReadonlyVec2} a vector to clone6488 * @returns {vec2} a new 2D vector6489 */6490 function clone$8(a) {6491 var out = new ARRAY_TYPE(2);6492 out[0] = a[0];6493 out[1] = a[1];6494 return out;6495 }6496 /**6497 * Creates a new vec2 initialized with the given values6498 *6499 * @param {Number} x X component6500 * @param {Number} y Y component6501 * @returns {vec2} a new 2D vector6502 */6503 function fromValues$8(x, y) {6504 var out = new ARRAY_TYPE(2);6505 out[0] = x;6506 out[1] = y;6507 return out;6508 }6509 /**6510 * Copy the values from one vec2 to another6511 *6512 * @param {vec2} out the receiving vector6513 * @param {ReadonlyVec2} a the source vector6514 * @returns {vec2} out6515 */6516 function copy$8(out, a) {6517 out[0] = a[0];6518 out[1] = a[1];6519 return out;6520 }6521 /**6522 * Set the components of a vec2 to the given values6523 *6524 * @param {vec2} out the receiving vector6525 * @param {Number} x X component6526 * @param {Number} y Y component6527 * @returns {vec2} out6528 */6529 function set$8(out, x, y) {6530 out[0] = x;6531 out[1] = y;6532 return out;6533 }6534 /**6535 * Adds two vec2's6536 *6537 * @param {vec2} out the receiving vector6538 * @param {ReadonlyVec2} a the first operand6539 * @param {ReadonlyVec2} b the second operand6540 * @returns {vec2} out6541 */6542 function add$8(out, a, b) {6543 out[0] = a[0] + b[0];6544 out[1] = a[1] + b[1];6545 return out;6546 }6547 /**6548 * Subtracts vector b from vector a6549 *6550 * @param {vec2} out the receiving vector6551 * @param {ReadonlyVec2} a the first operand6552 * @param {ReadonlyVec2} b the second operand6553 * @returns {vec2} out6554 */6555 function subtract$6(out, a, b) {6556 out[0] = a[0] - b[0];6557 out[1] = a[1] - b[1];6558 return out;6559 }6560 /**6561 * Multiplies two vec2's6562 *6563 * @param {vec2} out the receiving vector6564 * @param {ReadonlyVec2} a the first operand6565 * @param {ReadonlyVec2} b the second operand6566 * @returns {vec2} out6567 */6568 function multiply$8(out, a, b) {6569 out[0] = a[0] * b[0];6570 out[1] = a[1] * b[1];6571 return out;6572 }6573 /**6574 * Divides two vec2's6575 *6576 * @param {vec2} out the receiving vector6577 * @param {ReadonlyVec2} a the first operand6578 * @param {ReadonlyVec2} b the second operand6579 * @returns {vec2} out6580 */6581 function divide$2(out, a, b) {6582 out[0] = a[0] / b[0];6583 out[1] = a[1] / b[1];6584 return out;6585 }6586 /**6587 * Math.ceil the components of a vec26588 *6589 * @param {vec2} out the receiving vector6590 * @param {ReadonlyVec2} a vector to ceil6591 * @returns {vec2} out6592 */6593 function ceil$2(out, a) {6594 out[0] = Math.ceil(a[0]);6595 out[1] = Math.ceil(a[1]);6596 return out;6597 }6598 /**6599 * Math.floor the components of a vec26600 *6601 * @param {vec2} out the receiving vector6602 * @param {ReadonlyVec2} a vector to floor6603 * @returns {vec2} out6604 */6605 function floor$2(out, a) {6606 out[0] = Math.floor(a[0]);6607 out[1] = Math.floor(a[1]);6608 return out;6609 }6610 /**6611 * Returns the minimum of two vec2's6612 *6613 * @param {vec2} out the receiving vector6614 * @param {ReadonlyVec2} a the first operand6615 * @param {ReadonlyVec2} b the second operand6616 * @returns {vec2} out6617 */6618 function min$2(out, a, b) {6619 out[0] = Math.min(a[0], b[0]);6620 out[1] = Math.min(a[1], b[1]);6621 return out;6622 }6623 /**6624 * Returns the maximum of two vec2's6625 *6626 * @param {vec2} out the receiving vector6627 * @param {ReadonlyVec2} a the first operand6628 * @param {ReadonlyVec2} b the second operand6629 * @returns {vec2} out6630 */6631 function max$2(out, a, b) {6632 out[0] = Math.max(a[0], b[0]);6633 out[1] = Math.max(a[1], b[1]);6634 return out;6635 }6636 /**6637 * Math.round the components of a vec26638 *6639 * @param {vec2} out the receiving vector6640 * @param {ReadonlyVec2} a vector to round6641 * @returns {vec2} out6642 */6643 function round$2(out, a) {6644 out[0] = Math.round(a[0]);6645 out[1] = Math.round(a[1]);6646 return out;6647 }6648 /**6649 * Scales a vec2 by a scalar number6650 *6651 * @param {vec2} out the receiving vector6652 * @param {ReadonlyVec2} a the vector to scale6653 * @param {Number} b amount to scale the vector by6654 * @returns {vec2} out6655 */6656 function scale$8(out, a, b) {6657 out[0] = a[0] * b;6658 out[1] = a[1] * b;6659 return out;6660 }6661 /**6662 * Adds two vec2's after scaling the second operand by a scalar value6663 *6664 * @param {vec2} out the receiving vector6665 * @param {ReadonlyVec2} a the first operand6666 * @param {ReadonlyVec2} b the second operand6667 * @param {Number} scale the amount to scale b by before adding6668 * @returns {vec2} out6669 */6670 function scaleAndAdd$2(out, a, b, scale) {6671 out[0] = a[0] + b[0] * scale;6672 out[1] = a[1] + b[1] * scale;6673 return out;6674 }6675 /**6676 * Calculates the euclidian distance between two vec2's6677 *6678 * @param {ReadonlyVec2} a the first operand6679 * @param {ReadonlyVec2} b the second operand6680 * @returns {Number} distance between a and b6681 */6682 function distance$2(a, b) {6683 var x = b[0] - a[0],6684 y = b[1] - a[1];6685 return Math.hypot(x, y);6686 }6687 /**6688 * Calculates the squared euclidian distance between two vec2's6689 *6690 * @param {ReadonlyVec2} a the first operand6691 * @param {ReadonlyVec2} b the second operand6692 * @returns {Number} squared distance between a and b6693 */6694 function squaredDistance$2(a, b) {6695 var x = b[0] - a[0],6696 y = b[1] - a[1];6697 return x * x + y * y;6698 }6699 /**6700 * Calculates the length of a vec26701 *6702 * @param {ReadonlyVec2} a vector to calculate length of6703 * @returns {Number} length of a6704 */6705 function length$4(a) {6706 var x = a[0],6707 y = a[1];6708 return Math.hypot(x, y);6709 }6710 /**6711 * Calculates the squared length of a vec26712 *6713 * @param {ReadonlyVec2} a vector to calculate squared length of6714 * @returns {Number} squared length of a6715 */6716 function squaredLength$4(a) {6717 var x = a[0],6718 y = a[1];6719 return x * x + y * y;6720 }6721 /**6722 * Negates the components of a vec26723 *6724 * @param {vec2} out the receiving vector6725 * @param {ReadonlyVec2} a vector to negate6726 * @returns {vec2} out6727 */6728 function negate$2(out, a) {6729 out[0] = -a[0];6730 out[1] = -a[1];6731 return out;6732 }6733 /**6734 * Returns the inverse of the components of a vec26735 *6736 * @param {vec2} out the receiving vector6737 * @param {ReadonlyVec2} a vector to invert6738 * @returns {vec2} out6739 */6740 function inverse$2(out, a) {6741 out[0] = 1.0 / a[0];6742 out[1] = 1.0 / a[1];6743 return out;6744 }6745 /**6746 * Normalize a vec26747 *6748 * @param {vec2} out the receiving vector6749 * @param {ReadonlyVec2} a vector to normalize6750 * @returns {vec2} out6751 */6752 function normalize$4(out, a) {6753 var x = a[0],6754 y = a[1];6755 var len = x * x + y * y;6756 if (len > 0) {6757 //TODO: evaluate use of glm_invsqrt here?6758 len = 1 / Math.sqrt(len);6759 }6760 out[0] = a[0] * len;6761 out[1] = a[1] * len;6762 return out;6763 }6764 /**6765 * Calculates the dot product of two vec2's6766 *6767 * @param {ReadonlyVec2} a the first operand6768 * @param {ReadonlyVec2} b the second operand6769 * @returns {Number} dot product of a and b6770 */6771 function dot$4(a, b) {6772 return a[0] * b[0] + a[1] * b[1];6773 }6774 /**6775 * Computes the cross product of two vec2's6776 * Note that the cross product must by definition produce a 3D vector6777 *6778 * @param {vec3} out the receiving vector6779 * @param {ReadonlyVec2} a the first operand6780 * @param {ReadonlyVec2} b the second operand6781 * @returns {vec3} out6782 */6783 function cross$2(out, a, b) {6784 var z = a[0] * b[1] - a[1] * b[0];6785 out[0] = out[1] = 0;6786 out[2] = z;6787 return out;6788 }6789 /**6790 * Performs a linear interpolation between two vec2's6791 *6792 * @param {vec2} out the receiving vector6793 * @param {ReadonlyVec2} a the first operand6794 * @param {ReadonlyVec2} b the second operand6795 * @param {Number} t interpolation amount, in the range [0-1], between the two inputs6796 * @returns {vec2} out6797 */6798 function lerp$4(out, a, b, t) {6799 var ax = a[0],6800 ay = a[1];6801 out[0] = ax + t * (b[0] - ax);6802 out[1] = ay + t * (b[1] - ay);6803 return out;6804 }6805 /**6806 * Generates a random vector with the given scale6807 *6808 * @param {vec2} out the receiving vector6809 * @param {Number} [scale] Length of the resulting vector. If ommitted, a unit vector will be returned6810 * @returns {vec2} out6811 */6812 function random$3(out, scale) {6813 scale = scale || 1.0;6814 var r = RANDOM() * 2.0 * Math.PI;6815 out[0] = Math.cos(r) * scale;6816 out[1] = Math.sin(r) * scale;6817 return out;6818 }6819 /**6820 * Transforms the vec2 with a mat26821 *6822 * @param {vec2} out the receiving vector6823 * @param {ReadonlyVec2} a the vector to transform6824 * @param {ReadonlyMat2} m matrix to transform with6825 * @returns {vec2} out6826 */6827 function transformMat2(out, a, m) {6828 var x = a[0],6829 y = a[1];6830 out[0] = m[0] * x + m[2] * y;6831 out[1] = m[1] * x + m[3] * y;6832 return out;6833 }6834 /**6835 * Transforms the vec2 with a mat2d6836 *6837 * @param {vec2} out the receiving vector6838 * @param {ReadonlyVec2} a the vector to transform6839 * @param {ReadonlyMat2d} m matrix to transform with6840 * @returns {vec2} out6841 */6842 function transformMat2d(out, a, m) {6843 var x = a[0],6844 y = a[1];6845 out[0] = m[0] * x + m[2] * y + m[4];6846 out[1] = m[1] * x + m[3] * y + m[5];6847 return out;6848 }6849 /**6850 * Transforms the vec2 with a mat36851 * 3rd vector component is implicitly '1'6852 *6853 * @param {vec2} out the receiving vector6854 * @param {ReadonlyVec2} a the vector to transform6855 * @param {ReadonlyMat3} m matrix to transform with6856 * @returns {vec2} out6857 */6858 function transformMat3$1(out, a, m) {6859 var x = a[0],6860 y = a[1];6861 out[0] = m[0] * x + m[3] * y + m[6];6862 out[1] = m[1] * x + m[4] * y + m[7];6863 return out;6864 }6865 /**6866 * Transforms the vec2 with a mat46867 * 3rd vector component is implicitly '0'6868 * 4th vector component is implicitly '1'6869 *6870 * @param {vec2} out the receiving vector6871 * @param {ReadonlyVec2} a the vector to transform6872 * @param {ReadonlyMat4} m matrix to transform with6873 * @returns {vec2} out6874 */6875 function transformMat4$2(out, a, m) {6876 var x = a[0];6877 var y = a[1];6878 out[0] = m[0] * x + m[4] * y + m[12];6879 out[1] = m[1] * x + m[5] * y + m[13];6880 return out;6881 }6882 /**6883 * Rotate a 2D vector6884 * @param {vec2} out The receiving vec26885 * @param {ReadonlyVec2} a The vec2 point to rotate6886 * @param {ReadonlyVec2} b The origin of the rotation6887 * @param {Number} rad The angle of rotation in radians6888 * @returns {vec2} out6889 */6890 function rotate$4(out, a, b, rad) {6891 //Translate point to the origin6892 var p0 = a[0] - b[0],6893 p1 = a[1] - b[1],6894 sinC = Math.sin(rad),6895 cosC = Math.cos(rad); //perform rotation and translate to correct position6896 out[0] = p0 * cosC - p1 * sinC + b[0];6897 out[1] = p0 * sinC + p1 * cosC + b[1];6898 return out;6899 }6900 /**6901 * Get the angle between two 2D vectors6902 * @param {ReadonlyVec2} a The first operand6903 * @param {ReadonlyVec2} b The second operand6904 * @returns {Number} The angle in radians6905 */6906 function angle$1(a, b) {6907 var x1 = a[0],6908 y1 = a[1],6909 x2 = b[0],6910 y2 = b[1],6911 // mag is the product of the magnitudes of a and b6912 mag = Math.sqrt(x1 * x1 + y1 * y1) * Math.sqrt(x2 * x2 + y2 * y2),6913 // mag &&.. short circuits if mag == 06914 cosine = mag && (x1 * x2 + y1 * y2) / mag; // Math.min(Math.max(cosine, -1), 1) clamps the cosine between -1 and 16915 return Math.acos(Math.min(Math.max(cosine, -1), 1));6916 }6917 /**6918 * Set the components of a vec2 to zero6919 *6920 * @param {vec2} out the receiving vector6921 * @returns {vec2} out6922 */6923 function zero$2(out) {6924 out[0] = 0.0;6925 out[1] = 0.0;6926 return out;6927 }6928 /**6929 * Returns a string representation of a vector6930 *6931 * @param {ReadonlyVec2} a vector to represent as a string6932 * @returns {String} string representation of the vector6933 */6934 function str$8(a) {6935 return "vec2(" + a[0] + ", " + a[1] + ")";6936 }6937 /**6938 * Returns whether or not the vectors exactly have the same elements in the same position (when compared with ===)6939 *6940 * @param {ReadonlyVec2} a The first vector.6941 * @param {ReadonlyVec2} b The second vector.6942 * @returns {Boolean} True if the vectors are equal, false otherwise.6943 */6944 function exactEquals$8(a, b) {6945 return a[0] === b[0] && a[1] === b[1];6946 }6947 /**6948 * Returns whether or not the vectors have approximately the same elements in the same position.6949 *6950 * @param {ReadonlyVec2} a The first vector.6951 * @param {ReadonlyVec2} b The second vector.6952 * @returns {Boolean} True if the vectors are equal, false otherwise.6953 */6954 function equals$9(a, b) {6955 var a0 = a[0],6956 a1 = a[1];6957 var b0 = b[0],6958 b1 = b[1];6959 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));6960 }6961 /**6962 * Alias for {@link vec2.length}6963 * @function6964 */6965 var len$4 = length$4;6966 /**6967 * Alias for {@link vec2.subtract}6968 * @function6969 */6970 var sub$6 = subtract$6;6971 /**6972 * Alias for {@link vec2.multiply}6973 * @function6974 */6975 var mul$8 = multiply$8;6976 /**6977 * Alias for {@link vec2.divide}6978 * @function6979 */6980 var div$2 = divide$2;6981 /**6982 * Alias for {@link vec2.distance}6983 * @function6984 */6985 var dist$2 = distance$2;6986 /**6987 * Alias for {@link vec2.squaredDistance}6988 * @function6989 */6990 var sqrDist$2 = squaredDistance$2;6991 /**6992 * Alias for {@link vec2.squaredLength}6993 * @function6994 */6995 var sqrLen$4 = squaredLength$4;6996 /**6997 * Perform some operation over an array of vec2s.6998 *6999 * @param {Array} a the array of vectors to iterate over7000 * @param {Number} stride Number of elements between the start of each vec2. If 0 assumes tightly packed7001 * @param {Number} offset Number of elements to skip at the beginning of the array7002 * @param {Number} count Number of vec2s to iterate over. If 0 iterates over entire array7003 * @param {Function} fn Function to call for each vector in the array7004 * @param {Object} [arg] additional argument to pass to fn7005 * @returns {Array} a7006 * @function7007 */7008 var forEach$2 = function () {7009 var vec = create$8();7010 return function (a, stride, offset, count, fn, arg) {7011 var i, l;7012 if (!stride) {7013 stride = 2;7014 }7015 if (!offset) {7016 offset = 0;7017 }7018 if (count) {7019 l = Math.min(count * stride + offset, a.length);7020 } else {7021 l = a.length;7022 }7023 for (i = offset; i < l; i += stride) {7024 vec[0] = a[i];7025 vec[1] = a[i + 1];7026 fn(vec, vec, arg);7027 a[i] = vec[0];7028 a[i + 1] = vec[1];7029 }7030 return a;7031 };7032 }();7033 var vec2 = /*#__PURE__*/Object.freeze({7034 __proto__: null,7035 create: create$8,7036 clone: clone$8,7037 fromValues: fromValues$8,7038 copy: copy$8,7039 set: set$8,7040 add: add$8,7041 subtract: subtract$6,7042 multiply: multiply$8,7043 divide: divide$2,7044 ceil: ceil$2,7045 floor: floor$2,7046 min: min$2,7047 max: max$2,7048 round: round$2,7049 scale: scale$8,7050 scaleAndAdd: scaleAndAdd$2,7051 distance: distance$2,7052 squaredDistance: squaredDistance$2,7053 length: length$4,7054 squaredLength: squaredLength$4,7055 negate: negate$2,7056 inverse: inverse$2,7057 normalize: normalize$4,7058 dot: dot$4,7059 cross: cross$2,7060 lerp: lerp$4,7061 random: random$3,7062 transformMat2: transformMat2,7063 transformMat2d: transformMat2d,7064 transformMat3: transformMat3$1,7065 transformMat4: transformMat4$2,7066 rotate: rotate$4,7067 angle: angle$1,7068 zero: zero$2,7069 str: str$8,7070 exactEquals: exactEquals$8,7071 equals: equals$9,7072 len: len$4,7073 sub: sub$6,7074 mul: mul$8,7075 div: div$2,7076 dist: dist$2,7077 sqrDist: sqrDist$2,7078 sqrLen: sqrLen$4,7079 forEach: forEach$27080 });7081 exports.glMatrix = common;7082 exports.mat2 = mat2;7083 exports.mat2d = mat2d;7084 exports.mat3 = mat3;7085 exports.mat4 = mat4;7086 exports.quat = quat;7087 exports.quat2 = quat2;7088 exports.vec2 = vec2;7089 exports.vec3 = vec3;7090 exports.vec4 = vec4;7091 Object.defineProperty(exports, '__esModule', { value: true });...

Full Screen

Full Screen

gl-matrix.js

Source:gl-matrix.js Github

copy

Full Screen

1/*!2@fileoverview gl-matrix - High performance matrix and vector operations3@author Brandon Jones4@author Colin MacKenzie IV5@version 3.0.06Copyright (c) 2015-2019, Brandon Jones, Colin MacKenzie IV.7Permission is hereby granted, free of charge, to any person obtaining a copy8of this software and associated documentation files (the "Software"), to deal9in the Software without restriction, including without limitation the rights10to use, copy, modify, merge, publish, distribute, sublicense, and/or sell11copies of the Software, and to permit persons to whom the Software is12furnished to do so, subject to the following conditions:13The above copyright notice and this permission notice shall be included in14all copies or substantial portions of the Software.15THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR16IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,17FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE18AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER19LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,20OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN21THE SOFTWARE.22*/23(function (global, factory) {24 typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :25 typeof define === 'function' && define.amd ? define(['exports'], factory) :26 (global = global || self, factory(global.glMatrix = {}));27}(this, function (exports) { 'use strict';28 /**29 * Common utilities30 * @module glMatrix31 */32 // Configuration Constants33 var EPSILON = 0.000001;34 var ARRAY_TYPE = typeof Float32Array !== 'undefined' ? Float32Array : Array;35 var RANDOM = Math.random;36 /**37 * Sets the type of array used when creating new vectors and matrices38 *39 * @param {Type} type Array type, such as Float32Array or Array40 */41 function setMatrixArrayType(type) {42 ARRAY_TYPE = type;43 }44 var degree = Math.PI / 180;45 /**46 * Convert Degree To Radian47 *48 * @param {Number} a Angle in Degrees49 */50 function toRadian(a) {51 return a * degree;52 }53 /**54 * Tests whether or not the arguments have approximately the same value, within an absolute55 * or relative tolerance of glMatrix.EPSILON (an absolute tolerance is used for values less56 * than or equal to 1.0, and a relative tolerance is used for larger values)57 *58 * @param {Number} a The first number to test.59 * @param {Number} b The second number to test.60 * @returns {Boolean} True if the numbers are approximately equal, false otherwise.61 */62 function equals(a, b) {63 return Math.abs(a - b) <= EPSILON * Math.max(1.0, Math.abs(a), Math.abs(b));64 }65 if (!Math.hypot) Math.hypot = function () {66 var y = 0,67 i = arguments.length;68 while (i--) {69 y += arguments[i] * arguments[i];70 }71 return Math.sqrt(y);72 };73 var common = /*#__PURE__*/Object.freeze({74 EPSILON: EPSILON,75 get ARRAY_TYPE () { return ARRAY_TYPE; },76 RANDOM: RANDOM,77 setMatrixArrayType: setMatrixArrayType,78 toRadian: toRadian,79 equals: equals80 });81 /**82 * 2x2 Matrix83 * @module mat284 */85 /**86 * Creates a new identity mat287 *88 * @returns {mat2} a new 2x2 matrix89 */90 function create() {91 var out = new ARRAY_TYPE(4);92 if (ARRAY_TYPE != Float32Array) {93 out[1] = 0;94 out[2] = 0;95 }96 out[0] = 1;97 out[3] = 1;98 return out;99 }100 /**101 * Creates a new mat2 initialized with values from an existing matrix102 *103 * @param {mat2} a matrix to clone104 * @returns {mat2} a new 2x2 matrix105 */106 function clone(a) {107 var out = new ARRAY_TYPE(4);108 out[0] = a[0];109 out[1] = a[1];110 out[2] = a[2];111 out[3] = a[3];112 return out;113 }114 /**115 * Copy the values from one mat2 to another116 *117 * @param {mat2} out the receiving matrix118 * @param {mat2} a the source matrix119 * @returns {mat2} out120 */121 function copy(out, a) {122 out[0] = a[0];123 out[1] = a[1];124 out[2] = a[2];125 out[3] = a[3];126 return out;127 }128 /**129 * Set a mat2 to the identity matrix130 *131 * @param {mat2} out the receiving matrix132 * @returns {mat2} out133 */134 function identity(out) {135 out[0] = 1;136 out[1] = 0;137 out[2] = 0;138 out[3] = 1;139 return out;140 }141 /**142 * Create a new mat2 with the given values143 *144 * @param {Number} m00 Component in column 0, row 0 position (index 0)145 * @param {Number} m01 Component in column 0, row 1 position (index 1)146 * @param {Number} m10 Component in column 1, row 0 position (index 2)147 * @param {Number} m11 Component in column 1, row 1 position (index 3)148 * @returns {mat2} out A new 2x2 matrix149 */150 function fromValues(m00, m01, m10, m11) {151 var out = new ARRAY_TYPE(4);152 out[0] = m00;153 out[1] = m01;154 out[2] = m10;155 out[3] = m11;156 return out;157 }158 /**159 * Set the components of a mat2 to the given values160 *161 * @param {mat2} out the receiving matrix162 * @param {Number} m00 Component in column 0, row 0 position (index 0)163 * @param {Number} m01 Component in column 0, row 1 position (index 1)164 * @param {Number} m10 Component in column 1, row 0 position (index 2)165 * @param {Number} m11 Component in column 1, row 1 position (index 3)166 * @returns {mat2} out167 */168 function set(out, m00, m01, m10, m11) {169 out[0] = m00;170 out[1] = m01;171 out[2] = m10;172 out[3] = m11;173 return out;174 }175 /**176 * Transpose the values of a mat2177 *178 * @param {mat2} out the receiving matrix179 * @param {mat2} a the source matrix180 * @returns {mat2} out181 */182 function transpose(out, a) {183 // If we are transposing ourselves we can skip a few steps but have to cache184 // some values185 if (out === a) {186 var a1 = a[1];187 out[1] = a[2];188 out[2] = a1;189 } else {190 out[0] = a[0];191 out[1] = a[2];192 out[2] = a[1];193 out[3] = a[3];194 }195 return out;196 }197 /**198 * Inverts a mat2199 *200 * @param {mat2} out the receiving matrix201 * @param {mat2} a the source matrix202 * @returns {mat2} out203 */204 function invert(out, a) {205 var a0 = a[0],206 a1 = a[1],207 a2 = a[2],208 a3 = a[3]; // Calculate the determinant209 var det = a0 * a3 - a2 * a1;210 if (!det) {211 return null;212 }213 det = 1.0 / det;214 out[0] = a3 * det;215 out[1] = -a1 * det;216 out[2] = -a2 * det;217 out[3] = a0 * det;218 return out;219 }220 /**221 * Calculates the adjugate of a mat2222 *223 * @param {mat2} out the receiving matrix224 * @param {mat2} a the source matrix225 * @returns {mat2} out226 */227 function adjoint(out, a) {228 // Caching this value is nessecary if out == a229 var a0 = a[0];230 out[0] = a[3];231 out[1] = -a[1];232 out[2] = -a[2];233 out[3] = a0;234 return out;235 }236 /**237 * Calculates the determinant of a mat2238 *239 * @param {mat2} a the source matrix240 * @returns {Number} determinant of a241 */242 function determinant(a) {243 return a[0] * a[3] - a[2] * a[1];244 }245 /**246 * Multiplies two mat2's247 *248 * @param {mat2} out the receiving matrix249 * @param {mat2} a the first operand250 * @param {mat2} b the second operand251 * @returns {mat2} out252 */253 function multiply(out, a, b) {254 var a0 = a[0],255 a1 = a[1],256 a2 = a[2],257 a3 = a[3];258 var b0 = b[0],259 b1 = b[1],260 b2 = b[2],261 b3 = b[3];262 out[0] = a0 * b0 + a2 * b1;263 out[1] = a1 * b0 + a3 * b1;264 out[2] = a0 * b2 + a2 * b3;265 out[3] = a1 * b2 + a3 * b3;266 return out;267 }268 /**269 * Rotates a mat2 by the given angle270 *271 * @param {mat2} out the receiving matrix272 * @param {mat2} a the matrix to rotate273 * @param {Number} rad the angle to rotate the matrix by274 * @returns {mat2} out275 */276 function rotate(out, a, rad) {277 var a0 = a[0],278 a1 = a[1],279 a2 = a[2],280 a3 = a[3];281 var s = Math.sin(rad);282 var c = Math.cos(rad);283 out[0] = a0 * c + a2 * s;284 out[1] = a1 * c + a3 * s;285 out[2] = a0 * -s + a2 * c;286 out[3] = a1 * -s + a3 * c;287 return out;288 }289 /**290 * Scales the mat2 by the dimensions in the given vec2291 *292 * @param {mat2} out the receiving matrix293 * @param {mat2} a the matrix to rotate294 * @param {vec2} v the vec2 to scale the matrix by295 * @returns {mat2} out296 **/297 function scale(out, a, v) {298 var a0 = a[0],299 a1 = a[1],300 a2 = a[2],301 a3 = a[3];302 var v0 = v[0],303 v1 = v[1];304 out[0] = a0 * v0;305 out[1] = a1 * v0;306 out[2] = a2 * v1;307 out[3] = a3 * v1;308 return out;309 }310 /**311 * Creates a matrix from a given angle312 * This is equivalent to (but much faster than):313 *314 * mat2.identity(dest);315 * mat2.rotate(dest, dest, rad);316 *317 * @param {mat2} out mat2 receiving operation result318 * @param {Number} rad the angle to rotate the matrix by319 * @returns {mat2} out320 */321 function fromRotation(out, rad) {322 var s = Math.sin(rad);323 var c = Math.cos(rad);324 out[0] = c;325 out[1] = s;326 out[2] = -s;327 out[3] = c;328 return out;329 }330 /**331 * Creates a matrix from a vector scaling332 * This is equivalent to (but much faster than):333 *334 * mat2.identity(dest);335 * mat2.scale(dest, dest, vec);336 *337 * @param {mat2} out mat2 receiving operation result338 * @param {vec2} v Scaling vector339 * @returns {mat2} out340 */341 function fromScaling(out, v) {342 out[0] = v[0];343 out[1] = 0;344 out[2] = 0;345 out[3] = v[1];346 return out;347 }348 /**349 * Returns a string representation of a mat2350 *351 * @param {mat2} a matrix to represent as a string352 * @returns {String} string representation of the matrix353 */354 function str(a) {355 return 'mat2(' + a[0] + ', ' + a[1] + ', ' + a[2] + ', ' + a[3] + ')';356 }357 /**358 * Returns Frobenius norm of a mat2359 *360 * @param {mat2} a the matrix to calculate Frobenius norm of361 * @returns {Number} Frobenius norm362 */363 function frob(a) {364 return Math.hypot(a[0], a[1], a[2], a[3]);365 }366 /**367 * Returns L, D and U matrices (Lower triangular, Diagonal and Upper triangular) by factorizing the input matrix368 * @param {mat2} L the lower triangular matrix369 * @param {mat2} D the diagonal matrix370 * @param {mat2} U the upper triangular matrix371 * @param {mat2} a the input matrix to factorize372 */373 function LDU(L, D, U, a) {374 L[2] = a[2] / a[0];375 U[0] = a[0];376 U[1] = a[1];377 U[3] = a[3] - L[2] * U[1];378 return [L, D, U];379 }380 /**381 * Adds two mat2's382 *383 * @param {mat2} out the receiving matrix384 * @param {mat2} a the first operand385 * @param {mat2} b the second operand386 * @returns {mat2} out387 */388 function add(out, a, b) {389 out[0] = a[0] + b[0];390 out[1] = a[1] + b[1];391 out[2] = a[2] + b[2];392 out[3] = a[3] + b[3];393 return out;394 }395 /**396 * Subtracts matrix b from matrix a397 *398 * @param {mat2} out the receiving matrix399 * @param {mat2} a the first operand400 * @param {mat2} b the second operand401 * @returns {mat2} out402 */403 function subtract(out, a, b) {404 out[0] = a[0] - b[0];405 out[1] = a[1] - b[1];406 out[2] = a[2] - b[2];407 out[3] = a[3] - b[3];408 return out;409 }410 /**411 * Returns whether or not the matrices have exactly the same elements in the same position (when compared with ===)412 *413 * @param {mat2} a The first matrix.414 * @param {mat2} b The second matrix.415 * @returns {Boolean} True if the matrices are equal, false otherwise.416 */417 function exactEquals(a, b) {418 return a[0] === b[0] && a[1] === b[1] && a[2] === b[2] && a[3] === b[3];419 }420 /**421 * Returns whether or not the matrices have approximately the same elements in the same position.422 *423 * @param {mat2} a The first matrix.424 * @param {mat2} b The second matrix.425 * @returns {Boolean} True if the matrices are equal, false otherwise.426 */427 function equals$1(a, b) {428 var a0 = a[0],429 a1 = a[1],430 a2 = a[2],431 a3 = a[3];432 var b0 = b[0],433 b1 = b[1],434 b2 = b[2],435 b3 = b[3];436 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));437 }438 /**439 * Multiply each element of the matrix by a scalar.440 *441 * @param {mat2} out the receiving matrix442 * @param {mat2} a the matrix to scale443 * @param {Number} b amount to scale the matrix's elements by444 * @returns {mat2} out445 */446 function multiplyScalar(out, a, b) {447 out[0] = a[0] * b;448 out[1] = a[1] * b;449 out[2] = a[2] * b;450 out[3] = a[3] * b;451 return out;452 }453 /**454 * Adds two mat2's after multiplying each element of the second operand by a scalar value.455 *456 * @param {mat2} out the receiving vector457 * @param {mat2} a the first operand458 * @param {mat2} b the second operand459 * @param {Number} scale the amount to scale b's elements by before adding460 * @returns {mat2} out461 */462 function multiplyScalarAndAdd(out, a, b, scale) {463 out[0] = a[0] + b[0] * scale;464 out[1] = a[1] + b[1] * scale;465 out[2] = a[2] + b[2] * scale;466 out[3] = a[3] + b[3] * scale;467 return out;468 }469 /**470 * Alias for {@link mat2.multiply}471 * @function472 */473 var mul = multiply;474 /**475 * Alias for {@link mat2.subtract}476 * @function477 */478 var sub = subtract;479 var mat2 = /*#__PURE__*/Object.freeze({480 create: create,481 clone: clone,482 copy: copy,483 identity: identity,484 fromValues: fromValues,485 set: set,486 transpose: transpose,487 invert: invert,488 adjoint: adjoint,489 determinant: determinant,490 multiply: multiply,491 rotate: rotate,492 scale: scale,493 fromRotation: fromRotation,494 fromScaling: fromScaling,495 str: str,496 frob: frob,497 LDU: LDU,498 add: add,499 subtract: subtract,500 exactEquals: exactEquals,501 equals: equals$1,502 multiplyScalar: multiplyScalar,503 multiplyScalarAndAdd: multiplyScalarAndAdd,504 mul: mul,505 sub: sub506 });507 /**508 * 2x3 Matrix509 * @module mat2d510 *511 * @description512 * A mat2d contains six elements defined as:513 * <pre>514 * [a, c, tx,515 * b, d, ty]516 * </pre>517 * This is a short form for the 3x3 matrix:518 * <pre>519 * [a, c, tx,520 * b, d, ty,521 * 0, 0, 1]522 * </pre>523 * The last row is ignored so the array is shorter and operations are faster.524 */525 /**526 * Creates a new identity mat2d527 *528 * @returns {mat2d} a new 2x3 matrix529 */530 function create$1() {531 var out = new ARRAY_TYPE(6);532 if (ARRAY_TYPE != Float32Array) {533 out[1] = 0;534 out[2] = 0;535 out[4] = 0;536 out[5] = 0;537 }538 out[0] = 1;539 out[3] = 1;540 return out;541 }542 /**543 * Creates a new mat2d initialized with values from an existing matrix544 *545 * @param {mat2d} a matrix to clone546 * @returns {mat2d} a new 2x3 matrix547 */548 function clone$1(a) {549 var out = new ARRAY_TYPE(6);550 out[0] = a[0];551 out[1] = a[1];552 out[2] = a[2];553 out[3] = a[3];554 out[4] = a[4];555 out[5] = a[5];556 return out;557 }558 /**559 * Copy the values from one mat2d to another560 *561 * @param {mat2d} out the receiving matrix562 * @param {mat2d} a the source matrix563 * @returns {mat2d} out564 */565 function copy$1(out, a) {566 out[0] = a[0];567 out[1] = a[1];568 out[2] = a[2];569 out[3] = a[3];570 out[4] = a[4];571 out[5] = a[5];572 return out;573 }574 /**575 * Set a mat2d to the identity matrix576 *577 * @param {mat2d} out the receiving matrix578 * @returns {mat2d} out579 */580 function identity$1(out) {581 out[0] = 1;582 out[1] = 0;583 out[2] = 0;584 out[3] = 1;585 out[4] = 0;586 out[5] = 0;587 return out;588 }589 /**590 * Create a new mat2d with the given values591 *592 * @param {Number} a Component A (index 0)593 * @param {Number} b Component B (index 1)594 * @param {Number} c Component C (index 2)595 * @param {Number} d Component D (index 3)596 * @param {Number} tx Component TX (index 4)597 * @param {Number} ty Component TY (index 5)598 * @returns {mat2d} A new mat2d599 */600 function fromValues$1(a, b, c, d, tx, ty) {601 var out = new ARRAY_TYPE(6);602 out[0] = a;603 out[1] = b;604 out[2] = c;605 out[3] = d;606 out[4] = tx;607 out[5] = ty;608 return out;609 }610 /**611 * Set the components of a mat2d to the given values612 *613 * @param {mat2d} out the receiving matrix614 * @param {Number} a Component A (index 0)615 * @param {Number} b Component B (index 1)616 * @param {Number} c Component C (index 2)617 * @param {Number} d Component D (index 3)618 * @param {Number} tx Component TX (index 4)619 * @param {Number} ty Component TY (index 5)620 * @returns {mat2d} out621 */622 function set$1(out, a, b, c, d, tx, ty) {623 out[0] = a;624 out[1] = b;625 out[2] = c;626 out[3] = d;627 out[4] = tx;628 out[5] = ty;629 return out;630 }631 /**632 * Inverts a mat2d633 *634 * @param {mat2d} out the receiving matrix635 * @param {mat2d} a the source matrix636 * @returns {mat2d} out637 */638 function invert$1(out, a) {639 var aa = a[0],640 ab = a[1],641 ac = a[2],642 ad = a[3];643 var atx = a[4],644 aty = a[5];645 var det = aa * ad - ab * ac;646 if (!det) {647 return null;648 }649 det = 1.0 / det;650 out[0] = ad * det;651 out[1] = -ab * det;652 out[2] = -ac * det;653 out[3] = aa * det;654 out[4] = (ac * aty - ad * atx) * det;655 out[5] = (ab * atx - aa * aty) * det;656 return out;657 }658 /**659 * Calculates the determinant of a mat2d660 *661 * @param {mat2d} a the source matrix662 * @returns {Number} determinant of a663 */664 function determinant$1(a) {665 return a[0] * a[3] - a[1] * a[2];666 }667 /**668 * Multiplies two mat2d's669 *670 * @param {mat2d} out the receiving matrix671 * @param {mat2d} a the first operand672 * @param {mat2d} b the second operand673 * @returns {mat2d} out674 */675 function multiply$1(out, a, b) {676 var a0 = a[0],677 a1 = a[1],678 a2 = a[2],679 a3 = a[3],680 a4 = a[4],681 a5 = a[5];682 var b0 = b[0],683 b1 = b[1],684 b2 = b[2],685 b3 = b[3],686 b4 = b[4],687 b5 = b[5];688 out[0] = a0 * b0 + a2 * b1;689 out[1] = a1 * b0 + a3 * b1;690 out[2] = a0 * b2 + a2 * b3;691 out[3] = a1 * b2 + a3 * b3;692 out[4] = a0 * b4 + a2 * b5 + a4;693 out[5] = a1 * b4 + a3 * b5 + a5;694 return out;695 }696 /**697 * Rotates a mat2d by the given angle698 *699 * @param {mat2d} out the receiving matrix700 * @param {mat2d} a the matrix to rotate701 * @param {Number} rad the angle to rotate the matrix by702 * @returns {mat2d} out703 */704 function rotate$1(out, a, rad) {705 var a0 = a[0],706 a1 = a[1],707 a2 = a[2],708 a3 = a[3],709 a4 = a[4],710 a5 = a[5];711 var s = Math.sin(rad);712 var c = Math.cos(rad);713 out[0] = a0 * c + a2 * s;714 out[1] = a1 * c + a3 * s;715 out[2] = a0 * -s + a2 * c;716 out[3] = a1 * -s + a3 * c;717 out[4] = a4;718 out[5] = a5;719 return out;720 }721 /**722 * Scales the mat2d by the dimensions in the given vec2723 *724 * @param {mat2d} out the receiving matrix725 * @param {mat2d} a the matrix to translate726 * @param {vec2} v the vec2 to scale the matrix by727 * @returns {mat2d} out728 **/729 function scale$1(out, a, v) {730 var a0 = a[0],731 a1 = a[1],732 a2 = a[2],733 a3 = a[3],734 a4 = a[4],735 a5 = a[5];736 var v0 = v[0],737 v1 = v[1];738 out[0] = a0 * v0;739 out[1] = a1 * v0;740 out[2] = a2 * v1;741 out[3] = a3 * v1;742 out[4] = a4;743 out[5] = a5;744 return out;745 }746 /**747 * Translates the mat2d by the dimensions in the given vec2748 *749 * @param {mat2d} out the receiving matrix750 * @param {mat2d} a the matrix to translate751 * @param {vec2} v the vec2 to translate the matrix by752 * @returns {mat2d} out753 **/754 function translate(out, a, v) {755 var a0 = a[0],756 a1 = a[1],757 a2 = a[2],758 a3 = a[3],759 a4 = a[4],760 a5 = a[5];761 var v0 = v[0],762 v1 = v[1];763 out[0] = a0;764 out[1] = a1;765 out[2] = a2;766 out[3] = a3;767 out[4] = a0 * v0 + a2 * v1 + a4;768 out[5] = a1 * v0 + a3 * v1 + a5;769 return out;770 }771 /**772 * Creates a matrix from a given angle773 * This is equivalent to (but much faster than):774 *775 * mat2d.identity(dest);776 * mat2d.rotate(dest, dest, rad);777 *778 * @param {mat2d} out mat2d receiving operation result779 * @param {Number} rad the angle to rotate the matrix by780 * @returns {mat2d} out781 */782 function fromRotation$1(out, rad) {783 var s = Math.sin(rad),784 c = Math.cos(rad);785 out[0] = c;786 out[1] = s;787 out[2] = -s;788 out[3] = c;789 out[4] = 0;790 out[5] = 0;791 return out;792 }793 /**794 * Creates a matrix from a vector scaling795 * This is equivalent to (but much faster than):796 *797 * mat2d.identity(dest);798 * mat2d.scale(dest, dest, vec);799 *800 * @param {mat2d} out mat2d receiving operation result801 * @param {vec2} v Scaling vector802 * @returns {mat2d} out803 */804 function fromScaling$1(out, v) {805 out[0] = v[0];806 out[1] = 0;807 out[2] = 0;808 out[3] = v[1];809 out[4] = 0;810 out[5] = 0;811 return out;812 }813 /**814 * Creates a matrix from a vector translation815 * This is equivalent to (but much faster than):816 *817 * mat2d.identity(dest);818 * mat2d.translate(dest, dest, vec);819 *820 * @param {mat2d} out mat2d receiving operation result821 * @param {vec2} v Translation vector822 * @returns {mat2d} out823 */824 function fromTranslation(out, v) {825 out[0] = 1;826 out[1] = 0;827 out[2] = 0;828 out[3] = 1;829 out[4] = v[0];830 out[5] = v[1];831 return out;832 }833 /**834 * Returns a string representation of a mat2d835 *836 * @param {mat2d} a matrix to represent as a string837 * @returns {String} string representation of the matrix838 */839 function str$1(a) {840 return 'mat2d(' + a[0] + ', ' + a[1] + ', ' + a[2] + ', ' + a[3] + ', ' + a[4] + ', ' + a[5] + ')';841 }842 /**843 * Returns Frobenius norm of a mat2d844 *845 * @param {mat2d} a the matrix to calculate Frobenius norm of846 * @returns {Number} Frobenius norm847 */848 function frob$1(a) {849 return Math.hypot(a[0], a[1], a[2], a[3], a[4], a[5], 1);850 }851 /**852 * Adds two mat2d's853 *854 * @param {mat2d} out the receiving matrix855 * @param {mat2d} a the first operand856 * @param {mat2d} b the second operand857 * @returns {mat2d} out858 */859 function add$1(out, a, b) {860 out[0] = a[0] + b[0];861 out[1] = a[1] + b[1];862 out[2] = a[2] + b[2];863 out[3] = a[3] + b[3];864 out[4] = a[4] + b[4];865 out[5] = a[5] + b[5];866 return out;867 }868 /**869 * Subtracts matrix b from matrix a870 *871 * @param {mat2d} out the receiving matrix872 * @param {mat2d} a the first operand873 * @param {mat2d} b the second operand874 * @returns {mat2d} out875 */876 function subtract$1(out, a, b) {877 out[0] = a[0] - b[0];878 out[1] = a[1] - b[1];879 out[2] = a[2] - b[2];880 out[3] = a[3] - b[3];881 out[4] = a[4] - b[4];882 out[5] = a[5] - b[5];883 return out;884 }885 /**886 * Multiply each element of the matrix by a scalar.887 *888 * @param {mat2d} out the receiving matrix889 * @param {mat2d} a the matrix to scale890 * @param {Number} b amount to scale the matrix's elements by891 * @returns {mat2d} out892 */893 function multiplyScalar$1(out, a, b) {894 out[0] = a[0] * b;895 out[1] = a[1] * b;896 out[2] = a[2] * b;897 out[3] = a[3] * b;898 out[4] = a[4] * b;899 out[5] = a[5] * b;900 return out;901 }902 /**903 * Adds two mat2d's after multiplying each element of the second operand by a scalar value.904 *905 * @param {mat2d} out the receiving vector906 * @param {mat2d} a the first operand907 * @param {mat2d} b the second operand908 * @param {Number} scale the amount to scale b's elements by before adding909 * @returns {mat2d} out910 */911 function multiplyScalarAndAdd$1(out, a, b, scale) {912 out[0] = a[0] + b[0] * scale;913 out[1] = a[1] + b[1] * scale;914 out[2] = a[2] + b[2] * scale;915 out[3] = a[3] + b[3] * scale;916 out[4] = a[4] + b[4] * scale;917 out[5] = a[5] + b[5] * scale;918 return out;919 }920 /**921 * Returns whether or not the matrices have exactly the same elements in the same position (when compared with ===)922 *923 * @param {mat2d} a The first matrix.924 * @param {mat2d} b The second matrix.925 * @returns {Boolean} True if the matrices are equal, false otherwise.926 */927 function exactEquals$1(a, b) {928 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];929 }930 /**931 * Returns whether or not the matrices have approximately the same elements in the same position.932 *933 * @param {mat2d} a The first matrix.934 * @param {mat2d} b The second matrix.935 * @returns {Boolean} True if the matrices are equal, false otherwise.936 */937 function equals$2(a, b) {938 var a0 = a[0],939 a1 = a[1],940 a2 = a[2],941 a3 = a[3],942 a4 = a[4],943 a5 = a[5];944 var b0 = b[0],945 b1 = b[1],946 b2 = b[2],947 b3 = b[3],948 b4 = b[4],949 b5 = b[5];950 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));951 }952 /**953 * Alias for {@link mat2d.multiply}954 * @function955 */956 var mul$1 = multiply$1;957 /**958 * Alias for {@link mat2d.subtract}959 * @function960 */961 var sub$1 = subtract$1;962 var mat2d = /*#__PURE__*/Object.freeze({963 create: create$1,964 clone: clone$1,965 copy: copy$1,966 identity: identity$1,967 fromValues: fromValues$1,968 set: set$1,969 invert: invert$1,970 determinant: determinant$1,971 multiply: multiply$1,972 rotate: rotate$1,973 scale: scale$1,974 translate: translate,975 fromRotation: fromRotation$1,976 fromScaling: fromScaling$1,977 fromTranslation: fromTranslation,978 str: str$1,979 frob: frob$1,980 add: add$1,981 subtract: subtract$1,982 multiplyScalar: multiplyScalar$1,983 multiplyScalarAndAdd: multiplyScalarAndAdd$1,984 exactEquals: exactEquals$1,985 equals: equals$2,986 mul: mul$1,987 sub: sub$1988 });989 /**990 * 3x3 Matrix991 * @module mat3992 */993 /**994 * Creates a new identity mat3995 *996 * @returns {mat3} a new 3x3 matrix997 */998 function create$2() {999 var out = new ARRAY_TYPE(9);1000 if (ARRAY_TYPE != Float32Array) {1001 out[1] = 0;1002 out[2] = 0;1003 out[3] = 0;1004 out[5] = 0;1005 out[6] = 0;1006 out[7] = 0;1007 }1008 out[0] = 1;1009 out[4] = 1;1010 out[8] = 1;1011 return out;1012 }1013 /**1014 * Copies the upper-left 3x3 values into the given mat3.1015 *1016 * @param {mat3} out the receiving 3x3 matrix1017 * @param {mat4} a the source 4x4 matrix1018 * @returns {mat3} out1019 */1020 function fromMat4(out, a) {1021 out[0] = a[0];1022 out[1] = a[1];1023 out[2] = a[2];1024 out[3] = a[4];1025 out[4] = a[5];1026 out[5] = a[6];1027 out[6] = a[8];1028 out[7] = a[9];1029 out[8] = a[10];1030 return out;1031 }1032 /**1033 * Creates a new mat3 initialized with values from an existing matrix1034 *1035 * @param {mat3} a matrix to clone1036 * @returns {mat3} a new 3x3 matrix1037 */1038 function clone$2(a) {1039 var out = new ARRAY_TYPE(9);1040 out[0] = a[0];1041 out[1] = a[1];1042 out[2] = a[2];1043 out[3] = a[3];1044 out[4] = a[4];1045 out[5] = a[5];1046 out[6] = a[6];1047 out[7] = a[7];1048 out[8] = a[8];1049 return out;1050 }1051 /**1052 * Copy the values from one mat3 to another1053 *1054 * @param {mat3} out the receiving matrix1055 * @param {mat3} a the source matrix1056 * @returns {mat3} out1057 */1058 function copy$2(out, a) {1059 out[0] = a[0];1060 out[1] = a[1];1061 out[2] = a[2];1062 out[3] = a[3];1063 out[4] = a[4];1064 out[5] = a[5];1065 out[6] = a[6];1066 out[7] = a[7];1067 out[8] = a[8];1068 return out;1069 }1070 /**1071 * Create a new mat3 with the given values1072 *1073 * @param {Number} m00 Component in column 0, row 0 position (index 0)1074 * @param {Number} m01 Component in column 0, row 1 position (index 1)1075 * @param {Number} m02 Component in column 0, row 2 position (index 2)1076 * @param {Number} m10 Component in column 1, row 0 position (index 3)1077 * @param {Number} m11 Component in column 1, row 1 position (index 4)1078 * @param {Number} m12 Component in column 1, row 2 position (index 5)1079 * @param {Number} m20 Component in column 2, row 0 position (index 6)1080 * @param {Number} m21 Component in column 2, row 1 position (index 7)1081 * @param {Number} m22 Component in column 2, row 2 position (index 8)1082 * @returns {mat3} A new mat31083 */1084 function fromValues$2(m00, m01, m02, m10, m11, m12, m20, m21, m22) {1085 var out = new ARRAY_TYPE(9);1086 out[0] = m00;1087 out[1] = m01;1088 out[2] = m02;1089 out[3] = m10;1090 out[4] = m11;1091 out[5] = m12;1092 out[6] = m20;1093 out[7] = m21;1094 out[8] = m22;1095 return out;1096 }1097 /**1098 * Set the components of a mat3 to the given values1099 *1100 * @param {mat3} out the receiving matrix1101 * @param {Number} m00 Component in column 0, row 0 position (index 0)1102 * @param {Number} m01 Component in column 0, row 1 position (index 1)1103 * @param {Number} m02 Component in column 0, row 2 position (index 2)1104 * @param {Number} m10 Component in column 1, row 0 position (index 3)1105 * @param {Number} m11 Component in column 1, row 1 position (index 4)1106 * @param {Number} m12 Component in column 1, row 2 position (index 5)1107 * @param {Number} m20 Component in column 2, row 0 position (index 6)1108 * @param {Number} m21 Component in column 2, row 1 position (index 7)1109 * @param {Number} m22 Component in column 2, row 2 position (index 8)1110 * @returns {mat3} out1111 */1112 function set$2(out, m00, m01, m02, m10, m11, m12, m20, m21, m22) {1113 out[0] = m00;1114 out[1] = m01;1115 out[2] = m02;1116 out[3] = m10;1117 out[4] = m11;1118 out[5] = m12;1119 out[6] = m20;1120 out[7] = m21;1121 out[8] = m22;1122 return out;1123 }1124 /**1125 * Set a mat3 to the identity matrix1126 *1127 * @param {mat3} out the receiving matrix1128 * @returns {mat3} out1129 */1130 function identity$2(out) {1131 out[0] = 1;1132 out[1] = 0;1133 out[2] = 0;1134 out[3] = 0;1135 out[4] = 1;1136 out[5] = 0;1137 out[6] = 0;1138 out[7] = 0;1139 out[8] = 1;1140 return out;1141 }1142 /**1143 * Transpose the values of a mat31144 *1145 * @param {mat3} out the receiving matrix1146 * @param {mat3} a the source matrix1147 * @returns {mat3} out1148 */1149 function transpose$1(out, a) {1150 // If we are transposing ourselves we can skip a few steps but have to cache some values1151 if (out === a) {1152 var a01 = a[1],1153 a02 = a[2],1154 a12 = a[5];1155 out[1] = a[3];1156 out[2] = a[6];1157 out[3] = a01;1158 out[5] = a[7];1159 out[6] = a02;1160 out[7] = a12;1161 } else {1162 out[0] = a[0];1163 out[1] = a[3];1164 out[2] = a[6];1165 out[3] = a[1];1166 out[4] = a[4];1167 out[5] = a[7];1168 out[6] = a[2];1169 out[7] = a[5];1170 out[8] = a[8];1171 }1172 return out;1173 }1174 /**1175 * Inverts a mat31176 *1177 * @param {mat3} out the receiving matrix1178 * @param {mat3} a the source matrix1179 * @returns {mat3} out1180 */1181 function invert$2(out, a) {1182 var a00 = a[0],1183 a01 = a[1],1184 a02 = a[2];1185 var a10 = a[3],1186 a11 = a[4],1187 a12 = a[5];1188 var a20 = a[6],1189 a21 = a[7],1190 a22 = a[8];1191 var b01 = a22 * a11 - a12 * a21;1192 var b11 = -a22 * a10 + a12 * a20;1193 var b21 = a21 * a10 - a11 * a20; // Calculate the determinant1194 var det = a00 * b01 + a01 * b11 + a02 * b21;1195 if (!det) {1196 return null;1197 }1198 det = 1.0 / det;1199 out[0] = b01 * det;1200 out[1] = (-a22 * a01 + a02 * a21) * det;1201 out[2] = (a12 * a01 - a02 * a11) * det;1202 out[3] = b11 * det;1203 out[4] = (a22 * a00 - a02 * a20) * det;1204 out[5] = (-a12 * a00 + a02 * a10) * det;1205 out[6] = b21 * det;1206 out[7] = (-a21 * a00 + a01 * a20) * det;1207 out[8] = (a11 * a00 - a01 * a10) * det;1208 return out;1209 }1210 /**1211 * Calculates the adjugate of a mat31212 *1213 * @param {mat3} out the receiving matrix1214 * @param {mat3} a the source matrix1215 * @returns {mat3} out1216 */1217 function adjoint$1(out, a) {1218 var a00 = a[0],1219 a01 = a[1],1220 a02 = a[2];1221 var a10 = a[3],1222 a11 = a[4],1223 a12 = a[5];1224 var a20 = a[6],1225 a21 = a[7],1226 a22 = a[8];1227 out[0] = a11 * a22 - a12 * a21;1228 out[1] = a02 * a21 - a01 * a22;1229 out[2] = a01 * a12 - a02 * a11;1230 out[3] = a12 * a20 - a10 * a22;1231 out[4] = a00 * a22 - a02 * a20;1232 out[5] = a02 * a10 - a00 * a12;1233 out[6] = a10 * a21 - a11 * a20;1234 out[7] = a01 * a20 - a00 * a21;1235 out[8] = a00 * a11 - a01 * a10;1236 return out;1237 }1238 /**1239 * Calculates the determinant of a mat31240 *1241 * @param {mat3} a the source matrix1242 * @returns {Number} determinant of a1243 */1244 function determinant$2(a) {1245 var a00 = a[0],1246 a01 = a[1],1247 a02 = a[2];1248 var a10 = a[3],1249 a11 = a[4],1250 a12 = a[5];1251 var a20 = a[6],1252 a21 = a[7],1253 a22 = a[8];1254 return a00 * (a22 * a11 - a12 * a21) + a01 * (-a22 * a10 + a12 * a20) + a02 * (a21 * a10 - a11 * a20);1255 }1256 /**1257 * Multiplies two mat3's1258 *1259 * @param {mat3} out the receiving matrix1260 * @param {mat3} a the first operand1261 * @param {mat3} b the second operand1262 * @returns {mat3} out1263 */1264 function multiply$2(out, a, b) {1265 var a00 = a[0],1266 a01 = a[1],1267 a02 = a[2];1268 var a10 = a[3],1269 a11 = a[4],1270 a12 = a[5];1271 var a20 = a[6],1272 a21 = a[7],1273 a22 = a[8];1274 var b00 = b[0],1275 b01 = b[1],1276 b02 = b[2];1277 var b10 = b[3],1278 b11 = b[4],1279 b12 = b[5];1280 var b20 = b[6],1281 b21 = b[7],1282 b22 = b[8];1283 out[0] = b00 * a00 + b01 * a10 + b02 * a20;1284 out[1] = b00 * a01 + b01 * a11 + b02 * a21;1285 out[2] = b00 * a02 + b01 * a12 + b02 * a22;1286 out[3] = b10 * a00 + b11 * a10 + b12 * a20;1287 out[4] = b10 * a01 + b11 * a11 + b12 * a21;1288 out[5] = b10 * a02 + b11 * a12 + b12 * a22;1289 out[6] = b20 * a00 + b21 * a10 + b22 * a20;1290 out[7] = b20 * a01 + b21 * a11 + b22 * a21;1291 out[8] = b20 * a02 + b21 * a12 + b22 * a22;1292 return out;1293 }1294 /**1295 * Translate a mat3 by the given vector1296 *1297 * @param {mat3} out the receiving matrix1298 * @param {mat3} a the matrix to translate1299 * @param {vec2} v vector to translate by1300 * @returns {mat3} out1301 */1302 function translate$1(out, a, v) {1303 var a00 = a[0],1304 a01 = a[1],1305 a02 = a[2],1306 a10 = a[3],1307 a11 = a[4],1308 a12 = a[5],1309 a20 = a[6],1310 a21 = a[7],1311 a22 = a[8],1312 x = v[0],1313 y = v[1];1314 out[0] = a00;1315 out[1] = a01;1316 out[2] = a02;1317 out[3] = a10;1318 out[4] = a11;1319 out[5] = a12;1320 out[6] = x * a00 + y * a10 + a20;1321 out[7] = x * a01 + y * a11 + a21;1322 out[8] = x * a02 + y * a12 + a22;1323 return out;1324 }1325 /**1326 * Rotates a mat3 by the given angle1327 *1328 * @param {mat3} out the receiving matrix1329 * @param {mat3} a the matrix to rotate1330 * @param {Number} rad the angle to rotate the matrix by1331 * @returns {mat3} out1332 */1333 function rotate$2(out, a, rad) {1334 var a00 = a[0],1335 a01 = a[1],1336 a02 = a[2],1337 a10 = a[3],1338 a11 = a[4],1339 a12 = a[5],1340 a20 = a[6],1341 a21 = a[7],1342 a22 = a[8],1343 s = Math.sin(rad),1344 c = Math.cos(rad);1345 out[0] = c * a00 + s * a10;1346 out[1] = c * a01 + s * a11;1347 out[2] = c * a02 + s * a12;1348 out[3] = c * a10 - s * a00;1349 out[4] = c * a11 - s * a01;1350 out[5] = c * a12 - s * a02;1351 out[6] = a20;1352 out[7] = a21;1353 out[8] = a22;1354 return out;1355 }1356 /**1357 * Scales the mat3 by the dimensions in the given vec21358 *1359 * @param {mat3} out the receiving matrix1360 * @param {mat3} a the matrix to rotate1361 * @param {vec2} v the vec2 to scale the matrix by1362 * @returns {mat3} out1363 **/1364 function scale$2(out, a, v) {1365 var x = v[0],1366 y = v[1];1367 out[0] = x * a[0];1368 out[1] = x * a[1];1369 out[2] = x * a[2];1370 out[3] = y * a[3];1371 out[4] = y * a[4];1372 out[5] = y * a[5];1373 out[6] = a[6];1374 out[7] = a[7];1375 out[8] = a[8];1376 return out;1377 }1378 /**1379 * Creates a matrix from a vector translation1380 * This is equivalent to (but much faster than):1381 *1382 * mat3.identity(dest);1383 * mat3.translate(dest, dest, vec);1384 *1385 * @param {mat3} out mat3 receiving operation result1386 * @param {vec2} v Translation vector1387 * @returns {mat3} out1388 */1389 function fromTranslation$1(out, v) {1390 out[0] = 1;1391 out[1] = 0;1392 out[2] = 0;1393 out[3] = 0;1394 out[4] = 1;1395 out[5] = 0;1396 out[6] = v[0];1397 out[7] = v[1];1398 out[8] = 1;1399 return out;1400 }1401 /**1402 * Creates a matrix from a given angle1403 * This is equivalent to (but much faster than):1404 *1405 * mat3.identity(dest);1406 * mat3.rotate(dest, dest, rad);1407 *1408 * @param {mat3} out mat3 receiving operation result1409 * @param {Number} rad the angle to rotate the matrix by1410 * @returns {mat3} out1411 */1412 function fromRotation$2(out, rad) {1413 var s = Math.sin(rad),1414 c = Math.cos(rad);1415 out[0] = c;1416 out[1] = s;1417 out[2] = 0;1418 out[3] = -s;1419 out[4] = c;1420 out[5] = 0;1421 out[6] = 0;1422 out[7] = 0;1423 out[8] = 1;1424 return out;1425 }1426 /**1427 * Creates a matrix from a vector scaling1428 * This is equivalent to (but much faster than):1429 *1430 * mat3.identity(dest);1431 * mat3.scale(dest, dest, vec);1432 *1433 * @param {mat3} out mat3 receiving operation result1434 * @param {vec2} v Scaling vector1435 * @returns {mat3} out1436 */1437 function fromScaling$2(out, v) {1438 out[0] = v[0];1439 out[1] = 0;1440 out[2] = 0;1441 out[3] = 0;1442 out[4] = v[1];1443 out[5] = 0;1444 out[6] = 0;1445 out[7] = 0;1446 out[8] = 1;1447 return out;1448 }1449 /**1450 * Copies the values from a mat2d into a mat31451 *1452 * @param {mat3} out the receiving matrix1453 * @param {mat2d} a the matrix to copy1454 * @returns {mat3} out1455 **/1456 function fromMat2d(out, a) {1457 out[0] = a[0];1458 out[1] = a[1];1459 out[2] = 0;1460 out[3] = a[2];1461 out[4] = a[3];1462 out[5] = 0;1463 out[6] = a[4];1464 out[7] = a[5];1465 out[8] = 1;1466 return out;1467 }1468 /**1469 * Calculates a 3x3 matrix from the given quaternion1470 *1471 * @param {mat3} out mat3 receiving operation result1472 * @param {quat} q Quaternion to create matrix from1473 *1474 * @returns {mat3} out1475 */1476 function fromQuat(out, q) {1477 var x = q[0],1478 y = q[1],1479 z = q[2],1480 w = q[3];1481 var x2 = x + x;1482 var y2 = y + y;1483 var z2 = z + z;1484 var xx = x * x2;1485 var yx = y * x2;1486 var yy = y * y2;1487 var zx = z * x2;1488 var zy = z * y2;1489 var zz = z * z2;1490 var wx = w * x2;1491 var wy = w * y2;1492 var wz = w * z2;1493 out[0] = 1 - yy - zz;1494 out[3] = yx - wz;1495 out[6] = zx + wy;1496 out[1] = yx + wz;1497 out[4] = 1 - xx - zz;1498 out[7] = zy - wx;1499 out[2] = zx - wy;1500 out[5] = zy + wx;1501 out[8] = 1 - xx - yy;1502 return out;1503 }1504 /**1505 * Calculates a 3x3 normal matrix (transpose inverse) from the 4x4 matrix1506 *1507 * @param {mat3} out mat3 receiving operation result1508 * @param {mat4} a Mat4 to derive the normal matrix from1509 *1510 * @returns {mat3} out1511 */1512 function normalFromMat4(out, a) {1513 var a00 = a[0],1514 a01 = a[1],1515 a02 = a[2],1516 a03 = a[3];1517 var a10 = a[4],1518 a11 = a[5],1519 a12 = a[6],1520 a13 = a[7];1521 var a20 = a[8],1522 a21 = a[9],1523 a22 = a[10],1524 a23 = a[11];1525 var a30 = a[12],1526 a31 = a[13],1527 a32 = a[14],1528 a33 = a[15];1529 var b00 = a00 * a11 - a01 * a10;1530 var b01 = a00 * a12 - a02 * a10;1531 var b02 = a00 * a13 - a03 * a10;1532 var b03 = a01 * a12 - a02 * a11;1533 var b04 = a01 * a13 - a03 * a11;1534 var b05 = a02 * a13 - a03 * a12;1535 var b06 = a20 * a31 - a21 * a30;1536 var b07 = a20 * a32 - a22 * a30;1537 var b08 = a20 * a33 - a23 * a30;1538 var b09 = a21 * a32 - a22 * a31;1539 var b10 = a21 * a33 - a23 * a31;1540 var b11 = a22 * a33 - a23 * a32; // Calculate the determinant1541 var det = b00 * b11 - b01 * b10 + b02 * b09 + b03 * b08 - b04 * b07 + b05 * b06;1542 if (!det) {1543 return null;1544 }1545 det = 1.0 / det;1546 out[0] = (a11 * b11 - a12 * b10 + a13 * b09) * det;1547 out[1] = (a12 * b08 - a10 * b11 - a13 * b07) * det;1548 out[2] = (a10 * b10 - a11 * b08 + a13 * b06) * det;1549 out[3] = (a02 * b10 - a01 * b11 - a03 * b09) * det;1550 out[4] = (a00 * b11 - a02 * b08 + a03 * b07) * det;1551 out[5] = (a01 * b08 - a00 * b10 - a03 * b06) * det;1552 out[6] = (a31 * b05 - a32 * b04 + a33 * b03) * det;1553 out[7] = (a32 * b02 - a30 * b05 - a33 * b01) * det;1554 out[8] = (a30 * b04 - a31 * b02 + a33 * b00) * det;1555 return out;1556 }1557 /**1558 * Generates a 2D projection matrix with the given bounds1559 *1560 * @param {mat3} out mat3 frustum matrix will be written into1561 * @param {number} width Width of your gl context1562 * @param {number} height Height of gl context1563 * @returns {mat3} out1564 */1565 function projection(out, width, height) {1566 out[0] = 2 / width;1567 out[1] = 0;1568 out[2] = 0;1569 out[3] = 0;1570 out[4] = -2 / height;1571 out[5] = 0;1572 out[6] = -1;1573 out[7] = 1;1574 out[8] = 1;1575 return out;1576 }1577 /**1578 * Returns a string representation of a mat31579 *1580 * @param {mat3} a matrix to represent as a string1581 * @returns {String} string representation of the matrix1582 */1583 function str$2(a) {1584 return 'mat3(' + a[0] + ', ' + a[1] + ', ' + a[2] + ', ' + a[3] + ', ' + a[4] + ', ' + a[5] + ', ' + a[6] + ', ' + a[7] + ', ' + a[8] + ')';1585 }1586 /**1587 * Returns Frobenius norm of a mat31588 *1589 * @param {mat3} a the matrix to calculate Frobenius norm of1590 * @returns {Number} Frobenius norm1591 */1592 function frob$2(a) {1593 return Math.hypot(a[0], a[1], a[2], a[3], a[4], a[5], a[6], a[7], a[8]);1594 }1595 /**1596 * Adds two mat3's1597 *1598 * @param {mat3} out the receiving matrix1599 * @param {mat3} a the first operand1600 * @param {mat3} b the second operand1601 * @returns {mat3} out1602 */1603 function add$2(out, a, b) {1604 out[0] = a[0] + b[0];1605 out[1] = a[1] + b[1];1606 out[2] = a[2] + b[2];1607 out[3] = a[3] + b[3];1608 out[4] = a[4] + b[4];1609 out[5] = a[5] + b[5];1610 out[6] = a[6] + b[6];1611 out[7] = a[7] + b[7];1612 out[8] = a[8] + b[8];1613 return out;1614 }1615 /**1616 * Subtracts matrix b from matrix a1617 *1618 * @param {mat3} out the receiving matrix1619 * @param {mat3} a the first operand1620 * @param {mat3} b the second operand1621 * @returns {mat3} out1622 */1623 function subtract$2(out, a, b) {1624 out[0] = a[0] - b[0];1625 out[1] = a[1] - b[1];1626 out[2] = a[2] - b[2];1627 out[3] = a[3] - b[3];1628 out[4] = a[4] - b[4];1629 out[5] = a[5] - b[5];1630 out[6] = a[6] - b[6];1631 out[7] = a[7] - b[7];1632 out[8] = a[8] - b[8];1633 return out;1634 }1635 /**1636 * Multiply each element of the matrix by a scalar.1637 *1638 * @param {mat3} out the receiving matrix1639 * @param {mat3} a the matrix to scale1640 * @param {Number} b amount to scale the matrix's elements by1641 * @returns {mat3} out1642 */1643 function multiplyScalar$2(out, a, b) {1644 out[0] = a[0] * b;1645 out[1] = a[1] * b;1646 out[2] = a[2] * b;1647 out[3] = a[3] * b;1648 out[4] = a[4] * b;1649 out[5] = a[5] * b;1650 out[6] = a[6] * b;1651 out[7] = a[7] * b;1652 out[8] = a[8] * b;1653 return out;1654 }1655 /**1656 * Adds two mat3's after multiplying each element of the second operand by a scalar value.1657 *1658 * @param {mat3} out the receiving vector1659 * @param {mat3} a the first operand1660 * @param {mat3} b the second operand1661 * @param {Number} scale the amount to scale b's elements by before adding1662 * @returns {mat3} out1663 */1664 function multiplyScalarAndAdd$2(out, a, b, scale) {1665 out[0] = a[0] + b[0] * scale;1666 out[1] = a[1] + b[1] * scale;1667 out[2] = a[2] + b[2] * scale;1668 out[3] = a[3] + b[3] * scale;1669 out[4] = a[4] + b[4] * scale;1670 out[5] = a[5] + b[5] * scale;1671 out[6] = a[6] + b[6] * scale;1672 out[7] = a[7] + b[7] * scale;1673 out[8] = a[8] + b[8] * scale;1674 return out;1675 }1676 /**1677 * Returns whether or not the matrices have exactly the same elements in the same position (when compared with ===)1678 *1679 * @param {mat3} a The first matrix.1680 * @param {mat3} b The second matrix.1681 * @returns {Boolean} True if the matrices are equal, false otherwise.1682 */1683 function exactEquals$2(a, b) {1684 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];1685 }1686 /**1687 * Returns whether or not the matrices have approximately the same elements in the same position.1688 *1689 * @param {mat3} a The first matrix.1690 * @param {mat3} b The second matrix.1691 * @returns {Boolean} True if the matrices are equal, false otherwise.1692 */1693 function equals$3(a, b) {1694 var a0 = a[0],1695 a1 = a[1],1696 a2 = a[2],1697 a3 = a[3],1698 a4 = a[4],1699 a5 = a[5],1700 a6 = a[6],1701 a7 = a[7],1702 a8 = a[8];1703 var b0 = b[0],1704 b1 = b[1],1705 b2 = b[2],1706 b3 = b[3],1707 b4 = b[4],1708 b5 = b[5],1709 b6 = b[6],1710 b7 = b[7],1711 b8 = b[8];1712 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));1713 }1714 /**1715 * Alias for {@link mat3.multiply}1716 * @function1717 */1718 var mul$2 = multiply$2;1719 /**1720 * Alias for {@link mat3.subtract}1721 * @function1722 */1723 var sub$2 = subtract$2;1724 var mat3 = /*#__PURE__*/Object.freeze({1725 create: create$2,1726 fromMat4: fromMat4,1727 clone: clone$2,1728 copy: copy$2,1729 fromValues: fromValues$2,1730 set: set$2,1731 identity: identity$2,1732 transpose: transpose$1,1733 invert: invert$2,1734 adjoint: adjoint$1,1735 determinant: determinant$2,1736 multiply: multiply$2,1737 translate: translate$1,1738 rotate: rotate$2,1739 scale: scale$2,1740 fromTranslation: fromTranslation$1,1741 fromRotation: fromRotation$2,1742 fromScaling: fromScaling$2,1743 fromMat2d: fromMat2d,1744 fromQuat: fromQuat,1745 normalFromMat4: normalFromMat4,1746 projection: projection,1747 str: str$2,1748 frob: frob$2,1749 add: add$2,1750 subtract: subtract$2,1751 multiplyScalar: multiplyScalar$2,1752 multiplyScalarAndAdd: multiplyScalarAndAdd$2,1753 exactEquals: exactEquals$2,1754 equals: equals$3,1755 mul: mul$2,1756 sub: sub$21757 });1758 /**1759 * 4x4 Matrix<br>Format: column-major, when typed out it looks like row-major<br>The matrices are being post multiplied.1760 * @module mat41761 */1762 /**1763 * Creates a new identity mat41764 *1765 * @returns {mat4} a new 4x4 matrix1766 */1767 function create$3() {1768 var out = new ARRAY_TYPE(16);1769 if (ARRAY_TYPE != Float32Array) {1770 out[1] = 0;1771 out[2] = 0;1772 out[3] = 0;1773 out[4] = 0;1774 out[6] = 0;1775 out[7] = 0;1776 out[8] = 0;1777 out[9] = 0;1778 out[11] = 0;1779 out[12] = 0;1780 out[13] = 0;1781 out[14] = 0;1782 }1783 out[0] = 1;1784 out[5] = 1;1785 out[10] = 1;1786 out[15] = 1;1787 return out;1788 }1789 /**1790 * Creates a new mat4 initialized with values from an existing matrix1791 *1792 * @param {mat4} a matrix to clone1793 * @returns {mat4} a new 4x4 matrix1794 */1795 function clone$3(a) {1796 var out = new ARRAY_TYPE(16);1797 out[0] = a[0];1798 out[1] = a[1];1799 out[2] = a[2];1800 out[3] = a[3];1801 out[4] = a[4];1802 out[5] = a[5];1803 out[6] = a[6];1804 out[7] = a[7];1805 out[8] = a[8];1806 out[9] = a[9];1807 out[10] = a[10];1808 out[11] = a[11];1809 out[12] = a[12];1810 out[13] = a[13];1811 out[14] = a[14];1812 out[15] = a[15];1813 return out;1814 }1815 /**1816 * Copy the values from one mat4 to another1817 *1818 * @param {mat4} out the receiving matrix1819 * @param {mat4} a the source matrix1820 * @returns {mat4} out1821 */1822 function copy$3(out, a) {1823 out[0] = a[0];1824 out[1] = a[1];1825 out[2] = a[2];1826 out[3] = a[3];1827 out[4] = a[4];1828 out[5] = a[5];1829 out[6] = a[6];1830 out[7] = a[7];1831 out[8] = a[8];1832 out[9] = a[9];1833 out[10] = a[10];1834 out[11] = a[11];1835 out[12] = a[12];1836 out[13] = a[13];1837 out[14] = a[14];1838 out[15] = a[15];1839 return out;1840 }1841 /**1842 * Create a new mat4 with the given values1843 *1844 * @param {Number} m00 Component in column 0, row 0 position (index 0)1845 * @param {Number} m01 Component in column 0, row 1 position (index 1)1846 * @param {Number} m02 Component in column 0, row 2 position (index 2)1847 * @param {Number} m03 Component in column 0, row 3 position (index 3)1848 * @param {Number} m10 Component in column 1, row 0 position (index 4)1849 * @param {Number} m11 Component in column 1, row 1 position (index 5)1850 * @param {Number} m12 Component in column 1, row 2 position (index 6)1851 * @param {Number} m13 Component in column 1, row 3 position (index 7)1852 * @param {Number} m20 Component in column 2, row 0 position (index 8)1853 * @param {Number} m21 Component in column 2, row 1 position (index 9)1854 * @param {Number} m22 Component in column 2, row 2 position (index 10)1855 * @param {Number} m23 Component in column 2, row 3 position (index 11)1856 * @param {Number} m30 Component in column 3, row 0 position (index 12)1857 * @param {Number} m31 Component in column 3, row 1 position (index 13)1858 * @param {Number} m32 Component in column 3, row 2 position (index 14)1859 * @param {Number} m33 Component in column 3, row 3 position (index 15)1860 * @returns {mat4} A new mat41861 */1862 function fromValues$3(m00, m01, m02, m03, m10, m11, m12, m13, m20, m21, m22, m23, m30, m31, m32, m33) {1863 var out = new ARRAY_TYPE(16);1864 out[0] = m00;1865 out[1] = m01;1866 out[2] = m02;1867 out[3] = m03;1868 out[4] = m10;1869 out[5] = m11;1870 out[6] = m12;1871 out[7] = m13;1872 out[8] = m20;1873 out[9] = m21;1874 out[10] = m22;1875 out[11] = m23;1876 out[12] = m30;1877 out[13] = m31;1878 out[14] = m32;1879 out[15] = m33;1880 return out;1881 }1882 /**1883 * Set the components of a mat4 to the given values1884 *1885 * @param {mat4} out the receiving matrix1886 * @param {Number} m00 Component in column 0, row 0 position (index 0)1887 * @param {Number} m01 Component in column 0, row 1 position (index 1)1888 * @param {Number} m02 Component in column 0, row 2 position (index 2)1889 * @param {Number} m03 Component in column 0, row 3 position (index 3)1890 * @param {Number} m10 Component in column 1, row 0 position (index 4)1891 * @param {Number} m11 Component in column 1, row 1 position (index 5)1892 * @param {Number} m12 Component in column 1, row 2 position (index 6)1893 * @param {Number} m13 Component in column 1, row 3 position (index 7)1894 * @param {Number} m20 Component in column 2, row 0 position (index 8)1895 * @param {Number} m21 Component in column 2, row 1 position (index 9)1896 * @param {Number} m22 Component in column 2, row 2 position (index 10)1897 * @param {Number} m23 Component in column 2, row 3 position (index 11)1898 * @param {Number} m30 Component in column 3, row 0 position (index 12)1899 * @param {Number} m31 Component in column 3, row 1 position (index 13)1900 * @param {Number} m32 Component in column 3, row 2 position (index 14)1901 * @param {Number} m33 Component in column 3, row 3 position (index 15)1902 * @returns {mat4} out1903 */1904 function set$3(out, m00, m01, m02, m03, m10, m11, m12, m13, m20, m21, m22, m23, m30, m31, m32, m33) {1905 out[0] = m00;1906 out[1] = m01;1907 out[2] = m02;1908 out[3] = m03;1909 out[4] = m10;1910 out[5] = m11;1911 out[6] = m12;1912 out[7] = m13;1913 out[8] = m20;1914 out[9] = m21;1915 out[10] = m22;1916 out[11] = m23;1917 out[12] = m30;1918 out[13] = m31;1919 out[14] = m32;1920 out[15] = m33;1921 return out;1922 }1923 /**1924 * Set a mat4 to the identity matrix1925 *1926 * @param {mat4} out the receiving matrix1927 * @returns {mat4} out1928 */1929 function identity$3(out) {1930 out[0] = 1;1931 out[1] = 0;1932 out[2] = 0;1933 out[3] = 0;1934 out[4] = 0;1935 out[5] = 1;1936 out[6] = 0;1937 out[7] = 0;1938 out[8] = 0;1939 out[9] = 0;1940 out[10] = 1;1941 out[11] = 0;1942 out[12] = 0;1943 out[13] = 0;1944 out[14] = 0;1945 out[15] = 1;1946 return out;1947 }1948 /**1949 * Transpose the values of a mat41950 *1951 * @param {mat4} out the receiving matrix1952 * @param {mat4} a the source matrix1953 * @returns {mat4} out1954 */1955 function transpose$2(out, a) {1956 // If we are transposing ourselves we can skip a few steps but have to cache some values1957 if (out === a) {1958 var a01 = a[1],1959 a02 = a[2],1960 a03 = a[3];1961 var a12 = a[6],1962 a13 = a[7];1963 var a23 = a[11];1964 out[1] = a[4];1965 out[2] = a[8];1966 out[3] = a[12];1967 out[4] = a01;1968 out[6] = a[9];1969 out[7] = a[13];1970 out[8] = a02;1971 out[9] = a12;1972 out[11] = a[14];1973 out[12] = a03;1974 out[13] = a13;1975 out[14] = a23;1976 } else {1977 out[0] = a[0];1978 out[1] = a[4];1979 out[2] = a[8];1980 out[3] = a[12];1981 out[4] = a[1];1982 out[5] = a[5];1983 out[6] = a[9];1984 out[7] = a[13];1985 out[8] = a[2];1986 out[9] = a[6];1987 out[10] = a[10];1988 out[11] = a[14];1989 out[12] = a[3];1990 out[13] = a[7];1991 out[14] = a[11];1992 out[15] = a[15];1993 }1994 return out;1995 }1996 /**1997 * Inverts a mat41998 *1999 * @param {mat4} out the receiving matrix2000 * @param {mat4} a the source matrix2001 * @returns {mat4} out2002 */2003 function invert$3(out, a) {2004 var a00 = a[0],2005 a01 = a[1],2006 a02 = a[2],2007 a03 = a[3];2008 var a10 = a[4],2009 a11 = a[5],2010 a12 = a[6],2011 a13 = a[7];2012 var a20 = a[8],2013 a21 = a[9],2014 a22 = a[10],2015 a23 = a[11];2016 var a30 = a[12],2017 a31 = a[13],2018 a32 = a[14],2019 a33 = a[15];2020 var b00 = a00 * a11 - a01 * a10;2021 var b01 = a00 * a12 - a02 * a10;2022 var b02 = a00 * a13 - a03 * a10;2023 var b03 = a01 * a12 - a02 * a11;2024 var b04 = a01 * a13 - a03 * a11;2025 var b05 = a02 * a13 - a03 * a12;2026 var b06 = a20 * a31 - a21 * a30;2027 var b07 = a20 * a32 - a22 * a30;2028 var b08 = a20 * a33 - a23 * a30;2029 var b09 = a21 * a32 - a22 * a31;2030 var b10 = a21 * a33 - a23 * a31;2031 var b11 = a22 * a33 - a23 * a32; // Calculate the determinant2032 var det = b00 * b11 - b01 * b10 + b02 * b09 + b03 * b08 - b04 * b07 + b05 * b06;2033 if (!det) {2034 return null;2035 }2036 det = 1.0 / det;2037 out[0] = (a11 * b11 - a12 * b10 + a13 * b09) * det;2038 out[1] = (a02 * b10 - a01 * b11 - a03 * b09) * det;2039 out[2] = (a31 * b05 - a32 * b04 + a33 * b03) * det;2040 out[3] = (a22 * b04 - a21 * b05 - a23 * b03) * det;2041 out[4] = (a12 * b08 - a10 * b11 - a13 * b07) * det;2042 out[5] = (a00 * b11 - a02 * b08 + a03 * b07) * det;2043 out[6] = (a32 * b02 - a30 * b05 - a33 * b01) * det;2044 out[7] = (a20 * b05 - a22 * b02 + a23 * b01) * det;2045 out[8] = (a10 * b10 - a11 * b08 + a13 * b06) * det;2046 out[9] = (a01 * b08 - a00 * b10 - a03 * b06) * det;2047 out[10] = (a30 * b04 - a31 * b02 + a33 * b00) * det;2048 out[11] = (a21 * b02 - a20 * b04 - a23 * b00) * det;2049 out[12] = (a11 * b07 - a10 * b09 - a12 * b06) * det;2050 out[13] = (a00 * b09 - a01 * b07 + a02 * b06) * det;2051 out[14] = (a31 * b01 - a30 * b03 - a32 * b00) * det;2052 out[15] = (a20 * b03 - a21 * b01 + a22 * b00) * det;2053 return out;2054 }2055 /**2056 * Calculates the adjugate of a mat42057 *2058 * @param {mat4} out the receiving matrix2059 * @param {mat4} a the source matrix2060 * @returns {mat4} out2061 */2062 function adjoint$2(out, a) {2063 var a00 = a[0],2064 a01 = a[1],2065 a02 = a[2],2066 a03 = a[3];2067 var a10 = a[4],2068 a11 = a[5],2069 a12 = a[6],2070 a13 = a[7];2071 var a20 = a[8],2072 a21 = a[9],2073 a22 = a[10],2074 a23 = a[11];2075 var a30 = a[12],2076 a31 = a[13],2077 a32 = a[14],2078 a33 = a[15];2079 out[0] = a11 * (a22 * a33 - a23 * a32) - a21 * (a12 * a33 - a13 * a32) + a31 * (a12 * a23 - a13 * a22);2080 out[1] = -(a01 * (a22 * a33 - a23 * a32) - a21 * (a02 * a33 - a03 * a32) + a31 * (a02 * a23 - a03 * a22));2081 out[2] = a01 * (a12 * a33 - a13 * a32) - a11 * (a02 * a33 - a03 * a32) + a31 * (a02 * a13 - a03 * a12);2082 out[3] = -(a01 * (a12 * a23 - a13 * a22) - a11 * (a02 * a23 - a03 * a22) + a21 * (a02 * a13 - a03 * a12));2083 out[4] = -(a10 * (a22 * a33 - a23 * a32) - a20 * (a12 * a33 - a13 * a32) + a30 * (a12 * a23 - a13 * a22));2084 out[5] = a00 * (a22 * a33 - a23 * a32) - a20 * (a02 * a33 - a03 * a32) + a30 * (a02 * a23 - a03 * a22);2085 out[6] = -(a00 * (a12 * a33 - a13 * a32) - a10 * (a02 * a33 - a03 * a32) + a30 * (a02 * a13 - a03 * a12));2086 out[7] = a00 * (a12 * a23 - a13 * a22) - a10 * (a02 * a23 - a03 * a22) + a20 * (a02 * a13 - a03 * a12);2087 out[8] = a10 * (a21 * a33 - a23 * a31) - a20 * (a11 * a33 - a13 * a31) + a30 * (a11 * a23 - a13 * a21);2088 out[9] = -(a00 * (a21 * a33 - a23 * a31) - a20 * (a01 * a33 - a03 * a31) + a30 * (a01 * a23 - a03 * a21));2089 out[10] = a00 * (a11 * a33 - a13 * a31) - a10 * (a01 * a33 - a03 * a31) + a30 * (a01 * a13 - a03 * a11);2090 out[11] = -(a00 * (a11 * a23 - a13 * a21) - a10 * (a01 * a23 - a03 * a21) + a20 * (a01 * a13 - a03 * a11));2091 out[12] = -(a10 * (a21 * a32 - a22 * a31) - a20 * (a11 * a32 - a12 * a31) + a30 * (a11 * a22 - a12 * a21));2092 out[13] = a00 * (a21 * a32 - a22 * a31) - a20 * (a01 * a32 - a02 * a31) + a30 * (a01 * a22 - a02 * a21);2093 out[14] = -(a00 * (a11 * a32 - a12 * a31) - a10 * (a01 * a32 - a02 * a31) + a30 * (a01 * a12 - a02 * a11));2094 out[15] = a00 * (a11 * a22 - a12 * a21) - a10 * (a01 * a22 - a02 * a21) + a20 * (a01 * a12 - a02 * a11);2095 return out;2096 }2097 /**2098 * Calculates the determinant of a mat42099 *2100 * @param {mat4} a the source matrix2101 * @returns {Number} determinant of a2102 */2103 function determinant$3(a) {2104 var a00 = a[0],2105 a01 = a[1],2106 a02 = a[2],2107 a03 = a[3];2108 var a10 = a[4],2109 a11 = a[5],2110 a12 = a[6],2111 a13 = a[7];2112 var a20 = a[8],2113 a21 = a[9],2114 a22 = a[10],2115 a23 = a[11];2116 var a30 = a[12],2117 a31 = a[13],2118 a32 = a[14],2119 a33 = a[15];2120 var b00 = a00 * a11 - a01 * a10;2121 var b01 = a00 * a12 - a02 * a10;2122 var b02 = a00 * a13 - a03 * a10;2123 var b03 = a01 * a12 - a02 * a11;2124 var b04 = a01 * a13 - a03 * a11;2125 var b05 = a02 * a13 - a03 * a12;2126 var b06 = a20 * a31 - a21 * a30;2127 var b07 = a20 * a32 - a22 * a30;2128 var b08 = a20 * a33 - a23 * a30;2129 var b09 = a21 * a32 - a22 * a31;2130 var b10 = a21 * a33 - a23 * a31;2131 var b11 = a22 * a33 - a23 * a32; // Calculate the determinant2132 return b00 * b11 - b01 * b10 + b02 * b09 + b03 * b08 - b04 * b07 + b05 * b06;2133 }2134 /**2135 * Multiplies two mat4s2136 *2137 * @param {mat4} out the receiving matrix2138 * @param {mat4} a the first operand2139 * @param {mat4} b the second operand2140 * @returns {mat4} out2141 */2142 function multiply$3(out, a, b) {2143 var a00 = a[0],2144 a01 = a[1],2145 a02 = a[2],2146 a03 = a[3];2147 var a10 = a[4],2148 a11 = a[5],2149 a12 = a[6],2150 a13 = a[7];2151 var a20 = a[8],2152 a21 = a[9],2153 a22 = a[10],2154 a23 = a[11];2155 var a30 = a[12],2156 a31 = a[13],2157 a32 = a[14],2158 a33 = a[15]; // Cache only the current line of the second matrix2159 var b0 = b[0],2160 b1 = b[1],2161 b2 = b[2],2162 b3 = b[3];2163 out[0] = b0 * a00 + b1 * a10 + b2 * a20 + b3 * a30;2164 out[1] = b0 * a01 + b1 * a11 + b2 * a21 + b3 * a31;2165 out[2] = b0 * a02 + b1 * a12 + b2 * a22 + b3 * a32;2166 out[3] = b0 * a03 + b1 * a13 + b2 * a23 + b3 * a33;2167 b0 = b[4];2168 b1 = b[5];2169 b2 = b[6];2170 b3 = b[7];2171 out[4] = b0 * a00 + b1 * a10 + b2 * a20 + b3 * a30;2172 out[5] = b0 * a01 + b1 * a11 + b2 * a21 + b3 * a31;2173 out[6] = b0 * a02 + b1 * a12 + b2 * a22 + b3 * a32;2174 out[7] = b0 * a03 + b1 * a13 + b2 * a23 + b3 * a33;2175 b0 = b[8];2176 b1 = b[9];2177 b2 = b[10];2178 b3 = b[11];2179 out[8] = b0 * a00 + b1 * a10 + b2 * a20 + b3 * a30;2180 out[9] = b0 * a01 + b1 * a11 + b2 * a21 + b3 * a31;2181 out[10] = b0 * a02 + b1 * a12 + b2 * a22 + b3 * a32;2182 out[11] = b0 * a03 + b1 * a13 + b2 * a23 + b3 * a33;2183 b0 = b[12];2184 b1 = b[13];2185 b2 = b[14];2186 b3 = b[15];2187 out[12] = b0 * a00 + b1 * a10 + b2 * a20 + b3 * a30;2188 out[13] = b0 * a01 + b1 * a11 + b2 * a21 + b3 * a31;2189 out[14] = b0 * a02 + b1 * a12 + b2 * a22 + b3 * a32;2190 out[15] = b0 * a03 + b1 * a13 + b2 * a23 + b3 * a33;2191 return out;2192 }2193 /**2194 * Translate a mat4 by the given vector2195 *2196 * @param {mat4} out the receiving matrix2197 * @param {mat4} a the matrix to translate2198 * @param {vec3} v vector to translate by2199 * @returns {mat4} out2200 */2201 function translate$2(out, a, v) {2202 var x = v[0],2203 y = v[1],2204 z = v[2];2205 var a00, a01, a02, a03;2206 var a10, a11, a12, a13;2207 var a20, a21, a22, a23;2208 if (a === out) {2209 out[12] = a[0] * x + a[4] * y + a[8] * z + a[12];2210 out[13] = a[1] * x + a[5] * y + a[9] * z + a[13];2211 out[14] = a[2] * x + a[6] * y + a[10] * z + a[14];2212 out[15] = a[3] * x + a[7] * y + a[11] * z + a[15];2213 } else {2214 a00 = a[0];2215 a01 = a[1];2216 a02 = a[2];2217 a03 = a[3];2218 a10 = a[4];2219 a11 = a[5];2220 a12 = a[6];2221 a13 = a[7];2222 a20 = a[8];2223 a21 = a[9];2224 a22 = a[10];2225 a23 = a[11];2226 out[0] = a00;2227 out[1] = a01;2228 out[2] = a02;2229 out[3] = a03;2230 out[4] = a10;2231 out[5] = a11;2232 out[6] = a12;2233 out[7] = a13;2234 out[8] = a20;2235 out[9] = a21;2236 out[10] = a22;2237 out[11] = a23;2238 out[12] = a00 * x + a10 * y + a20 * z + a[12];2239 out[13] = a01 * x + a11 * y + a21 * z + a[13];2240 out[14] = a02 * x + a12 * y + a22 * z + a[14];2241 out[15] = a03 * x + a13 * y + a23 * z + a[15];2242 }2243 return out;2244 }2245 /**2246 * Scales the mat4 by the dimensions in the given vec3 not using vectorization2247 *2248 * @param {mat4} out the receiving matrix2249 * @param {mat4} a the matrix to scale2250 * @param {vec3} v the vec3 to scale the matrix by2251 * @returns {mat4} out2252 **/2253 function scale$3(out, a, v) {2254 var x = v[0],2255 y = v[1],2256 z = v[2];2257 out[0] = a[0] * x;2258 out[1] = a[1] * x;2259 out[2] = a[2] * x;2260 out[3] = a[3] * x;2261 out[4] = a[4] * y;2262 out[5] = a[5] * y;2263 out[6] = a[6] * y;2264 out[7] = a[7] * y;2265 out[8] = a[8] * z;2266 out[9] = a[9] * z;2267 out[10] = a[10] * z;2268 out[11] = a[11] * z;2269 out[12] = a[12];2270 out[13] = a[13];2271 out[14] = a[14];2272 out[15] = a[15];2273 return out;2274 }2275 /**2276 * Rotates a mat4 by the given angle around the given axis2277 *2278 * @param {mat4} out the receiving matrix2279 * @param {mat4} a the matrix to rotate2280 * @param {Number} rad the angle to rotate the matrix by2281 * @param {vec3} axis the axis to rotate around2282 * @returns {mat4} out2283 */2284 function rotate$3(out, a, rad, axis) {2285 var x = axis[0],2286 y = axis[1],2287 z = axis[2];2288 var len = Math.hypot(x, y, z);2289 var s, c, t;2290 var a00, a01, a02, a03;2291 var a10, a11, a12, a13;2292 var a20, a21, a22, a23;2293 var b00, b01, b02;2294 var b10, b11, b12;2295 var b20, b21, b22;2296 if (len < EPSILON) {2297 return null;2298 }2299 len = 1 / len;2300 x *= len;2301 y *= len;2302 z *= len;2303 s = Math.sin(rad);2304 c = Math.cos(rad);2305 t = 1 - c;2306 a00 = a[0];2307 a01 = a[1];2308 a02 = a[2];2309 a03 = a[3];2310 a10 = a[4];2311 a11 = a[5];2312 a12 = a[6];2313 a13 = a[7];2314 a20 = a[8];2315 a21 = a[9];2316 a22 = a[10];2317 a23 = a[11]; // Construct the elements of the rotation matrix2318 b00 = x * x * t + c;2319 b01 = y * x * t + z * s;2320 b02 = z * x * t - y * s;2321 b10 = x * y * t - z * s;2322 b11 = y * y * t + c;2323 b12 = z * y * t + x * s;2324 b20 = x * z * t + y * s;2325 b21 = y * z * t - x * s;2326 b22 = z * z * t + c; // Perform rotation-specific matrix multiplication2327 out[0] = a00 * b00 + a10 * b01 + a20 * b02;2328 out[1] = a01 * b00 + a11 * b01 + a21 * b02;2329 out[2] = a02 * b00 + a12 * b01 + a22 * b02;2330 out[3] = a03 * b00 + a13 * b01 + a23 * b02;2331 out[4] = a00 * b10 + a10 * b11 + a20 * b12;2332 out[5] = a01 * b10 + a11 * b11 + a21 * b12;2333 out[6] = a02 * b10 + a12 * b11 + a22 * b12;2334 out[7] = a03 * b10 + a13 * b11 + a23 * b12;2335 out[8] = a00 * b20 + a10 * b21 + a20 * b22;2336 out[9] = a01 * b20 + a11 * b21 + a21 * b22;2337 out[10] = a02 * b20 + a12 * b21 + a22 * b22;2338 out[11] = a03 * b20 + a13 * b21 + a23 * b22;2339 if (a !== out) {2340 // If the source and destination differ, copy the unchanged last row2341 out[12] = a[12];2342 out[13] = a[13];2343 out[14] = a[14];2344 out[15] = a[15];2345 }2346 return out;2347 }2348 /**2349 * Rotates a matrix by the given angle around the X axis2350 *2351 * @param {mat4} out the receiving matrix2352 * @param {mat4} a the matrix to rotate2353 * @param {Number} rad the angle to rotate the matrix by2354 * @returns {mat4} out2355 */2356 function rotateX(out, a, rad) {2357 var s = Math.sin(rad);2358 var c = Math.cos(rad);2359 var a10 = a[4];2360 var a11 = a[5];2361 var a12 = a[6];2362 var a13 = a[7];2363 var a20 = a[8];2364 var a21 = a[9];2365 var a22 = a[10];2366 var a23 = a[11];2367 if (a !== out) {2368 // If the source and destination differ, copy the unchanged rows2369 out[0] = a[0];2370 out[1] = a[1];2371 out[2] = a[2];2372 out[3] = a[3];2373 out[12] = a[12];2374 out[13] = a[13];2375 out[14] = a[14];2376 out[15] = a[15];2377 } // Perform axis-specific matrix multiplication2378 out[4] = a10 * c + a20 * s;2379 out[5] = a11 * c + a21 * s;2380 out[6] = a12 * c + a22 * s;2381 out[7] = a13 * c + a23 * s;2382 out[8] = a20 * c - a10 * s;2383 out[9] = a21 * c - a11 * s;2384 out[10] = a22 * c - a12 * s;2385 out[11] = a23 * c - a13 * s;2386 return out;2387 }2388 /**2389 * Rotates a matrix by the given angle around the Y axis2390 *2391 * @param {mat4} out the receiving matrix2392 * @param {mat4} a the matrix to rotate2393 * @param {Number} rad the angle to rotate the matrix by2394 * @returns {mat4} out2395 */2396 function rotateY(out, a, rad) {2397 var s = Math.sin(rad);2398 var c = Math.cos(rad);2399 var a00 = a[0];2400 var a01 = a[1];2401 var a02 = a[2];2402 var a03 = a[3];2403 var a20 = a[8];2404 var a21 = a[9];2405 var a22 = a[10];2406 var a23 = a[11];2407 if (a !== out) {2408 // If the source and destination differ, copy the unchanged rows2409 out[4] = a[4];2410 out[5] = a[5];2411 out[6] = a[6];2412 out[7] = a[7];2413 out[12] = a[12];2414 out[13] = a[13];2415 out[14] = a[14];2416 out[15] = a[15];2417 } // Perform axis-specific matrix multiplication2418 out[0] = a00 * c - a20 * s;2419 out[1] = a01 * c - a21 * s;2420 out[2] = a02 * c - a22 * s;2421 out[3] = a03 * c - a23 * s;2422 out[8] = a00 * s + a20 * c;2423 out[9] = a01 * s + a21 * c;2424 out[10] = a02 * s + a22 * c;2425 out[11] = a03 * s + a23 * c;2426 return out;2427 }2428 /**2429 * Rotates a matrix by the given angle around the Z axis2430 *2431 * @param {mat4} out the receiving matrix2432 * @param {mat4} a the matrix to rotate2433 * @param {Number} rad the angle to rotate the matrix by2434 * @returns {mat4} out2435 */2436 function rotateZ(out, a, rad) {2437 var s = Math.sin(rad);2438 var c = Math.cos(rad);2439 var a00 = a[0];2440 var a01 = a[1];2441 var a02 = a[2];2442 var a03 = a[3];2443 var a10 = a[4];2444 var a11 = a[5];2445 var a12 = a[6];2446 var a13 = a[7];2447 if (a !== out) {2448 // If the source and destination differ, copy the unchanged last row2449 out[8] = a[8];2450 out[9] = a[9];2451 out[10] = a[10];2452 out[11] = a[11];2453 out[12] = a[12];2454 out[13] = a[13];2455 out[14] = a[14];2456 out[15] = a[15];2457 } // Perform axis-specific matrix multiplication2458 out[0] = a00 * c + a10 * s;2459 out[1] = a01 * c + a11 * s;2460 out[2] = a02 * c + a12 * s;2461 out[3] = a03 * c + a13 * s;2462 out[4] = a10 * c - a00 * s;2463 out[5] = a11 * c - a01 * s;2464 out[6] = a12 * c - a02 * s;2465 out[7] = a13 * c - a03 * s;2466 return out;2467 }2468 /**2469 * Creates a matrix from a vector translation2470 * This is equivalent to (but much faster than):2471 *2472 * mat4.identity(dest);2473 * mat4.translate(dest, dest, vec);2474 *2475 * @param {mat4} out mat4 receiving operation result2476 * @param {vec3} v Translation vector2477 * @returns {mat4} out2478 */2479 function fromTranslation$2(out, v) {2480 out[0] = 1;2481 out[1] = 0;2482 out[2] = 0;2483 out[3] = 0;2484 out[4] = 0;2485 out[5] = 1;2486 out[6] = 0;2487 out[7] = 0;2488 out[8] = 0;2489 out[9] = 0;2490 out[10] = 1;2491 out[11] = 0;2492 out[12] = v[0];2493 out[13] = v[1];2494 out[14] = v[2];2495 out[15] = 1;2496 return out;2497 }2498 /**2499 * Creates a matrix from a vector scaling2500 * This is equivalent to (but much faster than):2501 *2502 * mat4.identity(dest);2503 * mat4.scale(dest, dest, vec);2504 *2505 * @param {mat4} out mat4 receiving operation result2506 * @param {vec3} v Scaling vector2507 * @returns {mat4} out2508 */2509 function fromScaling$3(out, v) {2510 out[0] = v[0];2511 out[1] = 0;2512 out[2] = 0;2513 out[3] = 0;2514 out[4] = 0;2515 out[5] = v[1];2516 out[6] = 0;2517 out[7] = 0;2518 out[8] = 0;2519 out[9] = 0;2520 out[10] = v[2];2521 out[11] = 0;2522 out[12] = 0;2523 out[13] = 0;2524 out[14] = 0;2525 out[15] = 1;2526 return out;2527 }2528 /**2529 * Creates a matrix from a given angle around a given axis2530 * This is equivalent to (but much faster than):2531 *2532 * mat4.identity(dest);2533 * mat4.rotate(dest, dest, rad, axis);2534 *2535 * @param {mat4} out mat4 receiving operation result2536 * @param {Number} rad the angle to rotate the matrix by2537 * @param {vec3} axis the axis to rotate around2538 * @returns {mat4} out2539 */2540 function fromRotation$3(out, rad, axis) {2541 var x = axis[0],2542 y = axis[1],2543 z = axis[2];2544 var len = Math.hypot(x, y, z);2545 var s, c, t;2546 if (len < EPSILON) {2547 return null;2548 }2549 len = 1 / len;2550 x *= len;2551 y *= len;2552 z *= len;2553 s = Math.sin(rad);2554 c = Math.cos(rad);2555 t = 1 - c; // Perform rotation-specific matrix multiplication2556 out[0] = x * x * t + c;2557 out[1] = y * x * t + z * s;2558 out[2] = z * x * t - y * s;2559 out[3] = 0;2560 out[4] = x * y * t - z * s;2561 out[5] = y * y * t + c;2562 out[6] = z * y * t + x * s;2563 out[7] = 0;2564 out[8] = x * z * t + y * s;2565 out[9] = y * z * t - x * s;2566 out[10] = z * z * t + c;2567 out[11] = 0;2568 out[12] = 0;2569 out[13] = 0;2570 out[14] = 0;2571 out[15] = 1;2572 return out;2573 }2574 /**2575 * Creates a matrix from the given angle around the X axis2576 * This is equivalent to (but much faster than):2577 *2578 * mat4.identity(dest);2579 * mat4.rotateX(dest, dest, rad);2580 *2581 * @param {mat4} out mat4 receiving operation result2582 * @param {Number} rad the angle to rotate the matrix by2583 * @returns {mat4} out2584 */2585 function fromXRotation(out, rad) {2586 var s = Math.sin(rad);2587 var c = Math.cos(rad); // Perform axis-specific matrix multiplication2588 out[0] = 1;2589 out[1] = 0;2590 out[2] = 0;2591 out[3] = 0;2592 out[4] = 0;2593 out[5] = c;2594 out[6] = s;2595 out[7] = 0;2596 out[8] = 0;2597 out[9] = -s;2598 out[10] = c;2599 out[11] = 0;2600 out[12] = 0;2601 out[13] = 0;2602 out[14] = 0;2603 out[15] = 1;2604 return out;2605 }2606 /**2607 * Creates a matrix from the given angle around the Y axis2608 * This is equivalent to (but much faster than):2609 *2610 * mat4.identity(dest);2611 * mat4.rotateY(dest, dest, rad);2612 *2613 * @param {mat4} out mat4 receiving operation result2614 * @param {Number} rad the angle to rotate the matrix by2615 * @returns {mat4} out2616 */2617 function fromYRotation(out, rad) {2618 var s = Math.sin(rad);2619 var c = Math.cos(rad); // Perform axis-specific matrix multiplication2620 out[0] = c;2621 out[1] = 0;2622 out[2] = -s;2623 out[3] = 0;2624 out[4] = 0;2625 out[5] = 1;2626 out[6] = 0;2627 out[7] = 0;2628 out[8] = s;2629 out[9] = 0;2630 out[10] = c;2631 out[11] = 0;2632 out[12] = 0;2633 out[13] = 0;2634 out[14] = 0;2635 out[15] = 1;2636 return out;2637 }2638 /**2639 * Creates a matrix from the given angle around the Z axis2640 * This is equivalent to (but much faster than):2641 *2642 * mat4.identity(dest);2643 * mat4.rotateZ(dest, dest, rad);2644 *2645 * @param {mat4} out mat4 receiving operation result2646 * @param {Number} rad the angle to rotate the matrix by2647 * @returns {mat4} out2648 */2649 function fromZRotation(out, rad) {2650 var s = Math.sin(rad);2651 var c = Math.cos(rad); // Perform axis-specific matrix multiplication2652 out[0] = c;2653 out[1] = s;2654 out[2] = 0;2655 out[3] = 0;2656 out[4] = -s;2657 out[5] = c;2658 out[6] = 0;2659 out[7] = 0;2660 out[8] = 0;2661 out[9] = 0;2662 out[10] = 1;2663 out[11] = 0;2664 out[12] = 0;2665 out[13] = 0;2666 out[14] = 0;2667 out[15] = 1;2668 return out;2669 }2670 /**2671 * Creates a matrix from a quaternion rotation and vector translation2672 * This is equivalent to (but much faster than):2673 *2674 * mat4.identity(dest);2675 * mat4.translate(dest, vec);2676 * let quatMat = mat4.create();2677 * quat4.toMat4(quat, quatMat);2678 * mat4.multiply(dest, quatMat);2679 *2680 * @param {mat4} out mat4 receiving operation result2681 * @param {quat4} q Rotation quaternion2682 * @param {vec3} v Translation vector2683 * @returns {mat4} out2684 */2685 function fromRotationTranslation(out, q, v) {2686 // Quaternion math2687 var x = q[0],2688 y = q[1],2689 z = q[2],2690 w = q[3];2691 var x2 = x + x;2692 var y2 = y + y;2693 var z2 = z + z;2694 var xx = x * x2;2695 var xy = x * y2;2696 var xz = x * z2;2697 var yy = y * y2;2698 var yz = y * z2;2699 var zz = z * z2;2700 var wx = w * x2;2701 var wy = w * y2;2702 var wz = w * z2;2703 out[0] = 1 - (yy + zz);2704 out[1] = xy + wz;2705 out[2] = xz - wy;2706 out[3] = 0;2707 out[4] = xy - wz;2708 out[5] = 1 - (xx + zz);2709 out[6] = yz + wx;2710 out[7] = 0;2711 out[8] = xz + wy;2712 out[9] = yz - wx;2713 out[10] = 1 - (xx + yy);2714 out[11] = 0;2715 out[12] = v[0];2716 out[13] = v[1];2717 out[14] = v[2];2718 out[15] = 1;2719 return out;2720 }2721 /**2722 * Creates a new mat4 from a dual quat.2723 *2724 * @param {mat4} out Matrix2725 * @param {quat2} a Dual Quaternion2726 * @returns {mat4} mat4 receiving operation result2727 */2728 function fromQuat2(out, a) {2729 var translation = new ARRAY_TYPE(3);2730 var bx = -a[0],2731 by = -a[1],2732 bz = -a[2],2733 bw = a[3],2734 ax = a[4],2735 ay = a[5],2736 az = a[6],2737 aw = a[7];2738 var magnitude = bx * bx + by * by + bz * bz + bw * bw; //Only scale if it makes sense2739 if (magnitude > 0) {2740 translation[0] = (ax * bw + aw * bx + ay * bz - az * by) * 2 / magnitude;2741 translation[1] = (ay * bw + aw * by + az * bx - ax * bz) * 2 / magnitude;2742 translation[2] = (az * bw + aw * bz + ax * by - ay * bx) * 2 / magnitude;2743 } else {2744 translation[0] = (ax * bw + aw * bx + ay * bz - az * by) * 2;2745 translation[1] = (ay * bw + aw * by + az * bx - ax * bz) * 2;2746 translation[2] = (az * bw + aw * bz + ax * by - ay * bx) * 2;2747 }2748 fromRotationTranslation(out, a, translation);2749 return out;2750 }2751 /**2752 * Returns the translation vector component of a transformation2753 * matrix. If a matrix is built with fromRotationTranslation,2754 * the returned vector will be the same as the translation vector2755 * originally supplied.2756 * @param {vec3} out Vector to receive translation component2757 * @param {mat4} mat Matrix to be decomposed (input)2758 * @return {vec3} out2759 */2760 function getTranslation(out, mat) {2761 out[0] = mat[12];2762 out[1] = mat[13];2763 out[2] = mat[14];2764 return out;2765 }2766 /**2767 * Returns the scaling factor component of a transformation2768 * matrix. If a matrix is built with fromRotationTranslationScale2769 * with a normalized Quaternion paramter, the returned vector will be2770 * the same as the scaling vector2771 * originally supplied.2772 * @param {vec3} out Vector to receive scaling factor component2773 * @param {mat4} mat Matrix to be decomposed (input)2774 * @return {vec3} out2775 */2776 function getScaling(out, mat) {2777 var m11 = mat[0];2778 var m12 = mat[1];2779 var m13 = mat[2];2780 var m21 = mat[4];2781 var m22 = mat[5];2782 var m23 = mat[6];2783 var m31 = mat[8];2784 var m32 = mat[9];2785 var m33 = mat[10];2786 out[0] = Math.hypot(m11, m12, m13);2787 out[1] = Math.hypot(m21, m22, m23);2788 out[2] = Math.hypot(m31, m32, m33);2789 return out;2790 }2791 /**2792 * Returns a quaternion representing the rotational component2793 * of a transformation matrix. If a matrix is built with2794 * fromRotationTranslation, the returned quaternion will be the2795 * same as the quaternion originally supplied.2796 * @param {quat} out Quaternion to receive the rotation component2797 * @param {mat4} mat Matrix to be decomposed (input)2798 * @return {quat} out2799 */2800 function getRotation(out, mat) {2801 var scaling = new ARRAY_TYPE(3);2802 getScaling(scaling, mat);2803 var is1 = 1 / scaling[0];2804 var is2 = 1 / scaling[1];2805 var is3 = 1 / scaling[2];2806 var sm11 = mat[0] * is1;2807 var sm12 = mat[1] * is2;2808 var sm13 = mat[2] * is3;2809 var sm21 = mat[4] * is1;2810 var sm22 = mat[5] * is2;2811 var sm23 = mat[6] * is3;2812 var sm31 = mat[8] * is1;2813 var sm32 = mat[9] * is2;2814 var sm33 = mat[10] * is3;2815 var trace = sm11 + sm22 + sm33;2816 var S = 0;2817 if (trace > 0) {2818 S = Math.sqrt(trace + 1.0) * 2;2819 out[3] = 0.25 * S;2820 out[0] = (sm23 - sm32) / S;2821 out[1] = (sm31 - sm13) / S;2822 out[2] = (sm12 - sm21) / S;2823 } else if (sm11 > sm22 && sm11 > sm33) {2824 S = Math.sqrt(1.0 + sm11 - sm22 - sm33) * 2;2825 out[3] = (sm23 - sm32) / S;2826 out[0] = 0.25 * S;2827 out[1] = (sm12 + sm21) / S;2828 out[2] = (sm31 + sm13) / S;2829 } else if (sm22 > sm33) {2830 S = Math.sqrt(1.0 + sm22 - sm11 - sm33) * 2;2831 out[3] = (sm31 - sm13) / S;2832 out[0] = (sm12 + sm21) / S;2833 out[1] = 0.25 * S;2834 out[2] = (sm23 + sm32) / S;2835 } else {2836 S = Math.sqrt(1.0 + sm33 - sm11 - sm22) * 2;2837 out[3] = (sm12 - sm21) / S;2838 out[0] = (sm31 + sm13) / S;2839 out[1] = (sm23 + sm32) / S;2840 out[2] = 0.25 * S;2841 }2842 return out;2843 }2844 /**2845 * Creates a matrix from a quaternion rotation, vector translation and vector scale2846 * This is equivalent to (but much faster than):2847 *2848 * mat4.identity(dest);2849 * mat4.translate(dest, vec);2850 * let quatMat = mat4.create();2851 * quat4.toMat4(quat, quatMat);2852 * mat4.multiply(dest, quatMat);2853 * mat4.scale(dest, scale)2854 *2855 * @param {mat4} out mat4 receiving operation result2856 * @param {quat4} q Rotation quaternion2857 * @param {vec3} v Translation vector2858 * @param {vec3} s Scaling vector2859 * @returns {mat4} out2860 */2861 function fromRotationTranslationScale(out, q, v, s) {2862 // Quaternion math2863 var x = q[0],2864 y = q[1],2865 z = q[2],2866 w = q[3];2867 var x2 = x + x;2868 var y2 = y + y;2869 var z2 = z + z;2870 var xx = x * x2;2871 var xy = x * y2;2872 var xz = x * z2;2873 var yy = y * y2;2874 var yz = y * z2;2875 var zz = z * z2;2876 var wx = w * x2;2877 var wy = w * y2;2878 var wz = w * z2;2879 var sx = s[0];2880 var sy = s[1];2881 var sz = s[2];2882 out[0] = (1 - (yy + zz)) * sx;2883 out[1] = (xy + wz) * sx;2884 out[2] = (xz - wy) * sx;2885 out[3] = 0;2886 out[4] = (xy - wz) * sy;2887 out[5] = (1 - (xx + zz)) * sy;2888 out[6] = (yz + wx) * sy;2889 out[7] = 0;2890 out[8] = (xz + wy) * sz;2891 out[9] = (yz - wx) * sz;2892 out[10] = (1 - (xx + yy)) * sz;2893 out[11] = 0;2894 out[12] = v[0];2895 out[13] = v[1];2896 out[14] = v[2];2897 out[15] = 1;2898 return out;2899 }2900 /**2901 * Creates a matrix from a quaternion rotation, vector translation and vector scale, rotating and scaling around the given origin2902 * This is equivalent to (but much faster than):2903 *2904 * mat4.identity(dest);2905 * mat4.translate(dest, vec);2906 * mat4.translate(dest, origin);2907 * let quatMat = mat4.create();2908 * quat4.toMat4(quat, quatMat);2909 * mat4.multiply(dest, quatMat);2910 * mat4.scale(dest, scale)2911 * mat4.translate(dest, negativeOrigin);2912 *2913 * @param {mat4} out mat4 receiving operation result2914 * @param {quat4} q Rotation quaternion2915 * @param {vec3} v Translation vector2916 * @param {vec3} s Scaling vector2917 * @param {vec3} o The origin vector around which to scale and rotate2918 * @returns {mat4} out2919 */2920 function fromRotationTranslationScaleOrigin(out, q, v, s, o) {2921 // Quaternion math2922 var x = q[0],2923 y = q[1],2924 z = q[2],2925 w = q[3];2926 var x2 = x + x;2927 var y2 = y + y;2928 var z2 = z + z;2929 var xx = x * x2;2930 var xy = x * y2;2931 var xz = x * z2;2932 var yy = y * y2;2933 var yz = y * z2;2934 var zz = z * z2;2935 var wx = w * x2;2936 var wy = w * y2;2937 var wz = w * z2;2938 var sx = s[0];2939 var sy = s[1];2940 var sz = s[2];2941 var ox = o[0];2942 var oy = o[1];2943 var oz = o[2];2944 var out0 = (1 - (yy + zz)) * sx;2945 var out1 = (xy + wz) * sx;2946 var out2 = (xz - wy) * sx;2947 var out4 = (xy - wz) * sy;2948 var out5 = (1 - (xx + zz)) * sy;2949 var out6 = (yz + wx) * sy;2950 var out8 = (xz + wy) * sz;2951 var out9 = (yz - wx) * sz;2952 var out10 = (1 - (xx + yy)) * sz;2953 out[0] = out0;2954 out[1] = out1;2955 out[2] = out2;2956 out[3] = 0;2957 out[4] = out4;2958 out[5] = out5;2959 out[6] = out6;2960 out[7] = 0;2961 out[8] = out8;2962 out[9] = out9;2963 out[10] = out10;2964 out[11] = 0;2965 out[12] = v[0] + ox - (out0 * ox + out4 * oy + out8 * oz);2966 out[13] = v[1] + oy - (out1 * ox + out5 * oy + out9 * oz);2967 out[14] = v[2] + oz - (out2 * ox + out6 * oy + out10 * oz);2968 out[15] = 1;2969 return out;2970 }2971 /**2972 * Calculates a 4x4 matrix from the given quaternion2973 *2974 * @param {mat4} out mat4 receiving operation result2975 * @param {quat} q Quaternion to create matrix from2976 *2977 * @returns {mat4} out2978 */2979 function fromQuat$1(out, q) {2980 var x = q[0],2981 y = q[1],2982 z = q[2],2983 w = q[3];2984 var x2 = x + x;2985 var y2 = y + y;2986 var z2 = z + z;2987 var xx = x * x2;2988 var yx = y * x2;2989 var yy = y * y2;2990 var zx = z * x2;2991 var zy = z * y2;2992 var zz = z * z2;2993 var wx = w * x2;2994 var wy = w * y2;2995 var wz = w * z2;2996 out[0] = 1 - yy - zz;2997 out[1] = yx + wz;2998 out[2] = zx - wy;2999 out[3] = 0;3000 out[4] = yx - wz;3001 out[5] = 1 - xx - zz;3002 out[6] = zy + wx;3003 out[7] = 0;3004 out[8] = zx + wy;3005 out[9] = zy - wx;3006 out[10] = 1 - xx - yy;3007 out[11] = 0;3008 out[12] = 0;3009 out[13] = 0;3010 out[14] = 0;3011 out[15] = 1;3012 return out;3013 }3014 /**3015 * Generates a frustum matrix with the given bounds3016 *3017 * @param {mat4} out mat4 frustum matrix will be written into3018 * @param {Number} left Left bound of the frustum3019 * @param {Number} right Right bound of the frustum3020 * @param {Number} bottom Bottom bound of the frustum3021 * @param {Number} top Top bound of the frustum3022 * @param {Number} near Near bound of the frustum3023 * @param {Number} far Far bound of the frustum3024 * @returns {mat4} out3025 */3026 function frustum(out, left, right, bottom, top, near, far) {3027 var rl = 1 / (right - left);3028 var tb = 1 / (top - bottom);3029 var nf = 1 / (near - far);3030 out[0] = near * 2 * rl;3031 out[1] = 0;3032 out[2] = 0;3033 out[3] = 0;3034 out[4] = 0;3035 out[5] = near * 2 * tb;3036 out[6] = 0;3037 out[7] = 0;3038 out[8] = (right + left) * rl;3039 out[9] = (top + bottom) * tb;3040 out[10] = (far + near) * nf;3041 out[11] = -1;3042 out[12] = 0;3043 out[13] = 0;3044 out[14] = far * near * 2 * nf;3045 out[15] = 0;3046 return out;3047 }3048 /**3049 * Generates a perspective projection matrix with the given bounds.3050 * Passing null/undefined/no value for far will generate infinite projection matrix.3051 *3052 * @param {mat4} out mat4 frustum matrix will be written into3053 * @param {number} fovy Vertical field of view in radians3054 * @param {number} aspect Aspect ratio. typically viewport width/height3055 * @param {number} near Near bound of the frustum3056 * @param {number} far Far bound of the frustum, can be null or Infinity3057 * @returns {mat4} out3058 */3059 function perspective(out, fovy, aspect, near, far) {3060 var f = 1.0 / Math.tan(fovy / 2),3061 nf;3062 out[0] = f / aspect;3063 out[1] = 0;3064 out[2] = 0;3065 out[3] = 0;3066 out[4] = 0;3067 out[5] = f;3068 out[6] = 0;3069 out[7] = 0;3070 out[8] = 0;3071 out[9] = 0;3072 out[11] = -1;3073 out[12] = 0;3074 out[13] = 0;3075 out[15] = 0;3076 if (far != null && far !== Infinity) {3077 nf = 1 / (near - far);3078 out[10] = (far + near) * nf;3079 out[14] = 2 * far * near * nf;3080 } else {3081 out[10] = -1;3082 out[14] = -2 * near;3083 }3084 return out;3085 }3086 /**3087 * Generates a perspective projection matrix with the given field of view.3088 * This is primarily useful for generating projection matrices to be used3089 * with the still experiemental WebVR API.3090 *3091 * @param {mat4} out mat4 frustum matrix will be written into3092 * @param {Object} fov Object containing the following values: upDegrees, downDegrees, leftDegrees, rightDegrees3093 * @param {number} near Near bound of the frustum3094 * @param {number} far Far bound of the frustum3095 * @returns {mat4} out3096 */3097 function perspectiveFromFieldOfView(out, fov, near, far) {3098 var upTan = Math.tan(fov.upDegrees * Math.PI / 180.0);3099 var downTan = Math.tan(fov.downDegrees * Math.PI / 180.0);3100 var leftTan = Math.tan(fov.leftDegrees * Math.PI / 180.0);3101 var rightTan = Math.tan(fov.rightDegrees * Math.PI / 180.0);3102 var xScale = 2.0 / (leftTan + rightTan);3103 var yScale = 2.0 / (upTan + downTan);3104 out[0] = xScale;3105 out[1] = 0.0;3106 out[2] = 0.0;3107 out[3] = 0.0;3108 out[4] = 0.0;3109 out[5] = yScale;3110 out[6] = 0.0;3111 out[7] = 0.0;3112 out[8] = -((leftTan - rightTan) * xScale * 0.5);3113 out[9] = (upTan - downTan) * yScale * 0.5;3114 out[10] = far / (near - far);3115 out[11] = -1.0;3116 out[12] = 0.0;3117 out[13] = 0.0;3118 out[14] = far * near / (near - far);3119 out[15] = 0.0;3120 return out;3121 }3122 /**3123 * Generates a orthogonal projection matrix with the given bounds3124 *3125 * @param {mat4} out mat4 frustum matrix will be written into3126 * @param {number} left Left bound of the frustum3127 * @param {number} right Right bound of the frustum3128 * @param {number} bottom Bottom bound of the frustum3129 * @param {number} top Top bound of the frustum3130 * @param {number} near Near bound of the frustum3131 * @param {number} far Far bound of the frustum3132 * @returns {mat4} out3133 */3134 function ortho(out, left, right, bottom, top, near, far) {3135 var lr = 1 / (left - right);3136 var bt = 1 / (bottom - top);3137 var nf = 1 / (near - far);3138 out[0] = -2 * lr;3139 out[1] = 0;3140 out[2] = 0;3141 out[3] = 0;3142 out[4] = 0;3143 out[5] = -2 * bt;3144 out[6] = 0;3145 out[7] = 0;3146 out[8] = 0;3147 out[9] = 0;3148 out[10] = 2 * nf;3149 out[11] = 0;3150 out[12] = (left + right) * lr;3151 out[13] = (top + bottom) * bt;3152 out[14] = (far + near) * nf;3153 out[15] = 1;3154 return out;3155 }3156 /**3157 * Generates a look-at matrix with the given eye position, focal point, and up axis.3158 * If you want a matrix that actually makes an object look at another object, you should use targetTo instead.3159 *3160 * @param {mat4} out mat4 frustum matrix will be written into3161 * @param {vec3} eye Position of the viewer3162 * @param {vec3} center Point the viewer is looking at3163 * @param {vec3} up vec3 pointing up3164 * @returns {mat4} out3165 */3166 function lookAt(out, eye, center, up) {3167 var x0, x1, x2, y0, y1, y2, z0, z1, z2, len;3168 var eyex = eye[0];3169 var eyey = eye[1];3170 var eyez = eye[2];3171 var upx = up[0];3172 var upy = up[1];3173 var upz = up[2];3174 var centerx = center[0];3175 var centery = center[1];3176 var centerz = center[2];3177 if (Math.abs(eyex - centerx) < EPSILON && Math.abs(eyey - centery) < EPSILON && Math.abs(eyez - centerz) < EPSILON) {3178 return identity$3(out);3179 }3180 z0 = eyex - centerx;3181 z1 = eyey - centery;3182 z2 = eyez - centerz;3183 len = 1 / Math.hypot(z0, z1, z2);3184 z0 *= len;3185 z1 *= len;3186 z2 *= len;3187 x0 = upy * z2 - upz * z1;3188 x1 = upz * z0 - upx * z2;3189 x2 = upx * z1 - upy * z0;3190 len = Math.hypot(x0, x1, x2);3191 if (!len) {3192 x0 = 0;3193 x1 = 0;3194 x2 = 0;3195 } else {3196 len = 1 / len;3197 x0 *= len;3198 x1 *= len;3199 x2 *= len;3200 }3201 y0 = z1 * x2 - z2 * x1;3202 y1 = z2 * x0 - z0 * x2;3203 y2 = z0 * x1 - z1 * x0;3204 len = Math.hypot(y0, y1, y2);3205 if (!len) {3206 y0 = 0;3207 y1 = 0;3208 y2 = 0;3209 } else {3210 len = 1 / len;3211 y0 *= len;3212 y1 *= len;3213 y2 *= len;3214 }3215 out[0] = x0;3216 out[1] = y0;3217 out[2] = z0;3218 out[3] = 0;3219 out[4] = x1;3220 out[5] = y1;3221 out[6] = z1;3222 out[7] = 0;3223 out[8] = x2;3224 out[9] = y2;3225 out[10] = z2;3226 out[11] = 0;3227 out[12] = -(x0 * eyex + x1 * eyey + x2 * eyez);3228 out[13] = -(y0 * eyex + y1 * eyey + y2 * eyez);3229 out[14] = -(z0 * eyex + z1 * eyey + z2 * eyez);3230 out[15] = 1;3231 return out;3232 }3233 /**3234 * Generates a matrix that makes something look at something else.3235 *3236 * @param {mat4} out mat4 frustum matrix will be written into3237 * @param {vec3} eye Position of the viewer3238 * @param {vec3} center Point the viewer is looking at3239 * @param {vec3} up vec3 pointing up3240 * @returns {mat4} out3241 */3242 function targetTo(out, eye, target, up) {3243 var eyex = eye[0],3244 eyey = eye[1],3245 eyez = eye[2],3246 upx = up[0],3247 upy = up[1],3248 upz = up[2];3249 var z0 = eyex - target[0],3250 z1 = eyey - target[1],3251 z2 = eyez - target[2];3252 var len = z0 * z0 + z1 * z1 + z2 * z2;3253 if (len > 0) {3254 len = 1 / Math.sqrt(len);3255 z0 *= len;3256 z1 *= len;3257 z2 *= len;3258 }3259 var x0 = upy * z2 - upz * z1,3260 x1 = upz * z0 - upx * z2,3261 x2 = upx * z1 - upy * z0;3262 len = x0 * x0 + x1 * x1 + x2 * x2;3263 if (len > 0) {3264 len = 1 / Math.sqrt(len);3265 x0 *= len;3266 x1 *= len;3267 x2 *= len;3268 }3269 out[0] = x0;3270 out[1] = x1;3271 out[2] = x2;3272 out[3] = 0;3273 out[4] = z1 * x2 - z2 * x1;3274 out[5] = z2 * x0 - z0 * x2;3275 out[6] = z0 * x1 - z1 * x0;3276 out[7] = 0;3277 out[8] = z0;3278 out[9] = z1;3279 out[10] = z2;3280 out[11] = 0;3281 out[12] = eyex;3282 out[13] = eyey;3283 out[14] = eyez;3284 out[15] = 1;3285 return out;3286 }3287 /**3288 * Returns a string representation of a mat43289 *3290 * @param {mat4} a matrix to represent as a string3291 * @returns {String} string representation of the matrix3292 */3293 function str$3(a) {3294 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] + ')';3295 }3296 /**3297 * Returns Frobenius norm of a mat43298 *3299 * @param {mat4} a the matrix to calculate Frobenius norm of3300 * @returns {Number} Frobenius norm3301 */3302 function frob$3(a) {3303 return Math.hypot(a[0], a[1], 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]);3304 }3305 /**3306 * Adds two mat4's3307 *3308 * @param {mat4} out the receiving matrix3309 * @param {mat4} a the first operand3310 * @param {mat4} b the second operand3311 * @returns {mat4} out3312 */3313 function add$3(out, a, b) {3314 out[0] = a[0] + b[0];3315 out[1] = a[1] + b[1];3316 out[2] = a[2] + b[2];3317 out[3] = a[3] + b[3];3318 out[4] = a[4] + b[4];3319 out[5] = a[5] + b[5];3320 out[6] = a[6] + b[6];3321 out[7] = a[7] + b[7];3322 out[8] = a[8] + b[8];3323 out[9] = a[9] + b[9];3324 out[10] = a[10] + b[10];3325 out[11] = a[11] + b[11];3326 out[12] = a[12] + b[12];3327 out[13] = a[13] + b[13];3328 out[14] = a[14] + b[14];3329 out[15] = a[15] + b[15];3330 return out;3331 }3332 /**3333 * Subtracts matrix b from matrix a3334 *3335 * @param {mat4} out the receiving matrix3336 * @param {mat4} a the first operand3337 * @param {mat4} b the second operand3338 * @returns {mat4} out3339 */3340 function subtract$3(out, a, b) {3341 out[0] = a[0] - b[0];3342 out[1] = a[1] - b[1];3343 out[2] = a[2] - b[2];3344 out[3] = a[3] - b[3];3345 out[4] = a[4] - b[4];3346 out[5] = a[5] - b[5];3347 out[6] = a[6] - b[6];3348 out[7] = a[7] - b[7];3349 out[8] = a[8] - b[8];3350 out[9] = a[9] - b[9];3351 out[10] = a[10] - b[10];3352 out[11] = a[11] - b[11];3353 out[12] = a[12] - b[12];3354 out[13] = a[13] - b[13];3355 out[14] = a[14] - b[14];3356 out[15] = a[15] - b[15];3357 return out;3358 }3359 /**3360 * Multiply each element of the matrix by a scalar.3361 *3362 * @param {mat4} out the receiving matrix3363 * @param {mat4} a the matrix to scale3364 * @param {Number} b amount to scale the matrix's elements by3365 * @returns {mat4} out3366 */3367 function multiplyScalar$3(out, a, b) {3368 out[0] = a[0] * b;3369 out[1] = a[1] * b;3370 out[2] = a[2] * b;3371 out[3] = a[3] * b;3372 out[4] = a[4] * b;3373 out[5] = a[5] * b;3374 out[6] = a[6] * b;3375 out[7] = a[7] * b;3376 out[8] = a[8] * b;3377 out[9] = a[9] * b;3378 out[10] = a[10] * b;3379 out[11] = a[11] * b;3380 out[12] = a[12] * b;3381 out[13] = a[13] * b;3382 out[14] = a[14] * b;3383 out[15] = a[15] * b;3384 return out;3385 }3386 /**3387 * Adds two mat4's after multiplying each element of the second operand by a scalar value.3388 *3389 * @param {mat4} out the receiving vector3390 * @param {mat4} a the first operand3391 * @param {mat4} b the second operand3392 * @param {Number} scale the amount to scale b's elements by before adding3393 * @returns {mat4} out3394 */3395 function multiplyScalarAndAdd$3(out, a, b, scale) {3396 out[0] = a[0] + b[0] * scale;3397 out[1] = a[1] + b[1] * scale;3398 out[2] = a[2] + b[2] * scale;3399 out[3] = a[3] + b[3] * scale;3400 out[4] = a[4] + b[4] * scale;3401 out[5] = a[5] + b[5] * scale;3402 out[6] = a[6] + b[6] * scale;3403 out[7] = a[7] + b[7] * scale;3404 out[8] = a[8] + b[8] * scale;3405 out[9] = a[9] + b[9] * scale;3406 out[10] = a[10] + b[10] * scale;3407 out[11] = a[11] + b[11] * scale;3408 out[12] = a[12] + b[12] * scale;3409 out[13] = a[13] + b[13] * scale;3410 out[14] = a[14] + b[14] * scale;3411 out[15] = a[15] + b[15] * scale;3412 return out;3413 }3414 /**3415 * Returns whether or not the matrices have exactly the same elements in the same position (when compared with ===)3416 *3417 * @param {mat4} a The first matrix.3418 * @param {mat4} b The second matrix.3419 * @returns {Boolean} True if the matrices are equal, false otherwise.3420 */3421 function exactEquals$3(a, b) {3422 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];3423 }3424 /**3425 * Returns whether or not the matrices have approximately the same elements in the same position.3426 *3427 * @param {mat4} a The first matrix.3428 * @param {mat4} b The second matrix.3429 * @returns {Boolean} True if the matrices are equal, false otherwise.3430 */3431 function equals$4(a, b) {3432 var a0 = a[0],3433 a1 = a[1],3434 a2 = a[2],3435 a3 = a[3];3436 var a4 = a[4],3437 a5 = a[5],3438 a6 = a[6],3439 a7 = a[7];3440 var a8 = a[8],3441 a9 = a[9],3442 a10 = a[10],3443 a11 = a[11];3444 var a12 = a[12],3445 a13 = a[13],3446 a14 = a[14],3447 a15 = a[15];3448 var b0 = b[0],3449 b1 = b[1],3450 b2 = b[2],3451 b3 = b[3];3452 var b4 = b[4],3453 b5 = b[5],3454 b6 = b[6],3455 b7 = b[7];3456 var b8 = b[8],3457 b9 = b[9],3458 b10 = b[10],3459 b11 = b[11];3460 var b12 = b[12],3461 b13 = b[13],3462 b14 = b[14],3463 b15 = b[15];3464 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));3465 }3466 /**3467 * Alias for {@link mat4.multiply}3468 * @function3469 */3470 var mul$3 = multiply$3;3471 /**3472 * Alias for {@link mat4.subtract}3473 * @function3474 */3475 var sub$3 = subtract$3;3476 var mat4 = /*#__PURE__*/Object.freeze({3477 create: create$3,3478 clone: clone$3,3479 copy: copy$3,3480 fromValues: fromValues$3,3481 set: set$3,3482 identity: identity$3,3483 transpose: transpose$2,3484 invert: invert$3,3485 adjoint: adjoint$2,3486 determinant: determinant$3,3487 multiply: multiply$3,3488 translate: translate$2,3489 scale: scale$3,3490 rotate: rotate$3,3491 rotateX: rotateX,3492 rotateY: rotateY,3493 rotateZ: rotateZ,3494 fromTranslation: fromTranslation$2,3495 fromScaling: fromScaling$3,3496 fromRotation: fromRotation$3,3497 fromXRotation: fromXRotation,3498 fromYRotation: fromYRotation,3499 fromZRotation: fromZRotation,3500 fromRotationTranslation: fromRotationTranslation,3501 fromQuat2: fromQuat2,3502 getTranslation: getTranslation,3503 getScaling: getScaling,3504 getRotation: getRotation,3505 fromRotationTranslationScale: fromRotationTranslationScale,3506 fromRotationTranslationScaleOrigin: fromRotationTranslationScaleOrigin,3507 fromQuat: fromQuat$1,3508 frustum: frustum,3509 perspective: perspective,3510 perspectiveFromFieldOfView: perspectiveFromFieldOfView,3511 ortho: ortho,3512 lookAt: lookAt,3513 targetTo: targetTo,3514 str: str$3,3515 frob: frob$3,3516 add: add$3,3517 subtract: subtract$3,3518 multiplyScalar: multiplyScalar$3,3519 multiplyScalarAndAdd: multiplyScalarAndAdd$3,3520 exactEquals: exactEquals$3,3521 equals: equals$4,3522 mul: mul$3,3523 sub: sub$33524 });3525 /**3526 * 3 Dimensional Vector3527 * @module vec33528 */3529 /**3530 * Creates a new, empty vec33531 *3532 * @returns {vec3} a new 3D vector3533 */3534 function create$4() {3535 var out = new ARRAY_TYPE(3);3536 if (ARRAY_TYPE != Float32Array) {3537 out[0] = 0;3538 out[1] = 0;3539 out[2] = 0;3540 }3541 return out;3542 }3543 /**3544 * Creates a new vec3 initialized with values from an existing vector3545 *3546 * @param {vec3} a vector to clone3547 * @returns {vec3} a new 3D vector3548 */3549 function clone$4(a) {3550 var out = new ARRAY_TYPE(3);3551 out[0] = a[0];3552 out[1] = a[1];3553 out[2] = a[2];3554 return out;3555 }3556 /**3557 * Calculates the length of a vec33558 *3559 * @param {vec3} a vector to calculate length of3560 * @returns {Number} length of a3561 */3562 function length(a) {3563 var x = a[0];3564 var y = a[1];3565 var z = a[2];3566 return Math.hypot(x, y, z);3567 }3568 /**3569 * Creates a new vec3 initialized with the given values3570 *3571 * @param {Number} x X component3572 * @param {Number} y Y component3573 * @param {Number} z Z component3574 * @returns {vec3} a new 3D vector3575 */3576 function fromValues$4(x, y, z) {3577 var out = new ARRAY_TYPE(3);3578 out[0] = x;3579 out[1] = y;3580 out[2] = z;3581 return out;3582 }3583 /**3584 * Copy the values from one vec3 to another3585 *3586 * @param {vec3} out the receiving vector3587 * @param {vec3} a the source vector3588 * @returns {vec3} out3589 */3590 function copy$4(out, a) {3591 out[0] = a[0];3592 out[1] = a[1];3593 out[2] = a[2];3594 return out;3595 }3596 /**3597 * Set the components of a vec3 to the given values3598 *3599 * @param {vec3} out the receiving vector3600 * @param {Number} x X component3601 * @param {Number} y Y component3602 * @param {Number} z Z component3603 * @returns {vec3} out3604 */3605 function set$4(out, x, y, z) {3606 out[0] = x;3607 out[1] = y;3608 out[2] = z;3609 return out;3610 }3611 /**3612 * Adds two vec3's3613 *3614 * @param {vec3} out the receiving vector3615 * @param {vec3} a the first operand3616 * @param {vec3} b the second operand3617 * @returns {vec3} out3618 */3619 function add$4(out, a, b) {3620 out[0] = a[0] + b[0];3621 out[1] = a[1] + b[1];3622 out[2] = a[2] + b[2];3623 return out;3624 }3625 /**3626 * Subtracts vector b from vector a3627 *3628 * @param {vec3} out the receiving vector3629 * @param {vec3} a the first operand3630 * @param {vec3} b the second operand3631 * @returns {vec3} out3632 */3633 function subtract$4(out, a, b) {3634 out[0] = a[0] - b[0];3635 out[1] = a[1] - b[1];3636 out[2] = a[2] - b[2];3637 return out;3638 }3639 /**3640 * Multiplies two vec3's3641 *3642 * @param {vec3} out the receiving vector3643 * @param {vec3} a the first operand3644 * @param {vec3} b the second operand3645 * @returns {vec3} out3646 */3647 function multiply$4(out, a, b) {3648 out[0] = a[0] * b[0];3649 out[1] = a[1] * b[1];3650 out[2] = a[2] * b[2];3651 return out;3652 }3653 /**3654 * Divides two vec3's3655 *3656 * @param {vec3} out the receiving vector3657 * @param {vec3} a the first operand3658 * @param {vec3} b the second operand3659 * @returns {vec3} out3660 */3661 function divide(out, a, b) {3662 out[0] = a[0] / b[0];3663 out[1] = a[1] / b[1];3664 out[2] = a[2] / b[2];3665 return out;3666 }3667 /**3668 * Math.ceil the components of a vec33669 *3670 * @param {vec3} out the receiving vector3671 * @param {vec3} a vector to ceil3672 * @returns {vec3} out3673 */3674 function ceil(out, a) {3675 out[0] = Math.ceil(a[0]);3676 out[1] = Math.ceil(a[1]);3677 out[2] = Math.ceil(a[2]);3678 return out;3679 }3680 /**3681 * Math.floor the components of a vec33682 *3683 * @param {vec3} out the receiving vector3684 * @param {vec3} a vector to floor3685 * @returns {vec3} out3686 */3687 function floor(out, a) {3688 out[0] = Math.floor(a[0]);3689 out[1] = Math.floor(a[1]);3690 out[2] = Math.floor(a[2]);3691 return out;3692 }3693 /**3694 * Returns the minimum of two vec3's3695 *3696 * @param {vec3} out the receiving vector3697 * @param {vec3} a the first operand3698 * @param {vec3} b the second operand3699 * @returns {vec3} out3700 */3701 function min(out, a, b) {3702 out[0] = Math.min(a[0], b[0]);3703 out[1] = Math.min(a[1], b[1]);3704 out[2] = Math.min(a[2], b[2]);3705 return out;3706 }3707 /**3708 * Returns the maximum of two vec3's3709 *3710 * @param {vec3} out the receiving vector3711 * @param {vec3} a the first operand3712 * @param {vec3} b the second operand3713 * @returns {vec3} out3714 */3715 function max(out, a, b) {3716 out[0] = Math.max(a[0], b[0]);3717 out[1] = Math.max(a[1], b[1]);3718 out[2] = Math.max(a[2], b[2]);3719 return out;3720 }3721 /**3722 * Math.round the components of a vec33723 *3724 * @param {vec3} out the receiving vector3725 * @param {vec3} a vector to round3726 * @returns {vec3} out3727 */3728 function round(out, a) {3729 out[0] = Math.round(a[0]);3730 out[1] = Math.round(a[1]);3731 out[2] = Math.round(a[2]);3732 return out;3733 }3734 /**3735 * Scales a vec3 by a scalar number3736 *3737 * @param {vec3} out the receiving vector3738 * @param {vec3} a the vector to scale3739 * @param {Number} b amount to scale the vector by3740 * @returns {vec3} out3741 */3742 function scale$4(out, a, b) {3743 out[0] = a[0] * b;3744 out[1] = a[1] * b;3745 out[2] = a[2] * b;3746 return out;3747 }3748 /**3749 * Adds two vec3's after scaling the second operand by a scalar value3750 *3751 * @param {vec3} out the receiving vector3752 * @param {vec3} a the first operand3753 * @param {vec3} b the second operand3754 * @param {Number} scale the amount to scale b by before adding3755 * @returns {vec3} out3756 */3757 function scaleAndAdd(out, a, b, scale) {3758 out[0] = a[0] + b[0] * scale;3759 out[1] = a[1] + b[1] * scale;3760 out[2] = a[2] + b[2] * scale;3761 return out;3762 }3763 /**3764 * Calculates the euclidian distance between two vec3's3765 *3766 * @param {vec3} a the first operand3767 * @param {vec3} b the second operand3768 * @returns {Number} distance between a and b3769 */3770 function distance(a, b) {3771 var x = b[0] - a[0];3772 var y = b[1] - a[1];3773 var z = b[2] - a[2];3774 return Math.hypot(x, y, z);3775 }3776 /**3777 * Calculates the squared euclidian distance between two vec3's3778 *3779 * @param {vec3} a the first operand3780 * @param {vec3} b the second operand3781 * @returns {Number} squared distance between a and b3782 */3783 function squaredDistance(a, b) {3784 var x = b[0] - a[0];3785 var y = b[1] - a[1];3786 var z = b[2] - a[2];3787 return x * x + y * y + z * z;3788 }3789 /**3790 * Calculates the squared length of a vec33791 *3792 * @param {vec3} a vector to calculate squared length of3793 * @returns {Number} squared length of a3794 */3795 function squaredLength(a) {3796 var x = a[0];3797 var y = a[1];3798 var z = a[2];3799 return x * x + y * y + z * z;3800 }3801 /**3802 * Negates the components of a vec33803 *3804 * @param {vec3} out the receiving vector3805 * @param {vec3} a vector to negate3806 * @returns {vec3} out3807 */3808 function negate(out, a) {3809 out[0] = -a[0];3810 out[1] = -a[1];3811 out[2] = -a[2];3812 return out;3813 }3814 /**3815 * Returns the inverse of the components of a vec33816 *3817 * @param {vec3} out the receiving vector3818 * @param {vec3} a vector to invert3819 * @returns {vec3} out3820 */3821 function inverse(out, a) {3822 out[0] = 1.0 / a[0];3823 out[1] = 1.0 / a[1];3824 out[2] = 1.0 / a[2];3825 return out;3826 }3827 /**3828 * Normalize a vec33829 *3830 * @param {vec3} out the receiving vector3831 * @param {vec3} a vector to normalize3832 * @returns {vec3} out3833 */3834 function normalize(out, a) {3835 var x = a[0];3836 var y = a[1];3837 var z = a[2];3838 var len = x * x + y * y + z * z;3839 if (len > 0) {3840 //TODO: evaluate use of glm_invsqrt here?3841 len = 1 / Math.sqrt(len);3842 }3843 out[0] = a[0] * len;3844 out[1] = a[1] * len;3845 out[2] = a[2] * len;3846 return out;3847 }3848 /**3849 * Calculates the dot product of two vec3's3850 *3851 * @param {vec3} a the first operand3852 * @param {vec3} b the second operand3853 * @returns {Number} dot product of a and b3854 */3855 function dot(a, b) {3856 return a[0] * b[0] + a[1] * b[1] + a[2] * b[2];3857 }3858 /**3859 * Computes the cross product of two vec3's3860 *3861 * @param {vec3} out the receiving vector3862 * @param {vec3} a the first operand3863 * @param {vec3} b the second operand3864 * @returns {vec3} out3865 */3866 function cross(out, a, b) {3867 var ax = a[0],3868 ay = a[1],3869 az = a[2];3870 var bx = b[0],3871 by = b[1],3872 bz = b[2];3873 out[0] = ay * bz - az * by;3874 out[1] = az * bx - ax * bz;3875 out[2] = ax * by - ay * bx;3876 return out;3877 }3878 /**3879 * Performs a linear interpolation between two vec3's3880 *3881 * @param {vec3} out the receiving vector3882 * @param {vec3} a the first operand3883 * @param {vec3} b the second operand3884 * @param {Number} t interpolation amount, in the range [0-1], between the two inputs3885 * @returns {vec3} out3886 */3887 function lerp(out, a, b, t) {3888 var ax = a[0];3889 var ay = a[1];3890 var az = a[2];3891 out[0] = ax + t * (b[0] - ax);3892 out[1] = ay + t * (b[1] - ay);3893 out[2] = az + t * (b[2] - az);3894 return out;3895 }3896 /**3897 * Performs a hermite interpolation with two control points3898 *3899 * @param {vec3} out the receiving vector3900 * @param {vec3} a the first operand3901 * @param {vec3} b the second operand3902 * @param {vec3} c the third operand3903 * @param {vec3} d the fourth operand3904 * @param {Number} t interpolation amount, in the range [0-1], between the two inputs3905 * @returns {vec3} out3906 */3907 function hermite(out, a, b, c, d, t) {3908 var factorTimes2 = t * t;3909 var factor1 = factorTimes2 * (2 * t - 3) + 1;3910 var factor2 = factorTimes2 * (t - 2) + t;3911 var factor3 = factorTimes2 * (t - 1);3912 var factor4 = factorTimes2 * (3 - 2 * t);3913 out[0] = a[0] * factor1 + b[0] * factor2 + c[0] * factor3 + d[0] * factor4;3914 out[1] = a[1] * factor1 + b[1] * factor2 + c[1] * factor3 + d[1] * factor4;3915 out[2] = a[2] * factor1 + b[2] * factor2 + c[2] * factor3 + d[2] * factor4;3916 return out;3917 }3918 /**3919 * Performs a bezier interpolation with two control points3920 *3921 * @param {vec3} out the receiving vector3922 * @param {vec3} a the first operand3923 * @param {vec3} b the second operand3924 * @param {vec3} c the third operand3925 * @param {vec3} d the fourth operand3926 * @param {Number} t interpolation amount, in the range [0-1], between the two inputs3927 * @returns {vec3} out3928 */3929 function bezier(out, a, b, c, d, t) {3930 var inverseFactor = 1 - t;3931 var inverseFactorTimesTwo = inverseFactor * inverseFactor;3932 var factorTimes2 = t * t;3933 var factor1 = inverseFactorTimesTwo * inverseFactor;3934 var factor2 = 3 * t * inverseFactorTimesTwo;3935 var factor3 = 3 * factorTimes2 * inverseFactor;3936 var factor4 = factorTimes2 * t;3937 out[0] = a[0] * factor1 + b[0] * factor2 + c[0] * factor3 + d[0] * factor4;3938 out[1] = a[1] * factor1 + b[1] * factor2 + c[1] * factor3 + d[1] * factor4;3939 out[2] = a[2] * factor1 + b[2] * factor2 + c[2] * factor3 + d[2] * factor4;3940 return out;3941 }3942 /**3943 * Generates a random vector with the given scale3944 *3945 * @param {vec3} out the receiving vector3946 * @param {Number} [scale] Length of the resulting vector. If ommitted, a unit vector will be returned3947 * @returns {vec3} out3948 */3949 function random(out, scale) {3950 scale = scale || 1.0;3951 var r = RANDOM() * 2.0 * Math.PI;3952 var z = RANDOM() * 2.0 - 1.0;3953 var zScale = Math.sqrt(1.0 - z * z) * scale;3954 out[0] = Math.cos(r) * zScale;3955 out[1] = Math.sin(r) * zScale;3956 out[2] = z * scale;3957 return out;3958 }3959 /**3960 * Transforms the vec3 with a mat4.3961 * 4th vector component is implicitly '1'3962 *3963 * @param {vec3} out the receiving vector3964 * @param {vec3} a the vector to transform3965 * @param {mat4} m matrix to transform with3966 * @returns {vec3} out3967 */3968 function transformMat4(out, a, m) {3969 var x = a[0],3970 y = a[1],3971 z = a[2];3972 var w = m[3] * x + m[7] * y + m[11] * z + m[15];3973 w = w || 1.0;3974 out[0] = (m[0] * x + m[4] * y + m[8] * z + m[12]) / w;3975 out[1] = (m[1] * x + m[5] * y + m[9] * z + m[13]) / w;3976 out[2] = (m[2] * x + m[6] * y + m[10] * z + m[14]) / w;3977 return out;3978 }3979 /**3980 * Transforms the vec3 with a mat3.3981 *3982 * @param {vec3} out the receiving vector3983 * @param {vec3} a the vector to transform3984 * @param {mat3} m the 3x3 matrix to transform with3985 * @returns {vec3} out3986 */3987 function transformMat3(out, a, m) {3988 var x = a[0],3989 y = a[1],3990 z = a[2];3991 out[0] = x * m[0] + y * m[3] + z * m[6];3992 out[1] = x * m[1] + y * m[4] + z * m[7];3993 out[2] = x * m[2] + y * m[5] + z * m[8];3994 return out;3995 }3996 /**3997 * Transforms the vec3 with a quat3998 * Can also be used for dual quaternions. (Multiply it with the real part)3999 *4000 * @param {vec3} out the receiving vector4001 * @param {vec3} a the vector to transform4002 * @param {quat} q quaternion to transform with4003 * @returns {vec3} out4004 */4005 function transformQuat(out, a, q) {4006 // benchmarks: https://jsperf.com/quaternion-transform-vec3-implementations-fixed4007 var qx = q[0],4008 qy = q[1],4009 qz = q[2],4010 qw = q[3];4011 var x = a[0],4012 y = a[1],4013 z = a[2]; // var qvec = [qx, qy, qz];4014 // var uv = vec3.cross([], qvec, a);4015 var uvx = qy * z - qz * y,4016 uvy = qz * x - qx * z,4017 uvz = qx * y - qy * x; // var uuv = vec3.cross([], qvec, uv);4018 var uuvx = qy * uvz - qz * uvy,4019 uuvy = qz * uvx - qx * uvz,4020 uuvz = qx * uvy - qy * uvx; // vec3.scale(uv, uv, 2 * w);4021 var w2 = qw * 2;4022 uvx *= w2;4023 uvy *= w2;4024 uvz *= w2; // vec3.scale(uuv, uuv, 2);4025 uuvx *= 2;4026 uuvy *= 2;4027 uuvz *= 2; // return vec3.add(out, a, vec3.add(out, uv, uuv));4028 out[0] = x + uvx + uuvx;4029 out[1] = y + uvy + uuvy;4030 out[2] = z + uvz + uuvz;4031 return out;4032 }4033 /**4034 * Rotate a 3D vector around the x-axis4035 * @param {vec3} out The receiving vec34036 * @param {vec3} a The vec3 point to rotate4037 * @param {vec3} b The origin of the rotation4038 * @param {Number} c The angle of rotation4039 * @returns {vec3} out4040 */4041 function rotateX$1(out, a, b, c) {4042 var p = [],4043 r = []; //Translate point to the origin4044 p[0] = a[0] - b[0];4045 p[1] = a[1] - b[1];4046 p[2] = a[2] - b[2]; //perform rotation4047 r[0] = p[0];4048 r[1] = p[1] * Math.cos(c) - p[2] * Math.sin(c);4049 r[2] = p[1] * Math.sin(c) + p[2] * Math.cos(c); //translate to correct position4050 out[0] = r[0] + b[0];4051 out[1] = r[1] + b[1];4052 out[2] = r[2] + b[2];4053 return out;4054 }4055 /**4056 * Rotate a 3D vector around the y-axis4057 * @param {vec3} out The receiving vec34058 * @param {vec3} a The vec3 point to rotate4059 * @param {vec3} b The origin of the rotation4060 * @param {Number} c The angle of rotation4061 * @returns {vec3} out4062 */4063 function rotateY$1(out, a, b, c) {4064 var p = [],4065 r = []; //Translate point to the origin4066 p[0] = a[0] - b[0];4067 p[1] = a[1] - b[1];4068 p[2] = a[2] - b[2]; //perform rotation4069 r[0] = p[2] * Math.sin(c) + p[0] * Math.cos(c);4070 r[1] = p[1];4071 r[2] = p[2] * Math.cos(c) - p[0] * Math.sin(c); //translate to correct position4072 out[0] = r[0] + b[0];4073 out[1] = r[1] + b[1];4074 out[2] = r[2] + b[2];4075 return out;4076 }4077 /**4078 * Rotate a 3D vector around the z-axis4079 * @param {vec3} out The receiving vec34080 * @param {vec3} a The vec3 point to rotate4081 * @param {vec3} b The origin of the rotation4082 * @param {Number} c The angle of rotation4083 * @returns {vec3} out4084 */4085 function rotateZ$1(out, a, b, c) {4086 var p = [],4087 r = []; //Translate point to the origin4088 p[0] = a[0] - b[0];4089 p[1] = a[1] - b[1];4090 p[2] = a[2] - b[2]; //perform rotation4091 r[0] = p[0] * Math.cos(c) - p[1] * Math.sin(c);4092 r[1] = p[0] * Math.sin(c) + p[1] * Math.cos(c);4093 r[2] = p[2]; //translate to correct position4094 out[0] = r[0] + b[0];4095 out[1] = r[1] + b[1];4096 out[2] = r[2] + b[2];4097 return out;4098 }4099 /**4100 * Get the angle between two 3D vectors4101 * @param {vec3} a The first operand4102 * @param {vec3} b The second operand4103 * @returns {Number} The angle in radians4104 */4105 function angle(a, b) {4106 var tempA = fromValues$4(a[0], a[1], a[2]);4107 var tempB = fromValues$4(b[0], b[1], b[2]);4108 normalize(tempA, tempA);4109 normalize(tempB, tempB);4110 var cosine = dot(tempA, tempB);4111 if (cosine > 1.0) {4112 return 0;4113 } else if (cosine < -1.0) {4114 return Math.PI;4115 } else {4116 return Math.acos(cosine);4117 }4118 }4119 /**4120 * Set the components of a vec3 to zero4121 *4122 * @param {vec3} out the receiving vector4123 * @returns {vec3} out4124 */4125 function zero(out) {4126 out[0] = 0.0;4127 out[1] = 0.0;4128 out[2] = 0.0;4129 return out;4130 }4131 /**4132 * Returns a string representation of a vector4133 *4134 * @param {vec3} a vector to represent as a string4135 * @returns {String} string representation of the vector4136 */4137 function str$4(a) {4138 return 'vec3(' + a[0] + ', ' + a[1] + ', ' + a[2] + ')';4139 }4140 /**4141 * Returns whether or not the vectors have exactly the same elements in the same position (when compared with ===)4142 *4143 * @param {vec3} a The first vector.4144 * @param {vec3} b The second vector.4145 * @returns {Boolean} True if the vectors are equal, false otherwise.4146 */4147 function exactEquals$4(a, b) {4148 return a[0] === b[0] && a[1] === b[1] && a[2] === b[2];4149 }4150 /**4151 * Returns whether or not the vectors have approximately the same elements in the same position.4152 *4153 * @param {vec3} a The first vector.4154 * @param {vec3} b The second vector.4155 * @returns {Boolean} True if the vectors are equal, false otherwise.4156 */4157 function equals$5(a, b) {4158 var a0 = a[0],4159 a1 = a[1],4160 a2 = a[2];4161 var b0 = b[0],4162 b1 = b[1],4163 b2 = b[2];4164 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));4165 }4166 /**4167 * Alias for {@link vec3.subtract}4168 * @function4169 */4170 var sub$4 = subtract$4;4171 /**4172 * Alias for {@link vec3.multiply}4173 * @function4174 */4175 var mul$4 = multiply$4;4176 /**4177 * Alias for {@link vec3.divide}4178 * @function4179 */4180 var div = divide;4181 /**4182 * Alias for {@link vec3.distance}4183 * @function4184 */4185 var dist = distance;4186 /**4187 * Alias for {@link vec3.squaredDistance}4188 * @function4189 */4190 var sqrDist = squaredDistance;4191 /**4192 * Alias for {@link vec3.length}4193 * @function4194 */4195 var len = length;4196 /**4197 * Alias for {@link vec3.squaredLength}4198 * @function4199 */4200 var sqrLen = squaredLength;4201 /**4202 * Perform some operation over an array of vec3s.4203 *4204 * @param {Array} a the array of vectors to iterate over4205 * @param {Number} stride Number of elements between the start of each vec3. If 0 assumes tightly packed4206 * @param {Number} offset Number of elements to skip at the beginning of the array4207 * @param {Number} count Number of vec3s to iterate over. If 0 iterates over entire array4208 * @param {Function} fn Function to call for each vector in the array4209 * @param {Object} [arg] additional argument to pass to fn4210 * @returns {Array} a4211 * @function4212 */4213 var forEach = function () {4214 var vec = create$4();4215 return function (a, stride, offset, count, fn, arg) {4216 var i, l;4217 if (!stride) {4218 stride = 3;4219 }4220 if (!offset) {4221 offset = 0;4222 }4223 if (count) {4224 l = Math.min(count * stride + offset, a.length);4225 } else {4226 l = a.length;4227 }4228 for (i = offset; i < l; i += stride) {4229 vec[0] = a[i];4230 vec[1] = a[i + 1];4231 vec[2] = a[i + 2];4232 fn(vec, vec, arg);4233 a[i] = vec[0];4234 a[i + 1] = vec[1];4235 a[i + 2] = vec[2];4236 }4237 return a;4238 };4239 }();4240 var vec3 = /*#__PURE__*/Object.freeze({4241 create: create$4,4242 clone: clone$4,4243 length: length,4244 fromValues: fromValues$4,4245 copy: copy$4,4246 set: set$4,4247 add: add$4,4248 subtract: subtract$4,4249 multiply: multiply$4,4250 divide: divide,4251 ceil: ceil,4252 floor: floor,4253 min: min,4254 max: max,4255 round: round,4256 scale: scale$4,4257 scaleAndAdd: scaleAndAdd,4258 distance: distance,4259 squaredDistance: squaredDistance,4260 squaredLength: squaredLength,4261 negate: negate,4262 inverse: inverse,4263 normalize: normalize,4264 dot: dot,4265 cross: cross,4266 lerp: lerp,4267 hermite: hermite,4268 bezier: bezier,4269 random: random,4270 transformMat4: transformMat4,4271 transformMat3: transformMat3,4272 transformQuat: transformQuat,4273 rotateX: rotateX$1,4274 rotateY: rotateY$1,4275 rotateZ: rotateZ$1,4276 angle: angle,4277 zero: zero,4278 str: str$4,4279 exactEquals: exactEquals$4,4280 equals: equals$5,4281 sub: sub$4,4282 mul: mul$4,4283 div: div,4284 dist: dist,4285 sqrDist: sqrDist,4286 len: len,4287 sqrLen: sqrLen,4288 forEach: forEach4289 });4290 /**4291 * 4 Dimensional Vector4292 * @module vec44293 */4294 /**4295 * Creates a new, empty vec44296 *4297 * @returns {vec4} a new 4D vector4298 */4299 function create$5() {4300 var out = new ARRAY_TYPE(4);4301 if (ARRAY_TYPE != Float32Array) {4302 out[0] = 0;4303 out[1] = 0;4304 out[2] = 0;4305 out[3] = 0;4306 }4307 return out;4308 }4309 /**4310 * Creates a new vec4 initialized with values from an existing vector4311 *4312 * @param {vec4} a vector to clone4313 * @returns {vec4} a new 4D vector4314 */4315 function clone$5(a) {4316 var out = new ARRAY_TYPE(4);4317 out[0] = a[0];4318 out[1] = a[1];4319 out[2] = a[2];4320 out[3] = a[3];4321 return out;4322 }4323 /**4324 * Creates a new vec4 initialized with the given values4325 *4326 * @param {Number} x X component4327 * @param {Number} y Y component4328 * @param {Number} z Z component4329 * @param {Number} w W component4330 * @returns {vec4} a new 4D vector4331 */4332 function fromValues$5(x, y, z, w) {4333 var out = new ARRAY_TYPE(4);4334 out[0] = x;4335 out[1] = y;4336 out[2] = z;4337 out[3] = w;4338 return out;4339 }4340 /**4341 * Copy the values from one vec4 to another4342 *4343 * @param {vec4} out the receiving vector4344 * @param {vec4} a the source vector4345 * @returns {vec4} out4346 */4347 function copy$5(out, a) {4348 out[0] = a[0];4349 out[1] = a[1];4350 out[2] = a[2];4351 out[3] = a[3];4352 return out;4353 }4354 /**4355 * Set the components of a vec4 to the given values4356 *4357 * @param {vec4} out the receiving vector4358 * @param {Number} x X component4359 * @param {Number} y Y component4360 * @param {Number} z Z component4361 * @param {Number} w W component4362 * @returns {vec4} out4363 */4364 function set$5(out, x, y, z, w) {4365 out[0] = x;4366 out[1] = y;4367 out[2] = z;4368 out[3] = w;4369 return out;4370 }4371 /**4372 * Adds two vec4's4373 *4374 * @param {vec4} out the receiving vector4375 * @param {vec4} a the first operand4376 * @param {vec4} b the second operand4377 * @returns {vec4} out4378 */4379 function add$5(out, a, b) {4380 out[0] = a[0] + b[0];4381 out[1] = a[1] + b[1];4382 out[2] = a[2] + b[2];4383 out[3] = a[3] + b[3];4384 return out;4385 }4386 /**4387 * Subtracts vector b from vector a4388 *4389 * @param {vec4} out the receiving vector4390 * @param {vec4} a the first operand4391 * @param {vec4} b the second operand4392 * @returns {vec4} out4393 */4394 function subtract$5(out, a, b) {4395 out[0] = a[0] - b[0];4396 out[1] = a[1] - b[1];4397 out[2] = a[2] - b[2];4398 out[3] = a[3] - b[3];4399 return out;4400 }4401 /**4402 * Multiplies two vec4's4403 *4404 * @param {vec4} out the receiving vector4405 * @param {vec4} a the first operand4406 * @param {vec4} b the second operand4407 * @returns {vec4} out4408 */4409 function multiply$5(out, a, b) {4410 out[0] = a[0] * b[0];4411 out[1] = a[1] * b[1];4412 out[2] = a[2] * b[2];4413 out[3] = a[3] * b[3];4414 return out;4415 }4416 /**4417 * Divides two vec4's4418 *4419 * @param {vec4} out the receiving vector4420 * @param {vec4} a the first operand4421 * @param {vec4} b the second operand4422 * @returns {vec4} out4423 */4424 function divide$1(out, a, b) {4425 out[0] = a[0] / b[0];4426 out[1] = a[1] / b[1];4427 out[2] = a[2] / b[2];4428 out[3] = a[3] / b[3];4429 return out;4430 }4431 /**4432 * Math.ceil the components of a vec44433 *4434 * @param {vec4} out the receiving vector4435 * @param {vec4} a vector to ceil4436 * @returns {vec4} out4437 */4438 function ceil$1(out, a) {4439 out[0] = Math.ceil(a[0]);4440 out[1] = Math.ceil(a[1]);4441 out[2] = Math.ceil(a[2]);4442 out[3] = Math.ceil(a[3]);4443 return out;4444 }4445 /**4446 * Math.floor the components of a vec44447 *4448 * @param {vec4} out the receiving vector4449 * @param {vec4} a vector to floor4450 * @returns {vec4} out4451 */4452 function floor$1(out, a) {4453 out[0] = Math.floor(a[0]);4454 out[1] = Math.floor(a[1]);4455 out[2] = Math.floor(a[2]);4456 out[3] = Math.floor(a[3]);4457 return out;4458 }4459 /**4460 * Returns the minimum of two vec4's4461 *4462 * @param {vec4} out the receiving vector4463 * @param {vec4} a the first operand4464 * @param {vec4} b the second operand4465 * @returns {vec4} out4466 */4467 function min$1(out, a, b) {4468 out[0] = Math.min(a[0], b[0]);4469 out[1] = Math.min(a[1], b[1]);4470 out[2] = Math.min(a[2], b[2]);4471 out[3] = Math.min(a[3], b[3]);4472 return out;4473 }4474 /**4475 * Returns the maximum of two vec4's4476 *4477 * @param {vec4} out the receiving vector4478 * @param {vec4} a the first operand4479 * @param {vec4} b the second operand4480 * @returns {vec4} out4481 */4482 function max$1(out, a, b) {4483 out[0] = Math.max(a[0], b[0]);4484 out[1] = Math.max(a[1], b[1]);4485 out[2] = Math.max(a[2], b[2]);4486 out[3] = Math.max(a[3], b[3]);4487 return out;4488 }4489 /**4490 * Math.round the components of a vec44491 *4492 * @param {vec4} out the receiving vector4493 * @param {vec4} a vector to round4494 * @returns {vec4} out4495 */4496 function round$1(out, a) {4497 out[0] = Math.round(a[0]);4498 out[1] = Math.round(a[1]);4499 out[2] = Math.round(a[2]);4500 out[3] = Math.round(a[3]);4501 return out;4502 }4503 /**4504 * Scales a vec4 by a scalar number4505 *4506 * @param {vec4} out the receiving vector4507 * @param {vec4} a the vector to scale4508 * @param {Number} b amount to scale the vector by4509 * @returns {vec4} out4510 */4511 function scale$5(out, a, b) {4512 out[0] = a[0] * b;4513 out[1] = a[1] * b;4514 out[2] = a[2] * b;4515 out[3] = a[3] * b;4516 return out;4517 }4518 /**4519 * Adds two vec4's after scaling the second operand by a scalar value4520 *4521 * @param {vec4} out the receiving vector4522 * @param {vec4} a the first operand4523 * @param {vec4} b the second operand4524 * @param {Number} scale the amount to scale b by before adding4525 * @returns {vec4} out4526 */4527 function scaleAndAdd$1(out, a, b, scale) {4528 out[0] = a[0] + b[0] * scale;4529 out[1] = a[1] + b[1] * scale;4530 out[2] = a[2] + b[2] * scale;4531 out[3] = a[3] + b[3] * scale;4532 return out;4533 }4534 /**4535 * Calculates the euclidian distance between two vec4's4536 *4537 * @param {vec4} a the first operand4538 * @param {vec4} b the second operand4539 * @returns {Number} distance between a and b4540 */4541 function distance$1(a, b) {4542 var x = b[0] - a[0];4543 var y = b[1] - a[1];4544 var z = b[2] - a[2];4545 var w = b[3] - a[3];4546 return Math.hypot(x, y, z, w);4547 }4548 /**4549 * Calculates the squared euclidian distance between two vec4's4550 *4551 * @param {vec4} a the first operand4552 * @param {vec4} b the second operand4553 * @returns {Number} squared distance between a and b4554 */4555 function squaredDistance$1(a, b) {4556 var x = b[0] - a[0];4557 var y = b[1] - a[1];4558 var z = b[2] - a[2];4559 var w = b[3] - a[3];4560 return x * x + y * y + z * z + w * w;4561 }4562 /**4563 * Calculates the length of a vec44564 *4565 * @param {vec4} a vector to calculate length of4566 * @returns {Number} length of a4567 */4568 function length$1(a) {4569 var x = a[0];4570 var y = a[1];4571 var z = a[2];4572 var w = a[3];4573 return Math.hypot(x, y, z, w);4574 }4575 /**4576 * Calculates the squared length of a vec44577 *4578 * @param {vec4} a vector to calculate squared length of4579 * @returns {Number} squared length of a4580 */4581 function squaredLength$1(a) {4582 var x = a[0];4583 var y = a[1];4584 var z = a[2];4585 var w = a[3];4586 return x * x + y * y + z * z + w * w;4587 }4588 /**4589 * Negates the components of a vec44590 *4591 * @param {vec4} out the receiving vector4592 * @param {vec4} a vector to negate4593 * @returns {vec4} out4594 */4595 function negate$1(out, a) {4596 out[0] = -a[0];4597 out[1] = -a[1];4598 out[2] = -a[2];4599 out[3] = -a[3];4600 return out;4601 }4602 /**4603 * Returns the inverse of the components of a vec44604 *4605 * @param {vec4} out the receiving vector4606 * @param {vec4} a vector to invert4607 * @returns {vec4} out4608 */4609 function inverse$1(out, a) {4610 out[0] = 1.0 / a[0];4611 out[1] = 1.0 / a[1];4612 out[2] = 1.0 / a[2];4613 out[3] = 1.0 / a[3];4614 return out;4615 }4616 /**4617 * Normalize a vec44618 *4619 * @param {vec4} out the receiving vector4620 * @param {vec4} a vector to normalize4621 * @returns {vec4} out4622 */4623 function normalize$1(out, a) {4624 var x = a[0];4625 var y = a[1];4626 var z = a[2];4627 var w = a[3];4628 var len = x * x + y * y + z * z + w * w;4629 if (len > 0) {4630 len = 1 / Math.sqrt(len);4631 }4632 out[0] = x * len;4633 out[1] = y * len;4634 out[2] = z * len;4635 out[3] = w * len;4636 return out;4637 }4638 /**4639 * Calculates the dot product of two vec4's4640 *4641 * @param {vec4} a the first operand4642 * @param {vec4} b the second operand4643 * @returns {Number} dot product of a and b4644 */4645 function dot$1(a, b) {4646 return a[0] * b[0] + a[1] * b[1] + a[2] * b[2] + a[3] * b[3];4647 }4648 /**4649 * Returns the cross-product of three vectors in a 4-dimensional space4650 *4651 * @param {vec4} result the receiving vector4652 * @param {vec4} U the first vector4653 * @param {vec4} V the second vector4654 * @param {vec4} W the third vector4655 * @returns {vec4} result4656 */4657 function cross$1(out, u, v, w) {4658 var A = v[0] * w[1] - v[1] * w[0],4659 B = v[0] * w[2] - v[2] * w[0],4660 C = v[0] * w[3] - v[3] * w[0],4661 D = v[1] * w[2] - v[2] * w[1],4662 E = v[1] * w[3] - v[3] * w[1],4663 F = v[2] * w[3] - v[3] * w[2];4664 var G = u[0];4665 var H = u[1];4666 var I = u[2];4667 var J = u[3];4668 out[0] = H * F - I * E + J * D;4669 out[1] = -(G * F) + I * C - J * B;4670 out[2] = G * E - H * C + J * A;4671 out[3] = -(G * D) + H * B - I * A;4672 return out;4673 }4674 /**4675 * Performs a linear interpolation between two vec4's4676 *4677 * @param {vec4} out the receiving vector4678 * @param {vec4} a the first operand4679 * @param {vec4} b the second operand4680 * @param {Number} t interpolation amount, in the range [0-1], between the two inputs4681 * @returns {vec4} out4682 */4683 function lerp$1(out, a, b, t) {4684 var ax = a[0];4685 var ay = a[1];4686 var az = a[2];4687 var aw = a[3];4688 out[0] = ax + t * (b[0] - ax);4689 out[1] = ay + t * (b[1] - ay);4690 out[2] = az + t * (b[2] - az);4691 out[3] = aw + t * (b[3] - aw);4692 return out;4693 }4694 /**4695 * Generates a random vector with the given scale4696 *4697 * @param {vec4} out the receiving vector4698 * @param {Number} [scale] Length of the resulting vector. If ommitted, a unit vector will be returned4699 * @returns {vec4} out4700 */4701 function random$1(out, scale) {4702 scale = scale || 1.0; // Marsaglia, George. Choosing a Point from the Surface of a4703 // Sphere. Ann. Math. Statist. 43 (1972), no. 2, 645--646.4704 // http://projecteuclid.org/euclid.aoms/1177692644;4705 var v1, v2, v3, v4;4706 var s1, s2;4707 do {4708 v1 = RANDOM() * 2 - 1;4709 v2 = RANDOM() * 2 - 1;4710 s1 = v1 * v1 + v2 * v2;4711 } while (s1 >= 1);4712 do {4713 v3 = RANDOM() * 2 - 1;4714 v4 = RANDOM() * 2 - 1;4715 s2 = v3 * v3 + v4 * v4;4716 } while (s2 >= 1);4717 var d = Math.sqrt((1 - s1) / s2);4718 out[0] = scale * v1;4719 out[1] = scale * v2;4720 out[2] = scale * v3 * d;4721 out[3] = scale * v4 * d;4722 return out;4723 }4724 /**4725 * Transforms the vec4 with a mat4.4726 *4727 * @param {vec4} out the receiving vector4728 * @param {vec4} a the vector to transform4729 * @param {mat4} m matrix to transform with4730 * @returns {vec4} out4731 */4732 function transformMat4$1(out, a, m) {4733 var x = a[0],4734 y = a[1],4735 z = a[2],4736 w = a[3];4737 out[0] = m[0] * x + m[4] * y + m[8] * z + m[12] * w;4738 out[1] = m[1] * x + m[5] * y + m[9] * z + m[13] * w;4739 out[2] = m[2] * x + m[6] * y + m[10] * z + m[14] * w;4740 out[3] = m[3] * x + m[7] * y + m[11] * z + m[15] * w;4741 return out;4742 }4743 /**4744 * Transforms the vec4 with a quat4745 *4746 * @param {vec4} out the receiving vector4747 * @param {vec4} a the vector to transform4748 * @param {quat} q quaternion to transform with4749 * @returns {vec4} out4750 */4751 function transformQuat$1(out, a, q) {4752 var x = a[0],4753 y = a[1],4754 z = a[2];4755 var qx = q[0],4756 qy = q[1],4757 qz = q[2],4758 qw = q[3]; // calculate quat * vec4759 var ix = qw * x + qy * z - qz * y;4760 var iy = qw * y + qz * x - qx * z;4761 var iz = qw * z + qx * y - qy * x;4762 var iw = -qx * x - qy * y - qz * z; // calculate result * inverse quat4763 out[0] = ix * qw + iw * -qx + iy * -qz - iz * -qy;4764 out[1] = iy * qw + iw * -qy + iz * -qx - ix * -qz;4765 out[2] = iz * qw + iw * -qz + ix * -qy - iy * -qx;4766 out[3] = a[3];4767 return out;4768 }4769 /**4770 * Set the components of a vec4 to zero4771 *4772 * @param {vec4} out the receiving vector4773 * @returns {vec4} out4774 */4775 function zero$1(out) {4776 out[0] = 0.0;4777 out[1] = 0.0;4778 out[2] = 0.0;4779 out[3] = 0.0;4780 return out;4781 }4782 /**4783 * Returns a string representation of a vector4784 *4785 * @param {vec4} a vector to represent as a string4786 * @returns {String} string representation of the vector4787 */4788 function str$5(a) {4789 return 'vec4(' + a[0] + ', ' + a[1] + ', ' + a[2] + ', ' + a[3] + ')';4790 }4791 /**4792 * Returns whether or not the vectors have exactly the same elements in the same position (when compared with ===)4793 *4794 * @param {vec4} a The first vector.4795 * @param {vec4} b The second vector.4796 * @returns {Boolean} True if the vectors are equal, false otherwise.4797 */4798 function exactEquals$5(a, b) {4799 return a[0] === b[0] && a[1] === b[1] && a[2] === b[2] && a[3] === b[3];4800 }4801 /**4802 * Returns whether or not the vectors have approximately the same elements in the same position.4803 *4804 * @param {vec4} a The first vector.4805 * @param {vec4} b The second vector.4806 * @returns {Boolean} True if the vectors are equal, false otherwise.4807 */4808 function equals$6(a, b) {4809 var a0 = a[0],4810 a1 = a[1],4811 a2 = a[2],4812 a3 = a[3];4813 var b0 = b[0],4814 b1 = b[1],4815 b2 = b[2],4816 b3 = b[3];4817 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));4818 }4819 /**4820 * Alias for {@link vec4.subtract}4821 * @function4822 */4823 var sub$5 = subtract$5;4824 /**4825 * Alias for {@link vec4.multiply}4826 * @function4827 */4828 var mul$5 = multiply$5;4829 /**4830 * Alias for {@link vec4.divide}4831 * @function4832 */4833 var div$1 = divide$1;4834 /**4835 * Alias for {@link vec4.distance}4836 * @function4837 */4838 var dist$1 = distance$1;4839 /**4840 * Alias for {@link vec4.squaredDistance}4841 * @function4842 */4843 var sqrDist$1 = squaredDistance$1;4844 /**4845 * Alias for {@link vec4.length}4846 * @function4847 */4848 var len$1 = length$1;4849 /**4850 * Alias for {@link vec4.squaredLength}4851 * @function4852 */4853 var sqrLen$1 = squaredLength$1;4854 /**4855 * Perform some operation over an array of vec4s.4856 *4857 * @param {Array} a the array of vectors to iterate over4858 * @param {Number} stride Number of elements between the start of each vec4. If 0 assumes tightly packed4859 * @param {Number} offset Number of elements to skip at the beginning of the array4860 * @param {Number} count Number of vec4s to iterate over. If 0 iterates over entire array4861 * @param {Function} fn Function to call for each vector in the array4862 * @param {Object} [arg] additional argument to pass to fn4863 * @returns {Array} a4864 * @function4865 */4866 var forEach$1 = function () {4867 var vec = create$5();4868 return function (a, stride, offset, count, fn, arg) {4869 var i, l;4870 if (!stride) {4871 stride = 4;4872 }4873 if (!offset) {4874 offset = 0;4875 }4876 if (count) {4877 l = Math.min(count * stride + offset, a.length);4878 } else {4879 l = a.length;4880 }4881 for (i = offset; i < l; i += stride) {4882 vec[0] = a[i];4883 vec[1] = a[i + 1];4884 vec[2] = a[i + 2];4885 vec[3] = a[i + 3];4886 fn(vec, vec, arg);4887 a[i] = vec[0];4888 a[i + 1] = vec[1];4889 a[i + 2] = vec[2];4890 a[i + 3] = vec[3];4891 }4892 return a;4893 };4894 }();4895 var vec4 = /*#__PURE__*/Object.freeze({4896 create: create$5,4897 clone: clone$5,4898 fromValues: fromValues$5,4899 copy: copy$5,4900 set: set$5,4901 add: add$5,4902 subtract: subtract$5,4903 multiply: multiply$5,4904 divide: divide$1,4905 ceil: ceil$1,4906 floor: floor$1,4907 min: min$1,4908 max: max$1,4909 round: round$1,4910 scale: scale$5,4911 scaleAndAdd: scaleAndAdd$1,4912 distance: distance$1,4913 squaredDistance: squaredDistance$1,4914 length: length$1,4915 squaredLength: squaredLength$1,4916 negate: negate$1,4917 inverse: inverse$1,4918 normalize: normalize$1,4919 dot: dot$1,4920 cross: cross$1,4921 lerp: lerp$1,4922 random: random$1,4923 transformMat4: transformMat4$1,4924 transformQuat: transformQuat$1,4925 zero: zero$1,4926 str: str$5,4927 exactEquals: exactEquals$5,4928 equals: equals$6,4929 sub: sub$5,4930 mul: mul$5,4931 div: div$1,4932 dist: dist$1,4933 sqrDist: sqrDist$1,4934 len: len$1,4935 sqrLen: sqrLen$1,4936 forEach: forEach$14937 });4938 /**4939 * Quaternion4940 * @module quat4941 */4942 /**4943 * Creates a new identity quat4944 *4945 * @returns {quat} a new quaternion4946 */4947 function create$6() {4948 var out = new ARRAY_TYPE(4);4949 if (ARRAY_TYPE != Float32Array) {4950 out[0] = 0;4951 out[1] = 0;4952 out[2] = 0;4953 }4954 out[3] = 1;4955 return out;4956 }4957 /**4958 * Set a quat to the identity quaternion4959 *4960 * @param {quat} out the receiving quaternion4961 * @returns {quat} out4962 */4963 function identity$4(out) {4964 out[0] = 0;4965 out[1] = 0;4966 out[2] = 0;4967 out[3] = 1;4968 return out;4969 }4970 /**4971 * Sets a quat from the given angle and rotation axis,4972 * then returns it.4973 *4974 * @param {quat} out the receiving quaternion4975 * @param {vec3} axis the axis around which to rotate4976 * @param {Number} rad the angle in radians4977 * @returns {quat} out4978 **/4979 function setAxisAngle(out, axis, rad) {4980 rad = rad * 0.5;4981 var s = Math.sin(rad);4982 out[0] = s * axis[0];4983 out[1] = s * axis[1];4984 out[2] = s * axis[2];4985 out[3] = Math.cos(rad);4986 return out;4987 }4988 /**4989 * Gets the rotation axis and angle for a given4990 * quaternion. If a quaternion is created with4991 * setAxisAngle, this method will return the same4992 * values as providied in the original parameter list4993 * OR functionally equivalent values.4994 * Example: The quaternion formed by axis [0, 0, 1] and4995 * angle -90 is the same as the quaternion formed by4996 * [0, 0, 1] and 270. This method favors the latter.4997 * @param {vec3} out_axis Vector receiving the axis of rotation4998 * @param {quat} q Quaternion to be decomposed4999 * @return {Number} Angle, in radians, of the rotation5000 */5001 function getAxisAngle(out_axis, q) {5002 var rad = Math.acos(q[3]) * 2.0;5003 var s = Math.sin(rad / 2.0);5004 if (s > EPSILON) {5005 out_axis[0] = q[0] / s;5006 out_axis[1] = q[1] / s;5007 out_axis[2] = q[2] / s;5008 } else {5009 // If s is zero, return any axis (no rotation - axis does not matter)5010 out_axis[0] = 1;5011 out_axis[1] = 0;5012 out_axis[2] = 0;5013 }5014 return rad;5015 }5016 /**5017 * Multiplies two quat's5018 *5019 * @param {quat} out the receiving quaternion5020 * @param {quat} a the first operand5021 * @param {quat} b the second operand5022 * @returns {quat} out5023 */5024 function multiply$6(out, a, b) {5025 var ax = a[0],5026 ay = a[1],5027 az = a[2],5028 aw = a[3];5029 var bx = b[0],5030 by = b[1],5031 bz = b[2],5032 bw = b[3];5033 out[0] = ax * bw + aw * bx + ay * bz - az * by;5034 out[1] = ay * bw + aw * by + az * bx - ax * bz;5035 out[2] = az * bw + aw * bz + ax * by - ay * bx;5036 out[3] = aw * bw - ax * bx - ay * by - az * bz;5037 return out;5038 }5039 /**5040 * Rotates a quaternion by the given angle about the X axis5041 *5042 * @param {quat} out quat receiving operation result5043 * @param {quat} a quat to rotate5044 * @param {number} rad angle (in radians) to rotate5045 * @returns {quat} out5046 */5047 function rotateX$2(out, a, rad) {5048 rad *= 0.5;5049 var ax = a[0],5050 ay = a[1],5051 az = a[2],5052 aw = a[3];5053 var bx = Math.sin(rad),5054 bw = Math.cos(rad);5055 out[0] = ax * bw + aw * bx;5056 out[1] = ay * bw + az * bx;5057 out[2] = az * bw - ay * bx;5058 out[3] = aw * bw - ax * bx;5059 return out;5060 }5061 /**5062 * Rotates a quaternion by the given angle about the Y axis5063 *5064 * @param {quat} out quat receiving operation result5065 * @param {quat} a quat to rotate5066 * @param {number} rad angle (in radians) to rotate5067 * @returns {quat} out5068 */5069 function rotateY$2(out, a, rad) {5070 rad *= 0.5;5071 var ax = a[0],5072 ay = a[1],5073 az = a[2],5074 aw = a[3];5075 var by = Math.sin(rad),5076 bw = Math.cos(rad);5077 out[0] = ax * bw - az * by;5078 out[1] = ay * bw + aw * by;5079 out[2] = az * bw + ax * by;5080 out[3] = aw * bw - ay * by;5081 return out;5082 }5083 /**5084 * Rotates a quaternion by the given angle about the Z axis5085 *5086 * @param {quat} out quat receiving operation result5087 * @param {quat} a quat to rotate5088 * @param {number} rad angle (in radians) to rotate5089 * @returns {quat} out5090 */5091 function rotateZ$2(out, a, rad) {5092 rad *= 0.5;5093 var ax = a[0],5094 ay = a[1],5095 az = a[2],5096 aw = a[3];5097 var bz = Math.sin(rad),5098 bw = Math.cos(rad);5099 out[0] = ax * bw + ay * bz;5100 out[1] = ay * bw - ax * bz;5101 out[2] = az * bw + aw * bz;5102 out[3] = aw * bw - az * bz;5103 return out;5104 }5105 /**5106 * Calculates the W component of a quat from the X, Y, and Z components.5107 * Assumes that quaternion is 1 unit in length.5108 * Any existing W component will be ignored.5109 *5110 * @param {quat} out the receiving quaternion5111 * @param {quat} a quat to calculate W component of5112 * @returns {quat} out5113 */5114 function calculateW(out, a) {5115 var x = a[0],5116 y = a[1],5117 z = a[2];5118 out[0] = x;5119 out[1] = y;5120 out[2] = z;5121 out[3] = Math.sqrt(Math.abs(1.0 - x * x - y * y - z * z));5122 return out;5123 }5124 /**5125 * Performs a spherical linear interpolation between two quat5126 *5127 * @param {quat} out the receiving quaternion5128 * @param {quat} a the first operand5129 * @param {quat} b the second operand5130 * @param {Number} t interpolation amount, in the range [0-1], between the two inputs5131 * @returns {quat} out5132 */5133 function slerp(out, a, b, t) {5134 // benchmarks:5135 // http://jsperf.com/quaternion-slerp-implementations5136 var ax = a[0],5137 ay = a[1],5138 az = a[2],5139 aw = a[3];5140 var bx = b[0],5141 by = b[1],5142 bz = b[2],5143 bw = b[3];5144 var omega, cosom, sinom, scale0, scale1; // calc cosine5145 cosom = ax * bx + ay * by + az * bz + aw * bw; // adjust signs (if necessary)5146 if (cosom < 0.0) {5147 cosom = -cosom;5148 bx = -bx;5149 by = -by;5150 bz = -bz;5151 bw = -bw;5152 } // calculate coefficients5153 if (1.0 - cosom > EPSILON) {5154 // standard case (slerp)5155 omega = Math.acos(cosom);5156 sinom = Math.sin(omega);5157 scale0 = Math.sin((1.0 - t) * omega) / sinom;5158 scale1 = Math.sin(t * omega) / sinom;5159 } else {5160 // "from" and "to" quaternions are very close5161 // ... so we can do a linear interpolation5162 scale0 = 1.0 - t;5163 scale1 = t;5164 } // calculate final values5165 out[0] = scale0 * ax + scale1 * bx;5166 out[1] = scale0 * ay + scale1 * by;5167 out[2] = scale0 * az + scale1 * bz;5168 out[3] = scale0 * aw + scale1 * bw;5169 return out;5170 }5171 /**5172 * Generates a random quaternion5173 *5174 * @param {quat} out the receiving quaternion5175 * @returns {quat} out5176 */5177 function random$2(out) {5178 // Implementation of http://planning.cs.uiuc.edu/node198.html5179 // TODO: Calling random 3 times is probably not the fastest solution5180 var u1 = RANDOM();5181 var u2 = RANDOM();5182 var u3 = RANDOM();5183 var sqrt1MinusU1 = Math.sqrt(1 - u1);5184 var sqrtU1 = Math.sqrt(u1);5185 out[0] = sqrt1MinusU1 * Math.sin(2.0 * Math.PI * u2);5186 out[1] = sqrt1MinusU1 * Math.cos(2.0 * Math.PI * u2);5187 out[2] = sqrtU1 * Math.sin(2.0 * Math.PI * u3);5188 out[3] = sqrtU1 * Math.cos(2.0 * Math.PI * u3);5189 return out;5190 }5191 /**5192 * Calculates the inverse of a quat5193 *5194 * @param {quat} out the receiving quaternion5195 * @param {quat} a quat to calculate inverse of5196 * @returns {quat} out5197 */5198 function invert$4(out, a) {5199 var a0 = a[0],5200 a1 = a[1],5201 a2 = a[2],5202 a3 = a[3];5203 var dot = a0 * a0 + a1 * a1 + a2 * a2 + a3 * a3;5204 var invDot = dot ? 1.0 / dot : 0; // TODO: Would be faster to return [0,0,0,0] immediately if dot == 05205 out[0] = -a0 * invDot;5206 out[1] = -a1 * invDot;5207 out[2] = -a2 * invDot;5208 out[3] = a3 * invDot;5209 return out;5210 }5211 /**5212 * Calculates the conjugate of a quat5213 * If the quaternion is normalized, this function is faster than quat.inverse and produces the same result.5214 *5215 * @param {quat} out the receiving quaternion5216 * @param {quat} a quat to calculate conjugate of5217 * @returns {quat} out5218 */5219 function conjugate(out, a) {5220 out[0] = -a[0];5221 out[1] = -a[1];5222 out[2] = -a[2];5223 out[3] = a[3];5224 return out;5225 }5226 /**5227 * Creates a quaternion from the given 3x3 rotation matrix.5228 *5229 * NOTE: The resultant quaternion is not normalized, so you should be sure5230 * to renormalize the quaternion yourself where necessary.5231 *5232 * @param {quat} out the receiving quaternion5233 * @param {mat3} m rotation matrix5234 * @returns {quat} out5235 * @function5236 */5237 function fromMat3(out, m) {5238 // Algorithm in Ken Shoemake's article in 1987 SIGGRAPH course notes5239 // article "Quaternion Calculus and Fast Animation".5240 var fTrace = m[0] + m[4] + m[8];5241 var fRoot;5242 if (fTrace > 0.0) {5243 // |w| > 1/2, may as well choose w > 1/25244 fRoot = Math.sqrt(fTrace + 1.0); // 2w5245 out[3] = 0.5 * fRoot;5246 fRoot = 0.5 / fRoot; // 1/(4w)5247 out[0] = (m[5] - m[7]) * fRoot;5248 out[1] = (m[6] - m[2]) * fRoot;5249 out[2] = (m[1] - m[3]) * fRoot;5250 } else {5251 // |w| <= 1/25252 var i = 0;5253 if (m[4] > m[0]) i = 1;5254 if (m[8] > m[i * 3 + i]) i = 2;5255 var j = (i + 1) % 3;5256 var k = (i + 2) % 3;5257 fRoot = Math.sqrt(m[i * 3 + i] - m[j * 3 + j] - m[k * 3 + k] + 1.0);5258 out[i] = 0.5 * fRoot;5259 fRoot = 0.5 / fRoot;5260 out[3] = (m[j * 3 + k] - m[k * 3 + j]) * fRoot;5261 out[j] = (m[j * 3 + i] + m[i * 3 + j]) * fRoot;5262 out[k] = (m[k * 3 + i] + m[i * 3 + k]) * fRoot;5263 }5264 return out;5265 }5266 /**5267 * Creates a quaternion from the given euler angle x, y, z.5268 *5269 * @param {quat} out the receiving quaternion5270 * @param {x} Angle to rotate around X axis in degrees.5271 * @param {y} Angle to rotate around Y axis in degrees.5272 * @param {z} Angle to rotate around Z axis in degrees.5273 * @returns {quat} out5274 * @function5275 */5276 function fromEuler(out, x, y, z) {5277 var halfToRad = 0.5 * Math.PI / 180.0;5278 x *= halfToRad;5279 y *= halfToRad;5280 z *= halfToRad;5281 var sx = Math.sin(x);5282 var cx = Math.cos(x);5283 var sy = Math.sin(y);5284 var cy = Math.cos(y);5285 var sz = Math.sin(z);5286 var cz = Math.cos(z);5287 out[0] = sx * cy * cz - cx * sy * sz;5288 out[1] = cx * sy * cz + sx * cy * sz;5289 out[2] = cx * cy * sz - sx * sy * cz;5290 out[3] = cx * cy * cz + sx * sy * sz;5291 return out;5292 }5293 /**5294 * Returns a string representation of a quatenion5295 *5296 * @param {quat} a vector to represent as a string5297 * @returns {String} string representation of the vector5298 */5299 function str$6(a) {5300 return 'quat(' + a[0] + ', ' + a[1] + ', ' + a[2] + ', ' + a[3] + ')';5301 }5302 /**5303 * Creates a new quat initialized with values from an existing quaternion5304 *5305 * @param {quat} a quaternion to clone5306 * @returns {quat} a new quaternion5307 * @function5308 */5309 var clone$6 = clone$5;5310 /**5311 * Creates a new quat initialized with the given values5312 *5313 * @param {Number} x X component5314 * @param {Number} y Y component5315 * @param {Number} z Z component5316 * @param {Number} w W component5317 * @returns {quat} a new quaternion5318 * @function5319 */5320 var fromValues$6 = fromValues$5;5321 /**5322 * Copy the values from one quat to another5323 *5324 * @param {quat} out the receiving quaternion5325 * @param {quat} a the source quaternion5326 * @returns {quat} out5327 * @function5328 */5329 var copy$6 = copy$5;5330 /**5331 * Set the components of a quat to the given values5332 *5333 * @param {quat} out the receiving quaternion5334 * @param {Number} x X component5335 * @param {Number} y Y component5336 * @param {Number} z Z component5337 * @param {Number} w W component5338 * @returns {quat} out5339 * @function5340 */5341 var set$6 = set$5;5342 /**5343 * Adds two quat's5344 *5345 * @param {quat} out the receiving quaternion5346 * @param {quat} a the first operand5347 * @param {quat} b the second operand5348 * @returns {quat} out5349 * @function5350 */5351 var add$6 = add$5;5352 /**5353 * Alias for {@link quat.multiply}5354 * @function5355 */5356 var mul$6 = multiply$6;5357 /**5358 * Scales a quat by a scalar number5359 *5360 * @param {quat} out the receiving vector5361 * @param {quat} a the vector to scale5362 * @param {Number} b amount to scale the vector by5363 * @returns {quat} out5364 * @function5365 */5366 var scale$6 = scale$5;5367 /**5368 * Calculates the dot product of two quat's5369 *5370 * @param {quat} a the first operand5371 * @param {quat} b the second operand5372 * @returns {Number} dot product of a and b5373 * @function5374 */5375 var dot$2 = dot$1;5376 /**5377 * Performs a linear interpolation between two quat's5378 *5379 * @param {quat} out the receiving quaternion5380 * @param {quat} a the first operand5381 * @param {quat} b the second operand5382 * @param {Number} t interpolation amount, in the range [0-1], between the two inputs5383 * @returns {quat} out5384 * @function5385 */5386 var lerp$2 = lerp$1;5387 /**5388 * Calculates the length of a quat5389 *5390 * @param {quat} a vector to calculate length of5391 * @returns {Number} length of a5392 */5393 var length$2 = length$1;5394 /**5395 * Alias for {@link quat.length}5396 * @function5397 */5398 var len$2 = length$2;5399 /**5400 * Calculates the squared length of a quat5401 *5402 * @param {quat} a vector to calculate squared length of5403 * @returns {Number} squared length of a5404 * @function5405 */5406 var squaredLength$2 = squaredLength$1;5407 /**5408 * Alias for {@link quat.squaredLength}5409 * @function5410 */5411 var sqrLen$2 = squaredLength$2;5412 /**5413 * Normalize a quat5414 *5415 * @param {quat} out the receiving quaternion5416 * @param {quat} a quaternion to normalize5417 * @returns {quat} out5418 * @function5419 */5420 var normalize$2 = normalize$1;5421 /**5422 * Returns whether or not the quaternions have exactly the same elements in the same position (when compared with ===)5423 *5424 * @param {quat} a The first quaternion.5425 * @param {quat} b The second quaternion.5426 * @returns {Boolean} True if the vectors are equal, false otherwise.5427 */5428 var exactEquals$6 = exactEquals$5;5429 /**5430 * Returns whether or not the quaternions have approximately the same elements in the same position.5431 *5432 * @param {quat} a The first vector.5433 * @param {quat} b The second vector.5434 * @returns {Boolean} True if the vectors are equal, false otherwise.5435 */5436 var equals$7 = equals$6;5437 /**5438 * Sets a quaternion to represent the shortest rotation from one5439 * vector to another.5440 *5441 * Both vectors are assumed to be unit length.5442 *5443 * @param {quat} out the receiving quaternion.5444 * @param {vec3} a the initial vector5445 * @param {vec3} b the destination vector5446 * @returns {quat} out5447 */5448 var rotationTo = function () {5449 var tmpvec3 = create$4();5450 var xUnitVec3 = fromValues$4(1, 0, 0);5451 var yUnitVec3 = fromValues$4(0, 1, 0);5452 return function (out, a, b) {5453 var dot$1 = dot(a, b);5454 if (dot$1 < -0.999999) {5455 cross(tmpvec3, xUnitVec3, a);5456 if (len(tmpvec3) < 0.000001) cross(tmpvec3, yUnitVec3, a);5457 normalize(tmpvec3, tmpvec3);5458 setAxisAngle(out, tmpvec3, Math.PI);5459 return out;5460 } else if (dot$1 > 0.999999) {5461 out[0] = 0;5462 out[1] = 0;5463 out[2] = 0;5464 out[3] = 1;5465 return out;5466 } else {5467 cross(tmpvec3, a, b);5468 out[0] = tmpvec3[0];5469 out[1] = tmpvec3[1];5470 out[2] = tmpvec3[2];5471 out[3] = 1 + dot$1;5472 return normalize$2(out, out);5473 }5474 };5475 }();5476 /**5477 * Performs a spherical linear interpolation with two control points5478 *5479 * @param {quat} out the receiving quaternion5480 * @param {quat} a the first operand5481 * @param {quat} b the second operand5482 * @param {quat} c the third operand5483 * @param {quat} d the fourth operand5484 * @param {Number} t interpolation amount, in the range [0-1], between the two inputs5485 * @returns {quat} out5486 */5487 var sqlerp = function () {5488 var temp1 = create$6();5489 var temp2 = create$6();5490 return function (out, a, b, c, d, t) {5491 slerp(temp1, a, d, t);5492 slerp(temp2, b, c, t);5493 slerp(out, temp1, temp2, 2 * t * (1 - t));5494 return out;5495 };5496 }();5497 /**5498 * Sets the specified quaternion with values corresponding to the given5499 * axes. Each axis is a vec3 and is expected to be unit length and5500 * perpendicular to all other specified axes.5501 *5502 * @param {vec3} view the vector representing the viewing direction5503 * @param {vec3} right the vector representing the local "right" direction5504 * @param {vec3} up the vector representing the local "up" direction5505 * @returns {quat} out5506 */5507 var setAxes = function () {5508 var matr = create$2();5509 return function (out, view, right, up) {5510 matr[0] = right[0];5511 matr[3] = right[1];5512 matr[6] = right[2];5513 matr[1] = up[0];5514 matr[4] = up[1];5515 matr[7] = up[2];5516 matr[2] = -view[0];5517 matr[5] = -view[1];5518 matr[8] = -view[2];5519 return normalize$2(out, fromMat3(out, matr));5520 };5521 }();5522 var quat = /*#__PURE__*/Object.freeze({5523 create: create$6,5524 identity: identity$4,5525 setAxisAngle: setAxisAngle,5526 getAxisAngle: getAxisAngle,5527 multiply: multiply$6,5528 rotateX: rotateX$2,5529 rotateY: rotateY$2,5530 rotateZ: rotateZ$2,5531 calculateW: calculateW,5532 slerp: slerp,5533 random: random$2,5534 invert: invert$4,5535 conjugate: conjugate,5536 fromMat3: fromMat3,5537 fromEuler: fromEuler,5538 str: str$6,5539 clone: clone$6,5540 fromValues: fromValues$6,5541 copy: copy$6,5542 set: set$6,5543 add: add$6,5544 mul: mul$6,5545 scale: scale$6,5546 dot: dot$2,5547 lerp: lerp$2,5548 length: length$2,5549 len: len$2,5550 squaredLength: squaredLength$2,5551 sqrLen: sqrLen$2,5552 normalize: normalize$2,5553 exactEquals: exactEquals$6,5554 equals: equals$7,5555 rotationTo: rotationTo,5556 sqlerp: sqlerp,5557 setAxes: setAxes5558 });5559 /**5560 * Dual Quaternion<br>5561 * Format: [real, dual]<br>5562 * Quaternion format: XYZW<br>5563 * Make sure to have normalized dual quaternions, otherwise the functions may not work as intended.<br>5564 * @module quat25565 */5566 /**5567 * Creates a new identity dual quat5568 *5569 * @returns {quat2} a new dual quaternion [real -> rotation, dual -> translation]5570 */5571 function create$7() {5572 var dq = new ARRAY_TYPE(8);5573 if (ARRAY_TYPE != Float32Array) {5574 dq[0] = 0;5575 dq[1] = 0;5576 dq[2] = 0;5577 dq[4] = 0;5578 dq[5] = 0;5579 dq[6] = 0;5580 dq[7] = 0;5581 }5582 dq[3] = 1;5583 return dq;5584 }5585 /**5586 * Creates a new quat initialized with values from an existing quaternion5587 *5588 * @param {quat2} a dual quaternion to clone5589 * @returns {quat2} new dual quaternion5590 * @function5591 */5592 function clone$7(a) {5593 var dq = new ARRAY_TYPE(8);5594 dq[0] = a[0];5595 dq[1] = a[1];5596 dq[2] = a[2];5597 dq[3] = a[3];5598 dq[4] = a[4];5599 dq[5] = a[5];5600 dq[6] = a[6];5601 dq[7] = a[7];5602 return dq;5603 }5604 /**5605 * Creates a new dual quat initialized with the given values5606 *5607 * @param {Number} x1 X component5608 * @param {Number} y1 Y component5609 * @param {Number} z1 Z component5610 * @param {Number} w1 W component5611 * @param {Number} x2 X component5612 * @param {Number} y2 Y component5613 * @param {Number} z2 Z component5614 * @param {Number} w2 W component5615 * @returns {quat2} new dual quaternion5616 * @function5617 */5618 function fromValues$7(x1, y1, z1, w1, x2, y2, z2, w2) {5619 var dq = new ARRAY_TYPE(8);5620 dq[0] = x1;5621 dq[1] = y1;5622 dq[2] = z1;5623 dq[3] = w1;5624 dq[4] = x2;5625 dq[5] = y2;5626 dq[6] = z2;5627 dq[7] = w2;5628 return dq;5629 }5630 /**5631 * Creates a new dual quat from the given values (quat and translation)5632 *5633 * @param {Number} x1 X component5634 * @param {Number} y1 Y component5635 * @param {Number} z1 Z component5636 * @param {Number} w1 W component5637 * @param {Number} x2 X component (translation)5638 * @param {Number} y2 Y component (translation)5639 * @param {Number} z2 Z component (translation)5640 * @returns {quat2} new dual quaternion5641 * @function5642 */5643 function fromRotationTranslationValues(x1, y1, z1, w1, x2, y2, z2) {5644 var dq = new ARRAY_TYPE(8);5645 dq[0] = x1;5646 dq[1] = y1;5647 dq[2] = z1;5648 dq[3] = w1;5649 var ax = x2 * 0.5,5650 ay = y2 * 0.5,5651 az = z2 * 0.5;5652 dq[4] = ax * w1 + ay * z1 - az * y1;5653 dq[5] = ay * w1 + az * x1 - ax * z1;5654 dq[6] = az * w1 + ax * y1 - ay * x1;5655 dq[7] = -ax * x1 - ay * y1 - az * z1;5656 return dq;5657 }5658 /**5659 * Creates a dual quat from a quaternion and a translation5660 *5661 * @param {quat2} dual quaternion receiving operation result5662 * @param {quat} q a normalized quaternion5663 * @param {vec3} t tranlation vector5664 * @returns {quat2} dual quaternion receiving operation result5665 * @function5666 */5667 function fromRotationTranslation$1(out, q, t) {5668 var ax = t[0] * 0.5,5669 ay = t[1] * 0.5,5670 az = t[2] * 0.5,5671 bx = q[0],5672 by = q[1],5673 bz = q[2],5674 bw = q[3];5675 out[0] = bx;5676 out[1] = by;5677 out[2] = bz;5678 out[3] = bw;5679 out[4] = ax * bw + ay * bz - az * by;5680 out[5] = ay * bw + az * bx - ax * bz;5681 out[6] = az * bw + ax * by - ay * bx;5682 out[7] = -ax * bx - ay * by - az * bz;5683 return out;5684 }5685 /**5686 * Creates a dual quat from a translation5687 *5688 * @param {quat2} dual quaternion receiving operation result5689 * @param {vec3} t translation vector5690 * @returns {quat2} dual quaternion receiving operation result5691 * @function5692 */5693 function fromTranslation$3(out, t) {5694 out[0] = 0;5695 out[1] = 0;5696 out[2] = 0;5697 out[3] = 1;5698 out[4] = t[0] * 0.5;5699 out[5] = t[1] * 0.5;5700 out[6] = t[2] * 0.5;5701 out[7] = 0;5702 return out;5703 }5704 /**5705 * Creates a dual quat from a quaternion5706 *5707 * @param {quat2} dual quaternion receiving operation result5708 * @param {quat} q the quaternion5709 * @returns {quat2} dual quaternion receiving operation result5710 * @function5711 */5712 function fromRotation$4(out, q) {5713 out[0] = q[0];5714 out[1] = q[1];5715 out[2] = q[2];5716 out[3] = q[3];5717 out[4] = 0;5718 out[5] = 0;5719 out[6] = 0;5720 out[7] = 0;5721 return out;5722 }5723 /**5724 * Creates a new dual quat from a matrix (4x4)5725 *5726 * @param {quat2} out the dual quaternion5727 * @param {mat4} a the matrix5728 * @returns {quat2} dual quat receiving operation result5729 * @function5730 */5731 function fromMat4$1(out, a) {5732 //TODO Optimize this5733 var outer = create$6();5734 getRotation(outer, a);5735 var t = new ARRAY_TYPE(3);5736 getTranslation(t, a);5737 fromRotationTranslation$1(out, outer, t);5738 return out;5739 }5740 /**5741 * Copy the values from one dual quat to another5742 *5743 * @param {quat2} out the receiving dual quaternion5744 * @param {quat2} a the source dual quaternion5745 * @returns {quat2} out5746 * @function5747 */5748 function copy$7(out, a) {5749 out[0] = a[0];5750 out[1] = a[1];5751 out[2] = a[2];5752 out[3] = a[3];5753 out[4] = a[4];5754 out[5] = a[5];5755 out[6] = a[6];5756 out[7] = a[7];5757 return out;5758 }5759 /**5760 * Set a dual quat to the identity dual quaternion5761 *5762 * @param {quat2} out the receiving quaternion5763 * @returns {quat2} out5764 */5765 function identity$5(out) {5766 out[0] = 0;5767 out[1] = 0;5768 out[2] = 0;5769 out[3] = 1;5770 out[4] = 0;5771 out[5] = 0;5772 out[6] = 0;5773 out[7] = 0;5774 return out;5775 }5776 /**5777 * Set the components of a dual quat to the given values5778 *5779 * @param {quat2} out the receiving quaternion5780 * @param {Number} x1 X component5781 * @param {Number} y1 Y component5782 * @param {Number} z1 Z component5783 * @param {Number} w1 W component5784 * @param {Number} x2 X component5785 * @param {Number} y2 Y component5786 * @param {Number} z2 Z component5787 * @param {Number} w2 W component5788 * @returns {quat2} out5789 * @function5790 */5791 function set$7(out, x1, y1, z1, w1, x2, y2, z2, w2) {5792 out[0] = x1;5793 out[1] = y1;5794 out[2] = z1;5795 out[3] = w1;5796 out[4] = x2;5797 out[5] = y2;5798 out[6] = z2;5799 out[7] = w2;5800 return out;5801 }5802 /**5803 * Gets the real part of a dual quat5804 * @param {quat} out real part5805 * @param {quat2} a Dual Quaternion5806 * @return {quat} real part5807 */5808 var getReal = copy$6;5809 /**5810 * Gets the dual part of a dual quat5811 * @param {quat} out dual part5812 * @param {quat2} a Dual Quaternion5813 * @return {quat} dual part5814 */5815 function getDual(out, a) {5816 out[0] = a[4];5817 out[1] = a[5];5818 out[2] = a[6];5819 out[3] = a[7];5820 return out;5821 }5822 /**5823 * Set the real component of a dual quat to the given quaternion5824 *5825 * @param {quat2} out the receiving quaternion5826 * @param {quat} q a quaternion representing the real part5827 * @returns {quat2} out5828 * @function5829 */5830 var setReal = copy$6;5831 /**5832 * Set the dual component of a dual quat to the given quaternion5833 *5834 * @param {quat2} out the receiving quaternion5835 * @param {quat} q a quaternion representing the dual part5836 * @returns {quat2} out5837 * @function5838 */5839 function setDual(out, q) {5840 out[4] = q[0];5841 out[5] = q[1];5842 out[6] = q[2];5843 out[7] = q[3];5844 return out;5845 }5846 /**5847 * Gets the translation of a normalized dual quat5848 * @param {vec3} out translation5849 * @param {quat2} a Dual Quaternion to be decomposed5850 * @return {vec3} translation5851 */5852 function getTranslation$1(out, a) {5853 var ax = a[4],5854 ay = a[5],5855 az = a[6],5856 aw = a[7],5857 bx = -a[0],5858 by = -a[1],5859 bz = -a[2],5860 bw = a[3];5861 out[0] = (ax * bw + aw * bx + ay * bz - az * by) * 2;5862 out[1] = (ay * bw + aw * by + az * bx - ax * bz) * 2;5863 out[2] = (az * bw + aw * bz + ax * by - ay * bx) * 2;5864 return out;5865 }5866 /**5867 * Translates a dual quat by the given vector5868 *5869 * @param {quat2} out the receiving dual quaternion5870 * @param {quat2} a the dual quaternion to translate5871 * @param {vec3} v vector to translate by5872 * @returns {quat2} out5873 */5874 function translate$3(out, a, v) {5875 var ax1 = a[0],5876 ay1 = a[1],5877 az1 = a[2],5878 aw1 = a[3],5879 bx1 = v[0] * 0.5,5880 by1 = v[1] * 0.5,5881 bz1 = v[2] * 0.5,5882 ax2 = a[4],5883 ay2 = a[5],5884 az2 = a[6],5885 aw2 = a[7];5886 out[0] = ax1;5887 out[1] = ay1;5888 out[2] = az1;5889 out[3] = aw1;5890 out[4] = aw1 * bx1 + ay1 * bz1 - az1 * by1 + ax2;5891 out[5] = aw1 * by1 + az1 * bx1 - ax1 * bz1 + ay2;5892 out[6] = aw1 * bz1 + ax1 * by1 - ay1 * bx1 + az2;5893 out[7] = -ax1 * bx1 - ay1 * by1 - az1 * bz1 + aw2;5894 return out;5895 }5896 /**5897 * Rotates a dual quat around the X axis5898 *5899 * @param {quat2} out the receiving dual quaternion5900 * @param {quat2} a the dual quaternion to rotate5901 * @param {number} rad how far should the rotation be5902 * @returns {quat2} out5903 */5904 function rotateX$3(out, a, rad) {5905 var bx = -a[0],5906 by = -a[1],5907 bz = -a[2],5908 bw = a[3],5909 ax = a[4],5910 ay = a[5],5911 az = a[6],5912 aw = a[7],5913 ax1 = ax * bw + aw * bx + ay * bz - az * by,5914 ay1 = ay * bw + aw * by + az * bx - ax * bz,5915 az1 = az * bw + aw * bz + ax * by - ay * bx,5916 aw1 = aw * bw - ax * bx - ay * by - az * bz;5917 rotateX$2(out, a, rad);5918 bx = out[0];5919 by = out[1];5920 bz = out[2];5921 bw = out[3];5922 out[4] = ax1 * bw + aw1 * bx + ay1 * bz - az1 * by;5923 out[5] = ay1 * bw + aw1 * by + az1 * bx - ax1 * bz;5924 out[6] = az1 * bw + aw1 * bz + ax1 * by - ay1 * bx;5925 out[7] = aw1 * bw - ax1 * bx - ay1 * by - az1 * bz;5926 return out;5927 }5928 /**5929 * Rotates a dual quat around the Y axis5930 *5931 * @param {quat2} out the receiving dual quaternion5932 * @param {quat2} a the dual quaternion to rotate5933 * @param {number} rad how far should the rotation be5934 * @returns {quat2} out5935 */5936 function rotateY$3(out, a, rad) {5937 var bx = -a[0],5938 by = -a[1],5939 bz = -a[2],5940 bw = a[3],5941 ax = a[4],5942 ay = a[5],5943 az = a[6],5944 aw = a[7],5945 ax1 = ax * bw + aw * bx + ay * bz - az * by,5946 ay1 = ay * bw + aw * by + az * bx - ax * bz,5947 az1 = az * bw + aw * bz + ax * by - ay * bx,5948 aw1 = aw * bw - ax * bx - ay * by - az * bz;5949 rotateY$2(out, a, rad);5950 bx = out[0];5951 by = out[1];5952 bz = out[2];5953 bw = out[3];5954 out[4] = ax1 * bw + aw1 * bx + ay1 * bz - az1 * by;5955 out[5] = ay1 * bw + aw1 * by + az1 * bx - ax1 * bz;5956 out[6] = az1 * bw + aw1 * bz + ax1 * by - ay1 * bx;5957 out[7] = aw1 * bw - ax1 * bx - ay1 * by - az1 * bz;5958 return out;5959 }5960 /**5961 * Rotates a dual quat around the Z axis5962 *5963 * @param {quat2} out the receiving dual quaternion5964 * @param {quat2} a the dual quaternion to rotate5965 * @param {number} rad how far should the rotation be5966 * @returns {quat2} out5967 */5968 function rotateZ$3(out, a, rad) {5969 var bx = -a[0],5970 by = -a[1],5971 bz = -a[2],5972 bw = a[3],5973 ax = a[4],5974 ay = a[5],5975 az = a[6],5976 aw = a[7],5977 ax1 = ax * bw + aw * bx + ay * bz - az * by,5978 ay1 = ay * bw + aw * by + az * bx - ax * bz,5979 az1 = az * bw + aw * bz + ax * by - ay * bx,5980 aw1 = aw * bw - ax * bx - ay * by - az * bz;5981 rotateZ$2(out, a, rad);5982 bx = out[0];5983 by = out[1];5984 bz = out[2];5985 bw = out[3];5986 out[4] = ax1 * bw + aw1 * bx + ay1 * bz - az1 * by;5987 out[5] = ay1 * bw + aw1 * by + az1 * bx - ax1 * bz;5988 out[6] = az1 * bw + aw1 * bz + ax1 * by - ay1 * bx;5989 out[7] = aw1 * bw - ax1 * bx - ay1 * by - az1 * bz;5990 return out;5991 }5992 /**5993 * Rotates a dual quat by a given quaternion (a * q)5994 *5995 * @param {quat2} out the receiving dual quaternion5996 * @param {quat2} a the dual quaternion to rotate5997 * @param {quat} q quaternion to rotate by5998 * @returns {quat2} out5999 */6000 function rotateByQuatAppend(out, a, q) {6001 var qx = q[0],6002 qy = q[1],6003 qz = q[2],6004 qw = q[3],6005 ax = a[0],6006 ay = a[1],6007 az = a[2],6008 aw = a[3];6009 out[0] = ax * qw + aw * qx + ay * qz - az * qy;6010 out[1] = ay * qw + aw * qy + az * qx - ax * qz;6011 out[2] = az * qw + aw * qz + ax * qy - ay * qx;6012 out[3] = aw * qw - ax * qx - ay * qy - az * qz;6013 ax = a[4];6014 ay = a[5];6015 az = a[6];6016 aw = a[7];6017 out[4] = ax * qw + aw * qx + ay * qz - az * qy;6018 out[5] = ay * qw + aw * qy + az * qx - ax * qz;6019 out[6] = az * qw + aw * qz + ax * qy - ay * qx;6020 out[7] = aw * qw - ax * qx - ay * qy - az * qz;6021 return out;6022 }6023 /**6024 * Rotates a dual quat by a given quaternion (q * a)6025 *6026 * @param {quat2} out the receiving dual quaternion6027 * @param {quat} q quaternion to rotate by6028 * @param {quat2} a the dual quaternion to rotate6029 * @returns {quat2} out6030 */6031 function rotateByQuatPrepend(out, q, a) {6032 var qx = q[0],6033 qy = q[1],6034 qz = q[2],6035 qw = q[3],6036 bx = a[0],6037 by = a[1],6038 bz = a[2],6039 bw = a[3];6040 out[0] = qx * bw + qw * bx + qy * bz - qz * by;6041 out[1] = qy * bw + qw * by + qz * bx - qx * bz;6042 out[2] = qz * bw + qw * bz + qx * by - qy * bx;6043 out[3] = qw * bw - qx * bx - qy * by - qz * bz;6044 bx = a[4];6045 by = a[5];6046 bz = a[6];6047 bw = a[7];6048 out[4] = qx * bw + qw * bx + qy * bz - qz * by;6049 out[5] = qy * bw + qw * by + qz * bx - qx * bz;6050 out[6] = qz * bw + qw * bz + qx * by - qy * bx;6051 out[7] = qw * bw - qx * bx - qy * by - qz * bz;6052 return out;6053 }6054 /**6055 * Rotates a dual quat around a given axis. Does the normalisation automatically6056 *6057 * @param {quat2} out the receiving dual quaternion6058 * @param {quat2} a the dual quaternion to rotate6059 * @param {vec3} axis the axis to rotate around6060 * @param {Number} rad how far the rotation should be6061 * @returns {quat2} out6062 */6063 function rotateAroundAxis(out, a, axis, rad) {6064 //Special case for rad = 06065 if (Math.abs(rad) < EPSILON) {6066 return copy$7(out, a);6067 }6068 var axisLength = Math.hypot(axis[0], axis[1], axis[2]);6069 rad = rad * 0.5;6070 var s = Math.sin(rad);6071 var bx = s * axis[0] / axisLength;6072 var by = s * axis[1] / axisLength;6073 var bz = s * axis[2] / axisLength;6074 var bw = Math.cos(rad);6075 var ax1 = a[0],6076 ay1 = a[1],6077 az1 = a[2],6078 aw1 = a[3];6079 out[0] = ax1 * bw + aw1 * bx + ay1 * bz - az1 * by;6080 out[1] = ay1 * bw + aw1 * by + az1 * bx - ax1 * bz;6081 out[2] = az1 * bw + aw1 * bz + ax1 * by - ay1 * bx;6082 out[3] = aw1 * bw - ax1 * bx - ay1 * by - az1 * bz;6083 var ax = a[4],6084 ay = a[5],6085 az = a[6],6086 aw = a[7];6087 out[4] = ax * bw + aw * bx + ay * bz - az * by;6088 out[5] = ay * bw + aw * by + az * bx - ax * bz;6089 out[6] = az * bw + aw * bz + ax * by - ay * bx;6090 out[7] = aw * bw - ax * bx - ay * by - az * bz;6091 return out;6092 }6093 /**6094 * Adds two dual quat's6095 *6096 * @param {quat2} out the receiving dual quaternion6097 * @param {quat2} a the first operand6098 * @param {quat2} b the second operand6099 * @returns {quat2} out6100 * @function6101 */6102 function add$7(out, a, b) {6103 out[0] = a[0] + b[0];6104 out[1] = a[1] + b[1];6105 out[2] = a[2] + b[2];6106 out[3] = a[3] + b[3];6107 out[4] = a[4] + b[4];6108 out[5] = a[5] + b[5];6109 out[6] = a[6] + b[6];6110 out[7] = a[7] + b[7];6111 return out;6112 }6113 /**6114 * Multiplies two dual quat's6115 *6116 * @param {quat2} out the receiving dual quaternion6117 * @param {quat2} a the first operand6118 * @param {quat2} b the second operand6119 * @returns {quat2} out6120 */6121 function multiply$7(out, a, b) {6122 var ax0 = a[0],6123 ay0 = a[1],6124 az0 = a[2],6125 aw0 = a[3],6126 bx1 = b[4],6127 by1 = b[5],6128 bz1 = b[6],6129 bw1 = b[7],6130 ax1 = a[4],6131 ay1 = a[5],6132 az1 = a[6],6133 aw1 = a[7],6134 bx0 = b[0],6135 by0 = b[1],6136 bz0 = b[2],6137 bw0 = b[3];6138 out[0] = ax0 * bw0 + aw0 * bx0 + ay0 * bz0 - az0 * by0;6139 out[1] = ay0 * bw0 + aw0 * by0 + az0 * bx0 - ax0 * bz0;6140 out[2] = az0 * bw0 + aw0 * bz0 + ax0 * by0 - ay0 * bx0;6141 out[3] = aw0 * bw0 - ax0 * bx0 - ay0 * by0 - az0 * bz0;6142 out[4] = ax0 * bw1 + aw0 * bx1 + ay0 * bz1 - az0 * by1 + ax1 * bw0 + aw1 * bx0 + ay1 * bz0 - az1 * by0;6143 out[5] = ay0 * bw1 + aw0 * by1 + az0 * bx1 - ax0 * bz1 + ay1 * bw0 + aw1 * by0 + az1 * bx0 - ax1 * bz0;6144 out[6] = az0 * bw1 + aw0 * bz1 + ax0 * by1 - ay0 * bx1 + az1 * bw0 + aw1 * bz0 + ax1 * by0 - ay1 * bx0;6145 out[7] = aw0 * bw1 - ax0 * bx1 - ay0 * by1 - az0 * bz1 + aw1 * bw0 - ax1 * bx0 - ay1 * by0 - az1 * bz0;6146 return out;6147 }6148 /**6149 * Alias for {@link quat2.multiply}6150 * @function6151 */6152 var mul$7 = multiply$7;6153 /**6154 * Scales a dual quat by a scalar number6155 *6156 * @param {quat2} out the receiving dual quat6157 * @param {quat2} a the dual quat to scale6158 * @param {Number} b amount to scale the dual quat by6159 * @returns {quat2} out6160 * @function6161 */6162 function scale$7(out, a, b) {6163 out[0] = a[0] * b;6164 out[1] = a[1] * b;6165 out[2] = a[2] * b;6166 out[3] = a[3] * b;6167 out[4] = a[4] * b;6168 out[5] = a[5] * b;6169 out[6] = a[6] * b;6170 out[7] = a[7] * b;6171 return out;6172 }6173 /**6174 * Calculates the dot product of two dual quat's (The dot product of the real parts)6175 *6176 * @param {quat2} a the first operand6177 * @param {quat2} b the second operand6178 * @returns {Number} dot product of a and b6179 * @function6180 */6181 var dot$3 = dot$2;6182 /**6183 * Performs a linear interpolation between two dual quats's6184 * NOTE: The resulting dual quaternions won't always be normalized (The error is most noticeable when t = 0.5)6185 *6186 * @param {quat2} out the receiving dual quat6187 * @param {quat2} a the first operand6188 * @param {quat2} b the second operand6189 * @param {Number} t interpolation amount, in the range [0-1], between the two inputs6190 * @returns {quat2} out6191 */6192 function lerp$3(out, a, b, t) {6193 var mt = 1 - t;6194 if (dot$3(a, b) < 0) t = -t;6195 out[0] = a[0] * mt + b[0] * t;6196 out[1] = a[1] * mt + b[1] * t;6197 out[2] = a[2] * mt + b[2] * t;6198 out[3] = a[3] * mt + b[3] * t;6199 out[4] = a[4] * mt + b[4] * t;6200 out[5] = a[5] * mt + b[5] * t;6201 out[6] = a[6] * mt + b[6] * t;6202 out[7] = a[7] * mt + b[7] * t;6203 return out;6204 }6205 /**6206 * Calculates the inverse of a dual quat. If they are normalized, conjugate is cheaper6207 *6208 * @param {quat2} out the receiving dual quaternion6209 * @param {quat2} a dual quat to calculate inverse of6210 * @returns {quat2} out6211 */6212 function invert$5(out, a) {6213 var sqlen = squaredLength$3(a);6214 out[0] = -a[0] / sqlen;6215 out[1] = -a[1] / sqlen;6216 out[2] = -a[2] / sqlen;6217 out[3] = a[3] / sqlen;6218 out[4] = -a[4] / sqlen;6219 out[5] = -a[5] / sqlen;6220 out[6] = -a[6] / sqlen;6221 out[7] = a[7] / sqlen;6222 return out;6223 }6224 /**6225 * Calculates the conjugate of a dual quat6226 * If the dual quaternion is normalized, this function is faster than quat2.inverse and produces the same result.6227 *6228 * @param {quat2} out the receiving quaternion6229 * @param {quat2} a quat to calculate conjugate of6230 * @returns {quat2} out6231 */6232 function conjugate$1(out, a) {6233 out[0] = -a[0];6234 out[1] = -a[1];6235 out[2] = -a[2];6236 out[3] = a[3];6237 out[4] = -a[4];6238 out[5] = -a[5];6239 out[6] = -a[6];6240 out[7] = a[7];6241 return out;6242 }6243 /**6244 * Calculates the length of a dual quat6245 *6246 * @param {quat2} a dual quat to calculate length of6247 * @returns {Number} length of a6248 * @function6249 */6250 var length$3 = length$2;6251 /**6252 * Alias for {@link quat2.length}6253 * @function6254 */6255 var len$3 = length$3;6256 /**6257 * Calculates the squared length of a dual quat6258 *6259 * @param {quat2} a dual quat to calculate squared length of6260 * @returns {Number} squared length of a6261 * @function6262 */6263 var squaredLength$3 = squaredLength$2;6264 /**6265 * Alias for {@link quat2.squaredLength}6266 * @function6267 */6268 var sqrLen$3 = squaredLength$3;6269 /**6270 * Normalize a dual quat6271 *6272 * @param {quat2} out the receiving dual quaternion6273 * @param {quat2} a dual quaternion to normalize6274 * @returns {quat2} out6275 * @function6276 */6277 function normalize$3(out, a) {6278 var magnitude = squaredLength$3(a);6279 if (magnitude > 0) {6280 magnitude = Math.sqrt(magnitude);6281 var a0 = a[0] / magnitude;6282 var a1 = a[1] / magnitude;6283 var a2 = a[2] / magnitude;6284 var a3 = a[3] / magnitude;6285 var b0 = a[4];6286 var b1 = a[5];6287 var b2 = a[6];6288 var b3 = a[7];6289 var a_dot_b = a0 * b0 + a1 * b1 + a2 * b2 + a3 * b3;6290 out[0] = a0;6291 out[1] = a1;6292 out[2] = a2;6293 out[3] = a3;6294 out[4] = (b0 - a0 * a_dot_b) / magnitude;6295 out[5] = (b1 - a1 * a_dot_b) / magnitude;6296 out[6] = (b2 - a2 * a_dot_b) / magnitude;6297 out[7] = (b3 - a3 * a_dot_b) / magnitude;6298 }6299 return out;6300 }6301 /**6302 * Returns a string representation of a dual quatenion6303 *6304 * @param {quat2} a dual quaternion to represent as a string6305 * @returns {String} string representation of the dual quat6306 */6307 function str$7(a) {6308 return 'quat2(' + a[0] + ', ' + a[1] + ', ' + a[2] + ', ' + a[3] + ', ' + a[4] + ', ' + a[5] + ', ' + a[6] + ', ' + a[7] + ')';6309 }6310 /**6311 * Returns whether or not the dual quaternions have exactly the same elements in the same position (when compared with ===)6312 *6313 * @param {quat2} a the first dual quaternion.6314 * @param {quat2} b the second dual quaternion.6315 * @returns {Boolean} true if the dual quaternions are equal, false otherwise.6316 */6317 function exactEquals$7(a, b) {6318 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];6319 }6320 /**6321 * Returns whether or not the dual quaternions have approximately the same elements in the same position.6322 *6323 * @param {quat2} a the first dual quat.6324 * @param {quat2} b the second dual quat.6325 * @returns {Boolean} true if the dual quats are equal, false otherwise.6326 */6327 function equals$8(a, b) {6328 var a0 = a[0],6329 a1 = a[1],6330 a2 = a[2],6331 a3 = a[3],6332 a4 = a[4],6333 a5 = a[5],6334 a6 = a[6],6335 a7 = a[7];6336 var b0 = b[0],6337 b1 = b[1],6338 b2 = b[2],6339 b3 = b[3],6340 b4 = b[4],6341 b5 = b[5],6342 b6 = b[6],6343 b7 = b[7];6344 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));6345 }6346 var quat2 = /*#__PURE__*/Object.freeze({6347 create: create$7,6348 clone: clone$7,6349 fromValues: fromValues$7,6350 fromRotationTranslationValues: fromRotationTranslationValues,6351 fromRotationTranslation: fromRotationTranslation$1,6352 fromTranslation: fromTranslation$3,6353 fromRotation: fromRotation$4,6354 fromMat4: fromMat4$1,6355 copy: copy$7,6356 identity: identity$5,6357 set: set$7,6358 getReal: getReal,6359 getDual: getDual,6360 setReal: setReal,6361 setDual: setDual,6362 getTranslation: getTranslation$1,6363 translate: translate$3,6364 rotateX: rotateX$3,6365 rotateY: rotateY$3,6366 rotateZ: rotateZ$3,6367 rotateByQuatAppend: rotateByQuatAppend,6368 rotateByQuatPrepend: rotateByQuatPrepend,6369 rotateAroundAxis: rotateAroundAxis,6370 add: add$7,6371 multiply: multiply$7,6372 mul: mul$7,6373 scale: scale$7,6374 dot: dot$3,6375 lerp: lerp$3,6376 invert: invert$5,6377 conjugate: conjugate$1,6378 length: length$3,6379 len: len$3,6380 squaredLength: squaredLength$3,6381 sqrLen: sqrLen$3,6382 normalize: normalize$3,6383 str: str$7,6384 exactEquals: exactEquals$7,6385 equals: equals$86386 });6387 /**6388 * 2 Dimensional Vector6389 * @module vec26390 */6391 /**6392 * Creates a new, empty vec26393 *6394 * @returns {vec2} a new 2D vector6395 */6396 function create$8() {6397 var out = new ARRAY_TYPE(2);6398 if (ARRAY_TYPE != Float32Array) {6399 out[0] = 0;6400 out[1] = 0;6401 }6402 return out;6403 }6404 /**6405 * Creates a new vec2 initialized with values from an existing vector6406 *6407 * @param {vec2} a vector to clone6408 * @returns {vec2} a new 2D vector6409 */6410 function clone$8(a) {6411 var out = new ARRAY_TYPE(2);6412 out[0] = a[0];6413 out[1] = a[1];6414 return out;6415 }6416 /**6417 * Creates a new vec2 initialized with the given values6418 *6419 * @param {Number} x X component6420 * @param {Number} y Y component6421 * @returns {vec2} a new 2D vector6422 */6423 function fromValues$8(x, y) {6424 var out = new ARRAY_TYPE(2);6425 out[0] = x;6426 out[1] = y;6427 return out;6428 }6429 /**6430 * Copy the values from one vec2 to another6431 *6432 * @param {vec2} out the receiving vector6433 * @param {vec2} a the source vector6434 * @returns {vec2} out6435 */6436 function copy$8(out, a) {6437 out[0] = a[0];6438 out[1] = a[1];6439 return out;6440 }6441 /**6442 * Set the components of a vec2 to the given values6443 *6444 * @param {vec2} out the receiving vector6445 * @param {Number} x X component6446 * @param {Number} y Y component6447 * @returns {vec2} out6448 */6449 function set$8(out, x, y) {6450 out[0] = x;6451 out[1] = y;6452 return out;6453 }6454 /**6455 * Adds two vec2's6456 *6457 * @param {vec2} out the receiving vector6458 * @param {vec2} a the first operand6459 * @param {vec2} b the second operand6460 * @returns {vec2} out6461 */6462 function add$8(out, a, b) {6463 out[0] = a[0] + b[0];6464 out[1] = a[1] + b[1];6465 return out;6466 }6467 /**6468 * Subtracts vector b from vector a6469 *6470 * @param {vec2} out the receiving vector6471 * @param {vec2} a the first operand6472 * @param {vec2} b the second operand6473 * @returns {vec2} out6474 */6475 function subtract$6(out, a, b) {6476 out[0] = a[0] - b[0];6477 out[1] = a[1] - b[1];6478 return out;6479 }6480 /**6481 * Multiplies two vec2's6482 *6483 * @param {vec2} out the receiving vector6484 * @param {vec2} a the first operand6485 * @param {vec2} b the second operand6486 * @returns {vec2} out6487 */6488 function multiply$8(out, a, b) {6489 out[0] = a[0] * b[0];6490 out[1] = a[1] * b[1];6491 return out;6492 }6493 /**6494 * Divides two vec2's6495 *6496 * @param {vec2} out the receiving vector6497 * @param {vec2} a the first operand6498 * @param {vec2} b the second operand6499 * @returns {vec2} out6500 */6501 function divide$2(out, a, b) {6502 out[0] = a[0] / b[0];6503 out[1] = a[1] / b[1];6504 return out;6505 }6506 /**6507 * Math.ceil the components of a vec26508 *6509 * @param {vec2} out the receiving vector6510 * @param {vec2} a vector to ceil6511 * @returns {vec2} out6512 */6513 function ceil$2(out, a) {6514 out[0] = Math.ceil(a[0]);6515 out[1] = Math.ceil(a[1]);6516 return out;6517 }6518 /**6519 * Math.floor the components of a vec26520 *6521 * @param {vec2} out the receiving vector6522 * @param {vec2} a vector to floor6523 * @returns {vec2} out6524 */6525 function floor$2(out, a) {6526 out[0] = Math.floor(a[0]);6527 out[1] = Math.floor(a[1]);6528 return out;6529 }6530 /**6531 * Returns the minimum of two vec2's6532 *6533 * @param {vec2} out the receiving vector6534 * @param {vec2} a the first operand6535 * @param {vec2} b the second operand6536 * @returns {vec2} out6537 */6538 function min$2(out, a, b) {6539 out[0] = Math.min(a[0], b[0]);6540 out[1] = Math.min(a[1], b[1]);6541 return out;6542 }6543 /**6544 * Returns the maximum of two vec2's6545 *6546 * @param {vec2} out the receiving vector6547 * @param {vec2} a the first operand6548 * @param {vec2} b the second operand6549 * @returns {vec2} out6550 */6551 function max$2(out, a, b) {6552 out[0] = Math.max(a[0], b[0]);6553 out[1] = Math.max(a[1], b[1]);6554 return out;6555 }6556 /**6557 * Math.round the components of a vec26558 *6559 * @param {vec2} out the receiving vector6560 * @param {vec2} a vector to round6561 * @returns {vec2} out6562 */6563 function round$2(out, a) {6564 out[0] = Math.round(a[0]);6565 out[1] = Math.round(a[1]);6566 return out;6567 }6568 /**6569 * Scales a vec2 by a scalar number6570 *6571 * @param {vec2} out the receiving vector6572 * @param {vec2} a the vector to scale6573 * @param {Number} b amount to scale the vector by6574 * @returns {vec2} out6575 */6576 function scale$8(out, a, b) {6577 out[0] = a[0] * b;6578 out[1] = a[1] * b;6579 return out;6580 }6581 /**6582 * Adds two vec2's after scaling the second operand by a scalar value6583 *6584 * @param {vec2} out the receiving vector6585 * @param {vec2} a the first operand6586 * @param {vec2} b the second operand6587 * @param {Number} scale the amount to scale b by before adding6588 * @returns {vec2} out6589 */6590 function scaleAndAdd$2(out, a, b, scale) {6591 out[0] = a[0] + b[0] * scale;6592 out[1] = a[1] + b[1] * scale;6593 return out;6594 }6595 /**6596 * Calculates the euclidian distance between two vec2's6597 *6598 * @param {vec2} a the first operand6599 * @param {vec2} b the second operand6600 * @returns {Number} distance between a and b6601 */6602 function distance$2(a, b) {6603 var x = b[0] - a[0],6604 y = b[1] - a[1];6605 return Math.hypot(x, y);6606 }6607 /**6608 * Calculates the squared euclidian distance between two vec2's6609 *6610 * @param {vec2} a the first operand6611 * @param {vec2} b the second operand6612 * @returns {Number} squared distance between a and b6613 */6614 function squaredDistance$2(a, b) {6615 var x = b[0] - a[0],6616 y = b[1] - a[1];6617 return x * x + y * y;6618 }6619 /**6620 * Calculates the length of a vec26621 *6622 * @param {vec2} a vector to calculate length of6623 * @returns {Number} length of a6624 */6625 function length$4(a) {6626 var x = a[0],6627 y = a[1];6628 return Math.hypot(x, y);6629 }6630 /**6631 * Calculates the squared length of a vec26632 *6633 * @param {vec2} a vector to calculate squared length of6634 * @returns {Number} squared length of a6635 */6636 function squaredLength$4(a) {6637 var x = a[0],6638 y = a[1];6639 return x * x + y * y;6640 }6641 /**6642 * Negates the components of a vec26643 *6644 * @param {vec2} out the receiving vector6645 * @param {vec2} a vector to negate6646 * @returns {vec2} out6647 */6648 function negate$2(out, a) {6649 out[0] = -a[0];6650 out[1] = -a[1];6651 return out;6652 }6653 /**6654 * Returns the inverse of the components of a vec26655 *6656 * @param {vec2} out the receiving vector6657 * @param {vec2} a vector to invert6658 * @returns {vec2} out6659 */6660 function inverse$2(out, a) {6661 out[0] = 1.0 / a[0];6662 out[1] = 1.0 / a[1];6663 return out;6664 }6665 /**6666 * Normalize a vec26667 *6668 * @param {vec2} out the receiving vector6669 * @param {vec2} a vector to normalize6670 * @returns {vec2} out6671 */6672 function normalize$4(out, a) {6673 var x = a[0],6674 y = a[1];6675 var len = x * x + y * y;6676 if (len > 0) {6677 //TODO: evaluate use of glm_invsqrt here?6678 len = 1 / Math.sqrt(len);6679 }6680 out[0] = a[0] * len;6681 out[1] = a[1] * len;6682 return out;6683 }6684 /**6685 * Calculates the dot product of two vec2's6686 *6687 * @param {vec2} a the first operand6688 * @param {vec2} b the second operand6689 * @returns {Number} dot product of a and b6690 */6691 function dot$4(a, b) {6692 return a[0] * b[0] + a[1] * b[1];6693 }6694 /**6695 * Computes the cross product of two vec2's6696 * Note that the cross product must by definition produce a 3D vector6697 *6698 * @param {vec3} out the receiving vector6699 * @param {vec2} a the first operand6700 * @param {vec2} b the second operand6701 * @returns {vec3} out6702 */6703 function cross$2(out, a, b) {6704 var z = a[0] * b[1] - a[1] * b[0];6705 out[0] = out[1] = 0;6706 out[2] = z;6707 return out;6708 }6709 /**6710 * Performs a linear interpolation between two vec2's6711 *6712 * @param {vec2} out the receiving vector6713 * @param {vec2} a the first operand6714 * @param {vec2} b the second operand6715 * @param {Number} t interpolation amount, in the range [0-1], between the two inputs6716 * @returns {vec2} out6717 */6718 function lerp$4(out, a, b, t) {6719 var ax = a[0],6720 ay = a[1];6721 out[0] = ax + t * (b[0] - ax);6722 out[1] = ay + t * (b[1] - ay);6723 return out;6724 }6725 /**6726 * Generates a random vector with the given scale6727 *6728 * @param {vec2} out the receiving vector6729 * @param {Number} [scale] Length of the resulting vector. If ommitted, a unit vector will be returned6730 * @returns {vec2} out6731 */6732 function random$3(out, scale) {6733 scale = scale || 1.0;6734 var r = RANDOM() * 2.0 * Math.PI;6735 out[0] = Math.cos(r) * scale;6736 out[1] = Math.sin(r) * scale;6737 return out;6738 }6739 /**6740 * Transforms the vec2 with a mat26741 *6742 * @param {vec2} out the receiving vector6743 * @param {vec2} a the vector to transform6744 * @param {mat2} m matrix to transform with6745 * @returns {vec2} out6746 */6747 function transformMat2(out, a, m) {6748 var x = a[0],6749 y = a[1];6750 out[0] = m[0] * x + m[2] * y;6751 out[1] = m[1] * x + m[3] * y;6752 return out;6753 }6754 /**6755 * Transforms the vec2 with a mat2d6756 *6757 * @param {vec2} out the receiving vector6758 * @param {vec2} a the vector to transform6759 * @param {mat2d} m matrix to transform with6760 * @returns {vec2} out6761 */6762 function transformMat2d(out, a, m) {6763 var x = a[0],6764 y = a[1];6765 out[0] = m[0] * x + m[2] * y + m[4];6766 out[1] = m[1] * x + m[3] * y + m[5];6767 return out;6768 }6769 /**6770 * Transforms the vec2 with a mat36771 * 3rd vector component is implicitly '1'6772 *6773 * @param {vec2} out the receiving vector6774 * @param {vec2} a the vector to transform6775 * @param {mat3} m matrix to transform with6776 * @returns {vec2} out6777 */6778 function transformMat3$1(out, a, m) {6779 var x = a[0],6780 y = a[1];6781 out[0] = m[0] * x + m[3] * y + m[6];6782 out[1] = m[1] * x + m[4] * y + m[7];6783 return out;6784 }6785 /**6786 * Transforms the vec2 with a mat46787 * 3rd vector component is implicitly '0'6788 * 4th vector component is implicitly '1'6789 *6790 * @param {vec2} out the receiving vector6791 * @param {vec2} a the vector to transform6792 * @param {mat4} m matrix to transform with6793 * @returns {vec2} out6794 */6795 function transformMat4$2(out, a, m) {6796 var x = a[0];6797 var y = a[1];6798 out[0] = m[0] * x + m[4] * y + m[12];6799 out[1] = m[1] * x + m[5] * y + m[13];6800 return out;6801 }6802 /**6803 * Rotate a 2D vector6804 * @param {vec2} out The receiving vec26805 * @param {vec2} a The vec2 point to rotate6806 * @param {vec2} b The origin of the rotation6807 * @param {Number} c The angle of rotation6808 * @returns {vec2} out6809 */6810 function rotate$4(out, a, b, c) {6811 //Translate point to the origin6812 var p0 = a[0] - b[0],6813 p1 = a[1] - b[1],6814 sinC = Math.sin(c),6815 cosC = Math.cos(c); //perform rotation and translate to correct position6816 out[0] = p0 * cosC - p1 * sinC + b[0];6817 out[1] = p0 * sinC + p1 * cosC + b[1];6818 return out;6819 }6820 /**6821 * Get the angle between two 2D vectors6822 * @param {vec2} a The first operand6823 * @param {vec2} b The second operand6824 * @returns {Number} The angle in radians6825 */6826 function angle$1(a, b) {6827 var x1 = a[0],6828 y1 = a[1],6829 x2 = b[0],6830 y2 = b[1];6831 var len1 = x1 * x1 + y1 * y1;6832 if (len1 > 0) {6833 //TODO: evaluate use of glm_invsqrt here?6834 len1 = 1 / Math.sqrt(len1);6835 }6836 var len2 = x2 * x2 + y2 * y2;6837 if (len2 > 0) {6838 //TODO: evaluate use of glm_invsqrt here?6839 len2 = 1 / Math.sqrt(len2);6840 }6841 var cosine = (x1 * x2 + y1 * y2) * len1 * len2;6842 if (cosine > 1.0) {6843 return 0;6844 } else if (cosine < -1.0) {6845 return Math.PI;6846 } else {6847 return Math.acos(cosine);6848 }6849 }6850 /**6851 * Set the components of a vec2 to zero6852 *6853 * @param {vec2} out the receiving vector6854 * @returns {vec2} out6855 */6856 function zero$2(out) {6857 out[0] = 0.0;6858 out[1] = 0.0;6859 return out;6860 }6861 /**6862 * Returns a string representation of a vector6863 *6864 * @param {vec2} a vector to represent as a string6865 * @returns {String} string representation of the vector6866 */6867 function str$8(a) {6868 return 'vec2(' + a[0] + ', ' + a[1] + ')';6869 }6870 /**6871 * Returns whether or not the vectors exactly have the same elements in the same position (when compared with ===)6872 *6873 * @param {vec2} a The first vector.6874 * @param {vec2} b The second vector.6875 * @returns {Boolean} True if the vectors are equal, false otherwise.6876 */6877 function exactEquals$8(a, b) {6878 return a[0] === b[0] && a[1] === b[1];6879 }6880 /**6881 * Returns whether or not the vectors have approximately the same elements in the same position.6882 *6883 * @param {vec2} a The first vector.6884 * @param {vec2} b The second vector.6885 * @returns {Boolean} True if the vectors are equal, false otherwise.6886 */6887 function equals$9(a, b) {6888 var a0 = a[0],6889 a1 = a[1];6890 var b0 = b[0],6891 b1 = b[1];6892 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));6893 }6894 /**6895 * Alias for {@link vec2.length}6896 * @function6897 */6898 var len$4 = length$4;6899 /**6900 * Alias for {@link vec2.subtract}6901 * @function6902 */6903 var sub$6 = subtract$6;6904 /**6905 * Alias for {@link vec2.multiply}6906 * @function6907 */6908 var mul$8 = multiply$8;6909 /**6910 * Alias for {@link vec2.divide}6911 * @function6912 */6913 var div$2 = divide$2;6914 /**6915 * Alias for {@link vec2.distance}6916 * @function6917 */6918 var dist$2 = distance$2;6919 /**6920 * Alias for {@link vec2.squaredDistance}6921 * @function6922 */6923 var sqrDist$2 = squaredDistance$2;6924 /**6925 * Alias for {@link vec2.squaredLength}6926 * @function6927 */6928 var sqrLen$4 = squaredLength$4;6929 /**6930 * Perform some operation over an array of vec2s.6931 *6932 * @param {Array} a the array of vectors to iterate over6933 * @param {Number} stride Number of elements between the start of each vec2. If 0 assumes tightly packed6934 * @param {Number} offset Number of elements to skip at the beginning of the array6935 * @param {Number} count Number of vec2s to iterate over. If 0 iterates over entire array6936 * @param {Function} fn Function to call for each vector in the array6937 * @param {Object} [arg] additional argument to pass to fn6938 * @returns {Array} a6939 * @function6940 */6941 var forEach$2 = function () {6942 var vec = create$8();6943 return function (a, stride, offset, count, fn, arg) {6944 var i, l;6945 if (!stride) {6946 stride = 2;6947 }6948 if (!offset) {6949 offset = 0;6950 }6951 if (count) {6952 l = Math.min(count * stride + offset, a.length);6953 } else {6954 l = a.length;6955 }6956 for (i = offset; i < l; i += stride) {6957 vec[0] = a[i];6958 vec[1] = a[i + 1];6959 fn(vec, vec, arg);6960 a[i] = vec[0];6961 a[i + 1] = vec[1];6962 }6963 return a;6964 };6965 }();6966 var vec2 = /*#__PURE__*/Object.freeze({6967 create: create$8,6968 clone: clone$8,6969 fromValues: fromValues$8,6970 copy: copy$8,6971 set: set$8,6972 add: add$8,6973 subtract: subtract$6,6974 multiply: multiply$8,6975 divide: divide$2,6976 ceil: ceil$2,6977 floor: floor$2,6978 min: min$2,6979 max: max$2,6980 round: round$2,6981 scale: scale$8,6982 scaleAndAdd: scaleAndAdd$2,6983 distance: distance$2,6984 squaredDistance: squaredDistance$2,6985 length: length$4,6986 squaredLength: squaredLength$4,6987 negate: negate$2,6988 inverse: inverse$2,6989 normalize: normalize$4,6990 dot: dot$4,6991 cross: cross$2,6992 lerp: lerp$4,6993 random: random$3,6994 transformMat2: transformMat2,6995 transformMat2d: transformMat2d,6996 transformMat3: transformMat3$1,6997 transformMat4: transformMat4$2,6998 rotate: rotate$4,6999 angle: angle$1,7000 zero: zero$2,7001 str: str$8,7002 exactEquals: exactEquals$8,7003 equals: equals$9,7004 len: len$4,7005 sub: sub$6,7006 mul: mul$8,7007 div: div$2,7008 dist: dist$2,7009 sqrDist: sqrDist$2,7010 sqrLen: sqrLen$4,7011 forEach: forEach$27012 });7013 exports.glMatrix = common;7014 exports.mat2 = mat2;7015 exports.mat2d = mat2d;7016 exports.mat3 = mat3;7017 exports.mat4 = mat4;7018 exports.quat = quat;7019 exports.quat2 = quat2;7020 exports.vec2 = vec2;7021 exports.vec3 = vec3;7022 exports.vec4 = vec4;7023 Object.defineProperty(exports, '__esModule', { value: true });...

Full Screen

Full Screen

glmatrix.js

Source:glmatrix.js Github

copy

Full Screen

1/**2 * @fileoverview gl-matrix - High performance matrix and vector operations3 * @author Brandon Jones4 * @author Colin MacKenzie IV5 * @version 2.1.06 */7/* Copyright (c) 2013, Brandon Jones, Colin MacKenzie IV. All rights reserved.8Redistribution and use in source and binary forms, with or without modification,9are permitted provided that the following conditions are met:10 * Redistributions of source code must retain the above copyright notice, this11 list of conditions and the following disclaimer.12 * Redistributions in binary form must reproduce the above copyright notice,13 this list of conditions and the following disclaimer in the documentation 14 and/or other materials provided with the distribution.15THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND16ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED17WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 18DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR19ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES20(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;21LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON22ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT23(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS24SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */25(function() {26 "use strict";27 var shim = {};28 if (typeof(exports) === 'undefined') {29 if (typeof define == 'function' && typeof define.amd == 'object' && define.amd) {30 shim.exports = {};31 define(function() {32 return shim.exports;33 });34 } else {35 // gl-matrix lives in a browser, define its namespaces in global36 shim.exports = window;37 }38 } else {39 // gl-matrix lives in commonjs, define its namespaces in exports40 shim.exports = exports;41 }42 (function(exports) {43 /* Copyright (c) 2013, Brandon Jones, Colin MacKenzie IV. All rights reserved.44Redistribution and use in source and binary forms, with or without modification,45are permitted provided that the following conditions are met:46 * Redistributions of source code must retain the above copyright notice, this47 list of conditions and the following disclaimer.48 * Redistributions in binary form must reproduce the above copyright notice,49 this list of conditions and the following disclaimer in the documentation 50 and/or other materials provided with the distribution.51THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND52ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED53WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 54DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR55ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES56(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;57LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON58ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT59(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS60SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */61 if (!GLMAT_EPSILON) {62 var GLMAT_EPSILON = 0.000001;63 }64 if (!GLMAT_ARRAY_TYPE) {65 var GLMAT_ARRAY_TYPE = (typeof Float32Array !== 'undefined') ? Float32Array : Array;66 }67 /**68 * @class Common utilities69 * @name glMatrix70 */71 var glMatrix = {};72 /**73 * Sets the type of array used when creating new vectors and matricies74 *75 * @param {Type} type Array type, such as Float32Array or Array76 */77 glMatrix.setMatrixArrayType = function(type) {78 GLMAT_ARRAY_TYPE = type;79 }80 if (typeof(exports) !== 'undefined') {81 exports.glMatrix = glMatrix;82 };83 /* Copyright (c) 2013, Brandon Jones, Colin MacKenzie IV. All rights reserved.84Redistribution and use in source and binary forms, with or without modification,85are permitted provided that the following conditions are met:86 * Redistributions of source code must retain the above copyright notice, this87 list of conditions and the following disclaimer.88 * Redistributions in binary form must reproduce the above copyright notice,89 this list of conditions and the following disclaimer in the documentation 90 and/or other materials provided with the distribution.91THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND92ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED93WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 94DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR95ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES96(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;97LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON98ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT99(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS100SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */101 /**102 * @class 2 Dimensional Vector103 * @name vec2104 */105 var vec2 = {};106 /**107 * Creates a new, empty vec2108 *109 * @returns {vec2} a new 2D vector110 */111 vec2.create = function() {112 var out = new GLMAT_ARRAY_TYPE(2);113 out[0] = 0;114 out[1] = 0;115 return out;116 };117 /**118 * Creates a new vec2 initialized with values from an existing vector119 *120 * @param {vec2} a vector to clone121 * @returns {vec2} a new 2D vector122 */123 vec2.clone = function(a) {124 var out = new GLMAT_ARRAY_TYPE(2);125 out[0] = a[0];126 out[1] = a[1];127 return out;128 };129 /**130 * Creates a new vec2 initialized with the given values131 *132 * @param {Number} x X component133 * @param {Number} y Y component134 * @returns {vec2} a new 2D vector135 */136 vec2.fromValues = function(x, y) {137 var out = new GLMAT_ARRAY_TYPE(2);138 out[0] = x;139 out[1] = y;140 return out;141 };142 /**143 * Copy the values from one vec2 to another144 *145 * @param {vec2} out the receiving vector146 * @param {vec2} a the source vector147 * @returns {vec2} out148 */149 vec2.copy = function(out, a) {150 out[0] = a[0];151 out[1] = a[1];152 return out;153 };154 /**155 * Set the components of a vec2 to the given values156 *157 * @param {vec2} out the receiving vector158 * @param {Number} x X component159 * @param {Number} y Y component160 * @returns {vec2} out161 */162 vec2.set = function(out, x, y) {163 out[0] = x;164 out[1] = y;165 return out;166 };167 /**168 * Adds two vec2's169 *170 * @param {vec2} out the receiving vector171 * @param {vec2} a the first operand172 * @param {vec2} b the second operand173 * @returns {vec2} out174 */175 vec2.add = function(out, a, b) {176 out[0] = a[0] + b[0];177 out[1] = a[1] + b[1];178 return out;179 };180 /**181 * Subtracts two vec2's182 *183 * @param {vec2} out the receiving vector184 * @param {vec2} a the first operand185 * @param {vec2} b the second operand186 * @returns {vec2} out187 */188 vec2.subtract = function(out, a, b) {189 out[0] = a[0] - b[0];190 out[1] = a[1] - b[1];191 return out;192 };193 /**194 * Alias for {@link vec2.subtract}195 * @function196 */197 vec2.sub = vec2.subtract;198 /**199 * Multiplies two vec2's200 *201 * @param {vec2} out the receiving vector202 * @param {vec2} a the first operand203 * @param {vec2} b the second operand204 * @returns {vec2} out205 */206 vec2.multiply = function(out, a, b) {207 out[0] = a[0] * b[0];208 out[1] = a[1] * b[1];209 return out;210 };211 /**212 * Alias for {@link vec2.multiply}213 * @function214 */215 vec2.mul = vec2.multiply;216 /**217 * Divides two vec2's218 *219 * @param {vec2} out the receiving vector220 * @param {vec2} a the first operand221 * @param {vec2} b the second operand222 * @returns {vec2} out223 */224 vec2.divide = function(out, a, b) {225 out[0] = a[0] / b[0];226 out[1] = a[1] / b[1];227 return out;228 };229 /**230 * Alias for {@link vec2.divide}231 * @function232 */233 vec2.div = vec2.divide;234 /**235 * Returns the minimum of two vec2's236 *237 * @param {vec2} out the receiving vector238 * @param {vec2} a the first operand239 * @param {vec2} b the second operand240 * @returns {vec2} out241 */242 vec2.min = function(out, a, b) {243 out[0] = Math.min(a[0], b[0]);244 out[1] = Math.min(a[1], b[1]);245 return out;246 };247 /**248 * Returns the maximum of two vec2's249 *250 * @param {vec2} out the receiving vector251 * @param {vec2} a the first operand252 * @param {vec2} b the second operand253 * @returns {vec2} out254 */255 vec2.max = function(out, a, b) {256 out[0] = Math.max(a[0], b[0]);257 out[1] = Math.max(a[1], b[1]);258 return out;259 };260 /**261 * Scales a vec2 by a scalar number262 *263 * @param {vec2} out the receiving vector264 * @param {vec2} a the vector to scale265 * @param {Number} b amount to scale the vector by266 * @returns {vec2} out267 */268 vec2.scale = function(out, a, b) {269 out[0] = a[0] * b;270 out[1] = a[1] * b;271 return out;272 };273 /**274 * Calculates the euclidian distance between two vec2's275 *276 * @param {vec2} a the first operand277 * @param {vec2} b the second operand278 * @returns {Number} distance between a and b279 */280 vec2.distance = function(a, b) {281 var x = b[0] - a[0],282 y = b[1] - a[1];283 return Math.sqrt(x * x + y * y);284 };285 /**286 * Alias for {@link vec2.distance}287 * @function288 */289 vec2.dist = vec2.distance;290 /**291 * Calculates the squared euclidian distance between two vec2's292 *293 * @param {vec2} a the first operand294 * @param {vec2} b the second operand295 * @returns {Number} squared distance between a and b296 */297 vec2.squaredDistance = function(a, b) {298 var x = b[0] - a[0],299 y = b[1] - a[1];300 return x * x + y * y;301 };302 /**303 * Alias for {@link vec2.squaredDistance}304 * @function305 */306 vec2.sqrDist = vec2.squaredDistance;307 /**308 * Calculates the length of a vec2309 *310 * @param {vec2} a vector to calculate length of311 * @returns {Number} length of a312 */313 vec2.length = function(a) {314 var x = a[0],315 y = a[1];316 return Math.sqrt(x * x + y * y);317 };318 /**319 * Alias for {@link vec2.length}320 * @function321 */322 vec2.len = vec2.length;323 /**324 * Calculates the squared length of a vec2325 *326 * @param {vec2} a vector to calculate squared length of327 * @returns {Number} squared length of a328 */329 vec2.squaredLength = function(a) {330 var x = a[0],331 y = a[1];332 return x * x + y * y;333 };334 /**335 * Alias for {@link vec2.squaredLength}336 * @function337 */338 vec2.sqrLen = vec2.squaredLength;339 /**340 * Negates the components of a vec2341 *342 * @param {vec2} out the receiving vector343 * @param {vec2} a vector to negate344 * @returns {vec2} out345 */346 vec2.negate = function(out, a) {347 out[0] = -a[0];348 out[1] = -a[1];349 return out;350 };351 /**352 * Normalize a vec2353 *354 * @param {vec2} out the receiving vector355 * @param {vec2} a vector to normalize356 * @returns {vec2} out357 */358 vec2.normalize = function(out, a) {359 var x = a[0],360 y = a[1];361 var len = x * x + y * y;362 if (len > 0) {363 //TODO: evaluate use of glm_invsqrt here?364 len = 1 / Math.sqrt(len);365 out[0] = a[0] * len;366 out[1] = a[1] * len;367 }368 return out;369 };370 /**371 * Calculates the dot product of two vec2's372 *373 * @param {vec2} a the first operand374 * @param {vec2} b the second operand375 * @returns {Number} dot product of a and b376 */377 vec2.dot = function(a, b) {378 return a[0] * b[0] + a[1] * b[1];379 };380 /**381 * Computes the cross product of two vec2's382 * Note that the cross product must by definition produce a 3D vector383 *384 * @param {vec3} out the receiving vector385 * @param {vec2} a the first operand386 * @param {vec2} b the second operand387 * @returns {vec3} out388 */389 vec2.cross = function(out, a, b) {390 var z = a[0] * b[1] - a[1] * b[0];391 out[0] = out[1] = 0;392 out[2] = z;393 return out;394 };395 /**396 * Performs a linear interpolation between two vec2's397 *398 * @param {vec2} out the receiving vector399 * @param {vec2} a the first operand400 * @param {vec2} b the second operand401 * @param {Number} t interpolation amount between the two inputs402 * @returns {vec2} out403 */404 vec2.lerp = function(out, a, b, t) {405 var ax = a[0],406 ay = a[1];407 out[0] = ax + t * (b[0] - ax);408 out[1] = ay + t * (b[1] - ay);409 return out;410 };411 /**412 * Transforms the vec2 with a mat2413 *414 * @param {vec2} out the receiving vector415 * @param {vec2} a the vector to transform416 * @param {mat2} m matrix to transform with417 * @returns {vec2} out418 */419 vec2.transformMat2 = function(out, a, m) {420 var x = a[0],421 y = a[1];422 out[0] = m[0] * x + m[2] * y;423 out[1] = m[1] * x + m[3] * y;424 return out;425 };426 /**427 * Transforms the vec2 with a mat2d428 *429 * @param {vec2} out the receiving vector430 * @param {vec2} a the vector to transform431 * @param {mat2d} m matrix to transform with432 * @returns {vec2} out433 */434 vec2.transformMat2d = function(out, a, m) {435 var x = a[0],436 y = a[1];437 out[0] = m[0] * x + m[2] * y + m[4];438 out[1] = m[1] * x + m[3] * y + m[5];439 return out;440 };441 /**442 * Transforms the vec2 with a mat3443 * 3rd vector component is implicitly '1'444 *445 * @param {vec2} out the receiving vector446 * @param {vec2} a the vector to transform447 * @param {mat3} m matrix to transform with448 * @returns {vec2} out449 */450 vec2.transformMat3 = function(out, a, m) {451 var x = a[0],452 y = a[1];453 out[0] = m[0] * x + m[3] * y + m[6];454 out[1] = m[1] * x + m[4] * y + m[7];455 return out;456 };457 /**458 * Transforms the vec2 with a mat4459 * 3rd vector component is implicitly '0'460 * 4th vector component is implicitly '1'461 *462 * @param {vec2} out the receiving vector463 * @param {vec2} a the vector to transform464 * @param {mat4} m matrix to transform with465 * @returns {vec2} out466 */467 vec2.transformMat4 = function(out, a, m) {468 var x = a[0],469 y = a[1];470 out[0] = m[0] * x + m[4] * y + m[12];471 out[1] = m[1] * x + m[5] * y + m[13];472 return out;473 };474 /**475 * Perform some operation over an array of vec2s.476 *477 * @param {Array} a the array of vectors to iterate over478 * @param {Number} stride Number of elements between the start of each vec2. If 0 assumes tightly packed479 * @param {Number} offset Number of elements to skip at the beginning of the array480 * @param {Number} count Number of vec2s to iterate over. If 0 iterates over entire array481 * @param {Function} fn Function to call for each vector in the array482 * @param {Object} [arg] additional argument to pass to fn483 * @returns {Array} a484 * @function485 */486 vec2.forEach = (function() {487 var vec = vec2.create();488 return function(a, stride, offset, count, fn, arg) {489 var i, l;490 if (!stride) {491 stride = 2;492 }493 if (!offset) {494 offset = 0;495 }496 if (count) {497 l = Math.min((count * stride) + offset, a.length);498 } else {499 l = a.length;500 }501 for (i = offset; i < l; i += stride) {502 vec[0] = a[i];503 vec[1] = a[i + 1];504 fn(vec, vec, arg);505 a[i] = vec[0];506 a[i + 1] = vec[1];507 }508 return a;509 };510 })();511 /**512 * Returns a string representation of a vector513 *514 * @param {vec2} vec vector to represent as a string515 * @returns {String} string representation of the vector516 */517 vec2.str = function(a) {518 return 'vec2(' + a[0] + ', ' + a[1] + ')';519 };520 if (typeof(exports) !== 'undefined') {521 exports.vec2 = vec2;522 };523 /* Copyright (c) 2013, Brandon Jones, Colin MacKenzie IV. All rights reserved.524Redistribution and use in source and binary forms, with or without modification,525are permitted provided that the following conditions are met:526 * Redistributions of source code must retain the above copyright notice, this527 list of conditions and the following disclaimer.528 * Redistributions in binary form must reproduce the above copyright notice,529 this list of conditions and the following disclaimer in the documentation 530 and/or other materials provided with the distribution.531THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND532ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED533WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 534DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR535ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES536(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;537LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON538ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT539(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS540SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */541 /**542 * @class 3 Dimensional Vector543 * @name vec3544 */545 var vec3 = {};546 /**547 * Creates a new, empty vec3548 *549 * @returns {vec3} a new 3D vector550 */551 vec3.create = function() {552 var out = new GLMAT_ARRAY_TYPE(3);553 out[0] = 0;554 out[1] = 0;555 out[2] = 0;556 return out;557 };558 /**559 * Creates a new vec3 initialized with values from an existing vector560 *561 * @param {vec3} a vector to clone562 * @returns {vec3} a new 3D vector563 */564 vec3.clone = function(a) {565 var out = new GLMAT_ARRAY_TYPE(3);566 out[0] = a[0];567 out[1] = a[1];568 out[2] = a[2];569 return out;570 };571 /**572 * Creates a new vec3 initialized with the given values573 *574 * @param {Number} x X component575 * @param {Number} y Y component576 * @param {Number} z Z component577 * @returns {vec3} a new 3D vector578 */579 vec3.fromValues = function(x, y, z) {580 var out = new GLMAT_ARRAY_TYPE(3);581 out[0] = x;582 out[1] = y;583 out[2] = z;584 return out;585 };586 /**587 * Copy the values from one vec3 to another588 *589 * @param {vec3} out the receiving vector590 * @param {vec3} a the source vector591 * @returns {vec3} out592 */593 vec3.copy = function(out, a) {594 out[0] = a[0];595 out[1] = a[1];596 out[2] = a[2];597 return out;598 };599 /**600 * Set the components of a vec3 to the given values601 *602 * @param {vec3} out the receiving vector603 * @param {Number} x X component604 * @param {Number} y Y component605 * @param {Number} z Z component606 * @returns {vec3} out607 */608 vec3.set = function(out, x, y, z) {609 out[0] = x;610 out[1] = y;611 out[2] = z;612 return out;613 };614 /**615 * Adds two vec3's616 *617 * @param {vec3} out the receiving vector618 * @param {vec3} a the first operand619 * @param {vec3} b the second operand620 * @returns {vec3} out621 */622 vec3.add = function(out, a, b) {623 out[0] = a[0] + b[0];624 out[1] = a[1] + b[1];625 out[2] = a[2] + b[2];626 return out;627 };628 /**629 * Subtracts two vec3's630 *631 * @param {vec3} out the receiving vector632 * @param {vec3} a the first operand633 * @param {vec3} b the second operand634 * @returns {vec3} out635 */636 vec3.subtract = function(out, a, b) {637 out[0] = a[0] - b[0];638 out[1] = a[1] - b[1];639 out[2] = a[2] - b[2];640 return out;641 };642 /**643 * Alias for {@link vec3.subtract}644 * @function645 */646 vec3.sub = vec3.subtract;647 /**648 * Multiplies two vec3's649 *650 * @param {vec3} out the receiving vector651 * @param {vec3} a the first operand652 * @param {vec3} b the second operand653 * @returns {vec3} out654 */655 vec3.multiply = function(out, a, b) {656 out[0] = a[0] * b[0];657 out[1] = a[1] * b[1];658 out[2] = a[2] * b[2];659 return out;660 };661 /**662 * Alias for {@link vec3.multiply}663 * @function664 */665 vec3.mul = vec3.multiply;666 /**667 * Divides two vec3's668 *669 * @param {vec3} out the receiving vector670 * @param {vec3} a the first operand671 * @param {vec3} b the second operand672 * @returns {vec3} out673 */674 vec3.divide = function(out, a, b) {675 out[0] = a[0] / b[0];676 out[1] = a[1] / b[1];677 out[2] = a[2] / b[2];678 return out;679 };680 /**681 * Alias for {@link vec3.divide}682 * @function683 */684 vec3.div = vec3.divide;685 /**686 * Returns the minimum of two vec3's687 *688 * @param {vec3} out the receiving vector689 * @param {vec3} a the first operand690 * @param {vec3} b the second operand691 * @returns {vec3} out692 */693 vec3.min = function(out, a, b) {694 out[0] = Math.min(a[0], b[0]);695 out[1] = Math.min(a[1], b[1]);696 out[2] = Math.min(a[2], b[2]);697 return out;698 };699 /**700 * Returns the maximum of two vec3's701 *702 * @param {vec3} out the receiving vector703 * @param {vec3} a the first operand704 * @param {vec3} b the second operand705 * @returns {vec3} out706 */707 vec3.max = function(out, a, b) {708 out[0] = Math.max(a[0], b[0]);709 out[1] = Math.max(a[1], b[1]);710 out[2] = Math.max(a[2], b[2]);711 return out;712 };713 /**714 * Scales a vec3 by a scalar number715 *716 * @param {vec3} out the receiving vector717 * @param {vec3} a the vector to scale718 * @param {Number} b amount to scale the vector by719 * @returns {vec3} out720 */721 vec3.scale = function(out, a, b) {722 out[0] = a[0] * b;723 out[1] = a[1] * b;724 out[2] = a[2] * b;725 return out;726 };727 /**728 * Calculates the euclidian distance between two vec3's729 *730 * @param {vec3} a the first operand731 * @param {vec3} b the second operand732 * @returns {Number} distance between a and b733 */734 vec3.distance = function(a, b) {735 var x = b[0] - a[0],736 y = b[1] - a[1],737 z = b[2] - a[2];738 return Math.sqrt(x * x + y * y + z * z);739 };740 /**741 * Alias for {@link vec3.distance}742 * @function743 */744 vec3.dist = vec3.distance;745 /**746 * Calculates the squared euclidian distance between two vec3's747 *748 * @param {vec3} a the first operand749 * @param {vec3} b the second operand750 * @returns {Number} squared distance between a and b751 */752 vec3.squaredDistance = function(a, b) {753 var x = b[0] - a[0],754 y = b[1] - a[1],755 z = b[2] - a[2];756 return x * x + y * y + z * z;757 };758 /**759 * Alias for {@link vec3.squaredDistance}760 * @function761 */762 vec3.sqrDist = vec3.squaredDistance;763 /**764 * Calculates the length of a vec3765 *766 * @param {vec3} a vector to calculate length of767 * @returns {Number} length of a768 */769 vec3.length = function(a) {770 var x = a[0],771 y = a[1],772 z = a[2];773 return Math.sqrt(x * x + y * y + z * z);774 };775 /**776 * Alias for {@link vec3.length}777 * @function778 */779 vec3.len = vec3.length;780 /**781 * Calculates the squared length of a vec3782 *783 * @param {vec3} a vector to calculate squared length of784 * @returns {Number} squared length of a785 */786 vec3.squaredLength = function(a) {787 var x = a[0],788 y = a[1],789 z = a[2];790 return x * x + y * y + z * z;791 };792 /**793 * Alias for {@link vec3.squaredLength}794 * @function795 */796 vec3.sqrLen = vec3.squaredLength;797 /**798 * Negates the components of a vec3799 *800 * @param {vec3} out the receiving vector801 * @param {vec3} a vector to negate802 * @returns {vec3} out803 */804 vec3.negate = function(out, a) {805 out[0] = -a[0];806 out[1] = -a[1];807 out[2] = -a[2];808 return out;809 };810 /**811 * Normalize a vec3812 *813 * @param {vec3} out the receiving vector814 * @param {vec3} a vector to normalize815 * @returns {vec3} out816 */817 vec3.normalize = function(out, a) {818 var x = a[0],819 y = a[1],820 z = a[2];821 var len = x * x + y * y + z * z;822 if (len > 0) {823 //TODO: evaluate use of glm_invsqrt here?824 len = 1 / Math.sqrt(len);825 out[0] = a[0] * len;826 out[1] = a[1] * len;827 out[2] = a[2] * len;828 }829 return out;830 };831 /**832 * Calculates the dot product of two vec3's833 *834 * @param {vec3} a the first operand835 * @param {vec3} b the second operand836 * @returns {Number} dot product of a and b837 */838 vec3.dot = function(a, b) {839 return a[0] * b[0] + a[1] * b[1] + a[2] * b[2];840 };841 /**842 * Computes the cross product of two vec3's843 *844 * @param {vec3} out the receiving vector845 * @param {vec3} a the first operand846 * @param {vec3} b the second operand847 * @returns {vec3} out848 */849 vec3.cross = function(out, a, b) {850 var ax = a[0],851 ay = a[1],852 az = a[2],853 bx = b[0],854 by = b[1],855 bz = b[2];856 out[0] = ay * bz - az * by;857 out[1] = az * bx - ax * bz;858 out[2] = ax * by - ay * bx;859 return out;860 };861 /**862 * Performs a linear interpolation between two vec3's863 *864 * @param {vec3} out the receiving vector865 * @param {vec3} a the first operand866 * @param {vec3} b the second operand867 * @param {Number} t interpolation amount between the two inputs868 * @returns {vec3} out869 */870 vec3.lerp = function(out, a, b, t) {871 var ax = a[0],872 ay = a[1],873 az = a[2];874 out[0] = ax + t * (b[0] - ax);875 out[1] = ay + t * (b[1] - ay);876 out[2] = az + t * (b[2] - az);877 return out;878 };879 /**880 * Transforms the vec3 with a mat4.881 * 4th vector component is implicitly '1'882 *883 * @param {vec3} out the receiving vector884 * @param {vec3} a the vector to transform885 * @param {mat4} m matrix to transform with886 * @returns {vec3} out887 */888 vec3.transformMat4 = function(out, a, m) {889 var x = a[0],890 y = a[1],891 z = a[2];892 out[0] = m[0] * x + m[4] * y + m[8] * z + m[12];893 out[1] = m[1] * x + m[5] * y + m[9] * z + m[13];894 out[2] = m[2] * x + m[6] * y + m[10] * z + m[14];895 return out;896 };897 /**898 * Transforms the vec3 with a quat899 *900 * @param {vec3} out the receiving vector901 * @param {vec3} a the vector to transform902 * @param {quat} q quaternion to transform with903 * @returns {vec3} out904 */905 vec3.transformQuat = function(out, a, q) {906 var x = a[0],907 y = a[1],908 z = a[2],909 qx = q[0],910 qy = q[1],911 qz = q[2],912 qw = q[3],913 // calculate quat * vec914 ix = qw * x + qy * z - qz * y,915 iy = qw * y + qz * x - qx * z,916 iz = qw * z + qx * y - qy * x,917 iw = -qx * x - qy * y - qz * z;918 // calculate result * inverse quat919 out[0] = ix * qw + iw * -qx + iy * -qz - iz * -qy;920 out[1] = iy * qw + iw * -qy + iz * -qx - ix * -qz;921 out[2] = iz * qw + iw * -qz + ix * -qy - iy * -qx;922 return out;923 };924 /**925 * Perform some operation over an array of vec3s.926 *927 * @param {Array} a the array of vectors to iterate over928 * @param {Number} stride Number of elements between the start of each vec3. If 0 assumes tightly packed929 * @param {Number} offset Number of elements to skip at the beginning of the array930 * @param {Number} count Number of vec3s to iterate over. If 0 iterates over entire array931 * @param {Function} fn Function to call for each vector in the array932 * @param {Object} [arg] additional argument to pass to fn933 * @returns {Array} a934 * @function935 */936 vec3.forEach = (function() {937 var vec = vec3.create();938 return function(a, stride, offset, count, fn, arg) {939 var i, l;940 if (!stride) {941 stride = 3;942 }943 if (!offset) {944 offset = 0;945 }946 if (count) {947 l = Math.min((count * stride) + offset, a.length);948 } else {949 l = a.length;950 }951 for (i = offset; i < l; i += stride) {952 vec[0] = a[i];953 vec[1] = a[i + 1];954 vec[2] = a[i + 2];955 fn(vec, vec, arg);956 a[i] = vec[0];957 a[i + 1] = vec[1];958 a[i + 2] = vec[2];959 }960 return a;961 };962 })();963 /**964 * Returns a string representation of a vector965 *966 * @param {vec3} vec vector to represent as a string967 * @returns {String} string representation of the vector968 */969 vec3.str = function(a) {970 return 'vec3(' + a[0] + ', ' + a[1] + ', ' + a[2] + ')';971 };972 if (typeof(exports) !== 'undefined') {973 exports.vec3 = vec3;974 };975 /* Copyright (c) 2013, Brandon Jones, Colin MacKenzie IV. All rights reserved.976Redistribution and use in source and binary forms, with or without modification,977are permitted provided that the following conditions are met:978 * Redistributions of source code must retain the above copyright notice, this979 list of conditions and the following disclaimer.980 * Redistributions in binary form must reproduce the above copyright notice,981 this list of conditions and the following disclaimer in the documentation 982 and/or other materials provided with the distribution.983THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND984ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED985WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 986DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR987ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES988(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;989LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON990ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT991(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS992SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */993 /**994 * @class 4 Dimensional Vector995 * @name vec4996 */997 var vec4 = {};998 /**999 * Creates a new, empty vec41000 *1001 * @returns {vec4} a new 4D vector1002 */1003 vec4.create = function() {1004 var out = new GLMAT_ARRAY_TYPE(4);1005 out[0] = 0;1006 out[1] = 0;1007 out[2] = 0;1008 out[3] = 0;1009 return out;1010 };1011 /**1012 * Creates a new vec4 initialized with values from an existing vector1013 *1014 * @param {vec4} a vector to clone1015 * @returns {vec4} a new 4D vector1016 */1017 vec4.clone = function(a) {1018 var out = new GLMAT_ARRAY_TYPE(4);1019 out[0] = a[0];1020 out[1] = a[1];1021 out[2] = a[2];1022 out[3] = a[3];1023 return out;1024 };1025 /**1026 * Creates a new vec4 initialized with the given values1027 *1028 * @param {Number} x X component1029 * @param {Number} y Y component1030 * @param {Number} z Z component1031 * @param {Number} w W component1032 * @returns {vec4} a new 4D vector1033 */1034 vec4.fromValues = function(x, y, z, w) {1035 var out = new GLMAT_ARRAY_TYPE(4);1036 out[0] = x;1037 out[1] = y;1038 out[2] = z;1039 out[3] = w;1040 return out;1041 };1042 /**1043 * Copy the values from one vec4 to another1044 *1045 * @param {vec4} out the receiving vector1046 * @param {vec4} a the source vector1047 * @returns {vec4} out1048 */1049 vec4.copy = function(out, a) {1050 out[0] = a[0];1051 out[1] = a[1];1052 out[2] = a[2];1053 out[3] = a[3];1054 return out;1055 };1056 /**1057 * Set the components of a vec4 to the given values1058 *1059 * @param {vec4} out the receiving vector1060 * @param {Number} x X component1061 * @param {Number} y Y component1062 * @param {Number} z Z component1063 * @param {Number} w W component1064 * @returns {vec4} out1065 */1066 vec4.set = function(out, x, y, z, w) {1067 out[0] = x;1068 out[1] = y;1069 out[2] = z;1070 out[3] = w;1071 return out;1072 };1073 /**1074 * Adds two vec4's1075 *1076 * @param {vec4} out the receiving vector1077 * @param {vec4} a the first operand1078 * @param {vec4} b the second operand1079 * @returns {vec4} out1080 */1081 vec4.add = function(out, a, b) {1082 out[0] = a[0] + b[0];1083 out[1] = a[1] + b[1];1084 out[2] = a[2] + b[2];1085 out[3] = a[3] + b[3];1086 return out;1087 };1088 /**1089 * Subtracts two vec4's1090 *1091 * @param {vec4} out the receiving vector1092 * @param {vec4} a the first operand1093 * @param {vec4} b the second operand1094 * @returns {vec4} out1095 */1096 vec4.subtract = function(out, a, b) {1097 out[0] = a[0] - b[0];1098 out[1] = a[1] - b[1];1099 out[2] = a[2] - b[2];1100 out[3] = a[3] - b[3];1101 return out;1102 };1103 /**1104 * Alias for {@link vec4.subtract}1105 * @function1106 */1107 vec4.sub = vec4.subtract;1108 /**1109 * Multiplies two vec4's1110 *1111 * @param {vec4} out the receiving vector1112 * @param {vec4} a the first operand1113 * @param {vec4} b the second operand1114 * @returns {vec4} out1115 */1116 vec4.multiply = function(out, a, b) {1117 out[0] = a[0] * b[0];1118 out[1] = a[1] * b[1];1119 out[2] = a[2] * b[2];1120 out[3] = a[3] * b[3];1121 return out;1122 };1123 /**1124 * Alias for {@link vec4.multiply}1125 * @function1126 */1127 vec4.mul = vec4.multiply;1128 /**1129 * Divides two vec4's1130 *1131 * @param {vec4} out the receiving vector1132 * @param {vec4} a the first operand1133 * @param {vec4} b the second operand1134 * @returns {vec4} out1135 */1136 vec4.divide = function(out, a, b) {1137 out[0] = a[0] / b[0];1138 out[1] = a[1] / b[1];1139 out[2] = a[2] / b[2];1140 out[3] = a[3] / b[3];1141 return out;1142 };1143 /**1144 * Alias for {@link vec4.divide}1145 * @function1146 */1147 vec4.div = vec4.divide;1148 /**1149 * Returns the minimum of two vec4's1150 *1151 * @param {vec4} out the receiving vector1152 * @param {vec4} a the first operand1153 * @param {vec4} b the second operand1154 * @returns {vec4} out1155 */1156 vec4.min = function(out, a, b) {1157 out[0] = Math.min(a[0], b[0]);1158 out[1] = Math.min(a[1], b[1]);1159 out[2] = Math.min(a[2], b[2]);1160 out[3] = Math.min(a[3], b[3]);1161 return out;1162 };1163 /**1164 * Returns the maximum of two vec4's1165 *1166 * @param {vec4} out the receiving vector1167 * @param {vec4} a the first operand1168 * @param {vec4} b the second operand1169 * @returns {vec4} out1170 */1171 vec4.max = function(out, a, b) {1172 out[0] = Math.max(a[0], b[0]);1173 out[1] = Math.max(a[1], b[1]);1174 out[2] = Math.max(a[2], b[2]);1175 out[3] = Math.max(a[3], b[3]);1176 return out;1177 };1178 /**1179 * Scales a vec4 by a scalar number1180 *1181 * @param {vec4} out the receiving vector1182 * @param {vec4} a the vector to scale1183 * @param {Number} b amount to scale the vector by1184 * @returns {vec4} out1185 */1186 vec4.scale = function(out, a, b) {1187 out[0] = a[0] * b;1188 out[1] = a[1] * b;1189 out[2] = a[2] * b;1190 out[3] = a[3] * b;1191 return out;1192 };1193 /**1194 * Calculates the euclidian distance between two vec4's1195 *1196 * @param {vec4} a the first operand1197 * @param {vec4} b the second operand1198 * @returns {Number} distance between a and b1199 */1200 vec4.distance = function(a, b) {1201 var x = b[0] - a[0],1202 y = b[1] - a[1],1203 z = b[2] - a[2],1204 w = b[3] - a[3];1205 return Math.sqrt(x * x + y * y + z * z + w * w);1206 };1207 /**1208 * Alias for {@link vec4.distance}1209 * @function1210 */1211 vec4.dist = vec4.distance;1212 /**1213 * Calculates the squared euclidian distance between two vec4's1214 *1215 * @param {vec4} a the first operand1216 * @param {vec4} b the second operand1217 * @returns {Number} squared distance between a and b1218 */1219 vec4.squaredDistance = function(a, b) {1220 var x = b[0] - a[0],1221 y = b[1] - a[1],1222 z = b[2] - a[2],1223 w = b[3] - a[3];1224 return x * x + y * y + z * z + w * w;1225 };1226 /**1227 * Alias for {@link vec4.squaredDistance}1228 * @function1229 */1230 vec4.sqrDist = vec4.squaredDistance;1231 /**1232 * Calculates the length of a vec41233 *1234 * @param {vec4} a vector to calculate length of1235 * @returns {Number} length of a1236 */1237 vec4.length = function(a) {1238 var x = a[0],1239 y = a[1],1240 z = a[2],1241 w = a[3];1242 return Math.sqrt(x * x + y * y + z * z + w * w);1243 };1244 /**1245 * Alias for {@link vec4.length}1246 * @function1247 */1248 vec4.len = vec4.length;1249 /**1250 * Calculates the squared length of a vec41251 *1252 * @param {vec4} a vector to calculate squared length of1253 * @returns {Number} squared length of a1254 */1255 vec4.squaredLength = function(a) {1256 var x = a[0],1257 y = a[1],1258 z = a[2],1259 w = a[3];1260 return x * x + y * y + z * z + w * w;1261 };1262 /**1263 * Alias for {@link vec4.squaredLength}1264 * @function1265 */1266 vec4.sqrLen = vec4.squaredLength;1267 /**1268 * Negates the components of a vec41269 *1270 * @param {vec4} out the receiving vector1271 * @param {vec4} a vector to negate1272 * @returns {vec4} out1273 */1274 vec4.negate = function(out, a) {1275 out[0] = -a[0];1276 out[1] = -a[1];1277 out[2] = -a[2];1278 out[3] = -a[3];1279 return out;1280 };1281 /**1282 * Normalize a vec41283 *1284 * @param {vec4} out the receiving vector1285 * @param {vec4} a vector to normalize1286 * @returns {vec4} out1287 */1288 vec4.normalize = function(out, a) {1289 var x = a[0],1290 y = a[1],1291 z = a[2],1292 w = a[3];1293 var len = x * x + y * y + z * z + w * w;1294 if (len > 0) {1295 len = 1 / Math.sqrt(len);1296 out[0] = a[0] * len;1297 out[1] = a[1] * len;1298 out[2] = a[2] * len;1299 out[3] = a[3] * len;1300 }1301 return out;1302 };1303 /**1304 * Calculates the dot product of two vec4's1305 *1306 * @param {vec4} a the first operand1307 * @param {vec4} b the second operand1308 * @returns {Number} dot product of a and b1309 */1310 vec4.dot = function(a, b) {1311 return a[0] * b[0] + a[1] * b[1] + a[2] * b[2] + a[3] * b[3];1312 };1313 /**1314 * Performs a linear interpolation between two vec4's1315 *1316 * @param {vec4} out the receiving vector1317 * @param {vec4} a the first operand1318 * @param {vec4} b the second operand1319 * @param {Number} t interpolation amount between the two inputs1320 * @returns {vec4} out1321 */1322 vec4.lerp = function(out, a, b, t) {1323 var ax = a[0],1324 ay = a[1],1325 az = a[2],1326 aw = a[3];1327 out[0] = ax + t * (b[0] - ax);1328 out[1] = ay + t * (b[1] - ay);1329 out[2] = az + t * (b[2] - az);1330 out[3] = aw + t * (b[3] - aw);1331 return out;1332 };1333 /**1334 * Transforms the vec4 with a mat4.1335 *1336 * @param {vec4} out the receiving vector1337 * @param {vec4} a the vector to transform1338 * @param {mat4} m matrix to transform with1339 * @returns {vec4} out1340 */1341 vec4.transformMat4 = function(out, a, m) {1342 var x = a[0],1343 y = a[1],1344 z = a[2],1345 w = a[3];1346 out[0] = m[0] * x + m[4] * y + m[8] * z + m[12] * w;1347 out[1] = m[1] * x + m[5] * y + m[9] * z + m[13] * w;1348 out[2] = m[2] * x + m[6] * y + m[10] * z + m[14] * w;1349 out[3] = m[3] * x + m[7] * y + m[11] * z + m[15] * w;1350 return out;1351 };1352 /**1353 * Transforms the vec4 with a quat1354 *1355 * @param {vec4} out the receiving vector1356 * @param {vec4} a the vector to transform1357 * @param {quat} q quaternion to transform with1358 * @returns {vec4} out1359 */1360 vec4.transformQuat = function(out, a, q) {1361 var x = a[0],1362 y = a[1],1363 z = a[2],1364 qx = q[0],1365 qy = q[1],1366 qz = q[2],1367 qw = q[3],1368 // calculate quat * vec1369 ix = qw * x + qy * z - qz * y,1370 iy = qw * y + qz * x - qx * z,1371 iz = qw * z + qx * y - qy * x,1372 iw = -qx * x - qy * y - qz * z;1373 // calculate result * inverse quat1374 out[0] = ix * qw + iw * -qx + iy * -qz - iz * -qy;1375 out[1] = iy * qw + iw * -qy + iz * -qx - ix * -qz;1376 out[2] = iz * qw + iw * -qz + ix * -qy - iy * -qx;1377 return out;1378 };1379 /**1380 * Perform some operation over an array of vec4s.1381 *1382 * @param {Array} a the array of vectors to iterate over1383 * @param {Number} stride Number of elements between the start of each vec4. If 0 assumes tightly packed1384 * @param {Number} offset Number of elements to skip at the beginning of the array1385 * @param {Number} count Number of vec2s to iterate over. If 0 iterates over entire array1386 * @param {Function} fn Function to call for each vector in the array1387 * @param {Object} [arg] additional argument to pass to fn1388 * @returns {Array} a1389 * @function1390 */1391 vec4.forEach = (function() {1392 var vec = vec4.create();1393 return function(a, stride, offset, count, fn, arg) {1394 var i, l;1395 if (!stride) {1396 stride = 4;1397 }1398 if (!offset) {1399 offset = 0;1400 }1401 if (count) {1402 l = Math.min((count * stride) + offset, a.length);1403 } else {1404 l = a.length;1405 }1406 for (i = offset; i < l; i += stride) {1407 vec[0] = a[i];1408 vec[1] = a[i + 1];1409 vec[2] = a[i + 2];1410 vec[3] = a[i + 3];1411 fn(vec, vec, arg);1412 a[i] = vec[0];1413 a[i + 1] = vec[1];1414 a[i + 2] = vec[2];1415 a[i + 3] = vec[3];1416 }1417 return a;1418 };1419 })();1420 /**1421 * Returns a string representation of a vector1422 *1423 * @param {vec4} vec vector to represent as a string1424 * @returns {String} string representation of the vector1425 */1426 vec4.str = function(a) {1427 return 'vec4(' + a[0] + ', ' + a[1] + ', ' + a[2] + ', ' + a[3] + ')';1428 };1429 if (typeof(exports) !== 'undefined') {1430 exports.vec4 = vec4;1431 };1432 /* Copyright (c) 2013, Brandon Jones, Colin MacKenzie IV. All rights reserved.1433Redistribution and use in source and binary forms, with or without modification,1434are permitted provided that the following conditions are met:1435 * Redistributions of source code must retain the above copyright notice, this1436 list of conditions and the following disclaimer.1437 * Redistributions in binary form must reproduce the above copyright notice,1438 this list of conditions and the following disclaimer in the documentation 1439 and/or other materials provided with the distribution.1440THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND1441ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED1442WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 1443DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR1444ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES1445(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;1446LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON1447ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT1448(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS1449SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */1450 /**1451 * @class 2x2 Matrix1452 * @name mat21453 */1454 var mat2 = {};1455 var mat2Identity = new Float32Array([1456 1, 0,1457 0, 11458 ]);1459 /**1460 * Creates a new identity mat21461 *1462 * @returns {mat2} a new 2x2 matrix1463 */1464 mat2.create = function() {1465 var out = new GLMAT_ARRAY_TYPE(4);1466 out[0] = 1;1467 out[1] = 0;1468 out[2] = 0;1469 out[3] = 1;1470 return out;1471 };1472 /**1473 * Creates a new mat2 initialized with values from an existing matrix1474 *1475 * @param {mat2} a matrix to clone1476 * @returns {mat2} a new 2x2 matrix1477 */1478 mat2.clone = function(a) {1479 var out = new GLMAT_ARRAY_TYPE(4);1480 out[0] = a[0];1481 out[1] = a[1];1482 out[2] = a[2];1483 out[3] = a[3];1484 return out;1485 };1486 /**1487 * Copy the values from one mat2 to another1488 *1489 * @param {mat2} out the receiving matrix1490 * @param {mat2} a the source matrix1491 * @returns {mat2} out1492 */1493 mat2.copy = function(out, a) {1494 out[0] = a[0];1495 out[1] = a[1];1496 out[2] = a[2];1497 out[3] = a[3];1498 return out;1499 };1500 /**1501 * Set a mat2 to the identity matrix1502 *1503 * @param {mat2} out the receiving matrix1504 * @returns {mat2} out1505 */1506 mat2.identity = function(out) {1507 out[0] = 1;1508 out[1] = 0;1509 out[2] = 0;1510 out[3] = 1;1511 return out;1512 };1513 /**1514 * Transpose the values of a mat21515 *1516 * @param {mat2} out the receiving matrix1517 * @param {mat2} a the source matrix1518 * @returns {mat2} out1519 */1520 mat2.transpose = function(out, a) {1521 // If we are transposing ourselves we can skip a few steps but have to cache some values1522 if (out === a) {1523 var a1 = a[1];1524 out[1] = a[2];1525 out[2] = a1;1526 } else {1527 out[0] = a[0];1528 out[1] = a[2];1529 out[2] = a[1];1530 out[3] = a[3];1531 }1532 return out;1533 };1534 /**1535 * Inverts a mat21536 *1537 * @param {mat2} out the receiving matrix1538 * @param {mat2} a the source matrix1539 * @returns {mat2} out1540 */1541 mat2.invert = function(out, a) {1542 var a0 = a[0],1543 a1 = a[1],1544 a2 = a[2],1545 a3 = a[3],1546 // Calculate the determinant1547 det = a0 * a3 - a2 * a1;1548 if (!det) {1549 return null;1550 }1551 det = 1.0 / det;1552 out[0] = a3 * det;1553 out[1] = -a1 * det;1554 out[2] = -a2 * det;1555 out[3] = a0 * det;1556 return out;1557 };1558 /**1559 * Calculates the adjugate of a mat21560 *1561 * @param {mat2} out the receiving matrix1562 * @param {mat2} a the source matrix1563 * @returns {mat2} out1564 */1565 mat2.adjoint = function(out, a) {1566 // Caching this value is nessecary if out == a1567 var a0 = a[0];1568 out[0] = a[3];1569 out[1] = -a[1];1570 out[2] = -a[2];1571 out[3] = a0;1572 return out;1573 };1574 /**1575 * Calculates the determinant of a mat21576 *1577 * @param {mat2} a the source matrix1578 * @returns {Number} determinant of a1579 */1580 mat2.determinant = function(a) {1581 return a[0] * a[3] - a[2] * a[1];1582 };1583 /**1584 * Multiplies two mat2's1585 *1586 * @param {mat2} out the receiving matrix1587 * @param {mat2} a the first operand1588 * @param {mat2} b the second operand1589 * @returns {mat2} out1590 */1591 mat2.multiply = function(out, a, b) {1592 var a0 = a[0],1593 a1 = a[1],1594 a2 = a[2],1595 a3 = a[3];1596 var b0 = b[0],1597 b1 = b[1],1598 b2 = b[2],1599 b3 = b[3];1600 out[0] = a0 * b0 + a1 * b2;1601 out[1] = a0 * b1 + a1 * b3;1602 out[2] = a2 * b0 + a3 * b2;1603 out[3] = a2 * b1 + a3 * b3;1604 return out;1605 };1606 /**1607 * Alias for {@link mat2.multiply}1608 * @function1609 */1610 mat2.mul = mat2.multiply;1611 /**1612 * Rotates a mat2 by the given angle1613 *1614 * @param {mat2} out the receiving matrix1615 * @param {mat2} a the matrix to rotate1616 * @param {Number} rad the angle to rotate the matrix by1617 * @returns {mat2} out1618 */1619 mat2.rotate = function(out, a, rad) {1620 var a0 = a[0],1621 a1 = a[1],1622 a2 = a[2],1623 a3 = a[3],1624 s = Math.sin(rad),1625 c = Math.cos(rad);1626 out[0] = a0 * c + a1 * s;1627 out[1] = a0 * -s + a1 * c;1628 out[2] = a2 * c + a3 * s;1629 out[3] = a2 * -s + a3 * c;1630 return out;1631 };1632 /**1633 * Scales the mat2 by the dimensions in the given vec21634 *1635 * @param {mat2} out the receiving matrix1636 * @param {mat2} a the matrix to rotate1637 * @param {vec2} v the vec2 to scale the matrix by1638 * @returns {mat2} out1639 **/1640 mat2.scale = function(out, a, v) {1641 var a0 = a[0],1642 a1 = a[1],1643 a2 = a[2],1644 a3 = a[3],1645 v0 = v[0],1646 v1 = v[1];1647 out[0] = a0 * v0;1648 out[1] = a1 * v1;1649 out[2] = a2 * v0;1650 out[3] = a3 * v1;1651 return out;1652 };1653 /**1654 * Returns a string representation of a mat21655 *1656 * @param {mat2} mat matrix to represent as a string1657 * @returns {String} string representation of the matrix1658 */1659 mat2.str = function(a) {1660 return 'mat2(' + a[0] + ', ' + a[1] + ', ' + a[2] + ', ' + a[3] + ')';1661 };1662 if (typeof(exports) !== 'undefined') {1663 exports.mat2 = mat2;1664 };1665 /* Copyright (c) 2013, Brandon Jones, Colin MacKenzie IV. All rights reserved.1666Redistribution and use in source and binary forms, with or without modification,1667are permitted provided that the following conditions are met:1668 * Redistributions of source code must retain the above copyright notice, this1669 list of conditions and the following disclaimer.1670 * Redistributions in binary form must reproduce the above copyright notice,1671 this list of conditions and the following disclaimer in the documentation 1672 and/or other materials provided with the distribution.1673THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND1674ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED1675WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 1676DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR1677ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES1678(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;1679LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON1680ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT1681(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS1682SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */1683 /**1684 * @class 2x3 Matrix1685 * @name mat2d1686 *1687 * @description1688 * A mat2d contains six elements defined as:1689 * <pre>1690 * [a, b,1691 * c, d,1692 * tx,ty]1693 * </pre>1694 * This is a short form for the 3x3 matrix:1695 * <pre>1696 * [a, b, 01697 * c, d, 01698 * tx,ty,1]1699 * </pre>1700 * The last column is ignored so the array is shorter and operations are faster.1701 */1702 var mat2d = {};1703 var mat2dIdentity = new Float32Array([1704 1, 0,1705 0, 1,1706 0, 01707 ]);1708 /**1709 * Creates a new identity mat2d1710 *1711 * @returns {mat2d} a new 2x3 matrix1712 */1713 mat2d.create = function() {1714 var out = new GLMAT_ARRAY_TYPE(6);1715 out[0] = 1;1716 out[1] = 0;1717 out[2] = 0;1718 out[3] = 1;1719 out[4] = 0;1720 out[5] = 0;1721 return out;1722 };1723 /**1724 * Creates a new mat2d initialized with values from an existing matrix1725 *1726 * @param {mat2d} a matrix to clone1727 * @returns {mat2d} a new 2x3 matrix1728 */1729 mat2d.clone = function(a) {1730 var out = new GLMAT_ARRAY_TYPE(6);1731 out[0] = a[0];1732 out[1] = a[1];1733 out[2] = a[2];1734 out[3] = a[3];1735 out[4] = a[4];1736 out[5] = a[5];1737 return out;1738 };1739 /**1740 * Copy the values from one mat2d to another1741 *1742 * @param {mat2d} out the receiving matrix1743 * @param {mat2d} a the source matrix1744 * @returns {mat2d} out1745 */1746 mat2d.copy = function(out, a) {1747 out[0] = a[0];1748 out[1] = a[1];1749 out[2] = a[2];1750 out[3] = a[3];1751 out[4] = a[4];1752 out[5] = a[5];1753 return out;1754 };1755 /**1756 * Set a mat2d to the identity matrix1757 *1758 * @param {mat2d} out the receiving matrix1759 * @returns {mat2d} out1760 */1761 mat2d.identity = function(out) {1762 out[0] = 1;1763 out[1] = 0;1764 out[2] = 0;1765 out[3] = 1;1766 out[4] = 0;1767 out[5] = 0;1768 return out;1769 };1770 /**1771 * Inverts a mat2d1772 *1773 * @param {mat2d} out the receiving matrix1774 * @param {mat2d} a the source matrix1775 * @returns {mat2d} out1776 */1777 mat2d.invert = function(out, a) {1778 var aa = a[0],1779 ab = a[1],1780 ac = a[2],1781 ad = a[3],1782 atx = a[4],1783 aty = a[5];1784 var det = aa * ad - ab * ac;1785 if (!det) {1786 return null;1787 }1788 det = 1.0 / det;1789 out[0] = ad * det;1790 out[1] = -ab * det;1791 out[2] = -ac * det;1792 out[3] = aa * det;1793 out[4] = (ac * aty - ad * atx) * det;1794 out[5] = (ab * atx - aa * aty) * det;1795 return out;1796 };1797 /**1798 * Calculates the determinant of a mat2d1799 *1800 * @param {mat2d} a the source matrix1801 * @returns {Number} determinant of a1802 */1803 mat2d.determinant = function(a) {1804 return a[0] * a[3] - a[1] * a[2];1805 };1806 /**1807 * Multiplies two mat2d's1808 *1809 * @param {mat2d} out the receiving matrix1810 * @param {mat2d} a the first operand1811 * @param {mat2d} b the second operand1812 * @returns {mat2d} out1813 */1814 mat2d.multiply = function(out, a, b) {1815 var aa = a[0],1816 ab = a[1],1817 ac = a[2],1818 ad = a[3],1819 atx = a[4],1820 aty = a[5],1821 ba = b[0],1822 bb = b[1],1823 bc = b[2],1824 bd = b[3],1825 btx = b[4],1826 bty = b[5];1827 out[0] = aa * ba + ab * bc;1828 out[1] = aa * bb + ab * bd;1829 out[2] = ac * ba + ad * bc;1830 out[3] = ac * bb + ad * bd;1831 out[4] = ba * atx + bc * aty + btx;1832 out[5] = bb * atx + bd * aty + bty;1833 return out;1834 };1835 /**1836 * Alias for {@link mat2d.multiply}1837 * @function1838 */1839 mat2d.mul = mat2d.multiply;1840 /**1841 * Rotates a mat2d by the given angle1842 *1843 * @param {mat2d} out the receiving matrix1844 * @param {mat2d} a the matrix to rotate1845 * @param {Number} rad the angle to rotate the matrix by1846 * @returns {mat2d} out1847 */1848 mat2d.rotate = function(out, a, rad) {1849 var aa = a[0],1850 ab = a[1],1851 ac = a[2],1852 ad = a[3],1853 atx = a[4],1854 aty = a[5],1855 st = Math.sin(rad),1856 ct = Math.cos(rad);1857 out[0] = aa * ct + ab * st;1858 out[1] = -aa * st + ab * ct;1859 out[2] = ac * ct + ad * st;1860 out[3] = -ac * st + ct * ad;1861 out[4] = ct * atx + st * aty;1862 out[5] = ct * aty - st * atx;1863 return out;1864 };1865 /**1866 * Scales the mat2d by the dimensions in the given vec21867 *1868 * @param {mat2d} out the receiving matrix1869 * @param {mat2d} a the matrix to translate1870 * @param {mat2d} v the vec2 to scale the matrix by1871 * @returns {mat2d} out1872 **/1873 mat2d.scale = function(out, a, v) {1874 var vx = v[0],1875 vy = v[1];1876 out[0] = a[0] * vx;1877 out[1] = a[1] * vy;1878 out[2] = a[2] * vx;1879 out[3] = a[3] * vy;1880 out[4] = a[4] * vx;1881 out[5] = a[5] * vy;1882 return out;1883 };1884 /**1885 * Translates the mat2d by the dimensions in the given vec21886 *1887 * @param {mat2d} out the receiving matrix1888 * @param {mat2d} a the matrix to translate1889 * @param {mat2d} v the vec2 to translate the matrix by1890 * @returns {mat2d} out1891 **/1892 mat2d.translate = function(out, a, v) {1893 out[0] = a[0];1894 out[1] = a[1];1895 out[2] = a[2];1896 out[3] = a[3];1897 out[4] = a[4] + v[0];1898 out[5] = a[5] + v[1];1899 return out;1900 };1901 /**1902 * Returns a string representation of a mat2d1903 *1904 * @param {mat2d} a matrix to represent as a string1905 * @returns {String} string representation of the matrix1906 */1907 mat2d.str = function(a) {1908 return 'mat2d(' + a[0] + ', ' + a[1] + ', ' + a[2] + ', ' +1909 a[3] + ', ' + a[4] + ', ' + a[5] + ')';1910 };1911 if (typeof(exports) !== 'undefined') {1912 exports.mat2d = mat2d;1913 };1914 /* Copyright (c) 2013, Brandon Jones, Colin MacKenzie IV. All rights reserved.1915Redistribution and use in source and binary forms, with or without modification,1916are permitted provided that the following conditions are met:1917 * Redistributions of source code must retain the above copyright notice, this1918 list of conditions and the following disclaimer.1919 * Redistributions in binary form must reproduce the above copyright notice,1920 this list of conditions and the following disclaimer in the documentation 1921 and/or other materials provided with the distribution.1922THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND1923ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED1924WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 1925DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR1926ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES1927(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;1928LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON1929ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT1930(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS1931SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */1932 /**1933 * @class 3x3 Matrix1934 * @name mat31935 */1936 var mat3 = {};1937 var mat3Identity = new Float32Array([1938 1, 0, 0,1939 0, 1, 0,1940 0, 0, 11941 ]);1942 /**1943 * Creates a new identity mat31944 *1945 * @returns {mat3} a new 3x3 matrix1946 */1947 mat3.create = function() {1948 var out = new GLMAT_ARRAY_TYPE(9);1949 out[0] = 1;1950 out[1] = 0;1951 out[2] = 0;1952 out[3] = 0;1953 out[4] = 1;1954 out[5] = 0;1955 out[6] = 0;1956 out[7] = 0;1957 out[8] = 1;1958 return out;1959 };1960 /**1961 * Creates a new mat3 initialized with values from an existing matrix1962 *1963 * @param {mat3} a matrix to clone1964 * @returns {mat3} a new 3x3 matrix1965 */1966 mat3.clone = function(a) {1967 var out = new GLMAT_ARRAY_TYPE(9);1968 out[0] = a[0];1969 out[1] = a[1];1970 out[2] = a[2];1971 out[3] = a[3];1972 out[4] = a[4];1973 out[5] = a[5];1974 out[6] = a[6];1975 out[7] = a[7];1976 out[8] = a[8];1977 return out;1978 };1979 /**1980 * Copy the values from one mat3 to another1981 *1982 * @param {mat3} out the receiving matrix1983 * @param {mat3} a the source matrix1984 * @returns {mat3} out1985 */1986 mat3.copy = function(out, a) {1987 out[0] = a[0];1988 out[1] = a[1];1989 out[2] = a[2];1990 out[3] = a[3];1991 out[4] = a[4];1992 out[5] = a[5];1993 out[6] = a[6];1994 out[7] = a[7];1995 out[8] = a[8];1996 return out;1997 };1998 /**1999 * Set a mat3 to the identity matrix2000 *2001 * @param {mat3} out the receiving matrix2002 * @returns {mat3} out2003 */2004 mat3.identity = function(out) {2005 out[0] = 1;2006 out[1] = 0;2007 out[2] = 0;2008 out[3] = 0;2009 out[4] = 1;2010 out[5] = 0;2011 out[6] = 0;2012 out[7] = 0;2013 out[8] = 1;2014 return out;2015 };2016 /**2017 * Transpose the values of a mat32018 *2019 * @param {mat3} out the receiving matrix2020 * @param {mat3} a the source matrix2021 * @returns {mat3} out2022 */2023 mat3.transpose = function(out, a) {2024 // If we are transposing ourselves we can skip a few steps but have to cache some values2025 if (out === a) {2026 var a01 = a[1],2027 a02 = a[2],2028 a12 = a[5];2029 out[1] = a[3];2030 out[2] = a[6];2031 out[3] = a01;2032 out[5] = a[7];2033 out[6] = a02;2034 out[7] = a12;2035 } else {2036 out[0] = a[0];2037 out[1] = a[3];2038 out[2] = a[6];2039 out[3] = a[1];2040 out[4] = a[4];2041 out[5] = a[7];2042 out[6] = a[2];2043 out[7] = a[5];2044 out[8] = a[8];2045 }2046 return out;2047 };2048 /**2049 * Inverts a mat32050 *2051 * @param {mat3} out the receiving matrix2052 * @param {mat3} a the source matrix2053 * @returns {mat3} out2054 */2055 mat3.invert = function(out, a) {2056 var a00 = a[0],2057 a01 = a[1],2058 a02 = a[2],2059 a10 = a[3],2060 a11 = a[4],2061 a12 = a[5],2062 a20 = a[6],2063 a21 = a[7],2064 a22 = a[8],2065 b01 = a22 * a11 - a12 * a21,2066 b11 = -a22 * a10 + a12 * a20,2067 b21 = a21 * a10 - a11 * a20,2068 // Calculate the determinant2069 det = a00 * b01 + a01 * b11 + a02 * b21;2070 if (!det) {2071 return null;2072 }2073 det = 1.0 / det;2074 out[0] = b01 * det;2075 out[1] = (-a22 * a01 + a02 * a21) * det;2076 out[2] = (a12 * a01 - a02 * a11) * det;2077 out[3] = b11 * det;2078 out[4] = (a22 * a00 - a02 * a20) * det;2079 out[5] = (-a12 * a00 + a02 * a10) * det;2080 out[6] = b21 * det;2081 out[7] = (-a21 * a00 + a01 * a20) * det;2082 out[8] = (a11 * a00 - a01 * a10) * det;2083 return out;2084 };2085 /**2086 * Calculates the adjugate of a mat32087 *2088 * @param {mat3} out the receiving matrix2089 * @param {mat3} a the source matrix2090 * @returns {mat3} out2091 */2092 mat3.adjoint = function(out, a) {2093 var a00 = a[0],2094 a01 = a[1],2095 a02 = a[2],2096 a10 = a[3],2097 a11 = a[4],2098 a12 = a[5],2099 a20 = a[6],2100 a21 = a[7],2101 a22 = a[8];2102 out[0] = (a11 * a22 - a12 * a21);2103 out[1] = (a02 * a21 - a01 * a22);2104 out[2] = (a01 * a12 - a02 * a11);2105 out[3] = (a12 * a20 - a10 * a22);2106 out[4] = (a00 * a22 - a02 * a20);2107 out[5] = (a02 * a10 - a00 * a12);2108 out[6] = (a10 * a21 - a11 * a20);2109 out[7] = (a01 * a20 - a00 * a21);2110 out[8] = (a00 * a11 - a01 * a10);2111 return out;2112 };2113 /**2114 * Calculates the determinant of a mat32115 *2116 * @param {mat3} a the source matrix2117 * @returns {Number} determinant of a2118 */2119 mat3.determinant = function(a) {2120 var a00 = a[0],2121 a01 = a[1],2122 a02 = a[2],2123 a10 = a[3],2124 a11 = a[4],2125 a12 = a[5],2126 a20 = a[6],2127 a21 = a[7],2128 a22 = a[8];2129 return a00 * (a22 * a11 - a12 * a21) + a01 * (-a22 * a10 + a12 * a20) + a02 * (a21 * a10 - a11 * a20);2130 };2131 /**2132 * Multiplies two mat3's2133 *2134 * @param {mat3} out the receiving matrix2135 * @param {mat3} a the first operand2136 * @param {mat3} b the second operand2137 * @returns {mat3} out2138 */2139 mat3.multiply = function(out, a, b) {2140 var a00 = a[0],2141 a01 = a[1],2142 a02 = a[2],2143 a10 = a[3],2144 a11 = a[4],2145 a12 = a[5],2146 a20 = a[6],2147 a21 = a[7],2148 a22 = a[8],2149 b00 = b[0],2150 b01 = b[1],2151 b02 = b[2],2152 b10 = b[3],2153 b11 = b[4],2154 b12 = b[5],2155 b20 = b[6],2156 b21 = b[7],2157 b22 = b[8];2158 out[0] = b00 * a00 + b01 * a10 + b02 * a20;2159 out[1] = b00 * a01 + b01 * a11 + b02 * a21;2160 out[2] = b00 * a02 + b01 * a12 + b02 * a22;2161 out[3] = b10 * a00 + b11 * a10 + b12 * a20;2162 out[4] = b10 * a01 + b11 * a11 + b12 * a21;2163 out[5] = b10 * a02 + b11 * a12 + b12 * a22;2164 out[6] = b20 * a00 + b21 * a10 + b22 * a20;2165 out[7] = b20 * a01 + b21 * a11 + b22 * a21;2166 out[8] = b20 * a02 + b21 * a12 + b22 * a22;2167 return out;2168 };2169 /**2170 * Alias for {@link mat3.multiply}2171 * @function2172 */2173 mat3.mul = mat3.multiply;2174 /**2175 * Translate a mat3 by the given vector2176 *2177 * @param {mat3} out the receiving matrix2178 * @param {mat3} a the matrix to translate2179 * @param {vec2} v vector to translate by2180 * @returns {mat3} out2181 */2182 mat3.translate = function(out, a, v) {2183 var a00 = a[0],2184 a01 = a[1],2185 a02 = a[2],2186 a10 = a[3],2187 a11 = a[4],2188 a12 = a[5],2189 a20 = a[6],2190 a21 = a[7],2191 a22 = a[8],2192 x = v[0],2193 y = v[1];2194 out[0] = a00;2195 out[1] = a01;2196 out[2] = a02;2197 out[3] = a10;2198 out[4] = a11;2199 out[5] = a12;2200 out[6] = x * a00 + y * a10 + a20;2201 out[7] = x * a01 + y * a11 + a21;2202 out[8] = x * a02 + y * a12 + a22;2203 return out;2204 };2205 /**2206 * Rotates a mat3 by the given angle2207 *2208 * @param {mat3} out the receiving matrix2209 * @param {mat3} a the matrix to rotate2210 * @param {Number} rad the angle to rotate the matrix by2211 * @returns {mat3} out2212 */2213 mat3.rotate = function(out, a, rad) {2214 var a00 = a[0],2215 a01 = a[1],2216 a02 = a[2],2217 a10 = a[3],2218 a11 = a[4],2219 a12 = a[5],2220 a20 = a[6],2221 a21 = a[7],2222 a22 = a[8],2223 s = Math.sin(rad),2224 c = Math.cos(rad);2225 out[0] = c * a00 + s * a10;2226 out[1] = c * a01 + s * a11;2227 out[2] = c * a02 + s * a12;2228 out[3] = c * a10 - s * a00;2229 out[4] = c * a11 - s * a01;2230 out[5] = c * a12 - s * a02;2231 out[6] = a20;2232 out[7] = a21;2233 out[8] = a22;2234 return out;2235 };2236 /**2237 * Scales the mat3 by the dimensions in the given vec22238 *2239 * @param {mat3} out the receiving matrix2240 * @param {mat3} a the matrix to rotate2241 * @param {vec2} v the vec2 to scale the matrix by2242 * @returns {mat3} out2243 **/2244 mat3.scale = function(out, a, v) {2245 var x = v[0],2246 y = v[2];2247 out[0] = x * a[0];2248 out[1] = x * a[1];2249 out[2] = x * a[2];2250 out[3] = y * a[3];2251 out[4] = y * a[4];2252 out[5] = y * a[5];2253 out[6] = a[6];2254 out[7] = a[7];2255 out[8] = a[8];2256 return out;2257 };2258 /**2259 * Copies the values from a mat2d into a mat32260 *2261 * @param {mat3} out the receiving matrix2262 * @param {mat3} a the matrix to rotate2263 * @param {vec2} v the vec2 to scale the matrix by2264 * @returns {mat3} out2265 **/2266 mat3.fromMat2d = function(out, a) {2267 out[0] = a[0];2268 out[1] = a[1];2269 out[2] = 0;2270 out[3] = a[2];2271 out[4] = a[3];2272 out[5] = 0;2273 out[6] = a[4];2274 out[7] = a[5];2275 out[8] = 1;2276 return out;2277 };2278 /**2279 * Calculates a 3x3 matrix from the given quaternion2280 *2281 * @param {mat3} out mat3 receiving operation result2282 * @param {quat} q Quaternion to create matrix from2283 *2284 * @returns {mat3} out2285 */2286 mat3.fromQuat = function(out, q) {2287 var x = q[0],2288 y = q[1],2289 z = q[2],2290 w = q[3],2291 x2 = x + x,2292 y2 = y + y,2293 z2 = z + z,2294 xx = x * x2,2295 xy = x * y2,2296 xz = x * z2,2297 yy = y * y2,2298 yz = y * z2,2299 zz = z * z2,2300 wx = w * x2,2301 wy = w * y2,2302 wz = w * z2;2303 out[0] = 1 - (yy + zz);2304 out[1] = xy + wz;2305 out[2] = xz - wy;2306 out[3] = xy - wz;2307 out[4] = 1 - (xx + zz);2308 out[5] = yz + wx;2309 out[6] = xz + wy;2310 out[7] = yz - wx;2311 out[8] = 1 - (xx + yy);2312 return out;2313 };2314 /**2315 * Returns a string representation of a mat32316 *2317 * @param {mat3} mat matrix to represent as a string2318 * @returns {String} string representation of the matrix2319 */2320 mat3.str = function(a) {2321 return 'mat3(' + a[0] + ', ' + a[1] + ', ' + a[2] + ', ' +2322 a[3] + ', ' + a[4] + ', ' + a[5] + ', ' +2323 a[6] + ', ' + a[7] + ', ' + a[8] + ')';2324 };2325 if (typeof(exports) !== 'undefined') {2326 exports.mat3 = mat3;2327 };2328 /* Copyright (c) 2013, Brandon Jones, Colin MacKenzie IV. All rights reserved.2329Redistribution and use in source and binary forms, with or without modification,2330are permitted provided that the following conditions are met:2331 * Redistributions of source code must retain the above copyright notice, this2332 list of conditions and the following disclaimer.2333 * Redistributions in binary form must reproduce the above copyright notice,2334 this list of conditions and the following disclaimer in the documentation 2335 and/or other materials provided with the distribution.2336THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND2337ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED2338WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 2339DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR2340ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES2341(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;2342LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON2343ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT2344(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS2345SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */2346 /**2347 * @class 4x4 Matrix2348 * @name mat42349 */2350 var mat4 = {};2351 var mat4Identity = new Float32Array([2352 1, 0, 0, 0,2353 0, 1, 0, 0,2354 0, 0, 1, 0,2355 0, 0, 0, 12356 ]);2357 /**2358 * Creates a new identity mat42359 *2360 * @returns {mat4} a new 4x4 matrix2361 */2362 mat4.create = function() {2363 var out = new GLMAT_ARRAY_TYPE(16);2364 out[0] = 1;2365 out[1] = 0;2366 out[2] = 0;2367 out[3] = 0;2368 out[4] = 0;2369 out[5] = 1;2370 out[6] = 0;2371 out[7] = 0;2372 out[8] = 0;2373 out[9] = 0;2374 out[10] = 1;2375 out[11] = 0;2376 out[12] = 0;2377 out[13] = 0;2378 out[14] = 0;2379 out[15] = 1;2380 return out;2381 };2382 /**2383 * Creates a new mat4 initialized with values from an existing matrix2384 *2385 * @param {mat4} a matrix to clone2386 * @returns {mat4} a new 4x4 matrix2387 */2388 mat4.clone = function(a) {2389 var out = new GLMAT_ARRAY_TYPE(16);2390 out[0] = a[0];2391 out[1] = a[1];2392 out[2] = a[2];2393 out[3] = a[3];2394 out[4] = a[4];2395 out[5] = a[5];2396 out[6] = a[6];2397 out[7] = a[7];2398 out[8] = a[8];2399 out[9] = a[9];2400 out[10] = a[10];2401 out[11] = a[11];2402 out[12] = a[12];2403 out[13] = a[13];2404 out[14] = a[14];2405 out[15] = a[15];2406 return out;2407 };2408 /**2409 * Copy the values from one mat4 to another2410 *2411 * @param {mat4} out the receiving matrix2412 * @param {mat4} a the source matrix2413 * @returns {mat4} out2414 */2415 mat4.copy = function(out, a) {2416 out[0] = a[0];2417 out[1] = a[1];2418 out[2] = a[2];2419 out[3] = a[3];2420 out[4] = a[4];2421 out[5] = a[5];2422 out[6] = a[6];2423 out[7] = a[7];2424 out[8] = a[8];2425 out[9] = a[9];2426 out[10] = a[10];2427 out[11] = a[11];2428 out[12] = a[12];2429 out[13] = a[13];2430 out[14] = a[14];2431 out[15] = a[15];2432 return out;2433 };2434 /**2435 * Set a mat4 to the identity matrix2436 *2437 * @param {mat4} out the receiving matrix2438 * @returns {mat4} out2439 */2440 mat4.identity = function(out) {2441 out[0] = 1;2442 out[1] = 0;2443 out[2] = 0;2444 out[3] = 0;2445 out[4] = 0;2446 out[5] = 1;2447 out[6] = 0;2448 out[7] = 0;2449 out[8] = 0;2450 out[9] = 0;2451 out[10] = 1;2452 out[11] = 0;2453 out[12] = 0;2454 out[13] = 0;2455 out[14] = 0;2456 out[15] = 1;2457 return out;2458 };2459 /**2460 * Transpose the values of a mat42461 *2462 * @param {mat4} out the receiving matrix2463 * @param {mat4} a the source matrix2464 * @returns {mat4} out2465 */2466 mat4.transpose = function(out, a) {2467 // If we are transposing ourselves we can skip a few steps but have to cache some values2468 if (out === a) {2469 var a01 = a[1],2470 a02 = a[2],2471 a03 = a[3],2472 a12 = a[6],2473 a13 = a[7],2474 a23 = a[11];2475 out[1] = a[4];2476 out[2] = a[8];2477 out[3] = a[12];2478 out[4] = a01;2479 out[6] = a[9];2480 out[7] = a[13];2481 out[8] = a02;2482 out[9] = a12;2483 out[11] = a[14];2484 out[12] = a03;2485 out[13] = a13;2486 out[14] = a23;2487 } else {2488 out[0] = a[0];2489 out[1] = a[4];2490 out[2] = a[8];2491 out[3] = a[12];2492 out[4] = a[1];2493 out[5] = a[5];2494 out[6] = a[9];2495 out[7] = a[13];2496 out[8] = a[2];2497 out[9] = a[6];2498 out[10] = a[10];2499 out[11] = a[14];2500 out[12] = a[3];2501 out[13] = a[7];2502 out[14] = a[11];2503 out[15] = a[15];2504 }2505 return out;2506 };2507 /**2508 * Inverts a mat42509 *2510 * @param {mat4} out the receiving matrix2511 * @param {mat4} a the source matrix2512 * @returns {mat4} out2513 */2514 mat4.invert = function(out, a) {2515 var a00 = a[0],2516 a01 = a[1],2517 a02 = a[2],2518 a03 = a[3],2519 a10 = a[4],2520 a11 = a[5],2521 a12 = a[6],2522 a13 = a[7],2523 a20 = a[8],2524 a21 = a[9],2525 a22 = a[10],2526 a23 = a[11],2527 a30 = a[12],2528 a31 = a[13],2529 a32 = a[14],2530 a33 = a[15],2531 b00 = a00 * a11 - a01 * a10,2532 b01 = a00 * a12 - a02 * a10,2533 b02 = a00 * a13 - a03 * a10,2534 b03 = a01 * a12 - a02 * a11,2535 b04 = a01 * a13 - a03 * a11,2536 b05 = a02 * a13 - a03 * a12,2537 b06 = a20 * a31 - a21 * a30,2538 b07 = a20 * a32 - a22 * a30,2539 b08 = a20 * a33 - a23 * a30,2540 b09 = a21 * a32 - a22 * a31,2541 b10 = a21 * a33 - a23 * a31,2542 b11 = a22 * a33 - a23 * a32,2543 // Calculate the determinant2544 det = b00 * b11 - b01 * b10 + b02 * b09 + b03 * b08 - b04 * b07 + b05 * b06;2545 if (!det) {2546 return null;2547 }2548 det = 1.0 / det;2549 out[0] = (a11 * b11 - a12 * b10 + a13 * b09) * det;2550 out[1] = (a02 * b10 - a01 * b11 - a03 * b09) * det;2551 out[2] = (a31 * b05 - a32 * b04 + a33 * b03) * det;2552 out[3] = (a22 * b04 - a21 * b05 - a23 * b03) * det;2553 out[4] = (a12 * b08 - a10 * b11 - a13 * b07) * det;2554 out[5] = (a00 * b11 - a02 * b08 + a03 * b07) * det;2555 out[6] = (a32 * b02 - a30 * b05 - a33 * b01) * det;2556 out[7] = (a20 * b05 - a22 * b02 + a23 * b01) * det;2557 out[8] = (a10 * b10 - a11 * b08 + a13 * b06) * det;2558 out[9] = (a01 * b08 - a00 * b10 - a03 * b06) * det;2559 out[10] = (a30 * b04 - a31 * b02 + a33 * b00) * det;2560 out[11] = (a21 * b02 - a20 * b04 - a23 * b00) * det;2561 out[12] = (a11 * b07 - a10 * b09 - a12 * b06) * det;2562 out[13] = (a00 * b09 - a01 * b07 + a02 * b06) * det;2563 out[14] = (a31 * b01 - a30 * b03 - a32 * b00) * det;2564 out[15] = (a20 * b03 - a21 * b01 + a22 * b00) * det;2565 return out;2566 };2567 /**2568 * Calculates the adjugate of a mat42569 *2570 * @param {mat4} out the receiving matrix2571 * @param {mat4} a the source matrix2572 * @returns {mat4} out2573 */2574 mat4.adjoint = function(out, a) {2575 var a00 = a[0],2576 a01 = a[1],2577 a02 = a[2],2578 a03 = a[3],2579 a10 = a[4],2580 a11 = a[5],2581 a12 = a[6],2582 a13 = a[7],2583 a20 = a[8],2584 a21 = a[9],2585 a22 = a[10],2586 a23 = a[11],2587 a30 = a[12],2588 a31 = a[13],2589 a32 = a[14],2590 a33 = a[15];2591 out[0] = (a11 * (a22 * a33 - a23 * a32) - a21 * (a12 * a33 - a13 * a32) + a31 * (a12 * a23 - a13 * a22));2592 out[1] = -(a01 * (a22 * a33 - a23 * a32) - a21 * (a02 * a33 - a03 * a32) + a31 * (a02 * a23 - a03 * a22));2593 out[2] = (a01 * (a12 * a33 - a13 * a32) - a11 * (a02 * a33 - a03 * a32) + a31 * (a02 * a13 - a03 * a12));2594 out[3] = -(a01 * (a12 * a23 - a13 * a22) - a11 * (a02 * a23 - a03 * a22) + a21 * (a02 * a13 - a03 * a12));2595 out[4] = -(a10 * (a22 * a33 - a23 * a32) - a20 * (a12 * a33 - a13 * a32) + a30 * (a12 * a23 - a13 * a22));2596 out[5] = (a00 * (a22 * a33 - a23 * a32) - a20 * (a02 * a33 - a03 * a32) + a30 * (a02 * a23 - a03 * a22));2597 out[6] = -(a00 * (a12 * a33 - a13 * a32) - a10 * (a02 * a33 - a03 * a32) + a30 * (a02 * a13 - a03 * a12));2598 out[7] = (a00 * (a12 * a23 - a13 * a22) - a10 * (a02 * a23 - a03 * a22) + a20 * (a02 * a13 - a03 * a12));2599 out[8] = (a10 * (a21 * a33 - a23 * a31) - a20 * (a11 * a33 - a13 * a31) + a30 * (a11 * a23 - a13 * a21));2600 out[9] = -(a00 * (a21 * a33 - a23 * a31) - a20 * (a01 * a33 - a03 * a31) + a30 * (a01 * a23 - a03 * a21));2601 out[10] = (a00 * (a11 * a33 - a13 * a31) - a10 * (a01 * a33 - a03 * a31) + a30 * (a01 * a13 - a03 * a11));2602 out[11] = -(a00 * (a11 * a23 - a13 * a21) - a10 * (a01 * a23 - a03 * a21) + a20 * (a01 * a13 - a03 * a11));2603 out[12] = -(a10 * (a21 * a32 - a22 * a31) - a20 * (a11 * a32 - a12 * a31) + a30 * (a11 * a22 - a12 * a21));2604 out[13] = (a00 * (a21 * a32 - a22 * a31) - a20 * (a01 * a32 - a02 * a31) + a30 * (a01 * a22 - a02 * a21));2605 out[14] = -(a00 * (a11 * a32 - a12 * a31) - a10 * (a01 * a32 - a02 * a31) + a30 * (a01 * a12 - a02 * a11));2606 out[15] = (a00 * (a11 * a22 - a12 * a21) - a10 * (a01 * a22 - a02 * a21) + a20 * (a01 * a12 - a02 * a11));2607 return out;2608 };2609 /**2610 * Calculates the determinant of a mat42611 *2612 * @param {mat4} a the source matrix2613 * @returns {Number} determinant of a2614 */2615 mat4.determinant = function(a) {2616 var a00 = a[0],2617 a01 = a[1],2618 a02 = a[2],2619 a03 = a[3],2620 a10 = a[4],2621 a11 = a[5],2622 a12 = a[6],2623 a13 = a[7],2624 a20 = a[8],2625 a21 = a[9],2626 a22 = a[10],2627 a23 = a[11],2628 a30 = a[12],2629 a31 = a[13],2630 a32 = a[14],2631 a33 = a[15],2632 b00 = a00 * a11 - a01 * a10,2633 b01 = a00 * a12 - a02 * a10,2634 b02 = a00 * a13 - a03 * a10,2635 b03 = a01 * a12 - a02 * a11,2636 b04 = a01 * a13 - a03 * a11,2637 b05 = a02 * a13 - a03 * a12,2638 b06 = a20 * a31 - a21 * a30,2639 b07 = a20 * a32 - a22 * a30,2640 b08 = a20 * a33 - a23 * a30,2641 b09 = a21 * a32 - a22 * a31,2642 b10 = a21 * a33 - a23 * a31,2643 b11 = a22 * a33 - a23 * a32;2644 // Calculate the determinant2645 return b00 * b11 - b01 * b10 + b02 * b09 + b03 * b08 - b04 * b07 + b05 * b06;2646 };2647 /**2648 * Multiplies two mat4's2649 *2650 * @param {mat4} out the receiving matrix2651 * @param {mat4} a the first operand2652 * @param {mat4} b the second operand2653 * @returns {mat4} out2654 */2655 mat4.multiply = function(out, a, b) {2656 var a00 = a[0],2657 a01 = a[1],2658 a02 = a[2],2659 a03 = a[3],2660 a10 = a[4],2661 a11 = a[5],2662 a12 = a[6],2663 a13 = a[7],2664 a20 = a[8],2665 a21 = a[9],2666 a22 = a[10],2667 a23 = a[11],2668 a30 = a[12],2669 a31 = a[13],2670 a32 = a[14],2671 a33 = a[15];2672 // Cache only the current line of the second matrix2673 var b0 = b[0],2674 b1 = b[1],2675 b2 = b[2],2676 b3 = b[3];2677 out[0] = b0 * a00 + b1 * a10 + b2 * a20 + b3 * a30;2678 out[1] = b0 * a01 + b1 * a11 + b2 * a21 + b3 * a31;2679 out[2] = b0 * a02 + b1 * a12 + b2 * a22 + b3 * a32;2680 out[3] = b0 * a03 + b1 * a13 + b2 * a23 + b3 * a33;2681 b0 = b[4];2682 b1 = b[5];2683 b2 = b[6];2684 b3 = b[7];2685 out[4] = b0 * a00 + b1 * a10 + b2 * a20 + b3 * a30;2686 out[5] = b0 * a01 + b1 * a11 + b2 * a21 + b3 * a31;2687 out[6] = b0 * a02 + b1 * a12 + b2 * a22 + b3 * a32;2688 out[7] = b0 * a03 + b1 * a13 + b2 * a23 + b3 * a33;2689 b0 = b[8];2690 b1 = b[9];2691 b2 = b[10];2692 b3 = b[11];2693 out[8] = b0 * a00 + b1 * a10 + b2 * a20 + b3 * a30;2694 out[9] = b0 * a01 + b1 * a11 + b2 * a21 + b3 * a31;2695 out[10] = b0 * a02 + b1 * a12 + b2 * a22 + b3 * a32;2696 out[11] = b0 * a03 + b1 * a13 + b2 * a23 + b3 * a33;2697 b0 = b[12];2698 b1 = b[13];2699 b2 = b[14];2700 b3 = b[15];2701 out[12] = b0 * a00 + b1 * a10 + b2 * a20 + b3 * a30;2702 out[13] = b0 * a01 + b1 * a11 + b2 * a21 + b3 * a31;2703 out[14] = b0 * a02 + b1 * a12 + b2 * a22 + b3 * a32;2704 out[15] = b0 * a03 + b1 * a13 + b2 * a23 + b3 * a33;2705 return out;2706 };2707 /**2708 * Alias for {@link mat4.multiply}2709 * @function2710 */2711 mat4.mul = mat4.multiply;2712 /**2713 * Translate a mat4 by the given vector2714 *2715 * @param {mat4} out the receiving matrix2716 * @param {mat4} a the matrix to translate2717 * @param {vec3} v vector to translate by2718 * @returns {mat4} out2719 */2720 mat4.translate = function(out, a, v) {2721 var x = v[0],2722 y = v[1],2723 z = v[2],2724 a00, a01, a02, a03,2725 a10, a11, a12, a13,2726 a20, a21, a22, a23;2727 if (a === out) {2728 out[12] = a[0] * x + a[4] * y + a[8] * z + a[12];2729 out[13] = a[1] * x + a[5] * y + a[9] * z + a[13];2730 out[14] = a[2] * x + a[6] * y + a[10] * z + a[14];2731 out[15] = a[3] * x + a[7] * y + a[11] * z + a[15];2732 } else {2733 a00 = a[0];2734 a01 = a[1];2735 a02 = a[2];2736 a03 = a[3];2737 a10 = a[4];2738 a11 = a[5];2739 a12 = a[6];2740 a13 = a[7];2741 a20 = a[8];2742 a21 = a[9];2743 a22 = a[10];2744 a23 = a[11];2745 out[0] = a00;2746 out[1] = a01;2747 out[2] = a02;2748 out[3] = a03;2749 out[4] = a10;2750 out[5] = a11;2751 out[6] = a12;2752 out[7] = a13;2753 out[8] = a20;2754 out[9] = a21;2755 out[10] = a22;2756 out[11] = a23;2757 out[12] = a00 * x + a10 * y + a20 * z + a[12];2758 out[13] = a01 * x + a11 * y + a21 * z + a[13];2759 out[14] = a02 * x + a12 * y + a22 * z + a[14];2760 out[15] = a03 * x + a13 * y + a23 * z + a[15];2761 }2762 return out;2763 };2764 /**2765 * Scales the mat4 by the dimensions in the given vec32766 *2767 * @param {mat4} out the receiving matrix2768 * @param {mat4} a the matrix to scale2769 * @param {vec3} v the vec3 to scale the matrix by2770 * @returns {mat4} out2771 **/2772 mat4.scale = function(out, a, v) {2773 var x = v[0],2774 y = v[1],2775 z = v[2];2776 out[0] = a[0] * x;2777 out[1] = a[1] * x;2778 out[2] = a[2] * x;2779 out[3] = a[3] * x;2780 out[4] = a[4] * y;2781 out[5] = a[5] * y;2782 out[6] = a[6] * y;2783 out[7] = a[7] * y;2784 out[8] = a[8] * z;2785 out[9] = a[9] * z;2786 out[10] = a[10] * z;2787 out[11] = a[11] * z;2788 out[12] = a[12];2789 out[13] = a[13];2790 out[14] = a[14];2791 out[15] = a[15];2792 return out;2793 };2794 /**2795 * Rotates a mat4 by the given angle2796 *2797 * @param {mat4} out the receiving matrix2798 * @param {mat4} a the matrix to rotate2799 * @param {Number} rad the angle to rotate the matrix by2800 * @param {vec3} axis the axis to rotate around2801 * @returns {mat4} out2802 */2803 mat4.rotate = function(out, a, rad, axis) {2804 var x = axis[0],2805 y = axis[1],2806 z = axis[2],2807 len = Math.sqrt(x * x + y * y + z * z),2808 s, c, t,2809 a00, a01, a02, a03,2810 a10, a11, a12, a13,2811 a20, a21, a22, a23,2812 b00, b01, b02,2813 b10, b11, b12,2814 b20, b21, b22;2815 if (Math.abs(len) < GLMAT_EPSILON) {2816 return null;2817 }2818 len = 1 / len;2819 x *= len;2820 y *= len;2821 z *= len;2822 s = Math.sin(rad);2823 c = Math.cos(rad);2824 t = 1 - c;2825 a00 = a[0];2826 a01 = a[1];2827 a02 = a[2];2828 a03 = a[3];2829 a10 = a[4];2830 a11 = a[5];2831 a12 = a[6];2832 a13 = a[7];2833 a20 = a[8];2834 a21 = a[9];2835 a22 = a[10];2836 a23 = a[11];2837 // Construct the elements of the rotation matrix2838 b00 = x * x * t + c;2839 b01 = y * x * t + z * s;2840 b02 = z * x * t - y * s;2841 b10 = x * y * t - z * s;2842 b11 = y * y * t + c;2843 b12 = z * y * t + x * s;2844 b20 = x * z * t + y * s;2845 b21 = y * z * t - x * s;2846 b22 = z * z * t + c;2847 // Perform rotation-specific matrix multiplication2848 out[0] = a00 * b00 + a10 * b01 + a20 * b02;2849 out[1] = a01 * b00 + a11 * b01 + a21 * b02;2850 out[2] = a02 * b00 + a12 * b01 + a22 * b02;2851 out[3] = a03 * b00 + a13 * b01 + a23 * b02;2852 out[4] = a00 * b10 + a10 * b11 + a20 * b12;2853 out[5] = a01 * b10 + a11 * b11 + a21 * b12;2854 out[6] = a02 * b10 + a12 * b11 + a22 * b12;2855 out[7] = a03 * b10 + a13 * b11 + a23 * b12;2856 out[8] = a00 * b20 + a10 * b21 + a20 * b22;2857 out[9] = a01 * b20 + a11 * b21 + a21 * b22;2858 out[10] = a02 * b20 + a12 * b21 + a22 * b22;2859 out[11] = a03 * b20 + a13 * b21 + a23 * b22;2860 if (a !== out) { // If the source and destination differ, copy the unchanged last row2861 out[12] = a[12];2862 out[13] = a[13];2863 out[14] = a[14];2864 out[15] = a[15];2865 }2866 return out;2867 };2868 /**2869 * Rotates a matrix by the given angle around the X axis2870 *2871 * @param {mat4} out the receiving matrix2872 * @param {mat4} a the matrix to rotate2873 * @param {Number} rad the angle to rotate the matrix by2874 * @returns {mat4} out2875 */2876 mat4.rotateX = function(out, a, rad) {2877 var s = Math.sin(rad),2878 c = Math.cos(rad),2879 a10 = a[4],2880 a11 = a[5],2881 a12 = a[6],2882 a13 = a[7],2883 a20 = a[8],2884 a21 = a[9],2885 a22 = a[10],2886 a23 = a[11];2887 if (a !== out) { // If the source and destination differ, copy the unchanged rows2888 out[0] = a[0];2889 out[1] = a[1];2890 out[2] = a[2];2891 out[3] = a[3];2892 out[12] = a[12];2893 out[13] = a[13];2894 out[14] = a[14];2895 out[15] = a[15];2896 }2897 // Perform axis-specific matrix multiplication2898 out[4] = a10 * c + a20 * s;2899 out[5] = a11 * c + a21 * s;2900 out[6] = a12 * c + a22 * s;2901 out[7] = a13 * c + a23 * s;2902 out[8] = a20 * c - a10 * s;2903 out[9] = a21 * c - a11 * s;2904 out[10] = a22 * c - a12 * s;2905 out[11] = a23 * c - a13 * s;2906 return out;2907 };2908 /**2909 * Rotates a matrix by the given angle around the Y axis2910 *2911 * @param {mat4} out the receiving matrix2912 * @param {mat4} a the matrix to rotate2913 * @param {Number} rad the angle to rotate the matrix by2914 * @returns {mat4} out2915 */2916 mat4.rotateY = function(out, a, rad) {2917 var s = Math.sin(rad),2918 c = Math.cos(rad),2919 a00 = a[0],2920 a01 = a[1],2921 a02 = a[2],2922 a03 = a[3],2923 a20 = a[8],2924 a21 = a[9],2925 a22 = a[10],2926 a23 = a[11];2927 if (a !== out) { // If the source and destination differ, copy the unchanged rows2928 out[4] = a[4];2929 out[5] = a[5];2930 out[6] = a[6];2931 out[7] = a[7];2932 out[12] = a[12];2933 out[13] = a[13];2934 out[14] = a[14];2935 out[15] = a[15];2936 }2937 // Perform axis-specific matrix multiplication2938 out[0] = a00 * c - a20 * s;2939 out[1] = a01 * c - a21 * s;2940 out[2] = a02 * c - a22 * s;2941 out[3] = a03 * c - a23 * s;2942 out[8] = a00 * s + a20 * c;2943 out[9] = a01 * s + a21 * c;2944 out[10] = a02 * s + a22 * c;2945 out[11] = a03 * s + a23 * c;2946 return out;2947 };2948 /**2949 * Rotates a matrix by the given angle around the Z axis2950 *2951 * @param {mat4} out the receiving matrix2952 * @param {mat4} a the matrix to rotate2953 * @param {Number} rad the angle to rotate the matrix by2954 * @returns {mat4} out2955 */2956 mat4.rotateZ = function(out, a, rad) {2957 var s = Math.sin(rad),2958 c = Math.cos(rad),2959 a00 = a[0],2960 a01 = a[1],2961 a02 = a[2],2962 a03 = a[3],2963 a10 = a[4],2964 a11 = a[5],2965 a12 = a[6],2966 a13 = a[7];2967 if (a !== out) { // If the source and destination differ, copy the unchanged last row2968 out[8] = a[8];2969 out[9] = a[9];2970 out[10] = a[10];2971 out[11] = a[11];2972 out[12] = a[12];2973 out[13] = a[13];2974 out[14] = a[14];2975 out[15] = a[15];2976 }2977 // Perform axis-specific matrix multiplication2978 out[0] = a00 * c + a10 * s;2979 out[1] = a01 * c + a11 * s;2980 out[2] = a02 * c + a12 * s;2981 out[3] = a03 * c + a13 * s;2982 out[4] = a10 * c - a00 * s;2983 out[5] = a11 * c - a01 * s;2984 out[6] = a12 * c - a02 * s;2985 out[7] = a13 * c - a03 * s;2986 return out;2987 };2988 /**2989 * Creates a matrix from a quaternion rotation and vector translation2990 * This is equivalent to (but much faster than):2991 *2992 * mat4.identity(dest);2993 * mat4.translate(dest, vec);2994 * var quatMat = mat4.create();2995 * quat4.toMat4(quat, quatMat);2996 * mat4.multiply(dest, quatMat);2997 *2998 * @param {mat4} out mat4 receiving operation result2999 * @param {quat4} q Rotation quaternion3000 * @param {vec3} v Translation vector3001 * @returns {mat4} out3002 */3003 mat4.fromRotationTranslation = function(out, q, v) {3004 // Quaternion math3005 var x = q[0],3006 y = q[1],3007 z = q[2],3008 w = q[3],3009 x2 = x + x,3010 y2 = y + y,3011 z2 = z + z,3012 xx = x * x2,3013 xy = x * y2,3014 xz = x * z2,3015 yy = y * y2,3016 yz = y * z2,3017 zz = z * z2,3018 wx = w * x2,3019 wy = w * y2,3020 wz = w * z2;3021 out[0] = 1 - (yy + zz);3022 out[1] = xy + wz;3023 out[2] = xz - wy;3024 out[3] = 0;3025 out[4] = xy - wz;3026 out[5] = 1 - (xx + zz);3027 out[6] = yz + wx;3028 out[7] = 0;3029 out[8] = xz + wy;3030 out[9] = yz - wx;3031 out[10] = 1 - (xx + yy);3032 out[11] = 0;3033 out[12] = v[0];3034 out[13] = v[1];3035 out[14] = v[2];3036 out[15] = 1;3037 return out;3038 };3039 /**3040 * Calculates a 4x4 matrix from the given quaternion3041 *3042 * @param {mat4} out mat4 receiving operation result3043 * @param {quat} q Quaternion to create matrix from3044 *3045 * @returns {mat4} out3046 */3047 mat4.fromQuat = function(out, q) {3048 var x = q[0],3049 y = q[1],3050 z = q[2],3051 w = q[3],3052 x2 = x + x,3053 y2 = y + y,3054 z2 = z + z,3055 xx = x * x2,3056 xy = x * y2,3057 xz = x * z2,3058 yy = y * y2,3059 yz = y * z2,3060 zz = z * z2,3061 wx = w * x2,3062 wy = w * y2,3063 wz = w * z2;3064 out[0] = 1 - (yy + zz);3065 out[1] = xy + wz;3066 out[2] = xz - wy;3067 out[3] = 0;3068 out[4] = xy - wz;3069 out[5] = 1 - (xx + zz);3070 out[6] = yz + wx;3071 out[7] = 0;3072 out[8] = xz + wy;3073 out[9] = yz - wx;3074 out[10] = 1 - (xx + yy);3075 out[11] = 0;3076 out[12] = 0;3077 out[13] = 0;3078 out[14] = 0;3079 out[15] = 1;3080 return out;3081 };3082 /**3083 * Generates a frustum matrix with the given bounds3084 *3085 * @param {mat4} out mat4 frustum matrix will be written into3086 * @param {Number} left Left bound of the frustum3087 * @param {Number} right Right bound of the frustum3088 * @param {Number} bottom Bottom bound of the frustum3089 * @param {Number} top Top bound of the frustum3090 * @param {Number} near Near bound of the frustum3091 * @param {Number} far Far bound of the frustum3092 * @returns {mat4} out3093 */3094 mat4.frustum = function(out, left, right, bottom, top, near, far) {3095 var rl = 1 / (right - left),3096 tb = 1 / (top - bottom),3097 nf = 1 / (near - far);3098 out[0] = (near * 2) * rl;3099 out[1] = 0;3100 out[2] = 0;3101 out[3] = 0;3102 out[4] = 0;3103 out[5] = (near * 2) * tb;3104 out[6] = 0;3105 out[7] = 0;3106 out[8] = (right + left) * rl;3107 out[9] = (top + bottom) * tb;3108 out[10] = (far + near) * nf;3109 out[11] = -1;3110 out[12] = 0;3111 out[13] = 0;3112 out[14] = (far * near * 2) * nf;3113 out[15] = 0;3114 return out;3115 };3116 /**3117 * Generates a perspective projection matrix with the given bounds3118 *3119 * @param {mat4} out mat4 frustum matrix will be written into3120 * @param {number} fovy Vertical field of view in radians3121 * @param {number} aspect Aspect ratio. typically viewport width/height3122 * @param {number} near Near bound of the frustum3123 * @param {number} far Far bound of the frustum3124 * @returns {mat4} out3125 */3126 mat4.perspective = function(out, fovy, aspect, near, far) {3127 var f = 1.0 / Math.tan(fovy / 2),3128 nf = 1 / (near - far);3129 out[0] = f / aspect;3130 out[1] = 0;3131 out[2] = 0;3132 out[3] = 0;3133 out[4] = 0;3134 out[5] = f;3135 out[6] = 0;3136 out[7] = 0;3137 out[8] = 0;3138 out[9] = 0;3139 out[10] = (far + near) * nf;3140 out[11] = -1;3141 out[12] = 0;3142 out[13] = 0;3143 out[14] = (2 * far * near) * nf;3144 out[15] = 0;3145 return out;3146 };3147 /**3148 * Generates a orthogonal projection matrix with the given bounds3149 *3150 * @param {mat4} out mat4 frustum matrix will be written into3151 * @param {number} left Left bound of the frustum3152 * @param {number} right Right bound of the frustum3153 * @param {number} bottom Bottom bound of the frustum3154 * @param {number} top Top bound of the frustum3155 * @param {number} near Near bound of the frustum3156 * @param {number} far Far bound of the frustum3157 * @returns {mat4} out3158 */3159 mat4.ortho = function(out, left, right, bottom, top, near, far) {3160 var lr = 1 / (left - right),3161 bt = 1 / (bottom - top),3162 nf = 1 / (near - far);3163 out[0] = -2 * lr;3164 out[1] = 0;3165 out[2] = 0;3166 out[3] = 0;3167 out[4] = 0;3168 out[5] = -2 * bt;3169 out[6] = 0;3170 out[7] = 0;3171 out[8] = 0;3172 out[9] = 0;3173 out[10] = 2 * nf;3174 out[11] = 0;3175 out[12] = (left + right) * lr;3176 out[13] = (top + bottom) * bt;3177 out[14] = (far + near) * nf;3178 out[15] = 1;3179 return out;3180 };3181 /**3182 * Generates a look-at matrix with the given eye position, focal point, and up axis3183 *3184 * @param {mat4} out mat4 frustum matrix will be written into3185 * @param {vec3} eye Position of the viewer3186 * @param {vec3} center Point the viewer is looking at3187 * @param {vec3} up vec3 pointing up3188 * @returns {mat4} out3189 */3190 mat4.lookAt = function(out, eye, center, up) {3191 var x0, x1, x2, y0, y1, y2, z0, z1, z2, len,3192 eyex = eye[0],3193 eyey = eye[1],3194 eyez = eye[2],3195 upx = up[0],3196 upy = up[1],3197 upz = up[2],3198 centerx = center[0],3199 centery = center[1],3200 centerz = center[2];3201 if (Math.abs(eyex - centerx) < GLMAT_EPSILON &&3202 Math.abs(eyey - centery) < GLMAT_EPSILON &&3203 Math.abs(eyez - centerz) < GLMAT_EPSILON) {3204 return mat4.identity(out);3205 }3206 z0 = eyex - centerx;3207 z1 = eyey - centery;3208 z2 = eyez - centerz;3209 len = 1 / Math.sqrt(z0 * z0 + z1 * z1 + z2 * z2);3210 z0 *= len;3211 z1 *= len;3212 z2 *= len;3213 x0 = upy * z2 - upz * z1;3214 x1 = upz * z0 - upx * z2;3215 x2 = upx * z1 - upy * z0;3216 len = Math.sqrt(x0 * x0 + x1 * x1 + x2 * x2);3217 if (!len) {3218 x0 = 0;3219 x1 = 0;3220 x2 = 0;3221 } else {3222 len = 1 / len;3223 x0 *= len;3224 x1 *= len;3225 x2 *= len;3226 }3227 y0 = z1 * x2 - z2 * x1;3228 y1 = z2 * x0 - z0 * x2;3229 y2 = z0 * x1 - z1 * x0;3230 len = Math.sqrt(y0 * y0 + y1 * y1 + y2 * y2);3231 if (!len) {3232 y0 = 0;3233 y1 = 0;3234 y2 = 0;3235 } else {3236 len = 1 / len;3237 y0 *= len;3238 y1 *= len;3239 y2 *= len;3240 }3241 out[0] = x0;3242 out[1] = y0;3243 out[2] = z0;3244 out[3] = 0;3245 out[4] = x1;3246 out[5] = y1;3247 out[6] = z1;3248 out[7] = 0;3249 out[8] = x2;3250 out[9] = y2;3251 out[10] = z2;3252 out[11] = 0;3253 out[12] = -(x0 * eyex + x1 * eyey + x2 * eyez);3254 out[13] = -(y0 * eyex + y1 * eyey + y2 * eyez);3255 out[14] = -(z0 * eyex + z1 * eyey + z2 * eyez);3256 out[15] = 1;3257 return out;3258 };3259 /**3260 * Returns a string representation of a mat43261 *3262 * @param {mat4} mat matrix to represent as a string3263 * @returns {String} string representation of the matrix3264 */3265 mat4.str = function(a) {3266 return 'mat4(' + a[0] + ', ' + a[1] + ', ' + a[2] + ', ' + a[3] + ', ' +3267 a[4] + ', ' + a[5] + ', ' + a[6] + ', ' + a[7] + ', ' +3268 a[8] + ', ' + a[9] + ', ' + a[10] + ', ' + a[11] + ', ' +3269 a[12] + ', ' + a[13] + ', ' + a[14] + ', ' + a[15] + ')';3270 };3271 if (typeof(exports) !== 'undefined') {3272 exports.mat4 = mat4;3273 };3274 /* Copyright (c) 2013, Brandon Jones, Colin MacKenzie IV. All rights reserved.3275Redistribution and use in source and binary forms, with or without modification,3276are permitted provided that the following conditions are met:3277 * Redistributions of source code must retain the above copyright notice, this3278 list of conditions and the following disclaimer.3279 * Redistributions in binary form must reproduce the above copyright notice,3280 this list of conditions and the following disclaimer in the documentation 3281 and/or other materials provided with the distribution.3282THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND3283ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED3284WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 3285DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR3286ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES3287(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;3288LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON3289ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT3290(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS3291SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */3292 /**3293 * @class Quaternion3294 * @name quat3295 */3296 var quat = {};3297 var quatIdentity = new Float32Array([0, 0, 0, 1]);3298 /**3299 * Creates a new identity quat3300 *3301 * @returns {quat} a new quaternion3302 */3303 quat.create = function() {3304 var out = new GLMAT_ARRAY_TYPE(4);3305 out[0] = 0;3306 out[1] = 0;3307 out[2] = 0;3308 out[3] = 1;3309 return out;3310 };3311 /**3312 * Creates a new quat initialized with values from an existing quaternion3313 *3314 * @param {quat} a quaternion to clone3315 * @returns {quat} a new quaternion3316 * @function3317 */3318 quat.clone = vec4.clone;3319 /**3320 * Creates a new quat initialized with the given values3321 *3322 * @param {Number} x X component3323 * @param {Number} y Y component3324 * @param {Number} z Z component3325 * @param {Number} w W component3326 * @returns {quat} a new quaternion3327 * @function3328 */3329 quat.fromValues = vec4.fromValues;3330 /**3331 * Copy the values from one quat to another3332 *3333 * @param {quat} out the receiving quaternion3334 * @param {quat} a the source quaternion3335 * @returns {quat} out3336 * @function3337 */3338 quat.copy = vec4.copy;3339 /**3340 * Set the components of a quat to the given values3341 *3342 * @param {quat} out the receiving quaternion3343 * @param {Number} x X component3344 * @param {Number} y Y component3345 * @param {Number} z Z component3346 * @param {Number} w W component3347 * @returns {quat} out3348 * @function3349 */3350 quat.set = vec4.set;3351 /**3352 * Set a quat to the identity quaternion3353 *3354 * @param {quat} out the receiving quaternion3355 * @returns {quat} out3356 */3357 quat.identity = function(out) {3358 out[0] = 0;3359 out[1] = 0;3360 out[2] = 0;3361 out[3] = 1;3362 return out;3363 };3364 /**3365 * Sets a quat from the given angle and rotation axis,3366 * then returns it.3367 *3368 * @param {quat} out the receiving quaternion3369 * @param {vec3} axis the axis around which to rotate3370 * @param {Number} rad the angle in radians3371 * @returns {quat} out3372 **/3373 quat.setAxisAngle = function(out, axis, rad) {3374 rad = rad * 0.5;3375 var s = Math.sin(rad);3376 out[0] = s * axis[0];3377 out[1] = s * axis[1];3378 out[2] = s * axis[2];3379 out[3] = Math.cos(rad);3380 return out;3381 };3382 /**3383 * Adds two quat's3384 *3385 * @param {quat} out the receiving quaternion3386 * @param {quat} a the first operand3387 * @param {quat} b the second operand3388 * @returns {quat} out3389 * @function3390 */3391 quat.add = vec4.add;3392 /**3393 * Multiplies two quat's3394 *3395 * @param {quat} out the receiving quaternion3396 * @param {quat} a the first operand3397 * @param {quat} b the second operand3398 * @returns {quat} out3399 */3400 quat.multiply = function(out, a, b) {3401 var ax = a[0],3402 ay = a[1],3403 az = a[2],3404 aw = a[3],3405 bx = b[0],3406 by = b[1],3407 bz = b[2],3408 bw = b[3];3409 out[0] = ax * bw + aw * bx + ay * bz - az * by;3410 out[1] = ay * bw + aw * by + az * bx - ax * bz;3411 out[2] = az * bw + aw * bz + ax * by - ay * bx;3412 out[3] = aw * bw - ax * bx - ay * by - az * bz;3413 return out;3414 };3415 /**3416 * Alias for {@link quat.multiply}3417 * @function3418 */3419 quat.mul = quat.multiply;3420 /**3421 * Scales a quat by a scalar number3422 *3423 * @param {quat} out the receiving vector3424 * @param {quat} a the vector to scale3425 * @param {Number} b amount to scale the vector by3426 * @returns {quat} out3427 * @function3428 */3429 quat.scale = vec4.scale;3430 /**3431 * Rotates a quaternion by the given angle around the X axis3432 *3433 * @param {quat} out quat receiving operation result3434 * @param {quat} a quat to rotate3435 * @param {number} rad angle (in radians) to rotate3436 * @returns {quat} out3437 */3438 quat.rotateX = function(out, a, rad) {3439 rad *= 0.5;3440 var ax = a[0],3441 ay = a[1],3442 az = a[2],3443 aw = a[3],3444 bx = Math.sin(rad),3445 bw = Math.cos(rad);3446 out[0] = ax * bw + aw * bx;3447 out[1] = ay * bw + az * bx;3448 out[2] = az * bw - ay * bx;3449 out[3] = aw * bw - ax * bx;3450 return out;3451 };3452 /**3453 * Rotates a quaternion by the given angle around the Y axis3454 *3455 * @param {quat} out quat receiving operation result3456 * @param {quat} a quat to rotate3457 * @param {number} rad angle (in radians) to rotate3458 * @returns {quat} out3459 */3460 quat.rotateY = function(out, a, rad) {3461 rad *= 0.5;3462 var ax = a[0],3463 ay = a[1],3464 az = a[2],3465 aw = a[3],3466 by = Math.sin(rad),3467 bw = Math.cos(rad);3468 out[0] = ax * bw - az * by;3469 out[1] = ay * bw + aw * by;3470 out[2] = az * bw + ax * by;3471 out[3] = aw * bw - ay * by;3472 return out;3473 };3474 /**3475 * Rotates a quaternion by the given angle around the Z axis3476 *3477 * @param {quat} out quat receiving operation result3478 * @param {quat} a quat to rotate3479 * @param {number} rad angle (in radians) to rotate3480 * @returns {quat} out3481 */3482 quat.rotateZ = function(out, a, rad) {3483 rad *= 0.5;3484 var ax = a[0],3485 ay = a[1],3486 az = a[2],3487 aw = a[3],3488 bz = Math.sin(rad),3489 bw = Math.cos(rad);3490 out[0] = ax * bw + ay * bz;3491 out[1] = ay * bw - ax * bz;3492 out[2] = az * bw + aw * bz;3493 out[3] = aw * bw - az * bz;3494 return out;3495 };3496 /**3497 * Calculates the W component of a quat from the X, Y, and Z components.3498 * Assumes that quaternion is 1 unit in length.3499 * Any existing W component will be ignored.3500 *3501 * @param {quat} out the receiving quaternion3502 * @param {quat} a quat to calculate W component of3503 * @returns {quat} out3504 */3505 quat.calculateW = function(out, a) {3506 var x = a[0],3507 y = a[1],3508 z = a[2];3509 out[0] = x;3510 out[1] = y;3511 out[2] = z;3512 out[3] = -Math.sqrt(Math.abs(1.0 - x * x - y * y - z * z));3513 return out;3514 };3515 /**3516 * Calculates the dot product of two quat's3517 *3518 * @param {quat} a the first operand3519 * @param {quat} b the second operand3520 * @returns {Number} dot product of a and b3521 * @function3522 */3523 quat.dot = vec4.dot;3524 /**3525 * Performs a linear interpolation between two quat's3526 *3527 * @param {quat} out the receiving quaternion3528 * @param {quat} a the first operand3529 * @param {quat} b the second operand3530 * @param {Number} t interpolation amount between the two inputs3531 * @returns {quat} out3532 * @function3533 */3534 quat.lerp = vec4.lerp;3535 /**3536 * Performs a spherical linear interpolation between two quat3537 *3538 * @param {quat} out the receiving quaternion3539 * @param {quat} a the first operand3540 * @param {quat} b the second operand3541 * @param {Number} t interpolation amount between the two inputs3542 * @returns {quat} out3543 */3544 quat.slerp = function(out, a, b, t) {3545 var ax = a[0],3546 ay = a[1],3547 az = a[2],3548 aw = a[3],3549 bx = b[0],3550 by = b[1],3551 bz = b[2],3552 bw = b[3];3553 var cosHalfTheta = ax * bx + ay * by + az * bz + aw * bw,3554 halfTheta,3555 sinHalfTheta,3556 ratioA,3557 ratioB;3558 if (Math.abs(cosHalfTheta) >= 1.0) {3559 if (out !== a) {3560 out[0] = ax;3561 out[1] = ay;3562 out[2] = az;3563 out[3] = aw;3564 }3565 return out;3566 }3567 halfTheta = Math.acos(cosHalfTheta);3568 sinHalfTheta = Math.sqrt(1.0 - cosHalfTheta * cosHalfTheta);3569 if (Math.abs(sinHalfTheta) < 0.001) {3570 out[0] = (ax * 0.5 + bx * 0.5);3571 out[1] = (ay * 0.5 + by * 0.5);3572 out[2] = (az * 0.5 + bz * 0.5);3573 out[3] = (aw * 0.5 + bw * 0.5);3574 return out;3575 }3576 ratioA = Math.sin((1 - t) * halfTheta) / sinHalfTheta;3577 ratioB = Math.sin(t * halfTheta) / sinHalfTheta;3578 out[0] = (ax * ratioA + bx * ratioB);3579 out[1] = (ay * ratioA + by * ratioB);3580 out[2] = (az * ratioA + bz * ratioB);3581 out[3] = (aw * ratioA + bw * ratioB);3582 return out;3583 };3584 /**3585 * Calculates the inverse of a quat3586 *3587 * @param {quat} out the receiving quaternion3588 * @param {quat} a quat to calculate inverse of3589 * @returns {quat} out3590 */3591 quat.invert = function(out, a) {3592 var a0 = a[0],3593 a1 = a[1],3594 a2 = a[2],3595 a3 = a[3],3596 dot = a0 * a0 + a1 * a1 + a2 * a2 + a3 * a3,3597 invDot = dot ? 1.0 / dot : 0;3598 // TODO: Would be faster to return [0,0,0,0] immediately if dot == 03599 out[0] = -a0 * invDot;3600 out[1] = -a1 * invDot;3601 out[2] = -a2 * invDot;3602 out[3] = a3 * invDot;3603 return out;3604 };3605 /**3606 * Calculates the conjugate of a quat3607 * If the quaternion is normalized, this function is faster than quat.inverse and produces the same result.3608 *3609 * @param {quat} out the receiving quaternion3610 * @param {quat} a quat to calculate conjugate of3611 * @returns {quat} out3612 */3613 quat.conjugate = function(out, a) {3614 out[0] = -a[0];3615 out[1] = -a[1];3616 out[2] = -a[2];3617 out[3] = a[3];3618 return out;3619 };3620 /**3621 * Calculates the length of a quat3622 *3623 * @param {quat} a vector to calculate length of3624 * @returns {Number} length of a3625 * @function3626 */3627 quat.length = vec4.length;3628 /**3629 * Alias for {@link quat.length}3630 * @function3631 */3632 quat.len = quat.length;3633 /**3634 * Calculates the squared length of a quat3635 *3636 * @param {quat} a vector to calculate squared length of3637 * @returns {Number} squared length of a3638 * @function3639 */3640 quat.squaredLength = vec4.squaredLength;3641 /**3642 * Alias for {@link quat.squaredLength}3643 * @function3644 */3645 quat.sqrLen = quat.squaredLength;3646 /**3647 * Normalize a quat3648 *3649 * @param {quat} out the receiving quaternion3650 * @param {quat} a quaternion to normalize3651 * @returns {quat} out3652 * @function3653 */3654 quat.normalize = vec4.normalize;3655 /**3656 * Creates a quaternion from the given 3x3 rotation matrix.3657 *3658 * @param {quat} out the receiving quaternion3659 * @param {mat3} m rotation matrix3660 * @returns {quat} out3661 * @function3662 */3663 quat.fromMat3 = (function() {3664 var s_iNext = [1, 2, 0];3665 return function(out, m) {3666 // Algorithm in Ken Shoemake's article in 1987 SIGGRAPH course notes3667 // article "Quaternion Calculus and Fast Animation".3668 var fTrace = m[0] + m[4] + m[8];3669 var fRoot;3670 if (fTrace > 0.0) {3671 // |w| > 1/2, may as well choose w > 1/23672 fRoot = Math.sqrt(fTrace + 1.0); // 2w3673 out[3] = 0.5 * fRoot;3674 fRoot = 0.5 / fRoot; // 1/(4w)3675 out[0] = (m[7] - m[5]) * fRoot;3676 out[1] = (m[2] - m[6]) * fRoot;3677 out[2] = (m[3] - m[1]) * fRoot;3678 } else {3679 // |w| <= 1/23680 var i = 0;3681 if (m[4] > m[0])3682 i = 1;3683 if (m[8] > m[i * 3 + i])3684 i = 2;3685 var j = s_iNext[i];3686 var k = s_iNext[j];3687 fRoot = Math.sqrt(m[i * 3 + i] - m[j * 3 + j] - m[k * 3 + k] + 1.0);3688 out[i] = 0.5 * fRoot;3689 fRoot = 0.5 / fRoot;3690 out[3] = (m[k * 3 + j] - m[j * 3 + k]) * fRoot;3691 out[j] = (m[j * 3 + i] + m[i * 3 + j]) * fRoot;3692 out[k] = (m[k * 3 + i] + m[i * 3 + k]) * fRoot;3693 }3694 return out;3695 };3696 })();3697 /**3698 * Returns a string representation of a quatenion3699 *3700 * @param {quat} vec vector to represent as a string3701 * @returns {String} string representation of the vector3702 */3703 quat.str = function(a) {3704 return 'quat(' + a[0] + ', ' + a[1] + ', ' + a[2] + ', ' + a[3] + ')';3705 };3706 if (typeof(exports) !== 'undefined') {3707 exports.quat = quat;3708 };3709 })(shim.exports);...

Full Screen

Full Screen

mat4.js

Source:mat4.js Github

copy

Full Screen

1import * as glMatrix from "./common.js";2/**3 * 4x4 Matrix<br>Format: column-major, when typed out it looks like row-major<br>The matrices are being post multiplied.4 * @module mat45 */6/**7 * Creates a new identity mat48 *9 * @returns {mat4} a new 4x4 matrix10 */11export function create() {12 let out = new glMatrix.ARRAY_TYPE(16);13 if (glMatrix.ARRAY_TYPE != Float32Array) {14 out[1] = 0;15 out[2] = 0;16 out[3] = 0;17 out[4] = 0;18 out[6] = 0;19 out[7] = 0;20 out[8] = 0;21 out[9] = 0;22 out[11] = 0;23 out[12] = 0;24 out[13] = 0;25 out[14] = 0;26 }27 out[0] = 1;28 out[5] = 1;29 out[10] = 1;30 out[15] = 1;31 return out;32}33/**34 * Creates a new mat4 initialized with values from an existing matrix35 *36 * @param {ReadonlyMat4} a matrix to clone37 * @returns {mat4} a new 4x4 matrix38 */39export function clone(a) {40 let out = new glMatrix.ARRAY_TYPE(16);41 out[0] = a[0];42 out[1] = a[1];43 out[2] = a[2];44 out[3] = a[3];45 out[4] = a[4];46 out[5] = a[5];47 out[6] = a[6];48 out[7] = a[7];49 out[8] = a[8];50 out[9] = a[9];51 out[10] = a[10];52 out[11] = a[11];53 out[12] = a[12];54 out[13] = a[13];55 out[14] = a[14];56 out[15] = a[15];57 return out;58}59/**60 * Copy the values from one mat4 to another61 *62 * @param {mat4} out the receiving matrix63 * @param {ReadonlyMat4} a the source matrix64 * @returns {mat4} out65 */66export function copy(out, a) {67 out[0] = a[0];68 out[1] = a[1];69 out[2] = a[2];70 out[3] = a[3];71 out[4] = a[4];72 out[5] = a[5];73 out[6] = a[6];74 out[7] = a[7];75 out[8] = a[8];76 out[9] = a[9];77 out[10] = a[10];78 out[11] = a[11];79 out[12] = a[12];80 out[13] = a[13];81 out[14] = a[14];82 out[15] = a[15];83 return out;84}85/**86 * Create a new mat4 with the given values87 *88 * @param {Number} m00 Component in column 0, row 0 position (index 0)89 * @param {Number} m01 Component in column 0, row 1 position (index 1)90 * @param {Number} m02 Component in column 0, row 2 position (index 2)91 * @param {Number} m03 Component in column 0, row 3 position (index 3)92 * @param {Number} m10 Component in column 1, row 0 position (index 4)93 * @param {Number} m11 Component in column 1, row 1 position (index 5)94 * @param {Number} m12 Component in column 1, row 2 position (index 6)95 * @param {Number} m13 Component in column 1, row 3 position (index 7)96 * @param {Number} m20 Component in column 2, row 0 position (index 8)97 * @param {Number} m21 Component in column 2, row 1 position (index 9)98 * @param {Number} m22 Component in column 2, row 2 position (index 10)99 * @param {Number} m23 Component in column 2, row 3 position (index 11)100 * @param {Number} m30 Component in column 3, row 0 position (index 12)101 * @param {Number} m31 Component in column 3, row 1 position (index 13)102 * @param {Number} m32 Component in column 3, row 2 position (index 14)103 * @param {Number} m33 Component in column 3, row 3 position (index 15)104 * @returns {mat4} A new mat4105 */106export function fromValues(107 m00,108 m01,109 m02,110 m03,111 m10,112 m11,113 m12,114 m13,115 m20,116 m21,117 m22,118 m23,119 m30,120 m31,121 m32,122 m33123) {124 let out = new glMatrix.ARRAY_TYPE(16);125 out[0] = m00;126 out[1] = m01;127 out[2] = m02;128 out[3] = m03;129 out[4] = m10;130 out[5] = m11;131 out[6] = m12;132 out[7] = m13;133 out[8] = m20;134 out[9] = m21;135 out[10] = m22;136 out[11] = m23;137 out[12] = m30;138 out[13] = m31;139 out[14] = m32;140 out[15] = m33;141 return out;142}143/**144 * Set the components of a mat4 to the given values145 *146 * @param {mat4} out the receiving matrix147 * @param {Number} m00 Component in column 0, row 0 position (index 0)148 * @param {Number} m01 Component in column 0, row 1 position (index 1)149 * @param {Number} m02 Component in column 0, row 2 position (index 2)150 * @param {Number} m03 Component in column 0, row 3 position (index 3)151 * @param {Number} m10 Component in column 1, row 0 position (index 4)152 * @param {Number} m11 Component in column 1, row 1 position (index 5)153 * @param {Number} m12 Component in column 1, row 2 position (index 6)154 * @param {Number} m13 Component in column 1, row 3 position (index 7)155 * @param {Number} m20 Component in column 2, row 0 position (index 8)156 * @param {Number} m21 Component in column 2, row 1 position (index 9)157 * @param {Number} m22 Component in column 2, row 2 position (index 10)158 * @param {Number} m23 Component in column 2, row 3 position (index 11)159 * @param {Number} m30 Component in column 3, row 0 position (index 12)160 * @param {Number} m31 Component in column 3, row 1 position (index 13)161 * @param {Number} m32 Component in column 3, row 2 position (index 14)162 * @param {Number} m33 Component in column 3, row 3 position (index 15)163 * @returns {mat4} out164 */165export function set(166 out,167 m00,168 m01,169 m02,170 m03,171 m10,172 m11,173 m12,174 m13,175 m20,176 m21,177 m22,178 m23,179 m30,180 m31,181 m32,182 m33183) {184 out[0] = m00;185 out[1] = m01;186 out[2] = m02;187 out[3] = m03;188 out[4] = m10;189 out[5] = m11;190 out[6] = m12;191 out[7] = m13;192 out[8] = m20;193 out[9] = m21;194 out[10] = m22;195 out[11] = m23;196 out[12] = m30;197 out[13] = m31;198 out[14] = m32;199 out[15] = m33;200 return out;201}202/**203 * Set a mat4 to the identity matrix204 *205 * @param {mat4} out the receiving matrix206 * @returns {mat4} out207 */208export function identity(out) {209 out[0] = 1;210 out[1] = 0;211 out[2] = 0;212 out[3] = 0;213 out[4] = 0;214 out[5] = 1;215 out[6] = 0;216 out[7] = 0;217 out[8] = 0;218 out[9] = 0;219 out[10] = 1;220 out[11] = 0;221 out[12] = 0;222 out[13] = 0;223 out[14] = 0;224 out[15] = 1;225 return out;226}227/**228 * Transpose the values of a mat4229 *230 * @param {mat4} out the receiving matrix231 * @param {ReadonlyMat4} a the source matrix232 * @returns {mat4} out233 */234export function transpose(out, a) {235 // If we are transposing ourselves we can skip a few steps but have to cache some values236 if (out === a) {237 let a01 = a[1],238 a02 = a[2],239 a03 = a[3];240 let a12 = a[6],241 a13 = a[7];242 let a23 = a[11];243 out[1] = a[4];244 out[2] = a[8];245 out[3] = a[12];246 out[4] = a01;247 out[6] = a[9];248 out[7] = a[13];249 out[8] = a02;250 out[9] = a12;251 out[11] = a[14];252 out[12] = a03;253 out[13] = a13;254 out[14] = a23;255 } else {256 out[0] = a[0];257 out[1] = a[4];258 out[2] = a[8];259 out[3] = a[12];260 out[4] = a[1];261 out[5] = a[5];262 out[6] = a[9];263 out[7] = a[13];264 out[8] = a[2];265 out[9] = a[6];266 out[10] = a[10];267 out[11] = a[14];268 out[12] = a[3];269 out[13] = a[7];270 out[14] = a[11];271 out[15] = a[15];272 }273 return out;274}275/**276 * Inverts a mat4277 *278 * @param {mat4} out the receiving matrix279 * @param {ReadonlyMat4} a the source matrix280 * @returns {mat4} out281 */282export function invert(out, a) {283 let a00 = a[0],284 a01 = a[1],285 a02 = a[2],286 a03 = a[3];287 let a10 = a[4],288 a11 = a[5],289 a12 = a[6],290 a13 = a[7];291 let a20 = a[8],292 a21 = a[9],293 a22 = a[10],294 a23 = a[11];295 let a30 = a[12],296 a31 = a[13],297 a32 = a[14],298 a33 = a[15];299 let b00 = a00 * a11 - a01 * a10;300 let b01 = a00 * a12 - a02 * a10;301 let b02 = a00 * a13 - a03 * a10;302 let b03 = a01 * a12 - a02 * a11;303 let b04 = a01 * a13 - a03 * a11;304 let b05 = a02 * a13 - a03 * a12;305 let b06 = a20 * a31 - a21 * a30;306 let b07 = a20 * a32 - a22 * a30;307 let b08 = a20 * a33 - a23 * a30;308 let b09 = a21 * a32 - a22 * a31;309 let b10 = a21 * a33 - a23 * a31;310 let b11 = a22 * a33 - a23 * a32;311 // Calculate the determinant312 let det =313 b00 * b11 - b01 * b10 + b02 * b09 + b03 * b08 - b04 * b07 + b05 * b06;314 if (!det) {315 return null;316 }317 det = 1.0 / det;318 out[0] = (a11 * b11 - a12 * b10 + a13 * b09) * det;319 out[1] = (a02 * b10 - a01 * b11 - a03 * b09) * det;320 out[2] = (a31 * b05 - a32 * b04 + a33 * b03) * det;321 out[3] = (a22 * b04 - a21 * b05 - a23 * b03) * det;322 out[4] = (a12 * b08 - a10 * b11 - a13 * b07) * det;323 out[5] = (a00 * b11 - a02 * b08 + a03 * b07) * det;324 out[6] = (a32 * b02 - a30 * b05 - a33 * b01) * det;325 out[7] = (a20 * b05 - a22 * b02 + a23 * b01) * det;326 out[8] = (a10 * b10 - a11 * b08 + a13 * b06) * det;327 out[9] = (a01 * b08 - a00 * b10 - a03 * b06) * det;328 out[10] = (a30 * b04 - a31 * b02 + a33 * b00) * det;329 out[11] = (a21 * b02 - a20 * b04 - a23 * b00) * det;330 out[12] = (a11 * b07 - a10 * b09 - a12 * b06) * det;331 out[13] = (a00 * b09 - a01 * b07 + a02 * b06) * det;332 out[14] = (a31 * b01 - a30 * b03 - a32 * b00) * det;333 out[15] = (a20 * b03 - a21 * b01 + a22 * b00) * det;334 return out;335}336/**337 * Calculates the adjugate of a mat4338 *339 * @param {mat4} out the receiving matrix340 * @param {ReadonlyMat4} a the source matrix341 * @returns {mat4} out342 */343export function adjoint(out, a) {344 let a00 = a[0],345 a01 = a[1],346 a02 = a[2],347 a03 = a[3];348 let a10 = a[4],349 a11 = a[5],350 a12 = a[6],351 a13 = a[7];352 let a20 = a[8],353 a21 = a[9],354 a22 = a[10],355 a23 = a[11];356 let a30 = a[12],357 a31 = a[13],358 a32 = a[14],359 a33 = a[15];360 let b00 = a00 * a11 - a01 * a10;361 let b01 = a00 * a12 - a02 * a10;362 let b02 = a00 * a13 - a03 * a10;363 let b03 = a01 * a12 - a02 * a11;364 let b04 = a01 * a13 - a03 * a11;365 let b05 = a02 * a13 - a03 * a12;366 let b06 = a20 * a31 - a21 * a30;367 let b07 = a20 * a32 - a22 * a30;368 let b08 = a20 * a33 - a23 * a30;369 let b09 = a21 * a32 - a22 * a31;370 let b10 = a21 * a33 - a23 * a31;371 let b11 = a22 * a33 - a23 * a32;372 out[0] = a11 * b11 - a12 * b10 + a13 * b09;373 out[1] = a02 * b10 - a01 * b11 - a03 * b09;374 out[2] = a31 * b05 - a32 * b04 + a33 * b03;375 out[3] = a22 * b04 - a21 * b05 - a23 * b03;376 out[4] = a12 * b08 - a10 * b11 - a13 * b07;377 out[5] = a00 * b11 - a02 * b08 + a03 * b07;378 out[6] = a32 * b02 - a30 * b05 - a33 * b01;379 out[7] = a20 * b05 - a22 * b02 + a23 * b01;380 out[8] = a10 * b10 - a11 * b08 + a13 * b06;381 out[9] = a01 * b08 - a00 * b10 - a03 * b06;382 out[10] = a30 * b04 - a31 * b02 + a33 * b00;383 out[11] = a21 * b02 - a20 * b04 - a23 * b00;384 out[12] = a11 * b07 - a10 * b09 - a12 * b06;385 out[13] = a00 * b09 - a01 * b07 + a02 * b06;386 out[14] = a31 * b01 - a30 * b03 - a32 * b00;387 out[15] = a20 * b03 - a21 * b01 + a22 * b00;388 return out;389}390/**391 * Calculates the determinant of a mat4392 *393 * @param {ReadonlyMat4} a the source matrix394 * @returns {Number} determinant of a395 */396export function determinant(a) {397 let a00 = a[0],398 a01 = a[1],399 a02 = a[2],400 a03 = a[3];401 let a10 = a[4],402 a11 = a[5],403 a12 = a[6],404 a13 = a[7];405 let a20 = a[8],406 a21 = a[9],407 a22 = a[10],408 a23 = a[11];409 let a30 = a[12],410 a31 = a[13],411 a32 = a[14],412 a33 = a[15];413 let b0 = a00 * a11 - a01 * a10;414 let b1 = a00 * a12 - a02 * a10;415 let b2 = a01 * a12 - a02 * a11;416 let b3 = a20 * a31 - a21 * a30;417 let b4 = a20 * a32 - a22 * a30;418 let b5 = a21 * a32 - a22 * a31;419 let b6 = a00 * b5 - a01 * b4 + a02 * b3;420 let b7 = a10 * b5 - a11 * b4 + a12 * b3;421 let b8 = a20 * b2 - a21 * b1 + a22 * b0;422 let b9 = a30 * b2 - a31 * b1 + a32 * b0;423 // Calculate the determinant424 return a13 * b6 - a03 * b7 + a33 * b8 - a23 * b9;425}426/**427 * Multiplies two mat4s428 *429 * @param {mat4} out the receiving matrix430 * @param {ReadonlyMat4} a the first operand431 * @param {ReadonlyMat4} b the second operand432 * @returns {mat4} out433 */434export function multiply(out, a, b) {435 let a00 = a[0],436 a01 = a[1],437 a02 = a[2],438 a03 = a[3];439 let a10 = a[4],440 a11 = a[5],441 a12 = a[6],442 a13 = a[7];443 let a20 = a[8],444 a21 = a[9],445 a22 = a[10],446 a23 = a[11];447 let a30 = a[12],448 a31 = a[13],449 a32 = a[14],450 a33 = a[15];451 // Cache only the current line of the second matrix452 let b0 = b[0],453 b1 = b[1],454 b2 = b[2],455 b3 = b[3];456 out[0] = b0 * a00 + b1 * a10 + b2 * a20 + b3 * a30;457 out[1] = b0 * a01 + b1 * a11 + b2 * a21 + b3 * a31;458 out[2] = b0 * a02 + b1 * a12 + b2 * a22 + b3 * a32;459 out[3] = b0 * a03 + b1 * a13 + b2 * a23 + b3 * a33;460 b0 = b[4];461 b1 = b[5];462 b2 = b[6];463 b3 = b[7];464 out[4] = b0 * a00 + b1 * a10 + b2 * a20 + b3 * a30;465 out[5] = b0 * a01 + b1 * a11 + b2 * a21 + b3 * a31;466 out[6] = b0 * a02 + b1 * a12 + b2 * a22 + b3 * a32;467 out[7] = b0 * a03 + b1 * a13 + b2 * a23 + b3 * a33;468 b0 = b[8];469 b1 = b[9];470 b2 = b[10];471 b3 = b[11];472 out[8] = b0 * a00 + b1 * a10 + b2 * a20 + b3 * a30;473 out[9] = b0 * a01 + b1 * a11 + b2 * a21 + b3 * a31;474 out[10] = b0 * a02 + b1 * a12 + b2 * a22 + b3 * a32;475 out[11] = b0 * a03 + b1 * a13 + b2 * a23 + b3 * a33;476 b0 = b[12];477 b1 = b[13];478 b2 = b[14];479 b3 = b[15];480 out[12] = b0 * a00 + b1 * a10 + b2 * a20 + b3 * a30;481 out[13] = b0 * a01 + b1 * a11 + b2 * a21 + b3 * a31;482 out[14] = b0 * a02 + b1 * a12 + b2 * a22 + b3 * a32;483 out[15] = b0 * a03 + b1 * a13 + b2 * a23 + b3 * a33;484 return out;485}486/**487 * Translate a mat4 by the given vector488 *489 * @param {mat4} out the receiving matrix490 * @param {ReadonlyMat4} a the matrix to translate491 * @param {ReadonlyVec3} v vector to translate by492 * @returns {mat4} out493 */494export function translate(out, a, v) {495 let x = v[0],496 y = v[1],497 z = v[2];498 let a00, a01, a02, a03;499 let a10, a11, a12, a13;500 let a20, a21, a22, a23;501 if (a === out) {502 out[12] = a[0] * x + a[4] * y + a[8] * z + a[12];503 out[13] = a[1] * x + a[5] * y + a[9] * z + a[13];504 out[14] = a[2] * x + a[6] * y + a[10] * z + a[14];505 out[15] = a[3] * x + a[7] * y + a[11] * z + a[15];506 } else {507 a00 = a[0];508 a01 = a[1];509 a02 = a[2];510 a03 = a[3];511 a10 = a[4];512 a11 = a[5];513 a12 = a[6];514 a13 = a[7];515 a20 = a[8];516 a21 = a[9];517 a22 = a[10];518 a23 = a[11];519 out[0] = a00;520 out[1] = a01;521 out[2] = a02;522 out[3] = a03;523 out[4] = a10;524 out[5] = a11;525 out[6] = a12;526 out[7] = a13;527 out[8] = a20;528 out[9] = a21;529 out[10] = a22;530 out[11] = a23;531 out[12] = a00 * x + a10 * y + a20 * z + a[12];532 out[13] = a01 * x + a11 * y + a21 * z + a[13];533 out[14] = a02 * x + a12 * y + a22 * z + a[14];534 out[15] = a03 * x + a13 * y + a23 * z + a[15];535 }536 return out;537}538/**539 * Scales the mat4 by the dimensions in the given vec3 not using vectorization540 *541 * @param {mat4} out the receiving matrix542 * @param {ReadonlyMat4} a the matrix to scale543 * @param {ReadonlyVec3} v the vec3 to scale the matrix by544 * @returns {mat4} out545 **/546export function scale(out, a, v) {547 let x = v[0],548 y = v[1],549 z = v[2];550 out[0] = a[0] * x;551 out[1] = a[1] * x;552 out[2] = a[2] * x;553 out[3] = a[3] * x;554 out[4] = a[4] * y;555 out[5] = a[5] * y;556 out[6] = a[6] * y;557 out[7] = a[7] * y;558 out[8] = a[8] * z;559 out[9] = a[9] * z;560 out[10] = a[10] * z;561 out[11] = a[11] * z;562 out[12] = a[12];563 out[13] = a[13];564 out[14] = a[14];565 out[15] = a[15];566 return out;567}568/**569 * Rotates a mat4 by the given angle around the given axis570 *571 * @param {mat4} out the receiving matrix572 * @param {ReadonlyMat4} a the matrix to rotate573 * @param {Number} rad the angle to rotate the matrix by574 * @param {ReadonlyVec3} axis the axis to rotate around575 * @returns {mat4} out576 */577export function rotate(out, a, rad, axis) {578 let x = axis[0],579 y = axis[1],580 z = axis[2];581 let len = Math.hypot(x, y, z);582 let s, c, t;583 let a00, a01, a02, a03;584 let a10, a11, a12, a13;585 let a20, a21, a22, a23;586 let b00, b01, b02;587 let b10, b11, b12;588 let b20, b21, b22;589 if (len < glMatrix.EPSILON) {590 return null;591 }592 len = 1 / len;593 x *= len;594 y *= len;595 z *= len;596 s = Math.sin(rad);597 c = Math.cos(rad);598 t = 1 - c;599 a00 = a[0];600 a01 = a[1];601 a02 = a[2];602 a03 = a[3];603 a10 = a[4];604 a11 = a[5];605 a12 = a[6];606 a13 = a[7];607 a20 = a[8];608 a21 = a[9];609 a22 = a[10];610 a23 = a[11];611 // Construct the elements of the rotation matrix612 b00 = x * x * t + c;613 b01 = y * x * t + z * s;614 b02 = z * x * t - y * s;615 b10 = x * y * t - z * s;616 b11 = y * y * t + c;617 b12 = z * y * t + x * s;618 b20 = x * z * t + y * s;619 b21 = y * z * t - x * s;620 b22 = z * z * t + c;621 // Perform rotation-specific matrix multiplication622 out[0] = a00 * b00 + a10 * b01 + a20 * b02;623 out[1] = a01 * b00 + a11 * b01 + a21 * b02;624 out[2] = a02 * b00 + a12 * b01 + a22 * b02;625 out[3] = a03 * b00 + a13 * b01 + a23 * b02;626 out[4] = a00 * b10 + a10 * b11 + a20 * b12;627 out[5] = a01 * b10 + a11 * b11 + a21 * b12;628 out[6] = a02 * b10 + a12 * b11 + a22 * b12;629 out[7] = a03 * b10 + a13 * b11 + a23 * b12;630 out[8] = a00 * b20 + a10 * b21 + a20 * b22;631 out[9] = a01 * b20 + a11 * b21 + a21 * b22;632 out[10] = a02 * b20 + a12 * b21 + a22 * b22;633 out[11] = a03 * b20 + a13 * b21 + a23 * b22;634 if (a !== out) {635 // If the source and destination differ, copy the unchanged last row636 out[12] = a[12];637 out[13] = a[13];638 out[14] = a[14];639 out[15] = a[15];640 }641 return out;642}643/**644 * Rotates a matrix by the given angle around the X axis645 *646 * @param {mat4} out the receiving matrix647 * @param {ReadonlyMat4} a the matrix to rotate648 * @param {Number} rad the angle to rotate the matrix by649 * @returns {mat4} out650 */651export function rotateX(out, a, rad) {652 let s = Math.sin(rad);653 let c = Math.cos(rad);654 let a10 = a[4];655 let a11 = a[5];656 let a12 = a[6];657 let a13 = a[7];658 let a20 = a[8];659 let a21 = a[9];660 let a22 = a[10];661 let a23 = a[11];662 if (a !== out) {663 // If the source and destination differ, copy the unchanged rows664 out[0] = a[0];665 out[1] = a[1];666 out[2] = a[2];667 out[3] = a[3];668 out[12] = a[12];669 out[13] = a[13];670 out[14] = a[14];671 out[15] = a[15];672 }673 // Perform axis-specific matrix multiplication674 out[4] = a10 * c + a20 * s;675 out[5] = a11 * c + a21 * s;676 out[6] = a12 * c + a22 * s;677 out[7] = a13 * c + a23 * s;678 out[8] = a20 * c - a10 * s;679 out[9] = a21 * c - a11 * s;680 out[10] = a22 * c - a12 * s;681 out[11] = a23 * c - a13 * s;682 return out;683}684/**685 * Rotates a matrix by the given angle around the Y axis686 *687 * @param {mat4} out the receiving matrix688 * @param {ReadonlyMat4} a the matrix to rotate689 * @param {Number} rad the angle to rotate the matrix by690 * @returns {mat4} out691 */692export function rotateY(out, a, rad) {693 let s = Math.sin(rad);694 let c = Math.cos(rad);695 let a00 = a[0];696 let a01 = a[1];697 let a02 = a[2];698 let a03 = a[3];699 let a20 = a[8];700 let a21 = a[9];701 let a22 = a[10];702 let a23 = a[11];703 if (a !== out) {704 // If the source and destination differ, copy the unchanged rows705 out[4] = a[4];706 out[5] = a[5];707 out[6] = a[6];708 out[7] = a[7];709 out[12] = a[12];710 out[13] = a[13];711 out[14] = a[14];712 out[15] = a[15];713 }714 // Perform axis-specific matrix multiplication715 out[0] = a00 * c - a20 * s;716 out[1] = a01 * c - a21 * s;717 out[2] = a02 * c - a22 * s;718 out[3] = a03 * c - a23 * s;719 out[8] = a00 * s + a20 * c;720 out[9] = a01 * s + a21 * c;721 out[10] = a02 * s + a22 * c;722 out[11] = a03 * s + a23 * c;723 return out;724}725/**726 * Rotates a matrix by the given angle around the Z axis727 *728 * @param {mat4} out the receiving matrix729 * @param {ReadonlyMat4} a the matrix to rotate730 * @param {Number} rad the angle to rotate the matrix by731 * @returns {mat4} out732 */733export function rotateZ(out, a, rad) {734 let s = Math.sin(rad);735 let c = Math.cos(rad);736 let a00 = a[0];737 let a01 = a[1];738 let a02 = a[2];739 let a03 = a[3];740 let a10 = a[4];741 let a11 = a[5];742 let a12 = a[6];743 let a13 = a[7];744 if (a !== out) {745 // If the source and destination differ, copy the unchanged last row746 out[8] = a[8];747 out[9] = a[9];748 out[10] = a[10];749 out[11] = a[11];750 out[12] = a[12];751 out[13] = a[13];752 out[14] = a[14];753 out[15] = a[15];754 }755 // Perform axis-specific matrix multiplication756 out[0] = a00 * c + a10 * s;757 out[1] = a01 * c + a11 * s;758 out[2] = a02 * c + a12 * s;759 out[3] = a03 * c + a13 * s;760 out[4] = a10 * c - a00 * s;761 out[5] = a11 * c - a01 * s;762 out[6] = a12 * c - a02 * s;763 out[7] = a13 * c - a03 * s;764 return out;765}766/**767 * Creates a matrix from a vector translation768 * This is equivalent to (but much faster than):769 *770 * mat4.identity(dest);771 * mat4.translate(dest, dest, vec);772 *773 * @param {mat4} out mat4 receiving operation result774 * @param {ReadonlyVec3} v Translation vector775 * @returns {mat4} out776 */777export function fromTranslation(out, v) {778 out[0] = 1;779 out[1] = 0;780 out[2] = 0;781 out[3] = 0;782 out[4] = 0;783 out[5] = 1;784 out[6] = 0;785 out[7] = 0;786 out[8] = 0;787 out[9] = 0;788 out[10] = 1;789 out[11] = 0;790 out[12] = v[0];791 out[13] = v[1];792 out[14] = v[2];793 out[15] = 1;794 return out;795}796/**797 * Creates a matrix from a vector scaling798 * This is equivalent to (but much faster than):799 *800 * mat4.identity(dest);801 * mat4.scale(dest, dest, vec);802 *803 * @param {mat4} out mat4 receiving operation result804 * @param {ReadonlyVec3} v Scaling vector805 * @returns {mat4} out806 */807export function fromScaling(out, v) {808 out[0] = v[0];809 out[1] = 0;810 out[2] = 0;811 out[3] = 0;812 out[4] = 0;813 out[5] = v[1];814 out[6] = 0;815 out[7] = 0;816 out[8] = 0;817 out[9] = 0;818 out[10] = v[2];819 out[11] = 0;820 out[12] = 0;821 out[13] = 0;822 out[14] = 0;823 out[15] = 1;824 return out;825}826/**827 * Creates a matrix from a given angle around a given axis828 * This is equivalent to (but much faster than):829 *830 * mat4.identity(dest);831 * mat4.rotate(dest, dest, rad, axis);832 *833 * @param {mat4} out mat4 receiving operation result834 * @param {Number} rad the angle to rotate the matrix by835 * @param {ReadonlyVec3} axis the axis to rotate around836 * @returns {mat4} out837 */838export function fromRotation(out, rad, axis) {839 let x = axis[0],840 y = axis[1],841 z = axis[2];842 let len = Math.hypot(x, y, z);843 let s, c, t;844 if (len < glMatrix.EPSILON) {845 return null;846 }847 len = 1 / len;848 x *= len;849 y *= len;850 z *= len;851 s = Math.sin(rad);852 c = Math.cos(rad);853 t = 1 - c;854 // Perform rotation-specific matrix multiplication855 out[0] = x * x * t + c;856 out[1] = y * x * t + z * s;857 out[2] = z * x * t - y * s;858 out[3] = 0;859 out[4] = x * y * t - z * s;860 out[5] = y * y * t + c;861 out[6] = z * y * t + x * s;862 out[7] = 0;863 out[8] = x * z * t + y * s;864 out[9] = y * z * t - x * s;865 out[10] = z * z * t + c;866 out[11] = 0;867 out[12] = 0;868 out[13] = 0;869 out[14] = 0;870 out[15] = 1;871 return out;872}873/**874 * Creates a matrix from the given angle around the X axis875 * This is equivalent to (but much faster than):876 *877 * mat4.identity(dest);878 * mat4.rotateX(dest, dest, rad);879 *880 * @param {mat4} out mat4 receiving operation result881 * @param {Number} rad the angle to rotate the matrix by882 * @returns {mat4} out883 */884export function fromXRotation(out, rad) {885 let s = Math.sin(rad);886 let c = Math.cos(rad);887 // Perform axis-specific matrix multiplication888 out[0] = 1;889 out[1] = 0;890 out[2] = 0;891 out[3] = 0;892 out[4] = 0;893 out[5] = c;894 out[6] = s;895 out[7] = 0;896 out[8] = 0;897 out[9] = -s;898 out[10] = c;899 out[11] = 0;900 out[12] = 0;901 out[13] = 0;902 out[14] = 0;903 out[15] = 1;904 return out;905}906/**907 * Creates a matrix from the given angle around the Y axis908 * This is equivalent to (but much faster than):909 *910 * mat4.identity(dest);911 * mat4.rotateY(dest, dest, rad);912 *913 * @param {mat4} out mat4 receiving operation result914 * @param {Number} rad the angle to rotate the matrix by915 * @returns {mat4} out916 */917export function fromYRotation(out, rad) {918 let s = Math.sin(rad);919 let c = Math.cos(rad);920 // Perform axis-specific matrix multiplication921 out[0] = c;922 out[1] = 0;923 out[2] = -s;924 out[3] = 0;925 out[4] = 0;926 out[5] = 1;927 out[6] = 0;928 out[7] = 0;929 out[8] = s;930 out[9] = 0;931 out[10] = c;932 out[11] = 0;933 out[12] = 0;934 out[13] = 0;935 out[14] = 0;936 out[15] = 1;937 return out;938}939/**940 * Creates a matrix from the given angle around the Z axis941 * This is equivalent to (but much faster than):942 *943 * mat4.identity(dest);944 * mat4.rotateZ(dest, dest, rad);945 *946 * @param {mat4} out mat4 receiving operation result947 * @param {Number} rad the angle to rotate the matrix by948 * @returns {mat4} out949 */950export function fromZRotation(out, rad) {951 let s = Math.sin(rad);952 let c = Math.cos(rad);953 // Perform axis-specific matrix multiplication954 out[0] = c;955 out[1] = s;956 out[2] = 0;957 out[3] = 0;958 out[4] = -s;959 out[5] = c;960 out[6] = 0;961 out[7] = 0;962 out[8] = 0;963 out[9] = 0;964 out[10] = 1;965 out[11] = 0;966 out[12] = 0;967 out[13] = 0;968 out[14] = 0;969 out[15] = 1;970 return out;971}972/**973 * Creates a matrix from a quaternion rotation and vector translation974 * This is equivalent to (but much faster than):975 *976 * mat4.identity(dest);977 * mat4.translate(dest, vec);978 * let quatMat = mat4.create();979 * quat4.toMat4(quat, quatMat);980 * mat4.multiply(dest, quatMat);981 *982 * @param {mat4} out mat4 receiving operation result983 * @param {quat4} q Rotation quaternion984 * @param {ReadonlyVec3} v Translation vector985 * @returns {mat4} out986 */987export function fromRotationTranslation(out, q, v) {988 // Quaternion math989 let x = q[0],990 y = q[1],991 z = q[2],992 w = q[3];993 let x2 = x + x;994 let y2 = y + y;995 let z2 = z + z;996 let xx = x * x2;997 let xy = x * y2;998 let xz = x * z2;999 let yy = y * y2;1000 let yz = y * z2;1001 let zz = z * z2;1002 let wx = w * x2;1003 let wy = w * y2;1004 let wz = w * z2;1005 out[0] = 1 - (yy + zz);1006 out[1] = xy + wz;1007 out[2] = xz - wy;1008 out[3] = 0;1009 out[4] = xy - wz;1010 out[5] = 1 - (xx + zz);1011 out[6] = yz + wx;1012 out[7] = 0;1013 out[8] = xz + wy;1014 out[9] = yz - wx;1015 out[10] = 1 - (xx + yy);1016 out[11] = 0;1017 out[12] = v[0];1018 out[13] = v[1];1019 out[14] = v[2];1020 out[15] = 1;1021 return out;1022}1023/**1024 * Creates a new mat4 from a dual quat.1025 *1026 * @param {mat4} out Matrix1027 * @param {ReadonlyQuat2} a Dual Quaternion1028 * @returns {mat4} mat4 receiving operation result1029 */1030export function fromQuat2(out, a) {1031 let translation = new glMatrix.ARRAY_TYPE(3);1032 let bx = -a[0],1033 by = -a[1],1034 bz = -a[2],1035 bw = a[3],1036 ax = a[4],1037 ay = a[5],1038 az = a[6],1039 aw = a[7];1040 let magnitude = bx * bx + by * by + bz * bz + bw * bw;1041 //Only scale if it makes sense1042 if (magnitude > 0) {1043 translation[0] = ((ax * bw + aw * bx + ay * bz - az * by) * 2) / magnitude;1044 translation[1] = ((ay * bw + aw * by + az * bx - ax * bz) * 2) / magnitude;1045 translation[2] = ((az * bw + aw * bz + ax * by - ay * bx) * 2) / magnitude;1046 } else {1047 translation[0] = (ax * bw + aw * bx + ay * bz - az * by) * 2;1048 translation[1] = (ay * bw + aw * by + az * bx - ax * bz) * 2;1049 translation[2] = (az * bw + aw * bz + ax * by - ay * bx) * 2;1050 }1051 fromRotationTranslation(out, a, translation);1052 return out;1053}1054/**1055 * Returns the translation vector component of a transformation1056 * matrix. If a matrix is built with fromRotationTranslation,1057 * the returned vector will be the same as the translation vector1058 * originally supplied.1059 * @param {vec3} out Vector to receive translation component1060 * @param {ReadonlyMat4} mat Matrix to be decomposed (input)1061 * @return {vec3} out1062 */1063export function getTranslation(out, mat) {1064 out[0] = mat[12];1065 out[1] = mat[13];1066 out[2] = mat[14];1067 return out;1068}1069/**1070 * Returns the scaling factor component of a transformation1071 * matrix. If a matrix is built with fromRotationTranslationScale1072 * with a normalized Quaternion paramter, the returned vector will be1073 * the same as the scaling vector1074 * originally supplied.1075 * @param {vec3} out Vector to receive scaling factor component1076 * @param {ReadonlyMat4} mat Matrix to be decomposed (input)1077 * @return {vec3} out1078 */1079export function getScaling(out, mat) {1080 let m11 = mat[0];1081 let m12 = mat[1];1082 let m13 = mat[2];1083 let m21 = mat[4];1084 let m22 = mat[5];1085 let m23 = mat[6];1086 let m31 = mat[8];1087 let m32 = mat[9];1088 let m33 = mat[10];1089 out[0] = Math.hypot(m11, m12, m13);1090 out[1] = Math.hypot(m21, m22, m23);1091 out[2] = Math.hypot(m31, m32, m33);1092 return out;1093}1094/**1095 * Returns a quaternion representing the rotational component1096 * of a transformation matrix. If a matrix is built with1097 * fromRotationTranslation, the returned quaternion will be the1098 * same as the quaternion originally supplied.1099 * @param {quat} out Quaternion to receive the rotation component1100 * @param {ReadonlyMat4} mat Matrix to be decomposed (input)1101 * @return {quat} out1102 */1103export function getRotation(out, mat) {1104 let scaling = new glMatrix.ARRAY_TYPE(3);1105 getScaling(scaling, mat);1106 let is1 = 1 / scaling[0];1107 let is2 = 1 / scaling[1];1108 let is3 = 1 / scaling[2];1109 let sm11 = mat[0] * is1;1110 let sm12 = mat[1] * is2;1111 let sm13 = mat[2] * is3;1112 let sm21 = mat[4] * is1;1113 let sm22 = mat[5] * is2;1114 let sm23 = mat[6] * is3;1115 let sm31 = mat[8] * is1;1116 let sm32 = mat[9] * is2;1117 let sm33 = mat[10] * is3;1118 let trace = sm11 + sm22 + sm33;1119 let S = 0;1120 if (trace > 0) {1121 S = Math.sqrt(trace + 1.0) * 2;1122 out[3] = 0.25 * S;1123 out[0] = (sm23 - sm32) / S;1124 out[1] = (sm31 - sm13) / S;1125 out[2] = (sm12 - sm21) / S;1126 } else if (sm11 > sm22 && sm11 > sm33) {1127 S = Math.sqrt(1.0 + sm11 - sm22 - sm33) * 2;1128 out[3] = (sm23 - sm32) / S;1129 out[0] = 0.25 * S;1130 out[1] = (sm12 + sm21) / S;1131 out[2] = (sm31 + sm13) / S;1132 } else if (sm22 > sm33) {1133 S = Math.sqrt(1.0 + sm22 - sm11 - sm33) * 2;1134 out[3] = (sm31 - sm13) / S;1135 out[0] = (sm12 + sm21) / S;1136 out[1] = 0.25 * S;1137 out[2] = (sm23 + sm32) / S;1138 } else {1139 S = Math.sqrt(1.0 + sm33 - sm11 - sm22) * 2;1140 out[3] = (sm12 - sm21) / S;1141 out[0] = (sm31 + sm13) / S;1142 out[1] = (sm23 + sm32) / S;1143 out[2] = 0.25 * S;1144 }1145 return out;1146}1147/**1148 * Decomposes a transformation matrix into its rotation, translation1149 * and scale components. Returns only the rotation component1150 * @param {quat} out_r Quaternion to receive the rotation component1151 * @param {vec3} out_t Vector to receive the translation vector1152 * @param {vec3} out_s Vector to receive the scaling factor1153 * @param {ReadonlyMat4} mat Matrix to be decomposed (input)1154 * @returns {quat} out_r1155 */1156export function decompose(out_r, out_t, out_s, mat) {1157 out_t[0] = mat[12];1158 out_t[1] = mat[13];1159 out_t[2] = mat[14];1160 let m11 = mat[0];1161 let m12 = mat[1];1162 let m13 = mat[2];1163 let m21 = mat[4];1164 let m22 = mat[5];1165 let m23 = mat[6];1166 let m31 = mat[8];1167 let m32 = mat[9];1168 let m33 = mat[10];1169 out_s[0] = Math.hypot(m11, m12, m13);1170 out_s[1] = Math.hypot(m21, m22, m23);1171 out_s[2] = Math.hypot(m31, m32, m33);1172 let is1 = 1 / out_s[0];1173 let is2 = 1 / out_s[1];1174 let is3 = 1 / out_s[2];1175 let sm11 = m11 * is1;1176 let sm12 = m12 * is2;1177 let sm13 = m13 * is3;1178 let sm21 = m21 * is1;1179 let sm22 = m22 * is2;1180 let sm23 = m23 * is3;1181 let sm31 = m31 * is1;1182 let sm32 = m32 * is2;1183 let sm33 = m33 * is3;1184 let trace = sm11 + sm22 + sm33;1185 let S = 0;1186 if (trace > 0) {1187 S = Math.sqrt(trace + 1.0) * 2;1188 out_r[3] = 0.25 * S;1189 out_r[0] = (sm23 - sm32) / S;1190 out_r[1] = (sm31 - sm13) / S;1191 out_r[2] = (sm12 - sm21) / S;1192 } else if (sm11 > sm22 && sm11 > sm33) {1193 S = Math.sqrt(1.0 + sm11 - sm22 - sm33) * 2;1194 out_r[3] = (sm23 - sm32) / S;1195 out_r[0] = 0.25 * S;1196 out_r[1] = (sm12 + sm21) / S;1197 out_r[2] = (sm31 + sm13) / S;1198 } else if (sm22 > sm33) {1199 S = Math.sqrt(1.0 + sm22 - sm11 - sm33) * 2;1200 out_r[3] = (sm31 - sm13) / S;1201 out_r[0] = (sm12 + sm21) / S;1202 out_r[1] = 0.25 * S;1203 out_r[2] = (sm23 + sm32) / S;1204 } else {1205 S = Math.sqrt(1.0 + sm33 - sm11 - sm22) * 2;1206 out_r[3] = (sm12 - sm21) / S;1207 out_r[0] = (sm31 + sm13) / S;1208 out_r[1] = (sm23 + sm32) / S;1209 out_r[2] = 0.25 * S;1210 }1211 return out_r;1212}1213/**1214 * Creates a matrix from a quaternion rotation, vector translation and vector scale1215 * This is equivalent to (but much faster than):1216 *1217 * mat4.identity(dest);1218 * mat4.translate(dest, vec);1219 * let quatMat = mat4.create();1220 * quat4.toMat4(quat, quatMat);1221 * mat4.multiply(dest, quatMat);1222 * mat4.scale(dest, scale)1223 *1224 * @param {mat4} out mat4 receiving operation result1225 * @param {quat4} q Rotation quaternion1226 * @param {ReadonlyVec3} v Translation vector1227 * @param {ReadonlyVec3} s Scaling vector1228 * @returns {mat4} out1229 */1230export function fromRotationTranslationScale(out, q, v, s) {1231 // Quaternion math1232 let x = q[0],1233 y = q[1],1234 z = q[2],1235 w = q[3];1236 let x2 = x + x;1237 let y2 = y + y;1238 let z2 = z + z;1239 let xx = x * x2;1240 let xy = x * y2;1241 let xz = x * z2;1242 let yy = y * y2;1243 let yz = y * z2;1244 let zz = z * z2;1245 let wx = w * x2;1246 let wy = w * y2;1247 let wz = w * z2;1248 let sx = s[0];1249 let sy = s[1];1250 let sz = s[2];1251 out[0] = (1 - (yy + zz)) * sx;1252 out[1] = (xy + wz) * sx;1253 out[2] = (xz - wy) * sx;1254 out[3] = 0;1255 out[4] = (xy - wz) * sy;1256 out[5] = (1 - (xx + zz)) * sy;1257 out[6] = (yz + wx) * sy;1258 out[7] = 0;1259 out[8] = (xz + wy) * sz;1260 out[9] = (yz - wx) * sz;1261 out[10] = (1 - (xx + yy)) * sz;1262 out[11] = 0;1263 out[12] = v[0];1264 out[13] = v[1];1265 out[14] = v[2];1266 out[15] = 1;1267 return out;1268}1269/**1270 * Creates a matrix from a quaternion rotation, vector translation and vector scale, rotating and scaling around the given origin1271 * This is equivalent to (but much faster than):1272 *1273 * mat4.identity(dest);1274 * mat4.translate(dest, vec);1275 * mat4.translate(dest, origin);1276 * let quatMat = mat4.create();1277 * quat4.toMat4(quat, quatMat);1278 * mat4.multiply(dest, quatMat);1279 * mat4.scale(dest, scale)1280 * mat4.translate(dest, negativeOrigin);1281 *1282 * @param {mat4} out mat4 receiving operation result1283 * @param {quat4} q Rotation quaternion1284 * @param {ReadonlyVec3} v Translation vector1285 * @param {ReadonlyVec3} s Scaling vector1286 * @param {ReadonlyVec3} o The origin vector around which to scale and rotate1287 * @returns {mat4} out1288 */1289export function fromRotationTranslationScaleOrigin(out, q, v, s, o) {1290 // Quaternion math1291 let x = q[0],1292 y = q[1],1293 z = q[2],1294 w = q[3];1295 let x2 = x + x;1296 let y2 = y + y;1297 let z2 = z + z;1298 let xx = x * x2;1299 let xy = x * y2;1300 let xz = x * z2;1301 let yy = y * y2;1302 let yz = y * z2;1303 let zz = z * z2;1304 let wx = w * x2;1305 let wy = w * y2;1306 let wz = w * z2;1307 let sx = s[0];1308 let sy = s[1];1309 let sz = s[2];1310 let ox = o[0];1311 let oy = o[1];1312 let oz = o[2];1313 let out0 = (1 - (yy + zz)) * sx;1314 let out1 = (xy + wz) * sx;1315 let out2 = (xz - wy) * sx;1316 let out4 = (xy - wz) * sy;1317 let out5 = (1 - (xx + zz)) * sy;1318 let out6 = (yz + wx) * sy;1319 let out8 = (xz + wy) * sz;1320 let out9 = (yz - wx) * sz;1321 let out10 = (1 - (xx + yy)) * sz;1322 out[0] = out0;1323 out[1] = out1;1324 out[2] = out2;1325 out[3] = 0;1326 out[4] = out4;1327 out[5] = out5;1328 out[6] = out6;1329 out[7] = 0;1330 out[8] = out8;1331 out[9] = out9;1332 out[10] = out10;1333 out[11] = 0;1334 out[12] = v[0] + ox - (out0 * ox + out4 * oy + out8 * oz);1335 out[13] = v[1] + oy - (out1 * ox + out5 * oy + out9 * oz);1336 out[14] = v[2] + oz - (out2 * ox + out6 * oy + out10 * oz);1337 out[15] = 1;1338 return out;1339}1340/**1341 * Calculates a 4x4 matrix from the given quaternion1342 *1343 * @param {mat4} out mat4 receiving operation result1344 * @param {ReadonlyQuat} q Quaternion to create matrix from1345 *1346 * @returns {mat4} out1347 */1348export function fromQuat(out, q) {1349 let x = q[0],1350 y = q[1],1351 z = q[2],1352 w = q[3];1353 let x2 = x + x;1354 let y2 = y + y;1355 let z2 = z + z;1356 let xx = x * x2;1357 let yx = y * x2;1358 let yy = y * y2;1359 let zx = z * x2;1360 let zy = z * y2;1361 let zz = z * z2;1362 let wx = w * x2;1363 let wy = w * y2;1364 let wz = w * z2;1365 out[0] = 1 - yy - zz;1366 out[1] = yx + wz;1367 out[2] = zx - wy;1368 out[3] = 0;1369 out[4] = yx - wz;1370 out[5] = 1 - xx - zz;1371 out[6] = zy + wx;1372 out[7] = 0;1373 out[8] = zx + wy;1374 out[9] = zy - wx;1375 out[10] = 1 - xx - yy;1376 out[11] = 0;1377 out[12] = 0;1378 out[13] = 0;1379 out[14] = 0;1380 out[15] = 1;1381 return out;1382}1383/**1384 * Generates a frustum matrix with the given bounds1385 *1386 * @param {mat4} out mat4 frustum matrix will be written into1387 * @param {Number} left Left bound of the frustum1388 * @param {Number} right Right bound of the frustum1389 * @param {Number} bottom Bottom bound of the frustum1390 * @param {Number} top Top bound of the frustum1391 * @param {Number} near Near bound of the frustum1392 * @param {Number} far Far bound of the frustum1393 * @returns {mat4} out1394 */1395export function frustum(out, left, right, bottom, top, near, far) {1396 let rl = 1 / (right - left);1397 let tb = 1 / (top - bottom);1398 let nf = 1 / (near - far);1399 out[0] = near * 2 * rl;1400 out[1] = 0;1401 out[2] = 0;1402 out[3] = 0;1403 out[4] = 0;1404 out[5] = near * 2 * tb;1405 out[6] = 0;1406 out[7] = 0;1407 out[8] = (right + left) * rl;1408 out[9] = (top + bottom) * tb;1409 out[10] = (far + near) * nf;1410 out[11] = -1;1411 out[12] = 0;1412 out[13] = 0;1413 out[14] = far * near * 2 * nf;1414 out[15] = 0;1415 return out;1416}1417/**1418 * Generates a perspective projection matrix with the given bounds.1419 * Passing null/undefined/no value for far will generate infinite projection matrix.1420 *1421 * @param {mat4} out mat4 frustum matrix will be written into1422 * @param {number} fovy Vertical field of view in radians1423 * @param {number} aspect Aspect ratio. typically viewport width/height1424 * @param {number} near Near bound of the frustum1425 * @param {number} far Far bound of the frustum, can be null or Infinity1426 * @returns {mat4} out1427 */1428export function perspective(out, fovy, aspect, near, far) {1429 let f = 1.0 / Math.tan(fovy / 2),1430 nf;1431 out[0] = f / aspect;1432 out[1] = 0;1433 out[2] = 0;1434 out[3] = 0;1435 out[4] = 0;1436 out[5] = f;1437 out[6] = 0;1438 out[7] = 0;1439 out[8] = 0;1440 out[9] = 0;1441 out[11] = -1;1442 out[12] = 0;1443 out[13] = 0;1444 out[15] = 0;1445 if (far != null && far !== Infinity) {1446 nf = 1 / (near - far);1447 out[10] = (far + near) * nf;1448 out[14] = 2 * far * near * nf;1449 } else {1450 out[10] = -1;1451 out[14] = -2 * near;1452 }1453 return out;1454}1455/**1456 * Generates a perspective projection matrix with the given field of view.1457 * This is primarily useful for generating projection matrices to be used1458 * with the still experiemental WebVR API.1459 *1460 * @param {mat4} out mat4 frustum matrix will be written into1461 * @param {Object} fov Object containing the following values: upDegrees, downDegrees, leftDegrees, rightDegrees1462 * @param {number} near Near bound of the frustum1463 * @param {number} far Far bound of the frustum1464 * @returns {mat4} out1465 */1466export function perspectiveFromFieldOfView(out, fov, near, far) {1467 let upTan = Math.tan((fov.upDegrees * Math.PI) / 180.0);1468 let downTan = Math.tan((fov.downDegrees * Math.PI) / 180.0);1469 let leftTan = Math.tan((fov.leftDegrees * Math.PI) / 180.0);1470 let rightTan = Math.tan((fov.rightDegrees * Math.PI) / 180.0);1471 let xScale = 2.0 / (leftTan + rightTan);1472 let yScale = 2.0 / (upTan + downTan);1473 out[0] = xScale;1474 out[1] = 0.0;1475 out[2] = 0.0;1476 out[3] = 0.0;1477 out[4] = 0.0;1478 out[5] = yScale;1479 out[6] = 0.0;1480 out[7] = 0.0;1481 out[8] = -((leftTan - rightTan) * xScale * 0.5);1482 out[9] = (upTan - downTan) * yScale * 0.5;1483 out[10] = far / (near - far);1484 out[11] = -1.0;1485 out[12] = 0.0;1486 out[13] = 0.0;1487 out[14] = (far * near) / (near - far);1488 out[15] = 0.0;1489 return out;1490}1491/**1492 * Generates a orthogonal projection matrix with the given bounds1493 *1494 * @param {mat4} out mat4 frustum matrix will be written into1495 * @param {number} left Left bound of the frustum1496 * @param {number} right Right bound of the frustum1497 * @param {number} bottom Bottom bound of the frustum1498 * @param {number} top Top bound of the frustum1499 * @param {number} near Near bound of the frustum1500 * @param {number} far Far bound of the frustum1501 * @returns {mat4} out1502 */1503export function ortho(out, left, right, bottom, top, near, far) {1504 let lr = 1 / (left - right);1505 let bt = 1 / (bottom - top);1506 let nf = 1 / (near - far);1507 out[0] = -2 * lr;1508 out[1] = 0;1509 out[2] = 0;1510 out[3] = 0;1511 out[4] = 0;1512 out[5] = -2 * bt;1513 out[6] = 0;1514 out[7] = 0;1515 out[8] = 0;1516 out[9] = 0;1517 out[10] = 2 * nf;1518 out[11] = 0;1519 out[12] = (left + right) * lr;1520 out[13] = (top + bottom) * bt;1521 out[14] = (far + near) * nf;1522 out[15] = 1;1523 return out;1524}1525/**1526 * Generates a look-at matrix with the given eye position, focal point, and up axis.1527 * If you want a matrix that actually makes an object look at another object, you should use targetTo instead.1528 *1529 * @param {mat4} out mat4 frustum matrix will be written into1530 * @param {ReadonlyVec3} eye Position of the viewer1531 * @param {ReadonlyVec3} center Point the viewer is looking at1532 * @param {ReadonlyVec3} up vec3 pointing up1533 * @returns {mat4} out1534 */1535export function lookAt(out, eye, center, up) {1536 let x0, x1, x2, y0, y1, y2, z0, z1, z2, len;1537 let eyex = eye[0];1538 let eyey = eye[1];1539 let eyez = eye[2];1540 let upx = up[0];1541 let upy = up[1];1542 let upz = up[2];1543 let centerx = center[0];1544 let centery = center[1];1545 let centerz = center[2];1546 if (1547 Math.abs(eyex - centerx) < glMatrix.EPSILON &&1548 Math.abs(eyey - centery) < glMatrix.EPSILON &&1549 Math.abs(eyez - centerz) < glMatrix.EPSILON1550 ) {1551 return identity(out);1552 }1553 z0 = eyex - centerx;1554 z1 = eyey - centery;1555 z2 = eyez - centerz;1556 len = 1 / Math.hypot(z0, z1, z2);1557 z0 *= len;1558 z1 *= len;1559 z2 *= len;1560 x0 = upy * z2 - upz * z1;1561 x1 = upz * z0 - upx * z2;1562 x2 = upx * z1 - upy * z0;1563 len = Math.hypot(x0, x1, x2);1564 if (!len) {1565 x0 = 0;1566 x1 = 0;1567 x2 = 0;1568 } else {1569 len = 1 / len;1570 x0 *= len;1571 x1 *= len;1572 x2 *= len;1573 }1574 y0 = z1 * x2 - z2 * x1;1575 y1 = z2 * x0 - z0 * x2;1576 y2 = z0 * x1 - z1 * x0;1577 len = Math.hypot(y0, y1, y2);1578 if (!len) {1579 y0 = 0;1580 y1 = 0;1581 y2 = 0;1582 } else {1583 len = 1 / len;1584 y0 *= len;1585 y1 *= len;1586 y2 *= len;1587 }1588 out[0] = x0;1589 out[1] = y0;1590 out[2] = z0;1591 out[3] = 0;1592 out[4] = x1;1593 out[5] = y1;1594 out[6] = z1;1595 out[7] = 0;1596 out[8] = x2;1597 out[9] = y2;1598 out[10] = z2;1599 out[11] = 0;1600 out[12] = -(x0 * eyex + x1 * eyey + x2 * eyez);1601 out[13] = -(y0 * eyex + y1 * eyey + y2 * eyez);1602 out[14] = -(z0 * eyex + z1 * eyey + z2 * eyez);1603 out[15] = 1;1604 return out;1605}1606/**1607 * Generates a matrix that makes something look at something else.1608 *1609 * @param {mat4} out mat4 frustum matrix will be written into1610 * @param {ReadonlyVec3} eye Position of the viewer1611 * @param {ReadonlyVec3} center Point the viewer is looking at1612 * @param {ReadonlyVec3} up vec3 pointing up1613 * @returns {mat4} out1614 */1615export function targetTo(out, eye, target, up) {1616 let eyex = eye[0],1617 eyey = eye[1],1618 eyez = eye[2],1619 upx = up[0],1620 upy = up[1],1621 upz = up[2];1622 let z0 = eyex - target[0],1623 z1 = eyey - target[1],1624 z2 = eyez - target[2];1625 let len = z0 * z0 + z1 * z1 + z2 * z2;1626 if (len > 0) {1627 len = 1 / Math.sqrt(len);1628 z0 *= len;1629 z1 *= len;1630 z2 *= len;1631 }1632 let x0 = upy * z2 - upz * z1,1633 x1 = upz * z0 - upx * z2,1634 x2 = upx * z1 - upy * z0;1635 len = x0 * x0 + x1 * x1 + x2 * x2;1636 if (len > 0) {1637 len = 1 / Math.sqrt(len);1638 x0 *= len;1639 x1 *= len;1640 x2 *= len;1641 }1642 out[0] = x0;1643 out[1] = x1;1644 out[2] = x2;1645 out[3] = 0;1646 out[4] = z1 * x2 - z2 * x1;1647 out[5] = z2 * x0 - z0 * x2;1648 out[6] = z0 * x1 - z1 * x0;1649 out[7] = 0;1650 out[8] = z0;1651 out[9] = z1;1652 out[10] = z2;1653 out[11] = 0;1654 out[12] = eyex;1655 out[13] = eyey;1656 out[14] = eyez;1657 out[15] = 1;1658 return out;1659}1660/**1661 * Returns a string representation of a mat41662 *1663 * @param {ReadonlyMat4} a matrix to represent as a string1664 * @returns {String} string representation of the matrix1665 */1666export function str(a) {1667 return (1668 "mat4(" +1669 a[0] +1670 ", " +1671 a[1] +1672 ", " +1673 a[2] +1674 ", " +1675 a[3] +1676 ", " +1677 a[4] +1678 ", " +1679 a[5] +1680 ", " +1681 a[6] +1682 ", " +1683 a[7] +1684 ", " +1685 a[8] +1686 ", " +1687 a[9] +1688 ", " +1689 a[10] +1690 ", " +1691 a[11] +1692 ", " +1693 a[12] +1694 ", " +1695 a[13] +1696 ", " +1697 a[14] +1698 ", " +1699 a[15] +1700 ")"1701 );1702}1703/**1704 * Returns Frobenius norm of a mat41705 *1706 * @param {ReadonlyMat4} a the matrix to calculate Frobenius norm of1707 * @returns {Number} Frobenius norm1708 */1709export function frob(a) {1710 return Math.hypot(1711 a[0],1712 a[1],1713 a[2],1714 a[3],1715 a[4],1716 a[5],1717 a[6],1718 a[7],1719 a[8],1720 a[9],1721 a[10],1722 a[11],1723 a[12],1724 a[13],1725 a[14],1726 a[15]1727 );1728}1729/**1730 * Adds two mat4's1731 *1732 * @param {mat4} out the receiving matrix1733 * @param {ReadonlyMat4} a the first operand1734 * @param {ReadonlyMat4} b the second operand1735 * @returns {mat4} out1736 */1737export function add(out, a, b) {1738 out[0] = a[0] + b[0];1739 out[1] = a[1] + b[1];1740 out[2] = a[2] + b[2];1741 out[3] = a[3] + b[3];1742 out[4] = a[4] + b[4];1743 out[5] = a[5] + b[5];1744 out[6] = a[6] + b[6];1745 out[7] = a[7] + b[7];1746 out[8] = a[8] + b[8];1747 out[9] = a[9] + b[9];1748 out[10] = a[10] + b[10];1749 out[11] = a[11] + b[11];1750 out[12] = a[12] + b[12];1751 out[13] = a[13] + b[13];1752 out[14] = a[14] + b[14];1753 out[15] = a[15] + b[15];1754 return out;1755}1756/**1757 * Subtracts matrix b from matrix a1758 *1759 * @param {mat4} out the receiving matrix1760 * @param {ReadonlyMat4} a the first operand1761 * @param {ReadonlyMat4} b the second operand1762 * @returns {mat4} out1763 */1764export function subtract(out, a, b) {1765 out[0] = a[0] - b[0];1766 out[1] = a[1] - b[1];1767 out[2] = a[2] - b[2];1768 out[3] = a[3] - b[3];1769 out[4] = a[4] - b[4];1770 out[5] = a[5] - b[5];1771 out[6] = a[6] - b[6];1772 out[7] = a[7] - b[7];1773 out[8] = a[8] - b[8];1774 out[9] = a[9] - b[9];1775 out[10] = a[10] - b[10];1776 out[11] = a[11] - b[11];1777 out[12] = a[12] - b[12];1778 out[13] = a[13] - b[13];1779 out[14] = a[14] - b[14];1780 out[15] = a[15] - b[15];1781 return out;1782}1783/**1784 * Multiply each element of the matrix by a scalar.1785 *1786 * @param {mat4} out the receiving matrix1787 * @param {ReadonlyMat4} a the matrix to scale1788 * @param {Number} b amount to scale the matrix's elements by1789 * @returns {mat4} out1790 */1791export function multiplyScalar(out, a, b) {1792 out[0] = a[0] * b;1793 out[1] = a[1] * b;1794 out[2] = a[2] * b;1795 out[3] = a[3] * b;1796 out[4] = a[4] * b;1797 out[5] = a[5] * b;1798 out[6] = a[6] * b;1799 out[7] = a[7] * b;1800 out[8] = a[8] * b;1801 out[9] = a[9] * b;1802 out[10] = a[10] * b;1803 out[11] = a[11] * b;1804 out[12] = a[12] * b;1805 out[13] = a[13] * b;1806 out[14] = a[14] * b;1807 out[15] = a[15] * b;1808 return out;1809}1810/**1811 * Adds two mat4's after multiplying each element of the second operand by a scalar value.1812 *1813 * @param {mat4} out the receiving vector1814 * @param {ReadonlyMat4} a the first operand1815 * @param {ReadonlyMat4} b the second operand1816 * @param {Number} scale the amount to scale b's elements by before adding1817 * @returns {mat4} out1818 */1819export function multiplyScalarAndAdd(out, a, b, scale) {1820 out[0] = a[0] + b[0] * scale;1821 out[1] = a[1] + b[1] * scale;1822 out[2] = a[2] + b[2] * scale;1823 out[3] = a[3] + b[3] * scale;1824 out[4] = a[4] + b[4] * scale;1825 out[5] = a[5] + b[5] * scale;1826 out[6] = a[6] + b[6] * scale;1827 out[7] = a[7] + b[7] * scale;1828 out[8] = a[8] + b[8] * scale;1829 out[9] = a[9] + b[9] * scale;1830 out[10] = a[10] + b[10] * scale;1831 out[11] = a[11] + b[11] * scale;1832 out[12] = a[12] + b[12] * scale;1833 out[13] = a[13] + b[13] * scale;1834 out[14] = a[14] + b[14] * scale;1835 out[15] = a[15] + b[15] * scale;1836 return out;1837}1838/**1839 * Returns whether or not the matrices have exactly the same elements in the same position (when compared with ===)1840 *1841 * @param {ReadonlyMat4} a The first matrix.1842 * @param {ReadonlyMat4} b The second matrix.1843 * @returns {Boolean} True if the matrices are equal, false otherwise.1844 */1845export function exactEquals(a, b) {1846 return (1847 a[0] === b[0] &&1848 a[1] === b[1] &&1849 a[2] === b[2] &&1850 a[3] === b[3] &&1851 a[4] === b[4] &&1852 a[5] === b[5] &&1853 a[6] === b[6] &&1854 a[7] === b[7] &&1855 a[8] === b[8] &&1856 a[9] === b[9] &&1857 a[10] === b[10] &&1858 a[11] === b[11] &&1859 a[12] === b[12] &&1860 a[13] === b[13] &&1861 a[14] === b[14] &&1862 a[15] === b[15]1863 );1864}1865/**1866 * Returns whether or not the matrices have approximately the same elements in the same position.1867 *1868 * @param {ReadonlyMat4} a The first matrix.1869 * @param {ReadonlyMat4} b The second matrix.1870 * @returns {Boolean} True if the matrices are equal, false otherwise.1871 */1872export function equals(a, b) {1873 let a0 = a[0],1874 a1 = a[1],1875 a2 = a[2],1876 a3 = a[3];1877 let a4 = a[4],1878 a5 = a[5],1879 a6 = a[6],1880 a7 = a[7];1881 let a8 = a[8],1882 a9 = a[9],1883 a10 = a[10],1884 a11 = a[11];1885 let a12 = a[12],1886 a13 = a[13],1887 a14 = a[14],1888 a15 = a[15];1889 let b0 = b[0],1890 b1 = b[1],1891 b2 = b[2],1892 b3 = b[3];1893 let b4 = b[4],1894 b5 = b[5],1895 b6 = b[6],1896 b7 = b[7];1897 let b8 = b[8],1898 b9 = b[9],1899 b10 = b[10],1900 b11 = b[11];1901 let b12 = b[12],1902 b13 = b[13],1903 b14 = b[14],1904 b15 = b[15];1905 return (1906 Math.abs(a0 - b0) <=1907 glMatrix.EPSILON * Math.max(1.0, Math.abs(a0), Math.abs(b0)) &&1908 Math.abs(a1 - b1) <=1909 glMatrix.EPSILON * Math.max(1.0, Math.abs(a1), Math.abs(b1)) &&1910 Math.abs(a2 - b2) <=1911 glMatrix.EPSILON * Math.max(1.0, Math.abs(a2), Math.abs(b2)) &&1912 Math.abs(a3 - b3) <=1913 glMatrix.EPSILON * Math.max(1.0, Math.abs(a3), Math.abs(b3)) &&1914 Math.abs(a4 - b4) <=1915 glMatrix.EPSILON * Math.max(1.0, Math.abs(a4), Math.abs(b4)) &&1916 Math.abs(a5 - b5) <=1917 glMatrix.EPSILON * Math.max(1.0, Math.abs(a5), Math.abs(b5)) &&1918 Math.abs(a6 - b6) <=1919 glMatrix.EPSILON * Math.max(1.0, Math.abs(a6), Math.abs(b6)) &&1920 Math.abs(a7 - b7) <=1921 glMatrix.EPSILON * Math.max(1.0, Math.abs(a7), Math.abs(b7)) &&1922 Math.abs(a8 - b8) <=1923 glMatrix.EPSILON * Math.max(1.0, Math.abs(a8), Math.abs(b8)) &&1924 Math.abs(a9 - b9) <=1925 glMatrix.EPSILON * Math.max(1.0, Math.abs(a9), Math.abs(b9)) &&1926 Math.abs(a10 - b10) <=1927 glMatrix.EPSILON * Math.max(1.0, Math.abs(a10), Math.abs(b10)) &&1928 Math.abs(a11 - b11) <=1929 glMatrix.EPSILON * Math.max(1.0, Math.abs(a11), Math.abs(b11)) &&1930 Math.abs(a12 - b12) <=1931 glMatrix.EPSILON * Math.max(1.0, Math.abs(a12), Math.abs(b12)) &&1932 Math.abs(a13 - b13) <=1933 glMatrix.EPSILON * Math.max(1.0, Math.abs(a13), Math.abs(b13)) &&1934 Math.abs(a14 - b14) <=1935 glMatrix.EPSILON * Math.max(1.0, Math.abs(a14), Math.abs(b14)) &&1936 Math.abs(a15 - b15) <=1937 glMatrix.EPSILON * Math.max(1.0, Math.abs(a15), Math.abs(b15))1938 );1939}1940/**1941 * Alias for {@link mat4.multiply}1942 * @function1943 */1944export const mul = multiply;1945/**1946 * Alias for {@link mat4.subtract}1947 * @function1948 */...

Full Screen

Full Screen

mat3.js

Source:mat3.js Github

copy

Full Screen

1import * as glMatrix from "./common.js";2/**3 * 3x3 Matrix4 * @module mat35 */6/**7 * Creates a new identity mat38 *9 * @returns {mat3} a new 3x3 matrix10 */11export function create() {12 let out = new glMatrix.ARRAY_TYPE(9);13 if (glMatrix.ARRAY_TYPE != Float32Array) {14 out[1] = 0;15 out[2] = 0;16 out[3] = 0;17 out[5] = 0;18 out[6] = 0;19 out[7] = 0;20 }21 out[0] = 1;22 out[4] = 1;23 out[8] = 1;24 return out;25}26/**27 * Copies the upper-left 3x3 values into the given mat3.28 *29 * @param {mat3} out the receiving 3x3 matrix30 * @param {ReadonlyMat4} a the source 4x4 matrix31 * @returns {mat3} out32 */33export function fromMat4(out, a) {34 out[0] = a[0];35 out[1] = a[1];36 out[2] = a[2];37 out[3] = a[4];38 out[4] = a[5];39 out[5] = a[6];40 out[6] = a[8];41 out[7] = a[9];42 out[8] = a[10];43 return out;44}45/**46 * Creates a new mat3 initialized with values from an existing matrix47 *48 * @param {ReadonlyMat3} a matrix to clone49 * @returns {mat3} a new 3x3 matrix50 */51export function clone(a) {52 let out = new glMatrix.ARRAY_TYPE(9);53 out[0] = a[0];54 out[1] = a[1];55 out[2] = a[2];56 out[3] = a[3];57 out[4] = a[4];58 out[5] = a[5];59 out[6] = a[6];60 out[7] = a[7];61 out[8] = a[8];62 return out;63}64/**65 * Copy the values from one mat3 to another66 *67 * @param {mat3} out the receiving matrix68 * @param {ReadonlyMat3} a the source matrix69 * @returns {mat3} out70 */71export function copy(out, a) {72 out[0] = a[0];73 out[1] = a[1];74 out[2] = a[2];75 out[3] = a[3];76 out[4] = a[4];77 out[5] = a[5];78 out[6] = a[6];79 out[7] = a[7];80 out[8] = a[8];81 return out;82}83/**84 * Create a new mat3 with the given values85 *86 * @param {Number} m00 Component in column 0, row 0 position (index 0)87 * @param {Number} m01 Component in column 0, row 1 position (index 1)88 * @param {Number} m02 Component in column 0, row 2 position (index 2)89 * @param {Number} m10 Component in column 1, row 0 position (index 3)90 * @param {Number} m11 Component in column 1, row 1 position (index 4)91 * @param {Number} m12 Component in column 1, row 2 position (index 5)92 * @param {Number} m20 Component in column 2, row 0 position (index 6)93 * @param {Number} m21 Component in column 2, row 1 position (index 7)94 * @param {Number} m22 Component in column 2, row 2 position (index 8)95 * @returns {mat3} A new mat396 */97export function fromValues(m00, m01, m02, m10, m11, m12, m20, m21, m22) {98 let out = new glMatrix.ARRAY_TYPE(9);99 out[0] = m00;100 out[1] = m01;101 out[2] = m02;102 out[3] = m10;103 out[4] = m11;104 out[5] = m12;105 out[6] = m20;106 out[7] = m21;107 out[8] = m22;108 return out;109}110/**111 * Set the components of a mat3 to the given values112 *113 * @param {mat3} out the receiving matrix114 * @param {Number} m00 Component in column 0, row 0 position (index 0)115 * @param {Number} m01 Component in column 0, row 1 position (index 1)116 * @param {Number} m02 Component in column 0, row 2 position (index 2)117 * @param {Number} m10 Component in column 1, row 0 position (index 3)118 * @param {Number} m11 Component in column 1, row 1 position (index 4)119 * @param {Number} m12 Component in column 1, row 2 position (index 5)120 * @param {Number} m20 Component in column 2, row 0 position (index 6)121 * @param {Number} m21 Component in column 2, row 1 position (index 7)122 * @param {Number} m22 Component in column 2, row 2 position (index 8)123 * @returns {mat3} out124 */125export function set(out, m00, m01, m02, m10, m11, m12, m20, m21, m22) {126 out[0] = m00;127 out[1] = m01;128 out[2] = m02;129 out[3] = m10;130 out[4] = m11;131 out[5] = m12;132 out[6] = m20;133 out[7] = m21;134 out[8] = m22;135 return out;136}137/**138 * Set a mat3 to the identity matrix139 *140 * @param {mat3} out the receiving matrix141 * @returns {mat3} out142 */143export function identity(out) {144 out[0] = 1;145 out[1] = 0;146 out[2] = 0;147 out[3] = 0;148 out[4] = 1;149 out[5] = 0;150 out[6] = 0;151 out[7] = 0;152 out[8] = 1;153 return out;154}155/**156 * Transpose the values of a mat3157 *158 * @param {mat3} out the receiving matrix159 * @param {ReadonlyMat3} a the source matrix160 * @returns {mat3} out161 */162export function transpose(out, a) {163 // If we are transposing ourselves we can skip a few steps but have to cache some values164 if (out === a) {165 let a01 = a[1],166 a02 = a[2],167 a12 = a[5];168 out[1] = a[3];169 out[2] = a[6];170 out[3] = a01;171 out[5] = a[7];172 out[6] = a02;173 out[7] = a12;174 } else {175 out[0] = a[0];176 out[1] = a[3];177 out[2] = a[6];178 out[3] = a[1];179 out[4] = a[4];180 out[5] = a[7];181 out[6] = a[2];182 out[7] = a[5];183 out[8] = a[8];184 }185 return out;186}187/**188 * Inverts a mat3189 *190 * @param {mat3} out the receiving matrix191 * @param {ReadonlyMat3} a the source matrix192 * @returns {mat3} out193 */194export function invert(out, a) {195 let a00 = a[0],196 a01 = a[1],197 a02 = a[2];198 let a10 = a[3],199 a11 = a[4],200 a12 = a[5];201 let a20 = a[6],202 a21 = a[7],203 a22 = a[8];204 let b01 = a22 * a11 - a12 * a21;205 let b11 = -a22 * a10 + a12 * a20;206 let b21 = a21 * a10 - a11 * a20;207 // Calculate the determinant208 let det = a00 * b01 + a01 * b11 + a02 * b21;209 if (!det) {210 return null;211 }212 det = 1.0 / det;213 out[0] = b01 * det;214 out[1] = (-a22 * a01 + a02 * a21) * det;215 out[2] = (a12 * a01 - a02 * a11) * det;216 out[3] = b11 * det;217 out[4] = (a22 * a00 - a02 * a20) * det;218 out[5] = (-a12 * a00 + a02 * a10) * det;219 out[6] = b21 * det;220 out[7] = (-a21 * a00 + a01 * a20) * det;221 out[8] = (a11 * a00 - a01 * a10) * det;222 return out;223}224/**225 * Calculates the adjugate of a mat3226 *227 * @param {mat3} out the receiving matrix228 * @param {ReadonlyMat3} a the source matrix229 * @returns {mat3} out230 */231export function adjoint(out, a) {232 let a00 = a[0],233 a01 = a[1],234 a02 = a[2];235 let a10 = a[3],236 a11 = a[4],237 a12 = a[5];238 let a20 = a[6],239 a21 = a[7],240 a22 = a[8];241 out[0] = a11 * a22 - a12 * a21;242 out[1] = a02 * a21 - a01 * a22;243 out[2] = a01 * a12 - a02 * a11;244 out[3] = a12 * a20 - a10 * a22;245 out[4] = a00 * a22 - a02 * a20;246 out[5] = a02 * a10 - a00 * a12;247 out[6] = a10 * a21 - a11 * a20;248 out[7] = a01 * a20 - a00 * a21;249 out[8] = a00 * a11 - a01 * a10;250 return out;251}252/**253 * Calculates the determinant of a mat3254 *255 * @param {ReadonlyMat3} a the source matrix256 * @returns {Number} determinant of a257 */258export function determinant(a) {259 let a00 = a[0],260 a01 = a[1],261 a02 = a[2];262 let a10 = a[3],263 a11 = a[4],264 a12 = a[5];265 let a20 = a[6],266 a21 = a[7],267 a22 = a[8];268 return (269 a00 * (a22 * a11 - a12 * a21) +270 a01 * (-a22 * a10 + a12 * a20) +271 a02 * (a21 * a10 - a11 * a20)272 );273}274/**275 * Multiplies two mat3's276 *277 * @param {mat3} out the receiving matrix278 * @param {ReadonlyMat3} a the first operand279 * @param {ReadonlyMat3} b the second operand280 * @returns {mat3} out281 */282export function multiply(out, a, b) {283 let a00 = a[0],284 a01 = a[1],285 a02 = a[2];286 let a10 = a[3],287 a11 = a[4],288 a12 = a[5];289 let a20 = a[6],290 a21 = a[7],291 a22 = a[8];292 let b00 = b[0],293 b01 = b[1],294 b02 = b[2];295 let b10 = b[3],296 b11 = b[4],297 b12 = b[5];298 let b20 = b[6],299 b21 = b[7],300 b22 = b[8];301 out[0] = b00 * a00 + b01 * a10 + b02 * a20;302 out[1] = b00 * a01 + b01 * a11 + b02 * a21;303 out[2] = b00 * a02 + b01 * a12 + b02 * a22;304 out[3] = b10 * a00 + b11 * a10 + b12 * a20;305 out[4] = b10 * a01 + b11 * a11 + b12 * a21;306 out[5] = b10 * a02 + b11 * a12 + b12 * a22;307 out[6] = b20 * a00 + b21 * a10 + b22 * a20;308 out[7] = b20 * a01 + b21 * a11 + b22 * a21;309 out[8] = b20 * a02 + b21 * a12 + b22 * a22;310 return out;311}312/**313 * Translate a mat3 by the given vector314 *315 * @param {mat3} out the receiving matrix316 * @param {ReadonlyMat3} a the matrix to translate317 * @param {ReadonlyVec2} v vector to translate by318 * @returns {mat3} out319 */320export function translate(out, a, v) {321 let a00 = a[0],322 a01 = a[1],323 a02 = a[2],324 a10 = a[3],325 a11 = a[4],326 a12 = a[5],327 a20 = a[6],328 a21 = a[7],329 a22 = a[8],330 x = v[0],331 y = v[1];332 out[0] = a00;333 out[1] = a01;334 out[2] = a02;335 out[3] = a10;336 out[4] = a11;337 out[5] = a12;338 out[6] = x * a00 + y * a10 + a20;339 out[7] = x * a01 + y * a11 + a21;340 out[8] = x * a02 + y * a12 + a22;341 return out;342}343/**344 * Rotates a mat3 by the given angle345 *346 * @param {mat3} out the receiving matrix347 * @param {ReadonlyMat3} a the matrix to rotate348 * @param {Number} rad the angle to rotate the matrix by349 * @returns {mat3} out350 */351export function rotate(out, a, rad) {352 let a00 = a[0],353 a01 = a[1],354 a02 = a[2],355 a10 = a[3],356 a11 = a[4],357 a12 = a[5],358 a20 = a[6],359 a21 = a[7],360 a22 = a[8],361 s = Math.sin(rad),362 c = Math.cos(rad);363 out[0] = c * a00 + s * a10;364 out[1] = c * a01 + s * a11;365 out[2] = c * a02 + s * a12;366 out[3] = c * a10 - s * a00;367 out[4] = c * a11 - s * a01;368 out[5] = c * a12 - s * a02;369 out[6] = a20;370 out[7] = a21;371 out[8] = a22;372 return out;373}374/**375 * Scales the mat3 by the dimensions in the given vec2376 *377 * @param {mat3} out the receiving matrix378 * @param {ReadonlyMat3} a the matrix to rotate379 * @param {ReadonlyVec2} v the vec2 to scale the matrix by380 * @returns {mat3} out381 **/382export function scale(out, a, v) {383 let x = v[0],384 y = v[1];385 out[0] = x * a[0];386 out[1] = x * a[1];387 out[2] = x * a[2];388 out[3] = y * a[3];389 out[4] = y * a[4];390 out[5] = y * a[5];391 out[6] = a[6];392 out[7] = a[7];393 out[8] = a[8];394 return out;395}396/**397 * Creates a matrix from a vector translation398 * This is equivalent to (but much faster than):399 *400 * mat3.identity(dest);401 * mat3.translate(dest, dest, vec);402 *403 * @param {mat3} out mat3 receiving operation result404 * @param {ReadonlyVec2} v Translation vector405 * @returns {mat3} out406 */407export function fromTranslation(out, v) {408 out[0] = 1;409 out[1] = 0;410 out[2] = 0;411 out[3] = 0;412 out[4] = 1;413 out[5] = 0;414 out[6] = v[0];415 out[7] = v[1];416 out[8] = 1;417 return out;418}419/**420 * Creates a matrix from a given angle421 * This is equivalent to (but much faster than):422 *423 * mat3.identity(dest);424 * mat3.rotate(dest, dest, rad);425 *426 * @param {mat3} out mat3 receiving operation result427 * @param {Number} rad the angle to rotate the matrix by428 * @returns {mat3} out429 */430export function fromRotation(out, rad) {431 let s = Math.sin(rad),432 c = Math.cos(rad);433 out[0] = c;434 out[1] = s;435 out[2] = 0;436 out[3] = -s;437 out[4] = c;438 out[5] = 0;439 out[6] = 0;440 out[7] = 0;441 out[8] = 1;442 return out;443}444/**445 * Creates a matrix from a vector scaling446 * This is equivalent to (but much faster than):447 *448 * mat3.identity(dest);449 * mat3.scale(dest, dest, vec);450 *451 * @param {mat3} out mat3 receiving operation result452 * @param {ReadonlyVec2} v Scaling vector453 * @returns {mat3} out454 */455export function fromScaling(out, v) {456 out[0] = v[0];457 out[1] = 0;458 out[2] = 0;459 out[3] = 0;460 out[4] = v[1];461 out[5] = 0;462 out[6] = 0;463 out[7] = 0;464 out[8] = 1;465 return out;466}467/**468 * Copies the values from a mat2d into a mat3469 *470 * @param {mat3} out the receiving matrix471 * @param {ReadonlyMat2d} a the matrix to copy472 * @returns {mat3} out473 **/474export function fromMat2d(out, a) {475 out[0] = a[0];476 out[1] = a[1];477 out[2] = 0;478 out[3] = a[2];479 out[4] = a[3];480 out[5] = 0;481 out[6] = a[4];482 out[7] = a[5];483 out[8] = 1;484 return out;485}486/**487 * Calculates a 3x3 matrix from the given quaternion488 *489 * @param {mat3} out mat3 receiving operation result490 * @param {ReadonlyQuat} q Quaternion to create matrix from491 *492 * @returns {mat3} out493 */494export function fromQuat(out, q) {495 let x = q[0],496 y = q[1],497 z = q[2],498 w = q[3];499 let x2 = x + x;500 let y2 = y + y;501 let z2 = z + z;502 let xx = x * x2;503 let yx = y * x2;504 let yy = y * y2;505 let zx = z * x2;506 let zy = z * y2;507 let zz = z * z2;508 let wx = w * x2;509 let wy = w * y2;510 let wz = w * z2;511 out[0] = 1 - yy - zz;512 out[3] = yx - wz;513 out[6] = zx + wy;514 out[1] = yx + wz;515 out[4] = 1 - xx - zz;516 out[7] = zy - wx;517 out[2] = zx - wy;518 out[5] = zy + wx;519 out[8] = 1 - xx - yy;520 return out;521}522/**523 * Calculates a 3x3 normal matrix (transpose inverse) from the 4x4 matrix524 *525 * @param {mat3} out mat3 receiving operation result526 * @param {ReadonlyMat4} a Mat4 to derive the normal matrix from527 *528 * @returns {mat3} out529 */530export function normalFromMat4(out, a) {531 let a00 = a[0],532 a01 = a[1],533 a02 = a[2],534 a03 = a[3];535 let a10 = a[4],536 a11 = a[5],537 a12 = a[6],538 a13 = a[7];539 let a20 = a[8],540 a21 = a[9],541 a22 = a[10],542 a23 = a[11];543 let a30 = a[12],544 a31 = a[13],545 a32 = a[14],546 a33 = a[15];547 let b00 = a00 * a11 - a01 * a10;548 let b01 = a00 * a12 - a02 * a10;549 let b02 = a00 * a13 - a03 * a10;550 let b03 = a01 * a12 - a02 * a11;551 let b04 = a01 * a13 - a03 * a11;552 let b05 = a02 * a13 - a03 * a12;553 let b06 = a20 * a31 - a21 * a30;554 let b07 = a20 * a32 - a22 * a30;555 let b08 = a20 * a33 - a23 * a30;556 let b09 = a21 * a32 - a22 * a31;557 let b10 = a21 * a33 - a23 * a31;558 let b11 = a22 * a33 - a23 * a32;559 // Calculate the determinant560 let det =561 b00 * b11 - b01 * b10 + b02 * b09 + b03 * b08 - b04 * b07 + b05 * b06;562 if (!det) {563 return null;564 }565 det = 1.0 / det;566 out[0] = (a11 * b11 - a12 * b10 + a13 * b09) * det;567 out[1] = (a12 * b08 - a10 * b11 - a13 * b07) * det;568 out[2] = (a10 * b10 - a11 * b08 + a13 * b06) * det;569 out[3] = (a02 * b10 - a01 * b11 - a03 * b09) * det;570 out[4] = (a00 * b11 - a02 * b08 + a03 * b07) * det;571 out[5] = (a01 * b08 - a00 * b10 - a03 * b06) * det;572 out[6] = (a31 * b05 - a32 * b04 + a33 * b03) * det;573 out[7] = (a32 * b02 - a30 * b05 - a33 * b01) * det;574 out[8] = (a30 * b04 - a31 * b02 + a33 * b00) * det;575 return out;576}577/**578 * Generates a 2D projection matrix with the given bounds579 *580 * @param {mat3} out mat3 frustum matrix will be written into581 * @param {number} width Width of your gl context582 * @param {number} height Height of gl context583 * @returns {mat3} out584 */585export function projection(out, width, height) {586 out[0] = 2 / width;587 out[1] = 0;588 out[2] = 0;589 out[3] = 0;590 out[4] = -2 / height;591 out[5] = 0;592 out[6] = -1;593 out[7] = 1;594 out[8] = 1;595 return out;596}597/**598 * Returns a string representation of a mat3599 *600 * @param {ReadonlyMat3} a matrix to represent as a string601 * @returns {String} string representation of the matrix602 */603export function str(a) {604 return (605 "mat3(" +606 a[0] +607 ", " +608 a[1] +609 ", " +610 a[2] +611 ", " +612 a[3] +613 ", " +614 a[4] +615 ", " +616 a[5] +617 ", " +618 a[6] +619 ", " +620 a[7] +621 ", " +622 a[8] +623 ")"624 );625}626/**627 * Returns Frobenius norm of a mat3628 *629 * @param {ReadonlyMat3} a the matrix to calculate Frobenius norm of630 * @returns {Number} Frobenius norm631 */632export function frob(a) {633 return Math.hypot(a[0], a[1], a[2], a[3], a[4], a[5], a[6], a[7], a[8]);634}635/**636 * Adds two mat3's637 *638 * @param {mat3} out the receiving matrix639 * @param {ReadonlyMat3} a the first operand640 * @param {ReadonlyMat3} b the second operand641 * @returns {mat3} out642 */643export function add(out, a, b) {644 out[0] = a[0] + b[0];645 out[1] = a[1] + b[1];646 out[2] = a[2] + b[2];647 out[3] = a[3] + b[3];648 out[4] = a[4] + b[4];649 out[5] = a[5] + b[5];650 out[6] = a[6] + b[6];651 out[7] = a[7] + b[7];652 out[8] = a[8] + b[8];653 return out;654}655/**656 * Subtracts matrix b from matrix a657 *658 * @param {mat3} out the receiving matrix659 * @param {ReadonlyMat3} a the first operand660 * @param {ReadonlyMat3} b the second operand661 * @returns {mat3} out662 */663export function subtract(out, a, b) {664 out[0] = a[0] - b[0];665 out[1] = a[1] - b[1];666 out[2] = a[2] - b[2];667 out[3] = a[3] - b[3];668 out[4] = a[4] - b[4];669 out[5] = a[5] - b[5];670 out[6] = a[6] - b[6];671 out[7] = a[7] - b[7];672 out[8] = a[8] - b[8];673 return out;674}675/**676 * Multiply each element of the matrix by a scalar.677 *678 * @param {mat3} out the receiving matrix679 * @param {ReadonlyMat3} a the matrix to scale680 * @param {Number} b amount to scale the matrix's elements by681 * @returns {mat3} out682 */683export function multiplyScalar(out, a, b) {684 out[0] = a[0] * b;685 out[1] = a[1] * b;686 out[2] = a[2] * b;687 out[3] = a[3] * b;688 out[4] = a[4] * b;689 out[5] = a[5] * b;690 out[6] = a[6] * b;691 out[7] = a[7] * b;692 out[8] = a[8] * b;693 return out;694}695/**696 * Adds two mat3's after multiplying each element of the second operand by a scalar value.697 *698 * @param {mat3} out the receiving vector699 * @param {ReadonlyMat3} a the first operand700 * @param {ReadonlyMat3} b the second operand701 * @param {Number} scale the amount to scale b's elements by before adding702 * @returns {mat3} out703 */704export function multiplyScalarAndAdd(out, a, b, scale) {705 out[0] = a[0] + b[0] * scale;706 out[1] = a[1] + b[1] * scale;707 out[2] = a[2] + b[2] * scale;708 out[3] = a[3] + b[3] * scale;709 out[4] = a[4] + b[4] * scale;710 out[5] = a[5] + b[5] * scale;711 out[6] = a[6] + b[6] * scale;712 out[7] = a[7] + b[7] * scale;713 out[8] = a[8] + b[8] * scale;714 return out;715}716/**717 * Returns whether or not the matrices have exactly the same elements in the same position (when compared with ===)718 *719 * @param {ReadonlyMat3} a The first matrix.720 * @param {ReadonlyMat3} b The second matrix.721 * @returns {Boolean} True if the matrices are equal, false otherwise.722 */723export function exactEquals(a, b) {724 return (725 a[0] === b[0] &&726 a[1] === b[1] &&727 a[2] === b[2] &&728 a[3] === b[3] &&729 a[4] === b[4] &&730 a[5] === b[5] &&731 a[6] === b[6] &&732 a[7] === b[7] &&733 a[8] === b[8]734 );735}736/**737 * Returns whether or not the matrices have approximately the same elements in the same position.738 *739 * @param {ReadonlyMat3} a The first matrix.740 * @param {ReadonlyMat3} b The second matrix.741 * @returns {Boolean} True if the matrices are equal, false otherwise.742 */743export function equals(a, b) {744 let a0 = a[0],745 a1 = a[1],746 a2 = a[2],747 a3 = a[3],748 a4 = a[4],749 a5 = a[5],750 a6 = a[6],751 a7 = a[7],752 a8 = a[8];753 let b0 = b[0],754 b1 = b[1],755 b2 = b[2],756 b3 = b[3],757 b4 = b[4],758 b5 = b[5],759 b6 = b[6],760 b7 = b[7],761 b8 = b[8];762 return (763 Math.abs(a0 - b0) <=764 glMatrix.EPSILON * Math.max(1.0, Math.abs(a0), Math.abs(b0)) &&765 Math.abs(a1 - b1) <=766 glMatrix.EPSILON * Math.max(1.0, Math.abs(a1), Math.abs(b1)) &&767 Math.abs(a2 - b2) <=768 glMatrix.EPSILON * Math.max(1.0, Math.abs(a2), Math.abs(b2)) &&769 Math.abs(a3 - b3) <=770 glMatrix.EPSILON * Math.max(1.0, Math.abs(a3), Math.abs(b3)) &&771 Math.abs(a4 - b4) <=772 glMatrix.EPSILON * Math.max(1.0, Math.abs(a4), Math.abs(b4)) &&773 Math.abs(a5 - b5) <=774 glMatrix.EPSILON * Math.max(1.0, Math.abs(a5), Math.abs(b5)) &&775 Math.abs(a6 - b6) <=776 glMatrix.EPSILON * Math.max(1.0, Math.abs(a6), Math.abs(b6)) &&777 Math.abs(a7 - b7) <=778 glMatrix.EPSILON * Math.max(1.0, Math.abs(a7), Math.abs(b7)) &&779 Math.abs(a8 - b8) <=780 glMatrix.EPSILON * Math.max(1.0, Math.abs(a8), Math.abs(b8))781 );782}783/**784 * Alias for {@link mat3.multiply}785 * @function786 */787export const mul = multiply;788/**789 * Alias for {@link mat3.subtract}790 * @function791 */...

Full Screen

Full Screen

index.js

Source:index.js Github

copy

Full Screen

1function _typeof(obj) { if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }2function _sliceIterator(arr, i) { var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"] != null) _i["return"](); } finally { if (_d) throw _e; } } return _arr; }3function _slicedToArray(arr, i) { if (Array.isArray(arr)) { return arr; } else if (Symbol.iterator in Object(arr)) { return _sliceIterator(arr, i); } else { throw new TypeError("Invalid attempt to destructure non-iterable instance"); } }4import { isAnonymous, isInstruction } from "@webassemblyjs/ast";5import Long from "@xtuc/long";6var compact = false;7var space = " ";8var quote = function quote(str) {9 return "\"".concat(str, "\"");10};11function indent(nb) {12 return Array(nb).fill(space + space).join("");13} // TODO(sven): allow arbitrary ast nodes14export function print(n) {15 if (n.type === "Program") {16 return printProgram(n, 0);17 } else {18 throw new Error("Unsupported node in print of type: " + String(n.type));19 }20}21function printProgram(n, depth) {22 return n.body.reduce(function (acc, child) {23 if (child.type === "Module") {24 acc += printModule(child, depth + 1);25 }26 if (child.type === "Func") {27 acc += printFunc(child, depth + 1);28 }29 if (child.type === "BlockComment") {30 acc += printBlockComment(child);31 }32 if (child.type === "LeadingComment") {33 acc += printLeadingComment(child);34 }35 if (compact === false) {36 acc += "\n";37 }38 return acc;39 }, "");40}41function printTypeInstruction(n) {42 var out = "";43 out += "(";44 out += "type";45 out += space;46 if (n.id != null) {47 out += printIndex(n.id);48 out += space;49 }50 out += "(";51 out += "func";52 n.functype.params.forEach(function (param) {53 out += space;54 out += "(";55 out += "param";56 out += space;57 out += printFuncParam(param);58 out += ")";59 });60 n.functype.results.forEach(function (result) {61 out += space;62 out += "(";63 out += "result";64 out += space;65 out += result;66 out += ")";67 });68 out += ")"; // func69 out += ")";70 return out;71}72function printModule(n, depth) {73 var out = "(";74 out += "module";75 if (typeof n.id === "string") {76 out += space;77 out += n.id;78 }79 if (compact === false) {80 out += "\n";81 } else {82 out += space;83 }84 n.fields.forEach(function (field) {85 if (compact === false) {86 out += indent(depth);87 }88 switch (field.type) {89 case "Func":90 {91 out += printFunc(field, depth + 1);92 break;93 }94 case "TypeInstruction":95 {96 out += printTypeInstruction(field);97 break;98 }99 case "Table":100 {101 out += printTable(field);102 break;103 }104 case "Global":105 {106 out += printGlobal(field, depth + 1);107 break;108 }109 case "ModuleExport":110 {111 out += printModuleExport(field);112 break;113 }114 case "ModuleImport":115 {116 out += printModuleImport(field);117 break;118 }119 case "Memory":120 {121 out += printMemory(field);122 break;123 }124 case "BlockComment":125 {126 out += printBlockComment(field);127 break;128 }129 case "LeadingComment":130 {131 out += printLeadingComment(field);132 break;133 }134 case "Start":135 {136 out += printStart(field);137 break;138 }139 case "Elem":140 {141 out += printElem(field, depth);142 break;143 }144 case "Data":145 {146 out += printData(field, depth);147 break;148 }149 default:150 throw new Error("Unsupported node in printModule: " + String(field.type));151 }152 if (compact === false) {153 out += "\n";154 }155 });156 out += ")";157 return out;158}159function printData(n, depth) {160 var out = "";161 out += "(";162 out += "data";163 out += space;164 out += printIndex(n.memoryIndex);165 out += space;166 out += printInstruction(n.offset, depth);167 out += space;168 var value = "";169 n.init.values.forEach(function (byte) {170 value += String.fromCharCode(byte);171 }); // Avoid non-displayable characters172 out += JSON.stringify(value);173 out += ")";174 return out;175}176function printElem(n, depth) {177 var out = "";178 out += "(";179 out += "elem";180 out += space;181 out += printIndex(n.table);182 var _n$offset = _slicedToArray(n.offset, 1),183 firstOffset = _n$offset[0];184 out += space;185 out += "(";186 out += "offset";187 out += space;188 out += printInstruction(firstOffset, depth);189 out += ")";190 n.funcs.forEach(function (func) {191 out += space;192 out += printIndex(func);193 });194 out += ")";195 return out;196}197function printStart(n) {198 var out = "";199 out += "(";200 out += "start";201 out += space;202 out += printIndex(n.index);203 out += ")";204 return out;205}206function printLeadingComment(n) {207 // Don't print leading comments in compact mode208 if (compact === true) {209 return "";210 }211 var out = "";212 out += ";;";213 out += n.value;214 out += "\n";215 return out;216}217function printBlockComment(n) {218 // Don't print block comments in compact mode219 if (compact === true) {220 return "";221 }222 var out = "";223 out += "(;";224 out += n.value;225 out += ";)";226 out += "\n";227 return out;228}229function printSignature(n) {230 var out = "";231 n.params.forEach(function (param) {232 out += space;233 out += "(";234 out += "param";235 out += space;236 out += printFuncParam(param);237 out += ")";238 });239 n.results.forEach(function (result) {240 out += space;241 out += "(";242 out += "result";243 out += space;244 out += result;245 out += ")";246 });247 return out;248}249function printModuleImportDescr(n) {250 var out = "";251 if (n.type === "FuncImportDescr") {252 out += "(";253 out += "func";254 if (isAnonymous(n.id) === false) {255 out += space;256 out += printIdentifier(n.id);257 }258 out += printSignature(n.signature);259 out += ")";260 }261 if (n.type === "GlobalType") {262 out += "(";263 out += "global";264 out += space;265 out += printGlobalType(n);266 out += ")";267 }268 if (n.type === "Table") {269 out += printTable(n);270 }271 return out;272}273function printModuleImport(n) {274 var out = "";275 out += "(";276 out += "import";277 out += space;278 out += quote(n.module);279 out += space;280 out += quote(n.name);281 out += space;282 out += printModuleImportDescr(n.descr);283 out += ")";284 return out;285}286function printGlobalType(n) {287 var out = "";288 if (n.mutability === "var") {289 out += "(";290 out += "mut";291 out += space;292 out += n.valtype;293 out += ")";294 } else {295 out += n.valtype;296 }297 return out;298}299function printGlobal(n, depth) {300 var out = "";301 out += "(";302 out += "global";303 out += space;304 if (n.name != null && isAnonymous(n.name) === false) {305 out += printIdentifier(n.name);306 out += space;307 }308 out += printGlobalType(n.globalType);309 out += space;310 n.init.forEach(function (i) {311 out += printInstruction(i, depth + 1);312 });313 out += ")";314 return out;315}316function printTable(n) {317 var out = "";318 out += "(";319 out += "table";320 out += space;321 if (n.name != null && isAnonymous(n.name) === false) {322 out += printIdentifier(n.name);323 out += space;324 }325 out += printLimit(n.limits);326 out += space;327 out += n.elementType;328 out += ")";329 return out;330}331function printFuncParam(n) {332 var out = "";333 if (typeof n.id === "string") {334 out += "$" + n.id;335 out += space;336 }337 out += n.valtype;338 return out;339}340function printFunc(n, depth) {341 var out = "";342 out += "(";343 out += "func";344 if (n.name != null) {345 if (n.name.type === "Identifier" && isAnonymous(n.name) === false) {346 out += space;347 out += printIdentifier(n.name);348 }349 }350 if (n.signature.type === "Signature") {351 out += printSignature(n.signature);352 } else {353 var index = n.signature;354 out += space;355 out += "(";356 out += "type";357 out += space;358 out += printIndex(index);359 out += ")";360 }361 if (n.body.length > 0) {362 if (compact === false) {363 out += "\n";364 }365 n.body.forEach(function (i) {366 out += indent(depth);367 out += printInstruction(i, depth);368 if (compact === false) {369 out += "\n";370 }371 });372 out += indent(depth - 1) + ")";373 } else {374 out += ")";375 }376 return out;377}378function printInstruction(n, depth) {379 switch (n.type) {380 case "Instr":381 // $FlowIgnore382 return printGenericInstruction(n, depth + 1);383 case "BlockInstruction":384 // $FlowIgnore385 return printBlockInstruction(n, depth + 1);386 case "IfInstruction":387 // $FlowIgnore388 return printIfInstruction(n, depth + 1);389 case "CallInstruction":390 // $FlowIgnore391 return printCallInstruction(n, depth + 1);392 case "CallIndirectInstruction":393 // $FlowIgnore394 return printCallIndirectIntruction(n, depth + 1);395 case "LoopInstruction":396 // $FlowIgnore397 return printLoopInstruction(n, depth + 1);398 default:399 throw new Error("Unsupported instruction: " + JSON.stringify(n.type));400 }401}402function printCallIndirectIntruction(n, depth) {403 var out = "";404 out += "(";405 out += "call_indirect";406 if (n.signature.type === "Signature") {407 out += printSignature(n.signature);408 } else if (n.signature.type === "Identifier") {409 out += space;410 out += "(";411 out += "type";412 out += space;413 out += printIdentifier(n.signature);414 out += ")";415 } else {416 throw new Error("CallIndirectInstruction: unsupported signature " + JSON.stringify(n.signature.type));417 }418 out += space;419 if (n.intrs != null) {420 // $FlowIgnore421 n.intrs.forEach(function (i, index) {422 // $FlowIgnore423 out += printInstruction(i, depth + 1); // $FlowIgnore424 if (index !== n.intrs.length - 1) {425 out += space;426 }427 });428 }429 out += ")";430 return out;431}432function printLoopInstruction(n, depth) {433 var out = "";434 out += "(";435 out += "loop";436 if (n.label != null && isAnonymous(n.label) === false) {437 out += space;438 out += printIdentifier(n.label);439 }440 if (typeof n.resulttype === "string") {441 out += space;442 out += "(";443 out += "result";444 out += space;445 out += n.resulttype;446 out += ")";447 }448 if (n.instr.length > 0) {449 n.instr.forEach(function (e) {450 if (compact === false) {451 out += "\n";452 }453 out += indent(depth);454 out += printInstruction(e, depth + 1);455 });456 if (compact === false) {457 out += "\n";458 out += indent(depth - 1);459 }460 }461 out += ")";462 return out;463}464function printCallInstruction(n, depth) {465 var out = "";466 out += "(";467 out += "call";468 out += space;469 out += printIndex(n.index);470 if (_typeof(n.instrArgs) === "object") {471 // $FlowIgnore472 n.instrArgs.forEach(function (arg) {473 out += space;474 out += printFuncInstructionArg(arg, depth + 1);475 });476 }477 out += ")";478 return out;479}480function printIfInstruction(n, depth) {481 var out = "";482 out += "(";483 out += "if";484 if (n.testLabel != null && isAnonymous(n.testLabel) === false) {485 out += space;486 out += printIdentifier(n.testLabel);487 }488 if (typeof n.result === "string") {489 out += space;490 out += "(";491 out += "result";492 out += space;493 out += n.result;494 out += ")";495 }496 if (n.test.length > 0) {497 out += space;498 n.test.forEach(function (i) {499 out += printInstruction(i, depth + 1);500 });501 }502 if (n.consequent.length > 0) {503 if (compact === false) {504 out += "\n";505 }506 out += indent(depth);507 out += "(";508 out += "then";509 depth++;510 n.consequent.forEach(function (i) {511 if (compact === false) {512 out += "\n";513 }514 out += indent(depth);515 out += printInstruction(i, depth + 1);516 });517 depth--;518 if (compact === false) {519 out += "\n";520 out += indent(depth);521 }522 out += ")";523 } else {524 if (compact === false) {525 out += "\n";526 out += indent(depth);527 }528 out += "(";529 out += "then";530 out += ")";531 }532 if (n.alternate.length > 0) {533 if (compact === false) {534 out += "\n";535 }536 out += indent(depth);537 out += "(";538 out += "else";539 depth++;540 n.alternate.forEach(function (i) {541 if (compact === false) {542 out += "\n";543 }544 out += indent(depth);545 out += printInstruction(i, depth + 1);546 });547 depth--;548 if (compact === false) {549 out += "\n";550 out += indent(depth);551 }552 out += ")";553 } else {554 if (compact === false) {555 out += "\n";556 out += indent(depth);557 }558 out += "(";559 out += "else";560 out += ")";561 }562 if (compact === false) {563 out += "\n";564 out += indent(depth - 1);565 }566 out += ")";567 return out;568}569function printBlockInstruction(n, depth) {570 var out = "";571 out += "(";572 out += "block";573 if (n.label != null && isAnonymous(n.label) === false) {574 out += space;575 out += printIdentifier(n.label);576 }577 if (typeof n.result === "string") {578 out += space;579 out += "(";580 out += "result";581 out += space;582 out += n.result;583 out += ")";584 }585 if (n.instr.length > 0) {586 n.instr.forEach(function (i) {587 if (compact === false) {588 out += "\n";589 }590 out += indent(depth);591 out += printInstruction(i, depth + 1);592 });593 if (compact === false) {594 out += "\n";595 }596 out += indent(depth - 1);597 out += ")";598 } else {599 out += ")";600 }601 return out;602}603function printGenericInstruction(n, depth) {604 var out = "";605 out += "(";606 if (typeof n.object === "string") {607 out += n.object;608 out += ".";609 }610 out += n.id;611 n.args.forEach(function (arg) {612 out += space;613 out += printFuncInstructionArg(arg, depth + 1);614 });615 out += ")";616 return out;617}618function printLongNumberLiteral(n) {619 if (typeof n.raw === "string") {620 return n.raw;621 }622 var _n$value = n.value,623 low = _n$value.low,624 high = _n$value.high;625 var v = new Long(low, high);626 return v.toString();627}628function printFloatLiteral(n) {629 if (typeof n.raw === "string") {630 return n.raw;631 }632 return String(n.value);633}634function printFuncInstructionArg(n, depth) {635 var out = "";636 if (n.type === "NumberLiteral") {637 out += printNumberLiteral(n);638 }639 if (n.type === "LongNumberLiteral") {640 out += printLongNumberLiteral(n);641 }642 if (n.type === "Identifier" && isAnonymous(n) === false) {643 out += printIdentifier(n);644 }645 if (n.type === "ValtypeLiteral") {646 out += n.name;647 }648 if (n.type === "FloatLiteral") {649 out += printFloatLiteral(n);650 }651 if (isInstruction(n)) {652 out += printInstruction(n, depth + 1);653 }654 return out;655}656function printNumberLiteral(n) {657 if (typeof n.raw === "string") {658 return n.raw;659 }660 return String(n.value);661}662function printModuleExport(n) {663 var out = "";664 out += "(";665 out += "export";666 out += space;667 out += quote(n.name);668 if (n.descr.exportType === "Func") {669 out += space;670 out += "(";671 out += "func";672 out += space;673 out += printIndex(n.descr.id);674 out += ")";675 } else if (n.descr.exportType === "Global") {676 out += space;677 out += "(";678 out += "global";679 out += space;680 out += printIndex(n.descr.id);681 out += ")";682 } else if (n.descr.exportType === "Memory" || n.descr.exportType === "Mem") {683 out += space;684 out += "(";685 out += "memory";686 out += space;687 out += printIndex(n.descr.id);688 out += ")";689 } else if (n.descr.exportType === "Table") {690 out += space;691 out += "(";692 out += "table";693 out += space;694 out += printIndex(n.descr.id);695 out += ")";696 } else {697 throw new Error("printModuleExport: unknown type: " + n.descr.exportType);698 }699 out += ")";700 return out;701}702function printIdentifier(n) {703 return "$" + n.value;704}705function printIndex(n) {706 if (n.type === "Identifier") {707 return printIdentifier(n);708 } else if (n.type === "NumberLiteral") {709 return printNumberLiteral(n);710 } else {711 throw new Error("Unsupported index: " + n.type);712 }713}714function printMemory(n) {715 var out = "";716 out += "(";717 out += "memory";718 if (n.id != null) {719 out += space;720 out += printIndex(n.id);721 out += space;722 }723 out += printLimit(n.limits);724 out += ")";725 return out;726}727function printLimit(n) {728 var out = "";729 out += n.min + "";730 if (n.max != null) {731 out += space;732 out += String(n.max);733 }734 return out;...

Full Screen

Full Screen

vector.js

Source:vector.js Github

copy

Full Screen

1define(function () {2 var ArrayCtor = typeof Float32Array === 'undefined'3 ? Array4 : Float32Array;5 /**6 * @typedef {Float32Array|Array.<number>} Vector27 */8 /**9 * 二维向量类10 * @exports zrender/tool/vector11 */12 var vector = {13 /**14 * 创建一个向量15 * @param {number} [x=0]16 * @param {number} [y=0]17 * @return {Vector2}18 */19 create: function (x, y) {20 var out = new ArrayCtor(2);21 out[0] = x || 0;22 out[1] = y || 0;23 return out;24 },25 /**26 * 复制向量数据27 * @param {Vector2} out28 * @param {Vector2} v29 * @return {Vector2}30 */31 copy: function (out, v) {32 out[0] = v[0];33 out[1] = v[1];34 return out;35 },36 /**37 * 克隆一个向量38 * @param {Vector2} v39 * @return {Vector2}40 */41 clone: function (v) {42 var out = new ArrayCtor(2);43 out[0] = v[0];44 out[1] = v[1];45 return out;46 },47 /**48 * 设置向量的两个项49 * @param {Vector2} out50 * @param {number} a51 * @param {number} b52 * @return {Vector2} 结果53 */54 set: function (out, a, b) {55 out[0] = a;56 out[1] = b;57 return out;58 },59 /**60 * 向量相加61 * @param {Vector2} out62 * @param {Vector2} v163 * @param {Vector2} v264 */65 add: function (out, v1, v2) {66 out[0] = v1[0] + v2[0];67 out[1] = v1[1] + v2[1];68 return out;69 },70 /**71 * 向量缩放后相加72 * @param {Vector2} out73 * @param {Vector2} v174 * @param {Vector2} v275 * @param {number} a76 */77 scaleAndAdd: function (out, v1, v2, a) {78 out[0] = v1[0] + v2[0] * a;79 out[1] = v1[1] + v2[1] * a;80 return out;81 },82 /**83 * 向量相减84 * @param {Vector2} out85 * @param {Vector2} v186 * @param {Vector2} v287 */88 sub: function (out, v1, v2) {89 out[0] = v1[0] - v2[0];90 out[1] = v1[1] - v2[1];91 return out;92 },93 /**94 * 向量长度95 * @param {Vector2} v96 * @return {number}97 */98 len: function (v) {99 return Math.sqrt(this.lenSquare(v));100 },101 /**102 * 向量长度平方103 * @param {Vector2} v104 * @return {number}105 */106 lenSquare: function (v) {107 return v[0] * v[0] + v[1] * v[1];108 },109 /**110 * 向量乘法111 * @param {Vector2} out112 * @param {Vector2} v1113 * @param {Vector2} v2114 */115 mul: function (out, v1, v2) {116 out[0] = v1[0] * v2[0];117 out[1] = v1[1] * v2[1];118 return out;119 },120 /**121 * 向量除法122 * @param {Vector2} out123 * @param {Vector2} v1124 * @param {Vector2} v2125 */126 div: function (out, v1, v2) {127 out[0] = v1[0] / v2[0];128 out[1] = v1[1] / v2[1];129 return out;130 },131 /**132 * 向量点乘133 * @param {Vector2} v1134 * @param {Vector2} v2135 * @return {number}136 */137 dot: function (v1, v2) {138 return v1[0] * v2[0] + v1[1] * v2[1];139 },140 /**141 * 向量缩放142 * @param {Vector2} out143 * @param {Vector2} v144 * @param {number} s145 */146 scale: function (out, v, s) {147 out[0] = v[0] * s;148 out[1] = v[1] * s;149 return out;150 },151 /**152 * 向量归一化153 * @param {Vector2} out154 * @param {Vector2} v155 */156 normalize: function (out, v) {157 var d = vector.len(v);158 if (d === 0) {159 out[0] = 0;160 out[1] = 0;161 }162 else {163 out[0] = v[0] / d;164 out[1] = v[1] / d;165 }166 return out;167 },168 /**169 * 计算向量间距离170 * @param {Vector2} v1171 * @param {Vector2} v2172 * @return {number}173 */174 distance: function (v1, v2) {175 return Math.sqrt(176 (v1[0] - v2[0]) * (v1[0] - v2[0])177 + (v1[1] - v2[1]) * (v1[1] - v2[1])178 );179 },180 /**181 * 向量距离平方182 * @param {Vector2} v1183 * @param {Vector2} v2184 * @return {number}185 */186 distanceSquare: function (v1, v2) {187 return (v1[0] - v2[0]) * (v1[0] - v2[0])188 + (v1[1] - v2[1]) * (v1[1] - v2[1]);189 },190 /**191 * 求负向量192 * @param {Vector2} out193 * @param {Vector2} v194 */195 negate: function (out, v) {196 out[0] = -v[0];197 out[1] = -v[1];198 return out;199 },200 /**201 * 插值两个点202 * @param {Vector2} out203 * @param {Vector2} v1204 * @param {Vector2} v2205 * @param {number} t206 */207 lerp: function (out, v1, v2, t) {208 out[0] = v1[0] + t * (v2[0] - v1[0]);209 out[1] = v1[1] + t * (v2[1] - v1[1]);210 return out;211 },212 /**213 * 矩阵左乘向量214 * @param {Vector2} out215 * @param {Vector2} v216 * @param {Vector2} m217 */218 applyTransform: function (out, v, m) {219 var x = v[0];220 var y = v[1];221 out[0] = m[0] * x + m[2] * y + m[4];222 out[1] = m[1] * x + m[3] * y + m[5];223 return out;224 },225 /**226 * 求两个向量最小值227 * @param {Vector2} out228 * @param {Vector2} v1229 * @param {Vector2} v2230 */231 min: function (out, v1, v2) {232 out[0] = Math.min(v1[0], v2[0]);233 out[1] = Math.min(v1[1], v2[1]);234 return out;235 },236 /**237 * 求两个向量最大值238 * @param {Vector2} out239 * @param {Vector2} v1240 * @param {Vector2} v2241 */242 max: function (out, v1, v2) {243 out[0] = Math.max(v1[0], v2[0]);244 out[1] = Math.max(v1[1], v2[1]);245 return out;246 }247 };248 vector.length = vector.len;249 vector.lengthSquare = vector.lenSquare;250 vector.dist = vector.distance;251 vector.distSquare = vector.distanceSquare;252 return vector;...

Full Screen

Full Screen

matrix.js

Source:matrix.js Github

copy

Full Screen

1define(function () {2 var ArrayCtor = typeof Float32Array === 'undefined'3 ? Array4 : Float32Array;5 /**6 * 3x2矩阵操作类7 * @exports zrender/tool/matrix8 */9 var matrix = {10 /**11 * 创建一个单位矩阵12 * @return {Float32Array|Array.<number>}13 */14 create : function() {15 var out = new ArrayCtor(6);16 matrix.identity(out);17 return out;18 },19 /**20 * 设置矩阵为单位矩阵21 * @param {Float32Array|Array.<number>} out22 */23 identity : function(out) {24 out[0] = 1;25 out[1] = 0;26 out[2] = 0;27 out[3] = 1;28 out[4] = 0;29 out[5] = 0;30 return out;31 },32 /**33 * 复制矩阵34 * @param {Float32Array|Array.<number>} out35 * @param {Float32Array|Array.<number>} m36 */37 copy: function(out, m) {38 out[0] = m[0];39 out[1] = m[1];40 out[2] = m[2];41 out[3] = m[3];42 out[4] = m[4];43 out[5] = m[5];44 return out;45 },46 /**47 * 矩阵相乘48 * @param {Float32Array|Array.<number>} out49 * @param {Float32Array|Array.<number>} m150 * @param {Float32Array|Array.<number>} m251 */52 mul : function (out, m1, m2) {53 // Consider matrix.mul(m, m2, m);54 // where out is the same as m2.55 // So use temp variable to escape error.56 var out0 = m1[0] * m2[0] + m1[2] * m2[1];57 var out1 = m1[1] * m2[0] + m1[3] * m2[1];58 var out2 = m1[0] * m2[2] + m1[2] * m2[3];59 var out3 = m1[1] * m2[2] + m1[3] * m2[3];60 var out4 = m1[0] * m2[4] + m1[2] * m2[5] + m1[4];61 var out5 = m1[1] * m2[4] + m1[3] * m2[5] + m1[5];62 out[0] = out0;63 out[1] = out1;64 out[2] = out2;65 out[3] = out3;66 out[4] = out4;67 out[5] = out5;68 return out;69 },70 /**71 * 平移变换72 * @param {Float32Array|Array.<number>} out73 * @param {Float32Array|Array.<number>} a74 * @param {Float32Array|Array.<number>} v75 */76 translate : function(out, a, v) {77 out[0] = a[0];78 out[1] = a[1];79 out[2] = a[2];80 out[3] = a[3];81 out[4] = a[4] + v[0];82 out[5] = a[5] + v[1];83 return out;84 },85 /**86 * 旋转变换87 * @param {Float32Array|Array.<number>} out88 * @param {Float32Array|Array.<number>} a89 * @param {number} rad90 */91 rotate : function(out, a, rad) {92 var aa = a[0];93 var ac = a[2];94 var atx = a[4];95 var ab = a[1];96 var ad = a[3];97 var aty = a[5];98 var st = Math.sin(rad);99 var ct = Math.cos(rad);100 out[0] = aa * ct + ab * st;101 out[1] = -aa * st + ab * ct;102 out[2] = ac * ct + ad * st;103 out[3] = -ac * st + ct * ad;104 out[4] = ct * atx + st * aty;105 out[5] = ct * aty - st * atx;106 return out;107 },108 /**109 * 缩放变换110 * @param {Float32Array|Array.<number>} out111 * @param {Float32Array|Array.<number>} a112 * @param {Float32Array|Array.<number>} v113 */114 scale : function(out, a, v) {115 var vx = v[0];116 var vy = v[1];117 out[0] = a[0] * vx;118 out[1] = a[1] * vy;119 out[2] = a[2] * vx;120 out[3] = a[3] * vy;121 out[4] = a[4] * vx;122 out[5] = a[5] * vy;123 return out;124 },125 /**126 * 求逆矩阵127 * @param {Float32Array|Array.<number>} out128 * @param {Float32Array|Array.<number>} a129 */130 invert : function(out, a) {131 var aa = a[0];132 var ac = a[2];133 var atx = a[4];134 var ab = a[1];135 var ad = a[3];136 var aty = a[5];137 var det = aa * ad - ab * ac;138 if (!det) {139 return null;140 }141 det = 1.0 / det;142 out[0] = ad * det;143 out[1] = -ab * det;144 out[2] = -ac * det;145 out[3] = aa * det;146 out[4] = (ac * aty - ad * atx) * det;147 out[5] = (ab * atx - aa * aty) * det;148 return out;149 }150 };151 return matrix;...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1const strykerParent = require('stryker-parent');2console.log(strykerParent.out('Hello World!'));3const strykerParent = require('stryker-parent');4console.log(strykerParent.out('Hello World!'));5const strykerParent = require('stryker-parent');6console.log(strykerParent.out('Hello World!'));7const strykerParent = require('stryker-parent');8console.log(strykerParent.out('Hello World!'));9const strykerParent = require('stryker-parent');10console.log(strykerParent.out('Hello World!'));11const strykerParent = require('stryker-parent');12console.log(strykerParent.out('Hello World!'));13const strykerParent = require('stryker-parent');14console.log(strykerParent.out('Hello World!'));15const strykerParent = require('stryker-parent');16console.log(strykerParent.out('Hello World!'));17const strykerParent = require('stryker-parent');18console.log(strykerParent.out('Hello World!'));19const strykerParent = require('stryker-parent');20console.log(strykerParent.out('Hello World!'));21const strykerParent = require('stryker-parent');22console.log(strykerParent.out('Hello World!'));23const strykerParent = require('stryker-parent');24console.log(strykerParent.out('Hello World!'));

Full Screen

Using AI Code Generation

copy

Full Screen

1var strykerParent = require('stryker-parent');2console.log(strykerParent.out('Hello world!'));3var strykerChild = require('stryker-child');4console.log(strykerChild.out('Hello world!'));5var stryker = require('stryker');6console.log(stryker.out('Hello world!'));7var strykerApi = require('stryker-api');8console.log(strykerApi.out('Hello world!'));9var strykerCli = require('stryker-cli');10console.log(strykerCli.out('Hello world!'));11var strykerHtmlReporter = require('stryker-html-reporter');12console.log(strykerHtmlReporter.out('Hello world!'));13var strykerJasmineRunner = require('stryker-jasmine-runner');14console.log(strykerJasmineRunner.out('Hello world!'));15var strykerKarmaRunner = require('stryker-karma-runner');16console.log(strykerKarmaRunner.out('Hello world!'));17var strykerMochaFramework = require('stryker-mocha-framework');18console.log(strykerMochaFramework.out('Hello world!'));19var strykerMochaRunner = require('stryker-mocha-runner');20console.log(strykerMochaRunner.out('Hello world!'));21var strykerTypescript = require('stryker-typescript');22console.log(strykerTypescript.out('Hello world!'));

Full Screen

Using AI Code Generation

copy

Full Screen

1const parent = require('stryker-parent');2parent.out('Hello world');3{4 "scripts": {5 },6 "dependencies": {7 }8}9const parent = require('stryker-parent');10parent.out('Hello world');11{12 "scripts": {13 },14 "dependencies": {15 }16}17const parent = require('stryker-parent');18parent.out('Hello world');19{20 "scripts": {21 },22 "dependencies": {23 }24}25const parent = require('stryker-parent');26parent.out('Hello world');27{

Full Screen

Using AI Code Generation

copy

Full Screen

1var strykerParent = require('stryker-parent');2strykerParent.out('Hello world');3module.exports = function(config) {4 config.set({5 });6};

Full Screen

Using AI Code Generation

copy

Full Screen

1var stryker = require('stryker-parent');2stryker.out('Hello world');3module.exports = {4 out: function (msg) {5 console.log(msg);6 }7};8{9 "dependencies": {10 }11}

Full Screen

Using AI Code Generation

copy

Full Screen

1var parent = require('stryker-parent');2parent.out('Hello world');3exports.out = function(str) {4 console.log('out: ' + str);5};6{7}8var parent = require('stryker-parent');9parent.out('Hello world');10exports.out = function(str) {11 console.log('out: ' + str);12};13{14}15var parent = require('stryker-parent');16parent.out('Hello world');17exports.out = function(str) {18 console.log('out: ' + str);19};20{21}22var parent = require('stryker-parent');23parent.out('Hello world');24exports.out = function(str) {25 console.log('out: ' + str);26};27{28}29var parent = require('stryker-parent');30parent.out('Hello world');31exports.out = function(str) {32 console.log('out: ' + str);33};34{35}

Full Screen

Using AI Code Generation

copy

Full Screen

1const stryker = require('stryker-parent');2stryker.out('test');3module.exports = {4 out: function (log) {5 console.log(log);6 }7};8module.exports = function (config) {9 config.set({10 });11};

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run stryker-parent automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful