Math/Matrix4: Add TransformInverse(translation, rotation, scale)

This commit is contained in:
Lynix 2022-05-15 22:29:20 +02:00
parent dd4be081aa
commit 52f822fbcb
2 changed files with 41 additions and 1 deletions

View File

@ -79,6 +79,7 @@ namespace Nz
Matrix4& MakeTransform(const Vector3<T>& translation, const Quaternion<T>& rotation);
Matrix4& MakeTransform(const Vector3<T>& translation, const Quaternion<T>& rotation, const Vector3<T>& scale);
Matrix4& MakeTransformInverse(const Vector3<T>& translation, const Quaternion<T>& rotation);
Matrix4& MakeTransformInverse(const Vector3<T>& translation, const Quaternion<T>& rotation, const Vector3<T>& scale);
Matrix4& MakeZero();
Matrix4& Set(T r11, T r12, T r13, T r14,
@ -130,7 +131,8 @@ namespace Nz
static Matrix4 Translate(const Vector3<T>& translation);
static Matrix4 Transform(const Vector3<T>& translation, const Quaternion<T>& rotation);
static Matrix4 Transform(const Vector3<T>& translation, const Quaternion<T>& rotation, const Vector3<T>& scale);
static Matrix4 TransformInverse(const Vector3<T>&translation, const Quaternion<T>&rotation);
static Matrix4 TransformInverse(const Vector3<T>& translation, const Quaternion<T>& rotation);
static Matrix4 TransformInverse(const Vector3<T>& translation, const Quaternion<T>& rotation, const Vector3<T>&scale);
static Matrix4 Zero();
T m11, m12, m13, m14,

View File

@ -1031,6 +1031,25 @@ namespace Nz
return MakeTransform(-(invRot * translation), invRot);
}
/*!
* \brief Makes the matrix an inverse transform matrix (aka view matrix)
* \return A reference to this matrix
*
* \param translation Vector3 representing the translation
* \param rotation Quaternion representing a rotation of space
* \param scale Vector3 representing the scale
*
* \see InverseTransformMatrix
*/
template<typename T>
Matrix4<T>& Matrix4<T>::MakeTransformInverse(const Vector3<T>& translation, const Quaternion<T>& rotation, const Vector3<T>& scale)
{
MakeTransformInverse(translation, rotation);
ConcatenateTransform(Scale(T(1.0) / scale));
return *this;
}
/*!
* \brief Makes the matrix zero (with 0 everywhere)
* \return A reference to this matrix with components (0 everywhere)
@ -1677,6 +1696,25 @@ namespace Nz
return mat;
}
/*!
* \brief Shorthand for the 'view' matrix
* \return A Matrix4 which is the 'view matrix'
*
* \param translation Vector3 representing the translation
* \param rotation Quaternion representing a rotation of space
* \param scale Vector3 representing the scale
*
* \see MakeInverseTransformMatrix
*/
template<typename T>
Matrix4<T> Matrix4<T>::TransformInverse(const Vector3<T>& translation, const Quaternion<T>& rotation, const Vector3<T>& scale)
{
Matrix4 mat;
mat.MakeTransformInverse(translation, rotation, scale);
return mat;
}
/*!
* \brief Shorthand for the 'zero' matrix
* \return A Matrix4 with components (0 everywhere)