From 7223cd1b47c4ba6328759a96d3dd135c1706fb3a Mon Sep 17 00:00:00 2001 From: CaptainCarrot Date: Sat, 22 Jul 2017 17:08:49 +0200 Subject: [PATCH 1/6] Add files via upload --- test/gtx/gtx_quaternion.cpp | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/test/gtx/gtx_quaternion.cpp b/test/gtx/gtx_quaternion.cpp index a6daf715..398adaee 100644 --- a/test/gtx/gtx_quaternion.cpp +++ b/test/gtx/gtx_quaternion.cpp @@ -90,7 +90,24 @@ int test_log() return Error; } -int main() +int test_quatLookAt() +{ + int Error(0); + + glm::vec3 eye(0.0f); + glm::vec3 center(1.1f, -2.0f, 3.1416f); + glm::vec3 up = glm::vec3(-0.17f, 7.23f, -1.744f); + + glm::quat test_quat = glm::quatLookAt(center - eye, up); + glm::quat test_mat = glm::conjugate(glm::quat_cast(glm::lookAt(eye, center, up))); + + Error += static_cast(glm::abs(glm::length(test_quat) - 1.0f) > glm::epsilon()); + Error += static_cast(glm::min(glm::length(test_quat + (-test_mat)), glm::length(test_quat + test_mat)) > glm::epsilon()); + + return Error; +} + +int main1() { int Error = 0; @@ -98,6 +115,7 @@ int main() Error += test_rotation(); Error += test_quat_fastMix(); Error += test_quat_shortMix(); + Error += test_quatLookAt(); return Error; } From 3ee83a15ef776cd9db9af29d3426bb9d7c39e6a2 Mon Sep 17 00:00:00 2001 From: CaptainCarrot Date: Sat, 22 Jul 2017 17:09:21 +0200 Subject: [PATCH 2/6] Add files via upload --- glm/gtx/quaternion.hpp | 28 ++++++++++++++++++++++++++++ glm/gtx/quaternion.inl | 34 ++++++++++++++++++++++++++++++++++ 2 files changed, 62 insertions(+) diff --git a/glm/gtx/quaternion.hpp b/glm/gtx/quaternion.hpp index ad298dae..401f22c0 100644 --- a/glm/gtx/quaternion.hpp +++ b/glm/gtx/quaternion.hpp @@ -177,6 +177,34 @@ namespace glm vec<3, T, P> const & orig, vec<3, T, P> const & dest); + /// Build a look at quaternion based on the default handedness. + /// + /// @param direction Desired direction of the camera. + /// @param up Up vector, how the camera is oriented.. Typically (0, 0, 1). + template + GLM_FUNC_DECL tquat quatLookAt( + tvec3 const & direction, + tvec3 const & up); + + /// Build a right-handed look at quaternion. + /// + /// @param direction Desired direction of the camera. + /// @param up Up vector, how the camera is oriented. Typically (0, 0, 1). + template + GLM_FUNC_DECL tquat quatLookAtRH( + tvec3 const & direction, + tvec3 const & up); + + /// Build a left-handed look at quaternion. + /// + /// @param eye Position of the camera + /// @param direction Desired direction onto which the +z-axis gets mapped + /// @param up Up vector, how the camera is oriented. Typically (0, 0, 1). + template + GLM_FUNC_DECL tquat quatLookAtLH( + tvec3 const & direction, + tvec3 const & up); + /// Returns the squared length of x. /// /// @see gtx_quaternion diff --git a/glm/gtx/quaternion.inl b/glm/gtx/quaternion.inl index 7bdcdf60..c69426bb 100644 --- a/glm/gtx/quaternion.inl +++ b/glm/gtx/quaternion.inl @@ -208,5 +208,39 @@ namespace glm rotationAxis.y * invs, rotationAxis.z * invs); } + + template + GLM_FUNC_QUALIFIER tquat quatLookAt(tvec3 const& direction, tvec3 const& up) + { +# if GLM_COORDINATE_SYSTEM == GLM_LEFT_HANDED + return quatLookAtLH(direction, up); +# else + return quatLookAtRH(direction, up); +# endif + } + + template + GLM_FUNC_QUALIFIER tquat quatLookAtRH(tvec3 const& direction, tvec3 const& up) + { + tmat3x3 Result(uninitialize); + + Result[2] = -normalize(direction); + Result[0] = normalize(cross(up, Result[2])); + Result[1] = cross(Result[2], Result[0]); + + return quat_cast(Result); + } + + template + GLM_FUNC_QUALIFIER tquat quatLookAtLH(tvec3 const& direction, tvec3 const& up) + { + tmat3x3 Result(uninitialize); + + Result[2] = normalize(direction); + Result[0] = normalize(cross(up, Result[2])); + Result[1] = cross(Result[2], Result[0]); + + return quat_cast(Result); + } }//namespace glm From 9a2176690603ea68d537d1737b44e6228a9003ca Mon Sep 17 00:00:00 2001 From: CaptainCarrot Date: Sat, 22 Jul 2017 17:10:31 +0200 Subject: [PATCH 3/6] Update gtx_quaternion.cpp --- test/gtx/gtx_quaternion.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/gtx/gtx_quaternion.cpp b/test/gtx/gtx_quaternion.cpp index 398adaee..2ab6d21b 100644 --- a/test/gtx/gtx_quaternion.cpp +++ b/test/gtx/gtx_quaternion.cpp @@ -107,7 +107,7 @@ int test_quatLookAt() return Error; } -int main1() +int main() { int Error = 0; From 580f36836592866e78801c9f834ca50e40647050 Mon Sep 17 00:00:00 2001 From: CaptainCarrot Date: Sat, 22 Jul 2017 17:16:49 +0200 Subject: [PATCH 4/6] Update quaternion.hpp --- glm/gtx/quaternion.hpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/glm/gtx/quaternion.hpp b/glm/gtx/quaternion.hpp index 401f22c0..801f0bc4 100644 --- a/glm/gtx/quaternion.hpp +++ b/glm/gtx/quaternion.hpp @@ -177,10 +177,10 @@ namespace glm vec<3, T, P> const & orig, vec<3, T, P> const & dest); - /// Build a look at quaternion based on the default handedness. + /// Build a look at quaternion based on the default handedness. /// /// @param direction Desired direction of the camera. - /// @param up Up vector, how the camera is oriented.. Typically (0, 0, 1). + /// @param up Up vector, how the camera is oriented. Typically (0, 1, 0). template GLM_FUNC_DECL tquat quatLookAt( tvec3 const & direction, @@ -189,7 +189,7 @@ namespace glm /// Build a right-handed look at quaternion. /// /// @param direction Desired direction of the camera. - /// @param up Up vector, how the camera is oriented. Typically (0, 0, 1). + /// @param up Up vector, how the camera is oriented. Typically (0, 1, 0). template GLM_FUNC_DECL tquat quatLookAtRH( tvec3 const & direction, @@ -199,7 +199,7 @@ namespace glm /// /// @param eye Position of the camera /// @param direction Desired direction onto which the +z-axis gets mapped - /// @param up Up vector, how the camera is oriented. Typically (0, 0, 1). + /// @param up Up vector, how the camera is oriented. Typically (0, 1, 0). template GLM_FUNC_DECL tquat quatLookAtLH( tvec3 const & direction, From df7f6cc03c5c2fe976c276097884549bd0c65622 Mon Sep 17 00:00:00 2001 From: CaptainCarrot Date: Sat, 22 Jul 2017 17:20:45 +0200 Subject: [PATCH 5/6] Update gtx_quaternion.cpp --- test/gtx/gtx_quaternion.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/gtx/gtx_quaternion.cpp b/test/gtx/gtx_quaternion.cpp index 2ab6d21b..e27981c4 100644 --- a/test/gtx/gtx_quaternion.cpp +++ b/test/gtx/gtx_quaternion.cpp @@ -90,7 +90,7 @@ int test_log() return Error; } -int test_quatLookAt() +int test_quat_lookAt() { int Error(0); @@ -115,7 +115,7 @@ int main() Error += test_rotation(); Error += test_quat_fastMix(); Error += test_quat_shortMix(); - Error += test_quatLookAt(); + Error += test_quat_lookAt(); return Error; } From c184671583d55242ca29b585c4f980baa90108d1 Mon Sep 17 00:00:00 2001 From: CaptainCarrot Date: Sun, 23 Jul 2017 09:27:25 +0200 Subject: [PATCH 6/6] Update quaternion.hpp --- glm/gtx/quaternion.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/glm/gtx/quaternion.hpp b/glm/gtx/quaternion.hpp index 801f0bc4..cce10892 100644 --- a/glm/gtx/quaternion.hpp +++ b/glm/gtx/quaternion.hpp @@ -200,7 +200,7 @@ namespace glm /// @param eye Position of the camera /// @param direction Desired direction onto which the +z-axis gets mapped /// @param up Up vector, how the camera is oriented. Typically (0, 1, 0). - template + template GLM_FUNC_DECL tquat quatLookAtLH( tvec3 const & direction, tvec3 const & up);