@@ -23,6 +23,15 @@ var Vector3 = new Class({
2323 }
2424 } ,
2525
26+ up : function ( )
27+ {
28+ this . x = 0 ;
29+ this . y = 1 ;
30+ this . z = 0 ;
31+
32+ return this ;
33+ } ,
34+
2635 clone : function ( )
2736 {
2837 return new Vector3 ( this . x , this . y , this . z ) ;
@@ -258,6 +267,25 @@ var Vector3 = new Class({
258267 return this ;
259268 } ,
260269
270+ transformCoordinates : function ( mat )
271+ {
272+ var x = this . x ;
273+ var y = this . y ;
274+ var z = this . z ;
275+ var m = mat . val ;
276+
277+ var tx = ( x * m [ 0 ] ) + ( y * m [ 4 ] ) + ( z * m [ 8 ] ) + m [ 12 ] ;
278+ var ty = ( x * m [ 1 ] ) + ( y * m [ 5 ] ) + ( z * m [ 9 ] ) + m [ 13 ] ;
279+ var tz = ( x * m [ 2 ] ) + ( y * m [ 6 ] ) + ( z * m [ 10 ] ) + m [ 14 ] ;
280+ var tw = ( x * m [ 3 ] ) + ( y * m [ 7 ] ) + ( z * m [ 11 ] ) + m [ 15 ] ;
281+
282+ this . x = tx / tw ;
283+ this . y = ty / tw ;
284+ this . z = tz / tw ;
285+
286+ return this ;
287+ } ,
288+
261289 transformQuat : function ( q )
262290 {
263291 // benchmarks: http://jsperf.com/quaternion-transform-vec3-implementations
@@ -368,12 +396,76 @@ var Vector3 = new Class({
368396
369397} ) ;
370398
371- Vector3 . prototype . sub = Vector3 . prototype . subtract ;
372- Vector3 . prototype . mul = Vector3 . prototype . multiply ;
373- Vector3 . prototype . div = Vector3 . prototype . divide ;
374- Vector3 . prototype . dist = Vector3 . prototype . distance ;
375- Vector3 . prototype . distSq = Vector3 . prototype . distanceSq ;
376- Vector3 . prototype . len = Vector3 . prototype . length ;
377- Vector3 . prototype . lenSq = Vector3 . prototype . lengthSq ;
399+ /*
400+ Vector3.Zero = function ()
401+ {
402+ return new Vector3(0, 0, 0);
403+ };
404+
405+ Vector3.Up = function ()
406+ {
407+ return new Vector3(0, 1.0, 0);
408+ };
409+
410+ Vector3.Copy = function (source)
411+ {
412+ return new Vector3(source.x, source.y, source.z);
413+ };
414+
415+ Vector3.TransformCoordinates = function (vector, transformation)
416+ {
417+ var x = (vector.x * transformation.m[0]) + (vector.y * transformation.m[4]) + (vector.z * transformation.m[8]) + transformation.m[12];
418+ var y = (vector.x * transformation.m[1]) + (vector.y * transformation.m[5]) + (vector.z * transformation.m[9]) + transformation.m[13];
419+ var z = (vector.x * transformation.m[2]) + (vector.y * transformation.m[6]) + (vector.z * transformation.m[10]) + transformation.m[14];
420+ var w = (vector.x * transformation.m[3]) + (vector.y * transformation.m[7]) + (vector.z * transformation.m[11]) + transformation.m[15];
421+
422+ return new Vector3(x / w, y / w, z / w);
423+ };
424+
425+ Vector3.TransformNormal = function (vector, transformation)
426+ {
427+ var x = (vector.x * transformation.m[0]) + (vector.y * transformation.m[4]) + (vector.z * transformation.m[8]);
428+ var y = (vector.x * transformation.m[1]) + (vector.y * transformation.m[5]) + (vector.z * transformation.m[9]);
429+ var z = (vector.x * transformation.m[2]) + (vector.y * transformation.m[6]) + (vector.z * transformation.m[10]);
430+
431+ return new Vector3(x, y, z);
432+ };
433+
434+ Vector3.Dot = function (left, right)
435+ {
436+ return (left.x * right.x + left.y * right.y + left.z * right.z);
437+ };
438+
439+ Vector3.Cross = function (left, right)
440+ {
441+ var x = left.y * right.z - left.z * right.y;
442+ var y = left.z * right.x - left.x * right.z;
443+ var z = left.x * right.y - left.y * right.x;
444+
445+ return new Vector3(x, y, z);
446+ };
447+
448+ Vector3.Normalize = function (vector)
449+ {
450+ var newVector = Vector3.Copy(vector);
451+ newVector.normalize();
452+
453+ return newVector;
454+ };
455+
456+ Vector3.Distance = function (value1, value2)
457+ {
458+ return Math.sqrt(Vector3.DistanceSquared(value1, value2));
459+ };
460+
461+ Vector3.DistanceSquared = function (value1, value2)
462+ {
463+ var x = value1.x - value2.x;
464+ var y = value1.y - value2.y;
465+ var z = value1.z - value2.z;
466+
467+ return (x * x) + (y * y) + (z * z);
468+ };
469+ */
378470
379471module . exports = Vector3 ;
0 commit comments