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>
156 : m00(*m), m10(*(++m)), m20(*(++m)), m30(*(++m)),
157 m01(*(++m)), m11(*(++m)), m21(*(++m)), m31(*(++m)),
158 m02(*(++m)), m12(*(++m)), m22(*(++m)), m32(*(++m)),
159 m03(*(++m)), m13(*(++m)), m23(*(++m)), m33(*(++m))
166 constexpr Matrix4(std::initializer_list<value_type> m) noexcept
169 assert(m.size() >= 16 );
226 explicit operator pointer() noexcept {
return &m00; }
241 m00 = m11 = m22 = m33 =
one;
245 m30 = m31 = m32 =
zero;
280 return load( src.cbegin() );
311 assert( column < 4 );
312 return v_out.set(
get(0+column*4),
324 assert( column < 4 );
338 return v_out.set(
get(0+column*4),
351 return v_out.set(
get( row + 0*4_unz),
354 get( row + 3*4_unz) );
378 return v_out.set(
get(row+0*4_unz),
417 constexpr std::vector<value_type>&
get(std::vector<value_type>& dst,
size_t dst_off)
const noexcept {
418 assert( dst.size() >= dst_off+16 && dst_off <= std::numeric_limits<size_t>::max() - 15 );
419 get( &dst[dst_off++] );
433 ret += m00 * ( + m11*(m22*m33 - m23*m32) - m12*(m21*m33 - m23*m31) + m13*(m21*m32 - m22*m31));
434 ret -= m01 * ( + m10*(m22*m33 - m23*m32) - m12*(m20*m33 - m23*m30) + m13*(m20*m32 - m22*m30));
435 ret += m02 * ( + m10*(m21*m33 - m23*m31) - m11*(m20*m33 - m23*m30) + m13*(m20*m31 - m21*m30));
436 ret -= m03 * ( + m10*(m21*m32 - m22*m31) - m11*(m20*m32 - m22*m30) + m12*(m20*m31 - m21*m30));
538 const value_type b00 = + a11*(a22*a33 - a23*a32) - a12*(a21*a33 - a23*a31) + a13*(a21*a32 - a22*a31);
539 const value_type b01 = -( + a10*(a22*a33 - a23*a32) - a12*(a20*a33 - a23*a30) + a13*(a20*a32 - a22*a30));
540 const value_type b02 = + a10*(a21*a33 - a23*a31) - a11*(a20*a33 - a23*a30) + a13*(a20*a31 - a21*a30);
541 const value_type b03 = -( + a10*(a21*a32 - a22*a31) - a11*(a20*a32 - a22*a30) + a12*(a20*a31 - a21*a30));
543 const value_type b10 = -( + a01*(a22*a33 - a23*a32) - a02*(a21*a33 - a23*a31) + a03*(a21*a32 - a22*a31));
544 const value_type b11 = + a00*(a22*a33 - a23*a32) - a02*(a20*a33 - a23*a30) + a03*(a20*a32 - a22*a30);
545 const value_type b12 = -( + a00*(a21*a33 - a23*a31) - a01*(a20*a33 - a23*a30) + a03*(a20*a31 - a21*a30));
546 const value_type b13 = + a00*(a21*a32 - a22*a31) - a01*(a20*a32 - a22*a30) + a02*(a20*a31 - a21*a30);
548 const value_type b20 = + a01*(a12*a33 - a13*a32) - a02*(a11*a33 - a13*a31) + a03*(a11*a32 - a12*a31);
549 const value_type b21 = -( + a00*(a12*a33 - a13*a32) - a02*(a10*a33 - a13*a30) + a03*(a10*a32 - a12*a30));
550 const value_type b22 = + a00*(a11*a33 - a13*a31) - a01*(a10*a33 - a13*a30) + a03*(a10*a31 - a11*a30);
551 const value_type b23 = -( + a00*(a11*a32 - a12*a31) - a01*(a10*a32 - a12*a30) + a02*(a10*a31 - a11*a30));
553 const value_type b30 = -( + a01*(a12*a23 - a13*a22) - a02*(a11*a23 - a13*a21) + a03*(a11*a22 - a12*a21));
554 const value_type b31 = + a00*(a12*a23 - a13*a22) - a02*(a10*a23 - a13*a20) + a03*(a10*a22 - a12*a20);
555 const value_type b32 = -( + a00*(a11*a23 - a13*a21) - a01*(a10*a23 - a13*a20) + a03*(a10*a21 - a11*a20));
556 const value_type b33 = + a00*(a11*a22 - a12*a21) - a01*(a10*a22 - a12*a20) + a02*(a10*a21 - a11*a20);
558 const value_type det = (a00*b00 + a01*b01 + a02*b02 + a03*b03) /
scale;
595 DBG_PRINT(
"Matrix4:invert(src): absMax==0: %s", src.toString().c_str());
619 const value_type b00 = + a11*(a22*a33 - a23*a32) - a12*(a21*a33 - a23*a31) + a13*(a21*a32 - a22*a31);
620 const value_type b01 = -( + a10*(a22*a33 - a23*a32) - a12*(a20*a33 - a23*a30) + a13*(a20*a32 - a22*a30));
621 const value_type b02 = + a10*(a21*a33 - a23*a31) - a11*(a20*a33 - a23*a30) + a13*(a20*a31 - a21*a30);
622 const value_type b03 = -( + a10*(a21*a32 - a22*a31) - a11*(a20*a32 - a22*a30) + a12*(a20*a31 - a21*a30));
624 const value_type b10 = -( + a01*(a22*a33 - a23*a32) - a02*(a21*a33 - a23*a31) + a03*(a21*a32 - a22*a31));
625 const value_type b11 = + a00*(a22*a33 - a23*a32) - a02*(a20*a33 - a23*a30) + a03*(a20*a32 - a22*a30);
626 const value_type b12 = -( + a00*(a21*a33 - a23*a31) - a01*(a20*a33 - a23*a30) + a03*(a20*a31 - a21*a30));
627 const value_type b13 = + a00*(a21*a32 - a22*a31) - a01*(a20*a32 - a22*a30) + a02*(a20*a31 - a21*a30);
629 const value_type b20 = + a01*(a12*a33 - a13*a32) - a02*(a11*a33 - a13*a31) + a03*(a11*a32 - a12*a31);
630 const value_type b21 = -( + a00*(a12*a33 - a13*a32) - a02*(a10*a33 - a13*a30) + a03*(a10*a32 - a12*a30));
631 const value_type b22 = + a00*(a11*a33 - a13*a31) - a01*(a10*a33 - a13*a30) + a03*(a10*a31 - a11*a30);
632 const value_type b23 = -( + a00*(a11*a32 - a12*a31) - a01*(a10*a32 - a12*a30) + a02*(a10*a31 - a11*a30));
634 const value_type b30 = -( + a01*(a12*a23 - a13*a22) - a02*(a11*a23 - a13*a21) + a03*(a11*a22 - a12*a21));
635 const value_type b31 = + a00*(a12*a23 - a13*a22) - a02*(a10*a23 - a13*a20) + a03*(a10*a22 - a12*a20);
636 const value_type b32 = -( + a00*(a11*a23 - a13*a21) - a01*(a10*a23 - a13*a20) + a03*(a10*a21 - a11*a20));
637 const value_type b33 = + a00*(a11*a22 - a12*a21) - a01*(a10*a22 - a12*a20) + a02*(a10*a21 - a11*a20);
639 const value_type det = (a00*b00 + a01*b01 + a02*b02 + a03*b03) /
scale;
642 DBG_PRINT(
"Matrix4:invert(src): det==0: %s", src.toString().c_str());
671 value_type absMax() const noexcept {
672 value_type
max = std::abs(m00);
673 max = std::max(
max, std::abs(m01));
674 max = std::max(
max, std::abs(m02));
675 max = std::max(
max, std::abs(m03));
677 max = std::max(
max, std::abs(m10));
678 max = std::max(
max, std::abs(m11));
679 max = std::max(
max, std::abs(m12));
680 max = std::max(
max, std::abs(m13));
682 max = std::max(
max, std::abs(m20));
683 max = std::max(
max, std::abs(m21));
684 max = std::max(
max, std::abs(m22));
685 max = std::max(
max, std::abs(m23));
687 max = std::max(
max, std::abs(m30));
688 max = std::max(
max, std::abs(m31));
689 max = std::max(
max, std::abs(m32));
690 max = std::max(
max, std::abs(m33));
701 m00 *= s; m10 *= s; m20 *= s; m30 *= s;
702 m01 *= s; m11 *= s; m21 *= s; m31 *= s;
703 m02 *= s; m12 *= s; m22 *= s; m32 *= s;
704 m03 *= s; m13 *= s; m23 *= s; m33 *= s;
720 m00 = ai0 * b.m00 + ai1 * b.m10 + ai2 * b.m20 + ai3 * b.m30 ;
721 m01 = ai0 * b.m01 + ai1 * b.m11 + ai2 * b.m21 + ai3 * b.m31 ;
722 m02 = ai0 * b.m02 + ai1 * b.m12 + ai2 * b.m22 + ai3 * b.m32 ;
723 m03 = ai0 * b.m03 + ai1 * b.m13 + ai2 * b.m23 + ai3 * b.m33 ;
729 m10 = ai0 * b.m00 + ai1 * b.m10 + ai2 * b.m20 + ai3 * b.m30 ;
730 m11 = ai0 * b.m01 + ai1 * b.m11 + ai2 * b.m21 + ai3 * b.m31 ;
731 m12 = ai0 * b.m02 + ai1 * b.m12 + ai2 * b.m22 + ai3 * b.m32 ;
732 m13 = ai0 * b.m03 + ai1 * b.m13 + ai2 * b.m23 + ai3 * b.m33 ;
738 m20 = ai0 * b.m00 + ai1 * b.m10 + ai2 * b.m20 + ai3 * b.m30 ;
739 m21 = ai0 * b.m01 + ai1 * b.m11 + ai2 * b.m21 + ai3 * b.m31 ;
740 m22 = ai0 * b.m02 + ai1 * b.m12 + ai2 * b.m22 + ai3 * b.m32 ;
741 m23 = ai0 * b.m03 + ai1 * b.m13 + ai2 * b.m23 + ai3 * b.m33 ;
747 m30 = ai0 * b.m00 + ai1 * b.m10 + ai2 * b.m20 + ai3 * b.m30 ;
748 m31 = ai0 * b.m01 + ai1 * b.m11 + ai2 * b.m21 + ai3 * b.m31 ;
749 m32 = ai0 * b.m02 + ai1 * b.m12 + ai2 * b.m22 + ai3 * b.m32 ;
750 m33 = ai0 * b.m03 + ai1 * b.m13 + ai2 * b.m23 + ai3 * b.m33 ;
772 m00 = a.m00 * b.m00 + a.m01 * b.m10 + a.m02 * b.m20 + a.m03 * b.m30 ;
773 m01 = a.m00 * b.m01 + a.m01 * b.m11 + a.m02 * b.m21 + a.m03 * b.m31 ;
774 m02 = a.m00 * b.m02 + a.m01 * b.m12 + a.m02 * b.m22 + a.m03 * b.m32 ;
775 m03 = a.m00 * b.m03 + a.m01 * b.m13 + a.m02 * b.m23 + a.m03 * b.m33 ;
778 m10 = a.m10 * b.m00 + a.m11 * b.m10 + a.m12 * b.m20 + a.m13 * b.m30 ;
779 m11 = a.m10 * b.m01 + a.m11 * b.m11 + a.m12 * b.m21 + a.m13 * b.m31 ;
780 m12 = a.m10 * b.m02 + a.m11 * b.m12 + a.m12 * b.m22 + a.m13 * b.m32 ;
781 m13 = a.m10 * b.m03 + a.m11 * b.m13 + a.m12 * b.m23 + a.m13 * b.m33 ;
784 m20 = a.m20 * b.m00 + a.m21 * b.m10 + a.m22 * b.m20 + a.m23 * b.m30 ;
785 m21 = a.m20 * b.m01 + a.m21 * b.m11 + a.m22 * b.m21 + a.m23 * b.m31 ;
786 m22 = a.m20 * b.m02 + a.m21 * b.m12 + a.m22 * b.m22 + a.m23 * b.m32 ;
787 m23 = a.m20 * b.m03 + a.m21 * b.m13 + a.m22 * b.m23 + a.m23 * b.m33 ;
790 m30 = a.m30 * b.m00 + a.m31 * b.m10 + a.m32 * b.m20 + a.m33 * b.m30 ;
791 m31 = a.m30 * b.m01 + a.m31 * b.m11 + a.m32 * b.m21 + a.m33 * b.m31 ;
792 m32 = a.m30 * b.m02 + a.m31 * b.m12 + a.m32 * b.m22 + a.m33 * b.m32 ;
793 m33 = a.m30 * b.m03 + a.m31 * b.m13 + a.m32 * b.m23 + a.m33 * b.m33 ;
805 const value_type x = v_in.x, y = v_in.y, z = v_in.z, w = v_in.w;
806 v_out.set( x * m00 + y * m01 + z * m02 + w * m03,
807 x * m10 + y * m11 + z * m12 + w * m13,
808 x * m20 + y * m21 + z * m22 + w * m23,
809 x * m30 + y * m31 + z * m32 + w * m33 );
819 const value_type x = rhs.x, y = rhs.y, z = rhs.z, w = rhs.w;
820 return Vec4( x * m00 + y * m01 + z * m02 + w * m03,
821 x * m10 + y * m11 + z * m12 + w * m13,
822 x * m20 + y * m21 + z * m22 + w * m23,
823 x * m30 + y * m31 + z * m32 + w * m33 );
832 const value_type x = v_inout.x, y = v_inout.y, z = v_inout.z, w = v_inout.w;
833 v_inout.set( x * m00 + y * m01 + z * m02 + w * m03,
834 x * m10 + y * m11 + z * m12 + w * m13,
835 x * m20 + y * m21 + z * m22 + w * m23,
836 x * m30 + y * m31 + z * m32 + w * m33 );
853 const value_type x = v_in.x, y = v_in.y, z = v_in.z;
854 v_out.set( x * m00 + y * m01 + z * m02 +
one * m03,
855 x * m10 + y * m11 + z * m12 +
one * m13,
856 x * m20 + y * m21 + z * m22 +
one * m23 );
870 const value_type x = rhs.x, y = rhs.y, z = rhs.z;
871 return Vec3( x * m00 + y * m01 + z * m02 +
one * m03,
872 x * m10 + y * m11 + z * m12 +
one * m13,
873 x * m20 + y * m21 + z * m22 +
one * m23 );
888 const value_type x = v_inout.x, y = v_inout.y, z = v_inout.z;
889 v_inout.set( x * m00 + y * m01 + z * m02 +
one * m03,
890 x * m10 + y * m11 + z * m12 +
one * m13,
891 x * m20 + y * m21 + z * m22 +
one * m23 );
914 m00 = m11 = m22 = m33 =
one;
921 m30 = m31 = m32 =
zero;
963 m30 = m31 = m32 =
zero;
1005 x = tmp.
x; y = tmp.
y; z = tmp.
z;
1091 m01 = sh*sb - ch*sa*cb;
1093 m21 = sh*sa*cb + ch*sb;
1096 m02 = ch*sa*sb + sh*cb;
1098 m22 = -sh*sa*sb + ch*cb;
1183 m10 = m20 = m30 =
zero;
1184 m01 = m21 = m31 =
zero;
1185 m02 = m12 = m32 =
zero;
1229 if( zNear <=
zero || zFar <= zNear ) {
1232 if( left == right || top == bottom) {
1237 m10 = m20 = m30 =
zero;
1238 m01 = m21 = m31 =
zero;
1280 return setToFrustum(left, right, bottom, top, zNear, zFar);
1300 return setToFrustum(left, right, bottom, top, zNear, zFar);
1324 const Vec3 fwd = ( center - eye ).normalize();
1387 const Recti& viewport)
noexcept {
1388 if (deltaX <= 0 || deltaY <= 0) {
1393 ( viewport.height() -
two * ( y - viewport.y() ) ) / deltaY,
1396 mat4Tmp.
setToScale( viewport.width() / deltaX, viewport.height() / deltaY,
one );
1508 const Recti& viewport,
Vec3& winPos)
noexcept
1512 return mapToWinImpl(rawWin, viewport, winPos);
1528 const Recti& viewport,
Vec3& winPos)
noexcept
1531 return mapToWinImpl(rawWin, viewport, winPos);
1545 const Recti& viewport,
Vec3& winPos)
noexcept
1548 return mapToWinImpl(rawWin, viewport, winPos);
1561 const Recti& viewport,
Vec3& winPos)
noexcept
1564 return mapToWinImpl(rawWin, viewport, winPos);
1568 static bool mapToWinImpl(Vec4& rawWin,
1569 const Recti& viewport, Vec3& winPos)
noexcept
1571 if ( zero == rawWin.w ) {
1575 const value_type s = (
one / rawWin.w ) * half;
1578 rawWin.scale(s).add(half, half, half, zero);
1581 winPos.set( rawWin.x * viewport.width() + viewport.x(),
1582 rawWin.y * viewport.height() + viewport.y(),
1605 const Recti& viewport,
1606 Vec3& objPos)
noexcept
1610 invPMv.
mul(mP, mMv);
1614 return mapWinToAny(winx, winy, winz, invPMv, viewport, objPos);
1630 const Recti& viewport,
1631 Vec3& viewPos)
noexcept
1638 return mapWinToAny(winx, winy, winz, invP, viewport, viewPos);
1662 const Recti& viewport,
1663 Vec3& objPos)
noexcept
1665 Vec4 winPos(winx, winy, winz,
one);
1674 Vec4 rawObjPos = invAny * winPos;
1676 if (
zero == rawObjPos.
w ) {
1708 const Recti& viewport,
1709 Vec3& objPos1,
Vec3& objPos2)
noexcept
1711 Vec4 winPos(winx, winy, winz1,
one);
1720 Vec4 rawObjPos = invAny * winPos;
1722 if (
zero == rawObjPos.
w ) {
1734 invAny.mulVec4(winPos, rawObjPos);
1736 if (
zero == rawObjPos.
w ) {
1763 const Recti& viewport,
1765 Vec4& objPos)
noexcept
1769 invPMv.
mul(mP, mMv);
1774 invPMv, viewport, near, far, objPos);
1796 const Recti& viewport,
1798 Vec4& objPos)
noexcept
1800 Vec4 winPos(winx, winy, winz, clipw);
1803 winPos.
add(-viewport.x(), -viewport.y(), -near,
zero).
mul(
one/viewport.width(),
one/viewport.height(),
one/(far-near),
one);
1809 invPMv.mulVec4(winPos, objPos);
1811 if (
zero == objPos.w ) {
1841 const Recti& viewport,
1846 invPMv.
mul(mP, mMv);
1850 return mapWinToAnyRay(winx, winy, winz0, winz1, invPMv, viewport, ray);
1877 const Recti& viewport,
1885 return mapWinToAnyRay(winx, winy, winz0, winz1, invP, viewport, ray);
1917 const Recti& viewport,
1920 if(
mapWinToAny(winx, winy, winz0, winz1, invAny, viewport, ray.orig, ray.dir) ) {
1921 (ray.dir -= ray.orig).normalize();
1933 std::string
toString(
const std::string& rowPrefix,
const std::string& f)
const noexcept {
1944 std::string
toString(
const std::string& rowPrefix)
const noexcept {
return toString(rowPrefix,
"%13.9f"); }
1950 std::enable_if_t<std::is_floating_point_v<T>,
bool> =
true>
1956 std::enable_if_t<std::is_floating_point_v<T>,
bool> =
true>
1962 std::enable_if_t<std::is_floating_point_v<T>,
bool> =
true>
1968 std::enable_if_t<std::is_floating_point_v<T>,
bool> =
true>
1970 return out << v.toString();
1975static_assert(
alignof(float) ==
alignof(
Mat4f));
1976static_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.
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,...
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 Matrix4 & scale(const Vec3 &sxyz) noexcept
Scale this matrix, i.e.
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.
Quaternion< value_type, std::is_floating_point_v< Value_type > > Quat
Matrix4 & rotate(const Quat &quat) noexcept
Rotate this matrix with the given Quaternion, i.e.
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.
Vector4F< value_type > Vec4
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.
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.
Vector3F< value_type > Vec3
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
Quat & getRotation(Quat &res) const noexcept
Returns the rotation [m00 .
constexpr Matrix4< T > operator*(const Matrix4< T > &lhs, const Matrix4< T > &rhs) noexcept
Matrix4 & setToRotation(const Quat &q)
Set this matrix to rotation using the given Quaternion.
std::ostream & operator<<(std::ostream &out, const Addr48Bit &a)