include/Spectre/Math/Matrix3.h: Add inverse()
This commit is contained in:
parent
910bad0fb7
commit
d8db86e40c
2 changed files with 27 additions and 0 deletions
|
|
@ -78,6 +78,9 @@ struct Matrix3
|
|||
|
||||
// Transpose matrix.
|
||||
Matrix3<T> transpose() const;
|
||||
|
||||
// Inverse
|
||||
Matrix3<T> inverse() const;
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
|
|
|
|||
|
|
@ -136,6 +136,30 @@ float Matrix3<T>::det() const
|
|||
return det;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
Matrix3<T> Matrix3<T>::inverse() const
|
||||
{
|
||||
float d = det();
|
||||
|
||||
if (d != 0.0f) {
|
||||
float a00 = (v[4] * v[8]) - (v[7] * v[5]);
|
||||
float a01 = -((v[1] * v[8]) - (v[7] * v[2]));
|
||||
float a02 = (v[1] * v[5]) - (v[4] * v[2]);
|
||||
|
||||
float a10 = -((v[3] * v[8]) - (v[6] * v[5]));
|
||||
float a11 = (v[0] * v[8]) - (v[6] * v[2]);
|
||||
float a12 = -((v[0] * v[5]) - (v[3] * v[2]));
|
||||
|
||||
float a20 = (v[3] * v[7]) - (v[6] * v[4]);
|
||||
float a21 = -((v[0] * v[7]) - (v[6] * v[1]));
|
||||
float a22 = (v[0] * v[4]) - (v[3] * v[1]);
|
||||
|
||||
return Matrix3<T>(a00, a01, a02, a10, a11, a12, a20, a21, a22) / d;
|
||||
}
|
||||
|
||||
return Matrix3<T>::Identity;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
Matrix3<T> Matrix3<T>::transpose() const
|
||||
{
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue