summaryrefslogtreecommitdiffstats
path: root/o3d/samples
diff options
context:
space:
mode:
authorkbr@google.com <kbr@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2009-08-19 03:12:40 +0000
committerkbr@google.com <kbr@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2009-08-19 03:12:40 +0000
commitcf5811e922d5aa215a4094bd88e70c38c6ddc57c (patch)
tree4cbd0096b3a501f32abe79d2aa20780246f61959 /o3d/samples
parent27dd7dd56fb606b31bfd34317408a41c6eadaadc (diff)
downloadchromium_src-cf5811e922d5aa215a4094bd88e70c38c6ddc57c.zip
chromium_src-cf5811e922d5aa215a4094bd88e70c38c6ddc57c.tar.gz
chromium_src-cf5811e922d5aa215a4094bd88e70c38c6ddc57c.tar.bz2
Additions of minor utility functions.
Review URL: http://codereview.chromium.org/173041 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@23689 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'o3d/samples')
-rw-r--r--o3d/samples/o3djs/math.js37
1 files changed, 37 insertions, 0 deletions
diff --git a/o3d/samples/o3djs/math.js b/o3d/samples/o3djs/math.js
index e3d32d4..a6bf33a 100644
--- a/o3d/samples/o3djs/math.js
+++ b/o3d/samples/o3djs/math.js
@@ -639,6 +639,25 @@ o3djs.math.copyMatrix = function(m) {
};
/**
+ * Returns the elements of a matrix as a one-dimensional array. The
+ * rows or columns (depending on whether the matrix is row-major or
+ * column-major) are concatenated.
+ * @param {!o3djs.math.Matrix} m The matrix.
+ * @return {!Array.<number>} The matrix's elements as a one-dimensional array.
+ */
+o3djs.math.getMatrixElements = function(m) {
+ var r = [];
+ var mLength = m.length;
+ var k = 0;
+ for (var i = 0; i < mLength; i++) {
+ for (var j = 0; j < m[i].length; j++) {
+ r[k++] = m[i][j];
+ }
+ }
+ return r;
+};
+
+/**
* Multiplies two scalars.
* @param {number} a Operand scalar.
* @param {number} b Operand scalar.
@@ -1750,6 +1769,24 @@ o3djs.math.matrix4.identity = function() {
};
/**
+ * Sets the given 4-by-4 matrix to the identity matrix.
+ * @param {!o3djs.math.Matrix4} m The matrix to set to identity.
+ * @return {!o3djs.math.Matrix4} m once modified.
+ */
+o3djs.math.matrix4.setIdentity = function(m) {
+ for (var i = 0; i < 4; i++) {
+ for (var j = 0; j < 4; j++) {
+ if (i == j) {
+ m[i][j] = 1;
+ } else {
+ m[i][j] = 0;
+ }
+ }
+ }
+ return m;
+};
+
+/**
* Computes a 4-by-4 perspective transformation matrix given the angular height
* of the frustum, the aspect ratio, and the near and far clipping planes. The
* arguments define a frustum extending in the negative z direction. The given