2010-04-29 10:54:07 +00:00
|
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
2011-01-20 11:40:14 +00:00
|
|
|
// OpenGL Mathematics Copyright (c) 2005 - 2011 G-Truc Creation (www.g-truc.net)
|
2010-04-29 10:54:07 +00:00
|
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Created : 2005-12-30
|
|
|
|
// Updated : 2008-09-29
|
|
|
|
// Licence : This source is under MIT License
|
|
|
|
// File : glm/gtx/vector_angle.inl
|
|
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
namespace glm{
|
|
|
|
|
|
|
|
template <typename genType>
|
2011-04-09 08:44:32 +00:00
|
|
|
GLM_FUNC_QUALIFIER typename genType::value_type angle
|
2010-04-29 10:54:07 +00:00
|
|
|
(
|
|
|
|
genType const & x,
|
|
|
|
genType const & y
|
|
|
|
)
|
|
|
|
{
|
|
|
|
return degrees(acos(dot(x, y)));
|
|
|
|
}
|
|
|
|
|
|
|
|
//! \todo epsilon is hard coded to 0.01
|
|
|
|
template <typename valType>
|
2011-04-09 08:44:32 +00:00
|
|
|
GLM_FUNC_QUALIFIER valType orientedAngle
|
2010-04-29 10:54:07 +00:00
|
|
|
(
|
|
|
|
detail::tvec2<valType> const & x,
|
|
|
|
detail::tvec2<valType> const & y
|
|
|
|
)
|
|
|
|
{
|
2011-05-17 16:19:38 +00:00
|
|
|
valType Angle = glm::degrees(acos(dot(x, y)));
|
2011-06-10 15:45:17 +00:00
|
|
|
detail::tvec2<valType> TransformedVector = glm::rotate(x, Angle);
|
2011-05-17 16:19:38 +00:00
|
|
|
if(all(equalEpsilon(y, TransformedVector, valType(0.01))))
|
|
|
|
return Angle;
|
2010-04-29 10:54:07 +00:00
|
|
|
else
|
2011-05-17 16:19:38 +00:00
|
|
|
return -Angle;
|
2010-04-29 10:54:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
template <typename valType>
|
2011-05-17 16:19:38 +00:00
|
|
|
GLM_FUNC_QUALIFIER valType orientedAngle
|
2010-04-29 10:54:07 +00:00
|
|
|
(
|
|
|
|
detail::tvec3<valType> const & x,
|
|
|
|
detail::tvec3<valType> const & y,
|
|
|
|
detail::tvec3<valType> const & ref
|
|
|
|
)
|
|
|
|
{
|
2011-05-17 16:19:38 +00:00
|
|
|
valType Angle = glm::degrees(glm::acos(glm::dot(x, y)));
|
2010-04-29 10:54:07 +00:00
|
|
|
|
|
|
|
if(glm::dot(ref, glm::cross(x, y)) < valType(0))
|
2011-05-17 16:19:38 +00:00
|
|
|
return -Angle;
|
2010-04-29 10:54:07 +00:00
|
|
|
else
|
2011-05-17 16:19:38 +00:00
|
|
|
return Angle;
|
2010-04-29 10:54:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}//namespace glm
|