From 00f99d392c89f5ad6e215117a293c74c886e333b Mon Sep 17 00:00:00 2001 From: Dustin Biser Date: Sat, 4 Jan 2014 15:11:16 -0500 Subject: [PATCH] Remove unncessary divisions for mat inverses --- glm/detail/func_matrix.inl | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/glm/detail/func_matrix.inl b/glm/detail/func_matrix.inl index 5da417ae..85208fbe 100644 --- a/glm/detail/func_matrix.inl +++ b/glm/detail/func_matrix.inl @@ -40,6 +40,7 @@ #include "type_mat4x3.hpp" #include "type_mat4x4.hpp" #include +#include namespace glm{ namespace detail @@ -456,13 +457,13 @@ namespace detail { static detail::tmat2x2 call(detail::tmat2x2 const & m) { - T Determinant = determinant(m); + T OneOverDeterminant = 1 / determinant(m); detail::tmat2x2 Inverse( - + m[1][1] / Determinant, - - m[0][1] / Determinant, - - m[1][0] / Determinant, - + m[0][0] / Determinant); + + m[1][1] * OneOverDeterminant, + - m[0][1] * OneOverDeterminant, + - m[1][0] * OneOverDeterminant, + + m[0][0] * OneOverDeterminant); return Inverse; } @@ -473,7 +474,7 @@ namespace detail { static detail::tmat3x3 call(detail::tmat3x3 const & m) { - T Determinant = determinant(m); + T OneOverDeterminant = 1 / determinant(m); detail::tmat3x3 Inverse(detail::tmat3x3::_null); Inverse[0][0] = + (m[1][1] * m[2][2] - m[2][1] * m[1][2]); @@ -485,7 +486,7 @@ namespace detail Inverse[0][2] = + (m[0][1] * m[1][2] - m[1][1] * m[0][2]); Inverse[1][2] = - (m[0][0] * m[1][2] - m[1][0] * m[0][2]); Inverse[2][2] = + (m[0][0] * m[1][1] - m[1][0] * m[0][1]); - Inverse /= Determinant; + Inverse *= OneOverDeterminant; return Inverse; } @@ -544,9 +545,9 @@ namespace detail detail::tvec4 Row0(Inverse[0][0], Inverse[1][0], Inverse[2][0], Inverse[3][0]); - T Determinant = dot(m[0], Row0); + T OneOverDeterminant = 1 / dot(m[0], Row0); - Inverse /= Determinant; + Inverse *= OneOverDeterminant; return Inverse; }