提交 b6e90711 编写于 作者: B Ben Houston (Clara.io) 提交者: Mr.doob

Math tightening (noticed with doing the Vector3.array/offset stuff)

* tighten up Vector4.

* tighten up Vector3.

* tighten up Vector2.

* add missing "return this" to Ray3.lookAt().

* tighten up Quaternion.

* missing "return this" on Spherical.

* missing "return this" on Euler.  Tighting up code.
上级 43fe77dc
......@@ -235,10 +235,10 @@ THREE.Euler.prototype = {
return function ( q, order, update ) {
if ( matrix === undefined ) matrix = new THREE.Matrix4();
matrix.makeRotationFromQuaternion( q );
this.setFromRotationMatrix( matrix, order, update );
return this;
return this.setFromRotationMatrix( matrix, order, update );
};
......@@ -259,7 +259,8 @@ THREE.Euler.prototype = {
return function ( newOrder ) {
q.setFromEuler( this );
this.setFromQuaternion( q, newOrder );
return this.setFromQuaternion( q, newOrder );
};
......
......@@ -292,9 +292,7 @@ THREE.Quaternion.prototype = {
this._z = v1.z;
this._w = r;
this.normalize();
return this;
return this.normalize();
};
......@@ -302,9 +300,7 @@ THREE.Quaternion.prototype = {
inverse: function () {
this.conjugate().normalize();
return this;
return this.conjugate().normalize();
},
......
......@@ -49,6 +49,8 @@ THREE.Ray.prototype = {
this.direction.copy( v ).sub( this.origin ).normalize();
return this;
},
recast: function () {
......
......@@ -28,6 +28,8 @@ THREE.Spherical.prototype = {
this.phi = phi;
this.theta = theta;
return this;
},
clone: function () {
......@@ -52,6 +54,8 @@ THREE.Spherical.prototype = {
var EPS = 0.000001;
this.phi = Math.max( EPS, Math.min( Math.PI - EPS, this.phi ) );
return this;
},
setFromVector3: function( vec3 ) {
......
......@@ -289,9 +289,7 @@ THREE.Vector2.prototype = {
var length = this.length();
this.multiplyScalar( Math.max( min, Math.min( max, length ) ) / length );
return this;
return this.multiplyScalar( Math.max( min, Math.min( max, length ) ) / length );
},
......@@ -412,9 +410,7 @@ THREE.Vector2.prototype = {
lerpVectors: function ( v1, v2, alpha ) {
this.subVectors( v2, v1 ).multiplyScalar( alpha ).add( v1 );
return this;
return this.subVectors( v2, v1 ).multiplyScalar( alpha ).add( v1 );
},
......
......@@ -250,9 +250,7 @@ THREE.Vector3.prototype = {
if ( quaternion === undefined ) quaternion = new THREE.Quaternion();
this.applyQuaternion( quaternion.setFromEuler( euler ) );
return this;
return this.applyQuaternion( quaternion.setFromEuler( euler ) );
};
......@@ -266,9 +264,7 @@ THREE.Vector3.prototype = {
if ( quaternion === undefined ) quaternion = new THREE.Quaternion();
this.applyQuaternion( quaternion.setFromAxisAngle( axis, angle ) );
return this;
return this.applyQuaternion( quaternion.setFromAxisAngle( axis, angle ) );
};
......@@ -276,10 +272,7 @@ THREE.Vector3.prototype = {
applyMatrix3: function ( m ) {
var x = this.x;
var y = this.y;
var z = this.z;
var x = this.x, y = this.y, z = this.z;
var e = m.elements;
this.x = e[ 0 ] * x + e[ 3 ] * y + e[ 6 ] * z;
......@@ -295,7 +288,6 @@ THREE.Vector3.prototype = {
// input: THREE.Matrix4 affine matrix
var x = this.x, y = this.y, z = this.z;
var e = m.elements;
this.x = e[ 0 ] * x + e[ 4 ] * y + e[ 8 ] * z + e[ 12 ];
......@@ -311,7 +303,6 @@ THREE.Vector3.prototype = {
// input: THREE.Matrix4 projection matrix
var x = this.x, y = this.y, z = this.z;
var e = m.elements;
var d = 1 / ( e[ 3 ] * x + e[ 7 ] * y + e[ 11 ] * z + e[ 15 ] ); // perspective divide
......@@ -325,14 +316,8 @@ THREE.Vector3.prototype = {
applyQuaternion: function ( q ) {
var x = this.x;
var y = this.y;
var z = this.z;
var qx = q.x;
var qy = q.y;
var qz = q.z;
var qw = q.w;
var x = this.x, y = this.y, z = this.z;
var qx = q.x, qy = q.y, qz = q.z, qw = q.w;
// calculate quat * vector
......@@ -387,16 +372,13 @@ THREE.Vector3.prototype = {
// vector interpreted as a direction
var x = this.x, y = this.y, z = this.z;
var e = m.elements;
this.x = e[ 0 ] * x + e[ 4 ] * y + e[ 8 ] * z;
this.y = e[ 1 ] * x + e[ 5 ] * y + e[ 9 ] * z;
this.z = e[ 2 ] * x + e[ 6 ] * y + e[ 10 ] * z;
this.normalize();
return this;
return this.normalize();
},
......@@ -474,9 +456,7 @@ THREE.Vector3.prototype = {
var length = this.length();
this.multiplyScalar( Math.max( min, Math.min( max, length ) ) / length );
return this;
return this.multiplyScalar( Math.max( min, Math.min( max, length ) ) / length );
},
......@@ -578,9 +558,7 @@ THREE.Vector3.prototype = {
lerpVectors: function ( v1, v2, alpha ) {
this.subVectors( v2, v1 ).multiplyScalar( alpha ).add( v1 );
return this;
return this.subVectors( v2, v1 ).multiplyScalar( alpha ).add( v1 );
},
......@@ -685,9 +663,7 @@ THREE.Vector3.prototype = {
distanceToSquared: function ( v ) {
var dx = this.x - v.x;
var dy = this.y - v.y;
var dz = this.z - v.z;
var dx = this.x - v.x, dy = this.y - v.y, dz = this.z - v.z;
return dx * dx + dy * dy + dz * dz;
......
......@@ -233,11 +233,7 @@ THREE.Vector4.prototype = {
applyMatrix4: function ( m ) {
var x = this.x;
var y = this.y;
var z = this.z;
var w = this.w;
var x = this.x, y = this.y, z = this.z, w = this.w;
var e = m.elements;
this.x = e[ 0 ] * x + e[ 4 ] * y + e[ 8 ] * z + e[ 12 ] * w;
......@@ -574,9 +570,7 @@ THREE.Vector4.prototype = {
lerpVectors: function ( v1, v2, alpha ) {
this.subVectors( v2, v1 ).multiplyScalar( alpha ).add( v1 );
return this;
return this.subVectors( v2, v1 ).multiplyScalar( alpha ).add( v1 );
},
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册