3#include <Foundation/Math/Angle.h>
4#include <Foundation/Math/Math.h>
5#include <Foundation/Math/Vec3.h>
6#include <Foundation/Math/Vec4.h>
9template <
typename Type>
13 PL_DECLARE_POD_TYPE();
15 using ComponentType = Type;
26 PL_ALWAYS_INLINE Type& Element(plInt32 iColumn, plInt32 iRow) {
return m_fElementsCM[iColumn * 4 + iRow]; }
27 PL_ALWAYS_INLINE Type Element(plInt32 iColumn, plInt32 iRow)
const {
return m_fElementsCM[iColumn * 4 + iRow]; }
44 plMat4Template(Type c1r1, Type c2r1, Type c3r1, Type c4r1, Type c1r2, Type c2r2, Type c3r2, Type c4r2, Type c1r3, Type c2r3, Type c3r3, Type c4r3,
45 Type c1r4, Type c2r4, Type c3r4, Type c4r4);
50#if PL_ENABLED(PL_MATH_CHECK_FOR_NAN)
51 void AssertNotNaN()
const
53 PL_ASSERT_ALWAYS(!
IsNaN(),
"This object contains NaN values. This can happen when you forgot to initialize it before using it. Please "
54 "check that all code-paths properly initialize this object.");
71 [[nodiscard]]
static plMat4Template<Type> MakeFromValues(Type c1r1, Type c2r1, Type c3r1, Type c4r1, Type c1r2, Type c2r2, Type c3r2, Type c4r2, Type c1r3, Type c2r3, Type c3r3, Type c4r3, Type c1r4, Type c2r4, Type c3r4, Type c4r4);
126 bool IsZero(Type fEpsilon = plMath::DefaultEpsilon<Type>())
const;
129 bool IsIdentity(Type fEpsilon = plMath::DefaultEpsilon<Type>())
const;
214template <
typename Type>
218template <
typename Type>
222template <
typename Type>
226template <
typename Type>
230template <
typename Type>
234template <
typename Type>
238template <
typename Type>
242template <
typename Type>
246template <
typename Type>
250template <
typename Type>
253#include <Foundation/Math/Implementation/Mat4_inl.h>
Float wrapper struct for a safe usage and conversions of angles.
Definition Angle.h:10
A 3x3 component matrix class.
Definition Mat3.h:9
A 4x4 component matrix class.
Definition Mat4.h:11
plMat4Template()
Default Constructor DOES NOT INITIALIZE the matrix, at all.
Definition Mat4_inl.h:6
static plMat4Template< Type > MakeAxisRotation(const plVec3Template< Type > &vAxis, plAngle angle)
Creates a matrix that is a rotation matrix around the given axis.
Definition AllClasses_inl.h:260
void SetIdentity()
Sets all elements to zero, except the diagonal, which is set to one.
Definition Mat4_inl.h:243
const plVec3Template< Type > GetTranslationVector() const
Returns the first 3 components of the last column.
Definition Mat4_inl.h:430
static plMat4Template< Type > MakeIdentity()
Returns an identity matrix.
Definition Mat4_inl.h:75
static plMat4Template< Type > MakeScaling(const plVec3Template< Type > &vScale)
Creates a matrix with all zero values, except along the diagonal, which is set to x,...
Definition Mat4_inl.h:158
plVec4Template< Type > GetColumn(plUInt32 uiColumn) const
Returns all 4 components of the i-th column.
Definition Mat4_inl.h:304
static plMat4Template< Type > MakeTransformation(const plMat3Template< Type > &mRotation, const plVec3Template< Type > &vTranslation)
Creates a transformation matrix from a rotation and a translation.
Definition Mat4_inl.h:150
const plMat3Template< Type > GetRotationalPart() const
Returns the 3x3 rotational and scaling part of the matrix.
Definition Mat4_inl.h:458
static plMat4Template< Type > MakeFromValues(Type c1r1, Type c2r1, Type c3r1, Type c4r1, Type c1r2, Type c2r2, Type c3r2, Type c4r2, Type c1r3, Type c2r3, Type c3r3, Type c4r3, Type c1r4, Type c2r4, Type c3r4, Type c4r4)
Creates a matrix from 16 values. Naming is "column-n row-m".
Definition Mat4_inl.h:120
static plMat4Template< Type > MakeFromRowMajorArray(const Type *const pData)
Creates a matrix from 16 values that are in row-major layout.
Definition Mat4_inl.h:98
bool IsValid() const
Checks whether all components are finite numbers.
Definition Mat4_inl.h:713
static plMat4Template< Type > MakeRotationY(plAngle angle)
Creates a matrix that is a rotation matrix around the Y-axis.
Definition Mat4_inl.h:190
static plMat4Template< Type > MakeRotationX(plAngle angle)
Creates a matrix that is a rotation matrix around the X-axis.
Definition Mat4_inl.h:181
void SetTranslationVector(const plVec3Template< Type > &v)
Sets the first 3 components of the last column.
Definition Mat4_inl.h:438
Type m_fElementsCM[16]
The matrix as a 16-element Type array (column-major)
Definition Mat4.h:24
plVec4Template< Type > GetDiagonal() const
Returns all 4 components on the diagonal of the matrix.
Definition Mat4_inl.h:330
const plVec3Template< Type > TransformPosition(const plVec3Template< Type > &v) const
Matrix-vector multiplication, assuming the 4th component of the vector is one (default behavior).
Definition Mat4_inl.h:347
const plMat4Template< Type > GetTranspose() const
Returns the transpose of this matrix.
Definition Mat4_inl.h:260
const plVec4Template< Type > Transform(const plVec4Template< Type > &v) const
Matrix-vector multiplication.
Definition Mat4_inl.h:402
plResult SetScalingFactors(const plVec3Template< Type > &vXYZ, Type fEpsilon=plMath::DefaultEpsilon< Type >())
Tries to set the three scaling factors in the matrix. Returns PL_FAILURE if the matrix columns cannot...
Definition Mat4_inl.h:750
static plMat4Template< Type > MakeRotationZ(plAngle angle)
Creates a matrix that is a rotation matrix around the Z-axis.
Definition Mat4_inl.h:199
void SetDiagonal(const plVec4Template< Type > &vDiag)
Sets all 4 components on the diagonal of the matrix.
Definition Mat4_inl.h:338
void Transpose()
Transposes this matrix.
Definition Mat4_inl.h:249
static plMat4Template< Type > MakeTranslation(const plVec3Template< Type > &vTranslation)
Creates a matrix with all zero values, except the last column, which is set to x, y,...
Definition Mat4_inl.h:143
static plMat4Template< Type > MakeZero()
Returns a zero matrix.
Definition Mat4_inl.h:64
const plVec3Template< Type > TransformDirection(const plVec3Template< Type > &v) const
Matrix-vector multiplication, assuming the 4th component of the vector is zero. So,...
Definition Mat4_inl.h:374
bool IsZero(Type fEpsilon=plMath::DefaultEpsilon< Type >()) const
Checks whether all elements are zero.
Definition Mat4_inl.h:655
void SetTransformationMatrix(const plMat3Template< Type > &mRotation, const plVec3Template< Type > &vTranslation)
Sets a transformation matrix from a rotation and a translation.
Definition Mat4_inl.h:208
bool IsIdentity(Type fEpsilon=plMath::DefaultEpsilon< Type >()) const
Checks whether this is an identity matrix.
Definition Mat4_inl.h:669
void SetRotationalPart(const plMat3Template< Type > &mRotation)
Sets the 3x3 rotational part of the matrix.
Definition Mat4_inl.h:446
bool IsIdentical(const plMat4Template< Type > &rhs) const
Equality Check.
Definition Mat4_inl.h:611
bool IsNaN() const
Checks whether any component is NaN.
Definition Mat4_inl.h:725
void SetColumn(plUInt32 uiColumn, const plVec4Template< Type > &vColumn)
Sets all 4 components of the i-th column.
Definition Mat4_inl.h:319
plVec4Template< Type > GetRow(plUInt32 uiRow) const
Returns all 4 components of the i-th row.
Definition Mat4_inl.h:278
const plVec3Template< Type > GetScalingFactors() const
Returns the 3 scaling factors that are encoded in the matrix.
Definition Mat4_inl.h:737
void GetAsArray(Type *out_pData, plMatrixLayout::Enum layout) const
Copies the 16 values of this matrix into the given array. 'layout' defines whether the data should en...
Definition Mat4_inl.h:216
const plMat4Template< Type > GetInverse(Type fEpsilon=plMath::SmallEpsilon< Type >()) const
Returns the inverse of this matrix.
Definition Mat4_inl.h:268
void operator*=(Type f)
Component-wise multiplication (commutative)
Definition Mat4_inl.h:475
void operator/=(Type f)
Component-wise division.
Definition Mat4_inl.h:484
bool IsEqual(const plMat4Template< Type > &rhs, Type fEpsilon) const
Equality Check with epsilon.
Definition Mat4_inl.h:626
plResult Invert(Type fEpsilon=plMath::SmallEpsilon< Type >())
Inverts this matrix. Return value indicates whether the matrix could be inverted.
Definition AllClasses_inl.h:310
void SetRow(plUInt32 uiRow, const plVec4Template< Type > &vRow)
Sets all 4 components of the i-th row.
Definition Mat4_inl.h:293
static plMat4Template< Type > MakeFromColumnMajorArray(const Type *const pData)
Creates a matrix from 16 values that are in column-major layout.
Definition Mat4_inl.h:112
void SetZero()
Sets all elements to zero.
Definition Mat4_inl.h:237
A 3-component vector class.
Definition Vec3.h:9
A 4-component vector class.
Definition Vec4.h:9
Enum
Definition Declarations.h:65
Default enum for returning failure or success, instead of using a bool.
Definition Types.h:54