| 1674 | // Returns a general-purpose inverse of an HMM_Mat4. Note that special-purpose inverses of many transformations |
| 1675 | // are available and will be more efficient. |
| 1676 | static inline HMM_Mat4 HMM_InvGeneralM4(HMM_Mat4 Matrix) |
| 1677 | { |
| 1678 | ASSERT_COVERED(HMM_InvGeneralM4); |
| 1679 | |
| 1680 | HMM_Vec3 C01 = HMM_Cross(Matrix.Columns[0].XYZ, Matrix.Columns[1].XYZ); |
| 1681 | HMM_Vec3 C23 = HMM_Cross(Matrix.Columns[2].XYZ, Matrix.Columns[3].XYZ); |
| 1682 | HMM_Vec3 B10 = HMM_SubV3(HMM_MulV3F(Matrix.Columns[0].XYZ, Matrix.Columns[1].W), HMM_MulV3F(Matrix.Columns[1].XYZ, Matrix.Columns[0].W)); |
| 1683 | HMM_Vec3 B32 = HMM_SubV3(HMM_MulV3F(Matrix.Columns[2].XYZ, Matrix.Columns[3].W), HMM_MulV3F(Matrix.Columns[3].XYZ, Matrix.Columns[2].W)); |
| 1684 | |
| 1685 | float InvDeterminant = 1.0f / (HMM_DotV3(C01, B32) + HMM_DotV3(C23, B10)); |
| 1686 | C01 = HMM_MulV3F(C01, InvDeterminant); |
| 1687 | C23 = HMM_MulV3F(C23, InvDeterminant); |
| 1688 | B10 = HMM_MulV3F(B10, InvDeterminant); |
| 1689 | B32 = HMM_MulV3F(B32, InvDeterminant); |
| 1690 | |
| 1691 | HMM_Mat4 Result; |
| 1692 | Result.Columns[0] = HMM_V4V(HMM_AddV3(HMM_Cross(Matrix.Columns[1].XYZ, B32), HMM_MulV3F(C23, Matrix.Columns[1].W)), -HMM_DotV3(Matrix.Columns[1].XYZ, C23)); |
| 1693 | Result.Columns[1] = HMM_V4V(HMM_SubV3(HMM_Cross(B32, Matrix.Columns[0].XYZ), HMM_MulV3F(C23, Matrix.Columns[0].W)), +HMM_DotV3(Matrix.Columns[0].XYZ, C23)); |
| 1694 | Result.Columns[2] = HMM_V4V(HMM_AddV3(HMM_Cross(Matrix.Columns[3].XYZ, B10), HMM_MulV3F(C01, Matrix.Columns[3].W)), -HMM_DotV3(Matrix.Columns[3].XYZ, C01)); |
| 1695 | Result.Columns[3] = HMM_V4V(HMM_SubV3(HMM_Cross(B10, Matrix.Columns[2].XYZ), HMM_MulV3F(C01, Matrix.Columns[2].W)), +HMM_DotV3(Matrix.Columns[2].XYZ, C01)); |
| 1696 | |
| 1697 | return HMM_TransposeM4(Result); |
| 1698 | } |
| 1699 | |
| 1700 | /* |
| 1701 | * Common graphics transformations |
no test coverage detected