2014-11-25 23:27:12 +00:00
|
|
|
/// @ref gtx_vector_angle
|
|
|
|
/// @file glm/gtx/vector_angle.inl
|
2010-04-29 10:54:07 +00:00
|
|
|
|
2011-10-14 13:07:53 +00:00
|
|
|
namespace glm
|
2010-04-29 10:54:07 +00:00
|
|
|
{
|
2013-09-29 23:57:05 +00:00
|
|
|
template <typename genType>
|
|
|
|
GLM_FUNC_QUALIFIER genType angle
|
2011-10-14 13:07:53 +00:00
|
|
|
(
|
2013-09-29 23:57:05 +00:00
|
|
|
genType const & x,
|
|
|
|
genType const & y
|
2011-10-14 13:07:53 +00:00
|
|
|
)
|
|
|
|
{
|
2013-09-29 23:57:05 +00:00
|
|
|
GLM_STATIC_ASSERT(std::numeric_limits<genType>::is_iec559, "'angle' only accept floating-point inputs");
|
2014-02-25 20:00:25 +00:00
|
|
|
return acos(clamp(dot(x, y), genType(-1), genType(1)));
|
2013-09-08 00:30:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
template <typename T, precision P, template <typename, precision> class vecType>
|
|
|
|
GLM_FUNC_QUALIFIER T angle
|
|
|
|
(
|
|
|
|
vecType<T, P> const & x,
|
|
|
|
vecType<T, P> const & y
|
|
|
|
)
|
|
|
|
{
|
2013-09-29 23:57:05 +00:00
|
|
|
GLM_STATIC_ASSERT(std::numeric_limits<T>::is_iec559, "'angle' only accept floating-point inputs");
|
2014-02-25 20:00:25 +00:00
|
|
|
return acos(clamp(dot(x, y), T(-1), T(1)));
|
2011-10-14 13:07:53 +00:00
|
|
|
}
|
2010-04-29 10:54:07 +00:00
|
|
|
|
2011-10-14 13:07:53 +00:00
|
|
|
//! \todo epsilon is hard coded to 0.01
|
2013-04-10 11:46:27 +00:00
|
|
|
template <typename T, precision P>
|
|
|
|
GLM_FUNC_QUALIFIER T orientedAngle
|
2011-10-14 13:07:53 +00:00
|
|
|
(
|
2014-10-05 17:37:07 +00:00
|
|
|
tvec2<T, P> const & x,
|
|
|
|
tvec2<T, P> const & y
|
2011-10-14 13:07:53 +00:00
|
|
|
)
|
|
|
|
{
|
2013-09-29 23:57:05 +00:00
|
|
|
GLM_STATIC_ASSERT(std::numeric_limits<T>::is_iec559, "'orientedAngle' only accept floating-point inputs");
|
2014-02-25 20:00:25 +00:00
|
|
|
T const Angle(acos(clamp(dot(x, y), T(-1), T(1))));
|
2013-09-08 00:30:16 +00:00
|
|
|
|
2014-02-25 20:00:25 +00:00
|
|
|
if(all(epsilonEqual(y, glm::rotate(x, Angle), T(0.0001))))
|
2011-10-14 13:07:53 +00:00
|
|
|
return Angle;
|
|
|
|
else
|
|
|
|
return -Angle;
|
|
|
|
}
|
2010-04-29 10:54:07 +00:00
|
|
|
|
2013-04-10 11:46:27 +00:00
|
|
|
template <typename T, precision P>
|
|
|
|
GLM_FUNC_QUALIFIER T orientedAngle
|
2011-10-14 13:07:53 +00:00
|
|
|
(
|
2014-10-05 17:37:07 +00:00
|
|
|
tvec3<T, P> const & x,
|
|
|
|
tvec3<T, P> const & y,
|
|
|
|
tvec3<T, P> const & ref
|
2011-10-14 13:07:53 +00:00
|
|
|
)
|
|
|
|
{
|
2013-09-29 23:57:05 +00:00
|
|
|
GLM_STATIC_ASSERT(std::numeric_limits<T>::is_iec559, "'orientedAngle' only accept floating-point inputs");
|
2013-09-08 00:30:16 +00:00
|
|
|
|
2014-02-25 20:00:25 +00:00
|
|
|
T const Angle(acos(clamp(dot(x, y), T(-1), T(1))));
|
2013-12-26 18:15:48 +00:00
|
|
|
return mix(Angle, -Angle, dot(ref, cross(x, y)) < T(0));
|
2011-10-14 13:07:53 +00:00
|
|
|
}
|
2010-04-29 10:54:07 +00:00
|
|
|
}//namespace glm
|