|
@@ -3,6 +3,7 @@
|
|
|
* @author kile / http://kile.stravaganza.org/
|
|
|
* @author philogb / http://blog.thejit.org/
|
|
|
* @author mikael emtinger / http://gomo.se/
|
|
|
+ * @author egraether / http://egraether.com/
|
|
|
*/
|
|
|
|
|
|
THREE.Vector3 = function ( x, y, z ) {
|
|
@@ -32,73 +33,56 @@ THREE.Vector3.prototype = {
|
|
|
|
|
|
copy : function ( v ) {
|
|
|
|
|
|
- this.set(
|
|
|
-
|
|
|
- v.x,
|
|
|
- v.y,
|
|
|
- v.z
|
|
|
-
|
|
|
- );
|
|
|
+ this.x = v.x;
|
|
|
+ this.y = v.y;
|
|
|
+ this.z = v.z;
|
|
|
|
|
|
return this;
|
|
|
|
|
|
},
|
|
|
|
|
|
+ clone : function () {
|
|
|
+
|
|
|
+ return new THREE.Vector3( this.x, this.y, this.z );
|
|
|
|
|
|
- add : function ( a, b ) {
|
|
|
+ },
|
|
|
|
|
|
- this.set(
|
|
|
|
|
|
- a.x + b.x,
|
|
|
- a.y + b.y,
|
|
|
- a.z + b.z
|
|
|
+ add : function ( v1, v2 ) {
|
|
|
|
|
|
- );
|
|
|
+ this.x = v1.x + v2.x;
|
|
|
+ this.y = v1.y + v2.y;
|
|
|
+ this.z = v1.z + v2.z;
|
|
|
|
|
|
return this;
|
|
|
|
|
|
},
|
|
|
|
|
|
-
|
|
|
addSelf : function ( v ) {
|
|
|
|
|
|
- this.set(
|
|
|
-
|
|
|
- this.x + v.x,
|
|
|
- this.y + v.y,
|
|
|
- this.z + v.z
|
|
|
-
|
|
|
- );
|
|
|
+ this.x += v.x;
|
|
|
+ this.y += v.y;
|
|
|
+ this.z += v.z;
|
|
|
|
|
|
return this;
|
|
|
|
|
|
},
|
|
|
|
|
|
-
|
|
|
addScalar : function ( s ) {
|
|
|
|
|
|
- this.set(
|
|
|
-
|
|
|
- this.x + s,
|
|
|
- this.y + s,
|
|
|
- this.z + s
|
|
|
-
|
|
|
- );
|
|
|
+ this.x += s;
|
|
|
+ this.y += s;
|
|
|
+ this.z += s;
|
|
|
|
|
|
return this;
|
|
|
|
|
|
},
|
|
|
|
|
|
+ sub : function ( v1, v2 ) {
|
|
|
|
|
|
- sub : function ( a, b ) {
|
|
|
-
|
|
|
- this.set(
|
|
|
-
|
|
|
- a.x - b.x,
|
|
|
- a.y - b.y,
|
|
|
- a.z - b.z
|
|
|
-
|
|
|
- );
|
|
|
+ this.x = v1.x - v2.x;
|
|
|
+ this.y = v1.y - v2.y;
|
|
|
+ this.z = v1.z - v2.z;
|
|
|
|
|
|
return this;
|
|
|
|
|
@@ -106,180 +90,151 @@ THREE.Vector3.prototype = {
|
|
|
|
|
|
subSelf : function ( v ) {
|
|
|
|
|
|
- this.set(
|
|
|
-
|
|
|
- this.x - v.x,
|
|
|
- this.y - v.y,
|
|
|
- this.z - v.z
|
|
|
-
|
|
|
- );
|
|
|
+ this.x -= v.x;
|
|
|
+ this.y -= v.y;
|
|
|
+ this.z -= v.z;
|
|
|
|
|
|
return this;
|
|
|
|
|
|
},
|
|
|
|
|
|
+ multiply : function ( a, b ) {
|
|
|
|
|
|
- cross : function ( a, b ) {
|
|
|
-
|
|
|
- this.set(
|
|
|
-
|
|
|
- a.y * b.z - a.z * b.y,
|
|
|
- a.z * b.x - a.x * b.z,
|
|
|
- a.x * b.y - a.y * b.x
|
|
|
-
|
|
|
- );
|
|
|
+ this.x = a.x * b.x;
|
|
|
+ this.y = a.y * b.y;
|
|
|
+ this.z = a.z * b.z;
|
|
|
|
|
|
return this;
|
|
|
|
|
|
},
|
|
|
|
|
|
- crossSelf : function ( v ) {
|
|
|
-
|
|
|
- var tx = this.x, ty = this.y, tz = this.z;
|
|
|
-
|
|
|
- this.set(
|
|
|
-
|
|
|
- ty * v.z - tz * v.y,
|
|
|
- tz * v.x - tx * v.z,
|
|
|
- tx * v.y - ty * v.x
|
|
|
+ multiplySelf : function ( v ) {
|
|
|
|
|
|
- );
|
|
|
+ this.x *= v.x;
|
|
|
+ this.y *= v.y;
|
|
|
+ this.z *= v.y;
|
|
|
|
|
|
return this;
|
|
|
|
|
|
},
|
|
|
|
|
|
- multiply : function ( a, b ) {
|
|
|
-
|
|
|
- this.set(
|
|
|
-
|
|
|
- a.x * b.x,
|
|
|
- a.y * b.y,
|
|
|
- a.z * b.z
|
|
|
+ multiplyScalar : function ( s ) {
|
|
|
|
|
|
- );
|
|
|
+ this.x *= s;
|
|
|
+ this.y *= s;
|
|
|
+ this.z *= s;
|
|
|
|
|
|
return this;
|
|
|
|
|
|
},
|
|
|
|
|
|
- multiplySelf : function ( v ) {
|
|
|
-
|
|
|
- this.set(
|
|
|
+ divideSelf : function ( v ) {
|
|
|
|
|
|
- this.x * v.x,
|
|
|
- this.y * v.y,
|
|
|
- this.z * v.z
|
|
|
+ return this.divide( this, v );
|
|
|
|
|
|
- );
|
|
|
+ },
|
|
|
|
|
|
- return this;
|
|
|
+ divideScalar : function ( s ) {
|
|
|
|
|
|
- },
|
|
|
+ if ( s ) {
|
|
|
|
|
|
- multiplyScalar : function ( s ) {
|
|
|
+ this.x /= s;
|
|
|
+ this.y /= s;
|
|
|
+ this.z /= s;
|
|
|
|
|
|
- this.set(
|
|
|
+ } else {
|
|
|
|
|
|
- this.x * s,
|
|
|
- this.y * s,
|
|
|
- this.z * s
|
|
|
+ this.set( 0, 0, 0 );
|
|
|
|
|
|
- );
|
|
|
+ }
|
|
|
|
|
|
return this;
|
|
|
|
|
|
},
|
|
|
|
|
|
- divideSelf : function ( v ) {
|
|
|
-
|
|
|
- this.set(
|
|
|
|
|
|
- this.x / v.x,
|
|
|
- this.y / v.y,
|
|
|
- this.z / v.z
|
|
|
+ negate : function() {
|
|
|
|
|
|
- );
|
|
|
-
|
|
|
- return this;
|
|
|
+ return this.multiplyScalar( -1 );
|
|
|
|
|
|
},
|
|
|
|
|
|
- divideScalar : function ( s ) {
|
|
|
+ dot : function ( v ) {
|
|
|
|
|
|
- this.set(
|
|
|
+ return this.x * v.x + this.y * v.y + this.z * v.z;
|
|
|
|
|
|
- this.x / s,
|
|
|
- this.y / s,
|
|
|
- this.z / s
|
|
|
+ },
|
|
|
|
|
|
- );
|
|
|
+ lengthSq : function () {
|
|
|
|
|
|
- return this;
|
|
|
+ return this.x * this.x + this.y * this.y + this.z * this.z;
|
|
|
|
|
|
},
|
|
|
|
|
|
- negate : function () {
|
|
|
+ length : function () {
|
|
|
|
|
|
- this.set(
|
|
|
+ return Math.sqrt( this.lengthSq() );
|
|
|
|
|
|
- - this.x,
|
|
|
- - this.y,
|
|
|
- - this.z
|
|
|
+ },
|
|
|
|
|
|
- );
|
|
|
+ lengthManhattan : function () {
|
|
|
|
|
|
- return this;
|
|
|
+ // correct version
|
|
|
+ // return Math.abs( this.x ) + Math.abs( this.y ) + Math.abs( this.z );
|
|
|
+
|
|
|
+ return this.x + this.y + this.z;
|
|
|
|
|
|
},
|
|
|
|
|
|
- dot : function ( v ) {
|
|
|
+ normalize : function () {
|
|
|
|
|
|
- return this.x * v.x + this.y * v.y + this.z * v.z;
|
|
|
+ return this.divideScalar( this.length() );
|
|
|
|
|
|
},
|
|
|
|
|
|
- distanceTo : function ( v ) {
|
|
|
+ setLength : function ( l ) {
|
|
|
|
|
|
- return Math.sqrt( this.distanceToSquared( v ) );
|
|
|
+ return this.normalize().multiplyScalar( l );
|
|
|
|
|
|
},
|
|
|
|
|
|
- distanceToSquared : function ( v ) {
|
|
|
|
|
|
- var dx = this.x - v.x, dy = this.y - v.y, dz = this.z - v.z;
|
|
|
- return dx * dx + dy * dy + dz * dz;
|
|
|
+ cross : function ( a, b ) {
|
|
|
|
|
|
- },
|
|
|
+ this.x = a.y * b.z - a.z * b.y;
|
|
|
+ this.y = a.z * b.x - a.x * b.z;
|
|
|
+ this.z = a.x * b.y - a.y * b.x;
|
|
|
|
|
|
- length : function () {
|
|
|
-
|
|
|
- return Math.sqrt( this.lengthSq() );
|
|
|
+ return this;
|
|
|
|
|
|
},
|
|
|
|
|
|
- lengthSq : function () {
|
|
|
-
|
|
|
- return this.x * this.x + this.y * this.y + this.z * this.z;
|
|
|
+ crossSelf : function ( v ) {
|
|
|
|
|
|
- },
|
|
|
+ return this.set(
|
|
|
|
|
|
- lengthManhattan : function () {
|
|
|
+ this.y * v.z - this.z * v.y,
|
|
|
+ this.z * v.x - this.x * v.z,
|
|
|
+ this.x * v.y - this.y * v.x
|
|
|
|
|
|
- return this.x + this.y + this.z;
|
|
|
+ );
|
|
|
|
|
|
},
|
|
|
|
|
|
- normalize : function () {
|
|
|
|
|
|
- var l = this.length();
|
|
|
+ distanceTo : function ( v ) {
|
|
|
|
|
|
- l > 0 ? this.multiplyScalar( 1 / l ) : this.set( 0, 0, 0 );
|
|
|
+ return Math.sqrt( this.distanceToSquared( v ) );
|
|
|
|
|
|
- return this;
|
|
|
+ },
|
|
|
+
|
|
|
+ distanceToSquared : function ( v ) {
|
|
|
+
|
|
|
+ return new THREE.Vector3().sub( this, v ).lengthSq();
|
|
|
|
|
|
},
|
|
|
|
|
|
+
|
|
|
setPositionFromMatrix : function ( m ) {
|
|
|
|
|
|
this.x = m.n14;
|
|
@@ -308,22 +263,9 @@ THREE.Vector3.prototype = {
|
|
|
|
|
|
},
|
|
|
|
|
|
- setLength : function ( l ) {
|
|
|
-
|
|
|
- return this.normalize().multiplyScalar( l );
|
|
|
-
|
|
|
- },
|
|
|
-
|
|
|
isZero : function () {
|
|
|
|
|
|
- var almostZero = 0.0001;
|
|
|
- return ( Math.abs( this.x ) < almostZero ) && ( Math.abs( this.y ) < almostZero ) && ( Math.abs( this.z ) < almostZero );
|
|
|
-
|
|
|
- },
|
|
|
-
|
|
|
- clone : function () {
|
|
|
-
|
|
|
- return new THREE.Vector3( this.x, this.y, this.z );
|
|
|
+ return ( this.lengthSq() < 0.0001 /* almostZero */ );
|
|
|
|
|
|
}
|
|
|
|