From 3ee83a15ef776cd9db9af29d3426bb9d7c39e6a2 Mon Sep 17 00:00:00 2001 From: CaptainCarrot Date: Sat, 22 Jul 2017 17:09:21 +0200 Subject: [PATCH] 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