scenejs_on_rails 1.0.0 → 1.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +5 -5
- data/app/controllers/scenejs_controller.rb +53 -0
- data/app/views/scenejs/get_scenejs_data.html.erb +3 -0
- data/lib/scenejs_on_rails.rb +1 -1
- data/lib/scenejs_on_rails/rails.rb +5 -0
- data/lib/scenejs_on_rails/version.rb +1 -1
- data/vendor/assets/javascripts/scenejs.js +17307 -0
- data/vendor/assets/javascripts/scenejs_extras/gui.js +478 -0
- data/vendor/assets/javascripts/scenejs_extras/gui/README.md +4 -0
- data/vendor/assets/javascripts/scenejs_extras/gui/dat.gui.min.js +94 -0
- data/vendor/assets/javascripts/scenejs_extras/gui/gui.js +385 -0
- data/vendor/assets/javascripts/scenejs_lib/cityBuilder.js +457 -0
- data/vendor/assets/javascripts/scenejs_lib/dat.gui.min.js +94 -0
- data/vendor/assets/javascripts/scenejs_lib/gl-matrix-min.js +28 -0
- data/vendor/assets/javascripts/scenejs_lib/gl-matrix.js +4078 -0
- data/vendor/assets/javascripts/scenejs_lib/require.js +36 -0
- data/vendor/assets/javascripts/scenejs_lib/requireConfig.js +18 -0
- data/vendor/assets/javascripts/scenejs_lib/requireWrapperEnd.js +1 -0
- data/vendor/assets/javascripts/scenejs_lib/requireWrapperStart.js +2 -0
- data/vendor/assets/javascripts/scenejs_lib/stats.min.js +6 -0
- data/vendor/assets/javascripts/scenejs_lib/sylvester.js +1 -0
- data/vendor/assets/javascripts/scenejs_lib/webgl-debug-utils.js +839 -0
- data/vendor/assets/javascripts/scenejs_plugins/geometry/boundary.js +59 -0
- data/vendor/assets/javascripts/scenejs_plugins/geometry/box.js +72 -0
- data/vendor/assets/javascripts/scenejs_plugins/geometry/plane.js +126 -0
- data/vendor/assets/javascripts/scenejs_plugins/geometry/quad.js +37 -0
- data/vendor/assets/javascripts/scenejs_plugins/geometry/skybox.js +86 -0
- data/vendor/assets/javascripts/scenejs_plugins/geometry/sphere.js +82 -0
- data/vendor/assets/javascripts/scenejs_plugins/geometry/teapot.js +5853 -0
- data/vendor/assets/javascripts/scenejs_plugins/geometry/torus.js +139 -0
- data/vendor/assets/javascripts/scenejs_plugins/geometry/vectorText.js +1499 -0
- data/vendor/assets/javascripts/scenejs_plugins/geometry/wobblyBox.js +44 -0
- data/vendor/assets/javascripts/scenejs_plugins/lib/canvas2image.js +198 -0
- data/vendor/assets/javascripts/scenejs_plugins/lib/frustum/frustumCullEngine.js +810 -0
- data/vendor/assets/javascripts/scenejs_plugins/lib/frustum/frustumCullSystem.js +185 -0
- data/vendor/assets/javascripts/scenejs_plugins/lib/frustum/frustumCullSystemPool.js +174 -0
- data/vendor/assets/javascripts/scenejs_plugins/lib/frustum/frustumCullWorker.js +142 -0
- data/vendor/assets/javascripts/scenejs_plugins/lib/gl-matrix-min.js +28 -0
- data/vendor/assets/javascripts/scenejs_plugins/lib/jquery-1.8.3.min.js +2 -0
- data/vendor/assets/javascripts/scenejs_plugins/lib/k3d.js +1029 -0
- data/vendor/assets/javascripts/scenejs_plugins/lib/physics/jiglib.all.min.js +3 -0
- data/vendor/assets/javascripts/scenejs_plugins/lib/physics/physics.js +223 -0
- data/vendor/assets/javascripts/scenejs_plugins/lib/physics/worker.js +330 -0
- data/vendor/assets/javascripts/scenejs_plugins/node/alpha/orbitTracking.js +295 -0
- data/vendor/assets/javascripts/scenejs_plugins/node/alpha/orbitTrackingTarget.js +43 -0
- data/vendor/assets/javascripts/scenejs_plugins/node/backgrounds/gradient.js +148 -0
- data/vendor/assets/javascripts/scenejs_plugins/node/cameras/orbit.js +172 -0
- data/vendor/assets/javascripts/scenejs_plugins/node/cameras/pickFlyOrbit.js +409 -0
- data/vendor/assets/javascripts/scenejs_plugins/node/canvas/capture.js +107 -0
- data/vendor/assets/javascripts/scenejs_plugins/node/demos/color.js +30 -0
- data/vendor/assets/javascripts/scenejs_plugins/node/demos/redTeapot.js +52 -0
- data/vendor/assets/javascripts/scenejs_plugins/node/demos/spinningTeapot.js +43 -0
- data/vendor/assets/javascripts/scenejs_plugins/node/effects/crt.js +36 -0
- data/vendor/assets/javascripts/scenejs_plugins/node/effects/fog.js +159 -0
- data/vendor/assets/javascripts/scenejs_plugins/node/effects/snowyPeaks.js +50 -0
- data/vendor/assets/javascripts/scenejs_plugins/node/effects/wobble.js +42 -0
- data/vendor/assets/javascripts/scenejs_plugins/node/effects/xray.js +126 -0
- data/vendor/assets/javascripts/scenejs_plugins/node/frustum/body.js +112 -0
- data/vendor/assets/javascripts/scenejs_plugins/node/frustum/cull.js +42 -0
- data/vendor/assets/javascripts/scenejs_plugins/node/frustum/lod.js +125 -0
- data/vendor/assets/javascripts/scenejs_plugins/node/heightmaps/custom.js +185 -0
- data/vendor/assets/javascripts/scenejs_plugins/node/import/3ds.js +91 -0
- data/vendor/assets/javascripts/scenejs_plugins/node/import/md2.js +139 -0
- data/vendor/assets/javascripts/scenejs_plugins/node/import/obj.js +100 -0
- data/vendor/assets/javascripts/scenejs_plugins/node/objects/buildings/building.js +352 -0
- data/vendor/assets/javascripts/scenejs_plugins/node/objects/buildings/building/HighRiseGlass.jpg +0 -0
- data/vendor/assets/javascripts/scenejs_plugins/node/objects/buildings/building/HighRiseGlassSpecular.jpg +0 -0
- data/vendor/assets/javascripts/scenejs_plugins/node/objects/buildings/building/highrise-windows.jpg +0 -0
- data/vendor/assets/javascripts/scenejs_plugins/node/objects/buildings/building/pixelcity_windows7.jpg +0 -0
- data/vendor/assets/javascripts/scenejs_plugins/node/objects/buildings/city.js +26 -0
- data/vendor/assets/javascripts/scenejs_plugins/node/objects/plants/ghostTree.js +387 -0
- data/vendor/assets/javascripts/scenejs_plugins/node/objects/space/planets/earth.js +168 -0
- data/vendor/assets/javascripts/scenejs_plugins/node/objects/space/planets/earth/earth-lights.gif +0 -0
- data/vendor/assets/javascripts/scenejs_plugins/node/objects/space/planets/earth/earth-specular.gif +0 -0
- data/vendor/assets/javascripts/scenejs_plugins/node/objects/space/planets/earth/earth-specular.jpg +0 -0
- data/vendor/assets/javascripts/scenejs_plugins/node/objects/space/planets/earth/earth.jpg +0 -0
- data/vendor/assets/javascripts/scenejs_plugins/node/objects/space/planets/earth/earthbump.jpg +0 -0
- data/vendor/assets/javascripts/scenejs_plugins/node/objects/space/planets/earth/earthclouds.jpg +0 -0
- data/vendor/assets/javascripts/scenejs_plugins/node/objects/toys/drinkingBird.js +632 -0
- data/vendor/assets/javascripts/scenejs_plugins/node/objects/vehicles/tank.js +77670 -0
- data/vendor/assets/javascripts/scenejs_plugins/node/objects/vehicles/tank.js~ +77636 -0
- data/vendor/assets/javascripts/scenejs_plugins/node/physics/body.js +85 -0
- data/vendor/assets/javascripts/scenejs_plugins/node/physics/box.js +30 -0
- data/vendor/assets/javascripts/scenejs_plugins/node/physics/material.js +35 -0
- data/vendor/assets/javascripts/scenejs_plugins/node/physics/plane.js +47 -0
- data/vendor/assets/javascripts/scenejs_plugins/node/physics/sphere.js +32 -0
- data/vendor/assets/javascripts/scenejs_plugins/node/physics/system.js +44 -0
- data/vendor/assets/javascripts/scenejs_plugins/node/physics/teapot.js +29 -0
- data/vendor/assets/javascripts/scenejs_plugins/node/prims/boundary.js +73 -0
- data/vendor/assets/javascripts/scenejs_plugins/node/prims/box.js +87 -0
- data/vendor/assets/javascripts/scenejs_plugins/node/prims/cylinder.js +186 -0
- data/vendor/assets/javascripts/scenejs_plugins/node/prims/grid.js +47 -0
- data/vendor/assets/javascripts/scenejs_plugins/node/prims/plane.js +137 -0
- data/vendor/assets/javascripts/scenejs_plugins/node/prims/quad.js +43 -0
- data/vendor/assets/javascripts/scenejs_plugins/node/prims/sphere.js +107 -0
- data/vendor/assets/javascripts/scenejs_plugins/node/prims/teapot.js +5846 -0
- data/vendor/assets/javascripts/scenejs_plugins/node/prims/torus.js +149 -0
- data/vendor/assets/javascripts/scenejs_plugins/node/prims/vectorText.js +1508 -0
- data/vendor/assets/javascripts/scenejs_plugins/node/skyboxes/clouds.js +19 -0
- data/vendor/assets/javascripts/scenejs_plugins/node/skyboxes/cloudySea.js +19 -0
- data/vendor/assets/javascripts/scenejs_plugins/node/skyboxes/custom.js +150 -0
- data/vendor/assets/javascripts/scenejs_plugins/node/skyboxes/grimmNight.js +19 -0
- data/vendor/assets/javascripts/scenejs_plugins/node/skyboxes/interstellarClouds.js +19 -0
- data/vendor/assets/javascripts/scenejs_plugins/node/skyboxes/miramarClouds.js +19 -0
- data/vendor/assets/javascripts/scenejs_plugins/node/skyboxes/stormyDays.js +19 -0
- data/vendor/assets/javascripts/scenejs_plugins/node/skyboxes/textures/clouds.jpg +0 -0
- data/vendor/assets/javascripts/scenejs_plugins/node/skyboxes/textures/cloudySea.jpg +0 -0
- data/vendor/assets/javascripts/scenejs_plugins/node/skyboxes/textures/grimmNight.jpg +0 -0
- data/vendor/assets/javascripts/scenejs_plugins/node/skyboxes/textures/interstellarClouds.jpg +0 -0
- data/vendor/assets/javascripts/scenejs_plugins/node/skyboxes/textures/miramarClouds.jpg +0 -0
- data/vendor/assets/javascripts/scenejs_plugins/node/skyboxes/textures/stormyDays.jpg +0 -0
- data/vendor/assets/javascripts/scenejs_plugins/node/skyboxes/textures/violentDays.jpg +0 -0
- data/vendor/assets/javascripts/scenejs_plugins/node/skyboxes/violentDays.js +19 -0
- data/vendor/assets/javascripts/scenejs_plugins/texture/image.js +67 -0
- data/vendor/assets/javascripts/scenejs_plugins/texture/video.js +105 -0
- metadata +113 -1
@@ -0,0 +1,94 @@
|
|
1
|
+
/**
|
2
|
+
* dat-gui JavaScript Controller Library
|
3
|
+
* http://code.google.com/p/dat-gui
|
4
|
+
*
|
5
|
+
* Copyright 2011 Data Arts Team, Google Creative Lab
|
6
|
+
*
|
7
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
8
|
+
* you may not use this file except in compliance with the License.
|
9
|
+
* You may obtain a copy of the License at
|
10
|
+
*
|
11
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
12
|
+
*/
|
13
|
+
var dat=dat||{};dat.gui=dat.gui||{};dat.utils=dat.utils||{};dat.controllers=dat.controllers||{};dat.dom=dat.dom||{};dat.color=dat.color||{};dat.utils.css=function(){return{load:function(e,a){var a=a||document,c=a.createElement("link");c.type="text/css";c.rel="stylesheet";c.href=e;a.getElementsByTagName("head")[0].appendChild(c)},inject:function(e,a){var a=a||document,c=document.createElement("style");c.type="text/css";c.innerHTML=e;a.getElementsByTagName("head")[0].appendChild(c)}}}();
|
14
|
+
dat.utils.common=function(){var e=Array.prototype.forEach,a=Array.prototype.slice;return{BREAK:{},extend:function(c){this.each(a.call(arguments,1),function(a){for(var f in a)this.isUndefined(a[f])||(c[f]=a[f])},this);return c},defaults:function(c){this.each(a.call(arguments,1),function(a){for(var f in a)this.isUndefined(c[f])&&(c[f]=a[f])},this);return c},compose:function(){var c=a.call(arguments);return function(){for(var d=a.call(arguments),f=c.length-1;f>=0;f--)d=[c[f].apply(this,d)];return d[0]}},
|
15
|
+
each:function(a,d,f){if(e&&a.forEach===e)a.forEach(d,f);else if(a.length===a.length+0)for(var b=0,n=a.length;b<n;b++){if(b in a&&d.call(f,a[b],b)===this.BREAK)break}else for(b in a)if(d.call(f,a[b],b)===this.BREAK)break},defer:function(a){setTimeout(a,0)},toArray:function(c){return c.toArray?c.toArray():a.call(c)},isUndefined:function(a){return a===void 0},isNull:function(a){return a===null},isNaN:function(a){return a!==a},isArray:Array.isArray||function(a){return a.constructor===Array},isObject:function(a){return a===
|
16
|
+
Object(a)},isNumber:function(a){return a===a+0},isString:function(a){return a===a+""},isBoolean:function(a){return a===false||a===true},isFunction:function(a){return Object.prototype.toString.call(a)==="[object Function]"}}}();
|
17
|
+
dat.controllers.Controller=function(e){var a=function(a,d){this.initialValue=a[d];this.domElement=document.createElement("div");this.object=a;this.property=d;this.__onFinishChange=this.__onChange=void 0};e.extend(a.prototype,{onChange:function(a){this.__onChange=a;return this},onFinishChange:function(a){this.__onFinishChange=a;return this},setValue:function(a){this.object[this.property]=a;this.__onChange&&this.__onChange.call(this,a);this.updateDisplay();return this},getValue:function(){return this.object[this.property]},
|
18
|
+
updateDisplay:function(){return this},isModified:function(){return this.initialValue!==this.getValue()}});return a}(dat.utils.common);
|
19
|
+
dat.dom.dom=function(e){function a(b){if(b==="0"||e.isUndefined(b))return 0;b=b.match(d);return!e.isNull(b)?parseFloat(b[1]):0}var c={};e.each({HTMLEvents:["change"],MouseEvents:["click","mousemove","mousedown","mouseup","mouseover"],KeyboardEvents:["keydown"]},function(b,a){e.each(b,function(b){c[b]=a})});var d=/(\d+(\.\d+)?)px/,f={makeSelectable:function(b,a){if(!(b===void 0||b.style===void 0))b.onselectstart=a?function(){return false}:function(){},b.style.MozUserSelect=a?"auto":"none",b.style.KhtmlUserSelect=
|
20
|
+
a?"auto":"none",b.unselectable=a?"on":"off"},makeFullscreen:function(b,a,d){e.isUndefined(a)&&(a=true);e.isUndefined(d)&&(d=true);b.style.position="absolute";if(a)b.style.left=0,b.style.right=0;if(d)b.style.top=0,b.style.bottom=0},fakeEvent:function(b,a,d,f){var d=d||{},m=c[a];if(!m)throw Error("Event type "+a+" not supported.");var l=document.createEvent(m);switch(m){case "MouseEvents":l.initMouseEvent(a,d.bubbles||false,d.cancelable||true,window,d.clickCount||1,0,0,d.x||d.clientX||0,d.y||d.clientY||
|
21
|
+
0,false,false,false,false,0,null);break;case "KeyboardEvents":m=l.initKeyboardEvent||l.initKeyEvent;e.defaults(d,{cancelable:true,ctrlKey:false,altKey:false,shiftKey:false,metaKey:false,keyCode:void 0,charCode:void 0});m(a,d.bubbles||false,d.cancelable,window,d.ctrlKey,d.altKey,d.shiftKey,d.metaKey,d.keyCode,d.charCode);break;default:l.initEvent(a,d.bubbles||false,d.cancelable||true)}e.defaults(l,f);b.dispatchEvent(l)},bind:function(b,a,d,c){b.addEventListener?b.addEventListener(a,d,c||false):b.attachEvent&&
|
22
|
+
b.attachEvent("on"+a,d);return f},unbind:function(b,a,d,c){b.removeEventListener?b.removeEventListener(a,d,c||false):b.detachEvent&&b.detachEvent("on"+a,d);return f},addClass:function(b,a){if(b.className===void 0)b.className=a;else if(b.className!==a){var d=b.className.split(/ +/);if(d.indexOf(a)==-1)d.push(a),b.className=d.join(" ").replace(/^\s+/,"").replace(/\s+$/,"")}return f},removeClass:function(b,a){if(a){if(b.className!==void 0)if(b.className===a)b.removeAttribute("class");else{var d=b.className.split(/ +/),
|
23
|
+
c=d.indexOf(a);if(c!=-1)d.splice(c,1),b.className=d.join(" ")}}else b.className=void 0;return f},hasClass:function(a,d){return RegExp("(?:^|\\s+)"+d+"(?:\\s+|$)").test(a.className)||false},getWidth:function(b){b=getComputedStyle(b);return a(b["border-left-width"])+a(b["border-right-width"])+a(b["padding-left"])+a(b["padding-right"])+a(b.width)},getHeight:function(b){b=getComputedStyle(b);return a(b["border-top-width"])+a(b["border-bottom-width"])+a(b["padding-top"])+a(b["padding-bottom"])+a(b.height)},
|
24
|
+
getOffset:function(a){var d={left:0,top:0};if(a.offsetParent){do d.left+=a.offsetLeft,d.top+=a.offsetTop;while(a=a.offsetParent)}return d},isActive:function(a){return a===document.activeElement&&(a.type||a.href)}};return f}(dat.utils.common);
|
25
|
+
dat.controllers.OptionController=function(e,a,c){var d=function(f,b,e){d.superclass.call(this,f,b);var h=this;this.__select=document.createElement("select");if(c.isArray(e)){var j={};c.each(e,function(a){j[a]=a});e=j}c.each(e,function(a,b){var d=document.createElement("option");d.innerHTML=b;d.setAttribute("value",a);h.__select.appendChild(d)});this.updateDisplay();a.bind(this.__select,"change",function(){h.setValue(this.options[this.selectedIndex].value)});this.domElement.appendChild(this.__select)};
|
26
|
+
d.superclass=e;c.extend(d.prototype,e.prototype,{setValue:function(a){a=d.superclass.prototype.setValue.call(this,a);this.__onFinishChange&&this.__onFinishChange.call(this,this.getValue());return a},updateDisplay:function(){this.__select.value=this.getValue();return d.superclass.prototype.updateDisplay.call(this)}});return d}(dat.controllers.Controller,dat.dom.dom,dat.utils.common);
|
27
|
+
dat.controllers.NumberController=function(e,a){var c=function(d,f,b){c.superclass.call(this,d,f);b=b||{};this.__min=b.min;this.__max=b.max;this.__step=b.step;d=this.__impliedStep=a.isUndefined(this.__step)?this.initialValue==0?1:Math.pow(10,Math.floor(Math.log(this.initialValue)/Math.LN10))/10:this.__step;d=d.toString();this.__precision=d.indexOf(".")>-1?d.length-d.indexOf(".")-1:0};c.superclass=e;a.extend(c.prototype,e.prototype,{setValue:function(a){if(this.__min!==void 0&&a<this.__min)a=this.__min;
|
28
|
+
else if(this.__max!==void 0&&a>this.__max)a=this.__max;this.__step!==void 0&&a%this.__step!=0&&(a=Math.round(a/this.__step)*this.__step);return c.superclass.prototype.setValue.call(this,a)},min:function(a){this.__min=a;return this},max:function(a){this.__max=a;return this},step:function(a){this.__step=a;return this}});return c}(dat.controllers.Controller,dat.utils.common);
|
29
|
+
dat.controllers.NumberControllerBox=function(e,a,c){var d=function(f,b,e){function h(){var a=parseFloat(l.__input.value);c.isNaN(a)||l.setValue(a)}function j(a){var b=o-a.clientY;l.setValue(l.getValue()+b*l.__impliedStep);o=a.clientY}function m(){a.unbind(window,"mousemove",j);a.unbind(window,"mouseup",m)}this.__truncationSuspended=false;d.superclass.call(this,f,b,e);var l=this,o;this.__input=document.createElement("input");this.__input.setAttribute("type","text");a.bind(this.__input,"change",h);
|
30
|
+
a.bind(this.__input,"blur",function(){h();l.__onFinishChange&&l.__onFinishChange.call(l,l.getValue())});a.bind(this.__input,"mousedown",function(b){a.bind(window,"mousemove",j);a.bind(window,"mouseup",m);o=b.clientY});a.bind(this.__input,"keydown",function(a){if(a.keyCode===13)l.__truncationSuspended=true,this.blur(),l.__truncationSuspended=false});this.updateDisplay();this.domElement.appendChild(this.__input)};d.superclass=e;c.extend(d.prototype,e.prototype,{updateDisplay:function(){var a=this.__input,
|
31
|
+
b;if(this.__truncationSuspended)b=this.getValue();else{b=this.getValue();var c=Math.pow(10,this.__precision);b=Math.round(b*c)/c}a.value=b;return d.superclass.prototype.updateDisplay.call(this)}});return d}(dat.controllers.NumberController,dat.dom.dom,dat.utils.common);
|
32
|
+
dat.controllers.NumberControllerSlider=function(e,a,c,d,f){var b=function(d,c,f,e,l){function o(b){b.preventDefault();var d=a.getOffset(g.__background),c=a.getWidth(g.__background);g.setValue(g.__min+(g.__max-g.__min)*((b.clientX-d.left)/(d.left+c-d.left)));return false}function y(){a.unbind(window,"mousemove",o);a.unbind(window,"mouseup",y);g.__onFinishChange&&g.__onFinishChange.call(g,g.getValue())}b.superclass.call(this,d,c,{min:f,max:e,step:l});var g=this;this.__background=document.createElement("div");
|
33
|
+
this.__foreground=document.createElement("div");a.bind(this.__background,"mousedown",function(b){a.bind(window,"mousemove",o);a.bind(window,"mouseup",y);o(b)});a.addClass(this.__background,"slider");a.addClass(this.__foreground,"slider-fg");this.updateDisplay();this.__background.appendChild(this.__foreground);this.domElement.appendChild(this.__background)};b.superclass=e;b.useDefaultStyles=function(){c.inject(f)};d.extend(b.prototype,e.prototype,{updateDisplay:function(){this.__foreground.style.width=
|
34
|
+
(this.getValue()-this.__min)/(this.__max-this.__min)*100+"%";return b.superclass.prototype.updateDisplay.call(this)}});return b}(dat.controllers.NumberController,dat.dom.dom,dat.utils.css,dat.utils.common,".slider {\n box-shadow: inset 0 2px 4px rgba(0,0,0,0.15);\n height: 1em;\n border-radius: 1em;\n background-color: #eee;\n padding: 0 0.5em;\n overflow: hidden;\n}\n\n.slider-fg {\n padding: 1px 0 2px 0;\n background-color: #aaa;\n height: 1em;\n margin-left: -0.5em;\n padding-right: 0.5em;\n border-radius: 1em 0 0 1em;\n}\n\n.slider-fg:after {\n display: inline-block;\n border-radius: 1em;\n background-color: #fff;\n border: 1px solid #aaa;\n content: '';\n float: right;\n margin-right: -1em;\n margin-top: -1px;\n height: 0.9em;\n width: 0.9em;\n}");
|
35
|
+
dat.controllers.FunctionController=function(e,a,c){var d=function(c,b,e){d.superclass.call(this,c,b);var h=this;this.__button=document.createElement("div");this.__button.innerHTML=e===void 0?"Fire":e;a.bind(this.__button,"click",function(a){a.preventDefault();h.fire();return false});a.addClass(this.__button,"button");this.domElement.appendChild(this.__button)};d.superclass=e;c.extend(d.prototype,e.prototype,{fire:function(){this.__onChange&&this.__onChange.call(this);this.__onFinishChange&&this.__onFinishChange.call(this,
|
36
|
+
this.getValue());this.getValue().call(this.object)}});return d}(dat.controllers.Controller,dat.dom.dom,dat.utils.common);
|
37
|
+
dat.controllers.BooleanController=function(e,a,c){var d=function(c,b){d.superclass.call(this,c,b);var e=this;this.__prev=this.getValue();this.__checkbox=document.createElement("input");this.__checkbox.setAttribute("type","checkbox");a.bind(this.__checkbox,"change",function(){e.setValue(!e.__prev)},false);this.domElement.appendChild(this.__checkbox);this.updateDisplay()};d.superclass=e;c.extend(d.prototype,e.prototype,{setValue:function(a){a=d.superclass.prototype.setValue.call(this,a);this.__onFinishChange&&
|
38
|
+
this.__onFinishChange.call(this,this.getValue());this.__prev=this.getValue();return a},updateDisplay:function(){this.getValue()===true?(this.__checkbox.setAttribute("checked","checked"),this.__checkbox.checked=true):this.__checkbox.checked=false;return d.superclass.prototype.updateDisplay.call(this)}});return d}(dat.controllers.Controller,dat.dom.dom,dat.utils.common);
|
39
|
+
dat.color.toString=function(e){return function(a){if(a.a==1||e.isUndefined(a.a)){for(a=a.hex.toString(16);a.length<6;)a="0"+a;return"#"+a}else return"rgba("+Math.round(a.r)+","+Math.round(a.g)+","+Math.round(a.b)+","+a.a+")"}}(dat.utils.common);
|
40
|
+
dat.color.interpret=function(e,a){var c,d,f=[{litmus:a.isString,conversions:{THREE_CHAR_HEX:{read:function(a){a=a.match(/^#([A-F0-9])([A-F0-9])([A-F0-9])$/i);return a===null?false:{space:"HEX",hex:parseInt("0x"+a[1].toString()+a[1].toString()+a[2].toString()+a[2].toString()+a[3].toString()+a[3].toString())}},write:e},SIX_CHAR_HEX:{read:function(a){a=a.match(/^#([A-F0-9]{6})$/i);return a===null?false:{space:"HEX",hex:parseInt("0x"+a[1].toString())}},write:e},CSS_RGB:{read:function(a){a=a.match(/^rgb\(\s*(.+)\s*,\s*(.+)\s*,\s*(.+)\s*\)/);
|
41
|
+
return a===null?false:{space:"RGB",r:parseFloat(a[1]),g:parseFloat(a[2]),b:parseFloat(a[3])}},write:e},CSS_RGBA:{read:function(a){a=a.match(/^rgba\(\s*(.+)\s*,\s*(.+)\s*,\s*(.+)\s*\,\s*(.+)\s*\)/);return a===null?false:{space:"RGB",r:parseFloat(a[1]),g:parseFloat(a[2]),b:parseFloat(a[3]),a:parseFloat(a[4])}},write:e}}},{litmus:a.isNumber,conversions:{HEX:{read:function(a){return{space:"HEX",hex:a,conversionName:"HEX"}},write:function(a){return a.hex}}}},{litmus:a.isArray,conversions:{RGB_ARRAY:{read:function(a){return a.length!=
|
42
|
+
3?false:{space:"RGB",r:a[0],g:a[1],b:a[2]}},write:function(a){return[a.r,a.g,a.b]}},RGBA_ARRAY:{read:function(a){return a.length!=4?false:{space:"RGB",r:a[0],g:a[1],b:a[2],a:a[3]}},write:function(a){return[a.r,a.g,a.b,a.a]}}}},{litmus:a.isObject,conversions:{RGBA_OBJ:{read:function(b){return a.isNumber(b.r)&&a.isNumber(b.g)&&a.isNumber(b.b)&&a.isNumber(b.a)?{space:"RGB",r:b.r,g:b.g,b:b.b,a:b.a}:false},write:function(a){return{r:a.r,g:a.g,b:a.b,a:a.a}}},RGB_OBJ:{read:function(b){return a.isNumber(b.r)&&
|
43
|
+
a.isNumber(b.g)&&a.isNumber(b.b)?{space:"RGB",r:b.r,g:b.g,b:b.b}:false},write:function(a){return{r:a.r,g:a.g,b:a.b}}},HSVA_OBJ:{read:function(b){return a.isNumber(b.h)&&a.isNumber(b.s)&&a.isNumber(b.v)&&a.isNumber(b.a)?{space:"HSV",h:b.h,s:b.s,v:b.v,a:b.a}:false},write:function(a){return{h:a.h,s:a.s,v:a.v,a:a.a}}},HSV_OBJ:{read:function(b){return a.isNumber(b.h)&&a.isNumber(b.s)&&a.isNumber(b.v)?{space:"HSV",h:b.h,s:b.s,v:b.v}:false},write:function(a){return{h:a.h,s:a.s,v:a.v}}}}}];return function(){d=
|
44
|
+
false;var b=arguments.length>1?a.toArray(arguments):arguments[0];a.each(f,function(e){if(e.litmus(b))return a.each(e.conversions,function(e,f){c=e.read(b);if(d===false&&c!==false)return d=c,c.conversionName=f,c.conversion=e,a.BREAK}),a.BREAK});return d}}(dat.color.toString,dat.utils.common);
|
45
|
+
dat.GUI=dat.gui.GUI=function(e,a,c,d,f,b,n,h,j,m,l,o,y,g,i){function q(a,b,r,c){if(b[r]===void 0)throw Error("Object "+b+' has no property "'+r+'"');c.color?b=new l(b,r):(b=[b,r].concat(c.factoryArgs),b=d.apply(a,b));if(c.before instanceof f)c.before=c.before.__li;t(a,b);g.addClass(b.domElement,"c");r=document.createElement("span");g.addClass(r,"property-name");r.innerHTML=b.property;var e=document.createElement("div");e.appendChild(r);e.appendChild(b.domElement);c=s(a,e,c.before);g.addClass(c,k.CLASS_CONTROLLER_ROW);
|
46
|
+
g.addClass(c,typeof b.getValue());p(a,c,b);a.__controllers.push(b);return b}function s(a,b,d){var c=document.createElement("li");b&&c.appendChild(b);d?a.__ul.insertBefore(c,params.before):a.__ul.appendChild(c);a.onResize();return c}function p(a,d,c){c.__li=d;c.__gui=a;i.extend(c,{options:function(b){if(arguments.length>1)return c.remove(),q(a,c.object,c.property,{before:c.__li.nextElementSibling,factoryArgs:[i.toArray(arguments)]});if(i.isArray(b)||i.isObject(b))return c.remove(),q(a,c.object,c.property,
|
47
|
+
{before:c.__li.nextElementSibling,factoryArgs:[b]})},name:function(a){c.__li.firstElementChild.firstElementChild.innerHTML=a;return c},listen:function(){c.__gui.listen(c);return c},remove:function(){c.__gui.remove(c);return c}});if(c instanceof j){var e=new h(c.object,c.property,{min:c.__min,max:c.__max,step:c.__step});i.each(["updateDisplay","onChange","onFinishChange"],function(a){var b=c[a],H=e[a];c[a]=e[a]=function(){var a=Array.prototype.slice.call(arguments);b.apply(c,a);return H.apply(e,a)}});
|
48
|
+
g.addClass(d,"has-slider");c.domElement.insertBefore(e.domElement,c.domElement.firstElementChild)}else if(c instanceof h){var f=function(b){return i.isNumber(c.__min)&&i.isNumber(c.__max)?(c.remove(),q(a,c.object,c.property,{before:c.__li.nextElementSibling,factoryArgs:[c.__min,c.__max,c.__step]})):b};c.min=i.compose(f,c.min);c.max=i.compose(f,c.max)}else if(c instanceof b)g.bind(d,"click",function(){g.fakeEvent(c.__checkbox,"click")}),g.bind(c.__checkbox,"click",function(a){a.stopPropagation()});
|
49
|
+
else if(c instanceof n)g.bind(d,"click",function(){g.fakeEvent(c.__button,"click")}),g.bind(d,"mouseover",function(){g.addClass(c.__button,"hover")}),g.bind(d,"mouseout",function(){g.removeClass(c.__button,"hover")});else if(c instanceof l)g.addClass(d,"color"),c.updateDisplay=i.compose(function(a){d.style.borderLeftColor=c.__color.toString();return a},c.updateDisplay),c.updateDisplay();c.setValue=i.compose(function(b){a.getRoot().__preset_select&&c.isModified()&&B(a.getRoot(),true);return b},c.setValue)}
|
50
|
+
function t(a,b){var c=a.getRoot(),d=c.__rememberedObjects.indexOf(b.object);if(d!=-1){var e=c.__rememberedObjectIndecesToControllers[d];e===void 0&&(e={},c.__rememberedObjectIndecesToControllers[d]=e);e[b.property]=b;if(c.load&&c.load.remembered){c=c.load.remembered;if(c[a.preset])c=c[a.preset];else if(c[w])c=c[w];else return;if(c[d]&&c[d][b.property]!==void 0)d=c[d][b.property],b.initialValue=d,b.setValue(d)}}}function I(a){var b=a.__save_row=document.createElement("li");g.addClass(a.domElement,
|
51
|
+
"has-save");a.__ul.insertBefore(b,a.__ul.firstChild);g.addClass(b,"save-row");var c=document.createElement("span");c.innerHTML=" ";g.addClass(c,"button gears");var d=document.createElement("span");d.innerHTML="Save";g.addClass(d,"button");g.addClass(d,"save");var e=document.createElement("span");e.innerHTML="New";g.addClass(e,"button");g.addClass(e,"save-as");var f=document.createElement("span");f.innerHTML="Revert";g.addClass(f,"button");g.addClass(f,"revert");var m=a.__preset_select=document.createElement("select");
|
52
|
+
a.load&&a.load.remembered?i.each(a.load.remembered,function(b,c){C(a,c,c==a.preset)}):C(a,w,false);g.bind(m,"change",function(){for(var b=0;b<a.__preset_select.length;b++)a.__preset_select[b].innerHTML=a.__preset_select[b].value;a.preset=this.value});b.appendChild(m);b.appendChild(c);b.appendChild(d);b.appendChild(e);b.appendChild(f);if(u){var b=document.getElementById("dg-save-locally"),l=document.getElementById("dg-local-explain");b.style.display="block";b=document.getElementById("dg-local-storage");
|
53
|
+
localStorage.getItem(document.location.href+".isLocal")==="true"&&b.setAttribute("checked","checked");var o=function(){l.style.display=a.useLocalStorage?"block":"none"};o();g.bind(b,"change",function(){a.useLocalStorage=!a.useLocalStorage;o()})}var h=document.getElementById("dg-new-constructor");g.bind(h,"keydown",function(a){a.metaKey&&(a.which===67||a.keyCode==67)&&x.hide()});g.bind(c,"click",function(){h.innerHTML=JSON.stringify(a.getSaveObject(),void 0,2);x.show();h.focus();h.select()});g.bind(d,
|
54
|
+
"click",function(){a.save()});g.bind(e,"click",function(){var b=prompt("Enter a new preset name.");b&&a.saveAs(b)});g.bind(f,"click",function(){a.revert()})}function J(a){function b(f){f.preventDefault();e=f.clientX;g.addClass(a.__closeButton,k.CLASS_DRAG);g.bind(window,"mousemove",c);g.bind(window,"mouseup",d);return false}function c(b){b.preventDefault();a.width+=e-b.clientX;a.onResize();e=b.clientX;return false}function d(){g.removeClass(a.__closeButton,k.CLASS_DRAG);g.unbind(window,"mousemove",
|
55
|
+
c);g.unbind(window,"mouseup",d)}a.__resize_handle=document.createElement("div");i.extend(a.__resize_handle.style,{width:"6px",marginLeft:"-3px",height:"200px",cursor:"ew-resize",position:"absolute"});var e;g.bind(a.__resize_handle,"mousedown",b);g.bind(a.__closeButton,"mousedown",b);a.domElement.insertBefore(a.__resize_handle,a.domElement.firstElementChild)}function D(a,b){a.domElement.style.width=b+"px";if(a.__save_row&&a.autoPlace)a.__save_row.style.width=b+"px";if(a.__closeButton)a.__closeButton.style.width=
|
56
|
+
b+"px"}function z(a,b){var c={};i.each(a.__rememberedObjects,function(d,e){var f={};i.each(a.__rememberedObjectIndecesToControllers[e],function(a,c){f[c]=b?a.initialValue:a.getValue()});c[e]=f});return c}function C(a,b,c){var d=document.createElement("option");d.innerHTML=b;d.value=b;a.__preset_select.appendChild(d);if(c)a.__preset_select.selectedIndex=a.__preset_select.length-1}function B(a,b){var c=a.__preset_select[a.__preset_select.selectedIndex];c.innerHTML=b?c.value+"*":c.value}function E(a){a.length!=
|
57
|
+
0&&o(function(){E(a)});i.each(a,function(a){a.updateDisplay()})}e.inject(c);var w="Default",u;try{u="localStorage"in window&&window.localStorage!==null}catch(K){u=false}var x,F=true,v,A=false,G=[],k=function(a){function b(){localStorage.setItem(document.location.href+".gui",JSON.stringify(d.getSaveObject()))}function c(){var a=d.getRoot();a.width+=1;i.defer(function(){a.width-=1})}var d=this;this.domElement=document.createElement("div");this.__ul=document.createElement("ul");this.domElement.appendChild(this.__ul);
|
58
|
+
g.addClass(this.domElement,"dg");this.__folders={};this.__controllers=[];this.__rememberedObjects=[];this.__rememberedObjectIndecesToControllers=[];this.__listening=[];a=a||{};a=i.defaults(a,{autoPlace:true,width:k.DEFAULT_WIDTH});a=i.defaults(a,{resizable:a.autoPlace,hideable:a.autoPlace});if(i.isUndefined(a.load))a.load={preset:w};else if(a.preset)a.load.preset=a.preset;i.isUndefined(a.parent)&&a.hideable&&G.push(this);a.resizable=i.isUndefined(a.parent)&&a.resizable;if(a.autoPlace&&i.isUndefined(a.scrollable))a.scrollable=
|
59
|
+
true;var e=u&&localStorage.getItem(document.location.href+".isLocal")==="true";Object.defineProperties(this,{parent:{get:function(){return a.parent}},scrollable:{get:function(){return a.scrollable}},autoPlace:{get:function(){return a.autoPlace}},preset:{get:function(){return d.parent?d.getRoot().preset:a.load.preset},set:function(b){d.parent?d.getRoot().preset=b:a.load.preset=b;for(b=0;b<this.__preset_select.length;b++)if(this.__preset_select[b].value==this.preset)this.__preset_select.selectedIndex=
|
60
|
+
b;d.revert()}},width:{get:function(){return a.width},set:function(b){a.width=b;D(d,b)}},name:{get:function(){return a.name},set:function(b){a.name=b;if(m)m.innerHTML=a.name}},closed:{get:function(){return a.closed},set:function(b){a.closed=b;a.closed?g.addClass(d.__ul,k.CLASS_CLOSED):g.removeClass(d.__ul,k.CLASS_CLOSED);this.onResize();if(d.__closeButton)d.__closeButton.innerHTML=b?k.TEXT_OPEN:k.TEXT_CLOSED}},load:{get:function(){return a.load}},useLocalStorage:{get:function(){return e},set:function(a){u&&
|
61
|
+
((e=a)?g.bind(window,"unload",b):g.unbind(window,"unload",b),localStorage.setItem(document.location.href+".isLocal",a))}}});if(i.isUndefined(a.parent)){a.closed=false;g.addClass(this.domElement,k.CLASS_MAIN);g.makeSelectable(this.domElement,false);if(u&&e){d.useLocalStorage=true;var f=localStorage.getItem(document.location.href+".gui");if(f)a.load=JSON.parse(f)}this.__closeButton=document.createElement("div");this.__closeButton.innerHTML=k.TEXT_CLOSED;g.addClass(this.__closeButton,k.CLASS_CLOSE_BUTTON);
|
62
|
+
this.domElement.appendChild(this.__closeButton);g.bind(this.__closeButton,"click",function(){d.closed=!d.closed})}else{if(a.closed===void 0)a.closed=true;var m=document.createTextNode(a.name);g.addClass(m,"controller-name");f=s(d,m);g.addClass(this.__ul,k.CLASS_CLOSED);g.addClass(f,"title");g.bind(f,"click",function(a){a.preventDefault();d.closed=!d.closed;return false});if(!a.closed)this.closed=false}a.autoPlace&&(i.isUndefined(a.parent)&&(F&&(v=document.createElement("div"),g.addClass(v,"dg"),g.addClass(v,
|
63
|
+
k.CLASS_AUTO_PLACE_CONTAINER),document.body.appendChild(v),F=false),v.appendChild(this.domElement),g.addClass(this.domElement,k.CLASS_AUTO_PLACE)),this.parent||D(d,a.width));g.bind(window,"resize",function(){d.onResize()});g.bind(this.__ul,"webkitTransitionEnd",function(){d.onResize()});g.bind(this.__ul,"transitionend",function(){d.onResize()});g.bind(this.__ul,"oTransitionEnd",function(){d.onResize()});this.onResize();a.resizable&&J(this);d.getRoot();a.parent||c()};k.toggleHide=function(){A=!A;i.each(G,
|
64
|
+
function(a){a.domElement.style.zIndex=A?-999:999;a.domElement.style.opacity=A?0:1})};k.CLASS_AUTO_PLACE="a";k.CLASS_AUTO_PLACE_CONTAINER="ac";k.CLASS_MAIN="main";k.CLASS_CONTROLLER_ROW="cr";k.CLASS_TOO_TALL="taller-than-window";k.CLASS_CLOSED="closed";k.CLASS_CLOSE_BUTTON="close-button";k.CLASS_DRAG="drag";k.DEFAULT_WIDTH=245;k.TEXT_CLOSED="Close Controls";k.TEXT_OPEN="Open Controls";g.bind(window,"keydown",function(a){document.activeElement.type!=="text"&&(a.which===72||a.keyCode==72)&&k.toggleHide()},
|
65
|
+
false);i.extend(k.prototype,{add:function(a,b){return q(this,a,b,{factoryArgs:Array.prototype.slice.call(arguments,2)})},addColor:function(a,b){return q(this,a,b,{color:true})},remove:function(a){this.__ul.removeChild(a.__li);this.__controllers.slice(this.__controllers.indexOf(a),1);var b=this;i.defer(function(){b.onResize()})},destroy:function(){this.autoPlace&&v.removeChild(this.domElement)},addFolder:function(a){if(this.__folders[a]!==void 0)throw Error('You already have a folder in this GUI by the name "'+
|
66
|
+
a+'"');var b={name:a,parent:this};b.autoPlace=this.autoPlace;if(this.load&&this.load.folders&&this.load.folders[a])b.closed=this.load.folders[a].closed,b.load=this.load.folders[a];b=new k(b);this.__folders[a]=b;a=s(this,b.domElement);g.addClass(a,"folder");return b},open:function(){this.closed=false},close:function(){this.closed=true},onResize:function(){var a=this.getRoot();if(a.scrollable){var b=g.getOffset(a.__ul).top,c=0;i.each(a.__ul.childNodes,function(b){a.autoPlace&&b===a.__save_row||(c+=
|
67
|
+
g.getHeight(b))});window.innerHeight-b-20<c?(g.addClass(a.domElement,k.CLASS_TOO_TALL),a.__ul.style.height=window.innerHeight-b-20+"px"):(g.removeClass(a.domElement,k.CLASS_TOO_TALL),a.__ul.style.height="auto")}a.__resize_handle&&i.defer(function(){a.__resize_handle.style.height=a.__ul.offsetHeight+"px"});if(a.__closeButton)a.__closeButton.style.width=a.width+"px"},remember:function(){if(i.isUndefined(x))x=new y,x.domElement.innerHTML=a;if(this.parent)throw Error("You can only call remember on a top level GUI.");
|
68
|
+
var b=this;i.each(Array.prototype.slice.call(arguments),function(a){b.__rememberedObjects.length==0&&I(b);b.__rememberedObjects.indexOf(a)==-1&&b.__rememberedObjects.push(a)});this.autoPlace&&D(this,this.width)},getRoot:function(){for(var a=this;a.parent;)a=a.parent;return a},getSaveObject:function(){var a=this.load;a.closed=this.closed;if(this.__rememberedObjects.length>0){a.preset=this.preset;if(!a.remembered)a.remembered={};a.remembered[this.preset]=z(this)}a.folders={};i.each(this.__folders,function(b,
|
69
|
+
c){a.folders[c]=b.getSaveObject()});return a},save:function(){if(!this.load.remembered)this.load.remembered={};this.load.remembered[this.preset]=z(this);B(this,false)},saveAs:function(a){if(!this.load.remembered)this.load.remembered={},this.load.remembered[w]=z(this,true);this.load.remembered[a]=z(this);this.preset=a;C(this,a,true)},revert:function(a){i.each(this.__controllers,function(b){this.getRoot().load.remembered?t(a||this.getRoot(),b):b.setValue(b.initialValue)},this);i.each(this.__folders,
|
70
|
+
function(a){a.revert(a)});a||B(this.getRoot(),false)},listen:function(a){var b=this.__listening.length==0;this.__listening.push(a);b&&E(this.__listening)}});return k}(dat.utils.css,'<div id="dg-save" class="dg dialogue">\n\n Here\'s the new load parameter for your <code>GUI</code>\'s constructor:\n\n <textarea id="dg-new-constructor"></textarea>\n\n <div id="dg-save-locally">\n\n <input id="dg-local-storage" type="checkbox"/> Automatically save\n values to <code>localStorage</code> on exit.\n\n <div id="dg-local-explain">The values saved to <code>localStorage</code> will\n override those passed to <code>dat.GUI</code>\'s constructor. This makes it\n easier to work incrementally, but <code>localStorage</code> is fragile,\n and your friends may not see the same values you do.\n \n </div>\n \n </div>\n\n</div>',
|
71
|
+
".dg ul{list-style:none;margin:0;padding:0;width:100%;clear:both}.dg.ac{position:fixed;top:0;left:0;right:0;height:0;z-index:0}.dg:not(.ac) .main{overflow:hidden}.dg.main{-webkit-transition:opacity 0.1s linear;-o-transition:opacity 0.1s linear;-moz-transition:opacity 0.1s linear;transition:opacity 0.1s linear}.dg.main.taller-than-window{overflow-y:auto}.dg.main.taller-than-window .close-button{opacity:1;margin-top:-1px;border-top:1px solid #2c2c2c}.dg.main ul.closed .close-button{opacity:1 !important}.dg.main:hover .close-button,.dg.main .close-button.drag{opacity:1}.dg.main .close-button{-webkit-transition:opacity 0.1s linear;-o-transition:opacity 0.1s linear;-moz-transition:opacity 0.1s linear;transition:opacity 0.1s linear;border:0;position:absolute;line-height:19px;height:20px;cursor:pointer;text-align:center;background-color:#000}.dg.main .close-button:hover{background-color:#111}.dg.a{float:right;margin-right:15px;overflow-x:hidden}.dg.a.has-save ul{margin-top:27px}.dg.a.has-save ul.closed{margin-top:0}.dg.a .save-row{position:fixed;top:0;z-index:1002}.dg li{-webkit-transition:height 0.1s ease-out;-o-transition:height 0.1s ease-out;-moz-transition:height 0.1s ease-out;transition:height 0.1s ease-out}.dg li:not(.folder){cursor:auto;height:27px;line-height:27px;overflow:hidden;padding:0 4px 0 5px}.dg li.folder{padding:0;border-left:4px solid rgba(0,0,0,0)}.dg li.title{cursor:pointer;margin-left:-4px}.dg .closed li:not(.title),.dg .closed ul li,.dg .closed ul li > *{height:0;overflow:hidden;border:0}.dg .cr{clear:both;padding-left:3px;height:27px}.dg .property-name{cursor:default;float:left;clear:left;width:40%;overflow:hidden;text-overflow:ellipsis}.dg .c{float:left;width:60%}.dg .c input[type=text]{border:0;margin-top:4px;padding:3px;width:100%;float:right}.dg .has-slider input[type=text]{width:30%;margin-left:0}.dg .slider{float:left;width:66%;margin-left:-5px;margin-right:0;height:19px;margin-top:4px}.dg .slider-fg{height:100%}.dg .c input[type=checkbox]{margin-top:9px}.dg .c select{margin-top:5px}.dg .cr.function,.dg .cr.function .property-name,.dg .cr.function *,.dg .cr.boolean,.dg .cr.boolean *{cursor:pointer}.dg .selector{display:none;position:absolute;margin-left:-9px;margin-top:23px;z-index:10}.dg .c:hover .selector,.dg .selector.drag{display:block}.dg li.save-row{padding:0}.dg li.save-row .button{display:inline-block;padding:0px 6px}.dg.dialogue{background-color:#222;width:460px;padding:15px;font-size:13px;line-height:15px}#dg-new-constructor{padding:10px;color:#222;font-family:Monaco, monospace;font-size:10px;border:0;resize:none;box-shadow:inset 1px 1px 1px #888;word-wrap:break-word;margin:12px 0;display:block;width:440px;overflow-y:scroll;height:100px;position:relative}#dg-local-explain{display:none;font-size:11px;line-height:17px;border-radius:3px;background-color:#333;padding:8px;margin-top:10px}#dg-local-explain code{font-size:10px}#dat-gui-save-locally{display:none}.dg{color:#eee;font:11px 'Lucida Grande', sans-serif;text-shadow:0 -1px 0 #111}.dg.main::-webkit-scrollbar{width:5px;background:#1a1a1a}.dg.main::-webkit-scrollbar-corner{height:0;display:none}.dg.main::-webkit-scrollbar-thumb{border-radius:5px;background:#676767}.dg li:not(.folder){background:#1a1a1a;border-bottom:1px solid #2c2c2c}.dg li.save-row{line-height:25px;background:#dad5cb;border:0}.dg li.save-row select{margin-left:5px;width:108px}.dg li.save-row .button{margin-left:5px;margin-top:1px;border-radius:2px;font-size:9px;line-height:7px;padding:4px 4px 5px 4px;background:#c5bdad;color:#fff;text-shadow:0 1px 0 #b0a58f;box-shadow:0 -1px 0 #b0a58f;cursor:pointer}.dg li.save-row .button.gears{background:#c5bdad url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAsAAAANCAYAAAB/9ZQ7AAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAQJJREFUeNpiYKAU/P//PwGIC/ApCABiBSAW+I8AClAcgKxQ4T9hoMAEUrxx2QSGN6+egDX+/vWT4e7N82AMYoPAx/evwWoYoSYbACX2s7KxCxzcsezDh3evFoDEBYTEEqycggWAzA9AuUSQQgeYPa9fPv6/YWm/Acx5IPb7ty/fw+QZblw67vDs8R0YHyQhgObx+yAJkBqmG5dPPDh1aPOGR/eugW0G4vlIoTIfyFcA+QekhhHJhPdQxbiAIguMBTQZrPD7108M6roWYDFQiIAAv6Aow/1bFwXgis+f2LUAynwoIaNcz8XNx3Dl7MEJUDGQpx9gtQ8YCueB+D26OECAAQDadt7e46D42QAAAABJRU5ErkJggg==) 2px 1px no-repeat;height:7px;width:8px}.dg li.save-row .button:hover{background-color:#bab19e;box-shadow:0 -1px 0 #b0a58f}.dg li.folder{border-bottom:0}.dg li.title{padding-left:16px;background:#000 url(data:image/gif;base64,R0lGODlhBQAFAJEAAP////Pz8////////yH5BAEAAAIALAAAAAAFAAUAAAIIlI+hKgFxoCgAOw==) 6px 10px no-repeat;cursor:pointer;border-bottom:1px solid rgba(255,255,255,0.2)}.dg .closed li.title{background-image:url(data:image/gif;base64,R0lGODlhBQAFAJEAAP////Pz8////////yH5BAEAAAIALAAAAAAFAAUAAAIIlGIWqMCbWAEAOw==)}.dg .cr.boolean{border-left:3px solid #806787}.dg .cr.function{border-left:3px solid #e61d5f}.dg .cr.number{border-left:3px solid #2fa1d6}.dg .cr.number input[type=text]{color:#2fa1d6}.dg .cr.string{border-left:3px solid #1ed36f}.dg .cr.string input[type=text]{color:#1ed36f}.dg .cr.function:hover,.dg .cr.boolean:hover{background:#111}.dg .c input[type=text]{background:#303030;outline:none}.dg .c input[type=text]:hover{background:#3c3c3c}.dg .c input[type=text]:focus{background:#494949;color:#fff}.dg .c .slider{background:#303030;cursor:ew-resize}.dg .c .slider-fg{background:#2fa1d6}.dg .c .slider:hover{background:#3c3c3c}.dg .c .slider:hover .slider-fg{background:#44abda}\n",
|
72
|
+
dat.controllers.factory=function(e,a,c,d,f,b,n){return function(h,j,m,l){var o=h[j];if(n.isArray(m)||n.isObject(m))return new e(h,j,m);if(n.isNumber(o))return n.isNumber(m)&&n.isNumber(l)?new c(h,j,m,l):new a(h,j,{min:m,max:l});if(n.isString(o))return new d(h,j);if(n.isFunction(o))return new f(h,j,"");if(n.isBoolean(o))return new b(h,j)}}(dat.controllers.OptionController,dat.controllers.NumberControllerBox,dat.controllers.NumberControllerSlider,dat.controllers.StringController=function(e,a,c){var d=
|
73
|
+
function(c,b){function e(){h.setValue(h.__input.value)}d.superclass.call(this,c,b);var h=this;this.__input=document.createElement("input");this.__input.setAttribute("type","text");a.bind(this.__input,"keyup",e);a.bind(this.__input,"change",e);a.bind(this.__input,"blur",function(){h.__onFinishChange&&h.__onFinishChange.call(h,h.getValue())});a.bind(this.__input,"keydown",function(a){a.keyCode===13&&this.blur()});this.updateDisplay();this.domElement.appendChild(this.__input)};d.superclass=e;c.extend(d.prototype,
|
74
|
+
e.prototype,{updateDisplay:function(){if(!a.isActive(this.__input))this.__input.value=this.getValue();return d.superclass.prototype.updateDisplay.call(this)}});return d}(dat.controllers.Controller,dat.dom.dom,dat.utils.common),dat.controllers.FunctionController,dat.controllers.BooleanController,dat.utils.common),dat.controllers.Controller,dat.controllers.BooleanController,dat.controllers.FunctionController,dat.controllers.NumberControllerBox,dat.controllers.NumberControllerSlider,dat.controllers.OptionController,
|
75
|
+
dat.controllers.ColorController=function(e,a,c,d,f){function b(a,b,c,d){a.style.background="";f.each(j,function(e){a.style.cssText+="background: "+e+"linear-gradient("+b+", "+c+" 0%, "+d+" 100%); "})}function n(a){a.style.background="";a.style.cssText+="background: -moz-linear-gradient(top, #ff0000 0%, #ff00ff 17%, #0000ff 34%, #00ffff 50%, #00ff00 67%, #ffff00 84%, #ff0000 100%);";a.style.cssText+="background: -webkit-linear-gradient(top, #ff0000 0%,#ff00ff 17%,#0000ff 34%,#00ffff 50%,#00ff00 67%,#ffff00 84%,#ff0000 100%);";
|
76
|
+
a.style.cssText+="background: -o-linear-gradient(top, #ff0000 0%,#ff00ff 17%,#0000ff 34%,#00ffff 50%,#00ff00 67%,#ffff00 84%,#ff0000 100%);";a.style.cssText+="background: -ms-linear-gradient(top, #ff0000 0%,#ff00ff 17%,#0000ff 34%,#00ffff 50%,#00ff00 67%,#ffff00 84%,#ff0000 100%);";a.style.cssText+="background: linear-gradient(top, #ff0000 0%,#ff00ff 17%,#0000ff 34%,#00ffff 50%,#00ff00 67%,#ffff00 84%,#ff0000 100%);"}var h=function(e,l){function o(b){q(b);a.bind(window,"mousemove",q);a.bind(window,
|
77
|
+
"mouseup",j)}function j(){a.unbind(window,"mousemove",q);a.unbind(window,"mouseup",j)}function g(){var a=d(this.value);a!==false?(p.__color.__state=a,p.setValue(p.__color.toOriginal())):this.value=p.__color.toString()}function i(){a.unbind(window,"mousemove",s);a.unbind(window,"mouseup",i)}function q(b){b.preventDefault();var c=a.getWidth(p.__saturation_field),d=a.getOffset(p.__saturation_field),e=(b.clientX-d.left+document.body.scrollLeft)/c,b=1-(b.clientY-d.top+document.body.scrollTop)/c;b>1?b=
|
78
|
+
1:b<0&&(b=0);e>1?e=1:e<0&&(e=0);p.__color.v=b;p.__color.s=e;p.setValue(p.__color.toOriginal());return false}function s(b){b.preventDefault();var c=a.getHeight(p.__hue_field),d=a.getOffset(p.__hue_field),b=1-(b.clientY-d.top+document.body.scrollTop)/c;b>1?b=1:b<0&&(b=0);p.__color.h=b*360;p.setValue(p.__color.toOriginal());return false}h.superclass.call(this,e,l);this.__color=new c(this.getValue());this.__temp=new c(0);var p=this;this.domElement=document.createElement("div");a.makeSelectable(this.domElement,
|
79
|
+
false);this.__selector=document.createElement("div");this.__selector.className="selector";this.__saturation_field=document.createElement("div");this.__saturation_field.className="saturation-field";this.__field_knob=document.createElement("div");this.__field_knob.className="field-knob";this.__field_knob_border="2px solid ";this.__hue_knob=document.createElement("div");this.__hue_knob.className="hue-knob";this.__hue_field=document.createElement("div");this.__hue_field.className="hue-field";this.__input=
|
80
|
+
document.createElement("input");this.__input.type="text";this.__input_textShadow="0 1px 1px ";a.bind(this.__input,"keydown",function(a){a.keyCode===13&&g.call(this)});a.bind(this.__input,"blur",g);a.bind(this.__selector,"mousedown",function(){a.addClass(this,"drag").bind(window,"mouseup",function(){a.removeClass(p.__selector,"drag")})});var t=document.createElement("div");f.extend(this.__selector.style,{width:"122px",height:"102px",padding:"3px",backgroundColor:"#222",boxShadow:"0px 1px 3px rgba(0,0,0,0.3)"});
|
81
|
+
f.extend(this.__field_knob.style,{position:"absolute",width:"12px",height:"12px",border:this.__field_knob_border+(this.__color.v<0.5?"#fff":"#000"),boxShadow:"0px 1px 3px rgba(0,0,0,0.5)",borderRadius:"12px",zIndex:1});f.extend(this.__hue_knob.style,{position:"absolute",width:"15px",height:"2px",borderRight:"4px solid #fff",zIndex:1});f.extend(this.__saturation_field.style,{width:"100px",height:"100px",border:"1px solid #555",marginRight:"3px",display:"inline-block",cursor:"pointer"});f.extend(t.style,
|
82
|
+
{width:"100%",height:"100%",background:"none"});b(t,"top","rgba(0,0,0,0)","#000");f.extend(this.__hue_field.style,{width:"15px",height:"100px",display:"inline-block",border:"1px solid #555",cursor:"ns-resize"});n(this.__hue_field);f.extend(this.__input.style,{outline:"none",textAlign:"center",color:"#fff",border:0,fontWeight:"bold",textShadow:this.__input_textShadow+"rgba(0,0,0,0.7)"});a.bind(this.__saturation_field,"mousedown",o);a.bind(this.__field_knob,"mousedown",o);a.bind(this.__hue_field,"mousedown",
|
83
|
+
function(b){s(b);a.bind(window,"mousemove",s);a.bind(window,"mouseup",i)});this.__saturation_field.appendChild(t);this.__selector.appendChild(this.__field_knob);this.__selector.appendChild(this.__saturation_field);this.__selector.appendChild(this.__hue_field);this.__hue_field.appendChild(this.__hue_knob);this.domElement.appendChild(this.__input);this.domElement.appendChild(this.__selector);this.updateDisplay()};h.superclass=e;f.extend(h.prototype,e.prototype,{updateDisplay:function(){var a=d(this.getValue());
|
84
|
+
if(a!==false){var e=false;f.each(c.COMPONENTS,function(b){if(!f.isUndefined(a[b])&&!f.isUndefined(this.__color.__state[b])&&a[b]!==this.__color.__state[b])return e=true,{}},this);e&&f.extend(this.__color.__state,a)}f.extend(this.__temp.__state,this.__color.__state);this.__temp.a=1;var h=this.__color.v<0.5||this.__color.s>0.5?255:0,j=255-h;f.extend(this.__field_knob.style,{marginLeft:100*this.__color.s-7+"px",marginTop:100*(1-this.__color.v)-7+"px",backgroundColor:this.__temp.toString(),border:this.__field_knob_border+
|
85
|
+
"rgb("+h+","+h+","+h+")"});this.__hue_knob.style.marginTop=(1-this.__color.h/360)*100+"px";this.__temp.s=1;this.__temp.v=1;b(this.__saturation_field,"left","#fff",this.__temp.toString());f.extend(this.__input.style,{backgroundColor:this.__input.value=this.__color.toString(),color:"rgb("+h+","+h+","+h+")",textShadow:this.__input_textShadow+"rgba("+j+","+j+","+j+",.7)"})}});var j=["-moz-","-o-","-webkit-","-ms-",""];return h}(dat.controllers.Controller,dat.dom.dom,dat.color.Color=function(e,a,c,d){function f(a,
|
86
|
+
b,c){Object.defineProperty(a,b,{get:function(){if(this.__state.space==="RGB")return this.__state[b];n(this,b,c);return this.__state[b]},set:function(a){if(this.__state.space!=="RGB")n(this,b,c),this.__state.space="RGB";this.__state[b]=a}})}function b(a,b){Object.defineProperty(a,b,{get:function(){if(this.__state.space==="HSV")return this.__state[b];h(this);return this.__state[b]},set:function(a){if(this.__state.space!=="HSV")h(this),this.__state.space="HSV";this.__state[b]=a}})}function n(b,c,e){if(b.__state.space===
|
87
|
+
"HEX")b.__state[c]=a.component_from_hex(b.__state.hex,e);else if(b.__state.space==="HSV")d.extend(b.__state,a.hsv_to_rgb(b.__state.h,b.__state.s,b.__state.v));else throw"Corrupted color state";}function h(b){var c=a.rgb_to_hsv(b.r,b.g,b.b);d.extend(b.__state,{s:c.s,v:c.v});if(d.isNaN(c.h)){if(d.isUndefined(b.__state.h))b.__state.h=0}else b.__state.h=c.h}var j=function(){this.__state=e.apply(this,arguments);if(this.__state===false)throw"Failed to interpret color arguments";this.__state.a=this.__state.a||
|
88
|
+
1};j.COMPONENTS="r,g,b,h,s,v,hex,a".split(",");d.extend(j.prototype,{toString:function(){return c(this)},toOriginal:function(){return this.__state.conversion.write(this)}});f(j.prototype,"r",2);f(j.prototype,"g",1);f(j.prototype,"b",0);b(j.prototype,"h");b(j.prototype,"s");b(j.prototype,"v");Object.defineProperty(j.prototype,"a",{get:function(){return this.__state.a},set:function(a){this.__state.a=a}});Object.defineProperty(j.prototype,"hex",{get:function(){if(!this.__state.space!=="HEX")this.__state.hex=
|
89
|
+
a.rgb_to_hex(this.r,this.g,this.b);return this.__state.hex},set:function(a){this.__state.space="HEX";this.__state.hex=a}});return j}(dat.color.interpret,dat.color.math=function(){var e;return{hsv_to_rgb:function(a,c,d){var e=a/60-Math.floor(a/60),b=d*(1-c),n=d*(1-e*c),c=d*(1-(1-e)*c),a=[[d,c,b],[n,d,b],[b,d,c],[b,n,d],[c,b,d],[d,b,n]][Math.floor(a/60)%6];return{r:a[0]*255,g:a[1]*255,b:a[2]*255}},rgb_to_hsv:function(a,c,d){var e=Math.min(a,c,d),b=Math.max(a,c,d),e=b-e;if(b==0)return{h:NaN,s:0,v:0};
|
90
|
+
a=a==b?(c-d)/e:c==b?2+(d-a)/e:4+(a-c)/e;a/=6;a<0&&(a+=1);return{h:a*360,s:e/b,v:b/255}},rgb_to_hex:function(a,c,d){a=this.hex_with_component(0,2,a);a=this.hex_with_component(a,1,c);return a=this.hex_with_component(a,0,d)},component_from_hex:function(a,c){return a>>c*8&255},hex_with_component:function(a,c,d){return d<<(e=c*8)|a&~(255<<e)}}}(),dat.color.toString,dat.utils.common),dat.color.interpret,dat.utils.common),dat.utils.requestAnimationFrame=function(){return window.webkitRequestAnimationFrame||
|
91
|
+
window.mozRequestAnimationFrame||window.oRequestAnimationFrame||window.msRequestAnimationFrame||function(e){window.setTimeout(e,1E3/60)}}(),dat.dom.CenteredDiv=function(e,a){var c=function(){this.backgroundElement=document.createElement("div");a.extend(this.backgroundElement.style,{backgroundColor:"rgba(0,0,0,0.8)",top:0,left:0,display:"none",zIndex:"1000",opacity:0,WebkitTransition:"opacity 0.2s linear"});e.makeFullscreen(this.backgroundElement);this.backgroundElement.style.position="fixed";this.domElement=
|
92
|
+
document.createElement("div");a.extend(this.domElement.style,{position:"fixed",display:"none",zIndex:"1001",opacity:0,WebkitTransition:"-webkit-transform 0.2s ease-out, opacity 0.2s linear"});document.body.appendChild(this.backgroundElement);document.body.appendChild(this.domElement);var c=this;e.bind(this.backgroundElement,"click",function(){c.hide()})};c.prototype.show=function(){var c=this;this.backgroundElement.style.display="block";this.domElement.style.display="block";this.domElement.style.opacity=
|
93
|
+
0;this.domElement.style.webkitTransform="scale(1.1)";this.layout();a.defer(function(){c.backgroundElement.style.opacity=1;c.domElement.style.opacity=1;c.domElement.style.webkitTransform="scale(1)"})};c.prototype.hide=function(){var a=this,c=function(){a.domElement.style.display="none";a.backgroundElement.style.display="none";e.unbind(a.domElement,"webkitTransitionEnd",c);e.unbind(a.domElement,"transitionend",c);e.unbind(a.domElement,"oTransitionEnd",c)};e.bind(this.domElement,"webkitTransitionEnd",
|
94
|
+
c);e.bind(this.domElement,"transitionend",c);e.bind(this.domElement,"oTransitionEnd",c);this.backgroundElement.style.opacity=0;this.domElement.style.opacity=0;this.domElement.style.webkitTransform="scale(1.1)"};c.prototype.layout=function(){this.domElement.style.left=window.innerWidth/2-e.getWidth(this.domElement)/2+"px";this.domElement.style.top=window.innerHeight/2-e.getHeight(this.domElement)/2+"px"};return c}(dat.dom.dom,dat.utils.common),dat.dom.dom,dat.utils.common);
|
@@ -0,0 +1,28 @@
|
|
1
|
+
/**
|
2
|
+
* @fileoverview gl-matrix - High performance matrix and vector operations
|
3
|
+
* @author Brandon Jones
|
4
|
+
* @author Colin MacKenzie IV
|
5
|
+
* @version 2.2.0
|
6
|
+
*/
|
7
|
+
/* Copyright (c) 2013, Brandon Jones, Colin MacKenzie IV. All rights reserved.
|
8
|
+
|
9
|
+
Redistribution and use in source and binary forms, with or without modification,
|
10
|
+
are permitted provided that the following conditions are met:
|
11
|
+
|
12
|
+
* Redistributions of source code must retain the above copyright notice, this
|
13
|
+
list of conditions and the following disclaimer.
|
14
|
+
* Redistributions in binary form must reproduce the above copyright notice,
|
15
|
+
this list of conditions and the following disclaimer in the documentation
|
16
|
+
and/or other materials provided with the distribution.
|
17
|
+
|
18
|
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
19
|
+
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
20
|
+
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
21
|
+
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
|
22
|
+
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
23
|
+
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
24
|
+
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
25
|
+
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
26
|
+
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
27
|
+
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */
|
28
|
+
(function(e){"use strict";var t={};typeof exports=="undefined"?typeof define=="function"&&typeof define.amd=="object"&&define.amd?(t.exports={},define(function(){return t.exports})):t.exports=typeof window!="undefined"?window:e:t.exports=exports,function(e){if(!t)var t=1e-6;if(!n)var n=typeof Float32Array!="undefined"?Float32Array:Array;if(!r)var r=Math.random;var i={};i.setMatrixArrayType=function(e){n=e},typeof e!="undefined"&&(e.glMatrix=i);var s={};s.create=function(){var e=new n(2);return e[0]=0,e[1]=0,e},s.clone=function(e){var t=new n(2);return t[0]=e[0],t[1]=e[1],t},s.fromValues=function(e,t){var r=new n(2);return r[0]=e,r[1]=t,r},s.copy=function(e,t){return e[0]=t[0],e[1]=t[1],e},s.set=function(e,t,n){return e[0]=t,e[1]=n,e},s.add=function(e,t,n){return e[0]=t[0]+n[0],e[1]=t[1]+n[1],e},s.subtract=function(e,t,n){return e[0]=t[0]-n[0],e[1]=t[1]-n[1],e},s.sub=s.subtract,s.multiply=function(e,t,n){return e[0]=t[0]*n[0],e[1]=t[1]*n[1],e},s.mul=s.multiply,s.divide=function(e,t,n){return e[0]=t[0]/n[0],e[1]=t[1]/n[1],e},s.div=s.divide,s.min=function(e,t,n){return e[0]=Math.min(t[0],n[0]),e[1]=Math.min(t[1],n[1]),e},s.max=function(e,t,n){return e[0]=Math.max(t[0],n[0]),e[1]=Math.max(t[1],n[1]),e},s.scale=function(e,t,n){return e[0]=t[0]*n,e[1]=t[1]*n,e},s.scaleAndAdd=function(e,t,n,r){return e[0]=t[0]+n[0]*r,e[1]=t[1]+n[1]*r,e},s.distance=function(e,t){var n=t[0]-e[0],r=t[1]-e[1];return Math.sqrt(n*n+r*r)},s.dist=s.distance,s.squaredDistance=function(e,t){var n=t[0]-e[0],r=t[1]-e[1];return n*n+r*r},s.sqrDist=s.squaredDistance,s.length=function(e){var t=e[0],n=e[1];return Math.sqrt(t*t+n*n)},s.len=s.length,s.squaredLength=function(e){var t=e[0],n=e[1];return t*t+n*n},s.sqrLen=s.squaredLength,s.negate=function(e,t){return e[0]=-t[0],e[1]=-t[1],e},s.normalize=function(e,t){var n=t[0],r=t[1],i=n*n+r*r;return i>0&&(i=1/Math.sqrt(i),e[0]=t[0]*i,e[1]=t[1]*i),e},s.dot=function(e,t){return e[0]*t[0]+e[1]*t[1]},s.cross=function(e,t,n){var r=t[0]*n[1]-t[1]*n[0];return e[0]=e[1]=0,e[2]=r,e},s.lerp=function(e,t,n,r){var i=t[0],s=t[1];return e[0]=i+r*(n[0]-i),e[1]=s+r*(n[1]-s),e},s.random=function(e,t){t=t||1;var n=r()*2*Math.PI;return e[0]=Math.cos(n)*t,e[1]=Math.sin(n)*t,e},s.transformMat2=function(e,t,n){var r=t[0],i=t[1];return e[0]=n[0]*r+n[2]*i,e[1]=n[1]*r+n[3]*i,e},s.transformMat2d=function(e,t,n){var r=t[0],i=t[1];return e[0]=n[0]*r+n[2]*i+n[4],e[1]=n[1]*r+n[3]*i+n[5],e},s.transformMat3=function(e,t,n){var r=t[0],i=t[1];return e[0]=n[0]*r+n[3]*i+n[6],e[1]=n[1]*r+n[4]*i+n[7],e},s.transformMat4=function(e,t,n){var r=t[0],i=t[1];return e[0]=n[0]*r+n[4]*i+n[12],e[1]=n[1]*r+n[5]*i+n[13],e},s.forEach=function(){var e=s.create();return function(t,n,r,i,s,o){var u,a;n||(n=2),r||(r=0),i?a=Math.min(i*n+r,t.length):a=t.length;for(u=r;u<a;u+=n)e[0]=t[u],e[1]=t[u+1],s(e,e,o),t[u]=e[0],t[u+1]=e[1];return t}}(),s.str=function(e){return"vec2("+e[0]+", "+e[1]+")"},typeof e!="undefined"&&(e.vec2=s);var o={};o.create=function(){var e=new n(3);return e[0]=0,e[1]=0,e[2]=0,e},o.clone=function(e){var t=new n(3);return t[0]=e[0],t[1]=e[1],t[2]=e[2],t},o.fromValues=function(e,t,r){var i=new n(3);return i[0]=e,i[1]=t,i[2]=r,i},o.copy=function(e,t){return e[0]=t[0],e[1]=t[1],e[2]=t[2],e},o.set=function(e,t,n,r){return e[0]=t,e[1]=n,e[2]=r,e},o.add=function(e,t,n){return e[0]=t[0]+n[0],e[1]=t[1]+n[1],e[2]=t[2]+n[2],e},o.subtract=function(e,t,n){return e[0]=t[0]-n[0],e[1]=t[1]-n[1],e[2]=t[2]-n[2],e},o.sub=o.subtract,o.multiply=function(e,t,n){return e[0]=t[0]*n[0],e[1]=t[1]*n[1],e[2]=t[2]*n[2],e},o.mul=o.multiply,o.divide=function(e,t,n){return e[0]=t[0]/n[0],e[1]=t[1]/n[1],e[2]=t[2]/n[2],e},o.div=o.divide,o.min=function(e,t,n){return e[0]=Math.min(t[0],n[0]),e[1]=Math.min(t[1],n[1]),e[2]=Math.min(t[2],n[2]),e},o.max=function(e,t,n){return e[0]=Math.max(t[0],n[0]),e[1]=Math.max(t[1],n[1]),e[2]=Math.max(t[2],n[2]),e},o.scale=function(e,t,n){return e[0]=t[0]*n,e[1]=t[1]*n,e[2]=t[2]*n,e},o.scaleAndAdd=function(e,t,n,r){return e[0]=t[0]+n[0]*r,e[1]=t[1]+n[1]*r,e[2]=t[2]+n[2]*r,e},o.distance=function(e,t){var n=t[0]-e[0],r=t[1]-e[1],i=t[2]-e[2];return Math.sqrt(n*n+r*r+i*i)},o.dist=o.distance,o.squaredDistance=function(e,t){var n=t[0]-e[0],r=t[1]-e[1],i=t[2]-e[2];return n*n+r*r+i*i},o.sqrDist=o.squaredDistance,o.length=function(e){var t=e[0],n=e[1],r=e[2];return Math.sqrt(t*t+n*n+r*r)},o.len=o.length,o.squaredLength=function(e){var t=e[0],n=e[1],r=e[2];return t*t+n*n+r*r},o.sqrLen=o.squaredLength,o.negate=function(e,t){return e[0]=-t[0],e[1]=-t[1],e[2]=-t[2],e},o.normalize=function(e,t){var n=t[0],r=t[1],i=t[2],s=n*n+r*r+i*i;return s>0&&(s=1/Math.sqrt(s),e[0]=t[0]*s,e[1]=t[1]*s,e[2]=t[2]*s),e},o.dot=function(e,t){return e[0]*t[0]+e[1]*t[1]+e[2]*t[2]},o.cross=function(e,t,n){var r=t[0],i=t[1],s=t[2],o=n[0],u=n[1],a=n[2];return e[0]=i*a-s*u,e[1]=s*o-r*a,e[2]=r*u-i*o,e},o.lerp=function(e,t,n,r){var i=t[0],s=t[1],o=t[2];return e[0]=i+r*(n[0]-i),e[1]=s+r*(n[1]-s),e[2]=o+r*(n[2]-o),e},o.random=function(e,t){t=t||1;var n=r()*2*Math.PI,i=r()*2-1,s=Math.sqrt(1-i*i)*t;return e[0]=Math.cos(n)*s,e[1]=Math.sin(n)*s,e[2]=i*t,e},o.transformMat4=function(e,t,n){var r=t[0],i=t[1],s=t[2];return e[0]=n[0]*r+n[4]*i+n[8]*s+n[12],e[1]=n[1]*r+n[5]*i+n[9]*s+n[13],e[2]=n[2]*r+n[6]*i+n[10]*s+n[14],e},o.transformMat3=function(e,t,n){var r=t[0],i=t[1],s=t[2];return e[0]=r*n[0]+i*n[3]+s*n[6],e[1]=r*n[1]+i*n[4]+s*n[7],e[2]=r*n[2]+i*n[5]+s*n[8],e},o.transformQuat=function(e,t,n){var r=t[0],i=t[1],s=t[2],o=n[0],u=n[1],a=n[2],f=n[3],l=f*r+u*s-a*i,c=f*i+a*r-o*s,h=f*s+o*i-u*r,p=-o*r-u*i-a*s;return e[0]=l*f+p*-o+c*-a-h*-u,e[1]=c*f+p*-u+h*-o-l*-a,e[2]=h*f+p*-a+l*-u-c*-o,e},o.forEach=function(){var e=o.create();return function(t,n,r,i,s,o){var u,a;n||(n=3),r||(r=0),i?a=Math.min(i*n+r,t.length):a=t.length;for(u=r;u<a;u+=n)e[0]=t[u],e[1]=t[u+1],e[2]=t[u+2],s(e,e,o),t[u]=e[0],t[u+1]=e[1],t[u+2]=e[2];return t}}(),o.str=function(e){return"vec3("+e[0]+", "+e[1]+", "+e[2]+")"},typeof e!="undefined"&&(e.vec3=o);var u={};u.create=function(){var e=new n(4);return e[0]=0,e[1]=0,e[2]=0,e[3]=0,e},u.clone=function(e){var t=new n(4);return t[0]=e[0],t[1]=e[1],t[2]=e[2],t[3]=e[3],t},u.fromValues=function(e,t,r,i){var s=new n(4);return s[0]=e,s[1]=t,s[2]=r,s[3]=i,s},u.copy=function(e,t){return e[0]=t[0],e[1]=t[1],e[2]=t[2],e[3]=t[3],e},u.set=function(e,t,n,r,i){return e[0]=t,e[1]=n,e[2]=r,e[3]=i,e},u.add=function(e,t,n){return e[0]=t[0]+n[0],e[1]=t[1]+n[1],e[2]=t[2]+n[2],e[3]=t[3]+n[3],e},u.subtract=function(e,t,n){return e[0]=t[0]-n[0],e[1]=t[1]-n[1],e[2]=t[2]-n[2],e[3]=t[3]-n[3],e},u.sub=u.subtract,u.multiply=function(e,t,n){return e[0]=t[0]*n[0],e[1]=t[1]*n[1],e[2]=t[2]*n[2],e[3]=t[3]*n[3],e},u.mul=u.multiply,u.divide=function(e,t,n){return e[0]=t[0]/n[0],e[1]=t[1]/n[1],e[2]=t[2]/n[2],e[3]=t[3]/n[3],e},u.div=u.divide,u.min=function(e,t,n){return e[0]=Math.min(t[0],n[0]),e[1]=Math.min(t[1],n[1]),e[2]=Math.min(t[2],n[2]),e[3]=Math.min(t[3],n[3]),e},u.max=function(e,t,n){return e[0]=Math.max(t[0],n[0]),e[1]=Math.max(t[1],n[1]),e[2]=Math.max(t[2],n[2]),e[3]=Math.max(t[3],n[3]),e},u.scale=function(e,t,n){return e[0]=t[0]*n,e[1]=t[1]*n,e[2]=t[2]*n,e[3]=t[3]*n,e},u.scaleAndAdd=function(e,t,n,r){return e[0]=t[0]+n[0]*r,e[1]=t[1]+n[1]*r,e[2]=t[2]+n[2]*r,e[3]=t[3]+n[3]*r,e},u.distance=function(e,t){var n=t[0]-e[0],r=t[1]-e[1],i=t[2]-e[2],s=t[3]-e[3];return Math.sqrt(n*n+r*r+i*i+s*s)},u.dist=u.distance,u.squaredDistance=function(e,t){var n=t[0]-e[0],r=t[1]-e[1],i=t[2]-e[2],s=t[3]-e[3];return n*n+r*r+i*i+s*s},u.sqrDist=u.squaredDistance,u.length=function(e){var t=e[0],n=e[1],r=e[2],i=e[3];return Math.sqrt(t*t+n*n+r*r+i*i)},u.len=u.length,u.squaredLength=function(e){var t=e[0],n=e[1],r=e[2],i=e[3];return t*t+n*n+r*r+i*i},u.sqrLen=u.squaredLength,u.negate=function(e,t){return e[0]=-t[0],e[1]=-t[1],e[2]=-t[2],e[3]=-t[3],e},u.normalize=function(e,t){var n=t[0],r=t[1],i=t[2],s=t[3],o=n*n+r*r+i*i+s*s;return o>0&&(o=1/Math.sqrt(o),e[0]=t[0]*o,e[1]=t[1]*o,e[2]=t[2]*o,e[3]=t[3]*o),e},u.dot=function(e,t){return e[0]*t[0]+e[1]*t[1]+e[2]*t[2]+e[3]*t[3]},u.lerp=function(e,t,n,r){var i=t[0],s=t[1],o=t[2],u=t[3];return e[0]=i+r*(n[0]-i),e[1]=s+r*(n[1]-s),e[2]=o+r*(n[2]-o),e[3]=u+r*(n[3]-u),e},u.random=function(e,t){return t=t||1,e[0]=r(),e[1]=r(),e[2]=r(),e[3]=r(),u.normalize(e,e),u.scale(e,e,t),e},u.transformMat4=function(e,t,n){var r=t[0],i=t[1],s=t[2],o=t[3];return e[0]=n[0]*r+n[4]*i+n[8]*s+n[12]*o,e[1]=n[1]*r+n[5]*i+n[9]*s+n[13]*o,e[2]=n[2]*r+n[6]*i+n[10]*s+n[14]*o,e[3]=n[3]*r+n[7]*i+n[11]*s+n[15]*o,e},u.transformQuat=function(e,t,n){var r=t[0],i=t[1],s=t[2],o=n[0],u=n[1],a=n[2],f=n[3],l=f*r+u*s-a*i,c=f*i+a*r-o*s,h=f*s+o*i-u*r,p=-o*r-u*i-a*s;return e[0]=l*f+p*-o+c*-a-h*-u,e[1]=c*f+p*-u+h*-o-l*-a,e[2]=h*f+p*-a+l*-u-c*-o,e},u.forEach=function(){var e=u.create();return function(t,n,r,i,s,o){var u,a;n||(n=4),r||(r=0),i?a=Math.min(i*n+r,t.length):a=t.length;for(u=r;u<a;u+=n)e[0]=t[u],e[1]=t[u+1],e[2]=t[u+2],e[3]=t[u+3],s(e,e,o),t[u]=e[0],t[u+1]=e[1],t[u+2]=e[2],t[u+3]=e[3];return t}}(),u.str=function(e){return"vec4("+e[0]+", "+e[1]+", "+e[2]+", "+e[3]+")"},typeof e!="undefined"&&(e.vec4=u);var a={};a.create=function(){var e=new n(4);return e[0]=1,e[1]=0,e[2]=0,e[3]=1,e},a.clone=function(e){var t=new n(4);return t[0]=e[0],t[1]=e[1],t[2]=e[2],t[3]=e[3],t},a.copy=function(e,t){return e[0]=t[0],e[1]=t[1],e[2]=t[2],e[3]=t[3],e},a.identity=function(e){return e[0]=1,e[1]=0,e[2]=0,e[3]=1,e},a.transpose=function(e,t){if(e===t){var n=t[1];e[1]=t[2],e[2]=n}else e[0]=t[0],e[1]=t[2],e[2]=t[1],e[3]=t[3];return e},a.invert=function(e,t){var n=t[0],r=t[1],i=t[2],s=t[3],o=n*s-i*r;return o?(o=1/o,e[0]=s*o,e[1]=-r*o,e[2]=-i*o,e[3]=n*o,e):null},a.adjoint=function(e,t){var n=t[0];return e[0]=t[3],e[1]=-t[1],e[2]=-t[2],e[3]=n,e},a.determinant=function(e){return e[0]*e[3]-e[2]*e[1]},a.multiply=function(e,t,n){var r=t[0],i=t[1],s=t[2],o=t[3],u=n[0],a=n[1],f=n[2],l=n[3];return e[0]=r*u+i*f,e[1]=r*a+i*l,e[2]=s*u+o*f,e[3]=s*a+o*l,e},a.mul=a.multiply,a.rotate=function(e,t,n){var r=t[0],i=t[1],s=t[2],o=t[3],u=Math.sin(n),a=Math.cos(n);return e[0]=r*a+i*u,e[1]=r*-u+i*a,e[2]=s*a+o*u,e[3]=s*-u+o*a,e},a.scale=function(e,t,n){var r=t[0],i=t[1],s=t[2],o=t[3],u=n[0],a=n[1];return e[0]=r*u,e[1]=i*a,e[2]=s*u,e[3]=o*a,e},a.str=function(e){return"mat2("+e[0]+", "+e[1]+", "+e[2]+", "+e[3]+")"},typeof e!="undefined"&&(e.mat2=a);var f={};f.create=function(){var e=new n(6);return e[0]=1,e[1]=0,e[2]=0,e[3]=1,e[4]=0,e[5]=0,e},f.clone=function(e){var t=new n(6);return t[0]=e[0],t[1]=e[1],t[2]=e[2],t[3]=e[3],t[4]=e[4],t[5]=e[5],t},f.copy=function(e,t){return e[0]=t[0],e[1]=t[1],e[2]=t[2],e[3]=t[3],e[4]=t[4],e[5]=t[5],e},f.identity=function(e){return e[0]=1,e[1]=0,e[2]=0,e[3]=1,e[4]=0,e[5]=0,e},f.invert=function(e,t){var n=t[0],r=t[1],i=t[2],s=t[3],o=t[4],u=t[5],a=n*s-r*i;return a?(a=1/a,e[0]=s*a,e[1]=-r*a,e[2]=-i*a,e[3]=n*a,e[4]=(i*u-s*o)*a,e[5]=(r*o-n*u)*a,e):null},f.determinant=function(e){return e[0]*e[3]-e[1]*e[2]},f.multiply=function(e,t,n){var r=t[0],i=t[1],s=t[2],o=t[3],u=t[4],a=t[5],f=n[0],l=n[1],c=n[2],h=n[3],p=n[4],d=n[5];return e[0]=r*f+i*c,e[1]=r*l+i*h,e[2]=s*f+o*c,e[3]=s*l+o*h,e[4]=f*u+c*a+p,e[5]=l*u+h*a+d,e},f.mul=f.multiply,f.rotate=function(e,t,n){var r=t[0],i=t[1],s=t[2],o=t[3],u=t[4],a=t[5],f=Math.sin(n),l=Math.cos(n);return e[0]=r*l+i*f,e[1]=-r*f+i*l,e[2]=s*l+o*f,e[3]=-s*f+l*o,e[4]=l*u+f*a,e[5]=l*a-f*u,e},f.scale=function(e,t,n){var r=n[0],i=n[1];return e[0]=t[0]*r,e[1]=t[1]*i,e[2]=t[2]*r,e[3]=t[3]*i,e[4]=t[4]*r,e[5]=t[5]*i,e},f.translate=function(e,t,n){return e[0]=t[0],e[1]=t[1],e[2]=t[2],e[3]=t[3],e[4]=t[4]+n[0],e[5]=t[5]+n[1],e},f.str=function(e){return"mat2d("+e[0]+", "+e[1]+", "+e[2]+", "+e[3]+", "+e[4]+", "+e[5]+")"},typeof e!="undefined"&&(e.mat2d=f);var l={};l.create=function(){var e=new n(9);return e[0]=1,e[1]=0,e[2]=0,e[3]=0,e[4]=1,e[5]=0,e[6]=0,e[7]=0,e[8]=1,e},l.fromMat4=function(e,t){return e[0]=t[0],e[1]=t[1],e[2]=t[2],e[3]=t[4],e[4]=t[5],e[5]=t[6],e[6]=t[8],e[7]=t[9],e[8]=t[10],e},l.clone=function(e){var t=new n(9);return t[0]=e[0],t[1]=e[1],t[2]=e[2],t[3]=e[3],t[4]=e[4],t[5]=e[5],t[6]=e[6],t[7]=e[7],t[8]=e[8],t},l.copy=function(e,t){return e[0]=t[0],e[1]=t[1],e[2]=t[2],e[3]=t[3],e[4]=t[4],e[5]=t[5],e[6]=t[6],e[7]=t[7],e[8]=t[8],e},l.identity=function(e){return e[0]=1,e[1]=0,e[2]=0,e[3]=0,e[4]=1,e[5]=0,e[6]=0,e[7]=0,e[8]=1,e},l.transpose=function(e,t){if(e===t){var n=t[1],r=t[2],i=t[5];e[1]=t[3],e[2]=t[6],e[3]=n,e[5]=t[7],e[6]=r,e[7]=i}else e[0]=t[0],e[1]=t[3],e[2]=t[6],e[3]=t[1],e[4]=t[4],e[5]=t[7],e[6]=t[2],e[7]=t[5],e[8]=t[8];return e},l.invert=function(e,t){var n=t[0],r=t[1],i=t[2],s=t[3],o=t[4],u=t[5],a=t[6],f=t[7],l=t[8],c=l*o-u*f,h=-l*s+u*a,p=f*s-o*a,d=n*c+r*h+i*p;return d?(d=1/d,e[0]=c*d,e[1]=(-l*r+i*f)*d,e[2]=(u*r-i*o)*d,e[3]=h*d,e[4]=(l*n-i*a)*d,e[5]=(-u*n+i*s)*d,e[6]=p*d,e[7]=(-f*n+r*a)*d,e[8]=(o*n-r*s)*d,e):null},l.adjoint=function(e,t){var n=t[0],r=t[1],i=t[2],s=t[3],o=t[4],u=t[5],a=t[6],f=t[7],l=t[8];return e[0]=o*l-u*f,e[1]=i*f-r*l,e[2]=r*u-i*o,e[3]=u*a-s*l,e[4]=n*l-i*a,e[5]=i*s-n*u,e[6]=s*f-o*a,e[7]=r*a-n*f,e[8]=n*o-r*s,e},l.determinant=function(e){var t=e[0],n=e[1],r=e[2],i=e[3],s=e[4],o=e[5],u=e[6],a=e[7],f=e[8];return t*(f*s-o*a)+n*(-f*i+o*u)+r*(a*i-s*u)},l.multiply=function(e,t,n){var r=t[0],i=t[1],s=t[2],o=t[3],u=t[4],a=t[5],f=t[6],l=t[7],c=t[8],h=n[0],p=n[1],d=n[2],v=n[3],m=n[4],g=n[5],y=n[6],b=n[7],w=n[8];return e[0]=h*r+p*o+d*f,e[1]=h*i+p*u+d*l,e[2]=h*s+p*a+d*c,e[3]=v*r+m*o+g*f,e[4]=v*i+m*u+g*l,e[5]=v*s+m*a+g*c,e[6]=y*r+b*o+w*f,e[7]=y*i+b*u+w*l,e[8]=y*s+b*a+w*c,e},l.mul=l.multiply,l.translate=function(e,t,n){var r=t[0],i=t[1],s=t[2],o=t[3],u=t[4],a=t[5],f=t[6],l=t[7],c=t[8],h=n[0],p=n[1];return e[0]=r,e[1]=i,e[2]=s,e[3]=o,e[4]=u,e[5]=a,e[6]=h*r+p*o+f,e[7]=h*i+p*u+l,e[8]=h*s+p*a+c,e},l.rotate=function(e,t,n){var r=t[0],i=t[1],s=t[2],o=t[3],u=t[4],a=t[5],f=t[6],l=t[7],c=t[8],h=Math.sin(n),p=Math.cos(n);return e[0]=p*r+h*o,e[1]=p*i+h*u,e[2]=p*s+h*a,e[3]=p*o-h*r,e[4]=p*u-h*i,e[5]=p*a-h*s,e[6]=f,e[7]=l,e[8]=c,e},l.scale=function(e,t,n){var r=n[0],i=n[1];return e[0]=r*t[0],e[1]=r*t[1],e[2]=r*t[2],e[3]=i*t[3],e[4]=i*t[4],e[5]=i*t[5],e[6]=t[6],e[7]=t[7],e[8]=t[8],e},l.fromMat2d=function(e,t){return e[0]=t[0],e[1]=t[1],e[2]=0,e[3]=t[2],e[4]=t[3],e[5]=0,e[6]=t[4],e[7]=t[5],e[8]=1,e},l.fromQuat=function(e,t){var n=t[0],r=t[1],i=t[2],s=t[3],o=n+n,u=r+r,a=i+i,f=n*o,l=n*u,c=n*a,h=r*u,p=r*a,d=i*a,v=s*o,m=s*u,g=s*a;return e[0]=1-(h+d),e[3]=l+g,e[6]=c-m,e[1]=l-g,e[4]=1-(f+d),e[7]=p+v,e[2]=c+m,e[5]=p-v,e[8]=1-(f+h),e},l.normalFromMat4=function(e,t){var n=t[0],r=t[1],i=t[2],s=t[3],o=t[4],u=t[5],a=t[6],f=t[7],l=t[8],c=t[9],h=t[10],p=t[11],d=t[12],v=t[13],m=t[14],g=t[15],y=n*u-r*o,b=n*a-i*o,w=n*f-s*o,E=r*a-i*u,S=r*f-s*u,x=i*f-s*a,T=l*v-c*d,N=l*m-h*d,C=l*g-p*d,k=c*m-h*v,L=c*g-p*v,A=h*g-p*m,O=y*A-b*L+w*k+E*C-S*N+x*T;return O?(O=1/O,e[0]=(u*A-a*L+f*k)*O,e[1]=(a*C-o*A-f*N)*O,e[2]=(o*L-u*C+f*T)*O,e[3]=(i*L-r*A-s*k)*O,e[4]=(n*A-i*C+s*N)*O,e[5]=(r*C-n*L-s*T)*O,e[6]=(v*x-m*S+g*E)*O,e[7]=(m*w-d*x-g*b)*O,e[8]=(d*S-v*w+g*y)*O,e):null},l.str=function(e){return"mat3("+e[0]+", "+e[1]+", "+e[2]+", "+e[3]+", "+e[4]+", "+e[5]+", "+e[6]+", "+e[7]+", "+e[8]+")"},typeof e!="undefined"&&(e.mat3=l);var c={};c.create=function(){var e=new n(16);return e[0]=1,e[1]=0,e[2]=0,e[3]=0,e[4]=0,e[5]=1,e[6]=0,e[7]=0,e[8]=0,e[9]=0,e[10]=1,e[11]=0,e[12]=0,e[13]=0,e[14]=0,e[15]=1,e},c.clone=function(e){var t=new n(16);return t[0]=e[0],t[1]=e[1],t[2]=e[2],t[3]=e[3],t[4]=e[4],t[5]=e[5],t[6]=e[6],t[7]=e[7],t[8]=e[8],t[9]=e[9],t[10]=e[10],t[11]=e[11],t[12]=e[12],t[13]=e[13],t[14]=e[14],t[15]=e[15],t},c.copy=function(e,t){return e[0]=t[0],e[1]=t[1],e[2]=t[2],e[3]=t[3],e[4]=t[4],e[5]=t[5],e[6]=t[6],e[7]=t[7],e[8]=t[8],e[9]=t[9],e[10]=t[10],e[11]=t[11],e[12]=t[12],e[13]=t[13],e[14]=t[14],e[15]=t[15],e},c.identity=function(e){return e[0]=1,e[1]=0,e[2]=0,e[3]=0,e[4]=0,e[5]=1,e[6]=0,e[7]=0,e[8]=0,e[9]=0,e[10]=1,e[11]=0,e[12]=0,e[13]=0,e[14]=0,e[15]=1,e},c.transpose=function(e,t){if(e===t){var n=t[1],r=t[2],i=t[3],s=t[6],o=t[7],u=t[11];e[1]=t[4],e[2]=t[8],e[3]=t[12],e[4]=n,e[6]=t[9],e[7]=t[13],e[8]=r,e[9]=s,e[11]=t[14],e[12]=i,e[13]=o,e[14]=u}else e[0]=t[0],e[1]=t[4],e[2]=t[8],e[3]=t[12],e[4]=t[1],e[5]=t[5],e[6]=t[9],e[7]=t[13],e[8]=t[2],e[9]=t[6],e[10]=t[10],e[11]=t[14],e[12]=t[3],e[13]=t[7],e[14]=t[11],e[15]=t[15];return e},c.invert=function(e,t){var n=t[0],r=t[1],i=t[2],s=t[3],o=t[4],u=t[5],a=t[6],f=t[7],l=t[8],c=t[9],h=t[10],p=t[11],d=t[12],v=t[13],m=t[14],g=t[15],y=n*u-r*o,b=n*a-i*o,w=n*f-s*o,E=r*a-i*u,S=r*f-s*u,x=i*f-s*a,T=l*v-c*d,N=l*m-h*d,C=l*g-p*d,k=c*m-h*v,L=c*g-p*v,A=h*g-p*m,O=y*A-b*L+w*k+E*C-S*N+x*T;return O?(O=1/O,e[0]=(u*A-a*L+f*k)*O,e[1]=(i*L-r*A-s*k)*O,e[2]=(v*x-m*S+g*E)*O,e[3]=(h*S-c*x-p*E)*O,e[4]=(a*C-o*A-f*N)*O,e[5]=(n*A-i*C+s*N)*O,e[6]=(m*w-d*x-g*b)*O,e[7]=(l*x-h*w+p*b)*O,e[8]=(o*L-u*C+f*T)*O,e[9]=(r*C-n*L-s*T)*O,e[10]=(d*S-v*w+g*y)*O,e[11]=(c*w-l*S-p*y)*O,e[12]=(u*N-o*k-a*T)*O,e[13]=(n*k-r*N+i*T)*O,e[14]=(v*b-d*E-m*y)*O,e[15]=(l*E-c*b+h*y)*O,e):null},c.adjoint=function(e,t){var n=t[0],r=t[1],i=t[2],s=t[3],o=t[4],u=t[5],a=t[6],f=t[7],l=t[8],c=t[9],h=t[10],p=t[11],d=t[12],v=t[13],m=t[14],g=t[15];return e[0]=u*(h*g-p*m)-c*(a*g-f*m)+v*(a*p-f*h),e[1]=-(r*(h*g-p*m)-c*(i*g-s*m)+v*(i*p-s*h)),e[2]=r*(a*g-f*m)-u*(i*g-s*m)+v*(i*f-s*a),e[3]=-(r*(a*p-f*h)-u*(i*p-s*h)+c*(i*f-s*a)),e[4]=-(o*(h*g-p*m)-l*(a*g-f*m)+d*(a*p-f*h)),e[5]=n*(h*g-p*m)-l*(i*g-s*m)+d*(i*p-s*h),e[6]=-(n*(a*g-f*m)-o*(i*g-s*m)+d*(i*f-s*a)),e[7]=n*(a*p-f*h)-o*(i*p-s*h)+l*(i*f-s*a),e[8]=o*(c*g-p*v)-l*(u*g-f*v)+d*(u*p-f*c),e[9]=-(n*(c*g-p*v)-l*(r*g-s*v)+d*(r*p-s*c)),e[10]=n*(u*g-f*v)-o*(r*g-s*v)+d*(r*f-s*u),e[11]=-(n*(u*p-f*c)-o*(r*p-s*c)+l*(r*f-s*u)),e[12]=-(o*(c*m-h*v)-l*(u*m-a*v)+d*(u*h-a*c)),e[13]=n*(c*m-h*v)-l*(r*m-i*v)+d*(r*h-i*c),e[14]=-(n*(u*m-a*v)-o*(r*m-i*v)+d*(r*a-i*u)),e[15]=n*(u*h-a*c)-o*(r*h-i*c)+l*(r*a-i*u),e},c.determinant=function(e){var t=e[0],n=e[1],r=e[2],i=e[3],s=e[4],o=e[5],u=e[6],a=e[7],f=e[8],l=e[9],c=e[10],h=e[11],p=e[12],d=e[13],v=e[14],m=e[15],g=t*o-n*s,y=t*u-r*s,b=t*a-i*s,w=n*u-r*o,E=n*a-i*o,S=r*a-i*u,x=f*d-l*p,T=f*v-c*p,N=f*m-h*p,C=l*v-c*d,k=l*m-h*d,L=c*m-h*v;return g*L-y*k+b*C+w*N-E*T+S*x},c.multiply=function(e,t,n){var r=t[0],i=t[1],s=t[2],o=t[3],u=t[4],a=t[5],f=t[6],l=t[7],c=t[8],h=t[9],p=t[10],d=t[11],v=t[12],m=t[13],g=t[14],y=t[15],b=n[0],w=n[1],E=n[2],S=n[3];return e[0]=b*r+w*u+E*c+S*v,e[1]=b*i+w*a+E*h+S*m,e[2]=b*s+w*f+E*p+S*g,e[3]=b*o+w*l+E*d+S*y,b=n[4],w=n[5],E=n[6],S=n[7],e[4]=b*r+w*u+E*c+S*v,e[5]=b*i+w*a+E*h+S*m,e[6]=b*s+w*f+E*p+S*g,e[7]=b*o+w*l+E*d+S*y,b=n[8],w=n[9],E=n[10],S=n[11],e[8]=b*r+w*u+E*c+S*v,e[9]=b*i+w*a+E*h+S*m,e[10]=b*s+w*f+E*p+S*g,e[11]=b*o+w*l+E*d+S*y,b=n[12],w=n[13],E=n[14],S=n[15],e[12]=b*r+w*u+E*c+S*v,e[13]=b*i+w*a+E*h+S*m,e[14]=b*s+w*f+E*p+S*g,e[15]=b*o+w*l+E*d+S*y,e},c.mul=c.multiply,c.translate=function(e,t,n){var r=n[0],i=n[1],s=n[2],o,u,a,f,l,c,h,p,d,v,m,g;return t===e?(e[12]=t[0]*r+t[4]*i+t[8]*s+t[12],e[13]=t[1]*r+t[5]*i+t[9]*s+t[13],e[14]=t[2]*r+t[6]*i+t[10]*s+t[14],e[15]=t[3]*r+t[7]*i+t[11]*s+t[15]):(o=t[0],u=t[1],a=t[2],f=t[3],l=t[4],c=t[5],h=t[6],p=t[7],d=t[8],v=t[9],m=t[10],g=t[11],e[0]=o,e[1]=u,e[2]=a,e[3]=f,e[4]=l,e[5]=c,e[6]=h,e[7]=p,e[8]=d,e[9]=v,e[10]=m,e[11]=g,e[12]=o*r+l*i+d*s+t[12],e[13]=u*r+c*i+v*s+t[13],e[14]=a*r+h*i+m*s+t[14],e[15]=f*r+p*i+g*s+t[15]),e},c.scale=function(e,t,n){var r=n[0],i=n[1],s=n[2];return e[0]=t[0]*r,e[1]=t[1]*r,e[2]=t[2]*r,e[3]=t[3]*r,e[4]=t[4]*i,e[5]=t[5]*i,e[6]=t[6]*i,e[7]=t[7]*i,e[8]=t[8]*s,e[9]=t[9]*s,e[10]=t[10]*s,e[11]=t[11]*s,e[12]=t[12],e[13]=t[13],e[14]=t[14],e[15]=t[15],e},c.rotate=function(e,n,r,i){var s=i[0],o=i[1],u=i[2],a=Math.sqrt(s*s+o*o+u*u),f,l,c,h,p,d,v,m,g,y,b,w,E,S,x,T,N,C,k,L,A,O,M,_;return Math.abs(a)<t?null:(a=1/a,s*=a,o*=a,u*=a,f=Math.sin(r),l=Math.cos(r),c=1-l,h=n[0],p=n[1],d=n[2],v=n[3],m=n[4],g=n[5],y=n[6],b=n[7],w=n[8],E=n[9],S=n[10],x=n[11],T=s*s*c+l,N=o*s*c+u*f,C=u*s*c-o*f,k=s*o*c-u*f,L=o*o*c+l,A=u*o*c+s*f,O=s*u*c+o*f,M=o*u*c-s*f,_=u*u*c+l,e[0]=h*T+m*N+w*C,e[1]=p*T+g*N+E*C,e[2]=d*T+y*N+S*C,e[3]=v*T+b*N+x*C,e[4]=h*k+m*L+w*A,e[5]=p*k+g*L+E*A,e[6]=d*k+y*L+S*A,e[7]=v*k+b*L+x*A,e[8]=h*O+m*M+w*_,e[9]=p*O+g*M+E*_,e[10]=d*O+y*M+S*_,e[11]=v*O+b*M+x*_,n!==e&&(e[12]=n[12],e[13]=n[13],e[14]=n[14],e[15]=n[15]),e)},c.rotateX=function(e,t,n){var r=Math.sin(n),i=Math.cos(n),s=t[4],o=t[5],u=t[6],a=t[7],f=t[8],l=t[9],c=t[10],h=t[11];return t!==e&&(e[0]=t[0],e[1]=t[1],e[2]=t[2],e[3]=t[3],e[12]=t[12],e[13]=t[13],e[14]=t[14],e[15]=t[15]),e[4]=s*i+f*r,e[5]=o*i+l*r,e[6]=u*i+c*r,e[7]=a*i+h*r,e[8]=f*i-s*r,e[9]=l*i-o*r,e[10]=c*i-u*r,e[11]=h*i-a*r,e},c.rotateY=function(e,t,n){var r=Math.sin(n),i=Math.cos(n),s=t[0],o=t[1],u=t[2],a=t[3],f=t[8],l=t[9],c=t[10],h=t[11];return t!==e&&(e[4]=t[4],e[5]=t[5],e[6]=t[6],e[7]=t[7],e[12]=t[12],e[13]=t[13],e[14]=t[14],e[15]=t[15]),e[0]=s*i-f*r,e[1]=o*i-l*r,e[2]=u*i-c*r,e[3]=a*i-h*r,e[8]=s*r+f*i,e[9]=o*r+l*i,e[10]=u*r+c*i,e[11]=a*r+h*i,e},c.rotateZ=function(e,t,n){var r=Math.sin(n),i=Math.cos(n),s=t[0],o=t[1],u=t[2],a=t[3],f=t[4],l=t[5],c=t[6],h=t[7];return t!==e&&(e[8]=t[8],e[9]=t[9],e[10]=t[10],e[11]=t[11],e[12]=t[12],e[13]=t[13],e[14]=t[14],e[15]=t[15]),e[0]=s*i+f*r,e[1]=o*i+l*r,e[2]=u*i+c*r,e[3]=a*i+h*r,e[4]=f*i-s*r,e[5]=l*i-o*r,e[6]=c*i-u*r,e[7]=h*i-a*r,e},c.fromRotationTranslation=function(e,t,n){var r=t[0],i=t[1],s=t[2],o=t[3],u=r+r,a=i+i,f=s+s,l=r*u,c=r*a,h=r*f,p=i*a,d=i*f,v=s*f,m=o*u,g=o*a,y=o*f;return e[0]=1-(p+v),e[1]=c+y,e[2]=h-g,e[3]=0,e[4]=c-y,e[5]=1-(l+v),e[6]=d+m,e[7]=0,e[8]=h+g,e[9]=d-m,e[10]=1-(l+p),e[11]=0,e[12]=n[0],e[13]=n[1],e[14]=n[2],e[15]=1,e},c.fromQuat=function(e,t){var n=t[0],r=t[1],i=t[2],s=t[3],o=n+n,u=r+r,a=i+i,f=n*o,l=n*u,c=n*a,h=r*u,p=r*a,d=i*a,v=s*o,m=s*u,g=s*a;return e[0]=1-(h+d),e[1]=l+g,e[2]=c-m,e[3]=0,e[4]=l-g,e[5]=1-(f+d),e[6]=p+v,e[7]=0,e[8]=c+m,e[9]=p-v,e[10]=1-(f+h),e[11]=0,e[12]=0,e[13]=0,e[14]=0,e[15]=1,e},c.frustum=function(e,t,n,r,i,s,o){var u=1/(n-t),a=1/(i-r),f=1/(s-o);return e[0]=s*2*u,e[1]=0,e[2]=0,e[3]=0,e[4]=0,e[5]=s*2*a,e[6]=0,e[7]=0,e[8]=(n+t)*u,e[9]=(i+r)*a,e[10]=(o+s)*f,e[11]=-1,e[12]=0,e[13]=0,e[14]=o*s*2*f,e[15]=0,e},c.perspective=function(e,t,n,r,i){var s=1/Math.tan(t/2),o=1/(r-i);return e[0]=s/n,e[1]=0,e[2]=0,e[3]=0,e[4]=0,e[5]=s,e[6]=0,e[7]=0,e[8]=0,e[9]=0,e[10]=(i+r)*o,e[11]=-1,e[12]=0,e[13]=0,e[14]=2*i*r*o,e[15]=0,e},c.ortho=function(e,t,n,r,i,s,o){var u=1/(t-n),a=1/(r-i),f=1/(s-o);return e[0]=-2*u,e[1]=0,e[2]=0,e[3]=0,e[4]=0,e[5]=-2*a,e[6]=0,e[7]=0,e[8]=0,e[9]=0,e[10]=2*f,e[11]=0,e[12]=(t+n)*u,e[13]=(i+r)*a,e[14]=(o+s)*f,e[15]=1,e},c.lookAt=function(e,n,r,i){var s,o,u,a,f,l,h,p,d,v,m=n[0],g=n[1],y=n[2],b=i[0],w=i[1],E=i[2],S=r[0],x=r[1],T=r[2];return Math.abs(m-S)<t&&Math.abs(g-x)<t&&Math.abs(y-T)<t?c.identity(e):(h=m-S,p=g-x,d=y-T,v=1/Math.sqrt(h*h+p*p+d*d),h*=v,p*=v,d*=v,s=w*d-E*p,o=E*h-b*d,u=b*p-w*h,v=Math.sqrt(s*s+o*o+u*u),v?(v=1/v,s*=v,o*=v,u*=v):(s=0,o=0,u=0),a=p*u-d*o,f=d*s-h*u,l=h*o-p*s,v=Math.sqrt(a*a+f*f+l*l),v?(v=1/v,a*=v,f*=v,l*=v):(a=0,f=0,l=0),e[0]=s,e[1]=a,e[2]=h,e[3]=0,e[4]=o,e[5]=f,e[6]=p,e[7]=0,e[8]=u,e[9]=l,e[10]=d,e[11]=0,e[12]=-(s*m+o*g+u*y),e[13]=-(a*m+f*g+l*y),e[14]=-(h*m+p*g+d*y),e[15]=1,e)},c.str=function(e){return"mat4("+e[0]+", "+e[1]+", "+e[2]+", "+e[3]+", "+e[4]+", "+e[5]+", "+e[6]+", "+e[7]+", "+e[8]+", "+e[9]+", "+e[10]+", "+e[11]+", "+e[12]+", "+e[13]+", "+e[14]+", "+e[15]+")"},typeof e!="undefined"&&(e.mat4=c);var h={};h.create=function(){var e=new n(4);return e[0]=0,e[1]=0,e[2]=0,e[3]=1,e},h.rotationTo=function(){var e=o.create(),t=o.fromValues(1,0,0),n=o.fromValues(0,1,0);return function(r,i,s){var u=o.dot(i,s);return u<-0.999999?(o.cross(e,t,i),o.length(e)<1e-6&&o.cross(e,n,i),o.normalize(e,e),h.setAxisAngle(r,e,Math.PI),r):u>.999999?(r[0]=0,r[1]=0,r[2]=0,r[3]=1,r):(o.cross(e,i,s),r[0]=e[0],r[1]=e[1],r[2]=e[2],r[3]=1+u,h.normalize(r,r))}}(),h.setAxes=function(){var e=l.create();return function(t,n,r,i){return e[0]=r[0],e[3]=r[1],e[6]=r[2],e[1]=i[0],e[4]=i[1],e[7]=i[2],e[2]=n[0],e[5]=n[1],e[8]=n[2],h.normalize(t,h.fromMat3(t,e))}}(),h.clone=u.clone,h.fromValues=u.fromValues,h.copy=u.copy,h.set=u.set,h.identity=function(e){return e[0]=0,e[1]=0,e[2]=0,e[3]=1,e},h.setAxisAngle=function(e,t,n){n*=.5;var r=Math.sin(n);return e[0]=r*t[0],e[1]=r*t[1],e[2]=r*t[2],e[3]=Math.cos(n),e},h.add=u.add,h.multiply=function(e,t,n){var r=t[0],i=t[1],s=t[2],o=t[3],u=n[0],a=n[1],f=n[2],l=n[3];return e[0]=r*l+o*u+i*f-s*a,e[1]=i*l+o*a+s*u-r*f,e[2]=s*l+o*f+r*a-i*u,e[3]=o*l-r*u-i*a-s*f,e},h.mul=h.multiply,h.scale=u.scale,h.rotateX=function(e,t,n){n*=.5;var r=t[0],i=t[1],s=t[2],o=t[3],u=Math.sin(n),a=Math.cos(n);return e[0]=r*a+o*u,e[1]=i*a+s*u,e[2]=s*a-i*u,e[3]=o*a-r*u,e},h.rotateY=function(e,t,n){n*=.5;var r=t[0],i=t[1],s=t[2],o=t[3],u=Math.sin(n),a=Math.cos(n);return e[0]=r*a-s*u,e[1]=i*a+o*u,e[2]=s*a+r*u,e[3]=o*a-i*u,e},h.rotateZ=function(e,t,n){n*=.5;var r=t[0],i=t[1],s=t[2],o=t[3],u=Math.sin(n),a=Math.cos(n);return e[0]=r*a+i*u,e[1]=i*a-r*u,e[2]=s*a+o*u,e[3]=o*a-s*u,e},h.calculateW=function(e,t){var n=t[0],r=t[1],i=t[2];return e[0]=n,e[1]=r,e[2]=i,e[3]=-Math.sqrt(Math.abs(1-n*n-r*r-i*i)),e},h.dot=u.dot,h.lerp=u.lerp,h.slerp=function(e,t,n,r){var i=t[0],s=t[1],o=t[2],u=t[3],a=n[0],f=n[1],l=n[2],c=n[3],h,p,d,v,m;return p=i*a+s*f+o*l+u*c,p<0&&(p=-p,a=-a,f=-f,l=-l,c=-c),1-p>1e-6?(h=Math.acos(p),d=Math.sin(h),v=Math.sin((1-r)*h)/d,m=Math.sin(r*h)/d):(v=1-r,m=r),e[0]=v*i+m*a,e[1]=v*s+m*f,e[2]=v*o+m*l,e[3]=v*u+m*c,e},h.invert=function(e,t){var n=t[0],r=t[1],i=t[2],s=t[3],o=n*n+r*r+i*i+s*s,u=o?1/o:0;return e[0]=-n*u,e[1]=-r*u,e[2]=-i*u,e[3]=s*u,e},h.conjugate=function(e,t){return e[0]=-t[0],e[1]=-t[1],e[2]=-t[2],e[3]=t[3],e},h.length=u.length,h.len=h.length,h.squaredLength=u.squaredLength,h.sqrLen=h.squaredLength,h.normalize=u.normalize,h.fromMat3=function(){var e=typeof Int8Array!="undefined"?new Int8Array([1,2,0]):[1,2,0];return function(t,n){var r=n[0]+n[4]+n[8],i;if(r>0)i=Math.sqrt(r+1),t[3]=.5*i,i=.5/i,t[0]=(n[7]-n[5])*i,t[1]=(n[2]-n[6])*i,t[2]=(n[3]-n[1])*i;else{var s=0;n[4]>n[0]&&(s=1),n[8]>n[s*3+s]&&(s=2);var o=e[s],u=e[o];i=Math.sqrt(n[s*3+s]-n[o*3+o]-n[u*3+u]+1),t[s]=.5*i,i=.5/i,t[3]=(n[u*3+o]-n[o*3+u])*i,t[o]=(n[o*3+s]+n[s*3+o])*i,t[u]=(n[u*3+s]+n[s*3+u])*i}return t}}(),h.str=function(e){return"quat("+e[0]+", "+e[1]+", "+e[2]+", "+e[3]+")"},typeof e!="undefined"&&(e.quat=h)}(t.exports)})(this);
|
@@ -0,0 +1,4078 @@
|
|
1
|
+
/**
|
2
|
+
* @fileoverview gl-matrix - High performance matrix and vector operations
|
3
|
+
* @author Brandon Jones
|
4
|
+
* @author Colin MacKenzie IV
|
5
|
+
* @version 2.2.0
|
6
|
+
*/
|
7
|
+
|
8
|
+
/* Copyright (c) 2013, Brandon Jones, Colin MacKenzie IV. All rights reserved.
|
9
|
+
|
10
|
+
Redistribution and use in source and binary forms, with or without modification,
|
11
|
+
are permitted provided that the following conditions are met:
|
12
|
+
|
13
|
+
* Redistributions of source code must retain the above copyright notice, this
|
14
|
+
list of conditions and the following disclaimer.
|
15
|
+
* Redistributions in binary form must reproduce the above copyright notice,
|
16
|
+
this list of conditions and the following disclaimer in the documentation
|
17
|
+
and/or other materials provided with the distribution.
|
18
|
+
|
19
|
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
20
|
+
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
21
|
+
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
22
|
+
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
|
23
|
+
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
24
|
+
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
25
|
+
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
26
|
+
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
27
|
+
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
28
|
+
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */
|
29
|
+
|
30
|
+
|
31
|
+
|
32
|
+
/* Copyright (c) 2013, Brandon Jones, Colin MacKenzie IV. All rights reserved.
|
33
|
+
|
34
|
+
Redistribution and use in source and binary forms, with or without modification,
|
35
|
+
are permitted provided that the following conditions are met:
|
36
|
+
|
37
|
+
* Redistributions of source code must retain the above copyright notice, this
|
38
|
+
list of conditions and the following disclaimer.
|
39
|
+
* Redistributions in binary form must reproduce the above copyright notice,
|
40
|
+
this list of conditions and the following disclaimer in the documentation
|
41
|
+
and/or other materials provided with the distribution.
|
42
|
+
|
43
|
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
44
|
+
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
45
|
+
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
46
|
+
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
|
47
|
+
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
48
|
+
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
49
|
+
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
50
|
+
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
51
|
+
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
52
|
+
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */
|
53
|
+
|
54
|
+
|
55
|
+
if(!GLMAT_EPSILON) {
|
56
|
+
var GLMAT_EPSILON = 0.000001;
|
57
|
+
}
|
58
|
+
|
59
|
+
if(!GLMAT_ARRAY_TYPE) {
|
60
|
+
var GLMAT_ARRAY_TYPE = (typeof Float32Array !== 'undefined') ? Float32Array : Array;
|
61
|
+
}
|
62
|
+
|
63
|
+
if(!GLMAT_RANDOM) {
|
64
|
+
var GLMAT_RANDOM = Math.random;
|
65
|
+
}
|
66
|
+
|
67
|
+
/**
|
68
|
+
* @class Common utilities
|
69
|
+
* @name glMatrix
|
70
|
+
*/
|
71
|
+
var glMatrix = {};
|
72
|
+
|
73
|
+
/**
|
74
|
+
* Sets the type of array used when creating new vectors and matricies
|
75
|
+
*
|
76
|
+
* @param {Type} type Array type, such as Float32Array or Array
|
77
|
+
*/
|
78
|
+
glMatrix.setMatrixArrayType = function(type) {
|
79
|
+
GLMAT_ARRAY_TYPE = type;
|
80
|
+
}
|
81
|
+
|
82
|
+
if(typeof(exports) !== 'undefined') {
|
83
|
+
exports.glMatrix = glMatrix;
|
84
|
+
}
|
85
|
+
;
|
86
|
+
/* Copyright (c) 2013, Brandon Jones, Colin MacKenzie IV. All rights reserved.
|
87
|
+
|
88
|
+
Redistribution and use in source and binary forms, with or without modification,
|
89
|
+
are permitted provided that the following conditions are met:
|
90
|
+
|
91
|
+
* Redistributions of source code must retain the above copyright notice, this
|
92
|
+
list of conditions and the following disclaimer.
|
93
|
+
* Redistributions in binary form must reproduce the above copyright notice,
|
94
|
+
this list of conditions and the following disclaimer in the documentation
|
95
|
+
and/or other materials provided with the distribution.
|
96
|
+
|
97
|
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
98
|
+
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
99
|
+
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
100
|
+
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
|
101
|
+
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
102
|
+
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
103
|
+
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
104
|
+
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
105
|
+
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
106
|
+
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */
|
107
|
+
|
108
|
+
/**
|
109
|
+
* @class 2 Dimensional Vector
|
110
|
+
* @name vec2
|
111
|
+
*/
|
112
|
+
|
113
|
+
var vec2 = {};
|
114
|
+
|
115
|
+
/**
|
116
|
+
* Creates a new, empty vec2
|
117
|
+
*
|
118
|
+
* @returns {vec2} a new 2D vector
|
119
|
+
*/
|
120
|
+
vec2.create = function() {
|
121
|
+
var out = new GLMAT_ARRAY_TYPE(2);
|
122
|
+
out[0] = 0;
|
123
|
+
out[1] = 0;
|
124
|
+
return out;
|
125
|
+
};
|
126
|
+
|
127
|
+
/**
|
128
|
+
* Creates a new vec2 initialized with values from an existing vector
|
129
|
+
*
|
130
|
+
* @param {vec2} a vector to clone
|
131
|
+
* @returns {vec2} a new 2D vector
|
132
|
+
*/
|
133
|
+
vec2.clone = function(a) {
|
134
|
+
var out = new GLMAT_ARRAY_TYPE(2);
|
135
|
+
out[0] = a[0];
|
136
|
+
out[1] = a[1];
|
137
|
+
return out;
|
138
|
+
};
|
139
|
+
|
140
|
+
/**
|
141
|
+
* Creates a new vec2 initialized with the given values
|
142
|
+
*
|
143
|
+
* @param {Number} x X component
|
144
|
+
* @param {Number} y Y component
|
145
|
+
* @returns {vec2} a new 2D vector
|
146
|
+
*/
|
147
|
+
vec2.fromValues = function(x, y) {
|
148
|
+
var out = new GLMAT_ARRAY_TYPE(2);
|
149
|
+
out[0] = x;
|
150
|
+
out[1] = y;
|
151
|
+
return out;
|
152
|
+
};
|
153
|
+
|
154
|
+
/**
|
155
|
+
* Copy the values from one vec2 to another
|
156
|
+
*
|
157
|
+
* @param {vec2} out the receiving vector
|
158
|
+
* @param {vec2} a the source vector
|
159
|
+
* @returns {vec2} out
|
160
|
+
*/
|
161
|
+
vec2.copy = function(out, a) {
|
162
|
+
out[0] = a[0];
|
163
|
+
out[1] = a[1];
|
164
|
+
return out;
|
165
|
+
};
|
166
|
+
|
167
|
+
/**
|
168
|
+
* Set the components of a vec2 to the given values
|
169
|
+
*
|
170
|
+
* @param {vec2} out the receiving vector
|
171
|
+
* @param {Number} x X component
|
172
|
+
* @param {Number} y Y component
|
173
|
+
* @returns {vec2} out
|
174
|
+
*/
|
175
|
+
vec2.set = function(out, x, y) {
|
176
|
+
out[0] = x;
|
177
|
+
out[1] = y;
|
178
|
+
return out;
|
179
|
+
};
|
180
|
+
|
181
|
+
/**
|
182
|
+
* Adds two vec2's
|
183
|
+
*
|
184
|
+
* @param {vec2} out the receiving vector
|
185
|
+
* @param {vec2} a the first operand
|
186
|
+
* @param {vec2} b the second operand
|
187
|
+
* @returns {vec2} out
|
188
|
+
*/
|
189
|
+
vec2.add = function(out, a, b) {
|
190
|
+
out[0] = a[0] + b[0];
|
191
|
+
out[1] = a[1] + b[1];
|
192
|
+
return out;
|
193
|
+
};
|
194
|
+
|
195
|
+
/**
|
196
|
+
* Subtracts vector b from vector a
|
197
|
+
*
|
198
|
+
* @param {vec2} out the receiving vector
|
199
|
+
* @param {vec2} a the first operand
|
200
|
+
* @param {vec2} b the second operand
|
201
|
+
* @returns {vec2} out
|
202
|
+
*/
|
203
|
+
vec2.subtract = function(out, a, b) {
|
204
|
+
out[0] = a[0] - b[0];
|
205
|
+
out[1] = a[1] - b[1];
|
206
|
+
return out;
|
207
|
+
};
|
208
|
+
|
209
|
+
/**
|
210
|
+
* Alias for {@link vec2.subtract}
|
211
|
+
* @function
|
212
|
+
*/
|
213
|
+
vec2.sub = vec2.subtract;
|
214
|
+
|
215
|
+
/**
|
216
|
+
* Multiplies two vec2's
|
217
|
+
*
|
218
|
+
* @param {vec2} out the receiving vector
|
219
|
+
* @param {vec2} a the first operand
|
220
|
+
* @param {vec2} b the second operand
|
221
|
+
* @returns {vec2} out
|
222
|
+
*/
|
223
|
+
vec2.multiply = function(out, a, b) {
|
224
|
+
out[0] = a[0] * b[0];
|
225
|
+
out[1] = a[1] * b[1];
|
226
|
+
return out;
|
227
|
+
};
|
228
|
+
|
229
|
+
/**
|
230
|
+
* Alias for {@link vec2.multiply}
|
231
|
+
* @function
|
232
|
+
*/
|
233
|
+
vec2.mul = vec2.multiply;
|
234
|
+
|
235
|
+
/**
|
236
|
+
* Divides two vec2's
|
237
|
+
*
|
238
|
+
* @param {vec2} out the receiving vector
|
239
|
+
* @param {vec2} a the first operand
|
240
|
+
* @param {vec2} b the second operand
|
241
|
+
* @returns {vec2} out
|
242
|
+
*/
|
243
|
+
vec2.divide = function(out, a, b) {
|
244
|
+
out[0] = a[0] / b[0];
|
245
|
+
out[1] = a[1] / b[1];
|
246
|
+
return out;
|
247
|
+
};
|
248
|
+
|
249
|
+
/**
|
250
|
+
* Alias for {@link vec2.divide}
|
251
|
+
* @function
|
252
|
+
*/
|
253
|
+
vec2.div = vec2.divide;
|
254
|
+
|
255
|
+
/**
|
256
|
+
* Returns the minimum of two vec2's
|
257
|
+
*
|
258
|
+
* @param {vec2} out the receiving vector
|
259
|
+
* @param {vec2} a the first operand
|
260
|
+
* @param {vec2} b the second operand
|
261
|
+
* @returns {vec2} out
|
262
|
+
*/
|
263
|
+
vec2.min = function(out, a, b) {
|
264
|
+
out[0] = Math.min(a[0], b[0]);
|
265
|
+
out[1] = Math.min(a[1], b[1]);
|
266
|
+
return out;
|
267
|
+
};
|
268
|
+
|
269
|
+
/**
|
270
|
+
* Returns the maximum of two vec2's
|
271
|
+
*
|
272
|
+
* @param {vec2} out the receiving vector
|
273
|
+
* @param {vec2} a the first operand
|
274
|
+
* @param {vec2} b the second operand
|
275
|
+
* @returns {vec2} out
|
276
|
+
*/
|
277
|
+
vec2.max = function(out, a, b) {
|
278
|
+
out[0] = Math.max(a[0], b[0]);
|
279
|
+
out[1] = Math.max(a[1], b[1]);
|
280
|
+
return out;
|
281
|
+
};
|
282
|
+
|
283
|
+
/**
|
284
|
+
* Scales a vec2 by a scalar number
|
285
|
+
*
|
286
|
+
* @param {vec2} out the receiving vector
|
287
|
+
* @param {vec2} a the vector to scale
|
288
|
+
* @param {Number} b amount to scale the vector by
|
289
|
+
* @returns {vec2} out
|
290
|
+
*/
|
291
|
+
vec2.scale = function(out, a, b) {
|
292
|
+
out[0] = a[0] * b;
|
293
|
+
out[1] = a[1] * b;
|
294
|
+
return out;
|
295
|
+
};
|
296
|
+
|
297
|
+
/**
|
298
|
+
* Adds two vec2's after scaling the second operand by a scalar value
|
299
|
+
*
|
300
|
+
* @param {vec2} out the receiving vector
|
301
|
+
* @param {vec2} a the first operand
|
302
|
+
* @param {vec2} b the second operand
|
303
|
+
* @param {Number} scale the amount to scale b by before adding
|
304
|
+
* @returns {vec2} out
|
305
|
+
*/
|
306
|
+
vec2.scaleAndAdd = function(out, a, b, scale) {
|
307
|
+
out[0] = a[0] + (b[0] * scale);
|
308
|
+
out[1] = a[1] + (b[1] * scale);
|
309
|
+
return out;
|
310
|
+
};
|
311
|
+
|
312
|
+
/**
|
313
|
+
* Calculates the euclidian distance between two vec2's
|
314
|
+
*
|
315
|
+
* @param {vec2} a the first operand
|
316
|
+
* @param {vec2} b the second operand
|
317
|
+
* @returns {Number} distance between a and b
|
318
|
+
*/
|
319
|
+
vec2.distance = function(a, b) {
|
320
|
+
var x = b[0] - a[0],
|
321
|
+
y = b[1] - a[1];
|
322
|
+
return Math.sqrt(x*x + y*y);
|
323
|
+
};
|
324
|
+
|
325
|
+
/**
|
326
|
+
* Alias for {@link vec2.distance}
|
327
|
+
* @function
|
328
|
+
*/
|
329
|
+
vec2.dist = vec2.distance;
|
330
|
+
|
331
|
+
/**
|
332
|
+
* Calculates the squared euclidian distance between two vec2's
|
333
|
+
*
|
334
|
+
* @param {vec2} a the first operand
|
335
|
+
* @param {vec2} b the second operand
|
336
|
+
* @returns {Number} squared distance between a and b
|
337
|
+
*/
|
338
|
+
vec2.squaredDistance = function(a, b) {
|
339
|
+
var x = b[0] - a[0],
|
340
|
+
y = b[1] - a[1];
|
341
|
+
return x*x + y*y;
|
342
|
+
};
|
343
|
+
|
344
|
+
/**
|
345
|
+
* Alias for {@link vec2.squaredDistance}
|
346
|
+
* @function
|
347
|
+
*/
|
348
|
+
vec2.sqrDist = vec2.squaredDistance;
|
349
|
+
|
350
|
+
/**
|
351
|
+
* Calculates the length of a vec2
|
352
|
+
*
|
353
|
+
* @param {vec2} a vector to calculate length of
|
354
|
+
* @returns {Number} length of a
|
355
|
+
*/
|
356
|
+
vec2.length = function (a) {
|
357
|
+
var x = a[0],
|
358
|
+
y = a[1];
|
359
|
+
return Math.sqrt(x*x + y*y);
|
360
|
+
};
|
361
|
+
|
362
|
+
/**
|
363
|
+
* Alias for {@link vec2.length}
|
364
|
+
* @function
|
365
|
+
*/
|
366
|
+
vec2.len = vec2.length;
|
367
|
+
|
368
|
+
/**
|
369
|
+
* Calculates the squared length of a vec2
|
370
|
+
*
|
371
|
+
* @param {vec2} a vector to calculate squared length of
|
372
|
+
* @returns {Number} squared length of a
|
373
|
+
*/
|
374
|
+
vec2.squaredLength = function (a) {
|
375
|
+
var x = a[0],
|
376
|
+
y = a[1];
|
377
|
+
return x*x + y*y;
|
378
|
+
};
|
379
|
+
|
380
|
+
/**
|
381
|
+
* Alias for {@link vec2.squaredLength}
|
382
|
+
* @function
|
383
|
+
*/
|
384
|
+
vec2.sqrLen = vec2.squaredLength;
|
385
|
+
|
386
|
+
/**
|
387
|
+
* Negates the components of a vec2
|
388
|
+
*
|
389
|
+
* @param {vec2} out the receiving vector
|
390
|
+
* @param {vec2} a vector to negate
|
391
|
+
* @returns {vec2} out
|
392
|
+
*/
|
393
|
+
vec2.negate = function(out, a) {
|
394
|
+
out[0] = -a[0];
|
395
|
+
out[1] = -a[1];
|
396
|
+
return out;
|
397
|
+
};
|
398
|
+
|
399
|
+
/**
|
400
|
+
* Normalize a vec2
|
401
|
+
*
|
402
|
+
* @param {vec2} out the receiving vector
|
403
|
+
* @param {vec2} a vector to normalize
|
404
|
+
* @returns {vec2} out
|
405
|
+
*/
|
406
|
+
vec2.normalize = function(out, a) {
|
407
|
+
var x = a[0],
|
408
|
+
y = a[1];
|
409
|
+
var len = x*x + y*y;
|
410
|
+
if (len > 0) {
|
411
|
+
//TODO: evaluate use of glm_invsqrt here?
|
412
|
+
len = 1 / Math.sqrt(len);
|
413
|
+
out[0] = a[0] * len;
|
414
|
+
out[1] = a[1] * len;
|
415
|
+
}
|
416
|
+
return out;
|
417
|
+
};
|
418
|
+
|
419
|
+
/**
|
420
|
+
* Calculates the dot product of two vec2's
|
421
|
+
*
|
422
|
+
* @param {vec2} a the first operand
|
423
|
+
* @param {vec2} b the second operand
|
424
|
+
* @returns {Number} dot product of a and b
|
425
|
+
*/
|
426
|
+
vec2.dot = function (a, b) {
|
427
|
+
return a[0] * b[0] + a[1] * b[1];
|
428
|
+
};
|
429
|
+
|
430
|
+
/**
|
431
|
+
* Computes the cross product of two vec2's
|
432
|
+
* Note that the cross product must by definition produce a 3D vector
|
433
|
+
*
|
434
|
+
* @param {vec3} out the receiving vector
|
435
|
+
* @param {vec2} a the first operand
|
436
|
+
* @param {vec2} b the second operand
|
437
|
+
* @returns {vec3} out
|
438
|
+
*/
|
439
|
+
vec2.cross = function(out, a, b) {
|
440
|
+
var z = a[0] * b[1] - a[1] * b[0];
|
441
|
+
out[0] = out[1] = 0;
|
442
|
+
out[2] = z;
|
443
|
+
return out;
|
444
|
+
};
|
445
|
+
|
446
|
+
/**
|
447
|
+
* Performs a linear interpolation between two vec2's
|
448
|
+
*
|
449
|
+
* @param {vec2} out the receiving vector
|
450
|
+
* @param {vec2} a the first operand
|
451
|
+
* @param {vec2} b the second operand
|
452
|
+
* @param {Number} t interpolation amount between the two inputs
|
453
|
+
* @returns {vec2} out
|
454
|
+
*/
|
455
|
+
vec2.lerp = function (out, a, b, t) {
|
456
|
+
var ax = a[0],
|
457
|
+
ay = a[1];
|
458
|
+
out[0] = ax + t * (b[0] - ax);
|
459
|
+
out[1] = ay + t * (b[1] - ay);
|
460
|
+
return out;
|
461
|
+
};
|
462
|
+
|
463
|
+
/**
|
464
|
+
* Generates a random vector with the given scale
|
465
|
+
*
|
466
|
+
* @param {vec2} out the receiving vector
|
467
|
+
* @param {Number} [scale] Length of the resulting vector. If ommitted, a unit vector will be returned
|
468
|
+
* @returns {vec2} out
|
469
|
+
*/
|
470
|
+
vec2.random = function (out, scale) {
|
471
|
+
scale = scale || 1.0;
|
472
|
+
var r = GLMAT_RANDOM() * 2.0 * Math.PI;
|
473
|
+
out[0] = Math.cos(r) * scale;
|
474
|
+
out[1] = Math.sin(r) * scale;
|
475
|
+
return out;
|
476
|
+
};
|
477
|
+
|
478
|
+
/**
|
479
|
+
* Transforms the vec2 with a mat2
|
480
|
+
*
|
481
|
+
* @param {vec2} out the receiving vector
|
482
|
+
* @param {vec2} a the vector to transform
|
483
|
+
* @param {mat2} m matrix to transform with
|
484
|
+
* @returns {vec2} out
|
485
|
+
*/
|
486
|
+
vec2.transformMat2 = function(out, a, m) {
|
487
|
+
var x = a[0],
|
488
|
+
y = a[1];
|
489
|
+
out[0] = m[0] * x + m[2] * y;
|
490
|
+
out[1] = m[1] * x + m[3] * y;
|
491
|
+
return out;
|
492
|
+
};
|
493
|
+
|
494
|
+
/**
|
495
|
+
* Transforms the vec2 with a mat2d
|
496
|
+
*
|
497
|
+
* @param {vec2} out the receiving vector
|
498
|
+
* @param {vec2} a the vector to transform
|
499
|
+
* @param {mat2d} m matrix to transform with
|
500
|
+
* @returns {vec2} out
|
501
|
+
*/
|
502
|
+
vec2.transformMat2d = function(out, a, m) {
|
503
|
+
var x = a[0],
|
504
|
+
y = a[1];
|
505
|
+
out[0] = m[0] * x + m[2] * y + m[4];
|
506
|
+
out[1] = m[1] * x + m[3] * y + m[5];
|
507
|
+
return out;
|
508
|
+
};
|
509
|
+
|
510
|
+
/**
|
511
|
+
* Transforms the vec2 with a mat3
|
512
|
+
* 3rd vector component is implicitly '1'
|
513
|
+
*
|
514
|
+
* @param {vec2} out the receiving vector
|
515
|
+
* @param {vec2} a the vector to transform
|
516
|
+
* @param {mat3} m matrix to transform with
|
517
|
+
* @returns {vec2} out
|
518
|
+
*/
|
519
|
+
vec2.transformMat3 = function(out, a, m) {
|
520
|
+
var x = a[0],
|
521
|
+
y = a[1];
|
522
|
+
out[0] = m[0] * x + m[3] * y + m[6];
|
523
|
+
out[1] = m[1] * x + m[4] * y + m[7];
|
524
|
+
return out;
|
525
|
+
};
|
526
|
+
|
527
|
+
/**
|
528
|
+
* Transforms the vec2 with a mat4
|
529
|
+
* 3rd vector component is implicitly '0'
|
530
|
+
* 4th vector component is implicitly '1'
|
531
|
+
*
|
532
|
+
* @param {vec2} out the receiving vector
|
533
|
+
* @param {vec2} a the vector to transform
|
534
|
+
* @param {mat4} m matrix to transform with
|
535
|
+
* @returns {vec2} out
|
536
|
+
*/
|
537
|
+
vec2.transformMat4 = function(out, a, m) {
|
538
|
+
var x = a[0],
|
539
|
+
y = a[1];
|
540
|
+
out[0] = m[0] * x + m[4] * y + m[12];
|
541
|
+
out[1] = m[1] * x + m[5] * y + m[13];
|
542
|
+
return out;
|
543
|
+
};
|
544
|
+
|
545
|
+
/**
|
546
|
+
* Perform some operation over an array of vec2s.
|
547
|
+
*
|
548
|
+
* @param {Array} a the array of vectors to iterate over
|
549
|
+
* @param {Number} stride Number of elements between the start of each vec2. If 0 assumes tightly packed
|
550
|
+
* @param {Number} offset Number of elements to skip at the beginning of the array
|
551
|
+
* @param {Number} count Number of vec2s to iterate over. If 0 iterates over entire array
|
552
|
+
* @param {Function} fn Function to call for each vector in the array
|
553
|
+
* @param {Object} [arg] additional argument to pass to fn
|
554
|
+
* @returns {Array} a
|
555
|
+
* @function
|
556
|
+
*/
|
557
|
+
vec2.forEach = (function() {
|
558
|
+
var vec = vec2.create();
|
559
|
+
|
560
|
+
return function(a, stride, offset, count, fn, arg) {
|
561
|
+
var i, l;
|
562
|
+
if(!stride) {
|
563
|
+
stride = 2;
|
564
|
+
}
|
565
|
+
|
566
|
+
if(!offset) {
|
567
|
+
offset = 0;
|
568
|
+
}
|
569
|
+
|
570
|
+
if(count) {
|
571
|
+
l = Math.min((count * stride) + offset, a.length);
|
572
|
+
} else {
|
573
|
+
l = a.length;
|
574
|
+
}
|
575
|
+
|
576
|
+
for(i = offset; i < l; i += stride) {
|
577
|
+
vec[0] = a[i]; vec[1] = a[i+1];
|
578
|
+
fn(vec, vec, arg);
|
579
|
+
a[i] = vec[0]; a[i+1] = vec[1];
|
580
|
+
}
|
581
|
+
|
582
|
+
return a;
|
583
|
+
};
|
584
|
+
})();
|
585
|
+
|
586
|
+
/**
|
587
|
+
* Returns a string representation of a vector
|
588
|
+
*
|
589
|
+
* @param {vec2} vec vector to represent as a string
|
590
|
+
* @returns {String} string representation of the vector
|
591
|
+
*/
|
592
|
+
vec2.str = function (a) {
|
593
|
+
return 'vec2(' + a[0] + ', ' + a[1] + ')';
|
594
|
+
};
|
595
|
+
|
596
|
+
if(typeof(exports) !== 'undefined') {
|
597
|
+
exports.vec2 = vec2;
|
598
|
+
}
|
599
|
+
;
|
600
|
+
/* Copyright (c) 2013, Brandon Jones, Colin MacKenzie IV. All rights reserved.
|
601
|
+
|
602
|
+
Redistribution and use in source and binary forms, with or without modification,
|
603
|
+
are permitted provided that the following conditions are met:
|
604
|
+
|
605
|
+
* Redistributions of source code must retain the above copyright notice, this
|
606
|
+
list of conditions and the following disclaimer.
|
607
|
+
* Redistributions in binary form must reproduce the above copyright notice,
|
608
|
+
this list of conditions and the following disclaimer in the documentation
|
609
|
+
and/or other materials provided with the distribution.
|
610
|
+
|
611
|
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
612
|
+
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
613
|
+
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
614
|
+
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
|
615
|
+
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
616
|
+
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
617
|
+
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
618
|
+
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
619
|
+
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
620
|
+
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */
|
621
|
+
|
622
|
+
/**
|
623
|
+
* @class 3 Dimensional Vector
|
624
|
+
* @name vec3
|
625
|
+
*/
|
626
|
+
|
627
|
+
var vec3 = {};
|
628
|
+
|
629
|
+
/**
|
630
|
+
* Creates a new, empty vec3
|
631
|
+
*
|
632
|
+
* @returns {vec3} a new 3D vector
|
633
|
+
*/
|
634
|
+
vec3.create = function() {
|
635
|
+
var out = new GLMAT_ARRAY_TYPE(3);
|
636
|
+
out[0] = 0;
|
637
|
+
out[1] = 0;
|
638
|
+
out[2] = 0;
|
639
|
+
return out;
|
640
|
+
};
|
641
|
+
|
642
|
+
/**
|
643
|
+
* Creates a new vec3 initialized with values from an existing vector
|
644
|
+
*
|
645
|
+
* @param {vec3} a vector to clone
|
646
|
+
* @returns {vec3} a new 3D vector
|
647
|
+
*/
|
648
|
+
vec3.clone = function(a) {
|
649
|
+
var out = new GLMAT_ARRAY_TYPE(3);
|
650
|
+
out[0] = a[0];
|
651
|
+
out[1] = a[1];
|
652
|
+
out[2] = a[2];
|
653
|
+
return out;
|
654
|
+
};
|
655
|
+
|
656
|
+
/**
|
657
|
+
* Creates a new vec3 initialized with the given values
|
658
|
+
*
|
659
|
+
* @param {Number} x X component
|
660
|
+
* @param {Number} y Y component
|
661
|
+
* @param {Number} z Z component
|
662
|
+
* @returns {vec3} a new 3D vector
|
663
|
+
*/
|
664
|
+
vec3.fromValues = function(x, y, z) {
|
665
|
+
var out = new GLMAT_ARRAY_TYPE(3);
|
666
|
+
out[0] = x;
|
667
|
+
out[1] = y;
|
668
|
+
out[2] = z;
|
669
|
+
return out;
|
670
|
+
};
|
671
|
+
|
672
|
+
/**
|
673
|
+
* Copy the values from one vec3 to another
|
674
|
+
*
|
675
|
+
* @param {vec3} out the receiving vector
|
676
|
+
* @param {vec3} a the source vector
|
677
|
+
* @returns {vec3} out
|
678
|
+
*/
|
679
|
+
vec3.copy = function(out, a) {
|
680
|
+
out[0] = a[0];
|
681
|
+
out[1] = a[1];
|
682
|
+
out[2] = a[2];
|
683
|
+
return out;
|
684
|
+
};
|
685
|
+
|
686
|
+
/**
|
687
|
+
* Set the components of a vec3 to the given values
|
688
|
+
*
|
689
|
+
* @param {vec3} out the receiving vector
|
690
|
+
* @param {Number} x X component
|
691
|
+
* @param {Number} y Y component
|
692
|
+
* @param {Number} z Z component
|
693
|
+
* @returns {vec3} out
|
694
|
+
*/
|
695
|
+
vec3.set = function(out, x, y, z) {
|
696
|
+
out[0] = x;
|
697
|
+
out[1] = y;
|
698
|
+
out[2] = z;
|
699
|
+
return out;
|
700
|
+
};
|
701
|
+
|
702
|
+
/**
|
703
|
+
* Adds two vec3's
|
704
|
+
*
|
705
|
+
* @param {vec3} out the receiving vector
|
706
|
+
* @param {vec3} a the first operand
|
707
|
+
* @param {vec3} b the second operand
|
708
|
+
* @returns {vec3} out
|
709
|
+
*/
|
710
|
+
vec3.add = function(out, a, b) {
|
711
|
+
out[0] = a[0] + b[0];
|
712
|
+
out[1] = a[1] + b[1];
|
713
|
+
out[2] = a[2] + b[2];
|
714
|
+
return out;
|
715
|
+
};
|
716
|
+
|
717
|
+
/**
|
718
|
+
* Subtracts vector b from vector a
|
719
|
+
*
|
720
|
+
* @param {vec3} out the receiving vector
|
721
|
+
* @param {vec3} a the first operand
|
722
|
+
* @param {vec3} b the second operand
|
723
|
+
* @returns {vec3} out
|
724
|
+
*/
|
725
|
+
vec3.subtract = function(out, a, b) {
|
726
|
+
out[0] = a[0] - b[0];
|
727
|
+
out[1] = a[1] - b[1];
|
728
|
+
out[2] = a[2] - b[2];
|
729
|
+
return out;
|
730
|
+
};
|
731
|
+
|
732
|
+
/**
|
733
|
+
* Alias for {@link vec3.subtract}
|
734
|
+
* @function
|
735
|
+
*/
|
736
|
+
vec3.sub = vec3.subtract;
|
737
|
+
|
738
|
+
/**
|
739
|
+
* Multiplies two vec3's
|
740
|
+
*
|
741
|
+
* @param {vec3} out the receiving vector
|
742
|
+
* @param {vec3} a the first operand
|
743
|
+
* @param {vec3} b the second operand
|
744
|
+
* @returns {vec3} out
|
745
|
+
*/
|
746
|
+
vec3.multiply = function(out, a, b) {
|
747
|
+
out[0] = a[0] * b[0];
|
748
|
+
out[1] = a[1] * b[1];
|
749
|
+
out[2] = a[2] * b[2];
|
750
|
+
return out;
|
751
|
+
};
|
752
|
+
|
753
|
+
/**
|
754
|
+
* Alias for {@link vec3.multiply}
|
755
|
+
* @function
|
756
|
+
*/
|
757
|
+
vec3.mul = vec3.multiply;
|
758
|
+
|
759
|
+
/**
|
760
|
+
* Divides two vec3's
|
761
|
+
*
|
762
|
+
* @param {vec3} out the receiving vector
|
763
|
+
* @param {vec3} a the first operand
|
764
|
+
* @param {vec3} b the second operand
|
765
|
+
* @returns {vec3} out
|
766
|
+
*/
|
767
|
+
vec3.divide = function(out, a, b) {
|
768
|
+
out[0] = a[0] / b[0];
|
769
|
+
out[1] = a[1] / b[1];
|
770
|
+
out[2] = a[2] / b[2];
|
771
|
+
return out;
|
772
|
+
};
|
773
|
+
|
774
|
+
/**
|
775
|
+
* Alias for {@link vec3.divide}
|
776
|
+
* @function
|
777
|
+
*/
|
778
|
+
vec3.div = vec3.divide;
|
779
|
+
|
780
|
+
/**
|
781
|
+
* Returns the minimum of two vec3's
|
782
|
+
*
|
783
|
+
* @param {vec3} out the receiving vector
|
784
|
+
* @param {vec3} a the first operand
|
785
|
+
* @param {vec3} b the second operand
|
786
|
+
* @returns {vec3} out
|
787
|
+
*/
|
788
|
+
vec3.min = function(out, a, b) {
|
789
|
+
out[0] = Math.min(a[0], b[0]);
|
790
|
+
out[1] = Math.min(a[1], b[1]);
|
791
|
+
out[2] = Math.min(a[2], b[2]);
|
792
|
+
return out;
|
793
|
+
};
|
794
|
+
|
795
|
+
/**
|
796
|
+
* Returns the maximum of two vec3's
|
797
|
+
*
|
798
|
+
* @param {vec3} out the receiving vector
|
799
|
+
* @param {vec3} a the first operand
|
800
|
+
* @param {vec3} b the second operand
|
801
|
+
* @returns {vec3} out
|
802
|
+
*/
|
803
|
+
vec3.max = function(out, a, b) {
|
804
|
+
out[0] = Math.max(a[0], b[0]);
|
805
|
+
out[1] = Math.max(a[1], b[1]);
|
806
|
+
out[2] = Math.max(a[2], b[2]);
|
807
|
+
return out;
|
808
|
+
};
|
809
|
+
|
810
|
+
/**
|
811
|
+
* Scales a vec3 by a scalar number
|
812
|
+
*
|
813
|
+
* @param {vec3} out the receiving vector
|
814
|
+
* @param {vec3} a the vector to scale
|
815
|
+
* @param {Number} b amount to scale the vector by
|
816
|
+
* @returns {vec3} out
|
817
|
+
*/
|
818
|
+
vec3.scale = function(out, a, b) {
|
819
|
+
out[0] = a[0] * b;
|
820
|
+
out[1] = a[1] * b;
|
821
|
+
out[2] = a[2] * b;
|
822
|
+
return out;
|
823
|
+
};
|
824
|
+
|
825
|
+
/**
|
826
|
+
* Adds two vec3's after scaling the second operand by a scalar value
|
827
|
+
*
|
828
|
+
* @param {vec3} out the receiving vector
|
829
|
+
* @param {vec3} a the first operand
|
830
|
+
* @param {vec3} b the second operand
|
831
|
+
* @param {Number} scale the amount to scale b by before adding
|
832
|
+
* @returns {vec3} out
|
833
|
+
*/
|
834
|
+
vec3.scaleAndAdd = function(out, a, b, scale) {
|
835
|
+
out[0] = a[0] + (b[0] * scale);
|
836
|
+
out[1] = a[1] + (b[1] * scale);
|
837
|
+
out[2] = a[2] + (b[2] * scale);
|
838
|
+
return out;
|
839
|
+
};
|
840
|
+
|
841
|
+
/**
|
842
|
+
* Calculates the euclidian distance between two vec3's
|
843
|
+
*
|
844
|
+
* @param {vec3} a the first operand
|
845
|
+
* @param {vec3} b the second operand
|
846
|
+
* @returns {Number} distance between a and b
|
847
|
+
*/
|
848
|
+
vec3.distance = function(a, b) {
|
849
|
+
var x = b[0] - a[0],
|
850
|
+
y = b[1] - a[1],
|
851
|
+
z = b[2] - a[2];
|
852
|
+
return Math.sqrt(x*x + y*y + z*z);
|
853
|
+
};
|
854
|
+
|
855
|
+
/**
|
856
|
+
* Alias for {@link vec3.distance}
|
857
|
+
* @function
|
858
|
+
*/
|
859
|
+
vec3.dist = vec3.distance;
|
860
|
+
|
861
|
+
/**
|
862
|
+
* Calculates the squared euclidian distance between two vec3's
|
863
|
+
*
|
864
|
+
* @param {vec3} a the first operand
|
865
|
+
* @param {vec3} b the second operand
|
866
|
+
* @returns {Number} squared distance between a and b
|
867
|
+
*/
|
868
|
+
vec3.squaredDistance = function(a, b) {
|
869
|
+
var x = b[0] - a[0],
|
870
|
+
y = b[1] - a[1],
|
871
|
+
z = b[2] - a[2];
|
872
|
+
return x*x + y*y + z*z;
|
873
|
+
};
|
874
|
+
|
875
|
+
/**
|
876
|
+
* Alias for {@link vec3.squaredDistance}
|
877
|
+
* @function
|
878
|
+
*/
|
879
|
+
vec3.sqrDist = vec3.squaredDistance;
|
880
|
+
|
881
|
+
/**
|
882
|
+
* Calculates the length of a vec3
|
883
|
+
*
|
884
|
+
* @param {vec3} a vector to calculate length of
|
885
|
+
* @returns {Number} length of a
|
886
|
+
*/
|
887
|
+
vec3.length = function (a) {
|
888
|
+
var x = a[0],
|
889
|
+
y = a[1],
|
890
|
+
z = a[2];
|
891
|
+
return Math.sqrt(x*x + y*y + z*z);
|
892
|
+
};
|
893
|
+
|
894
|
+
/**
|
895
|
+
* Alias for {@link vec3.length}
|
896
|
+
* @function
|
897
|
+
*/
|
898
|
+
vec3.len = vec3.length;
|
899
|
+
|
900
|
+
/**
|
901
|
+
* Calculates the squared length of a vec3
|
902
|
+
*
|
903
|
+
* @param {vec3} a vector to calculate squared length of
|
904
|
+
* @returns {Number} squared length of a
|
905
|
+
*/
|
906
|
+
vec3.squaredLength = function (a) {
|
907
|
+
var x = a[0],
|
908
|
+
y = a[1],
|
909
|
+
z = a[2];
|
910
|
+
return x*x + y*y + z*z;
|
911
|
+
};
|
912
|
+
|
913
|
+
/**
|
914
|
+
* Alias for {@link vec3.squaredLength}
|
915
|
+
* @function
|
916
|
+
*/
|
917
|
+
vec3.sqrLen = vec3.squaredLength;
|
918
|
+
|
919
|
+
/**
|
920
|
+
* Negates the components of a vec3
|
921
|
+
*
|
922
|
+
* @param {vec3} out the receiving vector
|
923
|
+
* @param {vec3} a vector to negate
|
924
|
+
* @returns {vec3} out
|
925
|
+
*/
|
926
|
+
vec3.negate = function(out, a) {
|
927
|
+
out[0] = -a[0];
|
928
|
+
out[1] = -a[1];
|
929
|
+
out[2] = -a[2];
|
930
|
+
return out;
|
931
|
+
};
|
932
|
+
|
933
|
+
/**
|
934
|
+
* Normalize a vec3
|
935
|
+
*
|
936
|
+
* @param {vec3} out the receiving vector
|
937
|
+
* @param {vec3} a vector to normalize
|
938
|
+
* @returns {vec3} out
|
939
|
+
*/
|
940
|
+
vec3.normalize = function(out, a) {
|
941
|
+
var x = a[0],
|
942
|
+
y = a[1],
|
943
|
+
z = a[2];
|
944
|
+
var len = x*x + y*y + z*z;
|
945
|
+
if (len > 0) {
|
946
|
+
//TODO: evaluate use of glm_invsqrt here?
|
947
|
+
len = 1 / Math.sqrt(len);
|
948
|
+
out[0] = a[0] * len;
|
949
|
+
out[1] = a[1] * len;
|
950
|
+
out[2] = a[2] * len;
|
951
|
+
}
|
952
|
+
return out;
|
953
|
+
};
|
954
|
+
|
955
|
+
/**
|
956
|
+
* Calculates the dot product of two vec3's
|
957
|
+
*
|
958
|
+
* @param {vec3} a the first operand
|
959
|
+
* @param {vec3} b the second operand
|
960
|
+
* @returns {Number} dot product of a and b
|
961
|
+
*/
|
962
|
+
vec3.dot = function (a, b) {
|
963
|
+
return a[0] * b[0] + a[1] * b[1] + a[2] * b[2];
|
964
|
+
};
|
965
|
+
|
966
|
+
/**
|
967
|
+
* Computes the cross product of two vec3's
|
968
|
+
*
|
969
|
+
* @param {vec3} out the receiving vector
|
970
|
+
* @param {vec3} a the first operand
|
971
|
+
* @param {vec3} b the second operand
|
972
|
+
* @returns {vec3} out
|
973
|
+
*/
|
974
|
+
vec3.cross = function(out, a, b) {
|
975
|
+
var ax = a[0], ay = a[1], az = a[2],
|
976
|
+
bx = b[0], by = b[1], bz = b[2];
|
977
|
+
|
978
|
+
out[0] = ay * bz - az * by;
|
979
|
+
out[1] = az * bx - ax * bz;
|
980
|
+
out[2] = ax * by - ay * bx;
|
981
|
+
return out;
|
982
|
+
};
|
983
|
+
|
984
|
+
/**
|
985
|
+
* Performs a linear interpolation between two vec3's
|
986
|
+
*
|
987
|
+
* @param {vec3} out the receiving vector
|
988
|
+
* @param {vec3} a the first operand
|
989
|
+
* @param {vec3} b the second operand
|
990
|
+
* @param {Number} t interpolation amount between the two inputs
|
991
|
+
* @returns {vec3} out
|
992
|
+
*/
|
993
|
+
vec3.lerp = function (out, a, b, t) {
|
994
|
+
var ax = a[0],
|
995
|
+
ay = a[1],
|
996
|
+
az = a[2];
|
997
|
+
out[0] = ax + t * (b[0] - ax);
|
998
|
+
out[1] = ay + t * (b[1] - ay);
|
999
|
+
out[2] = az + t * (b[2] - az);
|
1000
|
+
return out;
|
1001
|
+
};
|
1002
|
+
|
1003
|
+
/**
|
1004
|
+
* Generates a random vector with the given scale
|
1005
|
+
*
|
1006
|
+
* @param {vec3} out the receiving vector
|
1007
|
+
* @param {Number} [scale] Length of the resulting vector. If ommitted, a unit vector will be returned
|
1008
|
+
* @returns {vec3} out
|
1009
|
+
*/
|
1010
|
+
vec3.random = function (out, scale) {
|
1011
|
+
scale = scale || 1.0;
|
1012
|
+
|
1013
|
+
var r = GLMAT_RANDOM() * 2.0 * Math.PI;
|
1014
|
+
var z = (GLMAT_RANDOM() * 2.0) - 1.0;
|
1015
|
+
var zScale = Math.sqrt(1.0-z*z) * scale;
|
1016
|
+
|
1017
|
+
out[0] = Math.cos(r) * zScale;
|
1018
|
+
out[1] = Math.sin(r) * zScale;
|
1019
|
+
out[2] = z * scale;
|
1020
|
+
return out;
|
1021
|
+
};
|
1022
|
+
|
1023
|
+
/**
|
1024
|
+
* Transforms the vec3 with a mat4.
|
1025
|
+
* 4th vector component is implicitly '1'
|
1026
|
+
*
|
1027
|
+
* @param {vec3} out the receiving vector
|
1028
|
+
* @param {vec3} a the vector to transform
|
1029
|
+
* @param {mat4} m matrix to transform with
|
1030
|
+
* @returns {vec3} out
|
1031
|
+
*/
|
1032
|
+
vec3.transformMat4 = function(out, a, m) {
|
1033
|
+
var x = a[0], y = a[1], z = a[2];
|
1034
|
+
out[0] = m[0] * x + m[4] * y + m[8] * z + m[12];
|
1035
|
+
out[1] = m[1] * x + m[5] * y + m[9] * z + m[13];
|
1036
|
+
out[2] = m[2] * x + m[6] * y + m[10] * z + m[14];
|
1037
|
+
return out;
|
1038
|
+
};
|
1039
|
+
|
1040
|
+
/**
|
1041
|
+
* Transforms the vec3 with a mat3.
|
1042
|
+
*
|
1043
|
+
* @param {vec3} out the receiving vector
|
1044
|
+
* @param {vec3} a the vector to transform
|
1045
|
+
* @param {mat4} m the 3x3 matrix to transform with
|
1046
|
+
* @returns {vec3} out
|
1047
|
+
*/
|
1048
|
+
vec3.transformMat3 = function(out, a, m) {
|
1049
|
+
var x = a[0], y = a[1], z = a[2];
|
1050
|
+
out[0] = x * m[0] + y * m[3] + z * m[6];
|
1051
|
+
out[1] = x * m[1] + y * m[4] + z * m[7];
|
1052
|
+
out[2] = x * m[2] + y * m[5] + z * m[8];
|
1053
|
+
return out;
|
1054
|
+
};
|
1055
|
+
|
1056
|
+
/**
|
1057
|
+
* Transforms the vec3 with a quat
|
1058
|
+
*
|
1059
|
+
* @param {vec3} out the receiving vector
|
1060
|
+
* @param {vec3} a the vector to transform
|
1061
|
+
* @param {quat} q quaternion to transform with
|
1062
|
+
* @returns {vec3} out
|
1063
|
+
*/
|
1064
|
+
vec3.transformQuat = function(out, a, q) {
|
1065
|
+
// benchmarks: http://jsperf.com/quaternion-transform-vec3-implementations
|
1066
|
+
|
1067
|
+
var x = a[0], y = a[1], z = a[2],
|
1068
|
+
qx = q[0], qy = q[1], qz = q[2], qw = q[3],
|
1069
|
+
|
1070
|
+
// calculate quat * vec
|
1071
|
+
ix = qw * x + qy * z - qz * y,
|
1072
|
+
iy = qw * y + qz * x - qx * z,
|
1073
|
+
iz = qw * z + qx * y - qy * x,
|
1074
|
+
iw = -qx * x - qy * y - qz * z;
|
1075
|
+
|
1076
|
+
// calculate result * inverse quat
|
1077
|
+
out[0] = ix * qw + iw * -qx + iy * -qz - iz * -qy;
|
1078
|
+
out[1] = iy * qw + iw * -qy + iz * -qx - ix * -qz;
|
1079
|
+
out[2] = iz * qw + iw * -qz + ix * -qy - iy * -qx;
|
1080
|
+
return out;
|
1081
|
+
};
|
1082
|
+
|
1083
|
+
/**
|
1084
|
+
* Perform some operation over an array of vec3s.
|
1085
|
+
*
|
1086
|
+
* @param {Array} a the array of vectors to iterate over
|
1087
|
+
* @param {Number} stride Number of elements between the start of each vec3. If 0 assumes tightly packed
|
1088
|
+
* @param {Number} offset Number of elements to skip at the beginning of the array
|
1089
|
+
* @param {Number} count Number of vec3s to iterate over. If 0 iterates over entire array
|
1090
|
+
* @param {Function} fn Function to call for each vector in the array
|
1091
|
+
* @param {Object} [arg] additional argument to pass to fn
|
1092
|
+
* @returns {Array} a
|
1093
|
+
* @function
|
1094
|
+
*/
|
1095
|
+
vec3.forEach = (function() {
|
1096
|
+
var vec = vec3.create();
|
1097
|
+
|
1098
|
+
return function(a, stride, offset, count, fn, arg) {
|
1099
|
+
var i, l;
|
1100
|
+
if(!stride) {
|
1101
|
+
stride = 3;
|
1102
|
+
}
|
1103
|
+
|
1104
|
+
if(!offset) {
|
1105
|
+
offset = 0;
|
1106
|
+
}
|
1107
|
+
|
1108
|
+
if(count) {
|
1109
|
+
l = Math.min((count * stride) + offset, a.length);
|
1110
|
+
} else {
|
1111
|
+
l = a.length;
|
1112
|
+
}
|
1113
|
+
|
1114
|
+
for(i = offset; i < l; i += stride) {
|
1115
|
+
vec[0] = a[i]; vec[1] = a[i+1]; vec[2] = a[i+2];
|
1116
|
+
fn(vec, vec, arg);
|
1117
|
+
a[i] = vec[0]; a[i+1] = vec[1]; a[i+2] = vec[2];
|
1118
|
+
}
|
1119
|
+
|
1120
|
+
return a;
|
1121
|
+
};
|
1122
|
+
})();
|
1123
|
+
|
1124
|
+
/**
|
1125
|
+
* Returns a string representation of a vector
|
1126
|
+
*
|
1127
|
+
* @param {vec3} vec vector to represent as a string
|
1128
|
+
* @returns {String} string representation of the vector
|
1129
|
+
*/
|
1130
|
+
vec3.str = function (a) {
|
1131
|
+
return 'vec3(' + a[0] + ', ' + a[1] + ', ' + a[2] + ')';
|
1132
|
+
};
|
1133
|
+
|
1134
|
+
if(typeof(exports) !== 'undefined') {
|
1135
|
+
exports.vec3 = vec3;
|
1136
|
+
}
|
1137
|
+
;
|
1138
|
+
/* Copyright (c) 2013, Brandon Jones, Colin MacKenzie IV. All rights reserved.
|
1139
|
+
|
1140
|
+
Redistribution and use in source and binary forms, with or without modification,
|
1141
|
+
are permitted provided that the following conditions are met:
|
1142
|
+
|
1143
|
+
* Redistributions of source code must retain the above copyright notice, this
|
1144
|
+
list of conditions and the following disclaimer.
|
1145
|
+
* Redistributions in binary form must reproduce the above copyright notice,
|
1146
|
+
this list of conditions and the following disclaimer in the documentation
|
1147
|
+
and/or other materials provided with the distribution.
|
1148
|
+
|
1149
|
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
1150
|
+
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
1151
|
+
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
1152
|
+
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
|
1153
|
+
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
1154
|
+
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
1155
|
+
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
1156
|
+
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
1157
|
+
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
1158
|
+
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */
|
1159
|
+
|
1160
|
+
/**
|
1161
|
+
* @class 4 Dimensional Vector
|
1162
|
+
* @name vec4
|
1163
|
+
*/
|
1164
|
+
|
1165
|
+
var vec4 = {};
|
1166
|
+
|
1167
|
+
/**
|
1168
|
+
* Creates a new, empty vec4
|
1169
|
+
*
|
1170
|
+
* @returns {vec4} a new 4D vector
|
1171
|
+
*/
|
1172
|
+
vec4.create = function() {
|
1173
|
+
var out = new GLMAT_ARRAY_TYPE(4);
|
1174
|
+
out[0] = 0;
|
1175
|
+
out[1] = 0;
|
1176
|
+
out[2] = 0;
|
1177
|
+
out[3] = 0;
|
1178
|
+
return out;
|
1179
|
+
};
|
1180
|
+
|
1181
|
+
/**
|
1182
|
+
* Creates a new vec4 initialized with values from an existing vector
|
1183
|
+
*
|
1184
|
+
* @param {vec4} a vector to clone
|
1185
|
+
* @returns {vec4} a new 4D vector
|
1186
|
+
*/
|
1187
|
+
vec4.clone = function(a) {
|
1188
|
+
var out = new GLMAT_ARRAY_TYPE(4);
|
1189
|
+
out[0] = a[0];
|
1190
|
+
out[1] = a[1];
|
1191
|
+
out[2] = a[2];
|
1192
|
+
out[3] = a[3];
|
1193
|
+
return out;
|
1194
|
+
};
|
1195
|
+
|
1196
|
+
/**
|
1197
|
+
* Creates a new vec4 initialized with the given values
|
1198
|
+
*
|
1199
|
+
* @param {Number} x X component
|
1200
|
+
* @param {Number} y Y component
|
1201
|
+
* @param {Number} z Z component
|
1202
|
+
* @param {Number} w W component
|
1203
|
+
* @returns {vec4} a new 4D vector
|
1204
|
+
*/
|
1205
|
+
vec4.fromValues = function(x, y, z, w) {
|
1206
|
+
var out = new GLMAT_ARRAY_TYPE(4);
|
1207
|
+
out[0] = x;
|
1208
|
+
out[1] = y;
|
1209
|
+
out[2] = z;
|
1210
|
+
out[3] = w;
|
1211
|
+
return out;
|
1212
|
+
};
|
1213
|
+
|
1214
|
+
/**
|
1215
|
+
* Copy the values from one vec4 to another
|
1216
|
+
*
|
1217
|
+
* @param {vec4} out the receiving vector
|
1218
|
+
* @param {vec4} a the source vector
|
1219
|
+
* @returns {vec4} out
|
1220
|
+
*/
|
1221
|
+
vec4.copy = function(out, a) {
|
1222
|
+
out[0] = a[0];
|
1223
|
+
out[1] = a[1];
|
1224
|
+
out[2] = a[2];
|
1225
|
+
out[3] = a[3];
|
1226
|
+
return out;
|
1227
|
+
};
|
1228
|
+
|
1229
|
+
/**
|
1230
|
+
* Set the components of a vec4 to the given values
|
1231
|
+
*
|
1232
|
+
* @param {vec4} out the receiving vector
|
1233
|
+
* @param {Number} x X component
|
1234
|
+
* @param {Number} y Y component
|
1235
|
+
* @param {Number} z Z component
|
1236
|
+
* @param {Number} w W component
|
1237
|
+
* @returns {vec4} out
|
1238
|
+
*/
|
1239
|
+
vec4.set = function(out, x, y, z, w) {
|
1240
|
+
out[0] = x;
|
1241
|
+
out[1] = y;
|
1242
|
+
out[2] = z;
|
1243
|
+
out[3] = w;
|
1244
|
+
return out;
|
1245
|
+
};
|
1246
|
+
|
1247
|
+
/**
|
1248
|
+
* Adds two vec4's
|
1249
|
+
*
|
1250
|
+
* @param {vec4} out the receiving vector
|
1251
|
+
* @param {vec4} a the first operand
|
1252
|
+
* @param {vec4} b the second operand
|
1253
|
+
* @returns {vec4} out
|
1254
|
+
*/
|
1255
|
+
vec4.add = function(out, a, b) {
|
1256
|
+
out[0] = a[0] + b[0];
|
1257
|
+
out[1] = a[1] + b[1];
|
1258
|
+
out[2] = a[2] + b[2];
|
1259
|
+
out[3] = a[3] + b[3];
|
1260
|
+
return out;
|
1261
|
+
};
|
1262
|
+
|
1263
|
+
/**
|
1264
|
+
* Subtracts vector b from vector a
|
1265
|
+
*
|
1266
|
+
* @param {vec4} out the receiving vector
|
1267
|
+
* @param {vec4} a the first operand
|
1268
|
+
* @param {vec4} b the second operand
|
1269
|
+
* @returns {vec4} out
|
1270
|
+
*/
|
1271
|
+
vec4.subtract = function(out, a, b) {
|
1272
|
+
out[0] = a[0] - b[0];
|
1273
|
+
out[1] = a[1] - b[1];
|
1274
|
+
out[2] = a[2] - b[2];
|
1275
|
+
out[3] = a[3] - b[3];
|
1276
|
+
return out;
|
1277
|
+
};
|
1278
|
+
|
1279
|
+
/**
|
1280
|
+
* Alias for {@link vec4.subtract}
|
1281
|
+
* @function
|
1282
|
+
*/
|
1283
|
+
vec4.sub = vec4.subtract;
|
1284
|
+
|
1285
|
+
/**
|
1286
|
+
* Multiplies two vec4's
|
1287
|
+
*
|
1288
|
+
* @param {vec4} out the receiving vector
|
1289
|
+
* @param {vec4} a the first operand
|
1290
|
+
* @param {vec4} b the second operand
|
1291
|
+
* @returns {vec4} out
|
1292
|
+
*/
|
1293
|
+
vec4.multiply = function(out, a, b) {
|
1294
|
+
out[0] = a[0] * b[0];
|
1295
|
+
out[1] = a[1] * b[1];
|
1296
|
+
out[2] = a[2] * b[2];
|
1297
|
+
out[3] = a[3] * b[3];
|
1298
|
+
return out;
|
1299
|
+
};
|
1300
|
+
|
1301
|
+
/**
|
1302
|
+
* Alias for {@link vec4.multiply}
|
1303
|
+
* @function
|
1304
|
+
*/
|
1305
|
+
vec4.mul = vec4.multiply;
|
1306
|
+
|
1307
|
+
/**
|
1308
|
+
* Divides two vec4's
|
1309
|
+
*
|
1310
|
+
* @param {vec4} out the receiving vector
|
1311
|
+
* @param {vec4} a the first operand
|
1312
|
+
* @param {vec4} b the second operand
|
1313
|
+
* @returns {vec4} out
|
1314
|
+
*/
|
1315
|
+
vec4.divide = function(out, a, b) {
|
1316
|
+
out[0] = a[0] / b[0];
|
1317
|
+
out[1] = a[1] / b[1];
|
1318
|
+
out[2] = a[2] / b[2];
|
1319
|
+
out[3] = a[3] / b[3];
|
1320
|
+
return out;
|
1321
|
+
};
|
1322
|
+
|
1323
|
+
/**
|
1324
|
+
* Alias for {@link vec4.divide}
|
1325
|
+
* @function
|
1326
|
+
*/
|
1327
|
+
vec4.div = vec4.divide;
|
1328
|
+
|
1329
|
+
/**
|
1330
|
+
* Returns the minimum of two vec4's
|
1331
|
+
*
|
1332
|
+
* @param {vec4} out the receiving vector
|
1333
|
+
* @param {vec4} a the first operand
|
1334
|
+
* @param {vec4} b the second operand
|
1335
|
+
* @returns {vec4} out
|
1336
|
+
*/
|
1337
|
+
vec4.min = function(out, a, b) {
|
1338
|
+
out[0] = Math.min(a[0], b[0]);
|
1339
|
+
out[1] = Math.min(a[1], b[1]);
|
1340
|
+
out[2] = Math.min(a[2], b[2]);
|
1341
|
+
out[3] = Math.min(a[3], b[3]);
|
1342
|
+
return out;
|
1343
|
+
};
|
1344
|
+
|
1345
|
+
/**
|
1346
|
+
* Returns the maximum of two vec4's
|
1347
|
+
*
|
1348
|
+
* @param {vec4} out the receiving vector
|
1349
|
+
* @param {vec4} a the first operand
|
1350
|
+
* @param {vec4} b the second operand
|
1351
|
+
* @returns {vec4} out
|
1352
|
+
*/
|
1353
|
+
vec4.max = function(out, a, b) {
|
1354
|
+
out[0] = Math.max(a[0], b[0]);
|
1355
|
+
out[1] = Math.max(a[1], b[1]);
|
1356
|
+
out[2] = Math.max(a[2], b[2]);
|
1357
|
+
out[3] = Math.max(a[3], b[3]);
|
1358
|
+
return out;
|
1359
|
+
};
|
1360
|
+
|
1361
|
+
/**
|
1362
|
+
* Scales a vec4 by a scalar number
|
1363
|
+
*
|
1364
|
+
* @param {vec4} out the receiving vector
|
1365
|
+
* @param {vec4} a the vector to scale
|
1366
|
+
* @param {Number} b amount to scale the vector by
|
1367
|
+
* @returns {vec4} out
|
1368
|
+
*/
|
1369
|
+
vec4.scale = function(out, a, b) {
|
1370
|
+
out[0] = a[0] * b;
|
1371
|
+
out[1] = a[1] * b;
|
1372
|
+
out[2] = a[2] * b;
|
1373
|
+
out[3] = a[3] * b;
|
1374
|
+
return out;
|
1375
|
+
};
|
1376
|
+
|
1377
|
+
/**
|
1378
|
+
* Adds two vec4's after scaling the second operand by a scalar value
|
1379
|
+
*
|
1380
|
+
* @param {vec4} out the receiving vector
|
1381
|
+
* @param {vec4} a the first operand
|
1382
|
+
* @param {vec4} b the second operand
|
1383
|
+
* @param {Number} scale the amount to scale b by before adding
|
1384
|
+
* @returns {vec4} out
|
1385
|
+
*/
|
1386
|
+
vec4.scaleAndAdd = function(out, a, b, scale) {
|
1387
|
+
out[0] = a[0] + (b[0] * scale);
|
1388
|
+
out[1] = a[1] + (b[1] * scale);
|
1389
|
+
out[2] = a[2] + (b[2] * scale);
|
1390
|
+
out[3] = a[3] + (b[3] * scale);
|
1391
|
+
return out;
|
1392
|
+
};
|
1393
|
+
|
1394
|
+
/**
|
1395
|
+
* Calculates the euclidian distance between two vec4's
|
1396
|
+
*
|
1397
|
+
* @param {vec4} a the first operand
|
1398
|
+
* @param {vec4} b the second operand
|
1399
|
+
* @returns {Number} distance between a and b
|
1400
|
+
*/
|
1401
|
+
vec4.distance = function(a, b) {
|
1402
|
+
var x = b[0] - a[0],
|
1403
|
+
y = b[1] - a[1],
|
1404
|
+
z = b[2] - a[2],
|
1405
|
+
w = b[3] - a[3];
|
1406
|
+
return Math.sqrt(x*x + y*y + z*z + w*w);
|
1407
|
+
};
|
1408
|
+
|
1409
|
+
/**
|
1410
|
+
* Alias for {@link vec4.distance}
|
1411
|
+
* @function
|
1412
|
+
*/
|
1413
|
+
vec4.dist = vec4.distance;
|
1414
|
+
|
1415
|
+
/**
|
1416
|
+
* Calculates the squared euclidian distance between two vec4's
|
1417
|
+
*
|
1418
|
+
* @param {vec4} a the first operand
|
1419
|
+
* @param {vec4} b the second operand
|
1420
|
+
* @returns {Number} squared distance between a and b
|
1421
|
+
*/
|
1422
|
+
vec4.squaredDistance = function(a, b) {
|
1423
|
+
var x = b[0] - a[0],
|
1424
|
+
y = b[1] - a[1],
|
1425
|
+
z = b[2] - a[2],
|
1426
|
+
w = b[3] - a[3];
|
1427
|
+
return x*x + y*y + z*z + w*w;
|
1428
|
+
};
|
1429
|
+
|
1430
|
+
/**
|
1431
|
+
* Alias for {@link vec4.squaredDistance}
|
1432
|
+
* @function
|
1433
|
+
*/
|
1434
|
+
vec4.sqrDist = vec4.squaredDistance;
|
1435
|
+
|
1436
|
+
/**
|
1437
|
+
* Calculates the length of a vec4
|
1438
|
+
*
|
1439
|
+
* @param {vec4} a vector to calculate length of
|
1440
|
+
* @returns {Number} length of a
|
1441
|
+
*/
|
1442
|
+
vec4.length = function (a) {
|
1443
|
+
var x = a[0],
|
1444
|
+
y = a[1],
|
1445
|
+
z = a[2],
|
1446
|
+
w = a[3];
|
1447
|
+
return Math.sqrt(x*x + y*y + z*z + w*w);
|
1448
|
+
};
|
1449
|
+
|
1450
|
+
/**
|
1451
|
+
* Alias for {@link vec4.length}
|
1452
|
+
* @function
|
1453
|
+
*/
|
1454
|
+
vec4.len = vec4.length;
|
1455
|
+
|
1456
|
+
/**
|
1457
|
+
* Calculates the squared length of a vec4
|
1458
|
+
*
|
1459
|
+
* @param {vec4} a vector to calculate squared length of
|
1460
|
+
* @returns {Number} squared length of a
|
1461
|
+
*/
|
1462
|
+
vec4.squaredLength = function (a) {
|
1463
|
+
var x = a[0],
|
1464
|
+
y = a[1],
|
1465
|
+
z = a[2],
|
1466
|
+
w = a[3];
|
1467
|
+
return x*x + y*y + z*z + w*w;
|
1468
|
+
};
|
1469
|
+
|
1470
|
+
/**
|
1471
|
+
* Alias for {@link vec4.squaredLength}
|
1472
|
+
* @function
|
1473
|
+
*/
|
1474
|
+
vec4.sqrLen = vec4.squaredLength;
|
1475
|
+
|
1476
|
+
/**
|
1477
|
+
* Negates the components of a vec4
|
1478
|
+
*
|
1479
|
+
* @param {vec4} out the receiving vector
|
1480
|
+
* @param {vec4} a vector to negate
|
1481
|
+
* @returns {vec4} out
|
1482
|
+
*/
|
1483
|
+
vec4.negate = function(out, a) {
|
1484
|
+
out[0] = -a[0];
|
1485
|
+
out[1] = -a[1];
|
1486
|
+
out[2] = -a[2];
|
1487
|
+
out[3] = -a[3];
|
1488
|
+
return out;
|
1489
|
+
};
|
1490
|
+
|
1491
|
+
/**
|
1492
|
+
* Normalize a vec4
|
1493
|
+
*
|
1494
|
+
* @param {vec4} out the receiving vector
|
1495
|
+
* @param {vec4} a vector to normalize
|
1496
|
+
* @returns {vec4} out
|
1497
|
+
*/
|
1498
|
+
vec4.normalize = function(out, a) {
|
1499
|
+
var x = a[0],
|
1500
|
+
y = a[1],
|
1501
|
+
z = a[2],
|
1502
|
+
w = a[3];
|
1503
|
+
var len = x*x + y*y + z*z + w*w;
|
1504
|
+
if (len > 0) {
|
1505
|
+
len = 1 / Math.sqrt(len);
|
1506
|
+
out[0] = a[0] * len;
|
1507
|
+
out[1] = a[1] * len;
|
1508
|
+
out[2] = a[2] * len;
|
1509
|
+
out[3] = a[3] * len;
|
1510
|
+
}
|
1511
|
+
return out;
|
1512
|
+
};
|
1513
|
+
|
1514
|
+
/**
|
1515
|
+
* Calculates the dot product of two vec4's
|
1516
|
+
*
|
1517
|
+
* @param {vec4} a the first operand
|
1518
|
+
* @param {vec4} b the second operand
|
1519
|
+
* @returns {Number} dot product of a and b
|
1520
|
+
*/
|
1521
|
+
vec4.dot = function (a, b) {
|
1522
|
+
return a[0] * b[0] + a[1] * b[1] + a[2] * b[2] + a[3] * b[3];
|
1523
|
+
};
|
1524
|
+
|
1525
|
+
/**
|
1526
|
+
* Performs a linear interpolation between two vec4's
|
1527
|
+
*
|
1528
|
+
* @param {vec4} out the receiving vector
|
1529
|
+
* @param {vec4} a the first operand
|
1530
|
+
* @param {vec4} b the second operand
|
1531
|
+
* @param {Number} t interpolation amount between the two inputs
|
1532
|
+
* @returns {vec4} out
|
1533
|
+
*/
|
1534
|
+
vec4.lerp = function (out, a, b, t) {
|
1535
|
+
var ax = a[0],
|
1536
|
+
ay = a[1],
|
1537
|
+
az = a[2],
|
1538
|
+
aw = a[3];
|
1539
|
+
out[0] = ax + t * (b[0] - ax);
|
1540
|
+
out[1] = ay + t * (b[1] - ay);
|
1541
|
+
out[2] = az + t * (b[2] - az);
|
1542
|
+
out[3] = aw + t * (b[3] - aw);
|
1543
|
+
return out;
|
1544
|
+
};
|
1545
|
+
|
1546
|
+
/**
|
1547
|
+
* Generates a random vector with the given scale
|
1548
|
+
*
|
1549
|
+
* @param {vec4} out the receiving vector
|
1550
|
+
* @param {Number} [scale] Length of the resulting vector. If ommitted, a unit vector will be returned
|
1551
|
+
* @returns {vec4} out
|
1552
|
+
*/
|
1553
|
+
vec4.random = function (out, scale) {
|
1554
|
+
scale = scale || 1.0;
|
1555
|
+
|
1556
|
+
//TODO: This is a pretty awful way of doing this. Find something better.
|
1557
|
+
out[0] = GLMAT_RANDOM();
|
1558
|
+
out[1] = GLMAT_RANDOM();
|
1559
|
+
out[2] = GLMAT_RANDOM();
|
1560
|
+
out[3] = GLMAT_RANDOM();
|
1561
|
+
vec4.normalize(out, out);
|
1562
|
+
vec4.scale(out, out, scale);
|
1563
|
+
return out;
|
1564
|
+
};
|
1565
|
+
|
1566
|
+
/**
|
1567
|
+
* Transforms the vec4 with a mat4.
|
1568
|
+
*
|
1569
|
+
* @param {vec4} out the receiving vector
|
1570
|
+
* @param {vec4} a the vector to transform
|
1571
|
+
* @param {mat4} m matrix to transform with
|
1572
|
+
* @returns {vec4} out
|
1573
|
+
*/
|
1574
|
+
vec4.transformMat4 = function(out, a, m) {
|
1575
|
+
var x = a[0], y = a[1], z = a[2], w = a[3];
|
1576
|
+
out[0] = m[0] * x + m[4] * y + m[8] * z + m[12] * w;
|
1577
|
+
out[1] = m[1] * x + m[5] * y + m[9] * z + m[13] * w;
|
1578
|
+
out[2] = m[2] * x + m[6] * y + m[10] * z + m[14] * w;
|
1579
|
+
out[3] = m[3] * x + m[7] * y + m[11] * z + m[15] * w;
|
1580
|
+
return out;
|
1581
|
+
};
|
1582
|
+
|
1583
|
+
/**
|
1584
|
+
* Transforms the vec4 with a quat
|
1585
|
+
*
|
1586
|
+
* @param {vec4} out the receiving vector
|
1587
|
+
* @param {vec4} a the vector to transform
|
1588
|
+
* @param {quat} q quaternion to transform with
|
1589
|
+
* @returns {vec4} out
|
1590
|
+
*/
|
1591
|
+
vec4.transformQuat = function(out, a, q) {
|
1592
|
+
var x = a[0], y = a[1], z = a[2],
|
1593
|
+
qx = q[0], qy = q[1], qz = q[2], qw = q[3],
|
1594
|
+
|
1595
|
+
// calculate quat * vec
|
1596
|
+
ix = qw * x + qy * z - qz * y,
|
1597
|
+
iy = qw * y + qz * x - qx * z,
|
1598
|
+
iz = qw * z + qx * y - qy * x,
|
1599
|
+
iw = -qx * x - qy * y - qz * z;
|
1600
|
+
|
1601
|
+
// calculate result * inverse quat
|
1602
|
+
out[0] = ix * qw + iw * -qx + iy * -qz - iz * -qy;
|
1603
|
+
out[1] = iy * qw + iw * -qy + iz * -qx - ix * -qz;
|
1604
|
+
out[2] = iz * qw + iw * -qz + ix * -qy - iy * -qx;
|
1605
|
+
return out;
|
1606
|
+
};
|
1607
|
+
|
1608
|
+
/**
|
1609
|
+
* Perform some operation over an array of vec4s.
|
1610
|
+
*
|
1611
|
+
* @param {Array} a the array of vectors to iterate over
|
1612
|
+
* @param {Number} stride Number of elements between the start of each vec4. If 0 assumes tightly packed
|
1613
|
+
* @param {Number} offset Number of elements to skip at the beginning of the array
|
1614
|
+
* @param {Number} count Number of vec2s to iterate over. If 0 iterates over entire array
|
1615
|
+
* @param {Function} fn Function to call for each vector in the array
|
1616
|
+
* @param {Object} [arg] additional argument to pass to fn
|
1617
|
+
* @returns {Array} a
|
1618
|
+
* @function
|
1619
|
+
*/
|
1620
|
+
vec4.forEach = (function() {
|
1621
|
+
var vec = vec4.create();
|
1622
|
+
|
1623
|
+
return function(a, stride, offset, count, fn, arg) {
|
1624
|
+
var i, l;
|
1625
|
+
if(!stride) {
|
1626
|
+
stride = 4;
|
1627
|
+
}
|
1628
|
+
|
1629
|
+
if(!offset) {
|
1630
|
+
offset = 0;
|
1631
|
+
}
|
1632
|
+
|
1633
|
+
if(count) {
|
1634
|
+
l = Math.min((count * stride) + offset, a.length);
|
1635
|
+
} else {
|
1636
|
+
l = a.length;
|
1637
|
+
}
|
1638
|
+
|
1639
|
+
for(i = offset; i < l; i += stride) {
|
1640
|
+
vec[0] = a[i]; vec[1] = a[i+1]; vec[2] = a[i+2]; vec[3] = a[i+3];
|
1641
|
+
fn(vec, vec, arg);
|
1642
|
+
a[i] = vec[0]; a[i+1] = vec[1]; a[i+2] = vec[2]; a[i+3] = vec[3];
|
1643
|
+
}
|
1644
|
+
|
1645
|
+
return a;
|
1646
|
+
};
|
1647
|
+
})();
|
1648
|
+
|
1649
|
+
/**
|
1650
|
+
* Returns a string representation of a vector
|
1651
|
+
*
|
1652
|
+
* @param {vec4} vec vector to represent as a string
|
1653
|
+
* @returns {String} string representation of the vector
|
1654
|
+
*/
|
1655
|
+
vec4.str = function (a) {
|
1656
|
+
return 'vec4(' + a[0] + ', ' + a[1] + ', ' + a[2] + ', ' + a[3] + ')';
|
1657
|
+
};
|
1658
|
+
|
1659
|
+
if(typeof(exports) !== 'undefined') {
|
1660
|
+
exports.vec4 = vec4;
|
1661
|
+
}
|
1662
|
+
;
|
1663
|
+
/* Copyright (c) 2013, Brandon Jones, Colin MacKenzie IV. All rights reserved.
|
1664
|
+
|
1665
|
+
Redistribution and use in source and binary forms, with or without modification,
|
1666
|
+
are permitted provided that the following conditions are met:
|
1667
|
+
|
1668
|
+
* Redistributions of source code must retain the above copyright notice, this
|
1669
|
+
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.
|
1673
|
+
|
1674
|
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
1675
|
+
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
1676
|
+
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
1677
|
+
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
|
1678
|
+
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
1679
|
+
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
1680
|
+
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
1681
|
+
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
1682
|
+
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
1683
|
+
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */
|
1684
|
+
|
1685
|
+
/**
|
1686
|
+
* @class 2x2 Matrix
|
1687
|
+
* @name mat2
|
1688
|
+
*/
|
1689
|
+
|
1690
|
+
var mat2 = {};
|
1691
|
+
|
1692
|
+
/**
|
1693
|
+
* Creates a new identity mat2
|
1694
|
+
*
|
1695
|
+
* @returns {mat2} a new 2x2 matrix
|
1696
|
+
*/
|
1697
|
+
mat2.create = function() {
|
1698
|
+
var out = new GLMAT_ARRAY_TYPE(4);
|
1699
|
+
out[0] = 1;
|
1700
|
+
out[1] = 0;
|
1701
|
+
out[2] = 0;
|
1702
|
+
out[3] = 1;
|
1703
|
+
return out;
|
1704
|
+
};
|
1705
|
+
|
1706
|
+
/**
|
1707
|
+
* Creates a new mat2 initialized with values from an existing matrix
|
1708
|
+
*
|
1709
|
+
* @param {mat2} a matrix to clone
|
1710
|
+
* @returns {mat2} a new 2x2 matrix
|
1711
|
+
*/
|
1712
|
+
mat2.clone = function(a) {
|
1713
|
+
var out = new GLMAT_ARRAY_TYPE(4);
|
1714
|
+
out[0] = a[0];
|
1715
|
+
out[1] = a[1];
|
1716
|
+
out[2] = a[2];
|
1717
|
+
out[3] = a[3];
|
1718
|
+
return out;
|
1719
|
+
};
|
1720
|
+
|
1721
|
+
/**
|
1722
|
+
* Copy the values from one mat2 to another
|
1723
|
+
*
|
1724
|
+
* @param {mat2} out the receiving matrix
|
1725
|
+
* @param {mat2} a the source matrix
|
1726
|
+
* @returns {mat2} out
|
1727
|
+
*/
|
1728
|
+
mat2.copy = function(out, a) {
|
1729
|
+
out[0] = a[0];
|
1730
|
+
out[1] = a[1];
|
1731
|
+
out[2] = a[2];
|
1732
|
+
out[3] = a[3];
|
1733
|
+
return out;
|
1734
|
+
};
|
1735
|
+
|
1736
|
+
/**
|
1737
|
+
* Set a mat2 to the identity matrix
|
1738
|
+
*
|
1739
|
+
* @param {mat2} out the receiving matrix
|
1740
|
+
* @returns {mat2} out
|
1741
|
+
*/
|
1742
|
+
mat2.identity = function(out) {
|
1743
|
+
out[0] = 1;
|
1744
|
+
out[1] = 0;
|
1745
|
+
out[2] = 0;
|
1746
|
+
out[3] = 1;
|
1747
|
+
return out;
|
1748
|
+
};
|
1749
|
+
|
1750
|
+
/**
|
1751
|
+
* Transpose the values of a mat2
|
1752
|
+
*
|
1753
|
+
* @param {mat2} out the receiving matrix
|
1754
|
+
* @param {mat2} a the source matrix
|
1755
|
+
* @returns {mat2} out
|
1756
|
+
*/
|
1757
|
+
mat2.transpose = function(out, a) {
|
1758
|
+
// If we are transposing ourselves we can skip a few steps but have to cache some values
|
1759
|
+
if (out === a) {
|
1760
|
+
var a1 = a[1];
|
1761
|
+
out[1] = a[2];
|
1762
|
+
out[2] = a1;
|
1763
|
+
} else {
|
1764
|
+
out[0] = a[0];
|
1765
|
+
out[1] = a[2];
|
1766
|
+
out[2] = a[1];
|
1767
|
+
out[3] = a[3];
|
1768
|
+
}
|
1769
|
+
|
1770
|
+
return out;
|
1771
|
+
};
|
1772
|
+
|
1773
|
+
/**
|
1774
|
+
* Inverts a mat2
|
1775
|
+
*
|
1776
|
+
* @param {mat2} out the receiving matrix
|
1777
|
+
* @param {mat2} a the source matrix
|
1778
|
+
* @returns {mat2} out
|
1779
|
+
*/
|
1780
|
+
mat2.invert = function(out, a) {
|
1781
|
+
var a0 = a[0], a1 = a[1], a2 = a[2], a3 = a[3],
|
1782
|
+
|
1783
|
+
// Calculate the determinant
|
1784
|
+
det = a0 * a3 - a2 * a1;
|
1785
|
+
|
1786
|
+
if (!det) {
|
1787
|
+
return null;
|
1788
|
+
}
|
1789
|
+
det = 1.0 / det;
|
1790
|
+
|
1791
|
+
out[0] = a3 * det;
|
1792
|
+
out[1] = -a1 * det;
|
1793
|
+
out[2] = -a2 * det;
|
1794
|
+
out[3] = a0 * det;
|
1795
|
+
|
1796
|
+
return out;
|
1797
|
+
};
|
1798
|
+
|
1799
|
+
/**
|
1800
|
+
* Calculates the adjugate of a mat2
|
1801
|
+
*
|
1802
|
+
* @param {mat2} out the receiving matrix
|
1803
|
+
* @param {mat2} a the source matrix
|
1804
|
+
* @returns {mat2} out
|
1805
|
+
*/
|
1806
|
+
mat2.adjoint = function(out, a) {
|
1807
|
+
// Caching this value is nessecary if out == a
|
1808
|
+
var a0 = a[0];
|
1809
|
+
out[0] = a[3];
|
1810
|
+
out[1] = -a[1];
|
1811
|
+
out[2] = -a[2];
|
1812
|
+
out[3] = a0;
|
1813
|
+
|
1814
|
+
return out;
|
1815
|
+
};
|
1816
|
+
|
1817
|
+
/**
|
1818
|
+
* Calculates the determinant of a mat2
|
1819
|
+
*
|
1820
|
+
* @param {mat2} a the source matrix
|
1821
|
+
* @returns {Number} determinant of a
|
1822
|
+
*/
|
1823
|
+
mat2.determinant = function (a) {
|
1824
|
+
return a[0] * a[3] - a[2] * a[1];
|
1825
|
+
};
|
1826
|
+
|
1827
|
+
/**
|
1828
|
+
* Multiplies two mat2's
|
1829
|
+
*
|
1830
|
+
* @param {mat2} out the receiving matrix
|
1831
|
+
* @param {mat2} a the first operand
|
1832
|
+
* @param {mat2} b the second operand
|
1833
|
+
* @returns {mat2} out
|
1834
|
+
*/
|
1835
|
+
mat2.multiply = function (out, a, b) {
|
1836
|
+
var a0 = a[0], a1 = a[1], a2 = a[2], a3 = a[3];
|
1837
|
+
var b0 = b[0], b1 = b[1], b2 = b[2], b3 = b[3];
|
1838
|
+
out[0] = a0 * b0 + a1 * b2;
|
1839
|
+
out[1] = a0 * b1 + a1 * b3;
|
1840
|
+
out[2] = a2 * b0 + a3 * b2;
|
1841
|
+
out[3] = a2 * b1 + a3 * b3;
|
1842
|
+
return out;
|
1843
|
+
};
|
1844
|
+
|
1845
|
+
/**
|
1846
|
+
* Alias for {@link mat2.multiply}
|
1847
|
+
* @function
|
1848
|
+
*/
|
1849
|
+
mat2.mul = mat2.multiply;
|
1850
|
+
|
1851
|
+
/**
|
1852
|
+
* Rotates a mat2 by the given angle
|
1853
|
+
*
|
1854
|
+
* @param {mat2} out the receiving matrix
|
1855
|
+
* @param {mat2} a the matrix to rotate
|
1856
|
+
* @param {Number} rad the angle to rotate the matrix by
|
1857
|
+
* @returns {mat2} out
|
1858
|
+
*/
|
1859
|
+
mat2.rotate = function (out, a, rad) {
|
1860
|
+
var a0 = a[0], a1 = a[1], a2 = a[2], a3 = a[3],
|
1861
|
+
s = Math.sin(rad),
|
1862
|
+
c = Math.cos(rad);
|
1863
|
+
out[0] = a0 * c + a1 * s;
|
1864
|
+
out[1] = a0 * -s + a1 * c;
|
1865
|
+
out[2] = a2 * c + a3 * s;
|
1866
|
+
out[3] = a2 * -s + a3 * c;
|
1867
|
+
return out;
|
1868
|
+
};
|
1869
|
+
|
1870
|
+
/**
|
1871
|
+
* Scales the mat2 by the dimensions in the given vec2
|
1872
|
+
*
|
1873
|
+
* @param {mat2} out the receiving matrix
|
1874
|
+
* @param {mat2} a the matrix to rotate
|
1875
|
+
* @param {vec2} v the vec2 to scale the matrix by
|
1876
|
+
* @returns {mat2} out
|
1877
|
+
**/
|
1878
|
+
mat2.scale = function(out, a, v) {
|
1879
|
+
var a0 = a[0], a1 = a[1], a2 = a[2], a3 = a[3],
|
1880
|
+
v0 = v[0], v1 = v[1];
|
1881
|
+
out[0] = a0 * v0;
|
1882
|
+
out[1] = a1 * v1;
|
1883
|
+
out[2] = a2 * v0;
|
1884
|
+
out[3] = a3 * v1;
|
1885
|
+
return out;
|
1886
|
+
};
|
1887
|
+
|
1888
|
+
/**
|
1889
|
+
* Returns a string representation of a mat2
|
1890
|
+
*
|
1891
|
+
* @param {mat2} mat matrix to represent as a string
|
1892
|
+
* @returns {String} string representation of the matrix
|
1893
|
+
*/
|
1894
|
+
mat2.str = function (a) {
|
1895
|
+
return 'mat2(' + a[0] + ', ' + a[1] + ', ' + a[2] + ', ' + a[3] + ')';
|
1896
|
+
};
|
1897
|
+
|
1898
|
+
if(typeof(exports) !== 'undefined') {
|
1899
|
+
exports.mat2 = mat2;
|
1900
|
+
}
|
1901
|
+
;
|
1902
|
+
/* Copyright (c) 2013, Brandon Jones, Colin MacKenzie IV. All rights reserved.
|
1903
|
+
|
1904
|
+
Redistribution and use in source and binary forms, with or without modification,
|
1905
|
+
are permitted provided that the following conditions are met:
|
1906
|
+
|
1907
|
+
* Redistributions of source code must retain the above copyright notice, this
|
1908
|
+
list of conditions and the following disclaimer.
|
1909
|
+
* Redistributions in binary form must reproduce the above copyright notice,
|
1910
|
+
this list of conditions and the following disclaimer in the documentation
|
1911
|
+
and/or other materials provided with the distribution.
|
1912
|
+
|
1913
|
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
1914
|
+
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
1915
|
+
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
1916
|
+
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
|
1917
|
+
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
1918
|
+
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
1919
|
+
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
1920
|
+
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
1921
|
+
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
1922
|
+
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */
|
1923
|
+
|
1924
|
+
/**
|
1925
|
+
* @class 2x3 Matrix
|
1926
|
+
* @name mat2d
|
1927
|
+
*
|
1928
|
+
* @description
|
1929
|
+
* A mat2d contains six elements defined as:
|
1930
|
+
* <pre>
|
1931
|
+
* [a, b,
|
1932
|
+
* c, d,
|
1933
|
+
* tx,ty]
|
1934
|
+
* </pre>
|
1935
|
+
* This is a short form for the 3x3 matrix:
|
1936
|
+
* <pre>
|
1937
|
+
* [a, b, 0
|
1938
|
+
* c, d, 0
|
1939
|
+
* tx,ty,1]
|
1940
|
+
* </pre>
|
1941
|
+
* The last column is ignored so the array is shorter and operations are faster.
|
1942
|
+
*/
|
1943
|
+
|
1944
|
+
var mat2d = {};
|
1945
|
+
|
1946
|
+
/**
|
1947
|
+
* Creates a new identity mat2d
|
1948
|
+
*
|
1949
|
+
* @returns {mat2d} a new 2x3 matrix
|
1950
|
+
*/
|
1951
|
+
mat2d.create = function() {
|
1952
|
+
var out = new GLMAT_ARRAY_TYPE(6);
|
1953
|
+
out[0] = 1;
|
1954
|
+
out[1] = 0;
|
1955
|
+
out[2] = 0;
|
1956
|
+
out[3] = 1;
|
1957
|
+
out[4] = 0;
|
1958
|
+
out[5] = 0;
|
1959
|
+
return out;
|
1960
|
+
};
|
1961
|
+
|
1962
|
+
/**
|
1963
|
+
* Creates a new mat2d initialized with values from an existing matrix
|
1964
|
+
*
|
1965
|
+
* @param {mat2d} a matrix to clone
|
1966
|
+
* @returns {mat2d} a new 2x3 matrix
|
1967
|
+
*/
|
1968
|
+
mat2d.clone = function(a) {
|
1969
|
+
var out = new GLMAT_ARRAY_TYPE(6);
|
1970
|
+
out[0] = a[0];
|
1971
|
+
out[1] = a[1];
|
1972
|
+
out[2] = a[2];
|
1973
|
+
out[3] = a[3];
|
1974
|
+
out[4] = a[4];
|
1975
|
+
out[5] = a[5];
|
1976
|
+
return out;
|
1977
|
+
};
|
1978
|
+
|
1979
|
+
/**
|
1980
|
+
* Copy the values from one mat2d to another
|
1981
|
+
*
|
1982
|
+
* @param {mat2d} out the receiving matrix
|
1983
|
+
* @param {mat2d} a the source matrix
|
1984
|
+
* @returns {mat2d} out
|
1985
|
+
*/
|
1986
|
+
mat2d.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
|
+
return out;
|
1994
|
+
};
|
1995
|
+
|
1996
|
+
/**
|
1997
|
+
* Set a mat2d to the identity matrix
|
1998
|
+
*
|
1999
|
+
* @param {mat2d} out the receiving matrix
|
2000
|
+
* @returns {mat2d} out
|
2001
|
+
*/
|
2002
|
+
mat2d.identity = function(out) {
|
2003
|
+
out[0] = 1;
|
2004
|
+
out[1] = 0;
|
2005
|
+
out[2] = 0;
|
2006
|
+
out[3] = 1;
|
2007
|
+
out[4] = 0;
|
2008
|
+
out[5] = 0;
|
2009
|
+
return out;
|
2010
|
+
};
|
2011
|
+
|
2012
|
+
/**
|
2013
|
+
* Inverts a mat2d
|
2014
|
+
*
|
2015
|
+
* @param {mat2d} out the receiving matrix
|
2016
|
+
* @param {mat2d} a the source matrix
|
2017
|
+
* @returns {mat2d} out
|
2018
|
+
*/
|
2019
|
+
mat2d.invert = function(out, a) {
|
2020
|
+
var aa = a[0], ab = a[1], ac = a[2], ad = a[3],
|
2021
|
+
atx = a[4], aty = a[5];
|
2022
|
+
|
2023
|
+
var det = aa * ad - ab * ac;
|
2024
|
+
if(!det){
|
2025
|
+
return null;
|
2026
|
+
}
|
2027
|
+
det = 1.0 / det;
|
2028
|
+
|
2029
|
+
out[0] = ad * det;
|
2030
|
+
out[1] = -ab * det;
|
2031
|
+
out[2] = -ac * det;
|
2032
|
+
out[3] = aa * det;
|
2033
|
+
out[4] = (ac * aty - ad * atx) * det;
|
2034
|
+
out[5] = (ab * atx - aa * aty) * det;
|
2035
|
+
return out;
|
2036
|
+
};
|
2037
|
+
|
2038
|
+
/**
|
2039
|
+
* Calculates the determinant of a mat2d
|
2040
|
+
*
|
2041
|
+
* @param {mat2d} a the source matrix
|
2042
|
+
* @returns {Number} determinant of a
|
2043
|
+
*/
|
2044
|
+
mat2d.determinant = function (a) {
|
2045
|
+
return a[0] * a[3] - a[1] * a[2];
|
2046
|
+
};
|
2047
|
+
|
2048
|
+
/**
|
2049
|
+
* Multiplies two mat2d's
|
2050
|
+
*
|
2051
|
+
* @param {mat2d} out the receiving matrix
|
2052
|
+
* @param {mat2d} a the first operand
|
2053
|
+
* @param {mat2d} b the second operand
|
2054
|
+
* @returns {mat2d} out
|
2055
|
+
*/
|
2056
|
+
mat2d.multiply = function (out, a, b) {
|
2057
|
+
var aa = a[0], ab = a[1], ac = a[2], ad = a[3],
|
2058
|
+
atx = a[4], aty = a[5],
|
2059
|
+
ba = b[0], bb = b[1], bc = b[2], bd = b[3],
|
2060
|
+
btx = b[4], bty = b[5];
|
2061
|
+
|
2062
|
+
out[0] = aa*ba + ab*bc;
|
2063
|
+
out[1] = aa*bb + ab*bd;
|
2064
|
+
out[2] = ac*ba + ad*bc;
|
2065
|
+
out[3] = ac*bb + ad*bd;
|
2066
|
+
out[4] = ba*atx + bc*aty + btx;
|
2067
|
+
out[5] = bb*atx + bd*aty + bty;
|
2068
|
+
return out;
|
2069
|
+
};
|
2070
|
+
|
2071
|
+
/**
|
2072
|
+
* Alias for {@link mat2d.multiply}
|
2073
|
+
* @function
|
2074
|
+
*/
|
2075
|
+
mat2d.mul = mat2d.multiply;
|
2076
|
+
|
2077
|
+
|
2078
|
+
/**
|
2079
|
+
* Rotates a mat2d by the given angle
|
2080
|
+
*
|
2081
|
+
* @param {mat2d} out the receiving matrix
|
2082
|
+
* @param {mat2d} a the matrix to rotate
|
2083
|
+
* @param {Number} rad the angle to rotate the matrix by
|
2084
|
+
* @returns {mat2d} out
|
2085
|
+
*/
|
2086
|
+
mat2d.rotate = function (out, a, rad) {
|
2087
|
+
var aa = a[0],
|
2088
|
+
ab = a[1],
|
2089
|
+
ac = a[2],
|
2090
|
+
ad = a[3],
|
2091
|
+
atx = a[4],
|
2092
|
+
aty = a[5],
|
2093
|
+
st = Math.sin(rad),
|
2094
|
+
ct = Math.cos(rad);
|
2095
|
+
|
2096
|
+
out[0] = aa*ct + ab*st;
|
2097
|
+
out[1] = -aa*st + ab*ct;
|
2098
|
+
out[2] = ac*ct + ad*st;
|
2099
|
+
out[3] = -ac*st + ct*ad;
|
2100
|
+
out[4] = ct*atx + st*aty;
|
2101
|
+
out[5] = ct*aty - st*atx;
|
2102
|
+
return out;
|
2103
|
+
};
|
2104
|
+
|
2105
|
+
/**
|
2106
|
+
* Scales the mat2d by the dimensions in the given vec2
|
2107
|
+
*
|
2108
|
+
* @param {mat2d} out the receiving matrix
|
2109
|
+
* @param {mat2d} a the matrix to translate
|
2110
|
+
* @param {vec2} v the vec2 to scale the matrix by
|
2111
|
+
* @returns {mat2d} out
|
2112
|
+
**/
|
2113
|
+
mat2d.scale = function(out, a, v) {
|
2114
|
+
var vx = v[0], vy = v[1];
|
2115
|
+
out[0] = a[0] * vx;
|
2116
|
+
out[1] = a[1] * vy;
|
2117
|
+
out[2] = a[2] * vx;
|
2118
|
+
out[3] = a[3] * vy;
|
2119
|
+
out[4] = a[4] * vx;
|
2120
|
+
out[5] = a[5] * vy;
|
2121
|
+
return out;
|
2122
|
+
};
|
2123
|
+
|
2124
|
+
/**
|
2125
|
+
* Translates the mat2d by the dimensions in the given vec2
|
2126
|
+
*
|
2127
|
+
* @param {mat2d} out the receiving matrix
|
2128
|
+
* @param {mat2d} a the matrix to translate
|
2129
|
+
* @param {vec2} v the vec2 to translate the matrix by
|
2130
|
+
* @returns {mat2d} out
|
2131
|
+
**/
|
2132
|
+
mat2d.translate = function(out, a, v) {
|
2133
|
+
out[0] = a[0];
|
2134
|
+
out[1] = a[1];
|
2135
|
+
out[2] = a[2];
|
2136
|
+
out[3] = a[3];
|
2137
|
+
out[4] = a[4] + v[0];
|
2138
|
+
out[5] = a[5] + v[1];
|
2139
|
+
return out;
|
2140
|
+
};
|
2141
|
+
|
2142
|
+
/**
|
2143
|
+
* Returns a string representation of a mat2d
|
2144
|
+
*
|
2145
|
+
* @param {mat2d} a matrix to represent as a string
|
2146
|
+
* @returns {String} string representation of the matrix
|
2147
|
+
*/
|
2148
|
+
mat2d.str = function (a) {
|
2149
|
+
return 'mat2d(' + a[0] + ', ' + a[1] + ', ' + a[2] + ', ' +
|
2150
|
+
a[3] + ', ' + a[4] + ', ' + a[5] + ')';
|
2151
|
+
};
|
2152
|
+
|
2153
|
+
if(typeof(exports) !== 'undefined') {
|
2154
|
+
exports.mat2d = mat2d;
|
2155
|
+
}
|
2156
|
+
;
|
2157
|
+
/* Copyright (c) 2013, Brandon Jones, Colin MacKenzie IV. All rights reserved.
|
2158
|
+
|
2159
|
+
Redistribution and use in source and binary forms, with or without modification,
|
2160
|
+
are permitted provided that the following conditions are met:
|
2161
|
+
|
2162
|
+
* Redistributions of source code must retain the above copyright notice, this
|
2163
|
+
list of conditions and the following disclaimer.
|
2164
|
+
* Redistributions in binary form must reproduce the above copyright notice,
|
2165
|
+
this list of conditions and the following disclaimer in the documentation
|
2166
|
+
and/or other materials provided with the distribution.
|
2167
|
+
|
2168
|
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
2169
|
+
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
2170
|
+
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
2171
|
+
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
|
2172
|
+
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
2173
|
+
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
2174
|
+
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
2175
|
+
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
2176
|
+
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
2177
|
+
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */
|
2178
|
+
|
2179
|
+
/**
|
2180
|
+
* @class 3x3 Matrix
|
2181
|
+
* @name mat3
|
2182
|
+
*/
|
2183
|
+
|
2184
|
+
var mat3 = {};
|
2185
|
+
|
2186
|
+
/**
|
2187
|
+
* Creates a new identity mat3
|
2188
|
+
*
|
2189
|
+
* @returns {mat3} a new 3x3 matrix
|
2190
|
+
*/
|
2191
|
+
mat3.create = function() {
|
2192
|
+
var out = new GLMAT_ARRAY_TYPE(9);
|
2193
|
+
out[0] = 1;
|
2194
|
+
out[1] = 0;
|
2195
|
+
out[2] = 0;
|
2196
|
+
out[3] = 0;
|
2197
|
+
out[4] = 1;
|
2198
|
+
out[5] = 0;
|
2199
|
+
out[6] = 0;
|
2200
|
+
out[7] = 0;
|
2201
|
+
out[8] = 1;
|
2202
|
+
return out;
|
2203
|
+
};
|
2204
|
+
|
2205
|
+
/**
|
2206
|
+
* Copies the upper-left 3x3 values into the given mat3.
|
2207
|
+
*
|
2208
|
+
* @param {mat3} out the receiving 3x3 matrix
|
2209
|
+
* @param {mat4} a the source 4x4 matrix
|
2210
|
+
* @returns {mat3} out
|
2211
|
+
*/
|
2212
|
+
mat3.fromMat4 = function(out, a) {
|
2213
|
+
out[0] = a[0];
|
2214
|
+
out[1] = a[1];
|
2215
|
+
out[2] = a[2];
|
2216
|
+
out[3] = a[4];
|
2217
|
+
out[4] = a[5];
|
2218
|
+
out[5] = a[6];
|
2219
|
+
out[6] = a[8];
|
2220
|
+
out[7] = a[9];
|
2221
|
+
out[8] = a[10];
|
2222
|
+
return out;
|
2223
|
+
};
|
2224
|
+
|
2225
|
+
/**
|
2226
|
+
* Creates a new mat3 initialized with values from an existing matrix
|
2227
|
+
*
|
2228
|
+
* @param {mat3} a matrix to clone
|
2229
|
+
* @returns {mat3} a new 3x3 matrix
|
2230
|
+
*/
|
2231
|
+
mat3.clone = function(a) {
|
2232
|
+
var out = new GLMAT_ARRAY_TYPE(9);
|
2233
|
+
out[0] = a[0];
|
2234
|
+
out[1] = a[1];
|
2235
|
+
out[2] = a[2];
|
2236
|
+
out[3] = a[3];
|
2237
|
+
out[4] = a[4];
|
2238
|
+
out[5] = a[5];
|
2239
|
+
out[6] = a[6];
|
2240
|
+
out[7] = a[7];
|
2241
|
+
out[8] = a[8];
|
2242
|
+
return out;
|
2243
|
+
};
|
2244
|
+
|
2245
|
+
/**
|
2246
|
+
* Copy the values from one mat3 to another
|
2247
|
+
*
|
2248
|
+
* @param {mat3} out the receiving matrix
|
2249
|
+
* @param {mat3} a the source matrix
|
2250
|
+
* @returns {mat3} out
|
2251
|
+
*/
|
2252
|
+
mat3.copy = function(out, a) {
|
2253
|
+
out[0] = a[0];
|
2254
|
+
out[1] = a[1];
|
2255
|
+
out[2] = a[2];
|
2256
|
+
out[3] = a[3];
|
2257
|
+
out[4] = a[4];
|
2258
|
+
out[5] = a[5];
|
2259
|
+
out[6] = a[6];
|
2260
|
+
out[7] = a[7];
|
2261
|
+
out[8] = a[8];
|
2262
|
+
return out;
|
2263
|
+
};
|
2264
|
+
|
2265
|
+
/**
|
2266
|
+
* Set a mat3 to the identity matrix
|
2267
|
+
*
|
2268
|
+
* @param {mat3} out the receiving matrix
|
2269
|
+
* @returns {mat3} out
|
2270
|
+
*/
|
2271
|
+
mat3.identity = function(out) {
|
2272
|
+
out[0] = 1;
|
2273
|
+
out[1] = 0;
|
2274
|
+
out[2] = 0;
|
2275
|
+
out[3] = 0;
|
2276
|
+
out[4] = 1;
|
2277
|
+
out[5] = 0;
|
2278
|
+
out[6] = 0;
|
2279
|
+
out[7] = 0;
|
2280
|
+
out[8] = 1;
|
2281
|
+
return out;
|
2282
|
+
};
|
2283
|
+
|
2284
|
+
/**
|
2285
|
+
* Transpose the values of a mat3
|
2286
|
+
*
|
2287
|
+
* @param {mat3} out the receiving matrix
|
2288
|
+
* @param {mat3} a the source matrix
|
2289
|
+
* @returns {mat3} out
|
2290
|
+
*/
|
2291
|
+
mat3.transpose = function(out, a) {
|
2292
|
+
// If we are transposing ourselves we can skip a few steps but have to cache some values
|
2293
|
+
if (out === a) {
|
2294
|
+
var a01 = a[1], a02 = a[2], a12 = a[5];
|
2295
|
+
out[1] = a[3];
|
2296
|
+
out[2] = a[6];
|
2297
|
+
out[3] = a01;
|
2298
|
+
out[5] = a[7];
|
2299
|
+
out[6] = a02;
|
2300
|
+
out[7] = a12;
|
2301
|
+
} else {
|
2302
|
+
out[0] = a[0];
|
2303
|
+
out[1] = a[3];
|
2304
|
+
out[2] = a[6];
|
2305
|
+
out[3] = a[1];
|
2306
|
+
out[4] = a[4];
|
2307
|
+
out[5] = a[7];
|
2308
|
+
out[6] = a[2];
|
2309
|
+
out[7] = a[5];
|
2310
|
+
out[8] = a[8];
|
2311
|
+
}
|
2312
|
+
|
2313
|
+
return out;
|
2314
|
+
};
|
2315
|
+
|
2316
|
+
/**
|
2317
|
+
* Inverts a mat3
|
2318
|
+
*
|
2319
|
+
* @param {mat3} out the receiving matrix
|
2320
|
+
* @param {mat3} a the source matrix
|
2321
|
+
* @returns {mat3} out
|
2322
|
+
*/
|
2323
|
+
mat3.invert = function(out, a) {
|
2324
|
+
var a00 = a[0], a01 = a[1], a02 = a[2],
|
2325
|
+
a10 = a[3], a11 = a[4], a12 = a[5],
|
2326
|
+
a20 = a[6], a21 = a[7], a22 = a[8],
|
2327
|
+
|
2328
|
+
b01 = a22 * a11 - a12 * a21,
|
2329
|
+
b11 = -a22 * a10 + a12 * a20,
|
2330
|
+
b21 = a21 * a10 - a11 * a20,
|
2331
|
+
|
2332
|
+
// Calculate the determinant
|
2333
|
+
det = a00 * b01 + a01 * b11 + a02 * b21;
|
2334
|
+
|
2335
|
+
if (!det) {
|
2336
|
+
return null;
|
2337
|
+
}
|
2338
|
+
det = 1.0 / det;
|
2339
|
+
|
2340
|
+
out[0] = b01 * det;
|
2341
|
+
out[1] = (-a22 * a01 + a02 * a21) * det;
|
2342
|
+
out[2] = (a12 * a01 - a02 * a11) * det;
|
2343
|
+
out[3] = b11 * det;
|
2344
|
+
out[4] = (a22 * a00 - a02 * a20) * det;
|
2345
|
+
out[5] = (-a12 * a00 + a02 * a10) * det;
|
2346
|
+
out[6] = b21 * det;
|
2347
|
+
out[7] = (-a21 * a00 + a01 * a20) * det;
|
2348
|
+
out[8] = (a11 * a00 - a01 * a10) * det;
|
2349
|
+
return out;
|
2350
|
+
};
|
2351
|
+
|
2352
|
+
/**
|
2353
|
+
* Calculates the adjugate of a mat3
|
2354
|
+
*
|
2355
|
+
* @param {mat3} out the receiving matrix
|
2356
|
+
* @param {mat3} a the source matrix
|
2357
|
+
* @returns {mat3} out
|
2358
|
+
*/
|
2359
|
+
mat3.adjoint = function(out, a) {
|
2360
|
+
var a00 = a[0], a01 = a[1], a02 = a[2],
|
2361
|
+
a10 = a[3], a11 = a[4], a12 = a[5],
|
2362
|
+
a20 = a[6], a21 = a[7], a22 = a[8];
|
2363
|
+
|
2364
|
+
out[0] = (a11 * a22 - a12 * a21);
|
2365
|
+
out[1] = (a02 * a21 - a01 * a22);
|
2366
|
+
out[2] = (a01 * a12 - a02 * a11);
|
2367
|
+
out[3] = (a12 * a20 - a10 * a22);
|
2368
|
+
out[4] = (a00 * a22 - a02 * a20);
|
2369
|
+
out[5] = (a02 * a10 - a00 * a12);
|
2370
|
+
out[6] = (a10 * a21 - a11 * a20);
|
2371
|
+
out[7] = (a01 * a20 - a00 * a21);
|
2372
|
+
out[8] = (a00 * a11 - a01 * a10);
|
2373
|
+
return out;
|
2374
|
+
};
|
2375
|
+
|
2376
|
+
/**
|
2377
|
+
* Calculates the determinant of a mat3
|
2378
|
+
*
|
2379
|
+
* @param {mat3} a the source matrix
|
2380
|
+
* @returns {Number} determinant of a
|
2381
|
+
*/
|
2382
|
+
mat3.determinant = function (a) {
|
2383
|
+
var a00 = a[0], a01 = a[1], a02 = a[2],
|
2384
|
+
a10 = a[3], a11 = a[4], a12 = a[5],
|
2385
|
+
a20 = a[6], a21 = a[7], a22 = a[8];
|
2386
|
+
|
2387
|
+
return a00 * (a22 * a11 - a12 * a21) + a01 * (-a22 * a10 + a12 * a20) + a02 * (a21 * a10 - a11 * a20);
|
2388
|
+
};
|
2389
|
+
|
2390
|
+
/**
|
2391
|
+
* Multiplies two mat3's
|
2392
|
+
*
|
2393
|
+
* @param {mat3} out the receiving matrix
|
2394
|
+
* @param {mat3} a the first operand
|
2395
|
+
* @param {mat3} b the second operand
|
2396
|
+
* @returns {mat3} out
|
2397
|
+
*/
|
2398
|
+
mat3.multiply = function (out, a, b) {
|
2399
|
+
var a00 = a[0], a01 = a[1], a02 = a[2],
|
2400
|
+
a10 = a[3], a11 = a[4], a12 = a[5],
|
2401
|
+
a20 = a[6], a21 = a[7], a22 = a[8],
|
2402
|
+
|
2403
|
+
b00 = b[0], b01 = b[1], b02 = b[2],
|
2404
|
+
b10 = b[3], b11 = b[4], b12 = b[5],
|
2405
|
+
b20 = b[6], b21 = b[7], b22 = b[8];
|
2406
|
+
|
2407
|
+
out[0] = b00 * a00 + b01 * a10 + b02 * a20;
|
2408
|
+
out[1] = b00 * a01 + b01 * a11 + b02 * a21;
|
2409
|
+
out[2] = b00 * a02 + b01 * a12 + b02 * a22;
|
2410
|
+
|
2411
|
+
out[3] = b10 * a00 + b11 * a10 + b12 * a20;
|
2412
|
+
out[4] = b10 * a01 + b11 * a11 + b12 * a21;
|
2413
|
+
out[5] = b10 * a02 + b11 * a12 + b12 * a22;
|
2414
|
+
|
2415
|
+
out[6] = b20 * a00 + b21 * a10 + b22 * a20;
|
2416
|
+
out[7] = b20 * a01 + b21 * a11 + b22 * a21;
|
2417
|
+
out[8] = b20 * a02 + b21 * a12 + b22 * a22;
|
2418
|
+
return out;
|
2419
|
+
};
|
2420
|
+
|
2421
|
+
/**
|
2422
|
+
* Alias for {@link mat3.multiply}
|
2423
|
+
* @function
|
2424
|
+
*/
|
2425
|
+
mat3.mul = mat3.multiply;
|
2426
|
+
|
2427
|
+
/**
|
2428
|
+
* Translate a mat3 by the given vector
|
2429
|
+
*
|
2430
|
+
* @param {mat3} out the receiving matrix
|
2431
|
+
* @param {mat3} a the matrix to translate
|
2432
|
+
* @param {vec2} v vector to translate by
|
2433
|
+
* @returns {mat3} out
|
2434
|
+
*/
|
2435
|
+
mat3.translate = function(out, a, v) {
|
2436
|
+
var a00 = a[0], a01 = a[1], a02 = a[2],
|
2437
|
+
a10 = a[3], a11 = a[4], a12 = a[5],
|
2438
|
+
a20 = a[6], a21 = a[7], a22 = a[8],
|
2439
|
+
x = v[0], y = v[1];
|
2440
|
+
|
2441
|
+
out[0] = a00;
|
2442
|
+
out[1] = a01;
|
2443
|
+
out[2] = a02;
|
2444
|
+
|
2445
|
+
out[3] = a10;
|
2446
|
+
out[4] = a11;
|
2447
|
+
out[5] = a12;
|
2448
|
+
|
2449
|
+
out[6] = x * a00 + y * a10 + a20;
|
2450
|
+
out[7] = x * a01 + y * a11 + a21;
|
2451
|
+
out[8] = x * a02 + y * a12 + a22;
|
2452
|
+
return out;
|
2453
|
+
};
|
2454
|
+
|
2455
|
+
/**
|
2456
|
+
* Rotates a mat3 by the given angle
|
2457
|
+
*
|
2458
|
+
* @param {mat3} out the receiving matrix
|
2459
|
+
* @param {mat3} a the matrix to rotate
|
2460
|
+
* @param {Number} rad the angle to rotate the matrix by
|
2461
|
+
* @returns {mat3} out
|
2462
|
+
*/
|
2463
|
+
mat3.rotate = function (out, a, rad) {
|
2464
|
+
var a00 = a[0], a01 = a[1], a02 = a[2],
|
2465
|
+
a10 = a[3], a11 = a[4], a12 = a[5],
|
2466
|
+
a20 = a[6], a21 = a[7], a22 = a[8],
|
2467
|
+
|
2468
|
+
s = Math.sin(rad),
|
2469
|
+
c = Math.cos(rad);
|
2470
|
+
|
2471
|
+
out[0] = c * a00 + s * a10;
|
2472
|
+
out[1] = c * a01 + s * a11;
|
2473
|
+
out[2] = c * a02 + s * a12;
|
2474
|
+
|
2475
|
+
out[3] = c * a10 - s * a00;
|
2476
|
+
out[4] = c * a11 - s * a01;
|
2477
|
+
out[5] = c * a12 - s * a02;
|
2478
|
+
|
2479
|
+
out[6] = a20;
|
2480
|
+
out[7] = a21;
|
2481
|
+
out[8] = a22;
|
2482
|
+
return out;
|
2483
|
+
};
|
2484
|
+
|
2485
|
+
/**
|
2486
|
+
* Scales the mat3 by the dimensions in the given vec2
|
2487
|
+
*
|
2488
|
+
* @param {mat3} out the receiving matrix
|
2489
|
+
* @param {mat3} a the matrix to rotate
|
2490
|
+
* @param {vec2} v the vec2 to scale the matrix by
|
2491
|
+
* @returns {mat3} out
|
2492
|
+
**/
|
2493
|
+
mat3.scale = function(out, a, v) {
|
2494
|
+
var x = v[0], y = v[1];
|
2495
|
+
|
2496
|
+
out[0] = x * a[0];
|
2497
|
+
out[1] = x * a[1];
|
2498
|
+
out[2] = x * a[2];
|
2499
|
+
|
2500
|
+
out[3] = y * a[3];
|
2501
|
+
out[4] = y * a[4];
|
2502
|
+
out[5] = y * a[5];
|
2503
|
+
|
2504
|
+
out[6] = a[6];
|
2505
|
+
out[7] = a[7];
|
2506
|
+
out[8] = a[8];
|
2507
|
+
return out;
|
2508
|
+
};
|
2509
|
+
|
2510
|
+
/**
|
2511
|
+
* Copies the values from a mat2d into a mat3
|
2512
|
+
*
|
2513
|
+
* @param {mat3} out the receiving matrix
|
2514
|
+
* @param {mat2d} a the matrix to copy
|
2515
|
+
* @returns {mat3} out
|
2516
|
+
**/
|
2517
|
+
mat3.fromMat2d = function(out, a) {
|
2518
|
+
out[0] = a[0];
|
2519
|
+
out[1] = a[1];
|
2520
|
+
out[2] = 0;
|
2521
|
+
|
2522
|
+
out[3] = a[2];
|
2523
|
+
out[4] = a[3];
|
2524
|
+
out[5] = 0;
|
2525
|
+
|
2526
|
+
out[6] = a[4];
|
2527
|
+
out[7] = a[5];
|
2528
|
+
out[8] = 1;
|
2529
|
+
return out;
|
2530
|
+
};
|
2531
|
+
|
2532
|
+
/**
|
2533
|
+
* Calculates a 3x3 matrix from the given quaternion
|
2534
|
+
*
|
2535
|
+
* @param {mat3} out mat3 receiving operation result
|
2536
|
+
* @param {quat} q Quaternion to create matrix from
|
2537
|
+
*
|
2538
|
+
* @returns {mat3} out
|
2539
|
+
*/
|
2540
|
+
mat3.fromQuat = function (out, q) {
|
2541
|
+
var x = q[0], y = q[1], z = q[2], w = q[3],
|
2542
|
+
x2 = x + x,
|
2543
|
+
y2 = y + y,
|
2544
|
+
z2 = z + z,
|
2545
|
+
|
2546
|
+
xx = x * x2,
|
2547
|
+
xy = x * y2,
|
2548
|
+
xz = x * z2,
|
2549
|
+
yy = y * y2,
|
2550
|
+
yz = y * z2,
|
2551
|
+
zz = z * z2,
|
2552
|
+
wx = w * x2,
|
2553
|
+
wy = w * y2,
|
2554
|
+
wz = w * z2;
|
2555
|
+
|
2556
|
+
out[0] = 1 - (yy + zz);
|
2557
|
+
out[3] = xy + wz;
|
2558
|
+
out[6] = xz - wy;
|
2559
|
+
|
2560
|
+
out[1] = xy - wz;
|
2561
|
+
out[4] = 1 - (xx + zz);
|
2562
|
+
out[7] = yz + wx;
|
2563
|
+
|
2564
|
+
out[2] = xz + wy;
|
2565
|
+
out[5] = yz - wx;
|
2566
|
+
out[8] = 1 - (xx + yy);
|
2567
|
+
|
2568
|
+
return out;
|
2569
|
+
};
|
2570
|
+
|
2571
|
+
/**
|
2572
|
+
* Calculates a 3x3 normal matrix (transpose inverse) from the 4x4 matrix
|
2573
|
+
*
|
2574
|
+
* @param {mat3} out mat3 receiving operation result
|
2575
|
+
* @param {mat4} a Mat4 to derive the normal matrix from
|
2576
|
+
*
|
2577
|
+
* @returns {mat3} out
|
2578
|
+
*/
|
2579
|
+
mat3.normalFromMat4 = function (out, a) {
|
2580
|
+
var a00 = a[0], a01 = a[1], a02 = a[2], a03 = a[3],
|
2581
|
+
a10 = a[4], a11 = a[5], a12 = a[6], a13 = a[7],
|
2582
|
+
a20 = a[8], a21 = a[9], a22 = a[10], a23 = a[11],
|
2583
|
+
a30 = a[12], a31 = a[13], a32 = a[14], a33 = a[15],
|
2584
|
+
|
2585
|
+
b00 = a00 * a11 - a01 * a10,
|
2586
|
+
b01 = a00 * a12 - a02 * a10,
|
2587
|
+
b02 = a00 * a13 - a03 * a10,
|
2588
|
+
b03 = a01 * a12 - a02 * a11,
|
2589
|
+
b04 = a01 * a13 - a03 * a11,
|
2590
|
+
b05 = a02 * a13 - a03 * a12,
|
2591
|
+
b06 = a20 * a31 - a21 * a30,
|
2592
|
+
b07 = a20 * a32 - a22 * a30,
|
2593
|
+
b08 = a20 * a33 - a23 * a30,
|
2594
|
+
b09 = a21 * a32 - a22 * a31,
|
2595
|
+
b10 = a21 * a33 - a23 * a31,
|
2596
|
+
b11 = a22 * a33 - a23 * a32,
|
2597
|
+
|
2598
|
+
// Calculate the determinant
|
2599
|
+
det = b00 * b11 - b01 * b10 + b02 * b09 + b03 * b08 - b04 * b07 + b05 * b06;
|
2600
|
+
|
2601
|
+
if (!det) {
|
2602
|
+
return null;
|
2603
|
+
}
|
2604
|
+
det = 1.0 / det;
|
2605
|
+
|
2606
|
+
out[0] = (a11 * b11 - a12 * b10 + a13 * b09) * det;
|
2607
|
+
out[1] = (a12 * b08 - a10 * b11 - a13 * b07) * det;
|
2608
|
+
out[2] = (a10 * b10 - a11 * b08 + a13 * b06) * det;
|
2609
|
+
|
2610
|
+
out[3] = (a02 * b10 - a01 * b11 - a03 * b09) * det;
|
2611
|
+
out[4] = (a00 * b11 - a02 * b08 + a03 * b07) * det;
|
2612
|
+
out[5] = (a01 * b08 - a00 * b10 - a03 * b06) * det;
|
2613
|
+
|
2614
|
+
out[6] = (a31 * b05 - a32 * b04 + a33 * b03) * det;
|
2615
|
+
out[7] = (a32 * b02 - a30 * b05 - a33 * b01) * det;
|
2616
|
+
out[8] = (a30 * b04 - a31 * b02 + a33 * b00) * det;
|
2617
|
+
|
2618
|
+
return out;
|
2619
|
+
};
|
2620
|
+
|
2621
|
+
/**
|
2622
|
+
* Returns a string representation of a mat3
|
2623
|
+
*
|
2624
|
+
* @param {mat3} mat matrix to represent as a string
|
2625
|
+
* @returns {String} string representation of the matrix
|
2626
|
+
*/
|
2627
|
+
mat3.str = function (a) {
|
2628
|
+
return 'mat3(' + a[0] + ', ' + a[1] + ', ' + a[2] + ', ' +
|
2629
|
+
a[3] + ', ' + a[4] + ', ' + a[5] + ', ' +
|
2630
|
+
a[6] + ', ' + a[7] + ', ' + a[8] + ')';
|
2631
|
+
};
|
2632
|
+
|
2633
|
+
if(typeof(exports) !== 'undefined') {
|
2634
|
+
exports.mat3 = mat3;
|
2635
|
+
}
|
2636
|
+
;
|
2637
|
+
/* Copyright (c) 2013, Brandon Jones, Colin MacKenzie IV. All rights reserved.
|
2638
|
+
|
2639
|
+
Redistribution and use in source and binary forms, with or without modification,
|
2640
|
+
are permitted provided that the following conditions are met:
|
2641
|
+
|
2642
|
+
* Redistributions of source code must retain the above copyright notice, this
|
2643
|
+
list of conditions and the following disclaimer.
|
2644
|
+
* Redistributions in binary form must reproduce the above copyright notice,
|
2645
|
+
this list of conditions and the following disclaimer in the documentation
|
2646
|
+
and/or other materials provided with the distribution.
|
2647
|
+
|
2648
|
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
2649
|
+
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
2650
|
+
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
2651
|
+
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
|
2652
|
+
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
2653
|
+
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
2654
|
+
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
2655
|
+
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
2656
|
+
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
2657
|
+
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */
|
2658
|
+
|
2659
|
+
/**
|
2660
|
+
* @class 4x4 Matrix
|
2661
|
+
* @name mat4
|
2662
|
+
*/
|
2663
|
+
|
2664
|
+
var mat4 = {};
|
2665
|
+
|
2666
|
+
/**
|
2667
|
+
* Creates a new identity mat4
|
2668
|
+
*
|
2669
|
+
* @returns {mat4} a new 4x4 matrix
|
2670
|
+
*/
|
2671
|
+
mat4.create = function() {
|
2672
|
+
var out = new GLMAT_ARRAY_TYPE(16);
|
2673
|
+
out[0] = 1;
|
2674
|
+
out[1] = 0;
|
2675
|
+
out[2] = 0;
|
2676
|
+
out[3] = 0;
|
2677
|
+
out[4] = 0;
|
2678
|
+
out[5] = 1;
|
2679
|
+
out[6] = 0;
|
2680
|
+
out[7] = 0;
|
2681
|
+
out[8] = 0;
|
2682
|
+
out[9] = 0;
|
2683
|
+
out[10] = 1;
|
2684
|
+
out[11] = 0;
|
2685
|
+
out[12] = 0;
|
2686
|
+
out[13] = 0;
|
2687
|
+
out[14] = 0;
|
2688
|
+
out[15] = 1;
|
2689
|
+
return out;
|
2690
|
+
};
|
2691
|
+
|
2692
|
+
/**
|
2693
|
+
* Creates a new mat4 initialized with values from an existing matrix
|
2694
|
+
*
|
2695
|
+
* @param {mat4} a matrix to clone
|
2696
|
+
* @returns {mat4} a new 4x4 matrix
|
2697
|
+
*/
|
2698
|
+
mat4.clone = function(a) {
|
2699
|
+
var out = new GLMAT_ARRAY_TYPE(16);
|
2700
|
+
out[0] = a[0];
|
2701
|
+
out[1] = a[1];
|
2702
|
+
out[2] = a[2];
|
2703
|
+
out[3] = a[3];
|
2704
|
+
out[4] = a[4];
|
2705
|
+
out[5] = a[5];
|
2706
|
+
out[6] = a[6];
|
2707
|
+
out[7] = a[7];
|
2708
|
+
out[8] = a[8];
|
2709
|
+
out[9] = a[9];
|
2710
|
+
out[10] = a[10];
|
2711
|
+
out[11] = a[11];
|
2712
|
+
out[12] = a[12];
|
2713
|
+
out[13] = a[13];
|
2714
|
+
out[14] = a[14];
|
2715
|
+
out[15] = a[15];
|
2716
|
+
return out;
|
2717
|
+
};
|
2718
|
+
|
2719
|
+
/**
|
2720
|
+
* Copy the values from one mat4 to another
|
2721
|
+
*
|
2722
|
+
* @param {mat4} out the receiving matrix
|
2723
|
+
* @param {mat4} a the source matrix
|
2724
|
+
* @returns {mat4} out
|
2725
|
+
*/
|
2726
|
+
mat4.copy = function(out, a) {
|
2727
|
+
out[0] = a[0];
|
2728
|
+
out[1] = a[1];
|
2729
|
+
out[2] = a[2];
|
2730
|
+
out[3] = a[3];
|
2731
|
+
out[4] = a[4];
|
2732
|
+
out[5] = a[5];
|
2733
|
+
out[6] = a[6];
|
2734
|
+
out[7] = a[7];
|
2735
|
+
out[8] = a[8];
|
2736
|
+
out[9] = a[9];
|
2737
|
+
out[10] = a[10];
|
2738
|
+
out[11] = a[11];
|
2739
|
+
out[12] = a[12];
|
2740
|
+
out[13] = a[13];
|
2741
|
+
out[14] = a[14];
|
2742
|
+
out[15] = a[15];
|
2743
|
+
return out;
|
2744
|
+
};
|
2745
|
+
|
2746
|
+
/**
|
2747
|
+
* Set a mat4 to the identity matrix
|
2748
|
+
*
|
2749
|
+
* @param {mat4} out the receiving matrix
|
2750
|
+
* @returns {mat4} out
|
2751
|
+
*/
|
2752
|
+
mat4.identity = function(out) {
|
2753
|
+
out[0] = 1;
|
2754
|
+
out[1] = 0;
|
2755
|
+
out[2] = 0;
|
2756
|
+
out[3] = 0;
|
2757
|
+
out[4] = 0;
|
2758
|
+
out[5] = 1;
|
2759
|
+
out[6] = 0;
|
2760
|
+
out[7] = 0;
|
2761
|
+
out[8] = 0;
|
2762
|
+
out[9] = 0;
|
2763
|
+
out[10] = 1;
|
2764
|
+
out[11] = 0;
|
2765
|
+
out[12] = 0;
|
2766
|
+
out[13] = 0;
|
2767
|
+
out[14] = 0;
|
2768
|
+
out[15] = 1;
|
2769
|
+
return out;
|
2770
|
+
};
|
2771
|
+
|
2772
|
+
/**
|
2773
|
+
* Transpose the values of a mat4
|
2774
|
+
*
|
2775
|
+
* @param {mat4} out the receiving matrix
|
2776
|
+
* @param {mat4} a the source matrix
|
2777
|
+
* @returns {mat4} out
|
2778
|
+
*/
|
2779
|
+
mat4.transpose = function(out, a) {
|
2780
|
+
// If we are transposing ourselves we can skip a few steps but have to cache some values
|
2781
|
+
if (out === a) {
|
2782
|
+
var a01 = a[1], a02 = a[2], a03 = a[3],
|
2783
|
+
a12 = a[6], a13 = a[7],
|
2784
|
+
a23 = a[11];
|
2785
|
+
|
2786
|
+
out[1] = a[4];
|
2787
|
+
out[2] = a[8];
|
2788
|
+
out[3] = a[12];
|
2789
|
+
out[4] = a01;
|
2790
|
+
out[6] = a[9];
|
2791
|
+
out[7] = a[13];
|
2792
|
+
out[8] = a02;
|
2793
|
+
out[9] = a12;
|
2794
|
+
out[11] = a[14];
|
2795
|
+
out[12] = a03;
|
2796
|
+
out[13] = a13;
|
2797
|
+
out[14] = a23;
|
2798
|
+
} else {
|
2799
|
+
out[0] = a[0];
|
2800
|
+
out[1] = a[4];
|
2801
|
+
out[2] = a[8];
|
2802
|
+
out[3] = a[12];
|
2803
|
+
out[4] = a[1];
|
2804
|
+
out[5] = a[5];
|
2805
|
+
out[6] = a[9];
|
2806
|
+
out[7] = a[13];
|
2807
|
+
out[8] = a[2];
|
2808
|
+
out[9] = a[6];
|
2809
|
+
out[10] = a[10];
|
2810
|
+
out[11] = a[14];
|
2811
|
+
out[12] = a[3];
|
2812
|
+
out[13] = a[7];
|
2813
|
+
out[14] = a[11];
|
2814
|
+
out[15] = a[15];
|
2815
|
+
}
|
2816
|
+
|
2817
|
+
return out;
|
2818
|
+
};
|
2819
|
+
|
2820
|
+
/**
|
2821
|
+
* Inverts a mat4
|
2822
|
+
*
|
2823
|
+
* @param {mat4} out the receiving matrix
|
2824
|
+
* @param {mat4} a the source matrix
|
2825
|
+
* @returns {mat4} out
|
2826
|
+
*/
|
2827
|
+
mat4.invert = function(out, a) {
|
2828
|
+
var a00 = a[0], a01 = a[1], a02 = a[2], a03 = a[3],
|
2829
|
+
a10 = a[4], a11 = a[5], a12 = a[6], a13 = a[7],
|
2830
|
+
a20 = a[8], a21 = a[9], a22 = a[10], a23 = a[11],
|
2831
|
+
a30 = a[12], a31 = a[13], a32 = a[14], a33 = a[15],
|
2832
|
+
|
2833
|
+
b00 = a00 * a11 - a01 * a10,
|
2834
|
+
b01 = a00 * a12 - a02 * a10,
|
2835
|
+
b02 = a00 * a13 - a03 * a10,
|
2836
|
+
b03 = a01 * a12 - a02 * a11,
|
2837
|
+
b04 = a01 * a13 - a03 * a11,
|
2838
|
+
b05 = a02 * a13 - a03 * a12,
|
2839
|
+
b06 = a20 * a31 - a21 * a30,
|
2840
|
+
b07 = a20 * a32 - a22 * a30,
|
2841
|
+
b08 = a20 * a33 - a23 * a30,
|
2842
|
+
b09 = a21 * a32 - a22 * a31,
|
2843
|
+
b10 = a21 * a33 - a23 * a31,
|
2844
|
+
b11 = a22 * a33 - a23 * a32,
|
2845
|
+
|
2846
|
+
// Calculate the determinant
|
2847
|
+
det = b00 * b11 - b01 * b10 + b02 * b09 + b03 * b08 - b04 * b07 + b05 * b06;
|
2848
|
+
|
2849
|
+
if (!det) {
|
2850
|
+
return null;
|
2851
|
+
}
|
2852
|
+
det = 1.0 / det;
|
2853
|
+
|
2854
|
+
out[0] = (a11 * b11 - a12 * b10 + a13 * b09) * det;
|
2855
|
+
out[1] = (a02 * b10 - a01 * b11 - a03 * b09) * det;
|
2856
|
+
out[2] = (a31 * b05 - a32 * b04 + a33 * b03) * det;
|
2857
|
+
out[3] = (a22 * b04 - a21 * b05 - a23 * b03) * det;
|
2858
|
+
out[4] = (a12 * b08 - a10 * b11 - a13 * b07) * det;
|
2859
|
+
out[5] = (a00 * b11 - a02 * b08 + a03 * b07) * det;
|
2860
|
+
out[6] = (a32 * b02 - a30 * b05 - a33 * b01) * det;
|
2861
|
+
out[7] = (a20 * b05 - a22 * b02 + a23 * b01) * det;
|
2862
|
+
out[8] = (a10 * b10 - a11 * b08 + a13 * b06) * det;
|
2863
|
+
out[9] = (a01 * b08 - a00 * b10 - a03 * b06) * det;
|
2864
|
+
out[10] = (a30 * b04 - a31 * b02 + a33 * b00) * det;
|
2865
|
+
out[11] = (a21 * b02 - a20 * b04 - a23 * b00) * det;
|
2866
|
+
out[12] = (a11 * b07 - a10 * b09 - a12 * b06) * det;
|
2867
|
+
out[13] = (a00 * b09 - a01 * b07 + a02 * b06) * det;
|
2868
|
+
out[14] = (a31 * b01 - a30 * b03 - a32 * b00) * det;
|
2869
|
+
out[15] = (a20 * b03 - a21 * b01 + a22 * b00) * det;
|
2870
|
+
|
2871
|
+
return out;
|
2872
|
+
};
|
2873
|
+
|
2874
|
+
/**
|
2875
|
+
* Calculates the adjugate of a mat4
|
2876
|
+
*
|
2877
|
+
* @param {mat4} out the receiving matrix
|
2878
|
+
* @param {mat4} a the source matrix
|
2879
|
+
* @returns {mat4} out
|
2880
|
+
*/
|
2881
|
+
mat4.adjoint = function(out, a) {
|
2882
|
+
var a00 = a[0], a01 = a[1], a02 = a[2], a03 = a[3],
|
2883
|
+
a10 = a[4], a11 = a[5], a12 = a[6], a13 = a[7],
|
2884
|
+
a20 = a[8], a21 = a[9], a22 = a[10], a23 = a[11],
|
2885
|
+
a30 = a[12], a31 = a[13], a32 = a[14], a33 = a[15];
|
2886
|
+
|
2887
|
+
out[0] = (a11 * (a22 * a33 - a23 * a32) - a21 * (a12 * a33 - a13 * a32) + a31 * (a12 * a23 - a13 * a22));
|
2888
|
+
out[1] = -(a01 * (a22 * a33 - a23 * a32) - a21 * (a02 * a33 - a03 * a32) + a31 * (a02 * a23 - a03 * a22));
|
2889
|
+
out[2] = (a01 * (a12 * a33 - a13 * a32) - a11 * (a02 * a33 - a03 * a32) + a31 * (a02 * a13 - a03 * a12));
|
2890
|
+
out[3] = -(a01 * (a12 * a23 - a13 * a22) - a11 * (a02 * a23 - a03 * a22) + a21 * (a02 * a13 - a03 * a12));
|
2891
|
+
out[4] = -(a10 * (a22 * a33 - a23 * a32) - a20 * (a12 * a33 - a13 * a32) + a30 * (a12 * a23 - a13 * a22));
|
2892
|
+
out[5] = (a00 * (a22 * a33 - a23 * a32) - a20 * (a02 * a33 - a03 * a32) + a30 * (a02 * a23 - a03 * a22));
|
2893
|
+
out[6] = -(a00 * (a12 * a33 - a13 * a32) - a10 * (a02 * a33 - a03 * a32) + a30 * (a02 * a13 - a03 * a12));
|
2894
|
+
out[7] = (a00 * (a12 * a23 - a13 * a22) - a10 * (a02 * a23 - a03 * a22) + a20 * (a02 * a13 - a03 * a12));
|
2895
|
+
out[8] = (a10 * (a21 * a33 - a23 * a31) - a20 * (a11 * a33 - a13 * a31) + a30 * (a11 * a23 - a13 * a21));
|
2896
|
+
out[9] = -(a00 * (a21 * a33 - a23 * a31) - a20 * (a01 * a33 - a03 * a31) + a30 * (a01 * a23 - a03 * a21));
|
2897
|
+
out[10] = (a00 * (a11 * a33 - a13 * a31) - a10 * (a01 * a33 - a03 * a31) + a30 * (a01 * a13 - a03 * a11));
|
2898
|
+
out[11] = -(a00 * (a11 * a23 - a13 * a21) - a10 * (a01 * a23 - a03 * a21) + a20 * (a01 * a13 - a03 * a11));
|
2899
|
+
out[12] = -(a10 * (a21 * a32 - a22 * a31) - a20 * (a11 * a32 - a12 * a31) + a30 * (a11 * a22 - a12 * a21));
|
2900
|
+
out[13] = (a00 * (a21 * a32 - a22 * a31) - a20 * (a01 * a32 - a02 * a31) + a30 * (a01 * a22 - a02 * a21));
|
2901
|
+
out[14] = -(a00 * (a11 * a32 - a12 * a31) - a10 * (a01 * a32 - a02 * a31) + a30 * (a01 * a12 - a02 * a11));
|
2902
|
+
out[15] = (a00 * (a11 * a22 - a12 * a21) - a10 * (a01 * a22 - a02 * a21) + a20 * (a01 * a12 - a02 * a11));
|
2903
|
+
return out;
|
2904
|
+
};
|
2905
|
+
|
2906
|
+
/**
|
2907
|
+
* Calculates the determinant of a mat4
|
2908
|
+
*
|
2909
|
+
* @param {mat4} a the source matrix
|
2910
|
+
* @returns {Number} determinant of a
|
2911
|
+
*/
|
2912
|
+
mat4.determinant = function (a) {
|
2913
|
+
var a00 = a[0], a01 = a[1], a02 = a[2], a03 = a[3],
|
2914
|
+
a10 = a[4], a11 = a[5], a12 = a[6], a13 = a[7],
|
2915
|
+
a20 = a[8], a21 = a[9], a22 = a[10], a23 = a[11],
|
2916
|
+
a30 = a[12], a31 = a[13], a32 = a[14], a33 = a[15],
|
2917
|
+
|
2918
|
+
b00 = a00 * a11 - a01 * a10,
|
2919
|
+
b01 = a00 * a12 - a02 * a10,
|
2920
|
+
b02 = a00 * a13 - a03 * a10,
|
2921
|
+
b03 = a01 * a12 - a02 * a11,
|
2922
|
+
b04 = a01 * a13 - a03 * a11,
|
2923
|
+
b05 = a02 * a13 - a03 * a12,
|
2924
|
+
b06 = a20 * a31 - a21 * a30,
|
2925
|
+
b07 = a20 * a32 - a22 * a30,
|
2926
|
+
b08 = a20 * a33 - a23 * a30,
|
2927
|
+
b09 = a21 * a32 - a22 * a31,
|
2928
|
+
b10 = a21 * a33 - a23 * a31,
|
2929
|
+
b11 = a22 * a33 - a23 * a32;
|
2930
|
+
|
2931
|
+
// Calculate the determinant
|
2932
|
+
return b00 * b11 - b01 * b10 + b02 * b09 + b03 * b08 - b04 * b07 + b05 * b06;
|
2933
|
+
};
|
2934
|
+
|
2935
|
+
/**
|
2936
|
+
* Multiplies two mat4's
|
2937
|
+
*
|
2938
|
+
* @param {mat4} out the receiving matrix
|
2939
|
+
* @param {mat4} a the first operand
|
2940
|
+
* @param {mat4} b the second operand
|
2941
|
+
* @returns {mat4} out
|
2942
|
+
*/
|
2943
|
+
mat4.multiply = function (out, a, b) {
|
2944
|
+
var a00 = a[0], a01 = a[1], a02 = a[2], a03 = a[3],
|
2945
|
+
a10 = a[4], a11 = a[5], a12 = a[6], a13 = a[7],
|
2946
|
+
a20 = a[8], a21 = a[9], a22 = a[10], a23 = a[11],
|
2947
|
+
a30 = a[12], a31 = a[13], a32 = a[14], a33 = a[15];
|
2948
|
+
|
2949
|
+
// Cache only the current line of the second matrix
|
2950
|
+
var b0 = b[0], b1 = b[1], b2 = b[2], b3 = b[3];
|
2951
|
+
out[0] = b0*a00 + b1*a10 + b2*a20 + b3*a30;
|
2952
|
+
out[1] = b0*a01 + b1*a11 + b2*a21 + b3*a31;
|
2953
|
+
out[2] = b0*a02 + b1*a12 + b2*a22 + b3*a32;
|
2954
|
+
out[3] = b0*a03 + b1*a13 + b2*a23 + b3*a33;
|
2955
|
+
|
2956
|
+
b0 = b[4]; b1 = b[5]; b2 = b[6]; b3 = b[7];
|
2957
|
+
out[4] = b0*a00 + b1*a10 + b2*a20 + b3*a30;
|
2958
|
+
out[5] = b0*a01 + b1*a11 + b2*a21 + b3*a31;
|
2959
|
+
out[6] = b0*a02 + b1*a12 + b2*a22 + b3*a32;
|
2960
|
+
out[7] = b0*a03 + b1*a13 + b2*a23 + b3*a33;
|
2961
|
+
|
2962
|
+
b0 = b[8]; b1 = b[9]; b2 = b[10]; b3 = b[11];
|
2963
|
+
out[8] = b0*a00 + b1*a10 + b2*a20 + b3*a30;
|
2964
|
+
out[9] = b0*a01 + b1*a11 + b2*a21 + b3*a31;
|
2965
|
+
out[10] = b0*a02 + b1*a12 + b2*a22 + b3*a32;
|
2966
|
+
out[11] = b0*a03 + b1*a13 + b2*a23 + b3*a33;
|
2967
|
+
|
2968
|
+
b0 = b[12]; b1 = b[13]; b2 = b[14]; b3 = b[15];
|
2969
|
+
out[12] = b0*a00 + b1*a10 + b2*a20 + b3*a30;
|
2970
|
+
out[13] = b0*a01 + b1*a11 + b2*a21 + b3*a31;
|
2971
|
+
out[14] = b0*a02 + b1*a12 + b2*a22 + b3*a32;
|
2972
|
+
out[15] = b0*a03 + b1*a13 + b2*a23 + b3*a33;
|
2973
|
+
return out;
|
2974
|
+
};
|
2975
|
+
|
2976
|
+
/**
|
2977
|
+
* Alias for {@link mat4.multiply}
|
2978
|
+
* @function
|
2979
|
+
*/
|
2980
|
+
mat4.mul = mat4.multiply;
|
2981
|
+
|
2982
|
+
/**
|
2983
|
+
* Translate a mat4 by the given vector
|
2984
|
+
*
|
2985
|
+
* @param {mat4} out the receiving matrix
|
2986
|
+
* @param {mat4} a the matrix to translate
|
2987
|
+
* @param {vec3} v vector to translate by
|
2988
|
+
* @returns {mat4} out
|
2989
|
+
*/
|
2990
|
+
mat4.translate = function (out, a, v) {
|
2991
|
+
var x = v[0], y = v[1], z = v[2],
|
2992
|
+
a00, a01, a02, a03,
|
2993
|
+
a10, a11, a12, a13,
|
2994
|
+
a20, a21, a22, a23;
|
2995
|
+
|
2996
|
+
if (a === out) {
|
2997
|
+
out[12] = a[0] * x + a[4] * y + a[8] * z + a[12];
|
2998
|
+
out[13] = a[1] * x + a[5] * y + a[9] * z + a[13];
|
2999
|
+
out[14] = a[2] * x + a[6] * y + a[10] * z + a[14];
|
3000
|
+
out[15] = a[3] * x + a[7] * y + a[11] * z + a[15];
|
3001
|
+
} else {
|
3002
|
+
a00 = a[0]; a01 = a[1]; a02 = a[2]; a03 = a[3];
|
3003
|
+
a10 = a[4]; a11 = a[5]; a12 = a[6]; a13 = a[7];
|
3004
|
+
a20 = a[8]; a21 = a[9]; a22 = a[10]; a23 = a[11];
|
3005
|
+
|
3006
|
+
out[0] = a00; out[1] = a01; out[2] = a02; out[3] = a03;
|
3007
|
+
out[4] = a10; out[5] = a11; out[6] = a12; out[7] = a13;
|
3008
|
+
out[8] = a20; out[9] = a21; out[10] = a22; out[11] = a23;
|
3009
|
+
|
3010
|
+
out[12] = a00 * x + a10 * y + a20 * z + a[12];
|
3011
|
+
out[13] = a01 * x + a11 * y + a21 * z + a[13];
|
3012
|
+
out[14] = a02 * x + a12 * y + a22 * z + a[14];
|
3013
|
+
out[15] = a03 * x + a13 * y + a23 * z + a[15];
|
3014
|
+
}
|
3015
|
+
|
3016
|
+
return out;
|
3017
|
+
};
|
3018
|
+
|
3019
|
+
/**
|
3020
|
+
* Scales the mat4 by the dimensions in the given vec3
|
3021
|
+
*
|
3022
|
+
* @param {mat4} out the receiving matrix
|
3023
|
+
* @param {mat4} a the matrix to scale
|
3024
|
+
* @param {vec3} v the vec3 to scale the matrix by
|
3025
|
+
* @returns {mat4} out
|
3026
|
+
**/
|
3027
|
+
mat4.scale = function(out, a, v) {
|
3028
|
+
var x = v[0], y = v[1], z = v[2];
|
3029
|
+
|
3030
|
+
out[0] = a[0] * x;
|
3031
|
+
out[1] = a[1] * x;
|
3032
|
+
out[2] = a[2] * x;
|
3033
|
+
out[3] = a[3] * x;
|
3034
|
+
out[4] = a[4] * y;
|
3035
|
+
out[5] = a[5] * y;
|
3036
|
+
out[6] = a[6] * y;
|
3037
|
+
out[7] = a[7] * y;
|
3038
|
+
out[8] = a[8] * z;
|
3039
|
+
out[9] = a[9] * z;
|
3040
|
+
out[10] = a[10] * z;
|
3041
|
+
out[11] = a[11] * z;
|
3042
|
+
out[12] = a[12];
|
3043
|
+
out[13] = a[13];
|
3044
|
+
out[14] = a[14];
|
3045
|
+
out[15] = a[15];
|
3046
|
+
return out;
|
3047
|
+
};
|
3048
|
+
|
3049
|
+
/**
|
3050
|
+
* Rotates a mat4 by the given angle
|
3051
|
+
*
|
3052
|
+
* @param {mat4} out the receiving matrix
|
3053
|
+
* @param {mat4} a the matrix to rotate
|
3054
|
+
* @param {Number} rad the angle to rotate the matrix by
|
3055
|
+
* @param {vec3} axis the axis to rotate around
|
3056
|
+
* @returns {mat4} out
|
3057
|
+
*/
|
3058
|
+
mat4.rotate = function (out, a, rad, axis) {
|
3059
|
+
var x = axis[0], y = axis[1], z = axis[2],
|
3060
|
+
len = Math.sqrt(x * x + y * y + z * z),
|
3061
|
+
s, c, t,
|
3062
|
+
a00, a01, a02, a03,
|
3063
|
+
a10, a11, a12, a13,
|
3064
|
+
a20, a21, a22, a23,
|
3065
|
+
b00, b01, b02,
|
3066
|
+
b10, b11, b12,
|
3067
|
+
b20, b21, b22;
|
3068
|
+
|
3069
|
+
if (Math.abs(len) < GLMAT_EPSILON) { return null; }
|
3070
|
+
|
3071
|
+
len = 1 / len;
|
3072
|
+
x *= len;
|
3073
|
+
y *= len;
|
3074
|
+
z *= len;
|
3075
|
+
|
3076
|
+
s = Math.sin(rad);
|
3077
|
+
c = Math.cos(rad);
|
3078
|
+
t = 1 - c;
|
3079
|
+
|
3080
|
+
a00 = a[0]; a01 = a[1]; a02 = a[2]; a03 = a[3];
|
3081
|
+
a10 = a[4]; a11 = a[5]; a12 = a[6]; a13 = a[7];
|
3082
|
+
a20 = a[8]; a21 = a[9]; a22 = a[10]; a23 = a[11];
|
3083
|
+
|
3084
|
+
// Construct the elements of the rotation matrix
|
3085
|
+
b00 = x * x * t + c; b01 = y * x * t + z * s; b02 = z * x * t - y * s;
|
3086
|
+
b10 = x * y * t - z * s; b11 = y * y * t + c; b12 = z * y * t + x * s;
|
3087
|
+
b20 = x * z * t + y * s; b21 = y * z * t - x * s; b22 = z * z * t + c;
|
3088
|
+
|
3089
|
+
// Perform rotation-specific matrix multiplication
|
3090
|
+
out[0] = a00 * b00 + a10 * b01 + a20 * b02;
|
3091
|
+
out[1] = a01 * b00 + a11 * b01 + a21 * b02;
|
3092
|
+
out[2] = a02 * b00 + a12 * b01 + a22 * b02;
|
3093
|
+
out[3] = a03 * b00 + a13 * b01 + a23 * b02;
|
3094
|
+
out[4] = a00 * b10 + a10 * b11 + a20 * b12;
|
3095
|
+
out[5] = a01 * b10 + a11 * b11 + a21 * b12;
|
3096
|
+
out[6] = a02 * b10 + a12 * b11 + a22 * b12;
|
3097
|
+
out[7] = a03 * b10 + a13 * b11 + a23 * b12;
|
3098
|
+
out[8] = a00 * b20 + a10 * b21 + a20 * b22;
|
3099
|
+
out[9] = a01 * b20 + a11 * b21 + a21 * b22;
|
3100
|
+
out[10] = a02 * b20 + a12 * b21 + a22 * b22;
|
3101
|
+
out[11] = a03 * b20 + a13 * b21 + a23 * b22;
|
3102
|
+
|
3103
|
+
if (a !== out) { // If the source and destination differ, copy the unchanged last row
|
3104
|
+
out[12] = a[12];
|
3105
|
+
out[13] = a[13];
|
3106
|
+
out[14] = a[14];
|
3107
|
+
out[15] = a[15];
|
3108
|
+
}
|
3109
|
+
return out;
|
3110
|
+
};
|
3111
|
+
|
3112
|
+
/**
|
3113
|
+
* Rotates a matrix by the given angle around the X axis
|
3114
|
+
*
|
3115
|
+
* @param {mat4} out the receiving matrix
|
3116
|
+
* @param {mat4} a the matrix to rotate
|
3117
|
+
* @param {Number} rad the angle to rotate the matrix by
|
3118
|
+
* @returns {mat4} out
|
3119
|
+
*/
|
3120
|
+
mat4.rotateX = function (out, a, rad) {
|
3121
|
+
var s = Math.sin(rad),
|
3122
|
+
c = Math.cos(rad),
|
3123
|
+
a10 = a[4],
|
3124
|
+
a11 = a[5],
|
3125
|
+
a12 = a[6],
|
3126
|
+
a13 = a[7],
|
3127
|
+
a20 = a[8],
|
3128
|
+
a21 = a[9],
|
3129
|
+
a22 = a[10],
|
3130
|
+
a23 = a[11];
|
3131
|
+
|
3132
|
+
if (a !== out) { // If the source and destination differ, copy the unchanged rows
|
3133
|
+
out[0] = a[0];
|
3134
|
+
out[1] = a[1];
|
3135
|
+
out[2] = a[2];
|
3136
|
+
out[3] = a[3];
|
3137
|
+
out[12] = a[12];
|
3138
|
+
out[13] = a[13];
|
3139
|
+
out[14] = a[14];
|
3140
|
+
out[15] = a[15];
|
3141
|
+
}
|
3142
|
+
|
3143
|
+
// Perform axis-specific matrix multiplication
|
3144
|
+
out[4] = a10 * c + a20 * s;
|
3145
|
+
out[5] = a11 * c + a21 * s;
|
3146
|
+
out[6] = a12 * c + a22 * s;
|
3147
|
+
out[7] = a13 * c + a23 * s;
|
3148
|
+
out[8] = a20 * c - a10 * s;
|
3149
|
+
out[9] = a21 * c - a11 * s;
|
3150
|
+
out[10] = a22 * c - a12 * s;
|
3151
|
+
out[11] = a23 * c - a13 * s;
|
3152
|
+
return out;
|
3153
|
+
};
|
3154
|
+
|
3155
|
+
/**
|
3156
|
+
* Rotates a matrix by the given angle around the Y axis
|
3157
|
+
*
|
3158
|
+
* @param {mat4} out the receiving matrix
|
3159
|
+
* @param {mat4} a the matrix to rotate
|
3160
|
+
* @param {Number} rad the angle to rotate the matrix by
|
3161
|
+
* @returns {mat4} out
|
3162
|
+
*/
|
3163
|
+
mat4.rotateY = function (out, a, rad) {
|
3164
|
+
var s = Math.sin(rad),
|
3165
|
+
c = Math.cos(rad),
|
3166
|
+
a00 = a[0],
|
3167
|
+
a01 = a[1],
|
3168
|
+
a02 = a[2],
|
3169
|
+
a03 = a[3],
|
3170
|
+
a20 = a[8],
|
3171
|
+
a21 = a[9],
|
3172
|
+
a22 = a[10],
|
3173
|
+
a23 = a[11];
|
3174
|
+
|
3175
|
+
if (a !== out) { // If the source and destination differ, copy the unchanged rows
|
3176
|
+
out[4] = a[4];
|
3177
|
+
out[5] = a[5];
|
3178
|
+
out[6] = a[6];
|
3179
|
+
out[7] = a[7];
|
3180
|
+
out[12] = a[12];
|
3181
|
+
out[13] = a[13];
|
3182
|
+
out[14] = a[14];
|
3183
|
+
out[15] = a[15];
|
3184
|
+
}
|
3185
|
+
|
3186
|
+
// Perform axis-specific matrix multiplication
|
3187
|
+
out[0] = a00 * c - a20 * s;
|
3188
|
+
out[1] = a01 * c - a21 * s;
|
3189
|
+
out[2] = a02 * c - a22 * s;
|
3190
|
+
out[3] = a03 * c - a23 * s;
|
3191
|
+
out[8] = a00 * s + a20 * c;
|
3192
|
+
out[9] = a01 * s + a21 * c;
|
3193
|
+
out[10] = a02 * s + a22 * c;
|
3194
|
+
out[11] = a03 * s + a23 * c;
|
3195
|
+
return out;
|
3196
|
+
};
|
3197
|
+
|
3198
|
+
/**
|
3199
|
+
* Rotates a matrix by the given angle around the Z axis
|
3200
|
+
*
|
3201
|
+
* @param {mat4} out the receiving matrix
|
3202
|
+
* @param {mat4} a the matrix to rotate
|
3203
|
+
* @param {Number} rad the angle to rotate the matrix by
|
3204
|
+
* @returns {mat4} out
|
3205
|
+
*/
|
3206
|
+
mat4.rotateZ = function (out, a, rad) {
|
3207
|
+
var s = Math.sin(rad),
|
3208
|
+
c = Math.cos(rad),
|
3209
|
+
a00 = a[0],
|
3210
|
+
a01 = a[1],
|
3211
|
+
a02 = a[2],
|
3212
|
+
a03 = a[3],
|
3213
|
+
a10 = a[4],
|
3214
|
+
a11 = a[5],
|
3215
|
+
a12 = a[6],
|
3216
|
+
a13 = a[7];
|
3217
|
+
|
3218
|
+
if (a !== out) { // If the source and destination differ, copy the unchanged last row
|
3219
|
+
out[8] = a[8];
|
3220
|
+
out[9] = a[9];
|
3221
|
+
out[10] = a[10];
|
3222
|
+
out[11] = a[11];
|
3223
|
+
out[12] = a[12];
|
3224
|
+
out[13] = a[13];
|
3225
|
+
out[14] = a[14];
|
3226
|
+
out[15] = a[15];
|
3227
|
+
}
|
3228
|
+
|
3229
|
+
// Perform axis-specific matrix multiplication
|
3230
|
+
out[0] = a00 * c + a10 * s;
|
3231
|
+
out[1] = a01 * c + a11 * s;
|
3232
|
+
out[2] = a02 * c + a12 * s;
|
3233
|
+
out[3] = a03 * c + a13 * s;
|
3234
|
+
out[4] = a10 * c - a00 * s;
|
3235
|
+
out[5] = a11 * c - a01 * s;
|
3236
|
+
out[6] = a12 * c - a02 * s;
|
3237
|
+
out[7] = a13 * c - a03 * s;
|
3238
|
+
return out;
|
3239
|
+
};
|
3240
|
+
|
3241
|
+
/**
|
3242
|
+
* Creates a matrix from a quaternion rotation and vector translation
|
3243
|
+
* This is equivalent to (but much faster than):
|
3244
|
+
*
|
3245
|
+
* mat4.identity(dest);
|
3246
|
+
* mat4.translate(dest, vec);
|
3247
|
+
* var quatMat = mat4.create();
|
3248
|
+
* quat4.toMat4(quat, quatMat);
|
3249
|
+
* mat4.multiply(dest, quatMat);
|
3250
|
+
*
|
3251
|
+
* @param {mat4} out mat4 receiving operation result
|
3252
|
+
* @param {quat4} q Rotation quaternion
|
3253
|
+
* @param {vec3} v Translation vector
|
3254
|
+
* @returns {mat4} out
|
3255
|
+
*/
|
3256
|
+
mat4.fromRotationTranslation = function (out, q, v) {
|
3257
|
+
// Quaternion math
|
3258
|
+
var x = q[0], y = q[1], z = q[2], w = q[3],
|
3259
|
+
x2 = x + x,
|
3260
|
+
y2 = y + y,
|
3261
|
+
z2 = z + z,
|
3262
|
+
|
3263
|
+
xx = x * x2,
|
3264
|
+
xy = x * y2,
|
3265
|
+
xz = x * z2,
|
3266
|
+
yy = y * y2,
|
3267
|
+
yz = y * z2,
|
3268
|
+
zz = z * z2,
|
3269
|
+
wx = w * x2,
|
3270
|
+
wy = w * y2,
|
3271
|
+
wz = w * z2;
|
3272
|
+
|
3273
|
+
out[0] = 1 - (yy + zz);
|
3274
|
+
out[1] = xy + wz;
|
3275
|
+
out[2] = xz - wy;
|
3276
|
+
out[3] = 0;
|
3277
|
+
out[4] = xy - wz;
|
3278
|
+
out[5] = 1 - (xx + zz);
|
3279
|
+
out[6] = yz + wx;
|
3280
|
+
out[7] = 0;
|
3281
|
+
out[8] = xz + wy;
|
3282
|
+
out[9] = yz - wx;
|
3283
|
+
out[10] = 1 - (xx + yy);
|
3284
|
+
out[11] = 0;
|
3285
|
+
out[12] = v[0];
|
3286
|
+
out[13] = v[1];
|
3287
|
+
out[14] = v[2];
|
3288
|
+
out[15] = 1;
|
3289
|
+
|
3290
|
+
return out;
|
3291
|
+
};
|
3292
|
+
|
3293
|
+
/**
|
3294
|
+
* Calculates a 4x4 matrix from the given quaternion
|
3295
|
+
*
|
3296
|
+
* @param {mat4} out mat4 receiving operation result
|
3297
|
+
* @param {quat} q Quaternion to create matrix from
|
3298
|
+
*
|
3299
|
+
* @returns {mat4} out
|
3300
|
+
*/
|
3301
|
+
mat4.fromQuat = function (out, q) {
|
3302
|
+
var x = q[0], y = q[1], z = q[2], w = q[3],
|
3303
|
+
x2 = x + x,
|
3304
|
+
y2 = y + y,
|
3305
|
+
z2 = z + z,
|
3306
|
+
|
3307
|
+
xx = x * x2,
|
3308
|
+
xy = x * y2,
|
3309
|
+
xz = x * z2,
|
3310
|
+
yy = y * y2,
|
3311
|
+
yz = y * z2,
|
3312
|
+
zz = z * z2,
|
3313
|
+
wx = w * x2,
|
3314
|
+
wy = w * y2,
|
3315
|
+
wz = w * z2;
|
3316
|
+
|
3317
|
+
out[0] = 1 - (yy + zz);
|
3318
|
+
out[1] = xy + wz;
|
3319
|
+
out[2] = xz - wy;
|
3320
|
+
out[3] = 0;
|
3321
|
+
|
3322
|
+
out[4] = xy - wz;
|
3323
|
+
out[5] = 1 - (xx + zz);
|
3324
|
+
out[6] = yz + wx;
|
3325
|
+
out[7] = 0;
|
3326
|
+
|
3327
|
+
out[8] = xz + wy;
|
3328
|
+
out[9] = yz - wx;
|
3329
|
+
out[10] = 1 - (xx + yy);
|
3330
|
+
out[11] = 0;
|
3331
|
+
|
3332
|
+
out[12] = 0;
|
3333
|
+
out[13] = 0;
|
3334
|
+
out[14] = 0;
|
3335
|
+
out[15] = 1;
|
3336
|
+
|
3337
|
+
return out;
|
3338
|
+
};
|
3339
|
+
|
3340
|
+
/**
|
3341
|
+
* Generates a frustum matrix with the given bounds
|
3342
|
+
*
|
3343
|
+
* @param {mat4} out mat4 frustum matrix will be written into
|
3344
|
+
* @param {Number} left Left bound of the frustum
|
3345
|
+
* @param {Number} right Right bound of the frustum
|
3346
|
+
* @param {Number} bottom Bottom bound of the frustum
|
3347
|
+
* @param {Number} top Top bound of the frustum
|
3348
|
+
* @param {Number} near Near bound of the frustum
|
3349
|
+
* @param {Number} far Far bound of the frustum
|
3350
|
+
* @returns {mat4} out
|
3351
|
+
*/
|
3352
|
+
mat4.frustum = function (out, left, right, bottom, top, near, far) {
|
3353
|
+
var rl = 1 / (right - left),
|
3354
|
+
tb = 1 / (top - bottom),
|
3355
|
+
nf = 1 / (near - far);
|
3356
|
+
out[0] = (near * 2) * rl;
|
3357
|
+
out[1] = 0;
|
3358
|
+
out[2] = 0;
|
3359
|
+
out[3] = 0;
|
3360
|
+
out[4] = 0;
|
3361
|
+
out[5] = (near * 2) * tb;
|
3362
|
+
out[6] = 0;
|
3363
|
+
out[7] = 0;
|
3364
|
+
out[8] = (right + left) * rl;
|
3365
|
+
out[9] = (top + bottom) * tb;
|
3366
|
+
out[10] = (far + near) * nf;
|
3367
|
+
out[11] = -1;
|
3368
|
+
out[12] = 0;
|
3369
|
+
out[13] = 0;
|
3370
|
+
out[14] = (far * near * 2) * nf;
|
3371
|
+
out[15] = 0;
|
3372
|
+
return out;
|
3373
|
+
};
|
3374
|
+
|
3375
|
+
/**
|
3376
|
+
* Generates a perspective projection matrix with the given bounds
|
3377
|
+
*
|
3378
|
+
* @param {mat4} out mat4 frustum matrix will be written into
|
3379
|
+
* @param {number} fovy Vertical field of view in radians
|
3380
|
+
* @param {number} aspect Aspect ratio. typically viewport width/height
|
3381
|
+
* @param {number} near Near bound of the frustum
|
3382
|
+
* @param {number} far Far bound of the frustum
|
3383
|
+
* @returns {mat4} out
|
3384
|
+
*/
|
3385
|
+
mat4.perspective = function (out, fovy, aspect, near, far) {
|
3386
|
+
var f = 1.0 / Math.tan(fovy / 2),
|
3387
|
+
nf = 1 / (near - far);
|
3388
|
+
out[0] = f / aspect;
|
3389
|
+
out[1] = 0;
|
3390
|
+
out[2] = 0;
|
3391
|
+
out[3] = 0;
|
3392
|
+
out[4] = 0;
|
3393
|
+
out[5] = f;
|
3394
|
+
out[6] = 0;
|
3395
|
+
out[7] = 0;
|
3396
|
+
out[8] = 0;
|
3397
|
+
out[9] = 0;
|
3398
|
+
out[10] = (far + near) * nf;
|
3399
|
+
out[11] = -1;
|
3400
|
+
out[12] = 0;
|
3401
|
+
out[13] = 0;
|
3402
|
+
out[14] = (2 * far * near) * nf;
|
3403
|
+
out[15] = 0;
|
3404
|
+
return out;
|
3405
|
+
};
|
3406
|
+
|
3407
|
+
/**
|
3408
|
+
* Generates a orthogonal projection matrix with the given bounds
|
3409
|
+
*
|
3410
|
+
* @param {mat4} out mat4 frustum matrix will be written into
|
3411
|
+
* @param {number} left Left bound of the frustum
|
3412
|
+
* @param {number} right Right bound of the frustum
|
3413
|
+
* @param {number} bottom Bottom bound of the frustum
|
3414
|
+
* @param {number} top Top bound of the frustum
|
3415
|
+
* @param {number} near Near bound of the frustum
|
3416
|
+
* @param {number} far Far bound of the frustum
|
3417
|
+
* @returns {mat4} out
|
3418
|
+
*/
|
3419
|
+
mat4.ortho = function (out, left, right, bottom, top, near, far) {
|
3420
|
+
var lr = 1 / (left - right),
|
3421
|
+
bt = 1 / (bottom - top),
|
3422
|
+
nf = 1 / (near - far);
|
3423
|
+
out[0] = -2 * lr;
|
3424
|
+
out[1] = 0;
|
3425
|
+
out[2] = 0;
|
3426
|
+
out[3] = 0;
|
3427
|
+
out[4] = 0;
|
3428
|
+
out[5] = -2 * bt;
|
3429
|
+
out[6] = 0;
|
3430
|
+
out[7] = 0;
|
3431
|
+
out[8] = 0;
|
3432
|
+
out[9] = 0;
|
3433
|
+
out[10] = 2 * nf;
|
3434
|
+
out[11] = 0;
|
3435
|
+
out[12] = (left + right) * lr;
|
3436
|
+
out[13] = (top + bottom) * bt;
|
3437
|
+
out[14] = (far + near) * nf;
|
3438
|
+
out[15] = 1;
|
3439
|
+
return out;
|
3440
|
+
};
|
3441
|
+
|
3442
|
+
/**
|
3443
|
+
* Generates a look-at matrix with the given eye position, focal point, and up axis
|
3444
|
+
*
|
3445
|
+
* @param {mat4} out mat4 frustum matrix will be written into
|
3446
|
+
* @param {vec3} eye Position of the viewer
|
3447
|
+
* @param {vec3} center Point the viewer is looking at
|
3448
|
+
* @param {vec3} up vec3 pointing up
|
3449
|
+
* @returns {mat4} out
|
3450
|
+
*/
|
3451
|
+
mat4.lookAt = function (out, eye, center, up) {
|
3452
|
+
var x0, x1, x2, y0, y1, y2, z0, z1, z2, len,
|
3453
|
+
eyex = eye[0],
|
3454
|
+
eyey = eye[1],
|
3455
|
+
eyez = eye[2],
|
3456
|
+
upx = up[0],
|
3457
|
+
upy = up[1],
|
3458
|
+
upz = up[2],
|
3459
|
+
centerx = center[0],
|
3460
|
+
centery = center[1],
|
3461
|
+
centerz = center[2];
|
3462
|
+
|
3463
|
+
if (Math.abs(eyex - centerx) < GLMAT_EPSILON &&
|
3464
|
+
Math.abs(eyey - centery) < GLMAT_EPSILON &&
|
3465
|
+
Math.abs(eyez - centerz) < GLMAT_EPSILON) {
|
3466
|
+
return mat4.identity(out);
|
3467
|
+
}
|
3468
|
+
|
3469
|
+
z0 = eyex - centerx;
|
3470
|
+
z1 = eyey - centery;
|
3471
|
+
z2 = eyez - centerz;
|
3472
|
+
|
3473
|
+
len = 1 / Math.sqrt(z0 * z0 + z1 * z1 + z2 * z2);
|
3474
|
+
z0 *= len;
|
3475
|
+
z1 *= len;
|
3476
|
+
z2 *= len;
|
3477
|
+
|
3478
|
+
x0 = upy * z2 - upz * z1;
|
3479
|
+
x1 = upz * z0 - upx * z2;
|
3480
|
+
x2 = upx * z1 - upy * z0;
|
3481
|
+
len = Math.sqrt(x0 * x0 + x1 * x1 + x2 * x2);
|
3482
|
+
if (!len) {
|
3483
|
+
x0 = 0;
|
3484
|
+
x1 = 0;
|
3485
|
+
x2 = 0;
|
3486
|
+
} else {
|
3487
|
+
len = 1 / len;
|
3488
|
+
x0 *= len;
|
3489
|
+
x1 *= len;
|
3490
|
+
x2 *= len;
|
3491
|
+
}
|
3492
|
+
|
3493
|
+
y0 = z1 * x2 - z2 * x1;
|
3494
|
+
y1 = z2 * x0 - z0 * x2;
|
3495
|
+
y2 = z0 * x1 - z1 * x0;
|
3496
|
+
|
3497
|
+
len = Math.sqrt(y0 * y0 + y1 * y1 + y2 * y2);
|
3498
|
+
if (!len) {
|
3499
|
+
y0 = 0;
|
3500
|
+
y1 = 0;
|
3501
|
+
y2 = 0;
|
3502
|
+
} else {
|
3503
|
+
len = 1 / len;
|
3504
|
+
y0 *= len;
|
3505
|
+
y1 *= len;
|
3506
|
+
y2 *= len;
|
3507
|
+
}
|
3508
|
+
|
3509
|
+
out[0] = x0;
|
3510
|
+
out[1] = y0;
|
3511
|
+
out[2] = z0;
|
3512
|
+
out[3] = 0;
|
3513
|
+
out[4] = x1;
|
3514
|
+
out[5] = y1;
|
3515
|
+
out[6] = z1;
|
3516
|
+
out[7] = 0;
|
3517
|
+
out[8] = x2;
|
3518
|
+
out[9] = y2;
|
3519
|
+
out[10] = z2;
|
3520
|
+
out[11] = 0;
|
3521
|
+
out[12] = -(x0 * eyex + x1 * eyey + x2 * eyez);
|
3522
|
+
out[13] = -(y0 * eyex + y1 * eyey + y2 * eyez);
|
3523
|
+
out[14] = -(z0 * eyex + z1 * eyey + z2 * eyez);
|
3524
|
+
out[15] = 1;
|
3525
|
+
|
3526
|
+
return out;
|
3527
|
+
};
|
3528
|
+
|
3529
|
+
/**
|
3530
|
+
* Returns a string representation of a mat4
|
3531
|
+
*
|
3532
|
+
* @param {mat4} mat matrix to represent as a string
|
3533
|
+
* @returns {String} string representation of the matrix
|
3534
|
+
*/
|
3535
|
+
mat4.str = function (a) {
|
3536
|
+
return 'mat4(' + a[0] + ', ' + a[1] + ', ' + a[2] + ', ' + a[3] + ', ' +
|
3537
|
+
a[4] + ', ' + a[5] + ', ' + a[6] + ', ' + a[7] + ', ' +
|
3538
|
+
a[8] + ', ' + a[9] + ', ' + a[10] + ', ' + a[11] + ', ' +
|
3539
|
+
a[12] + ', ' + a[13] + ', ' + a[14] + ', ' + a[15] + ')';
|
3540
|
+
};
|
3541
|
+
|
3542
|
+
if(typeof(exports) !== 'undefined') {
|
3543
|
+
exports.mat4 = mat4;
|
3544
|
+
}
|
3545
|
+
;
|
3546
|
+
/* Copyright (c) 2013, Brandon Jones, Colin MacKenzie IV. All rights reserved.
|
3547
|
+
|
3548
|
+
Redistribution and use in source and binary forms, with or without modification,
|
3549
|
+
are permitted provided that the following conditions are met:
|
3550
|
+
|
3551
|
+
* Redistributions of source code must retain the above copyright notice, this
|
3552
|
+
list of conditions and the following disclaimer.
|
3553
|
+
* Redistributions in binary form must reproduce the above copyright notice,
|
3554
|
+
this list of conditions and the following disclaimer in the documentation
|
3555
|
+
and/or other materials provided with the distribution.
|
3556
|
+
|
3557
|
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
3558
|
+
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
3559
|
+
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
3560
|
+
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
|
3561
|
+
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
3562
|
+
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
3563
|
+
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
3564
|
+
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
3565
|
+
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
3566
|
+
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */
|
3567
|
+
|
3568
|
+
/**
|
3569
|
+
* @class Quaternion
|
3570
|
+
* @name quat
|
3571
|
+
*/
|
3572
|
+
|
3573
|
+
var quat = {};
|
3574
|
+
|
3575
|
+
/**
|
3576
|
+
* Creates a new identity quat
|
3577
|
+
*
|
3578
|
+
* @returns {quat} a new quaternion
|
3579
|
+
*/
|
3580
|
+
quat.create = function() {
|
3581
|
+
var out = new GLMAT_ARRAY_TYPE(4);
|
3582
|
+
out[0] = 0;
|
3583
|
+
out[1] = 0;
|
3584
|
+
out[2] = 0;
|
3585
|
+
out[3] = 1;
|
3586
|
+
return out;
|
3587
|
+
};
|
3588
|
+
|
3589
|
+
/**
|
3590
|
+
* Sets a quaternion to represent the shortest rotation from one
|
3591
|
+
* vector to another.
|
3592
|
+
*
|
3593
|
+
* Both vectors are assumed to be unit length.
|
3594
|
+
*
|
3595
|
+
* @param {quat} out the receiving quaternion.
|
3596
|
+
* @param {vec3} a the initial vector
|
3597
|
+
* @param {vec3} b the destination vector
|
3598
|
+
* @returns {quat} out
|
3599
|
+
*/
|
3600
|
+
quat.rotationTo = (function() {
|
3601
|
+
var tmpvec3 = vec3.create();
|
3602
|
+
var xUnitVec3 = vec3.fromValues(1,0,0);
|
3603
|
+
var yUnitVec3 = vec3.fromValues(0,1,0);
|
3604
|
+
|
3605
|
+
return function(out, a, b) {
|
3606
|
+
var dot = vec3.dot(a, b);
|
3607
|
+
if (dot < -0.999999) {
|
3608
|
+
vec3.cross(tmpvec3, xUnitVec3, a);
|
3609
|
+
if (vec3.length(tmpvec3) < 0.000001)
|
3610
|
+
vec3.cross(tmpvec3, yUnitVec3, a);
|
3611
|
+
vec3.normalize(tmpvec3, tmpvec3);
|
3612
|
+
quat.setAxisAngle(out, tmpvec3, Math.PI);
|
3613
|
+
return out;
|
3614
|
+
} else if (dot > 0.999999) {
|
3615
|
+
out[0] = 0;
|
3616
|
+
out[1] = 0;
|
3617
|
+
out[2] = 0;
|
3618
|
+
out[3] = 1;
|
3619
|
+
return out;
|
3620
|
+
} else {
|
3621
|
+
vec3.cross(tmpvec3, a, b);
|
3622
|
+
out[0] = tmpvec3[0];
|
3623
|
+
out[1] = tmpvec3[1];
|
3624
|
+
out[2] = tmpvec3[2];
|
3625
|
+
out[3] = 1 + dot;
|
3626
|
+
return quat.normalize(out, out);
|
3627
|
+
}
|
3628
|
+
};
|
3629
|
+
})();
|
3630
|
+
|
3631
|
+
/**
|
3632
|
+
* Sets the specified quaternion with values corresponding to the given
|
3633
|
+
* axes. Each axis is a vec3 and is expected to be unit length and
|
3634
|
+
* perpendicular to all other specified axes.
|
3635
|
+
*
|
3636
|
+
* @param {vec3} view the vector representing the viewing direction
|
3637
|
+
* @param {vec3} right the vector representing the local "right" direction
|
3638
|
+
* @param {vec3} up the vector representing the local "up" direction
|
3639
|
+
* @returns {quat} out
|
3640
|
+
*/
|
3641
|
+
quat.setAxes = (function() {
|
3642
|
+
var matr = mat3.create();
|
3643
|
+
|
3644
|
+
return function(out, view, right, up) {
|
3645
|
+
matr[0] = right[0];
|
3646
|
+
matr[3] = right[1];
|
3647
|
+
matr[6] = right[2];
|
3648
|
+
|
3649
|
+
matr[1] = up[0];
|
3650
|
+
matr[4] = up[1];
|
3651
|
+
matr[7] = up[2];
|
3652
|
+
|
3653
|
+
matr[2] = view[0];
|
3654
|
+
matr[5] = view[1];
|
3655
|
+
matr[8] = view[2];
|
3656
|
+
|
3657
|
+
return quat.normalize(out, quat.fromMat3(out, matr));
|
3658
|
+
};
|
3659
|
+
})();
|
3660
|
+
|
3661
|
+
/**
|
3662
|
+
* Creates a new quat initialized with values from an existing quaternion
|
3663
|
+
*
|
3664
|
+
* @param {quat} a quaternion to clone
|
3665
|
+
* @returns {quat} a new quaternion
|
3666
|
+
* @function
|
3667
|
+
*/
|
3668
|
+
quat.clone = vec4.clone;
|
3669
|
+
|
3670
|
+
/**
|
3671
|
+
* Creates a new quat initialized with the given values
|
3672
|
+
*
|
3673
|
+
* @param {Number} x X component
|
3674
|
+
* @param {Number} y Y component
|
3675
|
+
* @param {Number} z Z component
|
3676
|
+
* @param {Number} w W component
|
3677
|
+
* @returns {quat} a new quaternion
|
3678
|
+
* @function
|
3679
|
+
*/
|
3680
|
+
quat.fromValues = vec4.fromValues;
|
3681
|
+
|
3682
|
+
/**
|
3683
|
+
* Copy the values from one quat to another
|
3684
|
+
*
|
3685
|
+
* @param {quat} out the receiving quaternion
|
3686
|
+
* @param {quat} a the source quaternion
|
3687
|
+
* @returns {quat} out
|
3688
|
+
* @function
|
3689
|
+
*/
|
3690
|
+
quat.copy = vec4.copy;
|
3691
|
+
|
3692
|
+
/**
|
3693
|
+
* Set the components of a quat to the given values
|
3694
|
+
*
|
3695
|
+
* @param {quat} out the receiving quaternion
|
3696
|
+
* @param {Number} x X component
|
3697
|
+
* @param {Number} y Y component
|
3698
|
+
* @param {Number} z Z component
|
3699
|
+
* @param {Number} w W component
|
3700
|
+
* @returns {quat} out
|
3701
|
+
* @function
|
3702
|
+
*/
|
3703
|
+
quat.set = vec4.set;
|
3704
|
+
|
3705
|
+
/**
|
3706
|
+
* Set a quat to the identity quaternion
|
3707
|
+
*
|
3708
|
+
* @param {quat} out the receiving quaternion
|
3709
|
+
* @returns {quat} out
|
3710
|
+
*/
|
3711
|
+
quat.identity = function(out) {
|
3712
|
+
out[0] = 0;
|
3713
|
+
out[1] = 0;
|
3714
|
+
out[2] = 0;
|
3715
|
+
out[3] = 1;
|
3716
|
+
return out;
|
3717
|
+
};
|
3718
|
+
|
3719
|
+
/**
|
3720
|
+
* Sets a quat from the given angle and rotation axis,
|
3721
|
+
* then returns it.
|
3722
|
+
*
|
3723
|
+
* @param {quat} out the receiving quaternion
|
3724
|
+
* @param {vec3} axis the axis around which to rotate
|
3725
|
+
* @param {Number} rad the angle in radians
|
3726
|
+
* @returns {quat} out
|
3727
|
+
**/
|
3728
|
+
quat.setAxisAngle = function(out, axis, rad) {
|
3729
|
+
rad = rad * 0.5;
|
3730
|
+
var s = Math.sin(rad);
|
3731
|
+
out[0] = s * axis[0];
|
3732
|
+
out[1] = s * axis[1];
|
3733
|
+
out[2] = s * axis[2];
|
3734
|
+
out[3] = Math.cos(rad);
|
3735
|
+
return out;
|
3736
|
+
};
|
3737
|
+
|
3738
|
+
/**
|
3739
|
+
* Adds two quat's
|
3740
|
+
*
|
3741
|
+
* @param {quat} out the receiving quaternion
|
3742
|
+
* @param {quat} a the first operand
|
3743
|
+
* @param {quat} b the second operand
|
3744
|
+
* @returns {quat} out
|
3745
|
+
* @function
|
3746
|
+
*/
|
3747
|
+
quat.add = vec4.add;
|
3748
|
+
|
3749
|
+
/**
|
3750
|
+
* Multiplies two quat's
|
3751
|
+
*
|
3752
|
+
* @param {quat} out the receiving quaternion
|
3753
|
+
* @param {quat} a the first operand
|
3754
|
+
* @param {quat} b the second operand
|
3755
|
+
* @returns {quat} out
|
3756
|
+
*/
|
3757
|
+
quat.multiply = function(out, a, b) {
|
3758
|
+
var ax = a[0], ay = a[1], az = a[2], aw = a[3],
|
3759
|
+
bx = b[0], by = b[1], bz = b[2], bw = b[3];
|
3760
|
+
|
3761
|
+
out[0] = ax * bw + aw * bx + ay * bz - az * by;
|
3762
|
+
out[1] = ay * bw + aw * by + az * bx - ax * bz;
|
3763
|
+
out[2] = az * bw + aw * bz + ax * by - ay * bx;
|
3764
|
+
out[3] = aw * bw - ax * bx - ay * by - az * bz;
|
3765
|
+
return out;
|
3766
|
+
};
|
3767
|
+
|
3768
|
+
/**
|
3769
|
+
* Alias for {@link quat.multiply}
|
3770
|
+
* @function
|
3771
|
+
*/
|
3772
|
+
quat.mul = quat.multiply;
|
3773
|
+
|
3774
|
+
/**
|
3775
|
+
* Scales a quat by a scalar number
|
3776
|
+
*
|
3777
|
+
* @param {quat} out the receiving vector
|
3778
|
+
* @param {quat} a the vector to scale
|
3779
|
+
* @param {Number} b amount to scale the vector by
|
3780
|
+
* @returns {quat} out
|
3781
|
+
* @function
|
3782
|
+
*/
|
3783
|
+
quat.scale = vec4.scale;
|
3784
|
+
|
3785
|
+
/**
|
3786
|
+
* Rotates a quaternion by the given angle about the X axis
|
3787
|
+
*
|
3788
|
+
* @param {quat} out quat receiving operation result
|
3789
|
+
* @param {quat} a quat to rotate
|
3790
|
+
* @param {number} rad angle (in radians) to rotate
|
3791
|
+
* @returns {quat} out
|
3792
|
+
*/
|
3793
|
+
quat.rotateX = function (out, a, rad) {
|
3794
|
+
rad *= 0.5;
|
3795
|
+
|
3796
|
+
var ax = a[0], ay = a[1], az = a[2], aw = a[3],
|
3797
|
+
bx = Math.sin(rad), bw = Math.cos(rad);
|
3798
|
+
|
3799
|
+
out[0] = ax * bw + aw * bx;
|
3800
|
+
out[1] = ay * bw + az * bx;
|
3801
|
+
out[2] = az * bw - ay * bx;
|
3802
|
+
out[3] = aw * bw - ax * bx;
|
3803
|
+
return out;
|
3804
|
+
};
|
3805
|
+
|
3806
|
+
/**
|
3807
|
+
* Rotates a quaternion by the given angle about the Y axis
|
3808
|
+
*
|
3809
|
+
* @param {quat} out quat receiving operation result
|
3810
|
+
* @param {quat} a quat to rotate
|
3811
|
+
* @param {number} rad angle (in radians) to rotate
|
3812
|
+
* @returns {quat} out
|
3813
|
+
*/
|
3814
|
+
quat.rotateY = function (out, a, rad) {
|
3815
|
+
rad *= 0.5;
|
3816
|
+
|
3817
|
+
var ax = a[0], ay = a[1], az = a[2], aw = a[3],
|
3818
|
+
by = Math.sin(rad), bw = Math.cos(rad);
|
3819
|
+
|
3820
|
+
out[0] = ax * bw - az * by;
|
3821
|
+
out[1] = ay * bw + aw * by;
|
3822
|
+
out[2] = az * bw + ax * by;
|
3823
|
+
out[3] = aw * bw - ay * by;
|
3824
|
+
return out;
|
3825
|
+
};
|
3826
|
+
|
3827
|
+
/**
|
3828
|
+
* Rotates a quaternion by the given angle about the Z axis
|
3829
|
+
*
|
3830
|
+
* @param {quat} out quat receiving operation result
|
3831
|
+
* @param {quat} a quat to rotate
|
3832
|
+
* @param {number} rad angle (in radians) to rotate
|
3833
|
+
* @returns {quat} out
|
3834
|
+
*/
|
3835
|
+
quat.rotateZ = function (out, a, rad) {
|
3836
|
+
rad *= 0.5;
|
3837
|
+
|
3838
|
+
var ax = a[0], ay = a[1], az = a[2], aw = a[3],
|
3839
|
+
bz = Math.sin(rad), bw = Math.cos(rad);
|
3840
|
+
|
3841
|
+
out[0] = ax * bw + ay * bz;
|
3842
|
+
out[1] = ay * bw - ax * bz;
|
3843
|
+
out[2] = az * bw + aw * bz;
|
3844
|
+
out[3] = aw * bw - az * bz;
|
3845
|
+
return out;
|
3846
|
+
};
|
3847
|
+
|
3848
|
+
/**
|
3849
|
+
* Calculates the W component of a quat from the X, Y, and Z components.
|
3850
|
+
* Assumes that quaternion is 1 unit in length.
|
3851
|
+
* Any existing W component will be ignored.
|
3852
|
+
*
|
3853
|
+
* @param {quat} out the receiving quaternion
|
3854
|
+
* @param {quat} a quat to calculate W component of
|
3855
|
+
* @returns {quat} out
|
3856
|
+
*/
|
3857
|
+
quat.calculateW = function (out, a) {
|
3858
|
+
var x = a[0], y = a[1], z = a[2];
|
3859
|
+
|
3860
|
+
out[0] = x;
|
3861
|
+
out[1] = y;
|
3862
|
+
out[2] = z;
|
3863
|
+
out[3] = -Math.sqrt(Math.abs(1.0 - x * x - y * y - z * z));
|
3864
|
+
return out;
|
3865
|
+
};
|
3866
|
+
|
3867
|
+
/**
|
3868
|
+
* Calculates the dot product of two quat's
|
3869
|
+
*
|
3870
|
+
* @param {quat} a the first operand
|
3871
|
+
* @param {quat} b the second operand
|
3872
|
+
* @returns {Number} dot product of a and b
|
3873
|
+
* @function
|
3874
|
+
*/
|
3875
|
+
quat.dot = vec4.dot;
|
3876
|
+
|
3877
|
+
/**
|
3878
|
+
* Performs a linear interpolation between two quat's
|
3879
|
+
*
|
3880
|
+
* @param {quat} out the receiving quaternion
|
3881
|
+
* @param {quat} a the first operand
|
3882
|
+
* @param {quat} b the second operand
|
3883
|
+
* @param {Number} t interpolation amount between the two inputs
|
3884
|
+
* @returns {quat} out
|
3885
|
+
* @function
|
3886
|
+
*/
|
3887
|
+
quat.lerp = vec4.lerp;
|
3888
|
+
|
3889
|
+
/**
|
3890
|
+
* Performs a spherical linear interpolation between two quat
|
3891
|
+
*
|
3892
|
+
* @param {quat} out the receiving quaternion
|
3893
|
+
* @param {quat} a the first operand
|
3894
|
+
* @param {quat} b the second operand
|
3895
|
+
* @param {Number} t interpolation amount between the two inputs
|
3896
|
+
* @returns {quat} out
|
3897
|
+
*/
|
3898
|
+
quat.slerp = function (out, a, b, t) {
|
3899
|
+
// benchmarks:
|
3900
|
+
// http://jsperf.com/quaternion-slerp-implementations
|
3901
|
+
|
3902
|
+
var ax = a[0], ay = a[1], az = a[2], aw = a[3],
|
3903
|
+
bx = b[0], by = b[1], bz = b[2], bw = b[3];
|
3904
|
+
|
3905
|
+
var omega, cosom, sinom, scale0, scale1;
|
3906
|
+
|
3907
|
+
// calc cosine
|
3908
|
+
cosom = ax * bx + ay * by + az * bz + aw * bw;
|
3909
|
+
// adjust signs (if necessary)
|
3910
|
+
if ( cosom < 0.0 ) {
|
3911
|
+
cosom = -cosom;
|
3912
|
+
bx = - bx;
|
3913
|
+
by = - by;
|
3914
|
+
bz = - bz;
|
3915
|
+
bw = - bw;
|
3916
|
+
}
|
3917
|
+
// calculate coefficients
|
3918
|
+
if ( (1.0 - cosom) > 0.000001 ) {
|
3919
|
+
// standard case (slerp)
|
3920
|
+
omega = Math.acos(cosom);
|
3921
|
+
sinom = Math.sin(omega);
|
3922
|
+
scale0 = Math.sin((1.0 - t) * omega) / sinom;
|
3923
|
+
scale1 = Math.sin(t * omega) / sinom;
|
3924
|
+
} else {
|
3925
|
+
// "from" and "to" quaternions are very close
|
3926
|
+
// ... so we can do a linear interpolation
|
3927
|
+
scale0 = 1.0 - t;
|
3928
|
+
scale1 = t;
|
3929
|
+
}
|
3930
|
+
// calculate final values
|
3931
|
+
out[0] = scale0 * ax + scale1 * bx;
|
3932
|
+
out[1] = scale0 * ay + scale1 * by;
|
3933
|
+
out[2] = scale0 * az + scale1 * bz;
|
3934
|
+
out[3] = scale0 * aw + scale1 * bw;
|
3935
|
+
|
3936
|
+
return out;
|
3937
|
+
};
|
3938
|
+
|
3939
|
+
/**
|
3940
|
+
* Calculates the inverse of a quat
|
3941
|
+
*
|
3942
|
+
* @param {quat} out the receiving quaternion
|
3943
|
+
* @param {quat} a quat to calculate inverse of
|
3944
|
+
* @returns {quat} out
|
3945
|
+
*/
|
3946
|
+
quat.invert = function(out, a) {
|
3947
|
+
var a0 = a[0], a1 = a[1], a2 = a[2], a3 = a[3],
|
3948
|
+
dot = a0*a0 + a1*a1 + a2*a2 + a3*a3,
|
3949
|
+
invDot = dot ? 1.0/dot : 0;
|
3950
|
+
|
3951
|
+
// TODO: Would be faster to return [0,0,0,0] immediately if dot == 0
|
3952
|
+
|
3953
|
+
out[0] = -a0*invDot;
|
3954
|
+
out[1] = -a1*invDot;
|
3955
|
+
out[2] = -a2*invDot;
|
3956
|
+
out[3] = a3*invDot;
|
3957
|
+
return out;
|
3958
|
+
};
|
3959
|
+
|
3960
|
+
/**
|
3961
|
+
* Calculates the conjugate of a quat
|
3962
|
+
* If the quaternion is normalized, this function is faster than quat.inverse and produces the same result.
|
3963
|
+
*
|
3964
|
+
* @param {quat} out the receiving quaternion
|
3965
|
+
* @param {quat} a quat to calculate conjugate of
|
3966
|
+
* @returns {quat} out
|
3967
|
+
*/
|
3968
|
+
quat.conjugate = function (out, a) {
|
3969
|
+
out[0] = -a[0];
|
3970
|
+
out[1] = -a[1];
|
3971
|
+
out[2] = -a[2];
|
3972
|
+
out[3] = a[3];
|
3973
|
+
return out;
|
3974
|
+
};
|
3975
|
+
|
3976
|
+
/**
|
3977
|
+
* Calculates the length of a quat
|
3978
|
+
*
|
3979
|
+
* @param {quat} a vector to calculate length of
|
3980
|
+
* @returns {Number} length of a
|
3981
|
+
* @function
|
3982
|
+
*/
|
3983
|
+
quat.length = vec4.length;
|
3984
|
+
|
3985
|
+
/**
|
3986
|
+
* Alias for {@link quat.length}
|
3987
|
+
* @function
|
3988
|
+
*/
|
3989
|
+
quat.len = quat.length;
|
3990
|
+
|
3991
|
+
/**
|
3992
|
+
* Calculates the squared length of a quat
|
3993
|
+
*
|
3994
|
+
* @param {quat} a vector to calculate squared length of
|
3995
|
+
* @returns {Number} squared length of a
|
3996
|
+
* @function
|
3997
|
+
*/
|
3998
|
+
quat.squaredLength = vec4.squaredLength;
|
3999
|
+
|
4000
|
+
/**
|
4001
|
+
* Alias for {@link quat.squaredLength}
|
4002
|
+
* @function
|
4003
|
+
*/
|
4004
|
+
quat.sqrLen = quat.squaredLength;
|
4005
|
+
|
4006
|
+
/**
|
4007
|
+
* Normalize a quat
|
4008
|
+
*
|
4009
|
+
* @param {quat} out the receiving quaternion
|
4010
|
+
* @param {quat} a quaternion to normalize
|
4011
|
+
* @returns {quat} out
|
4012
|
+
* @function
|
4013
|
+
*/
|
4014
|
+
quat.normalize = vec4.normalize;
|
4015
|
+
|
4016
|
+
/**
|
4017
|
+
* Creates a quaternion from the given 3x3 rotation matrix.
|
4018
|
+
*
|
4019
|
+
* NOTE: The resultant quaternion is not normalized, so you should be sure
|
4020
|
+
* to renormalize the quaternion yourself where necessary.
|
4021
|
+
*
|
4022
|
+
* @param {quat} out the receiving quaternion
|
4023
|
+
* @param {mat3} m rotation matrix
|
4024
|
+
* @returns {quat} out
|
4025
|
+
* @function
|
4026
|
+
*/
|
4027
|
+
quat.fromMat3 = (function() {
|
4028
|
+
// benchmarks:
|
4029
|
+
// http://jsperf.com/typed-array-access-speed
|
4030
|
+
// http://jsperf.com/conversion-of-3x3-matrix-to-quaternion
|
4031
|
+
|
4032
|
+
var s_iNext = (typeof(Int8Array) !== 'undefined' ? new Int8Array([1,2,0]) : [1,2,0]);
|
4033
|
+
|
4034
|
+
return function(out, m) {
|
4035
|
+
// Algorithm in Ken Shoemake's article in 1987 SIGGRAPH course notes
|
4036
|
+
// article "Quaternion Calculus and Fast Animation".
|
4037
|
+
var fTrace = m[0] + m[4] + m[8];
|
4038
|
+
var fRoot;
|
4039
|
+
|
4040
|
+
if ( fTrace > 0.0 ) {
|
4041
|
+
// |w| > 1/2, may as well choose w > 1/2
|
4042
|
+
fRoot = Math.sqrt(fTrace + 1.0); // 2w
|
4043
|
+
out[3] = 0.5 * fRoot;
|
4044
|
+
fRoot = 0.5/fRoot; // 1/(4w)
|
4045
|
+
out[0] = (m[7]-m[5])*fRoot;
|
4046
|
+
out[1] = (m[2]-m[6])*fRoot;
|
4047
|
+
out[2] = (m[3]-m[1])*fRoot;
|
4048
|
+
} else {
|
4049
|
+
// |w| <= 1/2
|
4050
|
+
var i = 0;
|
4051
|
+
if ( m[4] > m[0] )
|
4052
|
+
i = 1;
|
4053
|
+
if ( m[8] > m[i*3+i] )
|
4054
|
+
i = 2;
|
4055
|
+
var j = s_iNext[i];
|
4056
|
+
var k = s_iNext[j];
|
4057
|
+
|
4058
|
+
fRoot = Math.sqrt(m[i*3+i]-m[j*3+j]-m[k*3+k] + 1.0);
|
4059
|
+
out[i] = 0.5 * fRoot;
|
4060
|
+
fRoot = 0.5 / fRoot;
|
4061
|
+
out[3] = (m[k*3+j] - m[j*3+k]) * fRoot;
|
4062
|
+
out[j] = (m[j*3+i] + m[i*3+j]) * fRoot;
|
4063
|
+
out[k] = (m[k*3+i] + m[i*3+k]) * fRoot;
|
4064
|
+
}
|
4065
|
+
|
4066
|
+
return out;
|
4067
|
+
};
|
4068
|
+
})();
|
4069
|
+
|
4070
|
+
/**
|
4071
|
+
* Returns a string representation of a quatenion
|
4072
|
+
*
|
4073
|
+
* @param {quat} vec vector to represent as a string
|
4074
|
+
* @returns {String} string representation of the vector
|
4075
|
+
*/
|
4076
|
+
quat.str = function (a) {
|
4077
|
+
return 'quat(' + a[0] + ', ' + a[1] + ', ' + a[2] + ', ' + a[3] + ')';
|
4078
|
+
};
|