Comparing version 2.0.0 to 2.2.1
@@ -5,5 +5,5 @@ /** | ||
* @author Colin MacKenzie IV | ||
* @version 2.0.0 | ||
* @version 2.2.1 | ||
*/ | ||
/* Copyright (c) 2012, Brandon Jones, Colin MacKenzie IV. All rights reserved. | ||
/* Copyright (c) 2013, Brandon Jones, Colin MacKenzie IV. All rights reserved. | ||
@@ -16,3 +16,3 @@ Redistribution and use in source and binary forms, with or without modification, | ||
* Redistributions in binary form must reproduce the above copyright notice, | ||
this list of conditions and the following disclaimer in the documentation | ||
this list of conditions and the following disclaimer in the documentation | ||
and/or other materials provided with the distribution. | ||
@@ -22,3 +22,3 @@ | ||
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR | ||
@@ -31,2 +31,2 @@ ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ | ||
(function(){"use strict";var e={};typeof exports=="undefined"?typeof define=="function"&&typeof define.amd=="object"&&define.amd?(e.exports={},define(function(){return e.exports})):e.exports=window:e.exports=exports,function(e){var t={};if(!n)var n=1e-6;t.create=function(){return new Float32Array(2)},t.clone=function(e){var t=new Float32Array(2);return t[0]=e[0],t[1]=e[1],t},t.fromValues=function(e,t){var n=new Float32Array(2);return n[0]=e,n[1]=t,n},t.copy=function(e,t){return e[0]=t[0],e[1]=t[1],e},t.set=function(e,t,n){return e[0]=t,e[1]=n,e},t.add=function(e,t,n){return e[0]=t[0]+n[0],e[1]=t[1]+n[1],e},t.sub=t.subtract=function(e,t,n){return e[0]=t[0]-n[0],e[1]=t[1]-n[1],e},t.mul=t.multiply=function(e,t,n){return e[0]=t[0]*n[0],e[1]=t[1]*n[1],e},t.div=t.divide=function(e,t,n){return e[0]=t[0]/n[0],e[1]=t[1]/n[1],e},t.min=function(e,t,n){return e[0]=Math.min(t[0],n[0]),e[1]=Math.min(t[1],n[1]),e},t.max=function(e,t,n){return e[0]=Math.max(t[0],n[0]),e[1]=Math.max(t[1],n[1]),e},t.scale=function(e,t,n){return e[0]=t[0]*n,e[1]=t[1]*n,e},t.dist=t.distance=function(e,t){var n=t[0]-e[0],r=t[1]-e[1];return Math.sqrt(n*n+r*r)},t.sqrDist=t.squaredDistance=function(e,t){var n=t[0]-e[0],r=t[1]-e[1];return n*n+r*r},t.len=t.length=function(e){var t=e[0],n=e[1];return Math.sqrt(t*t+n*n)},t.sqrLen=t.squaredLength=function(e){var t=e[0],n=e[1];return t*t+n*n},t.negate=function(e,t){return e[0]=-t[0],e[1]=-t[1],e},t.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},t.dot=function(e,t){return e[0]*t[0]+e[1]*t[1]},t.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},t.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},t.transformMat2=function(e,t,n){var r=t[0],i=t[1];return e[0]=r*n[0]+i*n[1],e[1]=r*n[2]+i*n[3],e},t.forEach=function(){var e=new Float32Array(2);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}}(),t.str=function(e){return"vec2("+e[0]+", "+e[1]+")"},typeof e!="undefined"&&(e.vec2=t);var r={};if(!n)var n=1e-6;r.create=function(){return new Float32Array(3)},r.clone=function(e){var t=new Float32Array(3);return t[0]=e[0],t[1]=e[1],t[2]=e[2],t},r.fromValues=function(e,t,n){var r=new Float32Array(3);return r[0]=e,r[1]=t,r[2]=n,r},r.copy=function(e,t){return e[0]=t[0],e[1]=t[1],e[2]=t[2],e},r.set=function(e,t,n,r){return e[0]=t,e[1]=n,e[2]=r,e},r.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},r.sub=r.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},r.mul=r.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},r.div=r.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},r.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},r.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},r.scale=function(e,t,n){return e[0]=t[0]*n,e[1]=t[1]*n,e[2]=t[2]*n,e},r.dist=r.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)},r.sqrDist=r.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},r.len=r.length=function(e){var t=e[0],n=e[1],r=e[2];return Math.sqrt(t*t+n*n+r*r)},r.sqrLen=r.squaredLength=function(e){var t=e[0],n=e[1],r=e[2];return t*t+n*n+r*r},r.negate=function(e,t){return e[0]=-t[0],e[1]=-t[1],e[2]=-t[2],e},r.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},r.dot=function(e,t){return e[0]*t[0]+e[1]*t[1]+e[2]*t[2]},r.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},r.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},r.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},r.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},r.forEach=function(){var e=new Float32Array(3);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}}(),r.str=function(e){return"vec3("+e[0]+", "+e[1]+", "+e[2]+")"},typeof e!="undefined"&&(e.vec3=r);var i={};if(!n)var n=1e-6;i.create=function(){return new Float32Array(4)},i.clone=function(e){var t=new Float32Array(4);return t[0]=e[0],t[1]=e[1],t[2]=e[2],t[3]=e[3],t},i.fromValues=function(e,t,n,r){var i=new Float32Array(4);return i[0]=e,i[1]=t,i[2]=n,i[3]=r,i},i.copy=function(e,t){return e[0]=t[0],e[1]=t[1],e[2]=t[2],e[3]=t[3],e},i.set=function(e,t,n,r,i){return e[0]=t,e[1]=n,e[2]=r,e[3]=i,e},i.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},i.sub=i.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},i.mul=i.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},i.div=i.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},i.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},i.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},i.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},i.dist=i.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)},i.sqrDist=i.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},i.len=i.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)},i.sqrLen=i.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},i.negate=function(e,t){return e[0]=-t[0],e[1]=-t[1],e[2]=-t[2],e[3]=-t[3],e},i.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},i.dot=function(e,t){return e[0]*t[0]+e[1]*t[1]+e[2]*t[2]+e[3]*t[3]},i.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},i.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},i.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},i.forEach=function(){var e=new Float32Array(4);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}}(),i.str=function(e){return"vec4("+e[0]+", "+e[1]+", "+e[2]+", "+e[3]+")"},typeof e!="undefined"&&(e.vec4=i);var s={},o=new Float32Array([1,0,0,1]);if(!n)var n=1e-6;s.create=function(){return new Float32Array(o)},s.clone=function(e){var t=new Float32Array(4);return t[0]=e[0],t[1]=e[1],t[2]=e[2],t[3]=e[3],t},s.copy=function(e,t){return e[0]=t[0],e[1]=t[1],e[2]=t[2],e[3]=t[3],e},s.identity=function(e){return e[0]=1,e[1]=0,e[2]=0,e[3]=1,e},s.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},s.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},s.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},s.determinant=function(e){return e[0]*e[3]-e[2]*e[1]},s.mul=s.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},s.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},s.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},s.str=function(e){return"mat2("+e[0]+", "+e[1]+", "+e[2]+", "+e[3]+")"},typeof e!="undefined"&&(e.mat2=s);var u={},a=new Float32Array([1,0,0,0,1,0,0,0,1]);if(!n)var n=1e-6;u.create=function(){return new Float32Array(a)},u.clone=function(e){var t=new Float32Array(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},u.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},u.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},u.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},u.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},u.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},u.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)},u.mul=u.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},u.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=u);var f={},l=new Float32Array([1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1]);if(!n)var n=1e-6;f.create=function(){return new Float32Array(l)},f.clone=function(e){var t=new Float32Array(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},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[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},f.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},f.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},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=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},f.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},f.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},f.mul=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=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},f.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},f.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},f.rotate=function(e,t,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)<n?null:(a=1/a,s*=a,o*=a,u*=a,f=Math.sin(r),l=Math.cos(r),c=1-l,h=t[0],p=t[1],d=t[2],v=t[3],m=t[4],g=t[5],y=t[6],b=t[7],w=t[8],E=t[9],S=t[10],x=t[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*_,t!==e&&(e[12]=t[12],e[13]=t[13],e[14]=t[14],e[15]=t[15]),e)},f.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},f.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},f.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},f.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},f.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},f.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},f.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},f.lookAt=function(e,t,r,i){var s,o,u,a,l,c,h,p,d,v,m=t[0],g=t[1],y=t[2],b=i[0],w=i[1],E=i[2],S=r[0],x=r[1],T=r[2];return Math.abs(m-S)<n&&Math.abs(g-x)<n&&Math.abs(y-T)<n?f.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,l=d*s-h*u,c=h*o-p*s,v=Math.sqrt(a*a+l*l+c*c),v?(v=1/v,a*=v,l*=v,c*=v):(a=0,l=0,c=0),e[0]=s,e[1]=a,e[2]=h,e[3]=0,e[4]=o,e[5]=l,e[6]=p,e[7]=0,e[8]=u,e[9]=c,e[10]=d,e[11]=0,e[12]=-(s*m+o*g+u*y),e[13]=-(a*m+l*g+c*y),e[14]=-(h*m+p*g+d*y),e[15]=1,e)},f.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=f);var c={},h=new Float32Array([0,0,0,1]);if(!n)var n=1e-6;c.create=function(){return new Float32Array(h)},c.clone=i.clone,c.fromValues=i.fromValues,c.copy=i.copy,c.set=i.set,c.identity=function(e){return e[0]=0,e[1]=0,e[2]=0,e[3]=1,e},c.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},c.add=i.add,c.mul=c.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},c.scale=i.scale,c.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},c.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},c.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},c.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},c.dot=i.dot,c.lerp=i.lerp,c.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=t[3],h=i*a+s*f+o*l+u*c,p,d,v,m;return Math.abs(h)>=1?(e!==t&&(e[0]=i,e[1]=s,e[2]=o,e[3]=u),e):(p=Math.acos(h),d=Math.sqrt(1-h*h),Math.abs(d)<.001?(e[0]=i*.5+a*.5,e[1]=s*.5+f*.5,e[2]=o*.5+l*.5,e[3]=u*.5+c*.5,e):(v=Math.sin((1-r)*p)/d,m=Math.sin(r*p)/d,e[0]=i*v+a*m,e[1]=s*v+f*m,e[2]=o*v+l*m,e[3]=u*v+c*m,e))},c.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},c.conjugate=function(e,t){return e[0]=-t[0],e[1]=-t[1],e[2]=-t[2],e[3]=t[3],e},c.len=c.length=i.length,c.sqrLen=c.squaredLength=i.squaredLength,c.normalize=i.normalize,c.str=function(e){return"quat("+e[0]+", "+e[1]+", "+e[2]+", "+e[3]+")"},typeof e!="undefined"&&(e.quat=c)}(e.exports)})(); | ||
(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=Math.PI/180;i.toRadian=function(e){return e*s};var o={};o.create=function(){var e=new n(2);return e[0]=0,e[1]=0,e},o.clone=function(e){var t=new n(2);return t[0]=e[0],t[1]=e[1],t},o.fromValues=function(e,t){var r=new n(2);return r[0]=e,r[1]=t,r},o.copy=function(e,t){return e[0]=t[0],e[1]=t[1],e},o.set=function(e,t,n){return e[0]=t,e[1]=n,e},o.add=function(e,t,n){return e[0]=t[0]+n[0],e[1]=t[1]+n[1],e},o.subtract=function(e,t,n){return e[0]=t[0]-n[0],e[1]=t[1]-n[1],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},o.mul=o.multiply,o.divide=function(e,t,n){return e[0]=t[0]/n[0],e[1]=t[1]/n[1],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},o.max=function(e,t,n){return e[0]=Math.max(t[0],n[0]),e[1]=Math.max(t[1],n[1]),e},o.scale=function(e,t,n){return e[0]=t[0]*n,e[1]=t[1]*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},o.distance=function(e,t){var n=t[0]-e[0],r=t[1]-e[1];return Math.sqrt(n*n+r*r)},o.dist=o.distance,o.squaredDistance=function(e,t){var n=t[0]-e[0],r=t[1]-e[1];return n*n+r*r},o.sqrDist=o.squaredDistance,o.length=function(e){var t=e[0],n=e[1];return Math.sqrt(t*t+n*n)},o.len=o.length,o.squaredLength=function(e){var t=e[0],n=e[1];return t*t+n*n},o.sqrLen=o.squaredLength,o.negate=function(e,t){return e[0]=-t[0],e[1]=-t[1],e},o.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},o.dot=function(e,t){return e[0]*t[0]+e[1]*t[1]},o.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},o.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},o.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},o.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},o.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},o.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},o.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},o.forEach=function(){var e=o.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}}(),o.str=function(e){return"vec2("+e[0]+", "+e[1]+")"},typeof e!="undefined"&&(e.vec2=o);var u={};u.create=function(){var e=new n(3);return e[0]=0,e[1]=0,e[2]=0,e},u.clone=function(e){var t=new n(3);return t[0]=e[0],t[1]=e[1],t[2]=e[2],t},u.fromValues=function(e,t,r){var i=new n(3);return i[0]=e,i[1]=t,i[2]=r,i},u.copy=function(e,t){return e[0]=t[0],e[1]=t[1],e[2]=t[2],e},u.set=function(e,t,n,r){return e[0]=t,e[1]=n,e[2]=r,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},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},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},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},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},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},u.scale=function(e,t,n){return e[0]=t[0]*n,e[1]=t[1]*n,e[2]=t[2]*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},u.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)},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];return n*n+r*r+i*i},u.sqrDist=u.squaredDistance,u.length=function(e){var t=e[0],n=e[1],r=e[2];return Math.sqrt(t*t+n*n+r*r)},u.len=u.length,u.squaredLength=function(e){var t=e[0],n=e[1],r=e[2];return t*t+n*n+r*r},u.sqrLen=u.squaredLength,u.negate=function(e,t){return e[0]=-t[0],e[1]=-t[1],e[2]=-t[2],e},u.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},u.dot=function(e,t){return e[0]*t[0]+e[1]*t[1]+e[2]*t[2]},u.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},u.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},u.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},u.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},u.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},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.rotateX=function(e,t,n,r){var i=[],s=[];return i[0]=t[0]-n[0],i[1]=t[1]-n[1],i[2]=t[2]-n[2],s[0]=i[0],s[1]=i[1]*Math.cos(r)-i[2]*Math.sin(r),s[2]=i[1]*Math.sin(r)+i[2]*Math.cos(r),e[0]=s[0]+n[0],e[1]=s[1]+n[1],e[2]=s[2]+n[2],e},u.rotateY=function(e,t,n,r){var i=[],s=[];return i[0]=t[0]-n[0],i[1]=t[1]-n[1],i[2]=t[2]-n[2],s[0]=i[2]*Math.sin(r)+i[0]*Math.cos(r),s[1]=i[1],s[2]=i[2]*Math.cos(r)-i[0]*Math.sin(r),e[0]=s[0]+n[0],e[1]=s[1]+n[1],e[2]=s[2]+n[2],e},u.rotateZ=function(e,t,n,r){var i=[],s=[];return i[0]=t[0]-n[0],i[1]=t[1]-n[1],i[2]=t[2]-n[2],s[0]=i[0]*Math.cos(r)-i[1]*Math.sin(r),s[1]=i[0]*Math.sin(r)+i[1]*Math.cos(r),s[2]=i[2],e[0]=s[0]+n[0],e[1]=s[1]+n[1],e[2]=s[2]+n[2],e},u.forEach=function(){var e=u.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}}(),u.str=function(e){return"vec3("+e[0]+", "+e[1]+", "+e[2]+")"},typeof e!="undefined"&&(e.vec3=u);var a={};a.create=function(){var e=new n(4);return e[0]=0,e[1]=0,e[2]=0,e[3]=0,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.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},a.copy=function(e,t){return e[0]=t[0],e[1]=t[1],e[2]=t[2],e[3]=t[3],e},a.set=function(e,t,n,r,i){return e[0]=t,e[1]=n,e[2]=r,e[3]=i,e},a.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},a.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},a.sub=a.subtract,a.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},a.mul=a.multiply,a.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},a.div=a.divide,a.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},a.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},a.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},a.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},a.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)},a.dist=a.distance,a.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},a.sqrDist=a.squaredDistance,a.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)},a.len=a.length,a.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},a.sqrLen=a.squaredLength,a.negate=function(e,t){return e[0]=-t[0],e[1]=-t[1],e[2]=-t[2],e[3]=-t[3],e},a.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},a.dot=function(e,t){return e[0]*t[0]+e[1]*t[1]+e[2]*t[2]+e[3]*t[3]},a.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},a.random=function(e,t){return t=t||1,e[0]=r(),e[1]=r(),e[2]=r(),e[3]=r(),a.normalize(e,e),a.scale(e,e,t),e},a.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},a.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},a.forEach=function(){var e=a.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}}(),a.str=function(e){return"vec4("+e[0]+", "+e[1]+", "+e[2]+", "+e[3]+")"},typeof e!="undefined"&&(e.vec4=a);var f={};f.create=function(){var e=new n(4);return e[0]=1,e[1]=0,e[2]=0,e[3]=1,e},f.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},f.copy=function(e,t){return e[0]=t[0],e[1]=t[1],e[2]=t[2],e[3]=t[3],e},f.identity=function(e){return e[0]=1,e[1]=0,e[2]=0,e[3]=1,e},f.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},f.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},f.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},f.determinant=function(e){return e[0]*e[3]-e[2]*e[1]},f.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+s*a,e[1]=i*u+o*a,e[2]=r*f+s*l,e[3]=i*f+o*l,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=Math.sin(n),a=Math.cos(n);return e[0]=r*a+s*u,e[1]=i*a+o*u,e[2]=r*-u+s*a,e[3]=i*-u+o*a,e},f.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*u,e[2]=s*a,e[3]=o*a,e},f.str=function(e){return"mat2("+e[0]+", "+e[1]+", "+e[2]+", "+e[3]+")"},f.frob=function(e){return Math.sqrt(Math.pow(e[0],2)+Math.pow(e[1],2)+Math.pow(e[2],2)+Math.pow(e[3],2))},f.LDU=function(e,t,n,r){return e[2]=r[2]/r[0],n[0]=r[0],n[1]=r[1],n[3]=r[3]-e[2]*n[1],[e,t,n]},typeof e!="undefined"&&(e.mat2=f);var l={};l.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},l.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},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},l.identity=function(e){return e[0]=1,e[1]=0,e[2]=0,e[3]=1,e[4]=0,e[5]=0,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=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},l.determinant=function(e){return e[0]*e[3]-e[1]*e[2]},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=n[0],l=n[1],c=n[2],h=n[3],p=n[4],d=n[5];return e[0]=r*f+s*l,e[1]=i*f+o*l,e[2]=r*c+s*h,e[3]=i*c+o*h,e[4]=r*p+s*d+u,e[5]=i*p+o*d+a,e},l.mul=l.multiply,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=Math.sin(n),l=Math.cos(n);return e[0]=r*l+s*f,e[1]=i*l+o*f,e[2]=r*-f+s*l,e[3]=i*-f+o*l,e[4]=u,e[5]=a,e},l.scale=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];return e[0]=r*f,e[1]=i*f,e[2]=s*l,e[3]=o*l,e[4]=u,e[5]=a,e},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=n[0],l=n[1];return e[0]=r,e[1]=i,e[2]=s,e[3]=o,e[4]=r*f+s*l+u,e[5]=i*f+o*l+a,e},l.str=function(e){return"mat2d("+e[0]+", "+e[1]+", "+e[2]+", "+e[3]+", "+e[4]+", "+e[5]+")"},l.frob=function(e){return Math.sqrt(Math.pow(e[0],2)+Math.pow(e[1],2)+Math.pow(e[2],2)+Math.pow(e[3],2)+Math.pow(e[4],2)+Math.pow(e[5],2)+1)},typeof e!="undefined"&&(e.mat2d=l);var c={};c.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},c.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},c.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},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},c.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},c.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},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=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},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];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},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];return t*(f*s-o*a)+n*(-f*i+o*u)+r*(a*i-s*u)},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=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},c.mul=c.multiply,c.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},c.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},c.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},c.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},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=r*o,c=r*u,h=i*o,p=i*u,d=i*a,v=s*o,m=s*u,g=s*a;return e[0]=1-c-d,e[3]=l-g,e[6]=h+m,e[1]=l+g,e[4]=1-f-d,e[7]=p-v,e[2]=h-m,e[5]=p+v,e[8]=1-f-c,e},c.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},c.str=function(e){return"mat3("+e[0]+", "+e[1]+", "+e[2]+", "+e[3]+", "+e[4]+", "+e[5]+", "+e[6]+", "+e[7]+", "+e[8]+")"},c.frob=function(e){return Math.sqrt(Math.pow(e[0],2)+Math.pow(e[1],2)+Math.pow(e[2],2)+Math.pow(e[3],2)+Math.pow(e[4],2)+Math.pow(e[5],2)+Math.pow(e[6],2)+Math.pow(e[7],2)+Math.pow(e[8],2))},typeof e!="undefined"&&(e.mat3=c);var h={};h.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},h.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},h.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},h.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},h.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},h.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},h.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},h.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},h.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},h.mul=h.multiply,h.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},h.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},h.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)},h.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},h.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},h.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},h.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},h.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=r*o,c=r*u,h=i*o,p=i*u,d=i*a,v=s*o,m=s*u,g=s*a;return e[0]=1-c-d,e[1]=l+g,e[2]=h-m,e[3]=0,e[4]=l-g,e[5]=1-f-d,e[6]=p+v,e[7]=0,e[8]=h+m,e[9]=p-v,e[10]=1-f-c,e[11]=0,e[12]=0,e[13]=0,e[14]=0,e[15]=1,e},h.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},h.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},h.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},h.lookAt=function(e,n,r,i){var s,o,u,a,f,l,c,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?h.identity(e):(c=m-S,p=g-x,d=y-T,v=1/Math.sqrt(c*c+p*p+d*d),c*=v,p*=v,d*=v,s=w*d-E*p,o=E*c-b*d,u=b*p-w*c,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-c*u,l=c*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]=c,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]=-(c*m+p*g+d*y),e[15]=1,e)},h.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]+")"},h.frob=function(e){return Math.sqrt(Math.pow(e[0],2)+Math.pow(e[1],2)+Math.pow(e[2],2)+Math.pow(e[3],2)+Math.pow(e[4],2)+Math.pow(e[5],2)+Math.pow(e[6],2)+Math.pow(e[6],2)+Math.pow(e[7],2)+Math.pow(e[8],2)+Math.pow(e[9],2)+Math.pow(e[10],2)+Math.pow(e[11],2)+Math.pow(e[12],2)+Math.pow(e[13],2)+Math.pow(e[14],2)+Math.pow(e[15],2))},typeof e!="undefined"&&(e.mat4=h);var p={};p.create=function(){var e=new n(4);return e[0]=0,e[1]=0,e[2]=0,e[3]=1,e},p.rotationTo=function(){var e=u.create(),t=u.fromValues(1,0,0),n=u.fromValues(0,1,0);return function(r,i,s){var o=u.dot(i,s);return o<-0.999999?(u.cross(e,t,i),u.length(e)<1e-6&&u.cross(e,n,i),u.normalize(e,e),p.setAxisAngle(r,e,Math.PI),r):o>.999999?(r[0]=0,r[1]=0,r[2]=0,r[3]=1,r):(u.cross(e,i,s),r[0]=e[0],r[1]=e[1],r[2]=e[2],r[3]=1+o,p.normalize(r,r))}}(),p.setAxes=function(){var e=c.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],p.normalize(t,p.fromMat3(t,e))}}(),p.clone=a.clone,p.fromValues=a.fromValues,p.copy=a.copy,p.set=a.set,p.identity=function(e){return e[0]=0,e[1]=0,e[2]=0,e[3]=1,e},p.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},p.add=a.add,p.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},p.mul=p.multiply,p.scale=a.scale,p.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},p.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},p.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},p.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},p.dot=a.dot,p.lerp=a.lerp,p.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},p.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},p.conjugate=function(e,t){return e[0]=-t[0],e[1]=-t[1],e[2]=-t[2],e[3]=t[3],e},p.length=a.length,p.len=p.length,p.squaredLength=a.squaredLength,p.sqrLen=p.squaredLength,p.normalize=a.normalize,p.fromMat3=function(e,t){var n=t[0]+t[4]+t[8],r;if(n>0)r=Math.sqrt(n+1),e[3]=.5*r,r=.5/r,e[0]=(t[7]-t[5])*r,e[1]=(t[2]-t[6])*r,e[2]=(t[3]-t[1])*r;else{var i=0;t[4]>t[0]&&(i=1),t[8]>t[i*3+i]&&(i=2);var s=(i+1)%3,o=(i+2)%3;r=Math.sqrt(t[i*3+i]-t[s*3+s]-t[o*3+o]+1),e[i]=.5*r,r=.5/r,e[3]=(t[o*3+s]-t[s*3+o])*r,e[s]=(t[s*3+i]+t[i*3+s])*r,e[o]=(t[o*3+i]+t[i*3+o])*r}return e},p.str=function(e){return"quat("+e[0]+", "+e[1]+", "+e[2]+", "+e[3]+")"},typeof e!="undefined"&&(e.quat=p)}(t.exports)})(this); |
@@ -1,2 +0,2 @@ | ||
Copyright (c) 2012 Brandon Jones, Colin MacKenzie IV | ||
Copyright (c) 2013 Brandon Jones, Colin MacKenzie IV | ||
@@ -3,0 +3,0 @@ This software is provided 'as-is', without any express or implied |
{ | ||
"name": "gl-matrix", | ||
"description": "Javascript Matrix and Vector library for High Performance WebGL apps", | ||
"version": "2.0.0", | ||
"version": "2.2.1", | ||
"main": "dist/gl-matrix.js", | ||
"homepage": "http://glmatrix.net", | ||
"bugs": { | ||
"url": "https://github.com/toji/gl-matrix/issues" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "http://glmatrix.net" | ||
"url": "https://github.com/toji/gl-matrix.git" | ||
}, | ||
"author": { | ||
"name": "Brandon Jones", | ||
"email": "tojiro@gmail.com" | ||
"contributors": [ | ||
{ | ||
"name": "Brandon Jones", | ||
"email": "tojiro@gmail.com" | ||
}, | ||
{ | ||
"name": "Colin MacKenzie IV", | ||
"email": "sinisterchipmunk@gmail.com" | ||
} | ||
], | ||
"devDependencies" : { | ||
"covershot": "0.1.0", | ||
"node-jsmeter": "0.1.2", | ||
"jasmine-node": "1.2.2" | ||
}, | ||
"license": "BSD" | ||
} |
glMatrix | ||
======================= | ||
Javascript has evolved into a lanugage capable of handling realtime 3D graphics, | ||
Javascript has evolved into a language capable of handling realtime 3D graphics, | ||
via WebGL, and computationally intensive tasks such as physics simulations. | ||
@@ -15,50 +15,9 @@ These types of applications demand high performance vector and matrix math, | ||
Documentation | ||
Learn More | ||
---------------------- | ||
Documentation for all glMatrix functions can be found [here](http://glmatrix.net/docs/2.0.0/) | ||
For documentation, news, tutorials, and more visit the [glMatrix Homepage](http://glmatrix.net/) | ||
What's new in 2.0? | ||
------------------------- | ||
glMatrix 2.0 is the result of a lot of excellent feedback from the community, | ||
and features: | ||
- Revamped and consistent API (not backward compatible with 1.x, sorry!) | ||
- New functions for each type, based on request. | ||
- New array operations: vec(2/3/4).forEach | ||
- Even more optimizations! | ||
- A cleaner code base, broken up by type. | ||
- A more complete unit testing suite. | ||
Looking for an older version? | ||
----------------------------- | ||
You can download previous versions of glMatrix [here](https://github.com/toji/gl-matrix/tags) | ||
A note about Matrix formatting | ||
------------------------------ | ||
glMatrix is modeled after the needs of WebGL, which in turn uses matrix | ||
conventions set by [OpenGL](http://www.opengl.org/archives/resources/faq/technical/transformations.htm). | ||
Specifically, a 4x4 matrix is an array of 16 contiguous floats with the 13th, | ||
14th, and 15th elements representing the X, Y, and Z, translation components. | ||
This may lead to some confusion when referencing OpenGL documentation, however, | ||
which represents out all matricies in column-major format. This means that while | ||
in code a matrix may be typed out as: | ||
[1, 0, 0, 0, | ||
0, 1, 0, 0, | ||
0, 0, 1, 0, | ||
x, y, z, 0] | ||
The same matrix in the [OpenGL documentation](http://www.opengl.org/sdk/docs/man2/xhtml/glTranslate.xml) | ||
is written as: | ||
1 0 0 x | ||
0 1 0 y | ||
0 0 1 z | ||
0 0 0 0 | ||
Please rest assured, however, that they are the same thing! This is not unique | ||
to glMatrix, either, as OpenGL developers have long been confused by the | ||
apparent lack of consistency between the memory layout and the documentation. | ||
Sorry about that, but there's not much I can do about it. | ||
Contributing | ||
---------------------- | ||
Contributions are welcome! Please make pull requests agains the `dev` branch, | ||
and please provide unit tests for new functionality. (See TESTING.md for details) |
@@ -1,2 +0,2 @@ | ||
/* Copyright (c) 2012, Brandon Jones, Colin MacKenzie IV. All rights reserved. | ||
/* Copyright (c) 2013, Brandon Jones, Colin MacKenzie IV. All rights reserved. | ||
@@ -125,3 +125,3 @@ Redistribution and use in source and binary forms, with or without modification, | ||
it("should place values into out", function() { expect(out).toBeEqualish([19, 22, 43, 50]); }); | ||
it("should place values into out", function() { expect(out).toBeEqualish([23, 34, 31, 46]); }); | ||
it("should return out", function() { expect(result).toBe(out); }); | ||
@@ -135,3 +135,3 @@ it("should not modify matA", function() { expect(matA).toBeEqualish([1, 2, 3, 4]); }); | ||
it("should place values into matA", function() { expect(matA).toBeEqualish([19, 22, 43, 50]); }); | ||
it("should place values into matA", function() { expect(matA).toBeEqualish([23, 34, 31, 46]); }); | ||
it("should return matA", function() { expect(result).toBe(matA); }); | ||
@@ -144,3 +144,3 @@ it("should not modify matB", function() { expect(matB).toBeEqualish([5, 6, 7, 8]); }); | ||
it("should place values into matB", function() { expect(matB).toBeEqualish([19, 22, 43, 50]); }); | ||
it("should place values into matB", function() { expect(matB).toBeEqualish([23, 34, 31, 46]); }); | ||
it("should return matB", function() { expect(result).toBe(matB); }); | ||
@@ -155,3 +155,3 @@ it("should not modify matA", function() { expect(matA).toBeEqualish([1, 2, 3, 4]); }); | ||
it("should place values into out", function() { expect(out).toBeEqualish([2, -1, 4, -3]); }); | ||
it("should place values into out", function() { expect(out).toBeEqualish([3, 4, -1, -2]); }); | ||
it("should return out", function() { expect(result).toBe(out); }); | ||
@@ -164,3 +164,3 @@ it("should not modify matA", function() { expect(matA).toBeEqualish([1, 2, 3, 4]); }); | ||
it("should place values into matA", function() { expect(matA).toBeEqualish([2, -1, 4, -3]); }); | ||
it("should place values into matA", function() { expect(matA).toBeEqualish([3, 4, -1, -2]); }); | ||
it("should return matA", function() { expect(result).toBe(matA); }); | ||
@@ -177,3 +177,3 @@ }); | ||
it("should place values into out", function() { expect(out).toBeEqualish([2, 6, 6, 12]); }); | ||
it("should place values into out", function() { expect(out).toBeEqualish([2, 4, 9, 12]); }); | ||
it("should return out", function() { expect(result).toBe(out); }); | ||
@@ -186,3 +186,3 @@ it("should not modify matA", function() { expect(matA).toBeEqualish([1, 2, 3, 4]); }); | ||
it("should place values into matA", function() { expect(matA).toBeEqualish([2, 6, 6, 12]); }); | ||
it("should place values into matA", function() { expect(matA).toBeEqualish([2, 4, 9, 12]); }); | ||
it("should return matA", function() { expect(result).toBe(matA); }); | ||
@@ -197,2 +197,22 @@ }); | ||
}); | ||
}); | ||
describe("frob", function() { | ||
beforeEach(function() { result = mat2.frob(matA); }); | ||
it("should return the Frobenius Norm of the matrix", function() { expect(result).toEqual( Math.sqrt(Math.pow(1, 2) + Math.pow(2, 2) + Math.pow(3, 2) + Math.pow(4, 2))); }); | ||
}); | ||
describe("LDU", function() { | ||
beforeEach(function() {L = mat2.create(); D = mat2.create(); U = mat2.create(); result = mat2.LDU(L, D, U, [4,3,6,3]); | ||
L_result = mat2.create(); L_result[2] = 1.5; | ||
D_result = mat2.create(); | ||
U_result = mat2.create(); | ||
U_result[0] = 4; U_result[1] = 3; U_result[3] = -1.5; | ||
}); | ||
it("should return a lower triangular, a diagonal and an upper triangular matrix", function() { | ||
expect(result[0]).toBeEqualish(L_result); | ||
expect(result[1]).toBeEqualish(D_result); | ||
expect(result[2]).toBeEqualish(U_result); | ||
}); | ||
}); | ||
}); |
@@ -1,2 +0,2 @@ | ||
/* Copyright (c) 2012, Brandon Jones, Colin MacKenzie IV. All rights reserved. | ||
/* Copyright (c) 2013, Brandon Jones, Colin MacKenzie IV. All rights reserved. | ||
@@ -44,2 +44,88 @@ Redistribution and use in source and binary forms, with or without modification, | ||
describe("normalFromMat4", function() { | ||
beforeEach(function() { | ||
matA = [1, 0, 0, 0, | ||
0, 1, 0, 0, | ||
0, 0, 1, 0, | ||
0, 0, 0, 1]; | ||
result = mat3.normalFromMat4(out, matA); | ||
}); | ||
it("should return out", function() { expect(result).toBe(out); }); | ||
describe("with translation and rotation", function() { | ||
beforeEach(function() { | ||
mat4.translate(matA, matA, [2, 4, 6]); | ||
mat4.rotateX(matA, matA, Math.PI / 2); | ||
result = mat3.normalFromMat4(out, matA); | ||
}); | ||
it("should give rotated matrix", function() { | ||
expect(result).toBeEqualish([1, 0, 0, | ||
0, 0, 1, | ||
0,-1, 0]); | ||
}); | ||
describe("and scale", function() { | ||
beforeEach(function() { | ||
mat4.scale(matA, matA, [2, 3, 4]); | ||
result = mat3.normalFromMat4(out, matA); | ||
}); | ||
it("should give rotated matrix", function() { | ||
expect(result).toBeEqualish([0.5, 0, 0, | ||
0, 0, 0.333333, | ||
0, -0.25, 0]); | ||
}); | ||
}); | ||
}); | ||
}); | ||
describe("fromQuat", function() { | ||
var q; | ||
beforeEach(function() { | ||
q = [ 0, -0.7071067811865475, 0, 0.7071067811865475 ]; | ||
result = mat3.fromQuat(out, q); | ||
}); | ||
it("should return out", function() { expect(result).toBe(out); }); | ||
it("should rotate a vector the same as the original quat", function() { | ||
expect(vec3.transformMat3([], [0,0,-1], out)).toBeEqualish(vec3.transformQuat([], [0,0,-1], q)); | ||
}); | ||
it("should rotate a vector by PI/2 radians", function() { | ||
expect(vec3.transformMat3([], [0,0,-1], out)).toBeEqualish([1,0,0]); | ||
}); | ||
}); | ||
describe("fromMat4", function() { | ||
beforeEach(function() { | ||
result = mat3.fromMat4(out, [ 1, 2, 3, 4, | ||
5, 6, 7, 8, | ||
9,10,11,12, | ||
13,14,15,16]); }); | ||
it("should return out", function() { expect(result).toBe(out); }); | ||
it("should calculate proper mat3", function() { | ||
expect(out).toBeEqualish([ 1, 2, 3, | ||
5, 6, 7, | ||
9,10,11]); | ||
}); | ||
}); | ||
describe("scale", function() { | ||
beforeEach(function() { result = mat3.scale(out, matA, [2,2]); }); | ||
it("should return out", function() { expect(result).toBe(out); }); | ||
it('should place proper values in out', function() { | ||
expect(out).toBeEqualish([ 2, 0, 0, | ||
0, 2, 0, | ||
1, 2, 1 ]); | ||
}); | ||
}); | ||
describe("create", function() { | ||
@@ -254,2 +340,8 @@ beforeEach(function() { result = mat3.create(); }); | ||
}); | ||
}); | ||
describe("frob", function() { | ||
beforeEach(function() { result = mat3.frob(matA); }); | ||
it("should return the Frobenius Norm of the matrix", function() { expect(result).toEqual( Math.sqrt(Math.pow(1, 2) + Math.pow(0, 2) + Math.pow(0, 2) + Math.pow(0, 2) + Math.pow(1, 2) + Math.pow(0, 2) + Math.pow(1, 2) + Math.pow(2, 2) + Math.pow(1, 2))); }); | ||
}); | ||
}); |
@@ -1,2 +0,2 @@ | ||
/* Copyright (c) 2012, Brandon Jones, Colin MacKenzie IV. All rights reserved. | ||
/* Copyright (c) 2013, Brandon Jones, Colin MacKenzie IV. All rights reserved. | ||
@@ -531,2 +531,12 @@ Redistribution and use in source and binary forms, with or without modification, | ||
it("should return out", function() { expect(result).toBe(out); }); | ||
describe("with nonzero near, 45deg fovy, and realistic aspect ratio", function() { | ||
beforeEach(function() { result = mat4.perspective(out, 45 * Math.PI / 180.0, 640/480, 0.1, 200); }); | ||
it("should calculate correct matrix", function() { expect(result).toBeEqualish([ | ||
1.81066, 0, 0, 0, | ||
0, 2.414213, 0, 0, | ||
0, 0, -1.001, -1, | ||
0, 0, -0.2001, 0 | ||
]); }); | ||
}); | ||
}); | ||
@@ -547,7 +557,60 @@ | ||
describe("lookAt", function() { | ||
var eye = [0, 0, 1]; | ||
var eye = [0, 0, 1]; | ||
var center = [0, 0, -1]; | ||
var up = [0, 1, 0]; | ||
var up = [0, 1, 0]; | ||
var view, up, right; | ||
beforeEach(function() { result = mat4.lookAt(out, eye, center, up); }); | ||
describe("looking down", function() { | ||
beforeEach(function() { | ||
view = [0, -1, 0]; | ||
up = [0, 0, -1]; | ||
right= [1, 0, 0]; | ||
result = mat4.lookAt(out, [0, 0, 0], view, up); | ||
}); | ||
it("should transform view into local -Z", function() { | ||
result = vec3.transformMat4([], view, out); | ||
expect(result).toBeEqualish([0, 0, -1]); | ||
}); | ||
it("should transform up into local +Y", function() { | ||
result = vec3.transformMat4([], up, out); | ||
expect(result).toBeEqualish([0, 1, 0]); | ||
}); | ||
it("should transform right into local +X", function() { | ||
result = vec3.transformMat4([], right, out); | ||
expect(result).toBeEqualish([1, 0, 0]); | ||
}); | ||
it("should return out", function() { expect(result).toBe(out); }); | ||
}); | ||
describe("#74", function() { | ||
beforeEach(function() { | ||
mat4.lookAt(out, [0,2,0], [0,0.6,0], [0,0,-1]); | ||
}); | ||
it("should transform a point 'above' into local +Y", function() { | ||
result = vec3.transformMat4([], [0, 2, -1], out); | ||
expect(result).toBeEqualish([0, 1, 0]); | ||
}); | ||
it("should transform a point 'right of' into local +X", function() { | ||
result = vec3.transformMat4([], [1, 2, 0], out); | ||
expect(result).toBeEqualish([1, 0, 0]); | ||
}); | ||
it("should transform a point 'in front of' into local -Z", function() { | ||
result = vec3.transformMat4([], [0, 1, 0], out); | ||
expect(result).toBeEqualish([0, 0, -1]); | ||
}); | ||
}); | ||
beforeEach(function() { | ||
eye = [0, 0, 1]; | ||
center = [0, 0, -1]; | ||
up = [0, 1, 0]; | ||
result = mat4.lookAt(out, eye, center, up); | ||
}); | ||
it("should place values into out", function() { expect(result).toBeEqualish([ | ||
@@ -568,2 +631,9 @@ 1, 0, 0, 0, | ||
}); | ||
}); | ||
describe("frob", function() { | ||
beforeEach(function() { result = mat4.frob(matA); }); | ||
it("should return the Frobenius Norm of the matrix", function() { expect(result).toEqual( Math.sqrt(Math.pow(1, 2) + Math.pow(1, 2) + Math.pow(1, 2) + Math.pow(1, 2) + Math.pow(1, 2) + Math.pow(2, 2) + Math.pow(3, 2) )); }); | ||
}); | ||
}); |
@@ -1,2 +0,2 @@ | ||
/* Copyright (c) 2012, Brandon Jones, Colin MacKenzie IV. All rights reserved. | ||
/* Copyright (c) 2013, Brandon Jones, Colin MacKenzie IV. All rights reserved. | ||
@@ -25,5 +25,291 @@ Redistribution and use in source and binary forms, with or without modification, | ||
var out, quatA, quatB, result; | ||
var vec, id, deg90; | ||
beforeEach(function() { quatA = [1, 2, 3, 4]; quatB = [5, 6, 7, 8]; out = [0, 0, 0, 0]; }); | ||
beforeEach(function() { | ||
quatA = [1, 2, 3, 4]; | ||
quatB = [5, 6, 7, 8]; | ||
out = [0, 0, 0, 0]; | ||
vec = [1, 1, -1]; | ||
id = [0, 0, 0, 1]; | ||
deg90 = Math.PI / 2; | ||
}); | ||
describe("slerp", function() { | ||
describe("the normal case", function() { | ||
beforeEach(function() { | ||
result = quat.slerp(out, [0, 0, 0, 1], [0, 1, 0, 0], 0.5); | ||
}); | ||
it("should return out", function() { expect(result).toBe(out); }); | ||
it("should calculate proper quat", function() { | ||
expect(result).toBeEqualish([0, 0.707106, 0, 0.707106]); | ||
}); | ||
}); | ||
describe("where a == b", function() { | ||
beforeEach(function() { | ||
result = quat.slerp(out, [0, 0, 0, 1], [0, 0, 0, 1], 0.5); | ||
}); | ||
it("should return out", function() { expect(result).toBe(out); }); | ||
it("should calculate proper quat", function() { | ||
expect(result).toBeEqualish([0, 0, 0, 1]); | ||
}); | ||
}); | ||
describe("where theta == 180deg", function() { | ||
beforeEach(function() { | ||
quat.rotateX(quatA, [1,0,0,0], Math.PI); // 180 deg | ||
result = quat.slerp(out, [1,0,0,0], quatA, 1); | ||
}); | ||
it("should calculate proper quat", function() { | ||
expect(result).toBeEqualish([0,0,0,-1]); | ||
}); | ||
}); | ||
describe("where a == -b", function() { | ||
beforeEach(function() { | ||
result = quat.slerp(out, [1, 0, 0, 0], [-1, 0, 0, 0], 0.5); | ||
}); | ||
it("should return out", function() { expect(result).toBe(out); }); | ||
it("should calculate proper quat", function() { | ||
expect(result).toBeEqualish([1, 0, 0, 0]); | ||
}); | ||
}); | ||
}); | ||
describe("rotateX", function() { | ||
beforeEach(function() { | ||
result = quat.rotateX(out, id, deg90); | ||
}); | ||
it("should return out", function() { expect(result).toBe(out); }); | ||
it("should transform vec accordingly", function() { | ||
vec3.transformQuat(vec, [0,0,-1], out); | ||
expect(vec).toBeEqualish([0, 1, 0]); | ||
}); | ||
}); | ||
describe("rotateY", function() { | ||
beforeEach(function() { | ||
result = quat.rotateY(out, id, deg90); | ||
}); | ||
it("should return out", function() { expect(result).toBe(out); }); | ||
it("should transform vec accordingly", function() { | ||
vec3.transformQuat(vec, [0,0,-1], out); | ||
expect(vec).toBeEqualish([-1, 0, 0]); | ||
}); | ||
}); | ||
describe("rotateZ", function() { | ||
beforeEach(function() { | ||
result = quat.rotateZ(out, id, deg90); | ||
}); | ||
it("should return out", function() { expect(result).toBe(out); }); | ||
it("should transform vec accordingly", function() { | ||
vec3.transformQuat(vec, [0,1,0], out); | ||
expect(vec).toBeEqualish([-1, 0, 0]); | ||
}); | ||
}); | ||
describe("fromMat3", function() { | ||
var matr; | ||
describe("legacy", function() { | ||
beforeEach(function() { | ||
matr = [ 1, 0, 0, | ||
0, 0, -1, | ||
0, 1, 0 ]; | ||
result = quat.fromMat3(out, matr); | ||
}); | ||
it("should set dest to the correct value", function() { | ||
expect(result).toBeEqualish([0.707106, 0, 0, 0.707106]); | ||
}); | ||
}); | ||
describe("where trace > 0", function() { | ||
beforeEach(function() { | ||
matr = [ 1, 0, 0, | ||
0, 0, -1, | ||
0, 1, 0 ]; | ||
result = quat.fromMat3(out, matr); | ||
}); | ||
it("should return out", function() { expect(result).toBe(out); }); | ||
it("should produce the correct transformation", function() { | ||
expect(vec3.transformQuat([], [0,1,0], out)).toBeEqualish([0,0,1]); | ||
}); | ||
}); | ||
describe("from a normal matrix looking 'backward'", function() { | ||
beforeEach(function() { | ||
matr = mat3.create(); | ||
mat3.transpose(matr, mat3.invert(matr, mat3.fromMat4(matr, mat4.lookAt(mat4.create(), [0, 0, 0], [0, 0, 1], [0, 1, 0])))); | ||
result = quat.fromMat3(out, matr); | ||
}); | ||
it("should return out", function() { expect(result).toBe(out); }); | ||
it("should produce the same transformation as the given matrix", function() { | ||
expect(vec3.transformQuat([], [3,2,-1], quat.normalize(out, out))).toBeEqualish(vec3.transformMat3([], [3,2,-1], matr)); | ||
}); | ||
}); | ||
describe("from a normal matrix looking 'left' and 'upside down'", function() { | ||
beforeEach(function() { | ||
matr = mat3.create(); | ||
mat3.transpose(matr, mat3.invert(matr, mat3.fromMat4(matr, mat4.lookAt(mat4.create(), [0, 0, 0], [-1, 0, 0], [0, -1, 0])))); | ||
result = quat.fromMat3(out, matr); | ||
}); | ||
it("should return out", function() { expect(result).toBe(out); }); | ||
it("should produce the same transformation as the given matrix", function() { | ||
expect(vec3.transformQuat([], [3,2,-1], quat.normalize(out, out))).toBeEqualish(vec3.transformMat3([], [3,2,-1], matr)); | ||
}); | ||
}); | ||
describe("from a normal matrix looking 'upside down'", function() { | ||
beforeEach(function() { | ||
matr = mat3.create(); | ||
mat3.transpose(matr, mat3.invert(matr, mat3.fromMat4(matr, mat4.lookAt(mat4.create(), [0, 0, 0], [0, 0, -1], [0, -1, 0])))); | ||
result = quat.fromMat3(out, matr); | ||
}); | ||
it("should return out", function() { expect(result).toBe(out); }); | ||
it("should produce the same transformation as the given matrix", function() { | ||
expect(vec3.transformQuat([], [3,2,-1], quat.normalize(out, out))).toBeEqualish(vec3.transformMat3([], [3,2,-1], matr)); | ||
}); | ||
}); | ||
}); | ||
describe("setAxes", function() { | ||
var r; | ||
beforeEach(function() { r = vec3.create(); }); | ||
describe("looking left", function() { | ||
var view, up, right; | ||
beforeEach(function() { | ||
view = [-1, 0, 0]; | ||
up = [ 0, 1, 0]; | ||
right= [ 0, 0,-1]; | ||
result = quat.setAxes([], view, right, up); | ||
}); | ||
it("should transform local view into world left", function() { | ||
r = vec3.transformQuat([], [0,0,-1], result); | ||
expect(r).toBeEqualish([-1, 0, 0]); | ||
}); | ||
it("should transform local right into world front", function() { | ||
r = vec3.transformQuat([], [1,0,0], result); | ||
expect(r).toBeEqualish([0, 0, -1]); | ||
}); | ||
}); | ||
describe("given opengl defaults", function() { | ||
var view, up, right; | ||
beforeEach(function() { | ||
view = [0, 0, -1]; | ||
up = [0, 1, 0]; | ||
right= [1, 0, 0]; | ||
result = quat.setAxes(out, view, right, up); | ||
}); | ||
it("should return out", function() { | ||
expect(result).toBe(out); | ||
}); | ||
it("should produce identity", function() { | ||
expect(out).toBeEqualish([0, 0, 0, 1]); | ||
}); | ||
}); | ||
describe("legacy example", function() { | ||
var view, up, right; | ||
beforeEach(function() { | ||
right= [1, 0, 0]; | ||
up = [0, 0, 1]; | ||
view = [0, -1, 0]; | ||
result = quat.setAxes(out, view, right, up); | ||
}); | ||
xit("should set correct quat4 values", function() { | ||
expect(result).toBeEqualish([0.707106, 0, 0, 0.707106]); | ||
}); | ||
}); | ||
}); | ||
describe("rotationTo", function() { | ||
var r; | ||
beforeEach(function() { r = vec3.create(); }); | ||
describe("at right angle", function() { | ||
beforeEach(function() { | ||
result = quat.rotationTo(out, [0, 1, 0], [1, 0, 0]); | ||
}); | ||
it("should return out", function() { expect(result).toBe(out); }); | ||
it("should calculate proper quaternion", function() { | ||
expect(out).toBeEqualish([0, 0, -0.707106, 0.707106]); | ||
}); | ||
}); | ||
describe("when vectors are parallel", function() { | ||
beforeEach(function() { | ||
result = quat.rotationTo(out, [0, 1, 0], [0, 1, 0]); | ||
}); | ||
it("should return out", function() { expect(result).toBe(out); }); | ||
it("multiplying A should produce B", function() { | ||
expect(vec3.transformQuat(r, [0, 1, 0], out)).toBeEqualish([0, 1, 0]); | ||
}); | ||
}); | ||
describe("when vectors are opposed X", function() { | ||
beforeEach(function() { | ||
result = quat.rotationTo(out, [1, 0, 0], [-1, 0, 0]); | ||
}); | ||
it("should return out", function() { expect(result).toBe(out); }); | ||
it("multiplying A should produce B", function() { | ||
expect(vec3.transformQuat(r, [1, 0, 0], out)).toBeEqualish([-1, 0, 0]); | ||
}); | ||
}); | ||
describe("when vectors are opposed Y", function() { | ||
beforeEach(function() { | ||
result = quat.rotationTo(out, [0, 1, 0], [0, -1, 0]); | ||
}); | ||
it("should return out", function() { expect(result).toBe(out); }); | ||
it("multiplying A should produce B", function() { | ||
expect(vec3.transformQuat(r, [0, 1, 0], out)).toBeEqualish([0, -1, 0]); | ||
}); | ||
}); | ||
describe("when vectors are opposed Z", function() { | ||
beforeEach(function() { | ||
result = quat.rotationTo(out, [0, 0, 1], [0, 0, -1]); | ||
}); | ||
it("should return out", function() { expect(result).toBe(out); }); | ||
it("multiplying A should produce B", function() { | ||
expect(vec3.transformQuat(r, [0, 0, 1], out)).toBeEqualish([0, 0, -1]); | ||
}); | ||
}); | ||
}); | ||
describe("create", function() { | ||
@@ -30,0 +316,0 @@ beforeEach(function() { result = quat.create(); }); |
@@ -1,2 +0,2 @@ | ||
/* Copyright (c) 2012, Brandon Jones, Colin MacKenzie IV. All rights reserved. | ||
/* Copyright (c) 2013, Brandon Jones, Colin MacKenzie IV. All rights reserved. | ||
@@ -244,2 +244,29 @@ Redistribution and use in source and binary forms, with or without modification, | ||
describe("scaleAndAdd", function() { | ||
describe("with a separate output vector", function() { | ||
beforeEach(function() { result = vec2.scaleAndAdd(out, vecA, vecB, 0.5); }); | ||
it("should place values into out", function() { expect(out).toBeEqualish([2.5, 4]); }); | ||
it("should return out", function() { expect(result).toBe(out); }); | ||
it("should not modify vecA", function() { expect(vecA).toBeEqualish([1, 2]); }); | ||
it("should not modify vecB", function() { expect(vecB).toBeEqualish([3, 4]); }); | ||
}); | ||
describe("when vecA is the output vector", function() { | ||
beforeEach(function() { result = vec2.scaleAndAdd(vecA, vecA, vecB, 0.5); }); | ||
it("should place values into vecA", function() { expect(vecA).toBeEqualish([2.5, 4]); }); | ||
it("should return vecA", function() { expect(result).toBe(vecA); }); | ||
it("should not modify vecB", function() { expect(vecB).toBeEqualish([3, 4]); }); | ||
}); | ||
describe("when vecB is the output vector", function() { | ||
beforeEach(function() { result = vec2.scaleAndAdd(vecB, vecA, vecB, 0.5); }); | ||
it("should place values into vecB", function() { expect(vecB).toBeEqualish([2.5, 4]); }); | ||
it("should return vecB", function() { expect(result).toBe(vecB); }); | ||
it("should not modify vecA", function() { expect(vecA).toBeEqualish([1, 2]); }); | ||
}); | ||
}); | ||
describe("distance", function() { | ||
@@ -362,2 +389,18 @@ it("should have an alias called 'dist'", function() { expect(vec2.dist).toEqual(vec2.distance); }); | ||
describe("random", function() { | ||
describe("with no scale", function() { | ||
beforeEach(function() { result = vec2.random(out); }); | ||
it("should result in a unit length vector", function() { expect(vec2.length(out)).toBeCloseTo(1.0); }); | ||
it("should return out", function() { expect(result).toBe(out); }); | ||
}); | ||
describe("with a scale", function() { | ||
beforeEach(function() { result = vec2.random(out, 5.0); }); | ||
it("should result in a unit length vector", function() { expect(vec2.length(out)).toBeCloseTo(5.0); }); | ||
it("should return out", function() { expect(result).toBe(out); }); | ||
}); | ||
}); | ||
describe("transformMat2", function() { | ||
@@ -370,3 +413,3 @@ var matA; | ||
it("should place values into out", function() { expect(out).toBeEqualish([5, 11]); }); | ||
it("should place values into out", function() { expect(out).toBeEqualish([7, 10]); }); | ||
it("should return out", function() { expect(result).toBe(out); }); | ||
@@ -380,3 +423,3 @@ it("should not modify vecA", function() { expect(vecA).toBeEqualish([1, 2]); }); | ||
it("should place values into vecA", function() { expect(vecA).toBeEqualish([5, 11]); }); | ||
it("should place values into vecA", function() { expect(vecA).toBeEqualish([7, 10]); }); | ||
it("should return vecA", function() { expect(result).toBe(vecA); }); | ||
@@ -387,2 +430,24 @@ it("should not modify matA", function() { expect(matA).toBeEqualish([1, 2, 3, 4]); }); | ||
describe("transformMat2d", function() { | ||
var matA; | ||
beforeEach(function() { matA = [1, 2, 3, 4, 5, 6]; }); | ||
describe("with a separate output vector", function() { | ||
beforeEach(function() { result = vec2.transformMat2d(out, vecA, matA); }); | ||
it("should place values into out", function() { expect(out).toBeEqualish([12, 16]); }); | ||
it("should return out", function() { expect(result).toBe(out); }); | ||
it("should not modify vecA", function() { expect(vecA).toBeEqualish([1, 2]); }); | ||
it("should not modify matA", function() { expect(matA).toBeEqualish([1, 2, 3, 4, 5, 6]); }); | ||
}); | ||
describe("when vecA is the output vector", function() { | ||
beforeEach(function() { result = vec2.transformMat2d(vecA, vecA, matA); }); | ||
it("should place values into vecA", function() { expect(vecA).toBeEqualish([12, 16]); }); | ||
it("should return vecA", function() { expect(result).toBe(vecA); }); | ||
it("should not modify matA", function() { expect(matA).toBeEqualish([1, 2, 3, 4, 5, 6]); }); | ||
}); | ||
}); | ||
describe("forEach", function() { | ||
@@ -389,0 +454,0 @@ var vecArray; |
@@ -1,2 +0,2 @@ | ||
/* Copyright (c) 2012, Brandon Jones, Colin MacKenzie IV. All rights reserved. | ||
/* Copyright (c) 2013, Brandon Jones, Colin MacKenzie IV. All rights reserved. | ||
@@ -27,3 +27,124 @@ Redistribution and use in source and binary forms, with or without modification, | ||
beforeEach(function() { vecA = [1, 2, 3]; vecB = [4, 5, 6]; out = [0, 0, 0]; }); | ||
describe('rotateX', function(){ | ||
describe('rotation around world origin [0, 0, 0]', function(){ | ||
beforeEach(function(){ vecA = [0, 1, 0]; vecB = [0, 0, 0]; result = vec3.rotateX(out, vecA, vecB, Math.PI); }); | ||
it("should return the rotated vector", function(){ expect(result).toBeEqualish([0, -1, 0]); }); | ||
}); | ||
describe('rotation around an arbitrary origin', function(){ | ||
beforeEach(function(){ vecA = [2, 7, 0]; vecB = [2, 5, 0]; result = vec3.rotateX(out, vecA, vecB, Math.PI); }); | ||
it("should return the rotated vector", function(){ expect(result).toBeEqualish([2, 3, 0]); }); | ||
}); | ||
}); | ||
describe('rotateY', function(){ | ||
describe('rotation around world origin [0, 0, 0]', function(){ | ||
beforeEach(function(){ vecA = [1, 0, 0]; vecB = [0, 0, 0]; result = vec3.rotateY(out, vecA, vecB, Math.PI); }); | ||
it("should return the rotated vector", function(){ expect(result).toBeEqualish([-1, 0, 0]); }); | ||
}); | ||
describe('rotation around an arbitrary origin', function(){ | ||
beforeEach(function(){ vecA = [-2, 3, 10]; vecB = [-4, 3, 10]; result = vec3.rotateY(out, vecA, vecB, Math.PI); }); | ||
it("should return the rotated vector", function(){ expect(result).toBeEqualish([-6, 3, 10]); }); | ||
}); | ||
}); | ||
describe('rotateZ', function(){ | ||
describe('rotation around world origin [0, 0, 0]', function(){ | ||
beforeEach(function(){ vecA = [0, 1, 0]; vecB = [0, 0, 0]; result = vec3.rotateZ(out, vecA, vecB, Math.PI); }); | ||
it("should return the rotated vector", function(){ expect(result).toBeEqualish([0, -1, 0]); }); | ||
}); | ||
describe('rotation around an arbitrary origin', function(){ | ||
beforeEach(function(){ vecA = [0, 6, -5]; vecB = [0, 0, -5]; result = vec3.rotateZ(out, vecA, vecB, Math.PI); }); | ||
it("should return the rotated vector", function(){ expect(result).toBeEqualish([0, -6, -5]); }); | ||
}); | ||
}); | ||
describe('transformMat4', function() { | ||
var matr; | ||
describe("with an identity", function() { | ||
beforeEach(function() { matr = [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1 ] }); | ||
beforeEach(function() { result = vec3.transformMat4(out, vecA, matr); }); | ||
it("should produce the input", function() { | ||
expect(out).toBeEqualish([1, 2, 3]); | ||
}); | ||
it("should return out", function() { expect(result).toBe(out); }); | ||
}); | ||
describe("with a lookAt", function() { | ||
beforeEach(function() { matr = mat4.lookAt(mat4.create(), [5, 6, 7], [2, 6, 7], [0, 1, 0]); }); | ||
beforeEach(function() { result = vec3.transformMat4(out, vecA, matr); }); | ||
it("should rotate and translate the input", function() { | ||
expect(out).toBeEqualish([ 4, -4, -4 ]); | ||
}); | ||
it("should return out", function() { expect(result).toBe(out); }); | ||
}); | ||
}); | ||
describe('transformMat3', function() { | ||
var matr; | ||
describe("with an identity", function() { | ||
beforeEach(function() { matr = [1, 0, 0, 0, 1, 0, 0, 0, 1 ] }); | ||
beforeEach(function() { result = vec3.transformMat3(out, vecA, matr); }); | ||
it("should produce the input", function() { | ||
expect(out).toBeEqualish([1, 2, 3]); | ||
}); | ||
it("should return out", function() { expect(result).toBe(out); }); | ||
}); | ||
describe("with 90deg about X", function() { | ||
beforeEach(function() { | ||
result = vec3.transformMat3(out, [0,1,0], [1,0,0,0,0,1,0,-1,0]); | ||
}); | ||
it("should produce correct output", function() { | ||
expect(out).toBeEqualish([0,0,1]); | ||
}); | ||
}); | ||
describe("with 90deg about Y", function() { | ||
beforeEach(function() { | ||
result = vec3.transformMat3(out, [1,0,0], [0,0,-1,0,1,0,1,0,0]); | ||
}); | ||
it("should produce correct output", function() { | ||
expect(out).toBeEqualish([0,0,-1]); | ||
}); | ||
}); | ||
describe("with 90deg about Z", function() { | ||
beforeEach(function() { | ||
result = vec3.transformMat3(out, [1,0,0], [0,1,0,-1,0,0,0,0,1]); | ||
}); | ||
it("should produce correct output", function() { | ||
expect(out).toBeEqualish([0,1,0]); | ||
}); | ||
}); | ||
describe("with a lookAt normal matrix", function() { | ||
beforeEach(function() { | ||
matr = mat4.lookAt(mat4.create(), [5, 6, 7], [2, 6, 7], [0, 1, 0]); | ||
var n = mat3.create(); | ||
matr = mat3.transpose(n, mat3.invert(n, mat3.fromMat4(n, matr))); | ||
}); | ||
beforeEach(function() { result = vec3.transformMat3(out, [1,0,0], matr); }); | ||
it("should rotate the input", function() { | ||
expect(out).toBeEqualish([ 0,0,1 ]); | ||
}); | ||
it("should return out", function() { expect(result).toBe(out); }); | ||
}); | ||
}); | ||
describe("create", function() { | ||
@@ -245,2 +366,29 @@ beforeEach(function() { result = vec3.create(); }); | ||
describe("scaleAndAdd", function() { | ||
describe("with a separate output vector", function() { | ||
beforeEach(function() { result = vec3.scaleAndAdd(out, vecA, vecB, 0.5); }); | ||
it("should place values into out", function() { expect(out).toBeEqualish([3, 4.5, 6]); }); | ||
it("should return out", function() { expect(result).toBe(out); }); | ||
it("should not modify vecA", function() { expect(vecA).toBeEqualish([1, 2, 3]); }); | ||
it("should not modify vecB", function() { expect(vecB).toBeEqualish([4, 5, 6]); }); | ||
}); | ||
describe("when vecA is the output vector", function() { | ||
beforeEach(function() { result = vec3.scaleAndAdd(vecA, vecA, vecB, 0.5); }); | ||
it("should place values into vecA", function() { expect(vecA).toBeEqualish([3, 4.5, 6]); }); | ||
it("should return vecA", function() { expect(result).toBe(vecA); }); | ||
it("should not modify vecB", function() { expect(vecB).toBeEqualish([4, 5, 6]); }); | ||
}); | ||
describe("when vecB is the output vector", function() { | ||
beforeEach(function() { result = vec3.scaleAndAdd(vecB, vecA, vecB, 0.5); }); | ||
it("should place values into vecB", function() { expect(vecB).toBeEqualish([3, 4.5, 6]); }); | ||
it("should return vecB", function() { expect(result).toBe(vecB); }); | ||
it("should not modify vecA", function() { expect(vecA).toBeEqualish([1, 2, 3]); }); | ||
}); | ||
}); | ||
describe("distance", function() { | ||
@@ -376,2 +524,18 @@ it("should have an alias called 'dist'", function() { expect(vec3.dist).toEqual(vec3.distance); }); | ||
describe("random", function() { | ||
describe("with no scale", function() { | ||
beforeEach(function() { result = vec3.random(out); }); | ||
it("should result in a unit length vector", function() { expect(vec3.length(out)).toBeCloseTo(1.0); }); | ||
it("should return out", function() { expect(result).toBe(out); }); | ||
}); | ||
describe("with a scale", function() { | ||
beforeEach(function() { result = vec3.random(out, 5.0); }); | ||
it("should result in a unit length vector", function() { expect(vec3.length(out)).toBeCloseTo(5.0); }); | ||
it("should return out", function() { expect(result).toBe(out); }); | ||
}); | ||
}); | ||
describe("forEach", function() { | ||
@@ -378,0 +542,0 @@ var vecArray; |
@@ -1,2 +0,2 @@ | ||
/* Copyright (c) 2012, Brandon Jones, Colin MacKenzie IV. All rights reserved. | ||
/* Copyright (c) 2013, Brandon Jones, Colin MacKenzie IV. All rights reserved. | ||
@@ -244,2 +244,29 @@ Redistribution and use in source and binary forms, with or without modification, | ||
describe("scaleAndAdd", function() { | ||
describe("with a separate output vector", function() { | ||
beforeEach(function() { result = vec4.scaleAndAdd(out, vecA, vecB, 0.5); }); | ||
it("should place values into out", function() { expect(out).toBeEqualish([3.5, 5, 6.5, 8]); }); | ||
it("should return out", function() { expect(result).toBe(out); }); | ||
it("should not modify vecA", function() { expect(vecA).toBeEqualish([1, 2, 3, 4]); }); | ||
it("should not modify vecB", function() { expect(vecB).toBeEqualish([5, 6, 7, 8]); }); | ||
}); | ||
describe("when vecA is the output vector", function() { | ||
beforeEach(function() { result = vec4.scaleAndAdd(vecA, vecA, vecB, 0.5); }); | ||
it("should place values into vecA", function() { expect(vecA).toBeEqualish([3.5, 5, 6.5, 8]); }); | ||
it("should return vecA", function() { expect(result).toBe(vecA); }); | ||
it("should not modify vecB", function() { expect(vecB).toBeEqualish([5, 6, 7, 8]); }); | ||
}); | ||
describe("when vecB is the output vector", function() { | ||
beforeEach(function() { result = vec4.scaleAndAdd(vecB, vecA, vecB, 0.5); }); | ||
it("should place values into vecB", function() { expect(vecB).toBeEqualish([3.5, 5, 6.5, 8]); }); | ||
it("should return vecB", function() { expect(result).toBe(vecB); }); | ||
it("should not modify vecA", function() { expect(vecA).toBeEqualish([1, 2, 3, 4]); }); | ||
}); | ||
}); | ||
describe("distance", function() { | ||
@@ -348,2 +375,18 @@ it("should have an alias called 'dist'", function() { expect(vec4.dist).toEqual(vec4.distance); }); | ||
describe("random", function() { | ||
describe("with no scale", function() { | ||
beforeEach(function() { result = vec4.random(out); }); | ||
it("should result in a unit length vector", function() { expect(vec4.length(out)).toBeCloseTo(1.0); }); | ||
it("should return out", function() { expect(result).toBe(out); }); | ||
}); | ||
describe("with a scale", function() { | ||
beforeEach(function() { result = vec4.random(out, 5.0); }); | ||
it("should result in a unit length vector", function() { expect(vec4.length(out)).toBeCloseTo(5.0); }); | ||
it("should return out", function() { expect(result).toBe(out); }); | ||
}); | ||
}); | ||
describe("forEach", function() { | ||
@@ -350,0 +393,0 @@ var vecArray; |
if (typeof(exports) !== 'undefined') { | ||
var glm = require("../../dist/gl-matrix"); | ||
var glm; | ||
try { | ||
glm = require("../../tmp/coverage/manifest"); | ||
} catch(e) { | ||
if (e.code === "MODULE_NOT_FOUND" || | ||
e.toString().indexOf("Cannot find module") !== -1) | ||
glm = require("../../dist/gl-matrix"); | ||
else throw e; | ||
} | ||
for (var ns in glm) { | ||
@@ -4,0 +12,0 @@ global[ns] = glm[ns]; |
@@ -0,1 +1,3 @@ | ||
//= require 'gl-matrix/common.js' | ||
//= require 'gl-matrix/vec2.js' | ||
@@ -6,2 +8,3 @@ //= require 'gl-matrix/vec3.js' | ||
//= require 'gl-matrix/mat2.js' | ||
//= require 'gl-matrix/mat2d.js' | ||
//= require 'gl-matrix/mat3.js' | ||
@@ -8,0 +11,0 @@ //= require 'gl-matrix/mat4.js' |
@@ -1,2 +0,2 @@ | ||
/* Copyright (c) 2012, Brandon Jones, Colin MacKenzie IV. All rights reserved. | ||
/* Copyright (c) 2013, Brandon Jones, Colin MacKenzie IV. All rights reserved. | ||
@@ -29,11 +29,2 @@ Redistribution and use in source and binary forms, with or without modification, | ||
var mat2Identity = new Float32Array([ | ||
1, 0, | ||
0, 1 | ||
]); | ||
if(!GLMAT_EPSILON) { | ||
var GLMAT_EPSILON = 0.000001; | ||
} | ||
/** | ||
@@ -45,3 +36,8 @@ * Creates a new identity mat2 | ||
mat2.create = function() { | ||
return new Float32Array(mat2Identity); | ||
var out = new GLMAT_ARRAY_TYPE(4); | ||
out[0] = 1; | ||
out[1] = 0; | ||
out[2] = 0; | ||
out[3] = 1; | ||
return out; | ||
}; | ||
@@ -56,3 +52,3 @@ | ||
mat2.clone = function(a) { | ||
var out = new Float32Array(4); | ||
var out = new GLMAT_ARRAY_TYPE(4); | ||
out[0] = a[0]; | ||
@@ -144,3 +140,3 @@ out[1] = a[1]; | ||
/** | ||
* Caclulates the adjugate of a mat2 | ||
* Calculates the adjugate of a mat2 | ||
* | ||
@@ -183,6 +179,6 @@ * @param {mat2} out the receiving matrix | ||
var b0 = b[0], b1 = b[1], b2 = b[2], b3 = b[3]; | ||
out[0] = a0 * b0 + a1 * b2; | ||
out[1] = a0 * b1 + a1 * b3; | ||
out[2] = a2 * b0 + a3 * b2; | ||
out[3] = a2 * b1 + a3 * b3; | ||
out[0] = a0 * b0 + a2 * b1; | ||
out[1] = a1 * b0 + a3 * b1; | ||
out[2] = a0 * b2 + a2 * b3; | ||
out[3] = a1 * b2 + a3 * b3; | ||
return out; | ||
@@ -202,3 +198,3 @@ }; | ||
* @param {mat2} a the matrix to rotate | ||
* @param {mat2} rad the angle to rotate the matrix by | ||
* @param {Number} rad the angle to rotate the matrix by | ||
* @returns {mat2} out | ||
@@ -210,6 +206,6 @@ */ | ||
c = Math.cos(rad); | ||
out[0] = a0 * c + a1 * s; | ||
out[1] = a0 * -s + a1 * c; | ||
out[2] = a2 * c + a3 * s; | ||
out[3] = a2 * -s + a3 * c; | ||
out[0] = a0 * c + a2 * s; | ||
out[1] = a1 * c + a3 * s; | ||
out[2] = a0 * -s + a2 * c; | ||
out[3] = a1 * -s + a3 * c; | ||
return out; | ||
@@ -223,3 +219,3 @@ }; | ||
* @param {mat2} a the matrix to rotate | ||
* @param {mat2} v the vec2 to scale the matrix by | ||
* @param {vec2} v the vec2 to scale the matrix by | ||
* @returns {mat2} out | ||
@@ -231,4 +227,4 @@ **/ | ||
out[0] = a0 * v0; | ||
out[1] = a1 * v1; | ||
out[2] = a2 * v0; | ||
out[1] = a1 * v0; | ||
out[2] = a2 * v1; | ||
out[3] = a3 * v1; | ||
@@ -248,4 +244,30 @@ return out; | ||
/** | ||
* Returns Frobenius norm of a mat2 | ||
* | ||
* @param {mat2} a the matrix to calculate Frobenius norm of | ||
* @returns {Number} Frobenius norm | ||
*/ | ||
mat2.frob = function (a) { | ||
return(Math.sqrt(Math.pow(a[0], 2) + Math.pow(a[1], 2) + Math.pow(a[2], 2) + Math.pow(a[3], 2))) | ||
}; | ||
/** | ||
* Returns L, D and U matrices (Lower triangular, Diagonal and Upper triangular) by factorizing the input matrix | ||
* @param {mat2} L the lower triangular matrix | ||
* @param {mat2} D the diagonal matrix | ||
* @param {mat2} U the upper triangular matrix | ||
* @param {mat2} a the input matrix to factorize | ||
*/ | ||
mat2.LDU = function (L, D, U, a) { | ||
L[2] = a[2]/a[0]; | ||
U[0] = a[0]; | ||
U[1] = a[1]; | ||
U[3] = a[3] - L[2] * U[1]; | ||
return [L, D, U]; | ||
}; | ||
if(typeof(exports) !== 'undefined') { | ||
exports.mat2 = mat2; | ||
} |
@@ -1,2 +0,2 @@ | ||
/* Copyright (c) 2012, Brandon Jones, Colin MacKenzie IV. All rights reserved. | ||
/* Copyright (c) 2013, Brandon Jones, Colin MacKenzie IV. All rights reserved. | ||
@@ -29,12 +29,2 @@ Redistribution and use in source and binary forms, with or without modification, | ||
var mat3Identity = new Float32Array([ | ||
1, 0, 0, | ||
0, 1, 0, | ||
0, 0, 1 | ||
]); | ||
if(!GLMAT_EPSILON) { | ||
var GLMAT_EPSILON = 0.000001; | ||
} | ||
/** | ||
@@ -46,6 +36,36 @@ * Creates a new identity mat3 | ||
mat3.create = function() { | ||
return new Float32Array(mat3Identity); | ||
var out = new GLMAT_ARRAY_TYPE(9); | ||
out[0] = 1; | ||
out[1] = 0; | ||
out[2] = 0; | ||
out[3] = 0; | ||
out[4] = 1; | ||
out[5] = 0; | ||
out[6] = 0; | ||
out[7] = 0; | ||
out[8] = 1; | ||
return out; | ||
}; | ||
/** | ||
* Copies the upper-left 3x3 values into the given mat3. | ||
* | ||
* @param {mat3} out the receiving 3x3 matrix | ||
* @param {mat4} a the source 4x4 matrix | ||
* @returns {mat3} out | ||
*/ | ||
mat3.fromMat4 = function(out, a) { | ||
out[0] = a[0]; | ||
out[1] = a[1]; | ||
out[2] = a[2]; | ||
out[3] = a[4]; | ||
out[4] = a[5]; | ||
out[5] = a[6]; | ||
out[6] = a[8]; | ||
out[7] = a[9]; | ||
out[8] = a[10]; | ||
return out; | ||
}; | ||
/** | ||
* Creates a new mat3 initialized with values from an existing matrix | ||
@@ -57,3 +77,3 @@ * | ||
mat3.clone = function(a) { | ||
var out = new Float32Array(9); | ||
var out = new GLMAT_ARRAY_TYPE(9); | ||
out[0] = a[0]; | ||
@@ -179,3 +199,3 @@ out[1] = a[1]; | ||
/** | ||
* Caclulates the adjugate of a mat3 | ||
* Calculates the adjugate of a mat3 | ||
* | ||
@@ -255,2 +275,196 @@ * @param {mat3} out the receiving matrix | ||
/** | ||
* Translate a mat3 by the given vector | ||
* | ||
* @param {mat3} out the receiving matrix | ||
* @param {mat3} a the matrix to translate | ||
* @param {vec2} v vector to translate by | ||
* @returns {mat3} out | ||
*/ | ||
mat3.translate = function(out, a, v) { | ||
var a00 = a[0], a01 = a[1], a02 = a[2], | ||
a10 = a[3], a11 = a[4], a12 = a[5], | ||
a20 = a[6], a21 = a[7], a22 = a[8], | ||
x = v[0], y = v[1]; | ||
out[0] = a00; | ||
out[1] = a01; | ||
out[2] = a02; | ||
out[3] = a10; | ||
out[4] = a11; | ||
out[5] = a12; | ||
out[6] = x * a00 + y * a10 + a20; | ||
out[7] = x * a01 + y * a11 + a21; | ||
out[8] = x * a02 + y * a12 + a22; | ||
return out; | ||
}; | ||
/** | ||
* Rotates a mat3 by the given angle | ||
* | ||
* @param {mat3} out the receiving matrix | ||
* @param {mat3} a the matrix to rotate | ||
* @param {Number} rad the angle to rotate the matrix by | ||
* @returns {mat3} out | ||
*/ | ||
mat3.rotate = function (out, a, rad) { | ||
var a00 = a[0], a01 = a[1], a02 = a[2], | ||
a10 = a[3], a11 = a[4], a12 = a[5], | ||
a20 = a[6], a21 = a[7], a22 = a[8], | ||
s = Math.sin(rad), | ||
c = Math.cos(rad); | ||
out[0] = c * a00 + s * a10; | ||
out[1] = c * a01 + s * a11; | ||
out[2] = c * a02 + s * a12; | ||
out[3] = c * a10 - s * a00; | ||
out[4] = c * a11 - s * a01; | ||
out[5] = c * a12 - s * a02; | ||
out[6] = a20; | ||
out[7] = a21; | ||
out[8] = a22; | ||
return out; | ||
}; | ||
/** | ||
* Scales the mat3 by the dimensions in the given vec2 | ||
* | ||
* @param {mat3} out the receiving matrix | ||
* @param {mat3} a the matrix to rotate | ||
* @param {vec2} v the vec2 to scale the matrix by | ||
* @returns {mat3} out | ||
**/ | ||
mat3.scale = function(out, a, v) { | ||
var x = v[0], y = v[1]; | ||
out[0] = x * a[0]; | ||
out[1] = x * a[1]; | ||
out[2] = x * a[2]; | ||
out[3] = y * a[3]; | ||
out[4] = y * a[4]; | ||
out[5] = y * a[5]; | ||
out[6] = a[6]; | ||
out[7] = a[7]; | ||
out[8] = a[8]; | ||
return out; | ||
}; | ||
/** | ||
* Copies the values from a mat2d into a mat3 | ||
* | ||
* @param {mat3} out the receiving matrix | ||
* @param {mat2d} a the matrix to copy | ||
* @returns {mat3} out | ||
**/ | ||
mat3.fromMat2d = function(out, a) { | ||
out[0] = a[0]; | ||
out[1] = a[1]; | ||
out[2] = 0; | ||
out[3] = a[2]; | ||
out[4] = a[3]; | ||
out[5] = 0; | ||
out[6] = a[4]; | ||
out[7] = a[5]; | ||
out[8] = 1; | ||
return out; | ||
}; | ||
/** | ||
* Calculates a 3x3 matrix from the given quaternion | ||
* | ||
* @param {mat3} out mat3 receiving operation result | ||
* @param {quat} q Quaternion to create matrix from | ||
* | ||
* @returns {mat3} out | ||
*/ | ||
mat3.fromQuat = function (out, q) { | ||
var x = q[0], y = q[1], z = q[2], w = q[3], | ||
x2 = x + x, | ||
y2 = y + y, | ||
z2 = z + z, | ||
xx = x * x2, | ||
yx = y * x2, | ||
yy = y * y2, | ||
zx = z * x2, | ||
zy = z * y2, | ||
zz = z * z2, | ||
wx = w * x2, | ||
wy = w * y2, | ||
wz = w * z2; | ||
out[0] = 1 - yy - zz; | ||
out[3] = yx - wz; | ||
out[6] = zx + wy; | ||
out[1] = yx + wz; | ||
out[4] = 1 - xx - zz; | ||
out[7] = zy - wx; | ||
out[2] = zx - wy; | ||
out[5] = zy + wx; | ||
out[8] = 1 - xx - yy; | ||
return out; | ||
}; | ||
/** | ||
* Calculates a 3x3 normal matrix (transpose inverse) from the 4x4 matrix | ||
* | ||
* @param {mat3} out mat3 receiving operation result | ||
* @param {mat4} a Mat4 to derive the normal matrix from | ||
* | ||
* @returns {mat3} out | ||
*/ | ||
mat3.normalFromMat4 = function (out, a) { | ||
var a00 = a[0], a01 = a[1], a02 = a[2], a03 = a[3], | ||
a10 = a[4], a11 = a[5], a12 = a[6], a13 = a[7], | ||
a20 = a[8], a21 = a[9], a22 = a[10], a23 = a[11], | ||
a30 = a[12], a31 = a[13], a32 = a[14], a33 = a[15], | ||
b00 = a00 * a11 - a01 * a10, | ||
b01 = a00 * a12 - a02 * a10, | ||
b02 = a00 * a13 - a03 * a10, | ||
b03 = a01 * a12 - a02 * a11, | ||
b04 = a01 * a13 - a03 * a11, | ||
b05 = a02 * a13 - a03 * a12, | ||
b06 = a20 * a31 - a21 * a30, | ||
b07 = a20 * a32 - a22 * a30, | ||
b08 = a20 * a33 - a23 * a30, | ||
b09 = a21 * a32 - a22 * a31, | ||
b10 = a21 * a33 - a23 * a31, | ||
b11 = a22 * a33 - a23 * a32, | ||
// Calculate the determinant | ||
det = b00 * b11 - b01 * b10 + b02 * b09 + b03 * b08 - b04 * b07 + b05 * b06; | ||
if (!det) { | ||
return null; | ||
} | ||
det = 1.0 / det; | ||
out[0] = (a11 * b11 - a12 * b10 + a13 * b09) * det; | ||
out[1] = (a12 * b08 - a10 * b11 - a13 * b07) * det; | ||
out[2] = (a10 * b10 - a11 * b08 + a13 * b06) * det; | ||
out[3] = (a02 * b10 - a01 * b11 - a03 * b09) * det; | ||
out[4] = (a00 * b11 - a02 * b08 + a03 * b07) * det; | ||
out[5] = (a01 * b08 - a00 * b10 - a03 * b06) * det; | ||
out[6] = (a31 * b05 - a32 * b04 + a33 * b03) * det; | ||
out[7] = (a32 * b02 - a30 * b05 - a33 * b01) * det; | ||
out[8] = (a30 * b04 - a31 * b02 + a33 * b00) * det; | ||
return out; | ||
}; | ||
/** | ||
* Returns a string representation of a mat3 | ||
@@ -267,4 +481,15 @@ * | ||
/** | ||
* Returns Frobenius norm of a mat3 | ||
* | ||
* @param {mat3} a the matrix to calculate Frobenius norm of | ||
* @returns {Number} Frobenius norm | ||
*/ | ||
mat3.frob = function (a) { | ||
return(Math.sqrt(Math.pow(a[0], 2) + Math.pow(a[1], 2) + Math.pow(a[2], 2) + Math.pow(a[3], 2) + Math.pow(a[4], 2) + Math.pow(a[5], 2) + Math.pow(a[6], 2) + Math.pow(a[7], 2) + Math.pow(a[8], 2))) | ||
}; | ||
if(typeof(exports) !== 'undefined') { | ||
exports.mat3 = mat3; | ||
} |
@@ -1,2 +0,2 @@ | ||
/* Copyright (c) 2012, Brandon Jones, Colin MacKenzie IV. All rights reserved. | ||
/* Copyright (c) 2013, Brandon Jones, Colin MacKenzie IV. All rights reserved. | ||
@@ -29,13 +29,2 @@ Redistribution and use in source and binary forms, with or without modification, | ||
var mat4Identity = new Float32Array([ | ||
1, 0, 0, 0, | ||
0, 1, 0, 0, | ||
0, 0, 1, 0, | ||
0, 0, 0, 1 | ||
]); | ||
if(!GLMAT_EPSILON) { | ||
var GLMAT_EPSILON = 0.000001; | ||
} | ||
/** | ||
@@ -47,3 +36,20 @@ * Creates a new identity mat4 | ||
mat4.create = function() { | ||
return new Float32Array(mat4Identity); | ||
var out = new GLMAT_ARRAY_TYPE(16); | ||
out[0] = 1; | ||
out[1] = 0; | ||
out[2] = 0; | ||
out[3] = 0; | ||
out[4] = 0; | ||
out[5] = 1; | ||
out[6] = 0; | ||
out[7] = 0; | ||
out[8] = 0; | ||
out[9] = 0; | ||
out[10] = 1; | ||
out[11] = 0; | ||
out[12] = 0; | ||
out[13] = 0; | ||
out[14] = 0; | ||
out[15] = 1; | ||
return out; | ||
}; | ||
@@ -58,3 +64,3 @@ | ||
mat4.clone = function(a) { | ||
var out = new Float32Array(16); | ||
var out = new GLMAT_ARRAY_TYPE(16); | ||
out[0] = a[0]; | ||
@@ -235,3 +241,3 @@ out[1] = a[1]; | ||
/** | ||
* Caclulates the adjugate of a mat4 | ||
* Calculates the adjugate of a mat4 | ||
* | ||
@@ -654,2 +660,41 @@ * @param {mat4} out the receiving matrix | ||
mat4.fromQuat = function (out, q) { | ||
var x = q[0], y = q[1], z = q[2], w = q[3], | ||
x2 = x + x, | ||
y2 = y + y, | ||
z2 = z + z, | ||
xx = x * x2, | ||
yx = y * x2, | ||
yy = y * y2, | ||
zx = z * x2, | ||
zy = z * y2, | ||
zz = z * z2, | ||
wx = w * x2, | ||
wy = w * y2, | ||
wz = w * z2; | ||
out[0] = 1 - yy - zz; | ||
out[1] = yx + wz; | ||
out[2] = zx - wy; | ||
out[3] = 0; | ||
out[4] = yx - wz; | ||
out[5] = 1 - xx - zz; | ||
out[6] = zy + wx; | ||
out[7] = 0; | ||
out[8] = zx + wy; | ||
out[9] = zy - wx; | ||
out[10] = 1 - xx - yy; | ||
out[11] = 0; | ||
out[12] = 0; | ||
out[13] = 0; | ||
out[14] = 0; | ||
out[15] = 1; | ||
return out; | ||
}; | ||
/** | ||
@@ -857,4 +902,15 @@ * Generates a frustum matrix with the given bounds | ||
/** | ||
* Returns Frobenius norm of a mat4 | ||
* | ||
* @param {mat4} a the matrix to calculate Frobenius norm of | ||
* @returns {Number} Frobenius norm | ||
*/ | ||
mat4.frob = function (a) { | ||
return(Math.sqrt(Math.pow(a[0], 2) + Math.pow(a[1], 2) + Math.pow(a[2], 2) + Math.pow(a[3], 2) + Math.pow(a[4], 2) + Math.pow(a[5], 2) + Math.pow(a[6], 2) + Math.pow(a[6], 2) + Math.pow(a[7], 2) + Math.pow(a[8], 2) + Math.pow(a[9], 2) + Math.pow(a[10], 2) + Math.pow(a[11], 2) + Math.pow(a[12], 2) + Math.pow(a[13], 2) + Math.pow(a[14], 2) + Math.pow(a[15], 2) )) | ||
}; | ||
if(typeof(exports) !== 'undefined') { | ||
exports.mat4 = mat4; | ||
} |
@@ -1,2 +0,2 @@ | ||
/* Copyright (c) 2012, Brandon Jones, Colin MacKenzie IV. All rights reserved. | ||
/* Copyright (c) 2013, Brandon Jones, Colin MacKenzie IV. All rights reserved. | ||
@@ -29,8 +29,2 @@ Redistribution and use in source and binary forms, with or without modification, | ||
var quatIdentity = new Float32Array([0, 0, 0, 1]); | ||
if(!GLMAT_EPSILON) { | ||
var GLMAT_EPSILON = 0.000001; | ||
} | ||
/** | ||
@@ -42,6 +36,83 @@ * Creates a new identity quat | ||
quat.create = function() { | ||
return new Float32Array(quatIdentity); | ||
var out = new GLMAT_ARRAY_TYPE(4); | ||
out[0] = 0; | ||
out[1] = 0; | ||
out[2] = 0; | ||
out[3] = 1; | ||
return out; | ||
}; | ||
/** | ||
* Sets a quaternion to represent the shortest rotation from one | ||
* vector to another. | ||
* | ||
* Both vectors are assumed to be unit length. | ||
* | ||
* @param {quat} out the receiving quaternion. | ||
* @param {vec3} a the initial vector | ||
* @param {vec3} b the destination vector | ||
* @returns {quat} out | ||
*/ | ||
quat.rotationTo = (function() { | ||
var tmpvec3 = vec3.create(); | ||
var xUnitVec3 = vec3.fromValues(1,0,0); | ||
var yUnitVec3 = vec3.fromValues(0,1,0); | ||
return function(out, a, b) { | ||
var dot = vec3.dot(a, b); | ||
if (dot < -0.999999) { | ||
vec3.cross(tmpvec3, xUnitVec3, a); | ||
if (vec3.length(tmpvec3) < 0.000001) | ||
vec3.cross(tmpvec3, yUnitVec3, a); | ||
vec3.normalize(tmpvec3, tmpvec3); | ||
quat.setAxisAngle(out, tmpvec3, Math.PI); | ||
return out; | ||
} else if (dot > 0.999999) { | ||
out[0] = 0; | ||
out[1] = 0; | ||
out[2] = 0; | ||
out[3] = 1; | ||
return out; | ||
} else { | ||
vec3.cross(tmpvec3, a, b); | ||
out[0] = tmpvec3[0]; | ||
out[1] = tmpvec3[1]; | ||
out[2] = tmpvec3[2]; | ||
out[3] = 1 + dot; | ||
return quat.normalize(out, out); | ||
} | ||
}; | ||
})(); | ||
/** | ||
* Sets the specified quaternion with values corresponding to the given | ||
* axes. Each axis is a vec3 and is expected to be unit length and | ||
* perpendicular to all other specified axes. | ||
* | ||
* @param {vec3} view the vector representing the viewing direction | ||
* @param {vec3} right the vector representing the local "right" direction | ||
* @param {vec3} up the vector representing the local "up" direction | ||
* @returns {quat} out | ||
*/ | ||
quat.setAxes = (function() { | ||
var matr = mat3.create(); | ||
return function(out, view, right, up) { | ||
matr[0] = right[0]; | ||
matr[3] = right[1]; | ||
matr[6] = right[2]; | ||
matr[1] = up[0]; | ||
matr[4] = up[1]; | ||
matr[7] = up[2]; | ||
matr[2] = -view[0]; | ||
matr[5] = -view[1]; | ||
matr[8] = -view[2]; | ||
return quat.normalize(out, quat.fromMat3(out, matr)); | ||
}; | ||
})(); | ||
/** | ||
* Creates a new quat initialized with values from an existing quaternion | ||
@@ -164,3 +235,3 @@ * | ||
* @param {quat} a the vector to scale | ||
* @param {quat} b amount to scale the vector by | ||
* @param {Number} b amount to scale the vector by | ||
* @returns {quat} out | ||
@@ -172,3 +243,3 @@ * @function | ||
/** | ||
* Rotates a quaternion by the given angle around the X axis | ||
* Rotates a quaternion by the given angle about the X axis | ||
* | ||
@@ -194,3 +265,3 @@ * @param {quat} out quat receiving operation result | ||
/** | ||
* Rotates a quaternion by the given angle around the X axis | ||
* Rotates a quaternion by the given angle about the Y axis | ||
* | ||
@@ -216,3 +287,3 @@ * @param {quat} out quat receiving operation result | ||
/** | ||
* Rotates a quaternion by the given angle around the X axis | ||
* Rotates a quaternion by the given angle about the Z axis | ||
* | ||
@@ -257,3 +328,3 @@ * @param {quat} out quat receiving operation result | ||
/** | ||
* Caclulates the dot product of two quat's | ||
* Calculates the dot product of two quat's | ||
* | ||
@@ -289,40 +360,39 @@ * @param {quat} a the first operand | ||
quat.slerp = function (out, a, b, t) { | ||
// benchmarks: | ||
// http://jsperf.com/quaternion-slerp-implementations | ||
var ax = a[0], ay = a[1], az = a[2], aw = a[3], | ||
bx = b[0], by = b[1], bz = b[2], bw = a[3]; | ||
bx = b[0], by = b[1], bz = b[2], bw = b[3]; | ||
var cosHalfTheta = ax * bx + ay * by + az * bz + aw * bw, | ||
halfTheta, | ||
sinHalfTheta, | ||
ratioA, | ||
ratioB; | ||
var omega, cosom, sinom, scale0, scale1; | ||
if (Math.abs(cosHalfTheta) >= 1.0) { | ||
if (out !== a) { | ||
out[0] = ax; | ||
out[1] = ay; | ||
out[2] = az; | ||
out[3] = aw; | ||
} | ||
return out; | ||
// calc cosine | ||
cosom = ax * bx + ay * by + az * bz + aw * bw; | ||
// adjust signs (if necessary) | ||
if ( cosom < 0.0 ) { | ||
cosom = -cosom; | ||
bx = - bx; | ||
by = - by; | ||
bz = - bz; | ||
bw = - bw; | ||
} | ||
halfTheta = Math.acos(cosHalfTheta); | ||
sinHalfTheta = Math.sqrt(1.0 - cosHalfTheta * cosHalfTheta); | ||
if (Math.abs(sinHalfTheta) < 0.001) { | ||
out[0] = (ax * 0.5 + bx * 0.5); | ||
out[1] = (ay * 0.5 + by * 0.5); | ||
out[2] = (az * 0.5 + bz * 0.5); | ||
out[3] = (aw * 0.5 + bw * 0.5); | ||
return out; | ||
// calculate coefficients | ||
if ( (1.0 - cosom) > 0.000001 ) { | ||
// standard case (slerp) | ||
omega = Math.acos(cosom); | ||
sinom = Math.sin(omega); | ||
scale0 = Math.sin((1.0 - t) * omega) / sinom; | ||
scale1 = Math.sin(t * omega) / sinom; | ||
} else { | ||
// "from" and "to" quaternions are very close | ||
// ... so we can do a linear interpolation | ||
scale0 = 1.0 - t; | ||
scale1 = t; | ||
} | ||
ratioA = Math.sin((1 - t) * halfTheta) / sinHalfTheta; | ||
ratioB = Math.sin(t * halfTheta) / sinHalfTheta; | ||
out[0] = (ax * ratioA + bx * ratioB); | ||
out[1] = (ay * ratioA + by * ratioB); | ||
out[2] = (az * ratioA + bz * ratioB); | ||
out[3] = (aw * ratioA + bw * ratioB); | ||
// calculate final values | ||
out[0] = scale0 * ax + scale1 * bx; | ||
out[1] = scale0 * ay + scale1 * by; | ||
out[2] = scale0 * az + scale1 * bz; | ||
out[3] = scale0 * aw + scale1 * bw; | ||
return out; | ||
@@ -369,3 +439,3 @@ }; | ||
/** | ||
* Caclulates the length of a quat | ||
* Calculates the length of a quat | ||
* | ||
@@ -385,3 +455,3 @@ * @param {quat} a vector to calculate length of | ||
/** | ||
* Caclulates the squared length of a quat | ||
* Calculates the squared length of a quat | ||
* | ||
@@ -411,2 +481,48 @@ * @param {quat} a vector to calculate squared length of | ||
/** | ||
* Creates a quaternion from the given 3x3 rotation matrix. | ||
* | ||
* NOTE: The resultant quaternion is not normalized, so you should be sure | ||
* to renormalize the quaternion yourself where necessary. | ||
* | ||
* @param {quat} out the receiving quaternion | ||
* @param {mat3} m rotation matrix | ||
* @returns {quat} out | ||
* @function | ||
*/ | ||
quat.fromMat3 = function(out, m) { | ||
// Algorithm in Ken Shoemake's article in 1987 SIGGRAPH course notes | ||
// article "Quaternion Calculus and Fast Animation". | ||
var fTrace = m[0] + m[4] + m[8]; | ||
var fRoot; | ||
if ( fTrace > 0.0 ) { | ||
// |w| > 1/2, may as well choose w > 1/2 | ||
fRoot = Math.sqrt(fTrace + 1.0); // 2w | ||
out[3] = 0.5 * fRoot; | ||
fRoot = 0.5/fRoot; // 1/(4w) | ||
out[0] = (m[7]-m[5])*fRoot; | ||
out[1] = (m[2]-m[6])*fRoot; | ||
out[2] = (m[3]-m[1])*fRoot; | ||
} else { | ||
// |w| <= 1/2 | ||
var i = 0; | ||
if ( m[4] > m[0] ) | ||
i = 1; | ||
if ( m[8] > m[i*3+i] ) | ||
i = 2; | ||
var j = (i+1)%3; | ||
var k = (i+2)%3; | ||
fRoot = Math.sqrt(m[i*3+i]-m[j*3+j]-m[k*3+k] + 1.0); | ||
out[i] = 0.5 * fRoot; | ||
fRoot = 0.5 / fRoot; | ||
out[3] = (m[k*3+j] - m[j*3+k]) * fRoot; | ||
out[j] = (m[j*3+i] + m[i*3+j]) * fRoot; | ||
out[k] = (m[k*3+i] + m[i*3+k]) * fRoot; | ||
} | ||
return out; | ||
}; | ||
/** | ||
* Returns a string representation of a quatenion | ||
@@ -413,0 +529,0 @@ * |
@@ -1,2 +0,2 @@ | ||
/* Copyright (c) 2012, Brandon Jones, Colin MacKenzie IV. All rights reserved. | ||
/* Copyright (c) 2013, Brandon Jones, Colin MacKenzie IV. All rights reserved. | ||
@@ -29,6 +29,2 @@ Redistribution and use in source and binary forms, with or without modification, | ||
if(!GLMAT_EPSILON) { | ||
var GLMAT_EPSILON = 0.000001; | ||
} | ||
/** | ||
@@ -40,3 +36,6 @@ * Creates a new, empty vec2 | ||
vec2.create = function() { | ||
return new Float32Array(2); | ||
var out = new GLMAT_ARRAY_TYPE(2); | ||
out[0] = 0; | ||
out[1] = 0; | ||
return out; | ||
}; | ||
@@ -51,3 +50,3 @@ | ||
vec2.clone = function(a) { | ||
var out = new Float32Array(2); | ||
var out = new GLMAT_ARRAY_TYPE(2); | ||
out[0] = a[0]; | ||
@@ -66,3 +65,3 @@ out[1] = a[1]; | ||
vec2.fromValues = function(x, y) { | ||
var out = new Float32Array(2); | ||
var out = new GLMAT_ARRAY_TYPE(2); | ||
out[0] = x; | ||
@@ -115,3 +114,3 @@ out[1] = y; | ||
/** | ||
* Subtracts two vec2's | ||
* Subtracts vector b from vector a | ||
* | ||
@@ -208,3 +207,3 @@ * @param {vec2} out the receiving vector | ||
* @param {vec2} a the vector to scale | ||
* @param {vec2} b amount to scale the vector by | ||
* @param {Number} b amount to scale the vector by | ||
* @returns {vec2} out | ||
@@ -219,2 +218,17 @@ */ | ||
/** | ||
* Adds two vec2's after scaling the second operand by a scalar value | ||
* | ||
* @param {vec2} out the receiving vector | ||
* @param {vec2} a the first operand | ||
* @param {vec2} b the second operand | ||
* @param {Number} scale the amount to scale b by before adding | ||
* @returns {vec2} out | ||
*/ | ||
vec2.scaleAndAdd = function(out, a, b, scale) { | ||
out[0] = a[0] + (b[0] * scale); | ||
out[1] = a[1] + (b[1] * scale); | ||
return out; | ||
}; | ||
/** | ||
* Calculates the euclidian distance between two vec2's | ||
@@ -258,3 +272,3 @@ * | ||
/** | ||
* Caclulates the length of a vec2 | ||
* Calculates the length of a vec2 | ||
* | ||
@@ -277,3 +291,3 @@ * @param {vec2} a vector to calculate length of | ||
/** | ||
* Caclulates the squared length of a vec2 | ||
* Calculates the squared length of a vec2 | ||
* | ||
@@ -329,3 +343,3 @@ * @param {vec2} a vector to calculate squared length of | ||
/** | ||
* Caclulates the dot product of two vec2's | ||
* Calculates the dot product of two vec2's | ||
* | ||
@@ -359,3 +373,3 @@ * @param {vec2} a the first operand | ||
* | ||
* @param {vec3} out the receiving vector | ||
* @param {vec2} out the receiving vector | ||
* @param {vec2} a the first operand | ||
@@ -375,2 +389,17 @@ * @param {vec2} b the second operand | ||
/** | ||
* Generates a random vector with the given scale | ||
* | ||
* @param {vec2} out the receiving vector | ||
* @param {Number} [scale] Length of the resulting vector. If ommitted, a unit vector will be returned | ||
* @returns {vec2} out | ||
*/ | ||
vec2.random = function (out, scale) { | ||
scale = scale || 1.0; | ||
var r = GLMAT_RANDOM() * 2.0 * Math.PI; | ||
out[0] = Math.cos(r) * scale; | ||
out[1] = Math.sin(r) * scale; | ||
return out; | ||
}; | ||
/** | ||
* Transforms the vec2 with a mat2 | ||
@@ -386,4 +415,4 @@ * | ||
y = a[1]; | ||
out[0] = x * m[0] + y * m[1]; | ||
out[1] = x * m[2] + y * m[3]; | ||
out[0] = m[0] * x + m[2] * y; | ||
out[1] = m[1] * x + m[3] * y; | ||
return out; | ||
@@ -393,2 +422,53 @@ }; | ||
/** | ||
* Transforms the vec2 with a mat2d | ||
* | ||
* @param {vec2} out the receiving vector | ||
* @param {vec2} a the vector to transform | ||
* @param {mat2d} m matrix to transform with | ||
* @returns {vec2} out | ||
*/ | ||
vec2.transformMat2d = function(out, a, m) { | ||
var x = a[0], | ||
y = a[1]; | ||
out[0] = m[0] * x + m[2] * y + m[4]; | ||
out[1] = m[1] * x + m[3] * y + m[5]; | ||
return out; | ||
}; | ||
/** | ||
* Transforms the vec2 with a mat3 | ||
* 3rd vector component is implicitly '1' | ||
* | ||
* @param {vec2} out the receiving vector | ||
* @param {vec2} a the vector to transform | ||
* @param {mat3} m matrix to transform with | ||
* @returns {vec2} out | ||
*/ | ||
vec2.transformMat3 = function(out, a, m) { | ||
var x = a[0], | ||
y = a[1]; | ||
out[0] = m[0] * x + m[3] * y + m[6]; | ||
out[1] = m[1] * x + m[4] * y + m[7]; | ||
return out; | ||
}; | ||
/** | ||
* Transforms the vec2 with a mat4 | ||
* 3rd vector component is implicitly '0' | ||
* 4th vector component is implicitly '1' | ||
* | ||
* @param {vec2} out the receiving vector | ||
* @param {vec2} a the vector to transform | ||
* @param {mat4} m matrix to transform with | ||
* @returns {vec2} out | ||
*/ | ||
vec2.transformMat4 = function(out, a, m) { | ||
var x = a[0], | ||
y = a[1]; | ||
out[0] = m[0] * x + m[4] * y + m[12]; | ||
out[1] = m[1] * x + m[5] * y + m[13]; | ||
return out; | ||
}; | ||
/** | ||
* Perform some operation over an array of vec2s. | ||
@@ -406,3 +486,3 @@ * | ||
vec2.forEach = (function() { | ||
var vec = new Float32Array(2); | ||
var vec = vec2.create(); | ||
@@ -409,0 +489,0 @@ return function(a, stride, offset, count, fn, arg) { |
@@ -1,2 +0,2 @@ | ||
/* Copyright (c) 2012, Brandon Jones, Colin MacKenzie IV. All rights reserved. | ||
/* Copyright (c) 2013, Brandon Jones, Colin MacKenzie IV. All rights reserved. | ||
@@ -29,6 +29,2 @@ Redistribution and use in source and binary forms, with or without modification, | ||
if(!GLMAT_EPSILON) { | ||
var GLMAT_EPSILON = 0.000001; | ||
} | ||
/** | ||
@@ -40,3 +36,7 @@ * Creates a new, empty vec3 | ||
vec3.create = function() { | ||
return new Float32Array(3); | ||
var out = new GLMAT_ARRAY_TYPE(3); | ||
out[0] = 0; | ||
out[1] = 0; | ||
out[2] = 0; | ||
return out; | ||
}; | ||
@@ -51,3 +51,3 @@ | ||
vec3.clone = function(a) { | ||
var out = new Float32Array(3); | ||
var out = new GLMAT_ARRAY_TYPE(3); | ||
out[0] = a[0]; | ||
@@ -68,3 +68,3 @@ out[1] = a[1]; | ||
vec3.fromValues = function(x, y, z) { | ||
var out = new Float32Array(3); | ||
var out = new GLMAT_ARRAY_TYPE(3); | ||
out[0] = x; | ||
@@ -122,3 +122,3 @@ out[1] = y; | ||
/** | ||
* Subtracts two vec3's | ||
* Subtracts vector b from vector a | ||
* | ||
@@ -220,3 +220,3 @@ * @param {vec3} out the receiving vector | ||
* @param {vec3} a the vector to scale | ||
* @param {vec3} b amount to scale the vector by | ||
* @param {Number} b amount to scale the vector by | ||
* @returns {vec3} out | ||
@@ -232,2 +232,18 @@ */ | ||
/** | ||
* Adds two vec3's after scaling the second operand by a scalar value | ||
* | ||
* @param {vec3} out the receiving vector | ||
* @param {vec3} a the first operand | ||
* @param {vec3} b the second operand | ||
* @param {Number} scale the amount to scale b by before adding | ||
* @returns {vec3} out | ||
*/ | ||
vec3.scaleAndAdd = function(out, a, b, scale) { | ||
out[0] = a[0] + (b[0] * scale); | ||
out[1] = a[1] + (b[1] * scale); | ||
out[2] = a[2] + (b[2] * scale); | ||
return out; | ||
}; | ||
/** | ||
* Calculates the euclidian distance between two vec3's | ||
@@ -273,3 +289,3 @@ * | ||
/** | ||
* Caclulates the length of a vec3 | ||
* Calculates the length of a vec3 | ||
* | ||
@@ -293,3 +309,3 @@ * @param {vec3} a vector to calculate length of | ||
/** | ||
* Caclulates the squared length of a vec3 | ||
* Calculates the squared length of a vec3 | ||
* | ||
@@ -349,3 +365,3 @@ * @param {vec3} a vector to calculate squared length of | ||
/** | ||
* Caclulates the dot product of two vec3's | ||
* Calculates the dot product of two vec3's | ||
* | ||
@@ -398,2 +414,22 @@ * @param {vec3} a the first operand | ||
/** | ||
* Generates a random vector with the given scale | ||
* | ||
* @param {vec3} out the receiving vector | ||
* @param {Number} [scale] Length of the resulting vector. If ommitted, a unit vector will be returned | ||
* @returns {vec3} out | ||
*/ | ||
vec3.random = function (out, scale) { | ||
scale = scale || 1.0; | ||
var r = GLMAT_RANDOM() * 2.0 * Math.PI; | ||
var z = (GLMAT_RANDOM() * 2.0) - 1.0; | ||
var zScale = Math.sqrt(1.0-z*z) * scale; | ||
out[0] = Math.cos(r) * zScale; | ||
out[1] = Math.sin(r) * zScale; | ||
out[2] = z * scale; | ||
return out; | ||
}; | ||
/** | ||
* Transforms the vec3 with a mat4. | ||
@@ -416,2 +452,18 @@ * 4th vector component is implicitly '1' | ||
/** | ||
* Transforms the vec3 with a mat3. | ||
* | ||
* @param {vec3} out the receiving vector | ||
* @param {vec3} a the vector to transform | ||
* @param {mat4} m the 3x3 matrix to transform with | ||
* @returns {vec3} out | ||
*/ | ||
vec3.transformMat3 = function(out, a, m) { | ||
var x = a[0], y = a[1], z = a[2]; | ||
out[0] = x * m[0] + y * m[3] + z * m[6]; | ||
out[1] = x * m[1] + y * m[4] + z * m[7]; | ||
out[2] = x * m[2] + y * m[5] + z * m[8]; | ||
return out; | ||
}; | ||
/** | ||
* Transforms the vec3 with a quat | ||
@@ -425,2 +477,4 @@ * | ||
vec3.transformQuat = function(out, a, q) { | ||
// benchmarks: http://jsperf.com/quaternion-transform-vec3-implementations | ||
var x = a[0], y = a[1], z = a[2], | ||
@@ -442,2 +496,86 @@ qx = q[0], qy = q[1], qz = q[2], qw = q[3], | ||
/* | ||
* Rotate a 3D vector around the x-axis | ||
* @param {vec3} out The receiving vec3 | ||
* @param {vec3} a The vec3 point to rotate | ||
* @param {vec3} b The origin of the rotation | ||
* @param {Number} c The angle of rotation | ||
* @returns {vec3} out | ||
*/ | ||
vec3.rotateX = function(out, a, b, c){ | ||
var p = [], r=[]; | ||
//Translate point to the origin | ||
p[0] = a[0] - b[0]; | ||
p[1] = a[1] - b[1]; | ||
p[2] = a[2] - b[2]; | ||
//perform rotation | ||
r[0] = p[0]; | ||
r[1] = p[1]*Math.cos(c) - p[2]*Math.sin(c); | ||
r[2] = p[1]*Math.sin(c) + p[2]*Math.cos(c); | ||
//translate to correct position | ||
out[0] = r[0] + b[0]; | ||
out[1] = r[1] + b[1]; | ||
out[2] = r[2] + b[2]; | ||
return out; | ||
}; | ||
/* | ||
* Rotate a 3D vector around the y-axis | ||
* @param {vec3} out The receiving vec3 | ||
* @param {vec3} a The vec3 point to rotate | ||
* @param {vec3} b The origin of the rotation | ||
* @param {Number} c The angle of rotation | ||
* @returns {vec3} out | ||
*/ | ||
vec3.rotateY = function(out, a, b, c){ | ||
var p = [], r=[]; | ||
//Translate point to the origin | ||
p[0] = a[0] - b[0]; | ||
p[1] = a[1] - b[1]; | ||
p[2] = a[2] - b[2]; | ||
//perform rotation | ||
r[0] = p[2]*Math.sin(c) + p[0]*Math.cos(c); | ||
r[1] = p[1]; | ||
r[2] = p[2]*Math.cos(c) - p[0]*Math.sin(c); | ||
//translate to correct position | ||
out[0] = r[0] + b[0]; | ||
out[1] = r[1] + b[1]; | ||
out[2] = r[2] + b[2]; | ||
return out; | ||
}; | ||
/* | ||
* Rotate a 3D vector around the z-axis | ||
* @param {vec3} out The receiving vec3 | ||
* @param {vec3} a The vec3 point to rotate | ||
* @param {vec3} b The origin of the rotation | ||
* @param {Number} c The angle of rotation | ||
* @returns {vec3} out | ||
*/ | ||
vec3.rotateZ = function(out, a, b, c){ | ||
var p = [], r=[]; | ||
//Translate point to the origin | ||
p[0] = a[0] - b[0]; | ||
p[1] = a[1] - b[1]; | ||
p[2] = a[2] - b[2]; | ||
//perform rotation | ||
r[0] = p[0]*Math.cos(c) - p[1]*Math.sin(c); | ||
r[1] = p[0]*Math.sin(c) + p[1]*Math.cos(c); | ||
r[2] = p[2]; | ||
//translate to correct position | ||
out[0] = r[0] + b[0]; | ||
out[1] = r[1] + b[1]; | ||
out[2] = r[2] + b[2]; | ||
return out; | ||
}; | ||
/** | ||
@@ -456,3 +594,3 @@ * Perform some operation over an array of vec3s. | ||
vec3.forEach = (function() { | ||
var vec = new Float32Array(3); | ||
var vec = vec3.create(); | ||
@@ -459,0 +597,0 @@ return function(a, stride, offset, count, fn, arg) { |
@@ -1,2 +0,2 @@ | ||
/* Copyright (c) 2012, Brandon Jones, Colin MacKenzie IV. All rights reserved. | ||
/* Copyright (c) 2013, Brandon Jones, Colin MacKenzie IV. All rights reserved. | ||
@@ -29,6 +29,2 @@ Redistribution and use in source and binary forms, with or without modification, | ||
if(!GLMAT_EPSILON) { | ||
var GLMAT_EPSILON = 0.000001; | ||
} | ||
/** | ||
@@ -40,3 +36,8 @@ * Creates a new, empty vec4 | ||
vec4.create = function() { | ||
return new Float32Array(4); | ||
var out = new GLMAT_ARRAY_TYPE(4); | ||
out[0] = 0; | ||
out[1] = 0; | ||
out[2] = 0; | ||
out[3] = 0; | ||
return out; | ||
}; | ||
@@ -51,3 +52,3 @@ | ||
vec4.clone = function(a) { | ||
var out = new Float32Array(4); | ||
var out = new GLMAT_ARRAY_TYPE(4); | ||
out[0] = a[0]; | ||
@@ -70,3 +71,3 @@ out[1] = a[1]; | ||
vec4.fromValues = function(x, y, z, w) { | ||
var out = new Float32Array(4); | ||
var out = new GLMAT_ARRAY_TYPE(4); | ||
out[0] = x; | ||
@@ -129,3 +130,3 @@ out[1] = y; | ||
/** | ||
* Subtracts two vec4's | ||
* Subtracts vector b from vector a | ||
* | ||
@@ -232,3 +233,3 @@ * @param {vec4} out the receiving vector | ||
* @param {vec4} a the vector to scale | ||
* @param {vec4} b amount to scale the vector by | ||
* @param {Number} b amount to scale the vector by | ||
* @returns {vec4} out | ||
@@ -245,2 +246,19 @@ */ | ||
/** | ||
* Adds two vec4's after scaling the second operand by a scalar value | ||
* | ||
* @param {vec4} out the receiving vector | ||
* @param {vec4} a the first operand | ||
* @param {vec4} b the second operand | ||
* @param {Number} scale the amount to scale b by before adding | ||
* @returns {vec4} out | ||
*/ | ||
vec4.scaleAndAdd = function(out, a, b, scale) { | ||
out[0] = a[0] + (b[0] * scale); | ||
out[1] = a[1] + (b[1] * scale); | ||
out[2] = a[2] + (b[2] * scale); | ||
out[3] = a[3] + (b[3] * scale); | ||
return out; | ||
}; | ||
/** | ||
* Calculates the euclidian distance between two vec4's | ||
@@ -288,3 +306,3 @@ * | ||
/** | ||
* Caclulates the length of a vec4 | ||
* Calculates the length of a vec4 | ||
* | ||
@@ -309,3 +327,3 @@ * @param {vec4} a vector to calculate length of | ||
/** | ||
* Caclulates the squared length of a vec4 | ||
* Calculates the squared length of a vec4 | ||
* | ||
@@ -368,3 +386,3 @@ * @param {vec4} a vector to calculate squared length of | ||
/** | ||
* Caclulates the dot product of two vec4's | ||
* Calculates the dot product of two vec4's | ||
* | ||
@@ -401,2 +419,22 @@ * @param {vec4} a the first operand | ||
/** | ||
* Generates a random vector with the given scale | ||
* | ||
* @param {vec4} out the receiving vector | ||
* @param {Number} [scale] Length of the resulting vector. If ommitted, a unit vector will be returned | ||
* @returns {vec4} out | ||
*/ | ||
vec4.random = function (out, scale) { | ||
scale = scale || 1.0; | ||
//TODO: This is a pretty awful way of doing this. Find something better. | ||
out[0] = GLMAT_RANDOM(); | ||
out[1] = GLMAT_RANDOM(); | ||
out[2] = GLMAT_RANDOM(); | ||
out[3] = GLMAT_RANDOM(); | ||
vec4.normalize(out, out); | ||
vec4.scale(out, out, scale); | ||
return out; | ||
}; | ||
/** | ||
* Transforms the vec4 with a mat4. | ||
@@ -456,3 +494,3 @@ * | ||
vec4.forEach = (function() { | ||
var vec = new Float32Array(4); | ||
var vec = vec4.create(); | ||
@@ -459,0 +497,0 @@ return function(a, stride, offset, count, fn, arg) { |
@@ -9,2 +9,3 @@ Running the test suite | ||
* selenium -- used for automated in-browser testing via Ruby | ||
* jscoverage -- used for code coverage report generation | ||
@@ -11,0 +12,0 @@ If Ruby is installed, you can set up with: |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No bug tracker
MaintenancePackage does not have a linked bug tracker in package.json.
Found 1 instance in 1 package
No website
QualityPackage does not have a website.
Found 1 instance in 1 package
462977
57
11243
0
0
3
23