| 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 | 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 | static_assert(std::numeric_limits<T>::is_iec559 || GLM_CONFIG_UNRESTRICTED_FLOAT, "'angle' only accept floating-point inputs"); |
| 20 | return acos(clamp(dot(x, y), T(-1), T(1))); |
| 21 | } |
| 22 | |
| 23 | template<typename T, qualifier Q> |
| 24 | GLM_FUNC_QUALIFIER T orientedAngle(vec<2, T, Q> const& x, vec<2, T, Q> const& y) |
| 25 | { |
| 26 | static_assert(std::numeric_limits<T>::is_iec559 || GLM_CONFIG_UNRESTRICTED_FLOAT, "'orientedAngle' only accept floating-point inputs"); |
| 27 | T const Angle(acos(clamp(dot(x, y), T(-1), T(1)))); |
| 28 | |
| 29 | T const partialCross = x.x * y.y - y.x * x.y; |
| 30 | |
| 31 | if (partialCross > T(0)) |
| 32 | return Angle; |
| 33 | else |
| 34 | return -Angle; |
| 35 | } |
| 36 | |
| 37 | template<typename T, qualifier Q> |
| 38 | GLM_FUNC_QUALIFIER T orientedAngle(vec<3, T, Q> const& x, vec<3, T, Q> const& y, vec<3, T, Q> const& ref) |
| 39 | { |
| 40 | static_assert(std::numeric_limits<T>::is_iec559 || GLM_CONFIG_UNRESTRICTED_FLOAT, "'orientedAngle' only accept floating-point inputs"); |
| 41 | |
| 42 | T const Angle(acos(clamp(dot(x, y), T(-1), T(1)))); |
| 43 | return mix(Angle, -Angle, dot(ref, cross(x, y)) < T(0)); |
| 44 | } |
| 45 | }//namespace glm |