12#ifndef JAU_MATH_MAT4f_HPP_
13#define JAU_MATH_MAT4f_HPP_
21#include <initializer_list>
45 std::enable_if_t<std::is_floating_point_v<Value_type>,
bool>>
100 std::enable_if_t<std::is_floating_point_v<Value_type>,
bool> =
true>
155 : m00(*m), m10(*(++m)), m20(*(++m)), m30(*(++m)),
156 m01(*(++m)), m11(*(++m)), m21(*(++m)), m31(*(++m)),
157 m02(*(++m)), m12(*(++m)), m22(*(++m)), m32(*(++m)),
158 m03(*(++m)), m13(*(++m)), m23(*(++m)), m33(*(++m))
165 constexpr Matrix4(std::initializer_list<value_type> m) noexcept
168 assert(m.size() >= 16 );
225 explicit operator pointer() noexcept {
return &m00; }
240 m00 = m11 = m22 = m33 =
one;
244 m30 = m31 = m32 =
zero;
279 return load( src.cbegin() );
310 assert( column < 4 );
311 return v_out.set(
get(0+column*4),
323 assert( column < 4 );
337 return v_out.set(
get(0+column*4),
350 return v_out.set(
get( row + 0*4_unz),
353 get( row + 3*4_unz) );
377 return v_out.set(
get(row+0*4_unz),
416 constexpr std::vector<value_type>&
get(std::vector<value_type>& dst,
size_t dst_off)
const noexcept {
417 assert( dst.size() >= dst_off+16 && dst_off <= std::numeric_limits<size_t>::max() - 15 );
418 get( &dst[dst_off++] );
432 ret += m00 * ( + m11*(m22*m33 - m23*m32) - m12*(m21*m33 - m23*m31) + m13*(m21*m32 - m22*m31));
433 ret -= m01 * ( + m10*(m22*m33 - m23*m32) - m12*(m20*m33 - m23*m30) + m13*(m20*m32 - m22*m30));
434 ret += m02 * ( + m10*(m21*m33 - m23*m31) - m11*(m20*m33 - m23*m30) + m13*(m20*m31 - m21*m30));
435 ret -= m03 * ( + m10*(m21*m32 - m22*m31) - m11*(m20*m32 - m22*m30) + m12*(m20*m31 - m21*m30));
537 const value_type b00 = + a11*(a22*a33 - a23*a32) - a12*(a21*a33 - a23*a31) + a13*(a21*a32 - a22*a31);
538 const value_type b01 = -( + a10*(a22*a33 - a23*a32) - a12*(a20*a33 - a23*a30) + a13*(a20*a32 - a22*a30));
539 const value_type b02 = + a10*(a21*a33 - a23*a31) - a11*(a20*a33 - a23*a30) + a13*(a20*a31 - a21*a30);
540 const value_type b03 = -( + a10*(a21*a32 - a22*a31) - a11*(a20*a32 - a22*a30) + a12*(a20*a31 - a21*a30));
542 const value_type b10 = -( + a01*(a22*a33 - a23*a32) - a02*(a21*a33 - a23*a31) + a03*(a21*a32 - a22*a31));
543 const value_type b11 = + a00*(a22*a33 - a23*a32) - a02*(a20*a33 - a23*a30) + a03*(a20*a32 - a22*a30);
544 const value_type b12 = -( + a00*(a21*a33 - a23*a31) - a01*(a20*a33 - a23*a30) + a03*(a20*a31 - a21*a30));
545 const value_type b13 = + a00*(a21*a32 - a22*a31) - a01*(a20*a32 - a22*a30) + a02*(a20*a31 - a21*a30);
547 const value_type b20 = + a01*(a12*a33 - a13*a32) - a02*(a11*a33 - a13*a31) + a03*(a11*a32 - a12*a31);
548 const value_type b21 = -( + a00*(a12*a33 - a13*a32) - a02*(a10*a33 - a13*a30) + a03*(a10*a32 - a12*a30));
549 const value_type b22 = + a00*(a11*a33 - a13*a31) - a01*(a10*a33 - a13*a30) + a03*(a10*a31 - a11*a30);
550 const value_type b23 = -( + a00*(a11*a32 - a12*a31) - a01*(a10*a32 - a12*a30) + a02*(a10*a31 - a11*a30));
552 const value_type b30 = -( + a01*(a12*a23 - a13*a22) - a02*(a11*a23 - a13*a21) + a03*(a11*a22 - a12*a21));
553 const value_type b31 = + a00*(a12*a23 - a13*a22) - a02*(a10*a23 - a13*a20) + a03*(a10*a22 - a12*a20);
554 const value_type b32 = -( + a00*(a11*a23 - a13*a21) - a01*(a10*a23 - a13*a20) + a03*(a10*a21 - a11*a20));
555 const value_type b33 = + a00*(a11*a22 - a12*a21) - a01*(a10*a22 - a12*a20) + a02*(a10*a21 - a11*a20);
557 const value_type det = (a00*b00 + a01*b01 + a02*b02 + a03*b03) /
scale;
594 DBG_PRINT(
"Matrix4:invert(src): absMax==0: %s", src.toString().c_str());
618 const value_type b00 = + a11*(a22*a33 - a23*a32) - a12*(a21*a33 - a23*a31) + a13*(a21*a32 - a22*a31);
619 const value_type b01 = -( + a10*(a22*a33 - a23*a32) - a12*(a20*a33 - a23*a30) + a13*(a20*a32 - a22*a30));
620 const value_type b02 = + a10*(a21*a33 - a23*a31) - a11*(a20*a33 - a23*a30) + a13*(a20*a31 - a21*a30);
621 const value_type b03 = -( + a10*(a21*a32 - a22*a31) - a11*(a20*a32 - a22*a30) + a12*(a20*a31 - a21*a30));
623 const value_type b10 = -( + a01*(a22*a33 - a23*a32) - a02*(a21*a33 - a23*a31) + a03*(a21*a32 - a22*a31));
624 const value_type b11 = + a00*(a22*a33 - a23*a32) - a02*(a20*a33 - a23*a30) + a03*(a20*a32 - a22*a30);
625 const value_type b12 = -( + a00*(a21*a33 - a23*a31) - a01*(a20*a33 - a23*a30) + a03*(a20*a31 - a21*a30));
626 const value_type b13 = + a00*(a21*a32 - a22*a31) - a01*(a20*a32 - a22*a30) + a02*(a20*a31 - a21*a30);
628 const value_type b20 = + a01*(a12*a33 - a13*a32) - a02*(a11*a33 - a13*a31) + a03*(a11*a32 - a12*a31);
629 const value_type b21 = -( + a00*(a12*a33 - a13*a32) - a02*(a10*a33 - a13*a30) + a03*(a10*a32 - a12*a30));
630 const value_type b22 = + a00*(a11*a33 - a13*a31) - a01*(a10*a33 - a13*a30) + a03*(a10*a31 - a11*a30);
631 const value_type b23 = -( + a00*(a11*a32 - a12*a31) - a01*(a10*a32 - a12*a30) + a02*(a10*a31 - a11*a30));
633 const value_type b30 = -( + a01*(a12*a23 - a13*a22) - a02*(a11*a23 - a13*a21) + a03*(a11*a22 - a12*a21));
634 const value_type b31 = + a00*(a12*a23 - a13*a22) - a02*(a10*a23 - a13*a20) + a03*(a10*a22 - a12*a20);
635 const value_type b32 = -( + a00*(a11*a23 - a13*a21) - a01*(a10*a23 - a13*a20) + a03*(a10*a21 - a11*a20));
636 const value_type b33 = + a00*(a11*a22 - a12*a21) - a01*(a10*a22 - a12*a20) + a02*(a10*a21 - a11*a20);
638 const value_type det = (a00*b00 + a01*b01 + a02*b02 + a03*b03) /
scale;
641 DBG_PRINT(
"Matrix4:invert(src): det==0: %s", src.toString().c_str());
670 value_type absMax() const noexcept {
671 value_type
max = std::abs(m00);
672 max = std::max(
max, std::abs(m01));
673 max = std::max(
max, std::abs(m02));
674 max = std::max(
max, std::abs(m03));
676 max = std::max(
max, std::abs(m10));
677 max = std::max(
max, std::abs(m11));
678 max = std::max(
max, std::abs(m12));
679 max = std::max(
max, std::abs(m13));
681 max = std::max(
max, std::abs(m20));
682 max = std::max(
max, std::abs(m21));
683 max = std::max(
max, std::abs(m22));
684 max = std::max(
max, std::abs(m23));
686 max = std::max(
max, std::abs(m30));
687 max = std::max(
max, std::abs(m31));
688 max = std::max(
max, std::abs(m32));
689 max = std::max(
max, std::abs(m33));
700 m00 *= s; m10 *= s; m20 *= s; m30 *= s;
701 m01 *= s; m11 *= s; m21 *= s; m31 *= s;
702 m02 *= s; m12 *= s; m22 *= s; m32 *= s;
703 m03 *= s; m13 *= s; m23 *= s; m33 *= s;
719 m00 = ai0 * b.m00 + ai1 * b.m10 + ai2 * b.m20 + ai3 * b.m30 ;
720 m01 = ai0 * b.m01 + ai1 * b.m11 + ai2 * b.m21 + ai3 * b.m31 ;
721 m02 = ai0 * b.m02 + ai1 * b.m12 + ai2 * b.m22 + ai3 * b.m32 ;
722 m03 = ai0 * b.m03 + ai1 * b.m13 + ai2 * b.m23 + ai3 * b.m33 ;
728 m10 = ai0 * b.m00 + ai1 * b.m10 + ai2 * b.m20 + ai3 * b.m30 ;
729 m11 = ai0 * b.m01 + ai1 * b.m11 + ai2 * b.m21 + ai3 * b.m31 ;
730 m12 = ai0 * b.m02 + ai1 * b.m12 + ai2 * b.m22 + ai3 * b.m32 ;
731 m13 = ai0 * b.m03 + ai1 * b.m13 + ai2 * b.m23 + ai3 * b.m33 ;
737 m20 = ai0 * b.m00 + ai1 * b.m10 + ai2 * b.m20 + ai3 * b.m30 ;
738 m21 = ai0 * b.m01 + ai1 * b.m11 + ai2 * b.m21 + ai3 * b.m31 ;
739 m22 = ai0 * b.m02 + ai1 * b.m12 + ai2 * b.m22 + ai3 * b.m32 ;
740 m23 = ai0 * b.m03 + ai1 * b.m13 + ai2 * b.m23 + ai3 * b.m33 ;
746 m30 = ai0 * b.m00 + ai1 * b.m10 + ai2 * b.m20 + ai3 * b.m30 ;
747 m31 = ai0 * b.m01 + ai1 * b.m11 + ai2 * b.m21 + ai3 * b.m31 ;
748 m32 = ai0 * b.m02 + ai1 * b.m12 + ai2 * b.m22 + ai3 * b.m32 ;
749 m33 = ai0 * b.m03 + ai1 * b.m13 + ai2 * b.m23 + ai3 * b.m33 ;
771 m00 = a.m00 * b.m00 + a.m01 * b.m10 + a.m02 * b.m20 + a.m03 * b.m30 ;
772 m01 = a.m00 * b.m01 + a.m01 * b.m11 + a.m02 * b.m21 + a.m03 * b.m31 ;
773 m02 = a.m00 * b.m02 + a.m01 * b.m12 + a.m02 * b.m22 + a.m03 * b.m32 ;
774 m03 = a.m00 * b.m03 + a.m01 * b.m13 + a.m02 * b.m23 + a.m03 * b.m33 ;
777 m10 = a.m10 * b.m00 + a.m11 * b.m10 + a.m12 * b.m20 + a.m13 * b.m30 ;
778 m11 = a.m10 * b.m01 + a.m11 * b.m11 + a.m12 * b.m21 + a.m13 * b.m31 ;
779 m12 = a.m10 * b.m02 + a.m11 * b.m12 + a.m12 * b.m22 + a.m13 * b.m32 ;
780 m13 = a.m10 * b.m03 + a.m11 * b.m13 + a.m12 * b.m23 + a.m13 * b.m33 ;
783 m20 = a.m20 * b.m00 + a.m21 * b.m10 + a.m22 * b.m20 + a.m23 * b.m30 ;
784 m21 = a.m20 * b.m01 + a.m21 * b.m11 + a.m22 * b.m21 + a.m23 * b.m31 ;
785 m22 = a.m20 * b.m02 + a.m21 * b.m12 + a.m22 * b.m22 + a.m23 * b.m32 ;
786 m23 = a.m20 * b.m03 + a.m21 * b.m13 + a.m22 * b.m23 + a.m23 * b.m33 ;
789 m30 = a.m30 * b.m00 + a.m31 * b.m10 + a.m32 * b.m20 + a.m33 * b.m30 ;
790 m31 = a.m30 * b.m01 + a.m31 * b.m11 + a.m32 * b.m21 + a.m33 * b.m31 ;
791 m32 = a.m30 * b.m02 + a.m31 * b.m12 + a.m32 * b.m22 + a.m33 * b.m32 ;
792 m33 = a.m30 * b.m03 + a.m31 * b.m13 + a.m32 * b.m23 + a.m33 * b.m33 ;
804 const value_type x = v_in.x, y = v_in.y, z = v_in.z, w = v_in.w;
805 v_out.set( x * m00 + y * m01 + z * m02 + w * m03,
806 x * m10 + y * m11 + z * m12 + w * m13,
807 x * m20 + y * m21 + z * m22 + w * m23,
808 x * m30 + y * m31 + z * m32 + w * m33 );
818 const value_type x = rhs.x, y = rhs.y, z = rhs.z, w = rhs.w;
819 return Vec4( x * m00 + y * m01 + z * m02 + w * m03,
820 x * m10 + y * m11 + z * m12 + w * m13,
821 x * m20 + y * m21 + z * m22 + w * m23,
822 x * m30 + y * m31 + z * m32 + w * m33 );
831 const value_type x = v_inout.x, y = v_inout.y, z = v_inout.z, w = v_inout.w;
832 v_inout.set( x * m00 + y * m01 + z * m02 + w * m03,
833 x * m10 + y * m11 + z * m12 + w * m13,
834 x * m20 + y * m21 + z * m22 + w * m23,
835 x * m30 + y * m31 + z * m32 + w * m33 );
852 const value_type x = v_in.x, y = v_in.y, z = v_in.z;
853 v_out.set( x * m00 + y * m01 + z * m02 +
one * m03,
854 x * m10 + y * m11 + z * m12 +
one * m13,
855 x * m20 + y * m21 + z * m22 +
one * m23 );
869 const value_type x = rhs.x, y = rhs.y, z = rhs.z;
870 return Vec3( x * m00 + y * m01 + z * m02 +
one * m03,
871 x * m10 + y * m11 + z * m12 +
one * m13,
872 x * m20 + y * m21 + z * m22 +
one * m23 );
887 const value_type x = v_inout.x, y = v_inout.y, z = v_inout.z;
888 v_inout.set( x * m00 + y * m01 + z * m02 +
one * m03,
889 x * m10 + y * m11 + z * m12 +
one * m13,
890 x * m20 + y * m21 + z * m22 +
one * m23 );
913 m00 = m11 = m22 = m33 =
one;
920 m30 = m31 = m32 =
zero;
962 m30 = m31 = m32 =
zero;
1004 x = tmp.
x; y = tmp.
y; z = tmp.
z;
1090 m01 = sh*sb - ch*sa*cb;
1092 m21 = sh*sa*cb + ch*sb;
1095 m02 = ch*sa*sb + sh*cb;
1097 m22 = -sh*sa*sb + ch*cb;
1155 m10 = m20 = m30 =
zero;
1156 m01 = m21 = m31 =
zero;
1157 m02 = m12 = m32 =
zero;
1201 if( zNear <=
zero || zFar <= zNear ) {
1204 if( left == right || top == bottom) {
1209 m10 = m20 = m30 =
zero;
1210 m01 = m21 = m31 =
zero;
1252 return setToFrustum(left, right, bottom, top, zNear, zFar);
1272 return setToFrustum(left, right, bottom, top, zNear, zFar);
1296 const Vec3 fwd = ( center - eye ).normalize();
1359 const Recti& viewport)
noexcept {
1360 if (deltaX <= 0 || deltaY <= 0) {
1365 ( viewport.height() -
two * ( y - viewport.y() ) ) / deltaY,
1368 mat4Tmp.
setToScale( viewport.width() / deltaX, viewport.height() / deltaY,
one );
1463 const Recti& viewport,
Vec3& winPos)
noexcept
1467 return mapToWinImpl(rawWin, viewport, winPos);
1483 const Recti& viewport,
Vec3& winPos)
noexcept
1486 return mapToWinImpl(rawWin, viewport, winPos);
1500 const Recti& viewport,
Vec3& winPos)
noexcept
1503 return mapToWinImpl(rawWin, viewport, winPos);
1516 const Recti& viewport,
Vec3& winPos)
noexcept
1519 return mapToWinImpl(rawWin, viewport, winPos);
1523 static bool mapToWinImpl(Vec4& rawWin,
1524 const Recti& viewport, Vec3& winPos)
noexcept
1526 if ( zero == rawWin.w ) {
1530 const value_type s = (
one / rawWin.w ) * half;
1533 rawWin.scale(s).add(half, half, half, zero);
1536 winPos.set( rawWin.x * viewport.width() + viewport.x(),
1537 rawWin.y * viewport.height() + viewport.y(),
1560 const Recti& viewport,
1561 Vec3& objPos)
noexcept
1565 invPMv.
mul(mP, mMv);
1569 return mapWinToAny(winx, winy, winz, invPMv, viewport, objPos);
1585 const Recti& viewport,
1586 Vec3& viewPos)
noexcept
1593 return mapWinToAny(winx, winy, winz, invP, viewport, viewPos);
1617 const Recti& viewport,
1618 Vec3& objPos)
noexcept
1620 Vec4 winPos(winx, winy, winz,
one);
1629 Vec4 rawObjPos = invAny * winPos;
1631 if (
zero == rawObjPos.
w ) {
1663 const Recti& viewport,
1664 Vec3& objPos1,
Vec3& objPos2)
noexcept
1666 Vec4 winPos(winx, winy, winz1,
one);
1675 Vec4 rawObjPos = invAny * winPos;
1677 if (
zero == rawObjPos.
w ) {
1689 invAny.mulVec4(winPos, rawObjPos);
1691 if (
zero == rawObjPos.
w ) {
1718 const Recti& viewport,
1720 Vec4& objPos)
noexcept
1724 invPMv.
mul(mP, mMv);
1729 invPMv, viewport, near, far, objPos);
1751 const Recti& viewport,
1753 Vec4& objPos)
noexcept
1755 Vec4 winPos(winx, winy, winz, clipw);
1758 winPos.
add(-viewport.x(), -viewport.y(), -near,
zero).
mul(
one/viewport.width(),
one/viewport.height(),
one/(far-near),
one);
1764 invPMv.mulVec4(winPos, objPos);
1766 if (
zero == objPos.w ) {
1796 const Recti& viewport,
1801 invPMv.
mul(mP, mMv);
1805 return mapWinToAnyRay(winx, winy, winz0, winz1, invPMv, viewport, ray);
1832 const Recti& viewport,
1840 return mapWinToAnyRay(winx, winy, winz0, winz1, invP, viewport, ray);
1872 const Recti& viewport,
1875 if(
mapWinToAny(winx, winy, winz0, winz1, invAny, viewport, ray.orig, ray.dir) ) {
1876 (ray.dir -= ray.orig).normalize();
1888 std::string
toString(
const std::string& rowPrefix,
const std::string& f)
const noexcept {
1899 std::string
toString(
const std::string& rowPrefix)
const noexcept {
return toString(rowPrefix,
"%13.9f"); }
1905 std::enable_if_t<std::is_floating_point_v<T>,
bool> =
true>
1911 std::enable_if_t<std::is_floating_point_v<T>,
bool> =
true>
1917 std::enable_if_t<std::is_floating_point_v<T>,
bool> =
true>
1923 std::enable_if_t<std::is_floating_point_v<T>,
bool> =
true>
1925 return out << v.toString();
1930static_assert(
alignof(float) ==
alignof(
Mat4f));
1931static_assert(
sizeof(float)*16 ==
sizeof(
Mat4f));
Horizontal and vertical field of view (FOV) halves, allowing a non-centered projection.
float top
Half vertical FOV from center to top, either in inTangents or radians.
float right
Half horizontal FOV from center to right, either in inTangents or radians.
float left
Half horizontal FOV from center to left, either in inTangents or radians.
FovHVHalves toTangents() const noexcept
Returns this instance in tangent values.
float bottom
Half vertical FOV from center to bottom, either in inTangents or radians.
Basic 4x4 value_type matrix implementation using fields for intensive use-cases (host operations).
constexpr Matrix4 & scale(const value_type s) noexcept
Scale this matrix, i.e.
constexpr Matrix4 & setToScale(const value_type x, const value_type y, const value_type z) noexcept
Set this matrix to scale.
constexpr bool operator==(const Matrix4 &rhs) const noexcept
constexpr value_type get(const jau::nsize_t i) const noexcept
Returns the ith component of the given column-major order matrix, 0 <= i < 16, w/o boundary check.
constexpr iterator get(iterator dst) const noexcept
Get this matrix into the given value_type[16] array in column major order w/o boundary check.
Vector4F< value_type, std::is_floating_point_v< Value_type > > Vec4
static bool mapViewToWin(const Vec3 &view, const Matrix4 &mP, const Recti &viewport, Vec3 &winPos) noexcept
Map view coordinates ( Mv x object ) to window coordinates.
constexpr_cxx26 Matrix4 & setToRotationAxis(const value_type ang_rad, value_type x, value_type y, value_type z) noexcept
Set this matrix to rotation from the given axis and angle in radians.
constexpr Matrix4 & translate(const value_type x, const value_type y, const value_type z) noexcept
Translate this matrix, i.e.
constexpr Vec4 getRow(const jau::nsize_t row) const noexcept
Get the named column of the given column-major matrix to v_out w/o boundary check.
static constexpr const value_type one
std::string toString() const noexcept
constexpr void set(const jau::nsize_t i, const value_type v) noexcept
Sets the ith component of this column-major order matrix with value_type v, 0 <= i < 16 w/o boundary ...
constexpr value_type operator[](size_t i) const noexcept
Returns read-only ith component of the given column-major order matrix, 0 <= i < 16 w/o boundary chec...
constexpr_cxx26 Matrix4 & setToRotationAxis(const value_type ang_rad, const Vec3 &axis) noexcept
Set this matrix to rotation from the given axis and angle in radians.
bool invert() noexcept
Invert this matrix.
static bool mapWinToViewRay(const value_type winx, const value_type winy, const value_type winz0, const value_type winz1, const Matrix4 &mP, const Recti &viewport, Ray3 &ray) noexcept
Map two window coordinates w/ shared X/Y and distinctive Z to a Ray in view space.
Matrix4 & setToPerspective(const FovHVHalves &fovhv, const value_type zNear, const value_type zFar)
Set this matrix to perspective frustum projection.
constexpr Vec3 & getColumn(const jau::nsize_t column, Vec3 &v_out) const noexcept
Get the named column of the given column-major matrix to v_out w/o boundary check.
constexpr Vec3 & mulVec3(const Vec3 &v_in, Vec3 &v_out) const noexcept
Affine 3f-vector transformation by 4x4 matrix.
constexpr const_iterator cbegin() const noexcept
constexpr reference operator[](size_t i) noexcept
Returns writable reference to the ith component of this column-major order matrix,...
Ray3F< value_type, std::is_floating_point_v< Value_type > > Ray3
Matrix4 & transpose() noexcept
Transpose this matrix.
static bool mapWinToAny(const value_type winx, const value_type winy, const value_type winz1, const value_type winz2, const Matrix4 &invAny, const Recti &viewport, Vec3 &objPos1, Vec3 &objPos2) noexcept
Map two window coordinates to two to object, world or view coordinates, depending on invAny argument.
static bool mapWinToView(const value_type winx, const value_type winy, const value_type winz, const Matrix4 &mP, const Recti &viewport, Vec3 &viewPos) noexcept
Map window coordinates to view coordinates.
constexpr Vec4 & mulVec4(const Vec4 &v_in, Vec4 &v_out) const noexcept
constexpr Vec4 getColumn(const jau::nsize_t column) const noexcept
Get the named column of the given column-major matrix to v_out w/o boundary check.
value_type determinant() const noexcept
Returns the determinant of this matrix.
static bool mapWinToObj4(const value_type winx, const value_type winy, const value_type winz, const value_type clipw, const Matrix4 &mMv, const Matrix4 &mP, const Recti &viewport, const value_type near, const value_type far, Vec4 &objPos) noexcept
Map window coordinates to object coordinates.
constexpr_cxx26 Matrix4 & rotate(const value_type ang_rad, const value_type x, const value_type y, const value_type z) noexcept
Rotate this matrix about give axis and angle in radians, i.e.
Matrix4 & setToPerspective(const value_type fovy_rad, const value_type aspect, const value_type zNear, const value_type zFar)
Set this matrix to perspective frustum projection.
constexpr Matrix4 & translate(const Vec3 &t) noexcept
Translate this matrix, i.e.
constexpr bool equals(const Matrix4 &o, const value_type epsilon=std::numeric_limits< value_type >::epsilon()) const noexcept
const value_type & const_reference
constexpr Matrix4 & scale(const value_type x, const value_type y, const value_type z) noexcept
constexpr Vec3 & mulVec3(Vec3 &v_inout) const noexcept
Affine 3f-vector transformation by 4x4 matrix: v_inout = this * v_inout.
constexpr iterator begin() noexcept
static bool mapObjToWin(const Vec3 &obj, const Matrix4 &mPMv, const Recti &viewport, Vec3 &winPos) noexcept
Map object coordinates to window coordinates.
std::string toString(const std::string &rowPrefix, const std::string &f) const noexcept
static bool mapWinToObj(const value_type winx, const value_type winy, const value_type winz, const Matrix4 &mMv, const Matrix4 &mP, const Recti &viewport, Vec3 &objPos) noexcept
Map window coordinates to object coordinates.
Matrix4 & setToFrustum(const value_type left, const value_type right, const value_type bottom, const value_type top, const value_type zNear, const value_type zFar)
Set this matrix to frustum.
constexpr Vec3 operator*(const Vec3 &rhs) const noexcept
Returns new Vec3, with affine 3f-vector transformation by this 4x4 matrix: this x v_in.
constexpr Matrix4 & mul(const Matrix4 &a, const Matrix4 &b) noexcept
Multiply matrix: [this] = [a] x [b].
Matrix4 & transpose(const Matrix4 &src) noexcept
Transpose the given src matrix into this matrix.
constexpr Vec4 & getColumn(const jau::nsize_t column, Vec4 &v_out) const noexcept
Get the named column of the given column-major matrix to v_out w/o boundary check.
static bool mapWinToAny(const value_type winx, const value_type winy, const value_type winz, const Matrix4 &invAny, const Recti &viewport, Vec3 &objPos) noexcept
static bool mapObjToWin(const Vec3 &obj, const Matrix4 &mMv, const Matrix4 &mP, const Recti &viewport, Vec3 &winPos) noexcept
Map object coordinates to window coordinates.
constexpr Vec4 operator*(const Vec4 &rhs) const noexcept
Returns new Vec4, with this x v_in.
constexpr Vec4 & getRow(const jau::nsize_t row, Vec4 &v_out) const noexcept
Get the named row of the given column-major matrix to v_out w/ boundary check.
constexpr Matrix4 & operator*=(const Matrix4 &rhs) noexcept
Multiply matrix: [this] = [this] x [b].
constexpr Matrix4 & loadIdentity() noexcept
Set this matrix to identity.
constexpr Matrix4 & operator=(const Matrix4 &o) noexcept
Copy assignment using the the values of the given src matrix.
static constexpr const value_type half
constexpr bool setToPick(const value_type x, const value_type y, const value_type deltaX, const value_type deltaY, const Recti &viewport) noexcept
Set this matrix to the pick matrix based on given parameters.
static constexpr const value_type inv_deviation
static constexpr const value_type zero
static bool mapWinToObjRay(const value_type winx, const value_type winy, const value_type winz0, const value_type winz1, const Matrix4 &mMv, const Matrix4 &mP, const Recti &viewport, Ray3 &ray) noexcept
Map two window coordinates w/ shared X/Y and distinctive Z to a Ray in object space.
constexpr Vec4 & mulVec4(Vec4 &v_inout) const noexcept
std::string toString(const std::string &rowPrefix) const noexcept
Returns a formatted string representation of this matrix.
static bool mapWorldToWin(const Vec3 &world, const Matrix4 &mV, const Matrix4 &mP, const Recti &viewport, Vec3 &winPos) noexcept
Map world coordinates ( M x object ) to window coordinates.
constexpr Matrix4 & setToOrtho(const value_type left, const value_type right, const value_type bottom, const value_type top, const value_type zNear, const value_type zFar) noexcept
Set this matrix to orthogonal projection.
constexpr_cxx26 Matrix4 & setToRotationEuler(const value_type bankX, const value_type headingY, const value_type attitudeZ) noexcept
Set this matrix to rotation from the given Euler rotation angles in radians.
constexpr std::vector< value_type > & get(std::vector< value_type > &dst, size_t dst_off) const noexcept
Get this matrix into the given FloatBuffer in column major order.
static bool mapWinToAnyRay(const value_type winx, const value_type winy, const value_type winz0, const value_type winz1, const Matrix4 &invAny, const Recti &viewport, Ray3 &ray) noexcept
constexpr Matrix4 & setToScale(const Vec3 &s) noexcept
Set this matrix to scale.
Vector3F< value_type, std::is_floating_point_v< Value_type > > Vec3
constexpr Matrix4 & operator*=(const value_type s) noexcept
Multiply matrix with scalar: [this] = [this] x [s].
constexpr Matrix4(const_iterator m) noexcept
Creates a new matrix based on given value_type[4*4] column major order.
bool invert(const Matrix4 &src) noexcept
Invert the src matrix values into this matrix.
constexpr_cxx26 Matrix4 & rotate(const value_type ang_rad, const Vec3 &axis) noexcept
Rotate this matrix about give axis and angle in radians, i.e.
constexpr_cxx26 Matrix4 & setToRotationEuler(const Vec3 &angradXYZ) noexcept
Set this matrix to rotation from the given Euler rotation angles in radians.
constexpr Matrix4 & setToTranslation(const Vec3 &t) noexcept
Set this matrix to translation.
constexpr Matrix4() noexcept
Creates a new identity matrix.
const value_type * const_iterator
constexpr Matrix4 & mul(const Matrix4 &b) noexcept
Multiply matrix: [this] = [this] x [b].
constexpr Matrix4 & load(const_iterator src) noexcept
static bool mapWinToObj4(const value_type winx, const value_type winy, const value_type winz, const value_type clipw, const Matrix4 &invPMv, const Recti &viewport, const value_type near, const value_type far, Vec4 &objPos) noexcept
Map window coordinates to object coordinates.
constexpr Matrix4(const Matrix4 &o) noexcept
Creates a new matrix copying the values of the given src matrix.
constexpr Vec3 & getRow(const jau::nsize_t row, Vec3 &v_out) const noexcept
Get the named row of the given column-major matrix to v_out w/o boundary check.
constexpr Matrix4 & load(const Matrix4 &src) noexcept
Load the values of the given matrix src to this matrix w/o boundary check.
constexpr Matrix4 & setToTranslation(const value_type x, const value_type y, const value_type z) noexcept
Set this matrix to translation.
const value_type * const_pointer
static constexpr const value_type two
constexpr Matrix4(std::initializer_list< value_type > m) noexcept
Creates a new matrix based on given value_type initializer list in column major order.
constexpr Matrix4 & setToLookAt(const Vec3 &eye, const Vec3 ¢er, const Vec3 &up) noexcept
Set this matrix to the look-at matrix based on given parameters.
Quaternion implementation supporting Gimbal-Lock free rotations.
Simple compound denoting a ray.
3D vector using three value_type components.
constexpr Vector3F & normalize() noexcept
Normalize this vector in place.
constexpr Vector3F cross(const Vector3F &b) const noexcept
cross product this x b
4D vector using four value_type components.
constexpr Vec3 & getVec3(Vec3 &out) const noexcept
out = { this.x, this.y, this.z } dropping w, returns out.
constexpr Vector4F & mul(const Vector4F &s) noexcept
this = this * {s.x, s.y, s.z}, component wise.
constexpr Vector4F & add(const Vector4F &d) noexcept
this = this + {d.x, d.y, d.z, d.w}, component wise.
constexpr Vector4F & scale(const value_type s) noexcept
this = this * s, component wise.
Providing frustum planes derived by different inputs (P*MV, ..) used to classify objects.
#define DBG_PRINT(...)
Use for environment-variable environment::DEBUG conditional debug messages, prefix '[elapsed_time] De...
std::enable_if_t< std::is_floating_point_v< T >, bool > constexpr equals(const T &a, const T &b, const T &epsilon=std::numeric_limits< T >::epsilon()) noexcept
Returns true if both values are equal, i.e.
std::string & mat_to_string(std::string &sb, const std::string &rowPrefix, const std::string &f, const T a[], const jau::nsize_t rows, const jau::nsize_t columns, const bool rowMajorOrder) noexcept
Appends a matrix of floating points to the given string sb
uint_fast32_t nsize_t
Natural 'size_t' alternative using uint_fast32_t as its natural sized type.
constexpr Vector2F< T > max(const Vector2F< T > &lhs, const Vector2F< T > &rhs) noexcept
constexpr Matrix4< T > operator*(const Matrix4< T > &lhs, const Matrix4< T > &rhs) noexcept
std::ostream & operator<<(std::ostream &out, const Addr48Bit &a)