diff options
author | Jean-Luc Brouillet <jeanluc@google.com> | 2014-09-05 17:44:48 -0700 |
---|---|---|
committer | Jean-Luc Brouillet <jeanluc@google.com> | 2014-09-08 15:40:58 -0700 |
commit | 1bb2eed69caa28cf8198d58db7d9134cc2f563f5 (patch) | |
tree | a13139843a108be78b86d4f1eef0fe574055c1a7 /rsMatrix4x4.cpp | |
parent | 33164686a7ac88d4eda38201be4127937e9c12b0 (diff) | |
download | rs-1bb2eed69caa28cf8198d58db7d9134cc2f563f5.tar.gz |
Improve rsMatrix* documentation, fix bugs
Improves the user-facing documentation. Fix the incorrect row & column
naming on the Get/Set API. Fix a bug where rsMatrixLoadMultiply could
not have the destination be one of the source,
e.g. rsMatrixLoadMultiply(&l, &l, &r)
Change-Id: I42207aacf4ebe815d4a79db2aaa9c44f85864696
Diffstat (limited to 'rsMatrix4x4.cpp')
-rw-r--r-- | rsMatrix4x4.cpp | 13 |
1 files changed, 9 insertions, 4 deletions
diff --git a/rsMatrix4x4.cpp b/rsMatrix4x4.cpp index c6f96d8d..f166c57e 100644 --- a/rsMatrix4x4.cpp +++ b/rsMatrix4x4.cpp @@ -250,6 +250,9 @@ void Matrix4x4::loadTranslate(float x, float y, float z) { } void Matrix4x4::loadMultiply(const rs_matrix4x4 *lhs, const rs_matrix4x4 *rhs) { + // Use a temporary variable to support the case where one of the inputs + // is also the destination, e.g. left.loadMultiply(left, right); + Matrix4x4 temp; for (int i=0 ; i<4 ; i++) { float ri0 = 0; float ri1 = 0; @@ -262,11 +265,12 @@ void Matrix4x4::loadMultiply(const rs_matrix4x4 *lhs, const rs_matrix4x4 *rhs) { ri2 += ((const Matrix4x4 *)lhs)->get(j,2) * rhs_ij; ri3 += ((const Matrix4x4 *)lhs)->get(j,3) * rhs_ij; } - set(i,0, ri0); - set(i,1, ri1); - set(i,2, ri2); - set(i,3, ri3); + temp.set(i,0, ri0); + temp.set(i,1, ri1); + temp.set(i,2, ri2); + temp.set(i,3, ri3); } + load(&temp); } void Matrix4x4::loadOrtho(float left, float right, float bottom, float top, float near, float far) { @@ -299,6 +303,7 @@ void Matrix4x4::loadPerspective(float fovy, float aspect, float near, float far) loadFrustum(left, right, bottom, top, near, far); } +// Note: This assumes that the input vector (in) is of length 3. void Matrix4x4::vectorMultiply(float *out, const float *in) const { out[0] = (m[0] * in[0]) + (m[4] * in[1]) + (m[8] * in[2]) + m[12]; out[1] = (m[1] * in[0]) + (m[5] * in[1]) + (m[9] * in[2]) + m[13]; |