diff options
author | Sven Göthel <[email protected]> | 2024-04-13 20:43:10 +0200 |
---|---|---|
committer | Sven Göthel <[email protected]> | 2024-04-13 20:43:10 +0200 |
commit | b413c4b074d7b38b1487b7f557a672fa4fe36e51 (patch) | |
tree | b48eef97861f32f6cc37918a3b57aa3c69e7cef0 /include/jau | |
parent | 5364c7007ff008c9d823e3048a057c273fb97b01 (diff) |
math: Mat4f: Add get{Column|Row} w/o passing result storage; Add operator*(const Vec4f&)
Diffstat (limited to 'include/jau')
-rw-r--r-- | include/jau/math/mat4f.hpp | 42 |
1 files changed, 41 insertions, 1 deletions
diff --git a/include/jau/math/mat4f.hpp b/include/jau/math/mat4f.hpp index d8d2133..8ac87c2 100644 --- a/include/jau/math/mat4f.hpp +++ b/include/jau/math/mat4f.hpp @@ -288,7 +288,7 @@ class Mat4f { * </pre> * @return this matrix for chaining */ - Mat4f& load_identity() noexcept { + Mat4f& loadIdentity() noexcept { m00 = m11 = m22 = m33 = 1.0f; m01 = m02 = m03 = m10 = m12 = m13 = @@ -418,6 +418,20 @@ class Mat4f { get(3+column*4) ); return v_out; } + /** + * Get the named column of the given column-major matrix to v_out w/ boundary check. + * @param column named column to copy + * @return result vector holding the requested column + */ + Vec4f getColumn(const jau::nsize_t column) const { + if( column > 3 ) { + throw jau::IndexOutOfBoundsException(2+column*4, 16, E_FILE_LINE); + } + return Vec4f( get(0+column*4), + get(1+column*4), + get(2+column*4), + get(3+column*4) ); + } /** * Get the named column of the given column-major matrix to v_out w/ boundary check. @@ -451,6 +465,20 @@ class Mat4f { get(row+3*4) ); return v_out; } + /** + * Get the named column of the given column-major matrix to v_out w/ boundary check. + * @param row named row to copy + * @return result vector holding the requested row + */ + Vec4f getRow(const jau::nsize_t row) const { + if( row > 3 ) { + throw jau::IndexOutOfBoundsException(row+3*4, 16, E_FILE_LINE); + } + return Vec4f( get(row+0*4), + get(row+1*4), + get(row+2*4), + get(row+3*4) ); + } /** * Get the named row of the given column-major matrix to v_out w/ boundary check. @@ -916,6 +944,18 @@ class Mat4f { x * m30 + y * m31 + z * m32 + w * m33 ); return v_out; } + /** + * Returns new Vec4f holding this * v_in result + * @param v_in 4-component column-vector + */ + Vec4f operator*(const Vec4f& rhs) const noexcept { + // (one matrix row in column-major order) X (column vector) + const float x = rhs.x, y = rhs.y, z = rhs.z, w = rhs.w; + return Vec4f( x * m00 + y * m01 + z * m02 + w * m03, + x * m10 + y * m11 + z * m12 + w * m13, + x * m20 + y * m21 + z * m22 + w * m23, + x * m30 + y * m31 + z * m32 + w * m33 ); + } /** * @param v_inout 4-component column-vector input and output, i.e. in-place transformation |