From 0c6219b43f473b1f989aaf5b726763fa2b180be5 Mon Sep 17 00:00:00 2001 From: Ben Nolan Date: Mon, 27 Sep 2010 13:04:52 +1300 Subject: [PATCH] * Made vector methods chainable * Added getCenter to Face4 --- src/core/Face4.js | 7 +++++++ src/core/Vector2.js | 6 ++++++ src/core/Vector3.js | 16 ++++++++++++++++ src/core/Vector4.js | 4 ++++ 4 files changed, 33 insertions(+) diff --git a/src/core/Face4.js b/src/core/Face4.js index 5bed21fc80..695166e805 100644 --- a/src/core/Face4.js +++ b/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); + } + } diff --git a/src/core/Vector2.js b/src/core/Vector2.js index b14374a4d0..1d4eae7705 100644 --- a/src/core/Vector2.js +++ b/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 () { diff --git a/src/core/Vector3.js b/src/core/Vector3.js index 6a3b66dc2f..bc3e1141f6 100644 --- a/src/core/Vector3.js +++ b/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 () { diff --git a/src/core/Vector4.js b/src/core/Vector4.js index 557fa5f990..a109307cae 100644 --- a/src/core/Vector4.js +++ b/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 () { -- GitLab