1 /**
  2  * @author mikael emtinger / http://gomo.se/
  3  * @author alteredq / http://alteredqualia.com/
  4  * @author WestLangley / http://github.com/WestLangley
  5  */
  6 
  7 /**@constructor*/
  8 THREE.Quaternion = function( x, y, z, w ) {
  9 
 10 	this.x = x || 0;
 11 	this.y = y || 0;
 12 	this.z = z || 0;
 13 	this.w = ( w !== undefined ) ? w : 1;
 14 
 15 };
 16 
 17 THREE.Quaternion.prototype = {
 18 
 19 	constructor: THREE.Quaternion,
 20 
 21 	set: function ( x, y, z, w ) {
 22 
 23 		this.x = x;
 24 		this.y = y;
 25 		this.z = z;
 26 		this.w = w;
 27 
 28 		return this;
 29 
 30 	},
 31 
 32 	copy: function ( q ) {
 33 
 34 		this.x = q.x;
 35 		this.y = q.y;
 36 		this.z = q.z;
 37 		this.w = q.w;
 38 
 39 		return this;
 40 
 41 	},
 42 
 43 	setFromEuler: function ( v, order ) {
 44 
 45 		// http://www.mathworks.com/matlabcentral/fileexchange/
 46 		// 	20696-function-to-convert-between-dcm-euler-angles-quaternions-and-euler-vectors/
 47 		//	content/SpinCalc.m
 48 	
 49 		var c1 = Math.cos( v.x / 2 );
 50 		var c2 = Math.cos( v.y / 2 );
 51 		var c3 = Math.cos( v.z / 2 );
 52 		var s1 = Math.sin( v.x / 2 );
 53 		var s2 = Math.sin( v.y / 2 );
 54 		var s3 = Math.sin( v.z / 2 );
 55 
 56 		if ( order === undefined || order === 'XYZ' ) {
 57 
 58 			this.x = s1 * c2 * c3 + c1 * s2 * s3;
 59 			this.y = c1 * s2 * c3 - s1 * c2 * s3;
 60 			this.z = c1 * c2 * s3 + s1 * s2 * c3;
 61 			this.w = c1 * c2 * c3 - s1 * s2 * s3;
 62 
 63 		} else if ( order === 'YXZ' ) {
 64 	
 65 			this.x = s1 * c2 * c3 + c1 * s2 * s3;
 66 			this.y = c1 * s2 * c3 - s1 * c2 * s3;
 67 			this.z = c1 * c2 * s3 - s1 * s2 * c3;
 68 			this.w = c1 * c2 * c3 + s1 * s2 * s3;
 69 				
 70 		} else if ( order === 'ZXY' ) {
 71 	
 72 			this.x = s1 * c2 * c3 - c1 * s2 * s3;
 73 			this.y = c1 * s2 * c3 + s1 * c2 * s3;
 74 			this.z = c1 * c2 * s3 + s1 * s2 * c3;
 75 			this.w = c1 * c2 * c3 - s1 * s2 * s3;
 76 				
 77 		} else if ( order === 'ZYX' ) {
 78 	
 79 			this.x = s1 * c2 * c3 - c1 * s2 * s3;
 80 			this.y = c1 * s2 * c3 + s1 * c2 * s3;
 81 			this.z = c1 * c2 * s3 - s1 * s2 * c3;
 82 			this.w = c1 * c2 * c3 + s1 * s2 * s3;
 83 				
 84 		} else if ( order === 'YZX' ) {
 85 			
 86 			this.x = s1 * c2 * c3 + c1 * s2 * s3;
 87 			this.y = c1 * s2 * c3 + s1 * c2 * s3;
 88 			this.z = c1 * c2 * s3 - s1 * s2 * c3;
 89 			this.w = c1 * c2 * c3 - s1 * s2 * s3;
 90 				
 91 		} else if ( order === 'XZY' ) {
 92 			
 93 			this.x = s1 * c2 * c3 - c1 * s2 * s3;
 94 			this.y = c1 * s2 * c3 - s1 * c2 * s3;
 95 			this.z = c1 * c2 * s3 + s1 * s2 * c3;
 96 			this.w = c1 * c2 * c3 + s1 * s2 * s3;
 97 				
 98 		}
 99 		
100 		return this;
101 
102 	},
103 
104 	setFromAxisAngle: function ( axis, angle ) {
105 
106 		// from http://www.euclideanspace.com/maths/geometry/rotations/conversions/angleToQuaternion/index.htm
107 		// axis have to be normalized
108 
109 		var halfAngle = angle / 2,
110 			s = Math.sin( halfAngle );
111 
112 		this.x = axis.x * s;
113 		this.y = axis.y * s;
114 		this.z = axis.z * s;
115 		this.w = Math.cos( halfAngle );
116 
117 		return this;
118 
119 	},
120 
121 	setFromRotationMatrix: function ( m ) {
122 
123 		// http://www.euclideanspace.com/maths/geometry/rotations/conversions/matrixToQuaternion/index.htm
124 		
125 		// assumes the upper 3x3 of m is a pure rotation matrix (i.e, unscaled)
126 		
127 		var te = m.elements,
128 			
129 			m11 = te[0], m12 = te[4], m13 = te[8],
130 			m21 = te[1], m22 = te[5], m23 = te[9],
131 			m31 = te[2], m32 = te[6], m33 = te[10],
132 			
133 			trace = m11 + m22 + m33,
134 			s;
135 		
136 		if( trace > 0 ) {
137 		
138 			s = 0.5 / Math.sqrt( trace + 1.0 );
139 			
140 			this.w = 0.25 / s;
141 			this.x = ( m32 - m23 ) * s;
142 			this.y = ( m13 - m31 ) * s;
143 			this.z = ( m21 - m12 ) * s;
144 		
145 		} else if ( m11 > m22 && m11 > m33 ) {
146 		
147 			s = 2.0 * Math.sqrt( 1.0 + m11 - m22 - m33 );
148 			
149 			this.w = (m32 - m23 ) / s;
150 			this.x = 0.25 * s;
151 			this.y = (m12 + m21 ) / s;
152 			this.z = (m13 + m31 ) / s;
153 		
154 		} else if (m22 > m33) {
155 		
156 			s = 2.0 * Math.sqrt( 1.0 + m22 - m11 - m33 );
157 			
158 			this.w = (m13 - m31 ) / s;
159 			this.x = (m12 + m21 ) / s;
160 			this.y = 0.25 * s;
161 			this.z = (m23 + m32 ) / s;
162 		
163 		} else {
164 		
165 			s = 2.0 * Math.sqrt( 1.0 + m33 - m11 - m22 );
166 			
167 			this.w = ( m21 - m12 ) / s;
168 			this.x = ( m13 + m31 ) / s;
169 			this.y = ( m23 + m32 ) / s;
170 			this.z = 0.25 * s;
171 		
172 		}
173 	
174 		return this;
175 
176 	},
177 
178 	inverse: function () {
179 
180 		this.conjugate().normalize();
181 
182 		return this;
183 
184 	},
185 
186 	conjugate: function () {
187 
188 		this.x *= -1;
189 		this.y *= -1;
190 		this.z *= -1;
191 
192 		return this;
193 
194 	},
195 
196 	length: function () {
197 
198 		return Math.sqrt( this.x * this.x + this.y * this.y + this.z * this.z + this.w * this.w );
199 
200 	},
201 
202 	normalize: function () {
203 
204 		var l = Math.sqrt( this.x * this.x + this.y * this.y + this.z * this.z + this.w * this.w );
205 
206 		if ( l === 0 ) {
207 
208 			this.x = 0;
209 			this.y = 0;
210 			this.z = 0;
211 			this.w = 1;
212 
213 		} else {
214 
215 			l = 1 / l;
216 
217 			this.x = this.x * l;
218 			this.y = this.y * l;
219 			this.z = this.z * l;
220 			this.w = this.w * l;
221 
222 		}
223 
224 		return this;
225 
226 	},
227 
228 	multiply: function ( a, b ) {
229 
230 		// from http://www.euclideanspace.com/maths/algebra/realNormedAlgebra/quaternions/code/index.htm
231 		var qax = a.x, qay = a.y, qaz = a.z, qaw = a.w,
232 		qbx = b.x, qby = b.y, qbz = b.z, qbw = b.w;
233 
234 		this.x =  qax * qbw + qay * qbz - qaz * qby + qaw * qbx;
235 		this.y = -qax * qbz + qay * qbw + qaz * qbx + qaw * qby;
236 		this.z =  qax * qby - qay * qbx + qaz * qbw + qaw * qbz;
237 		this.w = -qax * qbx - qay * qby - qaz * qbz + qaw * qbw;
238 
239 		return this;
240 
241 	},
242 
243 	multiplySelf: function ( b ) {
244 
245 		var qax = this.x, qay = this.y, qaz = this.z, qaw = this.w,
246 		qbx = b.x, qby = b.y, qbz = b.z, qbw = b.w;
247 
248 		this.x = qax * qbw + qaw * qbx + qay * qbz - qaz * qby;
249 		this.y = qay * qbw + qaw * qby + qaz * qbx - qax * qbz;
250 		this.z = qaz * qbw + qaw * qbz + qax * qby - qay * qbx;
251 		this.w = qaw * qbw - qax * qbx - qay * qby - qaz * qbz;
252 
253 		return this;
254 
255 	},
256 
257 	multiplyVector3: function ( vector, dest ) {
258 
259 		if ( !dest ) { dest = vector; }
260 
261 		var x    = vector.x,  y  = vector.y,  z  = vector.z,
262 			qx   = this.x, qy = this.y, qz = this.z, qw = this.w;
263 
264 		// calculate quat * vector
265 
266 		var ix =  qw * x + qy * z - qz * y,
267 			iy =  qw * y + qz * x - qx * z,
268 			iz =  qw * z + qx * y - qy * x,
269 			iw = -qx * x - qy * y - qz * z;
270 
271 		// calculate result * inverse quat
272 
273 		dest.x = ix * qw + iw * -qx + iy * -qz - iz * -qy;
274 		dest.y = iy * qw + iw * -qy + iz * -qx - ix * -qz;
275 		dest.z = iz * qw + iw * -qz + ix * -qy - iy * -qx;
276 
277 		return dest;
278 
279 	},
280 
281 	slerpSelf: function ( qb, t ) {
282 
283 		var x = this.x, y = this.y, z = this.z, w = this.w;
284 
285 		// http://www.euclideanspace.com/maths/algebra/realNormedAlgebra/quaternions/slerp/
286 
287 		var cosHalfTheta = w * qb.w + x * qb.x + y * qb.y + z * qb.z;
288 
289 		if ( cosHalfTheta < 0 ) {
290 
291 			this.w = -qb.w;
292 			this.x = -qb.x;
293 			this.y = -qb.y;
294 			this.z = -qb.z;
295 
296 			cosHalfTheta = -cosHalfTheta;
297 
298 		} else {
299 
300 			this.copy( qb );
301 
302 		}
303 
304 		if ( cosHalfTheta >= 1.0 ) {
305 
306 			this.w = w;
307 			this.x = x;
308 			this.y = y;
309 			this.z = z;
310 
311 			return this;
312 
313 		}
314 
315 		var halfTheta = Math.acos( cosHalfTheta );
316 		var sinHalfTheta = Math.sqrt( 1.0 - cosHalfTheta * cosHalfTheta );
317 
318 		if ( Math.abs( sinHalfTheta ) < 0.001 ) {
319 
320 			this.w = 0.5 * ( w + this.w );
321 			this.x = 0.5 * ( x + this.x );
322 			this.y = 0.5 * ( y + this.y );
323 			this.z = 0.5 * ( z + this.z );
324 
325 			return this;
326 
327 		}
328 
329 		var ratioA = Math.sin( ( 1 - t ) * halfTheta ) / sinHalfTheta,
330 		ratioB = Math.sin( t * halfTheta ) / sinHalfTheta;
331 
332 		this.w = ( w * ratioA + this.w * ratioB );
333 		this.x = ( x * ratioA + this.x * ratioB );
334 		this.y = ( y * ratioA + this.y * ratioB );
335 		this.z = ( z * ratioA + this.z * ratioB );
336 
337 		return this;
338 
339 	},
340 
341 	clone: function () {
342 
343 		return new THREE.Quaternion( this.x, this.y, this.z, this.w );
344 
345 	}
346 
347 }
348 
349 THREE.Quaternion.slerp = function ( qa, qb, qm, t ) {
350 
351 	// http://www.euclideanspace.com/maths/algebra/realNormedAlgebra/quaternions/slerp/
352 
353 	var cosHalfTheta = qa.w * qb.w + qa.x * qb.x + qa.y * qb.y + qa.z * qb.z;
354 
355 	if ( cosHalfTheta < 0 ) {
356 
357 		qm.w = -qb.w;
358 		qm.x = -qb.x;
359 		qm.y = -qb.y;
360 		qm.z = -qb.z;
361 
362 		cosHalfTheta = -cosHalfTheta;
363 
364 	} else {
365 
366 		qm.copy( qb );
367 
368 	}
369 
370 	if ( Math.abs( cosHalfTheta ) >= 1.0 ) {
371 
372 		qm.w = qa.w;
373 		qm.x = qa.x;
374 		qm.y = qa.y;
375 		qm.z = qa.z;
376 
377 		return qm;
378 
379 	}
380 
381 	var halfTheta = Math.acos( cosHalfTheta );
382 	var sinHalfTheta = Math.sqrt( 1.0 - cosHalfTheta * cosHalfTheta );
383 
384 	if ( Math.abs( sinHalfTheta ) < 0.001 ) {
385 
386 		qm.w = 0.5 * ( qa.w + qm.w );
387 		qm.x = 0.5 * ( qa.x + qm.x );
388 		qm.y = 0.5 * ( qa.y + qm.y );
389 		qm.z = 0.5 * ( qa.z + qm.z );
390 
391 		return qm;
392 
393 	}
394 
395 	var ratioA = Math.sin( ( 1 - t ) * halfTheta ) / sinHalfTheta;
396 	var ratioB = Math.sin( t * halfTheta ) / sinHalfTheta;
397 
398 	qm.w = ( qa.w * ratioA + qm.w * ratioB );
399 	qm.x = ( qa.x * ratioA + qm.x * ratioB );
400 	qm.y = ( qa.y * ratioA + qm.y * ratioB );
401 	qm.z = ( qa.z * ratioA + qm.z * ratioB );
402 
403 	return qm;
404 
405 }
406 

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