Skip to content

Commit

Permalink
Added matrix operations to matrix namespaces
Browse files Browse the repository at this point in the history
  • Loading branch information
rehno-lindeque committed Jan 20, 2012
1 parent e62c7fc commit ea2ce7d
Show file tree
Hide file tree
Showing 9 changed files with 37 additions and 31 deletions.
4 changes: 2 additions & 2 deletions Cakefile
Expand Up @@ -9,9 +9,9 @@ libFiles = [
'vector3'
'vector4'
'matrix3'
'matrix3.set'
'matrix3.new'
'matrix4'
'matrix4.set'
'matrix4.new'
]

###
Expand Down
20 changes: 11 additions & 9 deletions dist/glquery.math.js
Expand Up @@ -120,10 +120,11 @@ glQueryMath.vec4.length = function(a) {
return Math.sqrt(a[0] * a[0] + a[1] * a[1] + a[2] * a[2] + a[3] * a[3]);
};

glQueryMath.matrix3 = {};
// Module for setting 3x3 matrix values

// Axis-angle rotation matrix using the right hand rule
glQueryMath.setMatrix3AxisRotation = function(axis, angle) {
glQueryMath.matrix3.newAxisRotation = function(axis, angle) {
var
// Convert rotation to quaternion representation
length = Math.sqrt(axis[0]*axis[0], axis[1]*axis[1], axis[2]*axis[2]),
Expand All @@ -144,17 +145,18 @@ glQueryMath.setMatrix3AxisRotation = function(axis, angle) {
};

// Matrix identity
glQueryMath.setMatrix3Identity = function() {
glQueryMath.matrix3.newIdentity = function() {
return [
1.0, 0.0, 0.0,
0.0, 1.0, 0.0,
0.0, 0.0, 1.0];
};

glQueryMath.matrix4 = {};
// Module for setting 4x4 matrix values

// Axis-angle rotation matrix using the right hand rule
glQueryMath.setMatrix4AxisRotation = function(axis, angle) {
glQueryMath.matrix4.newAxisRotation = function(axis, angle) {
var
// Convert rotation to quaternion representation
length = Math.sqrt(axis[0]*axis[0], axis[1]*axis[1], axis[2]*axis[2]),
Expand All @@ -176,19 +178,19 @@ glQueryMath.setMatrix4AxisRotation = function(axis, angle) {
};

// Matrix identity
glQueryMath.setMatrix4Identity = function() {
glQueryMath.matrix4.newIdentity = function() {
return [
1.0, 0.0, 0.0, 0.0,
0.0, 1.0, 0.0, 0.0,
0.0, 0.0, 1.0, 0.0,
0.0, 0.0, 0.0, 1.0];
};

glQueryMath.setMatrix4Rows = function(r0, r1, r2, r3) {
glQueryMath.matrix4.newRows = function(r0, r1, r2, r3) {
return [].concat(r0, r1, r2, r3);
}

glQueryMath.setMatrix4Columns = function(c0, c1, c2, c3) {
glQueryMath.matrix4.newColumns = function(c0, c1, c2, c3) {
return [
c0[0], c1[0], c2[0],c3[0],
c0[1], c1[1], c2[1],c3[1],
Expand All @@ -198,7 +200,7 @@ glQueryMath.setMatrix4Columns = function(c0, c1, c2, c3) {
}

// Right-handed orthogonal projection matrix
glQueryMath.setMatrix4Ortho = function(left, right, bottom, top, near, far) {
glQueryMath.matrix4.newOrtho = function(left, right, bottom, top, near, far) {
var x = left - right,
y = bottom - top,
z = near - far;
Expand All @@ -211,7 +213,7 @@ glQueryMath.setMatrix4Ortho = function(left, right, bottom, top, near, far) {
};

// Right-handed look-at matrix
glQueryMath.setMatrix4LookAt = function(eye, target, up) {
glQueryMath.matrix4.newLookAt = function(eye, target, up) {
// TODO: See if it would be more efficient to try and build the matrix
// by rows instead of by columns as is done presently
var x = MathMemoryPool.vector4[0],
Expand All @@ -236,5 +238,5 @@ glQueryMath.setMatrix4LookAt = function(eye, target, up) {
w[1] = 0.0;
w[2] = 0.0;
w[3] = 1.0;
return glQueryMath.setMatrix4Columns(x,y,z,w);
return glQueryMath.matrix4.newColumns(x,y,z,w);
};
2 changes: 1 addition & 1 deletion dist/glquery.math.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 11 additions & 9 deletions dist/glquery.math.module.js
Expand Up @@ -123,10 +123,11 @@ glQueryMath.vec4.length = function(a) {
return Math.sqrt(a[0] * a[0] + a[1] * a[1] + a[2] * a[2] + a[3] * a[3]);
};

glQueryMath.matrix3 = {};
// Module for setting 3x3 matrix values

// Axis-angle rotation matrix using the right hand rule
glQueryMath.setMatrix3AxisRotation = function(axis, angle) {
glQueryMath.matrix3.newAxisRotation = function(axis, angle) {
var
// Convert rotation to quaternion representation
length = Math.sqrt(axis[0]*axis[0], axis[1]*axis[1], axis[2]*axis[2]),
Expand All @@ -147,17 +148,18 @@ glQueryMath.setMatrix3AxisRotation = function(axis, angle) {
};

// Matrix identity
glQueryMath.setMatrix3Identity = function() {
glQueryMath.matrix3.newIdentity = function() {
return [
1.0, 0.0, 0.0,
0.0, 1.0, 0.0,
0.0, 0.0, 1.0];
};

glQueryMath.matrix4 = {};
// Module for setting 4x4 matrix values

// Axis-angle rotation matrix using the right hand rule
glQueryMath.setMatrix4AxisRotation = function(axis, angle) {
glQueryMath.matrix4.newAxisRotation = function(axis, angle) {
var
// Convert rotation to quaternion representation
length = Math.sqrt(axis[0]*axis[0], axis[1]*axis[1], axis[2]*axis[2]),
Expand All @@ -179,19 +181,19 @@ glQueryMath.setMatrix4AxisRotation = function(axis, angle) {
};

// Matrix identity
glQueryMath.setMatrix4Identity = function() {
glQueryMath.matrix4.newIdentity = function() {
return [
1.0, 0.0, 0.0, 0.0,
0.0, 1.0, 0.0, 0.0,
0.0, 0.0, 1.0, 0.0,
0.0, 0.0, 0.0, 1.0];
};

glQueryMath.setMatrix4Rows = function(r0, r1, r2, r3) {
glQueryMath.matrix4.newRows = function(r0, r1, r2, r3) {
return [].concat(r0, r1, r2, r3);
}

glQueryMath.setMatrix4Columns = function(c0, c1, c2, c3) {
glQueryMath.matrix4.newColumns = function(c0, c1, c2, c3) {
return [
c0[0], c1[0], c2[0],c3[0],
c0[1], c1[1], c2[1],c3[1],
Expand All @@ -201,7 +203,7 @@ glQueryMath.setMatrix4Columns = function(c0, c1, c2, c3) {
}

// Right-handed orthogonal projection matrix
glQueryMath.setMatrix4Ortho = function(left, right, bottom, top, near, far) {
glQueryMath.matrix4.newOrtho = function(left, right, bottom, top, near, far) {
var x = left - right,
y = bottom - top,
z = near - far;
Expand All @@ -214,7 +216,7 @@ glQueryMath.setMatrix4Ortho = function(left, right, bottom, top, near, far) {
};

// Right-handed look-at matrix
glQueryMath.setMatrix4LookAt = function(eye, target, up) {
glQueryMath.matrix4.newLookAt = function(eye, target, up) {
// TODO: See if it would be more efficient to try and build the matrix
// by rows instead of by columns as is done presently
var x = MathMemoryPool.vector4[0],
Expand All @@ -239,7 +241,7 @@ glQueryMath.setMatrix4LookAt = function(eye, target, up) {
w[1] = 0.0;
w[2] = 0.0;
w[3] = 1.0;
return glQueryMath.setMatrix4Columns(x,y,z,w);
return glQueryMath.matrix4.newColumns(x,y,z,w);
};

// Extend glQuery if it is defined
Expand Down

0 comments on commit ea2ce7d

Please sign in to comment.