1 /**
2 * @author supereggbert / http://www.paulbrunt.co.uk/
3 * @author philogb / http://blog.thejit.org/
4 * @author mikael emtinger / http://gomo.se/
5 * @author egraether / http://egraether.com/
6 * @author WestLangley / http://github.com/WestLangley
7 */
8
9 /**@constructor*/
10 THREE.Vector4 = function ( x, y, z, w ) {
11
12 this.x = x || 0;
13 this.y = y || 0;
14 this.z = z || 0;
15 this.w = ( w !== undefined ) ? w : 1;
16
17 };
18
19 THREE.Vector4.prototype = {
20
21 constructor: THREE.Vector4,
22
23 set: function ( x, y, z, w ) {
24
25 this.x = x;
26 this.y = y;
27 this.z = z;
28 this.w = w;
29
30 return this;
31
32 },
33
34 copy: function ( v ) {
35
36 this.x = v.x;
37 this.y = v.y;
38 this.z = v.z;
39 this.w = ( v.w !== undefined ) ? v.w : 1;
40
41 return this;
42
43 },
44
45 add: function ( a, b ) {
46
47 this.x = a.x + b.x;
48 this.y = a.y + b.y;
49 this.z = a.z + b.z;
50 this.w = a.w + b.w;
51
52 return this;
53
54 },
55
56 addSelf: function ( v ) {
57
58 this.x += v.x;
59 this.y += v.y;
60 this.z += v.z;
61 this.w += v.w;
62
63 return this;
64
65 },
66
67 sub: function ( a, b ) {
68
69 this.x = a.x - b.x;
70 this.y = a.y - b.y;
71 this.z = a.z - b.z;
72 this.w = a.w - b.w;
73
74 return this;
75
76 },
77
78 subSelf: function ( v ) {
79
80 this.x -= v.x;
81 this.y -= v.y;
82 this.z -= v.z;
83 this.w -= v.w;
84
85 return this;
86
87 },
88
89 multiplyScalar: function ( s ) {
90
91 this.x *= s;
92 this.y *= s;
93 this.z *= s;
94 this.w *= s;
95
96 return this;
97
98 },
99
100 divideScalar: function ( s ) {
101
102 if ( s ) {
103
104 this.x /= s;
105 this.y /= s;
106 this.z /= s;
107 this.w /= s;
108
109 } else {
110
111 this.x = 0;
112 this.y = 0;
113 this.z = 0;
114 this.w = 1;
115
116 }
117
118 return this;
119
120 },
121
122
123 negate: function() {
124
125 return this.multiplyScalar( -1 );
126
127 },
128
129 dot: function ( v ) {
130
131 return this.x * v.x + this.y * v.y + this.z * v.z + this.w * v.w;
132
133 },
134
135 lengthSq: function () {
136
137 return this.dot( this );
138
139 },
140
141 length: function () {
142
143 return Math.sqrt( this.lengthSq() );
144
145 },
146
147 lengthManhattan: function () {
148
149 return Math.abs( this.x ) + Math.abs( this.y ) + Math.abs( this.z ) + Math.abs( this.w );
150
151 },
152
153 normalize: function () {
154
155 return this.divideScalar( this.length() );
156
157 },
158
159 setLength: function ( l ) {
160
161 return this.normalize().multiplyScalar( l );
162
163 },
164
165 lerpSelf: function ( v, alpha ) {
166
167 this.x += ( v.x - this.x ) * alpha;
168 this.y += ( v.y - this.y ) * alpha;
169 this.z += ( v.z - this.z ) * alpha;
170 this.w += ( v.w - this.w ) * alpha;
171
172 return this;
173
174 },
175
176 clone: function () {
177
178 return new THREE.Vector4( this.x, this.y, this.z, this.w );
179
180 },
181
182 setAxisAngleFromQuaternion: function ( q ) {
183
184 // http://www.euclideanspace.com/maths/geometry/rotations/conversions/quaternionToAngle/index.htm
185
186 // q is assumed to be normalized
187
188 this.w = 2 * Math.acos( q.w );
189
190 var s = Math.sqrt( 1 - q.w * q.w );
191
192 if ( s < 0.0001 ) {
193
194 this.x = 1;
195 this.y = 0;
196 this.z = 0;
197
198 } else {
199
200 this.x = q.x / s;
201 this.y = q.y / s;
202 this.z = q.z / s;
203
204 }
205
206 return this;
207
208 },
209
210 setAxisAngleFromRotationMatrix: function ( m ) {
211
212 // http://www.euclideanspace.com/maths/geometry/rotations/conversions/matrixToAngle/index.htm
213
214 // assumes the upper 3x3 of m is a pure rotation matrix (i.e, unscaled)
215
216 var angle, x, y, z, // variables for result
217 epsilon = 0.01, // margin to allow for rounding errors
218 epsilon2 = 0.1, // margin to distinguish between 0 and 180 degrees
219
220 te = m.elements,
221
222 m11 = te[0], m12 = te[4], m13 = te[8],
223 m21 = te[1], m22 = te[5], m23 = te[9],
224 m31 = te[2], m32 = te[6], m33 = te[10];
225
226 if ( ( Math.abs( m12 - m21 ) < epsilon )
227 && ( Math.abs( m13 - m31 ) < epsilon )
228 && ( Math.abs( m23 - m32 ) < epsilon ) ) {
229
230 // singularity found
231 // first check for identity matrix which must have +1 for all terms
232 // in leading diagonal and zero in other terms
233
234 if ( ( Math.abs( m12 + m21 ) < epsilon2 )
235 && ( Math.abs( m13 + m31 ) < epsilon2 )
236 && ( Math.abs( m23 + m32 ) < epsilon2 )
237 && ( Math.abs( m11 + m22 + m33 - 3 ) < epsilon2 ) ) {
238
239 // this singularity is identity matrix so angle = 0
240
241 this.set( 1, 0, 0, 0 );
242
243 return this; // zero angle, arbitrary axis
244
245 }
246
247 // otherwise this singularity is angle = 180
248
249 angle = Math.PI;
250
251 var xx = ( m11 + 1 ) / 2;
252 var yy = ( m22 + 1 ) / 2;
253 var zz = ( m33 + 1 ) / 2;
254 var xy = ( m12 + m21 ) / 4;
255 var xz = ( m13 + m31 ) / 4;
256 var yz = ( m23 + m32 ) / 4;
257
258 if ( ( xx > yy ) && ( xx > zz ) ) { // m11 is the largest diagonal term
259
260 if ( xx < epsilon ) {
261
262 x = 0;
263 y = 0.707106781;
264 z = 0.707106781;
265
266 } else {
267
268 x = Math.sqrt( xx );
269 y = xy / x;
270 z = xz / x;
271
272 }
273
274 } else if ( yy > zz ) { // m22 is the largest diagonal term
275
276 if ( yy < epsilon ) {
277
278 x = 0.707106781;
279 y = 0;
280 z = 0.707106781;
281
282 } else {
283
284 y = Math.sqrt( yy );
285 x = xy / y;
286 z = yz / y;
287
288 }
289
290 } else { // m33 is the largest diagonal term so base result on this
291
292 if ( zz < epsilon ) {
293
294 x = 0.707106781;
295 y = 0.707106781;
296 z = 0;
297
298 } else {
299
300 z = Math.sqrt( zz );
301 x = xz / z;
302 y = yz / z;
303
304 }
305
306 }
307
308 this.set( x, y, z, angle );
309
310 return this; // return 180 deg rotation
311
312 }
313
314 // as we have reached here there are no singularities so we can handle normally
315
316 var s = Math.sqrt( ( m32 - m23 ) * ( m32 - m23 )
317 + ( m13 - m31 ) * ( m13 - m31 )
318 + ( m21 - m12 ) * ( m21 - m12 ) ); // used to normalize
319
320 if ( Math.abs( s ) < 0.001 ) s = 1;
321
322 // prevent divide by zero, should not happen if matrix is orthogonal and should be
323 // caught by singularity test above, but I've left it in just in case
324
325 this.x = ( m32 - m23 ) / s;
326 this.y = ( m13 - m31 ) / s;
327 this.z = ( m21 - m12 ) / s;
328 this.w = Math.acos( ( m11 + m22 + m33 - 1 ) / 2 );
329
330 return this;
331
332 }
333
334 };
335
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