diff options
Diffstat (limited to 'o3d/samples/o3d-webgl/transform.js')
-rw-r--r-- | o3d/samples/o3d-webgl/transform.js | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/o3d/samples/o3d-webgl/transform.js b/o3d/samples/o3d-webgl/transform.js index 640592c..a569dc2 100644 --- a/o3d/samples/o3d-webgl/transform.js +++ b/o3d/samples/o3d-webgl/transform.js @@ -626,6 +626,31 @@ o3d.Transform.transformPoint = function(m, v) { /** + * Takes a 4-by-4 matrix and a vector with 4 entries, + * interprets the vector as a point, transforms that point by the matrix, and + * returns the result as a vector with 4 entries. + * @param {!o3djs.math.Matrix4} m The matrix. + * @param {!o3djs.math.Vector4} v The vector. + * @return {!o3djs.math.Vector4} The transformed vector. + */ +o3d.Transform.multiplyVector = function(m, v) { + var v0 = v[0]; + var v1 = v[1]; + var v2 = v[2]; + var v3 = v[3]; + var m0 = m[0]; + var m1 = m[1]; + var m2 = m[2]; + var m3 = m[3]; + + return [(v0 * m0[0] + v1 * m1[0] + v2 * m2[0] + v3 * m3[0]), + (v0 * m0[1] + v1 * m1[1] + v2 * m2[1] + v3 * m3[1]), + (v0 * m0[2] + v1 * m1[2] + v2 * m2[2] + v3 * m3[2]), + (v0 * m0[3] + v1 * m1[3] + v2 * m2[3] + v3 * m3[3])]; +}; + + +/** * Takes a 4-by-4 matrix and a vector with 3 entries, * interprets the vector as a point, transforms that point by the matrix, * returning the z-component of the result only. |