3#include <Foundation/Memory/MemoryUtils.h>
5template <
typename Type>
8#if PL_ENABLED(PL_MATH_CHECK_FOR_NAN)
11 for (plUInt32 i = 0; i < 9; ++i)
12 m_fElementsCM[i] = TypeNaN;
16template <
typename Type>
27 for (
int i = 0; i < 3; ++i)
29 out_pData[i * 3 + 0] = Element(0, i);
30 out_pData[i * 3 + 1] = Element(1, i);
31 out_pData[i * 3 + 2] = Element(2, i);
36template <
typename Type>
41 for (plUInt32 i = 0; i < PL_ARRAY_SIZE(res.
m_fElementsCM); ++i)
47template <
typename Type>
63template <
typename Type>
67 for (
int i = 0; i < 3; ++i)
69 res.Element(0, i) = pData[i * 3 + 0];
70 res.Element(1, i) = pData[i * 3 + 1];
71 res.Element(2, i) = pData[i * 3 + 2];
76template <
typename Type>
84template <
typename Type>
88 res.Element(0, 0) = c1r1;
89 res.Element(1, 0) = c2r1;
90 res.Element(2, 0) = c3r1;
91 res.Element(0, 1) = c1r2;
92 res.Element(1, 1) = c2r2;
93 res.Element(2, 1) = c3r2;
94 res.Element(0, 2) = c1r3;
95 res.Element(1, 2) = c2r3;
96 res.Element(2, 2) = c3r3;
100template <
typename Type>
104 res.Element(0, 0) = vScale.x;
105 res.Element(1, 0) = 0;
106 res.Element(2, 0) = 0;
107 res.Element(0, 1) = 0;
108 res.Element(1, 1) = vScale.y;
109 res.Element(2, 1) = 0;
110 res.Element(0, 2) = 0;
111 res.Element(1, 2) = 0;
112 res.Element(2, 2) = vScale.z;
116template <
typename Type>
125template <
typename Type>
134template <
typename Type>
143template <
typename Type>
149template <
typename Type>
152 *
this = MakeIdentity();
155template <
typename Type>
163template <
typename Type>
169template <
typename Type>
174 PL_ASSERT_DEBUG(res.Succeeded(),
"Could not invert the given Mat3.");
175 PL_IGNORE_UNUSED(res);
179template <
typename Type>
182 PL_ASSERT_DEBUG(uiRow <= 2,
"Invalid Row Index {0}", uiRow);
185 r.x = Element(0, uiRow);
186 r.y = Element(1, uiRow);
187 r.z = Element(2, uiRow);
193template <
typename Type>
196 PL_ASSERT_DEBUG(uiRow <= 2,
"Invalid Row Index {0}", uiRow);
198 Element(0, uiRow) = vRow.x;
199 Element(1, uiRow) = vRow.y;
200 Element(2, uiRow) = vRow.z;
203template <
typename Type>
206 PL_ASSERT_DEBUG(uiColumn <= 2,
"Invalid Column Index {0}", uiColumn);
209 r.x = Element(uiColumn, 0);
210 r.y = Element(uiColumn, 1);
211 r.z = Element(uiColumn, 2);
217template <
typename Type>
220 PL_ASSERT_DEBUG(uiColumn <= 2,
"Invalid Column Index {0}", uiColumn);
222 Element(uiColumn, 0) = vColumn.x;
223 Element(uiColumn, 1) = vColumn.y;
224 Element(uiColumn, 2) = vColumn.z;
227template <
typename Type>
235template <
typename Type>
238 Element(0, 0) = vDiag.x;
239 Element(1, 1) = vDiag.y;
240 Element(2, 2) = vDiag.z;
243template <
typename Type>
247 r.x = Element(0, 0) * v.x + Element(1, 0) * v.y + Element(2, 0) * v.z;
248 r.y = Element(0, 1) * v.x + Element(1, 1) * v.y + Element(2, 1) * v.z;
249 r.z = Element(0, 2) * v.x + Element(1, 2) * v.y + Element(2, 2) * v.z;
255template <
typename Type>
258 for (plInt32 i = 0; i < 9; ++i)
259 m_fElementsCM[i] *= f;
264template <
typename Type>
272template <
typename Type>
276 for (plInt32 i = 0; i < 3; ++i)
278 r.Element(0, i) = m1.Element(0, i) * m2.Element(0, 0) + m1.Element(1, i) * m2.Element(0, 1) + m1.Element(2, i) * m2.Element(0, 2);
279 r.Element(1, i) = m1.Element(0, i) * m2.Element(1, 0) + m1.Element(1, i) * m2.Element(1, 1) + m1.Element(2, i) * m2.Element(1, 2);
280 r.Element(2, i) = m1.Element(0, i) * m2.Element(2, 0) + m1.Element(1, i) * m2.Element(2, 1) + m1.Element(2, i) * m2.Element(2, 2);
287template <
typename Type>
297template <
typename Type>
300 return operator*(m1, f);
303template <
typename Type>
308 for (plUInt32 i = 0; i < 9; ++i)
316template <
typename Type>
322template <
typename Type>
327 for (plUInt32 i = 0; i < 9; ++i)
335template <
typename Type>
340 for (plUInt32 i = 0; i < 9; ++i)
348template <
typename Type>
354 for (plUInt32 i = 0; i < 9; ++i)
363template <
typename Type>
369 PL_ASSERT_DEBUG(fEpsilon >= 0.0f,
"Epsilon may not be negative.");
371 for (plUInt32 i = 0; i < 9; ++i)
380template <
typename Type>
386template <
typename Type>
392template <
typename Type>
397 for (plUInt32 i = 0; i < 9; ++i)
406template <
typename Type>
435template <
typename Type>
438 for (plUInt32 i = 0; i < 9; ++i)
440 if (!plMath::IsFinite(m_fElementsCM[i]))
447template <
typename Type>
450 for (plUInt32 i = 0; i < 9; ++i)
452 if (plMath::IsNaN(m_fElementsCM[i]))
459template <
typename Type>
472template <
typename Type>
479 if (tx.
SetLength(vXYZ.x, fEpsilon) == PL_FAILURE)
481 if (ty.
SetLength(vXYZ.y, fEpsilon) == PL_FAILURE)
483 if (tz.
SetLength(vXYZ.z, fEpsilon) == PL_FAILURE)
487 Element(0, 0) = tx.x;
488 Element(0, 1) = tx.y;
489 Element(0, 2) = tx.z;
490 Element(1, 0) = ty.x;
491 Element(1, 1) = ty.y;
492 Element(1, 2) = ty.z;
493 Element(2, 0) = tz.x;
494 Element(2, 1) = tz.y;
495 Element(2, 2) = tz.z;
500template <
typename Type>
504 Type fDeterminant = 0;
505 for (
int i = 0; i < 3; i++)
507 fDeterminant += Element(i, 0) * Element((i + 1) % 3, 1) * Element((i + 2) % 3, 2);
508 fDeterminant -= Element(i, 2) * Element((i + 1) % 3, 1) * Element((i + 2) % 3, 0);
513#include <Foundation/Math/Implementation/AllClasses_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
void SetDiagonal(const plVec3Template< Type > &vDiag)
Sets all 3 components on the diagonal of the matrix.
Definition Mat3_inl.h:236
bool IsZero(Type fEpsilon=plMath::DefaultEpsilon< Type >()) const
Checks whether all elements are zero.
Definition Mat3_inl.h:393
void SetZero()
Sets all elements to zero.
Definition Mat3_inl.h:144
plVec3Template< Type > GetRow(plUInt32 uiRow) const
Returns all 3 components of the i-th row.
Definition Mat3_inl.h:180
void SetColumn(plUInt32 uiColumn, const plVec3Template< Type > &vColumn)
Sets all 3 components of the i-th column.
Definition Mat3_inl.h:218
void Transpose()
Transposes this matrix.
Definition Mat3_inl.h:156
static plMat3Template< Type > MakeRotationX(plAngle angle)
Creates a matrix that is a rotation matrix around the X-axis.
Definition Mat3_inl.h:117
static plMat3Template< Type > MakeScaling(const plVec3Template< Type > &vScale)
Creates a matrix with all zero values, except along the diagonal, which is set to x,...
Definition Mat3_inl.h:101
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 Mat3_inl.h:473
static plMat3Template< Type > MakeFromRowMajorArray(const Type *const pData)
Creates a matrix from 9 values that are in row-major layout.
Definition Mat3_inl.h:64
plResult Invert(Type fEpsilon=plMath::SmallEpsilon< Type >())
Inverts this matrix. Return value indicates whether the matrix could be Inverted.
Definition AllClasses_inl.h:230
bool IsEqual(const plMat3Template< Type > &rhs, Type fEpsilon) const
Equality Check with epsilon.
Definition Mat3_inl.h:364
bool IsIdentical(const plMat3Template< Type > &rhs) const
Equality Check.
Definition Mat3_inl.h:349
static plMat3Template< Type > MakeRotationZ(plAngle angle)
Creates a matrix that is a rotation matrix around the Z-axis.
Definition Mat3_inl.h:135
plVec3Template< Type > GetDiagonal() const
Returns all 3 components on the diagonal of the matrix.
Definition Mat3_inl.h:228
void operator*=(Type f)
Component-wise multiplication (commutative)
Definition Mat3_inl.h:256
static plMat3Template< Type > MakeRotationY(plAngle angle)
Creates a matrix that is a rotation matrix around the Y-axis.
Definition Mat3_inl.h:126
const plMat3Template< Type > GetTranspose() const
Returns the transpose of this matrix.
Definition Mat3_inl.h:164
const plMat3Template< Type > GetInverse(Type fEpsilon=plMath::SmallEpsilon< Type >()) const
Returns the inverse of this matrix.
Definition Mat3_inl.h:170
void operator/=(Type f)
Component-wise division.
Definition Mat3_inl.h:265
plMat3Template()
Default Constructor DOES NOT INITIALIZE the matrix, at all.
Definition Mat3_inl.h:6
void SetIdentity()
Sets all elements to zero, except the diagonal, which is set to one.
Definition Mat3_inl.h:150
static plMat3Template< Type > MakeFromValues(Type c1r1, Type c2r1, Type c3r1, Type c1r2, Type c2r2, Type c3r2, Type c1r3, Type c2r3, Type c3r3)
Creates a matrix from 9 values. Naming is "column-n row-m".
Definition Mat3_inl.h:85
static plMat3Template< Type > MakeZero()
Returns a zero matrix.
Definition Mat3_inl.h:37
const plVec3Template< Type > TransformDirection(const plVec3Template< Type > &v) const
Matrix-vector multiplication, assuming the 4th component of the vector is zero. So,...
Definition Mat3_inl.h:244
static plMat3Template< Type > MakeIdentity()
Returns an identity matrix.
Definition Mat3_inl.h:48
bool IsIdentity(Type fEpsilon=plMath::DefaultEpsilon< Type >()) const
Checks whether this is an identity matrix.
Definition Mat3_inl.h:407
Type GetDeterminant() const
Computes the determinant of the matrix.
Definition Mat3_inl.h:501
void GetAsArray(Type *out_pData, plMatrixLayout::Enum layout) const
Copies the 9 values of this matrix into the given array. 'layout' defines whether the data should end...
Definition Mat3_inl.h:17
bool IsValid() const
Checks whether all components are finite numbers.
Definition Mat3_inl.h:436
Type m_fElementsCM[9]
The matrix as a 9-element Type array (column-major)
Definition Mat3.h:22
bool IsNaN() const
Checks whether any component is NaN.
Definition Mat3_inl.h:448
void SetRow(plUInt32 uiRow, const plVec3Template< Type > &vRow)
Sets all 3 components of the i-th row.
Definition Mat3_inl.h:194
const plVec3Template< Type > GetScalingFactors() const
Returns the 3 scaling factors that are encoded in the matrix.
Definition Mat3_inl.h:460
static plMat3Template< Type > MakeFromColumnMajorArray(const Type *const pData)
Creates a matrix from 9 values that are in column-major layout.
Definition Mat3_inl.h:77
plVec3Template< Type > GetColumn(plUInt32 uiColumn) const
Returns all 3 components of the i-th column.
Definition Mat3_inl.h:204
static void Copy(T *pDestination, const T *pSource, size_t uiCount=1)
Copies objects of type T from pSource to pDestination.
A 3-component vector class.
Definition Vec3.h:9
PL_DECLARE_IF_FLOAT_TYPE Type GetLength() const
Returns the length of the vector.
Definition Vec3_inl.h:54
PL_DECLARE_IF_FLOAT_TYPE plResult SetLength(Type fNewLength, Type fEpsilon=plMath::DefaultEpsilon< Type >())
Tries to rescale the vector to the given length. If the vector is too close to zero,...
Definition Vec3_inl.h:60
PL_ALWAYS_INLINE float Sin(plAngle a)
***** Trigonometric Functions *****
Definition MathFloat_inl.h:62
constexpr Type Invert(Type f)
Returns 1 / f.
Definition Math_inl.h:63
constexpr TYPE NaN()
Returns the value for NaN as the template type. Returns zero, if the type does not support NaN.
Definition Constants_inl.h:58
bool IsZero(Type f, Type fEpsilon)
Checks whether the given number is close to zero.
Definition Math_inl.h:288
constexpr bool IsEqual(Type lhs, Type rhs, Type fEpsilon)
Checks, whether fValue is in the range [fDesired - fMaxImprecision; fDesired + fMaxImprecision].
Definition Math_inl.h:276
PL_ALWAYS_INLINE void Swap(T &ref_f1, T &ref_f2)
Swaps the values in the two variables f1 and f2.
Definition Math_inl.h:224
PL_ALWAYS_INLINE float Cos(plAngle a)
Takes an angle, returns its cosine.
Definition MathFloat_inl.h:67
Enum
Definition Declarations.h:65
@ ColumnMajor
The matrix is stored in column-major format.
Definition Declarations.h:67
Default enum for returning failure or success, instead of using a bool.
Definition Types.h:54