Skip to content

Commit

Permalink
minor math lib updates
Browse files Browse the repository at this point in the history
  • Loading branch information
schteppe committed Jan 22, 2015
1 parent 4d7ecfe commit 239eddf
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 14 deletions.
19 changes: 10 additions & 9 deletions src/math/Mat3.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,17 +28,18 @@ function Mat3(elements){
* @todo Create another function that immediately creates an identity matrix eg. eye()
*/
Mat3.prototype.identity = function(){
this.elements[0] = 1;
this.elements[1] = 0;
this.elements[2] = 0;
var e = this.elements;
e[0] = 1;
e[1] = 0;
e[2] = 0;

this.elements[3] = 0;
this.elements[4] = 1;
this.elements[5] = 0;
e[3] = 0;
e[4] = 1;
e[5] = 0;

this.elements[6] = 0;
this.elements[7] = 0;
this.elements[8] = 1;
e[6] = 0;
e[7] = 0;
e[8] = 1;
};

/**
Expand Down
27 changes: 22 additions & 5 deletions src/math/Vec3.js
Original file line number Diff line number Diff line change
Expand Up @@ -173,24 +173,40 @@ Vec3.prototype.unit = function(target){
};

/**
* Get the 2-norm (length) of the vector
* Get the length of the vector
* @method norm
* @return {Number}
* @deprecated Use .length() instead
*/
Vec3.prototype.norm = function(){
var x=this.x, y=this.y, z=this.z;
return Math.sqrt(x*x + y*y + z*z);
};

/**
* Get the length of the vector
* @method length
* @return {Number}
*/
Vec3.prototype.length = Vec3.prototype.norm;

/**
* Get the squared length of the vector
* @method norm2
* @return {Number}
* @deprecated Use .lengthSquared() instead.
*/
Vec3.prototype.norm2 = function(){
return this.dot(this);
};

/**
* Get the squared length of the vector.
* @method lengthSquared
* @return {Number}
*/
Vec3.prototype.lengthSquared = Vec3.prototype.norm2;

/**
* Get distance from this point to another point
* @method distanceTo
Expand All @@ -206,12 +222,13 @@ Vec3.prototype.distanceTo = function(p){
};

/**
* Multiply the vector with a scalar
* Multiply all the components of the vector with a scalar.
* @deprecated Use .scale instead
* @method mult
* @param {Number} scalar
* @param {Vec3} target
* @param {Vec3} target The vector to save the result in.
* @return {Vec3}
* @deprecated Use .scale() instead
*/
Vec3.prototype.mult = function(scalar,target){
target = target || new Vec3();
Expand Down Expand Up @@ -290,8 +307,8 @@ Vec3.prototype.tangents = function(t1,t2){
n.cross(t1,t2);
} else {
// The normal length is zero, make something up
t1.set(1,0,0).normalize();
t2.set(0,1,0).normalize();
t1.set(1, 0, 0);
t2.set(0, 1, 0);
}
};

Expand Down

0 comments on commit 239eddf

Please sign in to comment.