Переглянути джерело

* Made vector methods chainable
* Added getCenter to Face4

Ben Nolan 15 роки тому
батько
коміт
0c6219b43f
4 змінених файлів з 33 додано та 0 видалено
  1. 7 0
      src/core/Face4.js
  2. 6 0
      src/core/Vector2.js
  3. 16 0
      src/core/Vector3.js
  4. 4 0
      src/core/Vector4.js

+ 7 - 0
src/core/Face4.js

@@ -22,6 +22,13 @@ THREE.Face4.prototype = {
 
 		return 'THREE.Face4 ( ' + this.a + ', ' + this.b + ', ' + this.c + ' ' + this.d + ' )';
 
+	},
+	
+	getCenter : function(){
+
+	  return this.a.clone().addSelf(this.b).addSelf(this.c).addSelf(this.d).divideScalar(4);
+
 	}
 
+  
 }

+ 6 - 0
src/core/Vector2.js

@@ -30,6 +30,8 @@ THREE.Vector2.prototype = {
 
 		this.x += v.x;
 		this.y += v.y;
+		
+		return this;
 
 	},
 
@@ -45,6 +47,8 @@ THREE.Vector2.prototype = {
 		this.x -= v.x;
 		this.y -= v.y;
 
+		return this;
+
 	},
 
 	sub: function ( v1, v2 ) {
@@ -59,6 +63,8 @@ THREE.Vector2.prototype = {
 		this.x *= s;
 		this.y *= s;
 
+		return this;
+
 	},
 
 	unit: function () {

+ 16 - 0
src/core/Vector3.js

@@ -44,6 +44,8 @@ THREE.Vector3.prototype = {
 		this.y += v.y;
 		this.z += v.z;
 
+		return this;
+
 	},
 
 	addScalar: function ( s ) {
@@ -52,6 +54,8 @@ THREE.Vector3.prototype = {
 		this.y += s;
 		this.z += s;
 
+		return this;
+
 	},
 
 	sub: function( v1, v2 ) {
@@ -68,6 +72,8 @@ THREE.Vector3.prototype = {
 		this.y -= v.y;
 		this.z -= v.z;
 
+		return this;
+
 	},
 
 	cross: function ( v1, v2 ) {
@@ -86,6 +92,8 @@ THREE.Vector3.prototype = {
 		this.y = tz * v.x - tx * v.z;
 		this.z = tx * v.y - ty * v.x;
 
+		return this;
+
 	},
 
 	multiplySelf: function ( v ) {
@@ -94,6 +102,8 @@ THREE.Vector3.prototype = {
 		this.y *= v.y;
 		this.z *= v.z;
 
+		return this;
+
 	},
 
 	multiplyScalar: function ( s ) {
@@ -102,6 +112,8 @@ THREE.Vector3.prototype = {
 		this.y *= s;
 		this.z *= s;
 
+		return this;
+
 	},
 
 	divideScalar: function ( s ) {
@@ -110,6 +122,8 @@ THREE.Vector3.prototype = {
 		this.y /= s;
 		this.z /= s;
 
+		return this;
+
 	},
 
 	dot: function ( v ) {
@@ -149,6 +163,8 @@ THREE.Vector3.prototype = {
 		this.y = - this.y;
 		this.z = - this.z;
 
+		return this;
+
 	},
 
 	normalize: function () {

+ 4 - 0
src/core/Vector4.js

@@ -48,6 +48,8 @@ THREE.Vector4.prototype = {
 		this.z += v.z;
 		this.w += v.w;
 
+		return this;
+
 	},
 
 	sub: function ( v1, v2 ) {
@@ -66,6 +68,8 @@ THREE.Vector4.prototype = {
 		this.z -= v.z;
 		this.w -= v.w;
 
+		return this;
+
 	},
 
 	clone: function () {