Skip to content

Commit

Permalink
Added vec3 slerp #237
Browse files Browse the repository at this point in the history
  • Loading branch information
Christophe Riccio committed Sep 7, 2014
1 parent 4649717 commit 0d42f4a
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 0 deletions.
13 changes: 13 additions & 0 deletions glm/gtx/rotate_vector.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 <typename T, precision P>
GLM_FUNC_DECL detail::tvec3<T, P> slerp(
detail::tvec3<T, P> const & x,
detail::tvec3<T, P> const & y,
T const & a);

//! Rotate a two dimensional vector.
//! From GLM_GTX_rotate_vector extension.
template <typename T, precision P>
Expand Down
22 changes: 22 additions & 0 deletions glm/gtx/rotate_vector.inl
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,28 @@

namespace glm
{
template <typename T, precision P>
GLM_FUNC_QUALIFIER detail::tvec3<T, P> slerp
(
detail::tvec3<T, P> const & x,
detail::tvec3<T, P> 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<T>(1) - a) * Alpha) / SinAlpha;
T t2 = sin(a * Alpha) / sinAlpha;

// interpolate src vectors
return x * t1 + y * t2;
}

template <typename T, precision P>
GLM_FUNC_QUALIFIER detail::tvec2<T, P> rotate
(
Expand Down
1 change: 1 addition & 0 deletions readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 0d42f4a

Please # to comment.