12#ifndef JAU_MATH_UTIL_PMVMAT4f_HPP_
13#define JAU_MATH_UTIL_PMVMAT4f_HPP_
40 using namespace jau::enums;
115template <jau::req::packed_
floating_po
int Value_type>
197 : m_requestBits( matToReq(derivedMatrices) )
208 const PMVData requestBits = matToReq(derivedMatrices);
211 if( m == ( m & requestBits ) ) {
217 if( m == ( m & requestBits ) ) {
230 m_matP.loadIdentity();
231 m_matMv.loadIdentity();
232 m_matTex.loadIdentity();
251 constexpr Mat4&
getT() noexcept {
return m_matTex; }
252 constexpr const Mat4&
getT() const noexcept {
return m_matTex; }
264 constexpr const Mat4&
getP() const noexcept {
return m_matP; }
276 constexpr const Mat4&
getMv() const noexcept {
return m_matMv; }
422 if( m == ( m & m_requestBits ) ) {
428 if( m == ( m & m_requestBits ) ) {
448 return result.mul(m_matP, m_matMv);
460 return result.mul(m_matMv, m_matP);
470 return m_matMv.mulVec4(v_in, v_out);
479 return m_matMv.mulVec4(v_inout);
492 return m_matMv.mulVec3(v_in, v_out);
503 m_matMv.load(values);
519 quat.toMatrix(m_matMv);
544 quat.toMatrix(m_matP);
553 m_matTex.load(values);
569 quat.toMatrix(m_matTex);
578 m_matMv.loadIdentity();
587 m_matP.loadIdentity();
596 m_matTex.loadIdentity();
753 return mulMv( quat.toMatrix(mat4Tmp1) );
791 return mulP( quat.toMatrix(mat4Tmp1) );
796 m_stackMv.pop(m_matMv);
802 m_stackP.pop(m_matP);
808 m_stackTex.pop(m_matTex);
814 m_stackMv.push(m_matMv);
819 m_stackP.push(m_matP);
824 m_stackTex.push(m_matTex);
838 constexpr void orthoP(
const float left,
const float right,
const float bottom,
const float top,
const float zNear,
const float zFar)
noexcept {
840 mulP( mat4Tmp1.
setToOrtho(left, right, bottom, top, zNear, zFar) );
850 void frustumP(
const float left,
const float right,
const float bottom,
const float top,
const float zNear,
const float zFar) {
896 m_matMv.setToLookAt(eye, center, up);
968 bool mapWinToObj(
const float winx,
const float winy,
const float winz,
969 const Recti& viewport,
Vec3& objPos)
noexcept {
994 const Mat4& matVi,
const Recti& viewport,
Vec3& objPos)
noexcept {
1015 const Recti& viewport,
Vec3& objPos)
noexcept {
1039 bool mapWinToObj4(
const float winx,
const float winy,
const float winz,
const float clipw,
1040 const Recti& viewport,
const float near,
const float far,
Vec4& objPos)
const noexcept {
1068 bool mapWinToObjRay(
const float winx,
const float winy,
const float winz0,
const float winz1,
1069 const Recti& viewport,
Ray3f& ray)
noexcept {
1102 bool mapWinToWorldRay(
const float winx,
const float winy,
const float winz0,
const float winz1,
1129 bool mapWinToViewRay(
const float winx,
const float winy,
const float winz0,
const float winz1,
1130 const Recti& viewport,
Ray3f& ray)
noexcept {
1134 std::string&
toString(std::string& sb,
const std::string&
f)
const noexcept {
1137 sb.append(
"PMVMatrix4[req").append(
to_string(m_requestBits))
1138 .append(
", mod1").append(
to_string(m_dirtyBits))
1139 .append(
", mod2").append(
to_string(m_modifiedBits))
1140 .append(
", Projection\n");
1141 m_matP.toString(sb,
f);
1142 sb.append(
", Modelview\n");
1143 m_matMv.toString(sb,
f);
1144 sb.append(
", Texture\n");
1145 m_matTex.toString(sb,
f);
1147 sb.append(
", P * Mv\n");
1148 m_matPMv.toString(sb,
f);
1152 sb.append(
", P * Mv\n");
1153 m_matPMvi.toString(sb,
f);
1157 sb.append(
", Inverse Modelview\n");
1158 m_matMvi.toString(sb,
f);
1162 sb.append(
", Inverse Transposed Modelview\n");
1163 m_matMvit.toString(sb,
f);
1170 sb.append(
", matrices "+std::to_string(count)+
" + "+std::to_string(tmpCount)+
" temp = "+std::to_string(count+tmpCount)+
"]");
1195 const PMVMod r = m_modifiedBits;
1257 return has_any(m_dirtyBits, m_requestBits);
1322 m_matPMv.mul(m_matP, m_matMv);
1345 m_matPMviOK = m_matPMvi.invert(mPMv);
1366 m_frustum.setFromMat(
getPMv());
1416 return updateImpl(
true);
1424 void updateImpl0() noexcept { updateImpl(
false); }
1425 bool updateImpl(
bool clearModBits)
noexcept {
1426 bool mod =
has_any(m_modifiedBits);
1427 if( clearModBits ) {
1432 if( !m_matPi.
invert(m_matP) ) {
1441 if( !m_matMvi.invert(m_matMv) ) {
1450 m_matMvit.transpose(m_matMvi);
1458template <jau::req::packed_
floating_po
int Value_type>
1460 return out << v.toString();
Basic 4x4 value_type matrix implementation using fields for intensive use-cases (host operations).
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
static bool mapObjToWin(const Vec3 &obj, const Matrix4 &mPMv, const Recti &viewport, Vec3 &winPos) noexcept
static bool mapWorldToWin(const Vec3 &world, const Matrix4 &mV, const Matrix4 &mP, const Recti &viewport, Vec3 &winPos) noexcept
bool invert() noexcept
Invert this matrix.
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_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 & mul(const Matrix4 &b) noexcept
Multiply matrix: [this] = [this] x [b].
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
constexpr Matrix4 & setToTranslation(const value_type x, const value_type y, const value_type z) noexcept
Set this matrix to translation.
constexpr Matrix4 & setToScale(const value_type x, const value_type y, const value_type z) noexcept
Set this matrix to scale.
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 mapViewToWin(const Vec3 &view, const Matrix4 &mP, const Recti &viewport, Vec3 &winPos) noexcept
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.
std::string toString(const std::string &rowPrefix, const std::string_view f) const noexcept
Returns a formatted string representation of this matrix.
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.
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.
Simple compound denoting a ray.
3D vector using three value_type components.
4D vector using four value_type components.
Providing frustum planes derived by different inputs (P*MV, ..) used to classify objects.
A Matrix stack of compounds, each consisting of 16 * T
PMVMatrix4 implements the basic computer graphics Matrix4 pack using projection (P),...
PMVMatrix4() noexcept
Creates an instance of PMVMatrix4.
constexpr PMVMatrix4 & scaleMv(const Vec3 &s) noexcept
Scale the modelview matrix.
constexpr void setModelviewDirty() noexcept
Sets the Modelview (Mv) matrix dirty and modified, i.e.
constexpr PMVMatrix4 & scaleP(float x, float y, float z) noexcept
Scale the projection matrix.
SyncMats4f makeSyncPMvReq()
Returns a new SyncMatrices4f of either 4 matrices makeSyncPMvMviMvit(), 3 matrices makeSyncPMvMvi() o...
constexpr Mat4 & getMulMvP(Mat4 &result) noexcept
Returns multiplication result of Mv and P matrix, i.e.
constexpr PMVMod getModifiedBits(const bool clear) noexcept
Returns the modified bits due to mutable operations.
constexpr PMVMatrix4 & loadMv(float values[]) noexcept
Load the modelview matrix with the provided values.
constexpr PMVMatrix4 & mulP(const Mat4 &m) noexcept
Multiply the projection matrix: [c] = [c] x [m].
Matrix4< value_type > Mat4
constexpr const Mat4 & getT() const noexcept
constexpr PMVData requestedBits() noexcept
Returns the request bit mask, which uses bit values equal to the dirty mask and may contain.
bool update() noexcept
Update the derived inverse modelview (Mvi), inverse transposed modelview (Mvit) matrices if they are ...
PMVMatrix4(PMVData derivedMatrices) noexcept
Creates an instance of PMVMatrix4.
bool mapWinToViewRay(const float winx, const float winy, const float winz0, const float winz1, const Recti &viewport, Ray3f &ray) noexcept
Map two window coordinates w/ shared X/Y and distinctive Z to a Ray in view space.
constexpr PMVMatrix4 & rotateP(const Quat4f &quat) noexcept
Rotate the projection matrix with the given Quaternion's rotation matrix representation.
void frustumP(const float left, const float right, const float bottom, const float top, const float zNear, const float zFar)
Multiply the projection matrix with the frustum matrix.
constexpr PMVMatrix4 & mulMv(const Mat4 &m) noexcept
Multiply the modelview matrix: [c] = [c] x [m].
constexpr PMVMatrix4 & loadP(const Mat4 &m)
Load the projection matrix with the values of the given Mat4.
constexpr Vec4 & mulWithMv(const Vec4 &v_in, Vec4 &v_out) noexcept
v_out = Mv x v_in
static size_t matrixCount(PMVData derivedMatrices) noexcept
Return the number of Mat4 referenced by matrices()
constexpr const Mat4 & getP() const noexcept
constexpr Mat4 & getP() noexcept
Returns the projection matrix (P).
Vector4F< value_type > Vec4
constexpr SyncMats4 makeSyncMv() noexcept
Returns a new SyncMatrix of modelview matrix (Mv).
SyncMats4f makeSyncPMv() noexcept
Returns a new SyncMatrices4f of 2 matrices within one FloatBuffer: P and Mv.
SyncMats4f makeSyncPMvMviMvit()
Returns a new SyncMatrices4f of 4 matrices within one FloatBuffer: P, Mv, Mvi and Mvit if requested.
constexpr PMVMatrix4 & loadMv(const Mat4 &m) noexcept
Load the modelview matrix with the values of the given Mat4.
constexpr PMVMatrix4 & scaleP(const Vec3 &s) noexcept
Scale the projection matrix.
constexpr PMVMatrix4 & translateMv(float x, float y, float z) noexcept
Translate the modelview matrix.
std::string toString() const noexcept
constexpr_cxx26 PMVMatrix4 & rotateMv(const float ang_rad, const float x, const float y, const float z) noexcept
Rotate the modelview matrix by the given axis and angle in radians.
bool mapWinToWorld(const float winx, const float winy, const float winz, const Mat4 &matVi, const Recti &viewport, Vec3 &objPos) noexcept
Map window coordinates to object coordinates.
std::string & toString(std::string &sb, const std::string &f) const noexcept
const value_type * const_pointer
constexpr Vec3 & mulWithMv(const Vec3 &v_in, Vec3 &v_out) noexcept
v_out = Mv x v_in
constexpr_cxx26 PMVMatrix4 & rotateP(const float ang_rad, const float x, const float y, const float z) noexcept
Rotate the projection matrix by the given axis and angle in radians.
bool mapWinToWorldRay(const float winx, const float winy, const float winz0, const float winz1, const Mat4 &matVi, const Recti &viewport, Ray3f &ray) noexcept
Map two window coordinates w/ shared X/Y and distinctive Z to a Ray in world space.
const Mat4 & getPi()
Returns the inverse modelview matrix (Pi) if requested.
const Mat4 & getMvi()
Returns the inverse modelview matrix (Mvi) if requested.
constexpr bool isReqDirty() noexcept
Returns true if the one of the requested bits are are set dirty due to mutable operations,...
constexpr PMVMatrix4 & loadT(Mat4 &m) noexcept
Load the texture matrix with the values of the given Mat4.
bool mapWinToObj4(const float winx, const float winy, const float winz, const float clipw, const Recti &viewport, const float near, const float far, Vec4 &objPos) const noexcept
Map window coordinates to object coordinates.
constexpr PMVMatrix4 & lookAtMv(const Vec3 &eye, const Vec3 ¢er, const Vec3 &up) noexcept
Multiply the modelview matrix with the eye, object and orientation (camera), i.e.
constexpr_cxx20 PMVMatrix4 & popMv() noexcept
Pop the modelview matrix from its stack.
Vector3F< value_type > Vec3
const value_type * const_iterator
SyncMats4 makeSyncMvi()
Returns a new SyncMatrix of inverse modelview matrix (Mvi) if requested.
constexpr PMVMatrix4 & loadP(const Quat4f &quat) noexcept
Load the projection matrix with the values of the given Quaternion's rotation Quaternion::toMatrix() ...
constexpr Mat4 & getT() noexcept
Returns the texture matrix (T).
constexpr Vec4 & mulWithMv(Vec4 &v_inout) noexcept
v_inout = Mv x v_inout
const Mat4 & getMvit()
Returns the inverse transposed modelview matrix (Mvit) if requested.
constexpr PMVMatrix4 & translateMv(const Vec3 &t) noexcept
Translate the modelview matrix.
constexpr PMVMatrix4 & mulT(const Mat4 &m) noexcept
Multiply the texture matrix: [c] = [c] x [m].
PMVMatrix4 & perspectiveP(const float fovy_rad, const float aspect, const float zNear, const float zFar)
Multiply the projection matrix with the perspective/frustum matrix.
PMVMatrix4 & setToPerspective(const float fovy_rad, const float aspect, const float zNear, const float zFar)
Set the projection matrix to the perspective/frustum matrix.
constexpr PMVMatrix4 & loadMvIdentity() noexcept
Load the modelview matrix with the values of the given Mat4.
constexpr Mat4 & getMulPMv(Mat4 &result) noexcept
Returns multiplication result of P and Mv matrix, i.e.
constexpr void setTextureDirty() noexcept
Sets the Texture (T) matrix modified.
constexpr_cxx20 PMVMatrix4 & pushT() noexcept
Push the texture matrix to its stack, while preserving its values.
constexpr PMVMatrix4 & loadTIdentity() noexcept
Load the texture matrix with the values of the given Mat4.
constexpr PMVMatrix4 & loadT(const Quat4f &quat) noexcept
Load the texture matrix with the values of the given Quaternion's rotation Quaternion::toMatrix() rep...
constexpr PMVMatrix4 & rotateMv(const Quat4f &quat) noexcept
Rotate the modelview matrix with the given Quaternion's rotation matrix representation.
constexpr void orthoP(const float left, const float right, const float bottom, const float top, const float zNear, const float zFar) noexcept
Multiply the projection matrix with the orthogonal matrix.
bool mapViewToWin(const Vec3 &view, const Recti &viewport, Vec3 &winPos) const noexcept
Map view coordinates ( Mv x object ) to window coordinates.
constexpr PMVMatrix4 & loadP(float values[]) noexcept
Load the projection matrix with the provided values.
constexpr const Mat4 & getMv() const noexcept
bool mapWinToObjRay(const float winx, const float winy, const float winz0, const float winz1, const Recti &viewport, Ray3f &ray) noexcept
Map two window coordinates w/ shared X/Y and distinctive Z to a Ray in object space.
bool mapWorldToWin(const Vec3 &objPos, const Mat4 &matV, const Recti &viewport, Vec3 &winPos) const noexcept
Map world coordinates to window coordinates.
constexpr SyncMats4 makeSyncP() noexcept
Returns a new SyncMatrix of projection matrix (P).
constexpr_cxx20 PMVMatrix4 & popT() noexcept
Pop the texture matrix from its stack.
constexpr PMVMatrix4 & translateP(float x, float y, float z) noexcept
Translate the projection matrix.
constexpr PMVMatrix4 & translateP(const Vec3 &t) noexcept
Translate the projection matrix.
constexpr Mat4 & getPMvi() noexcept
Returns the pre-multiplied inverse projection x modelview, if Mat4#invert(Mat4) succeeded,...
SyncMats4f makeSyncPMvMvi()
Returns a new SyncMatrices4f of 3 matrices within one FloatBuffer: P, Mv and Mvi if requested.
constexpr PMVMatrix4 & scaleMv(float x, float y, float z) noexcept
Scale the modelview matrix.
bool mapWinToView(const float winx, const float winy, const float winz, const Recti &viewport, Vec3 &objPos) noexcept
Map window coordinates to view coordinates.
constexpr PMVMatrix4 & loadMv(const Quat4f &quat) noexcept
Load the modelview matrix with the values of the given Quaternion's rotation Quaternion::toMatrix() r...
constexpr_cxx20 PMVMatrix4 & pushP() noexcept
Push the projection matrix to its stack, while preserving its values.
constexpr_cxx26 PMVMatrix4 & rotateMv(const float ang_rad, const Vec3 &axis) noexcept
Rotate the modelview matrix by the given axis and angle in radians.
SyncMats4 makeSyncT() noexcept
Returns a new SyncMatrix of texture matrix (T).
constexpr Mat4 & getPMv() noexcept
Returns the pre-multiplied projection x modelview, P x Mv.
const jau::type_info & compSignature() const noexcept
Returns the component's value_type signature.
constexpr void setProjectionDirty() noexcept
Sets the Projection (P) matrix dirty and modified, i.e.
constexpr PMVMatrix4 & loadPIdentity() noexcept
Load the projection matrix with the values of the given Mat4.
jau::math::geom::Frustum getFrustum() noexcept
Returns the frustum, derived from projection x modelview.
SyncMatrices4< value_type > SyncMats4
constexpr_cxx20 PMVMatrix4 & popP() noexcept
Pop the projection matrix from its stack.
bool mapWinToObj(const float winx, const float winy, const float winz, const Recti &viewport, Vec3 &objPos) noexcept
Map window coordinates to object coordinates.
constexpr void reset() noexcept
Issues Mat4#loadIdentity() on all matrices and resets all internal states.
const value_type & const_reference
constexpr PMVMatrix4 & loadT(float values[]) noexcept
Load the texture matrix with the provided values.
constexpr Mat4 & getMv() noexcept
Returns the modelview matrix (Mv).
constexpr_cxx20 PMVMatrix4 & pushMv() noexcept
Push the modelview matrix to its stack, while preserving its values.
size_t matrixCount() const noexcept
Return the number of Mat4 referenced by matrices()
bool mapObjToWin(const Vec3 &objPos, const Recti &viewport, Vec3 &winPos) const noexcept
Map object coordinates to window coordinates.
SyncMats4 makeSyncMvit()
Returns a new SyncMatrix of inverse transposed modelview matrix (Mvit) if requested.
constexpr PMVData getDirtyBits() noexcept
Returns the dirty bits due to mutable operations, i.e.
constexpr_cxx26 PMVMatrix4 & rotateP(const float ang_rad, const Vec3 &axis) noexcept
Rotate the projection matrix by the given axis and angle in radians.
constexpr PMVMatrix4 & setToLookAtMv(const Vec3 &eye, const Vec3 ¢er, const Vec3 &up) noexcept
Set the modelview matrix to the eye, object and orientation (camera), i.e.
SyncBuffer interface with multiple underlying Matrix4.
Generic type information using either Runtime type information (RTTI) or Compile time type informatio...
#define DBG_ERR_PRINT(...)
Use for environment-variable environment::DEBUG conditional error messages, prefix '[elapsed_time] Wa...
constexpr bool has_any(const E mask, const E bits) noexcept
#define constexpr_cxx20
constexpr qualifier replacement for C++20 constexpr.
#define JAU_MAKE_BITFIELD_ENUM_STRING(type,...)
constexpr bool is_set(const E mask, const E bits) noexcept
std::ostream & operator<<(std::ostream &os, const T v)
const jau::type_info & static_ctti() noexcept
Returns a static global reference of make_ctti<T>(true) w/ identity instance.
jau::function< R(A...)> bind_member(C1 *base, R(C0::*mfunc)(A...)) noexcept
Bind given class instance and non-void member function to an anonymous function using func_member_tar...
SyncMatrices4< float > SyncMats4f
PMVMod
PMVMatrix4 modified core matrices.
PMVData
PMVMatrix4 derived matrices and values.
Quaternion< float > Quat4f
std::string to_string(const math_error_t v) noexcept
Returns std::string representation of math_error_t.
PMVMatrix4< float > PMVMat4f
@ text
Bit value stating a modified texture matrix (T), since last update() call.
@ proj
Bit value stating a modified projection matrix (P), since last update() call.
@ mv
Bit value stating a modified modelview matrix (Mv), since last update() call.
@ all
Bit value stating all is modified.
@ pre_pmvi
Bit value for pre-multiplied invert(P x Mv), updated by getPMvi().
@ frustum
Bit value for frustum and updated by getFrustum().
@ inv_mv
Bit value for inverse modelview matrix (Mvi), updated via update().
@ manual
Manual bits not covered by update() but getFrustum(), FRUSTUM, getPMv(), PREMUL_PMV,...
@ inv_proj
Bit value for inverse projection matrix (Pi), updated via update().
@ inv_tps_mv
Bit value for inverse transposed modelview matrix (Mvit), updated via update().
@ pre_pmv
Bit value for pre-multiplied P x Mv, updated by getPMv().
Requirement (concept) Definitions.
static std::string f(uint32_t v)