1 /**
  2  * @author mrdoob / http://mrdoob.com/
  3  * @author supereggbert / http://www.paulbrunt.co.uk/
  4  * @author philogb / http://blog.thejit.org/
  5  * @author jordi_ros / http://plattsoft.com
  6  * @author D1plo1d / http://github.com/D1plo1d
  7  * @author alteredq / http://alteredqualia.com/
  8  * @author mikael emtinger / http://gomo.se/
  9  * @author timknip / http://www.floorplanner.com/
 10  */
 11 
 12 
 13 /**@constructor*/
 14 THREE.Matrix4 = function ( n11, n12, n13, n14, n21, n22, n23, n24, n31, n32, n33, n34, n41, n42, n43, n44 ) {
 15 
 16 	this.elements = new Float32Array( 16 );
 17 
 18 	this.set(
 19 
 20 		( n11 !== undefined ) ? n11 : 1, n12 || 0, n13 || 0, n14 || 0,
 21 		n21 || 0, ( n22 !== undefined ) ? n22 : 1, n23 || 0, n24 || 0,
 22 		n31 || 0, n32 || 0, ( n33 !== undefined ) ? n33 : 1, n34 || 0,
 23 		n41 || 0, n42 || 0, n43 || 0, ( n44 !== undefined ) ? n44 : 1
 24 
 25 	);
 26 
 27 };
 28 
 29 THREE.Matrix4.prototype = {
 30 
 31 	constructor: THREE.Matrix4,
 32 
 33 	set: function ( n11, n12, n13, n14, n21, n22, n23, n24, n31, n32, n33, n34, n41, n42, n43, n44 ) {
 34 
 35 		var te = this.elements;
 36 
 37 		te[0] = n11; te[4] = n12; te[8] = n13; te[12] = n14;
 38 		te[1] = n21; te[5] = n22; te[9] = n23; te[13] = n24;
 39 		te[2] = n31; te[6] = n32; te[10] = n33; te[14] = n34;
 40 		te[3] = n41; te[7] = n42; te[11] = n43; te[15] = n44;
 41 
 42 		return this;
 43 
 44 	},
 45 
 46 	identity: function () {
 47 
 48 		this.set(
 49 
 50 			1, 0, 0, 0,
 51 			0, 1, 0, 0,
 52 			0, 0, 1, 0,
 53 			0, 0, 0, 1
 54 
 55 		);
 56 
 57 		return this;
 58 
 59 	},
 60 
 61 	copy: function ( m ) {
 62 
 63 		var me = m.elements;
 64 
 65 		this.set(
 66 
 67 			me[0], me[4], me[8], me[12],
 68 			me[1], me[5], me[9], me[13],
 69 			me[2], me[6], me[10], me[14],
 70 			me[3], me[7], me[11], me[15]
 71 
 72 		);
 73 
 74 		return this;
 75 
 76 	},
 77 
 78 	lookAt: function ( eye, target, up ) {
 79 
 80 		var te = this.elements;
 81 
 82 		var x = THREE.Matrix4.__v1;
 83 		var y = THREE.Matrix4.__v2;
 84 		var z = THREE.Matrix4.__v3;
 85 
 86 		z.sub( eye, target ).normalize();
 87 
 88 		if ( z.length() === 0 ) {
 89 
 90 			z.z = 1;
 91 
 92 		}
 93 
 94 		x.cross( up, z ).normalize();
 95 
 96 		if ( x.length() === 0 ) {
 97 
 98 			z.x += 0.0001;
 99 			x.cross( up, z ).normalize();
100 
101 		}
102 
103 		y.cross( z, x );
104 
105 
106 		te[0] = x.x; te[4] = y.x; te[8] = z.x;
107 		te[1] = x.y; te[5] = y.y; te[9] = z.y;
108 		te[2] = x.z; te[6] = y.z; te[10] = z.z;
109 
110 		return this;
111 
112 	},
113 
114 	multiply: function ( a, b ) {
115 
116 		var ae = a.elements;
117 		var be = b.elements;
118 		var te = this.elements;
119 
120 		var a11 = ae[0], a12 = ae[4], a13 = ae[8], a14 = ae[12];
121 		var a21 = ae[1], a22 = ae[5], a23 = ae[9], a24 = ae[13];
122 		var a31 = ae[2], a32 = ae[6], a33 = ae[10], a34 = ae[14];
123 		var a41 = ae[3], a42 = ae[7], a43 = ae[11], a44 = ae[15];
124 
125 		var b11 = be[0], b12 = be[4], b13 = be[8], b14 = be[12];
126 		var b21 = be[1], b22 = be[5], b23 = be[9], b24 = be[13];
127 		var b31 = be[2], b32 = be[6], b33 = be[10], b34 = be[14];
128 		var b41 = be[3], b42 = be[7], b43 = be[11], b44 = be[15];
129 
130 		te[0] = a11 * b11 + a12 * b21 + a13 * b31 + a14 * b41;
131 		te[4] = a11 * b12 + a12 * b22 + a13 * b32 + a14 * b42;
132 		te[8] = a11 * b13 + a12 * b23 + a13 * b33 + a14 * b43;
133 		te[12] = a11 * b14 + a12 * b24 + a13 * b34 + a14 * b44;
134 
135 		te[1] = a21 * b11 + a22 * b21 + a23 * b31 + a24 * b41;
136 		te[5] = a21 * b12 + a22 * b22 + a23 * b32 + a24 * b42;
137 		te[9] = a21 * b13 + a22 * b23 + a23 * b33 + a24 * b43;
138 		te[13] = a21 * b14 + a22 * b24 + a23 * b34 + a24 * b44;
139 
140 		te[2] = a31 * b11 + a32 * b21 + a33 * b31 + a34 * b41;
141 		te[6] = a31 * b12 + a32 * b22 + a33 * b32 + a34 * b42;
142 		te[10] = a31 * b13 + a32 * b23 + a33 * b33 + a34 * b43;
143 		te[14] = a31 * b14 + a32 * b24 + a33 * b34 + a34 * b44;
144 
145 		te[3] = a41 * b11 + a42 * b21 + a43 * b31 + a44 * b41;
146 		te[7] = a41 * b12 + a42 * b22 + a43 * b32 + a44 * b42;
147 		te[11] = a41 * b13 + a42 * b23 + a43 * b33 + a44 * b43;
148 		te[15] = a41 * b14 + a42 * b24 + a43 * b34 + a44 * b44;
149 
150 		return this;
151 
152 	},
153 
154 	multiplySelf: function ( m ) {
155 
156 		return this.multiply( this, m );
157 
158 	},
159 
160 	multiplyToArray: function ( a, b, r ) {
161 
162 		var te = this.elements;
163 
164 		this.multiply( a, b );
165 
166 		r[ 0 ] = te[0]; r[ 1 ] = te[1]; r[ 2 ] = te[2]; r[ 3 ] = te[3];
167 		r[ 4 ] = te[4]; r[ 5 ] = te[5]; r[ 6 ] = te[6]; r[ 7 ] = te[7];
168 		r[ 8 ]  = te[8]; r[ 9 ]  = te[9]; r[ 10 ] = te[10]; r[ 11 ] = te[11];
169 		r[ 12 ] = te[12]; r[ 13 ] = te[13]; r[ 14 ] = te[14]; r[ 15 ] = te[15];
170 
171 		return this;
172 
173 	},
174 
175 	multiplyScalar: function ( s ) {
176 
177 		var te = this.elements;
178 
179 		te[0] *= s; te[4] *= s; te[8] *= s; te[12] *= s;
180 		te[1] *= s; te[5] *= s; te[9] *= s; te[13] *= s;
181 		te[2] *= s; te[6] *= s; te[10] *= s; te[14] *= s;
182 		te[3] *= s; te[7] *= s; te[11] *= s; te[15] *= s;
183 
184 		return this;
185 
186 	},
187 
188 	multiplyVector3: function ( v ) {
189 
190 		var te = this.elements;
191 
192 		var vx = v.x, vy = v.y, vz = v.z;
193 		var d = 1 / ( te[3] * vx + te[7] * vy + te[11] * vz + te[15] );
194 
195 		v.x = ( te[0] * vx + te[4] * vy + te[8] * vz + te[12] ) * d;
196 		v.y = ( te[1] * vx + te[5] * vy + te[9] * vz + te[13] ) * d;
197 		v.z = ( te[2] * vx + te[6] * vy + te[10] * vz + te[14] ) * d;
198 
199 		return v;
200 
201 	},
202 
203 	multiplyVector4: function ( v ) {
204 
205 		var te = this.elements;
206 		var vx = v.x, vy = v.y, vz = v.z, vw = v.w;
207 
208 		v.x = te[0] * vx + te[4] * vy + te[8] * vz + te[12] * vw;
209 		v.y = te[1] * vx + te[5] * vy + te[9] * vz + te[13] * vw;
210 		v.z = te[2] * vx + te[6] * vy + te[10] * vz + te[14] * vw;
211 		v.w = te[3] * vx + te[7] * vy + te[11] * vz + te[15] * vw;
212 
213 		return v;
214 
215 	},
216 
217 	multiplyVector3Array: function ( a ) {
218 
219 		var tmp = THREE.Matrix4.__v1;
220 
221 		for ( var i = 0, il = a.length; i < il; i += 3 ) {
222 
223 			tmp.x = a[ i ];
224 			tmp.y = a[ i + 1 ];
225 			tmp.z = a[ i + 2 ];
226 
227 			this.multiplyVector3( tmp );
228 
229 			a[ i ]     = tmp.x;
230 			a[ i + 1 ] = tmp.y;
231 			a[ i + 2 ] = tmp.z;
232 
233 		}
234 
235 		return a;
236 
237 	},
238 
239 	rotateAxis: function ( v ) {
240 
241 		var te = this.elements;
242 		var vx = v.x, vy = v.y, vz = v.z;
243 
244 		v.x = vx * te[0] + vy * te[4] + vz * te[8];
245 		v.y = vx * te[1] + vy * te[5] + vz * te[9];
246 		v.z = vx * te[2] + vy * te[6] + vz * te[10];
247 
248 		v.normalize();
249 
250 		return v;
251 
252 	},
253 
254 	crossVector: function ( a ) {
255 
256 		var te = this.elements;
257 		var v = new THREE.Vector4();
258 
259 		v.x = te[0] * a.x + te[4] * a.y + te[8] * a.z + te[12] * a.w;
260 		v.y = te[1] * a.x + te[5] * a.y + te[9] * a.z + te[13] * a.w;
261 		v.z = te[2] * a.x + te[6] * a.y + te[10] * a.z + te[14] * a.w;
262 
263 		v.w = ( a.w ) ? te[3] * a.x + te[7] * a.y + te[11] * a.z + te[15] * a.w : 1;
264 
265 		return v;
266 
267 	},
268 
269 	determinant: function () {
270 
271 		var te = this.elements;
272 
273 		var n11 = te[0], n12 = te[4], n13 = te[8], n14 = te[12];
274 		var n21 = te[1], n22 = te[5], n23 = te[9], n24 = te[13];
275 		var n31 = te[2], n32 = te[6], n33 = te[10], n34 = te[14];
276 		var n41 = te[3], n42 = te[7], n43 = te[11], n44 = te[15];
277 
278 		//TODO: make this more efficient
279 		//( based on http://www.euclideanspace.com/maths/algebra/matrix/functions/inverse/fourD/index.htm )
280 
281 		return (
282 			n14 * n23 * n32 * n41-
283 			n13 * n24 * n32 * n41-
284 			n14 * n22 * n33 * n41+
285 			n12 * n24 * n33 * n41+
286 
287 			n13 * n22 * n34 * n41-
288 			n12 * n23 * n34 * n41-
289 			n14 * n23 * n31 * n42+
290 			n13 * n24 * n31 * n42+
291 
292 			n14 * n21 * n33 * n42-
293 			n11 * n24 * n33 * n42-
294 			n13 * n21 * n34 * n42+
295 			n11 * n23 * n34 * n42+
296 
297 			n14 * n22 * n31 * n43-
298 			n12 * n24 * n31 * n43-
299 			n14 * n21 * n32 * n43+
300 			n11 * n24 * n32 * n43+
301 
302 			n12 * n21 * n34 * n43-
303 			n11 * n22 * n34 * n43-
304 			n13 * n22 * n31 * n44+
305 			n12 * n23 * n31 * n44+
306 
307 			n13 * n21 * n32 * n44-
308 			n11 * n23 * n32 * n44-
309 			n12 * n21 * n33 * n44+
310 			n11 * n22 * n33 * n44
311 		);
312 
313 	},
314 
315 	transpose: function () {
316 
317 		var te = this.elements;
318 		var tmp;
319 
320 		tmp = te[1]; te[1] = te[4]; te[4] = tmp;
321 		tmp = te[2]; te[2] = te[8]; te[8] = tmp;
322 		tmp = te[6]; te[6] = te[9]; te[9] = tmp;
323 
324 		tmp = te[3]; te[3] = te[12]; te[12] = tmp;
325 		tmp = te[7]; te[7] = te[13]; te[13] = tmp;
326 		tmp = te[11]; te[11] = te[14]; te[14] = tmp;
327 
328 		return this;
329 
330 	},
331 
332 	flattenToArray: function ( flat ) {
333 
334 		var te = this.elements;
335 		flat[ 0 ] = te[0]; flat[ 1 ] = te[1]; flat[ 2 ] = te[2]; flat[ 3 ] = te[3];
336 		flat[ 4 ] = te[4]; flat[ 5 ] = te[5]; flat[ 6 ] = te[6]; flat[ 7 ] = te[7];
337 		flat[ 8 ]  = te[8]; flat[ 9 ]  = te[9]; flat[ 10 ] = te[10]; flat[ 11 ] = te[11];
338 		flat[ 12 ] = te[12]; flat[ 13 ] = te[13]; flat[ 14 ] = te[14]; flat[ 15 ] = te[15];
339 
340 		return flat;
341 
342 	},
343 
344 	flattenToArrayOffset: function( flat, offset ) {
345 
346 		var te = this.elements;
347 		flat[ offset ] = te[0];
348 		flat[ offset + 1 ] = te[1];
349 		flat[ offset + 2 ] = te[2];
350 		flat[ offset + 3 ] = te[3];
351 
352 		flat[ offset + 4 ] = te[4];
353 		flat[ offset + 5 ] = te[5];
354 		flat[ offset + 6 ] = te[6];
355 		flat[ offset + 7 ] = te[7];
356 
357 		flat[ offset + 8 ]  = te[8];
358 		flat[ offset + 9 ]  = te[9];
359 		flat[ offset + 10 ] = te[10];
360 		flat[ offset + 11 ] = te[11];
361 
362 		flat[ offset + 12 ] = te[12];
363 		flat[ offset + 13 ] = te[13];
364 		flat[ offset + 14 ] = te[14];
365 		flat[ offset + 15 ] = te[15];
366 
367 		return flat;
368 
369 	},
370 
371 	getPosition: function () {
372 
373 		var te = this.elements;
374 		return THREE.Matrix4.__v1.set( te[12], te[13], te[14] );
375 
376 	},
377 
378 	setPosition: function ( v ) {
379 
380 		var te = this.elements;
381 
382 		te[12] = v.x;
383 		te[13] = v.y;
384 		te[14] = v.z;
385 
386 		return this;
387 
388 	},
389 
390 	getColumnX: function () {
391 
392 		var te = this.elements;
393 		return THREE.Matrix4.__v1.set( te[0], te[1], te[2] );
394 
395 	},
396 
397 	getColumnY: function () {
398 
399 		var te = this.elements;
400 		return THREE.Matrix4.__v1.set( te[4], te[5], te[6] );
401 
402 	},
403 
404 	getColumnZ: function() {
405 
406 		var te = this.elements;
407 		return THREE.Matrix4.__v1.set( te[8], te[9], te[10] );
408 
409 	},
410 
411 	getInverse: function ( m ) {
412 
413 		// based on http://www.euclideanspace.com/maths/algebra/matrix/functions/inverse/fourD/index.htm
414 		var te = this.elements;
415 		var me = m.elements;
416 
417 		var n11 = me[0], n12 = me[4], n13 = me[8], n14 = me[12];
418 		var n21 = me[1], n22 = me[5], n23 = me[9], n24 = me[13];
419 		var n31 = me[2], n32 = me[6], n33 = me[10], n34 = me[14];
420 		var n41 = me[3], n42 = me[7], n43 = me[11], n44 = me[15];
421 
422 		te[0] = n23*n34*n42 - n24*n33*n42 + n24*n32*n43 - n22*n34*n43 - n23*n32*n44 + n22*n33*n44;
423 		te[4] = n14*n33*n42 - n13*n34*n42 - n14*n32*n43 + n12*n34*n43 + n13*n32*n44 - n12*n33*n44;
424 		te[8] = n13*n24*n42 - n14*n23*n42 + n14*n22*n43 - n12*n24*n43 - n13*n22*n44 + n12*n23*n44;
425 		te[12] = n14*n23*n32 - n13*n24*n32 - n14*n22*n33 + n12*n24*n33 + n13*n22*n34 - n12*n23*n34;
426 		te[1] = n24*n33*n41 - n23*n34*n41 - n24*n31*n43 + n21*n34*n43 + n23*n31*n44 - n21*n33*n44;
427 		te[5] = n13*n34*n41 - n14*n33*n41 + n14*n31*n43 - n11*n34*n43 - n13*n31*n44 + n11*n33*n44;
428 		te[9] = n14*n23*n41 - n13*n24*n41 - n14*n21*n43 + n11*n24*n43 + n13*n21*n44 - n11*n23*n44;
429 		te[13] = n13*n24*n31 - n14*n23*n31 + n14*n21*n33 - n11*n24*n33 - n13*n21*n34 + n11*n23*n34;
430 		te[2] = n22*n34*n41 - n24*n32*n41 + n24*n31*n42 - n21*n34*n42 - n22*n31*n44 + n21*n32*n44;
431 		te[6] = n14*n32*n41 - n12*n34*n41 - n14*n31*n42 + n11*n34*n42 + n12*n31*n44 - n11*n32*n44;
432 		te[10] = n12*n24*n41 - n14*n22*n41 + n14*n21*n42 - n11*n24*n42 - n12*n21*n44 + n11*n22*n44;
433 		te[14] = n14*n22*n31 - n12*n24*n31 - n14*n21*n32 + n11*n24*n32 + n12*n21*n34 - n11*n22*n34;
434 		te[3] = n23*n32*n41 - n22*n33*n41 - n23*n31*n42 + n21*n33*n42 + n22*n31*n43 - n21*n32*n43;
435 		te[7] = n12*n33*n41 - n13*n32*n41 + n13*n31*n42 - n11*n33*n42 - n12*n31*n43 + n11*n32*n43;
436 		te[11] = n13*n22*n41 - n12*n23*n41 - n13*n21*n42 + n11*n23*n42 + n12*n21*n43 - n11*n22*n43;
437 		te[15] = n12*n23*n31 - n13*n22*n31 + n13*n21*n32 - n11*n23*n32 - n12*n21*n33 + n11*n22*n33;
438 		this.multiplyScalar( 1 / m.determinant() );
439 
440 		return this;
441 
442 	},
443 
444 	setRotationFromEuler: function ( v, order ) {
445 
446 		var te = this.elements;
447 
448 		var x = v.x, y = v.y, z = v.z;
449 		var a = Math.cos( x ), b = Math.sin( x );
450 		var c = Math.cos( y ), d = Math.sin( y );
451 		var e = Math.cos( z ), f = Math.sin( z );
452 
453 		if ( order === undefined || order === 'XYZ' ) {
454 
455 			var ae = a * e, af = a * f, be = b * e, bf = b * f;
456 
457 			te[0] = c * e;
458 			te[4] = - c * f;
459 			te[8] = d;
460 
461 			te[1] = af + be * d;
462 			te[5] = ae - bf * d;
463 			te[9] = - b * c;
464 
465 			te[2] = bf - ae * d;
466 			te[6] = be + af * d;
467 			te[10] = a * c;
468 
469 		} else if ( order === 'YXZ' ) {
470 
471 			var ce = c * e, cf = c * f, de = d * e, df = d * f;
472 
473 			te[0] = ce + df * b;
474 			te[4] = de * b - cf;
475 			te[8] = a * d;
476 
477 			te[1] = a * f;
478 			te[5] = a * e;
479 			te[9] = - b;
480 
481 			te[2] = cf * b - de;
482 			te[6] = df + ce * b;
483 			te[10] = a * c;
484 
485 		} else if ( order === 'ZXY' ) {
486 
487 			var ce = c * e, cf = c * f, de = d * e, df = d * f;
488 
489 			te[0] = ce - df * b;
490 			te[4] = - a * f;
491 			te[8] = de + cf * b;
492 
493 			te[1] = cf + de * b;
494 			te[5] = a * e;
495 			te[9] = df - ce * b;
496 
497 			te[2] = - a * d;
498 			te[6] = b;
499 			te[10] = a * c;
500 
501 		} else if ( order === 'ZYX' ) {
502 
503 			var ae = a * e, af = a * f, be = b * e, bf = b * f;
504 
505 			te[0] = c * e;
506 			te[4] = be * d - af;
507 			te[8] = ae * d + bf;
508 
509 			te[1] = c * f;
510 			te[5] = bf * d + ae;
511 			te[9] = af * d - be;
512 
513 			te[2] = - d;
514 			te[6] = b * c;
515 			te[10] = a * c;
516 
517 		} else if ( order === 'YZX' ) {
518 
519 			var ac = a * c, ad = a * d, bc = b * c, bd = b * d;
520 
521 			te[0] = c * e;
522 			te[4] = bd - ac * f;
523 			te[8] = bc * f + ad;
524 
525 			te[1] = f;
526 			te[5] = a * e;
527 			te[9] = - b * e;
528 
529 			te[2] = - d * e;
530 			te[6] = ad * f + bc;
531 			te[10] = ac - bd * f;
532 
533 		} else if ( order === 'XZY' ) {
534 
535 			var ac = a * c, ad = a * d, bc = b * c, bd = b * d;
536 
537 			te[0] = c * e;
538 			te[4] = - f;
539 			te[8] = d * e;
540 
541 			te[1] = ac * f + bd;
542 			te[5] = a * e;
543 			te[9] = ad * f - bc;
544 
545 			te[2] = bc * f - ad;
546 			te[6] = b * e;
547 			te[10] = bd * f + ac;
548 
549 		}
550 
551 		return this;
552 
553 	},
554 
555 
556 	setRotationFromQuaternion: function ( q ) {
557 
558 		var te = this.elements;
559 
560 		var x = q.x, y = q.y, z = q.z, w = q.w;
561 		var x2 = x + x, y2 = y + y, z2 = z + z;
562 		var xx = x * x2, xy = x * y2, xz = x * z2;
563 		var yy = y * y2, yz = y * z2, zz = z * z2;
564 		var wx = w * x2, wy = w * y2, wz = w * z2;
565 
566 		te[0] = 1 - ( yy + zz );
567 		te[4] = xy - wz;
568 		te[8] = xz + wy;
569 
570 		te[1] = xy + wz;
571 		te[5] = 1 - ( xx + zz );
572 		te[9] = yz - wx;
573 
574 		te[2] = xz - wy;
575 		te[6] = yz + wx;
576 		te[10] = 1 - ( xx + yy );
577 
578 		return this;
579 
580 	},
581 
582 	compose: function ( translation, rotation, scale ) {
583 
584 		var te = this.elements;
585 		var mRotation = THREE.Matrix4.__m1;
586 		var mScale = THREE.Matrix4.__m2;
587 
588 		mRotation.identity();
589 		mRotation.setRotationFromQuaternion( rotation );
590 
591 		mScale.makeScale( scale.x, scale.y, scale.z );
592 
593 		this.multiply( mRotation, mScale );
594 
595 		te[12] = translation.x;
596 		te[13] = translation.y;
597 		te[14] = translation.z;
598 
599 		return this;
600 
601 	},
602 
603 	decompose: function ( translation, rotation, scale ) {
604 
605 		var te = this.elements;
606 
607 		// grab the axis vectors
608 		var x = THREE.Matrix4.__v1;
609 		var y = THREE.Matrix4.__v2;
610 		var z = THREE.Matrix4.__v3;
611 
612 		x.set( te[0], te[1], te[2] );
613 		y.set( te[4], te[5], te[6] );
614 		z.set( te[8], te[9], te[10] );
615 
616 		translation = ( translation instanceof THREE.Vector3 ) ? translation : new THREE.Vector3();
617 		rotation = ( rotation instanceof THREE.Quaternion ) ? rotation : new THREE.Quaternion();
618 		scale = ( scale instanceof THREE.Vector3 ) ? scale : new THREE.Vector3();
619 
620 		scale.x = x.length();
621 		scale.y = y.length();
622 		scale.z = z.length();
623 
624 		translation.x = te[12];
625 		translation.y = te[13];
626 		translation.z = te[14];
627 
628 		// scale the rotation part
629 
630 		var matrix = THREE.Matrix4.__m1;
631 
632 		matrix.copy( this );
633 
634 		matrix.elements[0] /= scale.x;
635 		matrix.elements[1] /= scale.x;
636 		matrix.elements[2] /= scale.x;
637 
638 		matrix.elements[4] /= scale.y;
639 		matrix.elements[5] /= scale.y;
640 		matrix.elements[6] /= scale.y;
641 
642 		matrix.elements[8] /= scale.z;
643 		matrix.elements[9] /= scale.z;
644 		matrix.elements[10] /= scale.z;
645 
646 		rotation.setFromRotationMatrix( matrix );
647 
648 		return [ translation, rotation, scale ];
649 
650 	},
651 
652 	extractPosition: function ( m ) {
653 
654 		var te = this.elements;
655 		var me = m.elements;
656 
657 		te[12] = me[12];
658 		te[13] = me[13];
659 		te[14] = me[14];
660 
661 		return this;
662 
663 	},
664 
665 	extractRotation: function ( m ) {
666 
667 		var te = this.elements;
668 		var me = m.elements;
669 
670 		var vector = THREE.Matrix4.__v1;
671 
672 		var scaleX = 1 / vector.set( me[0], me[1], me[2] ).length();
673 		var scaleY = 1 / vector.set( me[4], me[5], me[6] ).length();
674 		var scaleZ = 1 / vector.set( me[8], me[9], me[10] ).length();
675 
676 		te[0] = me[0] * scaleX;
677 		te[1] = me[1] * scaleX;
678 		te[2] = me[2] * scaleX;
679 
680 		te[4] = me[4] * scaleY;
681 		te[5] = me[5] * scaleY;
682 		te[6] = me[6] * scaleY;
683 
684 		te[8] = me[8] * scaleZ;
685 		te[9] = me[9] * scaleZ;
686 		te[10] = me[10] * scaleZ;
687 
688 		return this;
689 
690 	},
691 
692 	//
693 
694 	translate: function ( v ) {
695 
696 		var te = this.elements;
697 		var x = v.x, y = v.y, z = v.z;
698 
699 		te[12] = te[0] * x + te[4] * y + te[8] * z + te[12];
700 		te[13] = te[1] * x + te[5] * y + te[9] * z + te[13];
701 		te[14] = te[2] * x + te[6] * y + te[10] * z + te[14];
702 		te[15] = te[3] * x + te[7] * y + te[11] * z + te[15];
703 
704 		return this;
705 
706 	},
707 
708 	rotateX: function ( angle ) {
709 
710 		var te = this.elements;
711 		var m12 = te[4];
712 		var m22 = te[5];
713 		var m32 = te[6];
714 		var m42 = te[7];
715 		var m13 = te[8];
716 		var m23 = te[9];
717 		var m33 = te[10];
718 		var m43 = te[11];
719 		var c = Math.cos( angle );
720 		var s = Math.sin( angle );
721 
722 		te[4] = c * m12 + s * m13;
723 		te[5] = c * m22 + s * m23;
724 		te[6] = c * m32 + s * m33;
725 		te[7] = c * m42 + s * m43;
726 
727 		te[8] = c * m13 - s * m12;
728 		te[9] = c * m23 - s * m22;
729 		te[10] = c * m33 - s * m32;
730 		te[11] = c * m43 - s * m42;
731 
732 		return this;
733 
734 	},
735 
736 	rotateY: function ( angle ) {
737 
738 		var te = this.elements;
739 		var m11 = te[0];
740 		var m21 = te[1];
741 		var m31 = te[2];
742 		var m41 = te[3];
743 		var m13 = te[8];
744 		var m23 = te[9];
745 		var m33 = te[10];
746 		var m43 = te[11];
747 		var c = Math.cos( angle );
748 		var s = Math.sin( angle );
749 
750 		te[0] = c * m11 - s * m13;
751 		te[1] = c * m21 - s * m23;
752 		te[2] = c * m31 - s * m33;
753 		te[3] = c * m41 - s * m43;
754 
755 		te[8] = c * m13 + s * m11;
756 		te[9] = c * m23 + s * m21;
757 		te[10] = c * m33 + s * m31;
758 		te[11] = c * m43 + s * m41;
759 
760 		return this;
761 
762 	},
763 
764 	rotateZ: function ( angle ) {
765 
766 		var te = this.elements;
767 		var m11 = te[0];
768 		var m21 = te[1];
769 		var m31 = te[2];
770 		var m41 = te[3];
771 		var m12 = te[4];
772 		var m22 = te[5];
773 		var m32 = te[6];
774 		var m42 = te[7];
775 		var c = Math.cos( angle );
776 		var s = Math.sin( angle );
777 
778 		te[0] = c * m11 + s * m12;
779 		te[1] = c * m21 + s * m22;
780 		te[2] = c * m31 + s * m32;
781 		te[3] = c * m41 + s * m42;
782 
783 		te[4] = c * m12 - s * m11;
784 		te[5] = c * m22 - s * m21;
785 		te[6] = c * m32 - s * m31;
786 		te[7] = c * m42 - s * m41;
787 
788 		return this;
789 
790 	},
791 
792 	rotateByAxis: function ( axis, angle ) {
793 
794 		var te = this.elements;
795 
796 		// optimize by checking axis
797 
798 		if ( axis.x === 1 && axis.y === 0 && axis.z === 0 ) {
799 
800 			return this.rotateX( angle );
801 
802 		} else if ( axis.x === 0 && axis.y === 1 && axis.z === 0 ) {
803 
804 			return this.rotateY( angle );
805 
806 		} else if ( axis.x === 0 && axis.y === 0 && axis.z === 1 ) {
807 
808 			return this.rotateZ( angle );
809 
810 		}
811 
812 		var x = axis.x, y = axis.y, z = axis.z;
813 		var n = Math.sqrt(x * x + y * y + z * z);
814 
815 		x /= n;
816 		y /= n;
817 		z /= n;
818 
819 		var xx = x * x, yy = y * y, zz = z * z;
820 		var c = Math.cos( angle );
821 		var s = Math.sin( angle );
822 		var oneMinusCosine = 1 - c;
823 		var xy = x * y * oneMinusCosine;
824 		var xz = x * z * oneMinusCosine;
825 		var yz = y * z * oneMinusCosine;
826 		var xs = x * s;
827 		var ys = y * s;
828 		var zs = z * s;
829 
830 		var r11 = xx + (1 - xx) * c;
831 		var r21 = xy + zs;
832 		var r31 = xz - ys;
833 		var r12 = xy - zs;
834 		var r22 = yy + (1 - yy) * c;
835 		var r32 = yz + xs;
836 		var r13 = xz + ys;
837 		var r23 = yz - xs;
838 		var r33 = zz + (1 - zz) * c;
839 
840 		var m11 = te[0], m21 = te[1], m31 = te[2], m41 = te[3];
841 		var m12 = te[4], m22 = te[5], m32 = te[6], m42 = te[7];
842 		var m13 = te[8], m23 = te[9], m33 = te[10], m43 = te[11];
843 		var m14 = te[12], m24 = te[13], m34 = te[14], m44 = te[15];
844 
845 		te[0] = r11 * m11 + r21 * m12 + r31 * m13;
846 		te[1] = r11 * m21 + r21 * m22 + r31 * m23;
847 		te[2] = r11 * m31 + r21 * m32 + r31 * m33;
848 		te[3] = r11 * m41 + r21 * m42 + r31 * m43;
849 
850 		te[4] = r12 * m11 + r22 * m12 + r32 * m13;
851 		te[5] = r12 * m21 + r22 * m22 + r32 * m23;
852 		te[6] = r12 * m31 + r22 * m32 + r32 * m33;
853 		te[7] = r12 * m41 + r22 * m42 + r32 * m43;
854 
855 		te[8] = r13 * m11 + r23 * m12 + r33 * m13;
856 		te[9] = r13 * m21 + r23 * m22 + r33 * m23;
857 		te[10] = r13 * m31 + r23 * m32 + r33 * m33;
858 		te[11] = r13 * m41 + r23 * m42 + r33 * m43;
859 
860 		return this;
861 
862 	},
863 
864 	scale: function ( v ) {
865 
866 		var te = this.elements;
867 		var x = v.x, y = v.y, z = v.z;
868 
869 		te[0] *= x; te[4] *= y; te[8] *= z;
870 		te[1] *= x; te[5] *= y; te[9] *= z;
871 		te[2] *= x; te[6] *= y; te[10] *= z;
872 		te[3] *= x; te[7] *= y; te[11] *= z;
873 
874 		return this;
875 
876 	},
877 
878 	getMaxScaleOnAxis: function () {
879 
880 		var te = this.elements;
881 
882 		var scaleXSq =  te[0] * te[0] + te[1] * te[1] + te[2] * te[2];
883 		var scaleYSq =  te[4] * te[4] + te[5] * te[5] + te[6] * te[6];
884 		var scaleZSq =  te[8] * te[8] + te[9] * te[9] + te[10] * te[10];
885 
886 		return Math.sqrt( Math.max( scaleXSq, Math.max( scaleYSq, scaleZSq ) ) );
887 
888 	},
889 
890 	//
891 
892 	makeTranslation: function ( x, y, z ) {
893 
894 		this.set(
895 
896 			1, 0, 0, x,
897 			0, 1, 0, y,
898 			0, 0, 1, z,
899 			0, 0, 0, 1
900 
901 		);
902 
903 		return this;
904 
905 	},
906 
907 	makeRotationX: function ( theta ) {
908 
909 		var c = Math.cos( theta ), s = Math.sin( theta );
910 
911 		this.set(
912 
913 			1, 0,  0, 0,
914 			0, c, -s, 0,
915 			0, s,  c, 0,
916 			0, 0,  0, 1
917 
918 		);
919 
920 		return this;
921 
922 	},
923 
924 	makeRotationY: function ( theta ) {
925 
926 		var c = Math.cos( theta ), s = Math.sin( theta );
927 
928 		this.set(
929 
930 			 c, 0, s, 0,
931 			 0, 1, 0, 0,
932 			-s, 0, c, 0,
933 			 0, 0, 0, 1
934 
935 		);
936 
937 		return this;
938 
939 	},
940 
941 	makeRotationZ: function ( theta ) {
942 
943 		var c = Math.cos( theta ), s = Math.sin( theta );
944 
945 		this.set(
946 
947 			c, -s, 0, 0,
948 			s,  c, 0, 0,
949 			0,  0, 1, 0,
950 			0,  0, 0, 1
951 
952 		);
953 
954 		return this;
955 
956 	},
957 
958 	makeRotationAxis: function ( axis, angle ) {
959 
960 		// Based on http://www.gamedev.net/reference/articles/article1199.asp
961 
962 		var c = Math.cos( angle );
963 		var s = Math.sin( angle );
964 		var t = 1 - c;
965 		var x = axis.x, y = axis.y, z = axis.z;
966 		var tx = t * x, ty = t * y;
967 
968 		this.set(
969 
970 			tx * x + c, tx * y - s * z, tx * z + s * y, 0,
971 			tx * y + s * z, ty * y + c, ty * z - s * x, 0,
972 			tx * z - s * y, ty * z + s * x, t * z * z + c, 0,
973 			0, 0, 0, 1
974 
975 		);
976 
977 		 return this;
978 
979 	},
980 
981 	makeScale: function ( x, y, z ) {
982 
983 		this.set(
984 
985 			x, 0, 0, 0,
986 			0, y, 0, 0,
987 			0, 0, z, 0,
988 			0, 0, 0, 1
989 
990 		);
991 
992 		return this;
993 
994 	},
995 
996 	makeFrustum: function ( left, right, bottom, top, near, far ) {
997 
998 		var te = this.elements;
999 		var x = 2 * near / ( right - left );
1000 		var y = 2 * near / ( top - bottom );
1001 
1002 		var a = ( right + left ) / ( right - left );
1003 		var b = ( top + bottom ) / ( top - bottom );
1004 		var c = - ( far + near ) / ( far - near );
1005 		var d = - 2 * far * near / ( far - near );
1006 
1007 		te[0] = x;  te[4] = 0;  te[8] = a;   te[12] = 0;
1008 		te[1] = 0;  te[5] = y;  te[9] = b;   te[13] = 0;
1009 		te[2] = 0;  te[6] = 0;  te[10] = c;   te[14] = d;
1010 		te[3] = 0;  te[7] = 0;  te[11] = - 1; te[15] = 0;
1011 
1012 		return this;
1013 
1014 	},
1015 
1016 	makePerspective: function ( fov, aspect, near, far ) {
1017 
1018 		var ymax = near * Math.tan( fov * Math.PI / 360 );
1019 		var ymin = - ymax;
1020 		var xmin = ymin * aspect;
1021 		var xmax = ymax * aspect;
1022 
1023 		return this.makeFrustum( xmin, xmax, ymin, ymax, near, far );
1024 
1025 	},
1026 
1027 	makeOrthographic: function ( left, right, top, bottom, near, far ) {
1028 
1029 		var te = this.elements;
1030 		var w = right - left;
1031 		var h = top - bottom;
1032 		var p = far - near;
1033 
1034 		var x = ( right + left ) / w;
1035 		var y = ( top + bottom ) / h;
1036 		var z = ( far + near ) / p;
1037 
1038 		te[0] = 2 / w; te[4] = 0;     te[8] = 0;      te[12] = -x;
1039 		te[1] = 0;     te[5] = 2 / h; te[9] = 0;      te[13] = -y;
1040 		te[2] = 0;     te[6] = 0;     te[10] = -2 / p; te[14] = -z;
1041 		te[3] = 0;     te[7] = 0;     te[11] = 0;      te[15] = 1;
1042 
1043 		return this;
1044 
1045 	},
1046 
1047 
1048 	clone: function () {
1049 
1050 		var te = this.elements;
1051 
1052 		return new THREE.Matrix4(
1053 
1054 			te[0], te[4], te[8], te[12],
1055 			te[1], te[5], te[9], te[13],
1056 			te[2], te[6], te[10], te[14],
1057 			te[3], te[7], te[11], te[15]
1058 
1059 		);
1060 
1061 	}
1062 
1063 };
1064 
1065 THREE.Matrix4.__v1 = new THREE.Vector3();
1066 THREE.Matrix4.__v2 = new THREE.Vector3();
1067 THREE.Matrix4.__v3 = new THREE.Vector3();
1068 
1069 THREE.Matrix4.__m1 = new THREE.Matrix4();
1070 THREE.Matrix4.__m2 = new THREE.Matrix4();
1071 

nike free rn new balance hombre baratas cinturones gucci ugg rebajas cinturon gucci ray ban baratas nike cortez peuterey mujer christian louboutin madrid mbt zapatos gafas ray ban baratas mbt ofertas air max blancas mbt barcelona nike air max 90 woolrich barcelona nike mujer botas ugg gafas de sol carrera aratas air max 2016 baratas oakley baratas nike air max 2016

mbt skor nike sverige louboutin skor hollister sverige polo ralph lauren skjorta woolrich jacka dam canada goose jacka woolrich jacka ray ban rea canada goose rea michael kors rea new balance skor ralph lauren skjorta new balance rea uggs sverige lacoste rea christian louboutin skor moncler jacka nike shox barbour jacka uggs rea