From 0d42f4a32030029fd20eb098dfa6d3096622780e Mon Sep 17 00:00:00 2001 From: Christophe Riccio Date: Sun, 7 Sep 2014 19:56:24 +0200 Subject: [PATCH] Added vec3 slerp #237 --- glm/gtx/rotate_vector.hpp | 13 +++++++++++++ glm/gtx/rotate_vector.inl | 22 ++++++++++++++++++++++ readme.txt | 1 + 3 files changed, 36 insertions(+) diff --git a/glm/gtx/rotate_vector.hpp b/glm/gtx/rotate_vector.hpp index 06eaee01e..a8835f319 100644 --- a/glm/gtx/rotate_vector.hpp +++ b/glm/gtx/rotate_vector.hpp @@ -51,6 +51,19 @@ namespace glm /// @addtogroup gtx_rotate_vector /// @{ + /// Returns the length of the quaternion. + /// + /// @param x A first vector + /// @param y A second vector + /// @param a Interpolation factor. The interpolation is defined beyond the range [0, 1]. + /// + /// @see gtc_quaternion + template + GLM_FUNC_DECL detail::tvec3 slerp( + detail::tvec3 const & x, + detail::tvec3 const & y, + T const & a); + //! Rotate a two dimensional vector. //! From GLM_GTX_rotate_vector extension. template diff --git a/glm/gtx/rotate_vector.inl b/glm/gtx/rotate_vector.inl index 0978bd527..8e190c58f 100644 --- a/glm/gtx/rotate_vector.inl +++ b/glm/gtx/rotate_vector.inl @@ -9,6 +9,28 @@ namespace glm { + template + GLM_FUNC_QUALIFIER detail::tvec3 slerp + ( + detail::tvec3 const & x, + detail::tvec3 const & y, + T const & a + ) + { + // get cosine of angle between vectors (-1 -> 1) + T CosAlpha = dot(x, y); + // get angle (0 -> pi) + T Alpha = acos(CosAlpha); + // get sine of angle between vectors (0 -> 1) + T SinAlpha = sin(Alpha); + // this breaks down when SinAlpha = 0, i.e. Alpha = 0 or pi + T t1 = sin((static_cast(1) - a) * Alpha) / SinAlpha; + T t2 = sin(a * Alpha) / sinAlpha; + + // interpolate src vectors + return x * t1 + y * t2; + } + template GLM_FUNC_QUALIFIER detail::tvec2 rotate ( diff --git a/readme.txt b/readme.txt index 03d37a52a..dcc6d907e 100644 --- a/readme.txt +++ b/readme.txt @@ -48,6 +48,7 @@ GLM 0.9.6.0: 2014-XX-XX - Added *vec1 support to *vec2 types - Limited extended integer type redifinition (#233) - Improved linearRand: support precision and integers (#230) +- Added vec3 slerp (#237) ================================================================================ GLM 0.9.5.5: 2014-XX-XX