From afdbba7d82eda8486bf2566f4282c77ec323c757 Mon Sep 17 00:00:00 2001 From: Christophe Riccio Date: Fri, 21 Jan 2011 00:37:42 +0000 Subject: [PATCH] Uniformalized matrix transform function --- glm/gtc/matrix_transform.hpp | 1 + glm/gtc/matrix_transform.inl | 3 ++- glm/gtx/transform2.hpp | 8 ++++++++ glm/gtx/transform2.inl | 29 +++++++++++++++++++++++++++++ 4 files changed, 40 insertions(+), 1 deletion(-) diff --git a/glm/gtc/matrix_transform.hpp b/glm/gtc/matrix_transform.hpp index 8b6d82c9..1daca18b 100644 --- a/glm/gtc/matrix_transform.hpp +++ b/glm/gtc/matrix_transform.hpp @@ -137,6 +137,7 @@ namespace glm //! From GLM_GTC_matrix_transform extension. template detail::tmat4x4 lookAt( + detail::tmat4x4 const & m, detail::tvec3 const & eye, detail::tvec3 const & center, detail::tvec3 const & up); diff --git a/glm/gtc/matrix_transform.inl b/glm/gtc/matrix_transform.inl index ba1f75dc..9dc1cf38 100644 --- a/glm/gtc/matrix_transform.inl +++ b/glm/gtc/matrix_transform.inl @@ -326,6 +326,7 @@ namespace matrix_transform template inline detail::tmat4x4 lookAt( + detail::tmat4x4 const & m, const detail::tvec3& eye, const detail::tvec3& center, const detail::tvec3& up) @@ -350,7 +351,7 @@ namespace matrix_transform Result[3][1] =-dot(y, eye); Result[3][2] = dot(f, eye); */ - return gtc::matrix_transform::translate(Result, -eye); + return m * gtc::matrix_transform::translate(Result, -eye); } }//namespace matrix_transform }//namespace gtc diff --git a/glm/gtx/transform2.hpp b/glm/gtx/transform2.hpp index 9f05976c..c32a4bf6 100644 --- a/glm/gtx/transform2.hpp +++ b/glm/gtx/transform2.hpp @@ -109,6 +109,14 @@ namespace glm valType scale, valType bias); + //! Build a look at view matrix. + //! From GLM_GTX_transform2 extension. + template + detail::tmat4x4 lookAt( + detail::tvec3 const & eye, + detail::tvec3 const & center, + detail::tvec3 const & up); + }//namespace transform2 }//namespace gtx }//namespace glm diff --git a/glm/gtx/transform2.inl b/glm/gtx/transform2.inl index 841d180c..7e449a8c 100644 --- a/glm/gtx/transform2.inl +++ b/glm/gtx/transform2.inl @@ -153,6 +153,35 @@ namespace transform2 return m * scaleBias(scale, bias); } + template + inline detail::tmat4x4 lookAt( + const detail::tvec3& eye, + const detail::tvec3& center, + const detail::tvec3& up) + { + detail::tvec3 f = normalize(center - eye); + detail::tvec3 u = normalize(up); + detail::tvec3 s = normalize(cross(f, u)); + u = cross(s, f); + + detail::tmat4x4 Result(1); + Result[0][0] = s.x; + Result[1][0] = s.y; + Result[2][0] = s.z; + Result[0][1] = u.x; + Result[1][1] = u.y; + Result[2][1] = u.z; + Result[0][2] =-f.x; + Result[1][2] =-f.y; + Result[2][2] =-f.z; + /* Test this instead of translate3D + Result[3][0] =-dot(s, eye); + Result[3][1] =-dot(y, eye); + Result[3][2] = dot(f, eye); + */ + return gtc::matrix_transform::translate(Result, -eye); + } + }//namespace transform2 }//namespace gtx }//namespace glm