From 50f04fd988815b00636de200a70582906d3748f3 Mon Sep 17 00:00:00 2001 From: "Theunis J. Botha" Date: Wed, 23 Nov 2016 12:44:57 +0100 Subject: [PATCH] vector fixes --- src/game-lib-matrix-4.js | 39 --------------------------------------- src/game-lib-vector-2.js | 30 ++++++++++++------------------ src/game-lib-vector-4.js | 4 ++-- 3 files changed, 14 insertions(+), 59 deletions(-) diff --git a/src/game-lib-matrix-4.js b/src/game-lib-matrix-4.js index 9b43237..82f5095 100644 --- a/src/game-lib-matrix-4.js +++ b/src/game-lib-matrix-4.js @@ -131,43 +131,4 @@ GameLib.D3.Matrix4.prototype.lookAt = function (position, target, up) { this.rows[2].z = z.z; return this; - - // te[ 0 ] = x.x; te[ 4 ] = y.x; te[ 8 ] = z.x; - // te[ 1 ] = x.y; te[ 5 ] = y.y; te[ 9 ] = z.y; - // te[ 2 ] = x.z; te[ 6 ] = y.z; te[ 10 ] = z.z; - - - // var matrix4 = new Matrix4(); - // - // matrix4.rows[0] = side.negative(); - // matrix4.rows[1] = _up; - // matrix4.rows[2] = forward; - - // - // matrix4.setColumn(0, side.negative()); - // matrix4.setColumn(1, _up); - // matrix4.setColumn(2, forward); - - //return matrix4; - - // return new Matrix4( - // new Vector4( - // side.x, - // side.y, - // side.z, - // side.negative().dot(position) - // ), - // new Vector4( - // _up.x, - // _up.y, - // _up.z, - // _up.negative().dot(position) - // ), - // new Vector4( - // forward.negative().x, - // forward.negative().y, - // forward.negative().z, - // forward.dot(position) - // ) - // ) }; diff --git a/src/game-lib-vector-2.js b/src/game-lib-vector-2.js index 8c493c5..cad2907 100644 --- a/src/game-lib-vector-2.js +++ b/src/game-lib-vector-2.js @@ -3,15 +3,21 @@ GameLib.D3.Vector2 = function Vector2(x, y) { this.y = y || 0; }; -GameLib.D3.Vector2.prototype.copy = function() { - return new GameLib.D3.Vector2( - this.x, - this.y - ); +GameLib.D3.Vector2.prototype.copy = function (v) { + if (!GameLib.D3.Utils.UndefinedOrNull(v)) { + this.x = v.x; + this.y = v.y; + return this; + } else { + return new GameLib.D3.Vector2( + this.x, + this.y + ); + } }; GameLib.D3.Vector2.prototype.equals = function(v) { - return !!(((this.x == v.x) && + return (((this.x == v.x) && (this.y == v.y)) || ((this.y == v.x) && (this.x == v.y))); @@ -60,18 +66,6 @@ GameLib.D3.Vector2.prototype.divide = function(v) { } }; -GameLib.D3.Vector2.prototype.clone = function() { - return new GameLib.D3.Vector2( - this.x, - this.y - ); -}; - -GameLib.D3.Vector2.prototype.copy = function(v) { - this.x = v.x; - this.y = v.y; -}; - GameLib.D3.Vector2.prototype.set = function(x, y) { this.x = x; this.y = y; diff --git a/src/game-lib-vector-4.js b/src/game-lib-vector-4.js index 994a999..899323e 100644 --- a/src/game-lib-vector-4.js +++ b/src/game-lib-vector-4.js @@ -301,7 +301,7 @@ GameLib.D3.Vector4.Points.prototype.average = function () { ); }; -GameLib.D3.Vector4.Points.prototype.negative = function () { +GameLib.D3.Vector4.Points.prototype.negate = function () { for (var i = 0; i < this.vectors.length; i++) { this.vectors[i].x *= -1; @@ -315,7 +315,7 @@ GameLib.D3.Vector4.Points.prototype.negative = function () { GameLib.D3.Vector4.Points.prototype.toOrigin = function () { - var distanceFromOrigin = this.average().negative(); + var distanceFromOrigin = this.average().negate(); for (var i = 0; i < this.vectors.length; i++) { this.vectors[i].translate(distanceFromOrigin);