| 1 | /// @ref gtx_vector_angle |
| 2 | |
| 3 | namespace glm |
| 4 | { |
| 5 | template<typename genType> |
| 6 | GLM_FUNC_QUALIFIER genType angle |
| 7 | ( |
| 8 | genType const& x, |
| 9 | genType const& y |
| 10 | ) |
| 11 | { |
| 12 | GLM_STATIC_ASSERT(std::numeric_limits<genType>::is_iec559, "'angle' only accept floating-point inputs"); |
| 13 | return acos(clamp(dot(x, y), genType(-1), genType(1))); |
| 14 | } |
| 15 | |
| 16 | template<length_t L, typename T, qualifier Q> |
| 17 | GLM_FUNC_QUALIFIER T angle(vec<L, T, Q> const& x, vec<L, T, Q> const& y) |
| 18 | { |
| 19 | GLM_STATIC_ASSERT(std::numeric_limits<T>::is_iec559, "'angle' only accept floating-point inputs"); |
| 20 | return acos(clamp(dot(x, y), T(-1), T(1))); |
| 21 | } |
| 22 | |
| 23 | //! \todo epsilon is hard coded to 0.01 |
| 24 | template<typename T, qualifier Q> |
| 25 | GLM_FUNC_QUALIFIER T orientedAngle(vec<2, T, Q> const& x, vec<2, T, Q> const& y) |
| 26 | { |
| 27 | GLM_STATIC_ASSERT(std::numeric_limits<T>::is_iec559, "'orientedAngle' only accept floating-point inputs"); |
| 28 | T const Angle(acos(clamp(dot(x, y), T(-1), T(1)))); |
| 29 | |
| 30 | if(all(epsilonEqual(y, glm::rotate(x, Angle), T(0.0001)))) |
| 31 | return Angle; |
| 32 | else |
| 33 | return -Angle; |
| 34 | } |
| 35 | |
| 36 | template<typename T, qualifier Q> |
| 37 | GLM_FUNC_QUALIFIER T orientedAngle(vec<3, T, Q> const& x, vec<3, T, Q> const& y, vec<3, T, Q> const& ref) |
| 38 | { |
| 39 | GLM_STATIC_ASSERT(std::numeric_limits<T>::is_iec559, "'orientedAngle' only accept floating-point inputs"); |
| 40 | |
| 41 | T const Angle(acos(clamp(dot(x, y), T(-1), T(1)))); |
| 42 | return mix(Angle, -Angle, dot(ref, cross(x, y)) < T(0)); |
| 43 | } |
| 44 | }//namespace glm |