diff --git a/glm/gtx/rotate_vector.hpp b/glm/gtx/rotate_vector.hpp index 06eaee01..a8835f31 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 0978bd52..8e190c58 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 03d37a52..dcc6d907 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