• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1///////////////////////////////////////////////////////////////////////////////////////////////////
2// OpenGL Mathematics Copyright (c) 2005 - 2014 G-Truc Creation (www.g-truc.net)
3///////////////////////////////////////////////////////////////////////////////////////////////////
4// Created : 2005-12-30
5// Updated : 2008-09-29
6// Licence : This source is under MIT License
7// File    : glm/gtx/vector_angle.inl
8///////////////////////////////////////////////////////////////////////////////////////////////////
9
10namespace glm
11{
12	template <typename genType>
13	GLM_FUNC_QUALIFIER genType angle
14	(
15		genType const & x,
16		genType const & y
17	)
18	{
19		GLM_STATIC_ASSERT(std::numeric_limits<genType>::is_iec559, "'angle' only accept floating-point inputs");
20
21		genType const Angle(acos(clamp(dot(x, y), genType(-1), genType(1))));
22
23#ifdef GLM_FORCE_RADIANS
24		return Angle;
25#else
26#		pragma message("GLM: angle function returning degrees is deprecated. #define GLM_FORCE_RADIANS before including GLM headers to remove this message.")
27		return degrees(Angle);
28#endif
29	}
30
31	template <typename T, precision P, template <typename, precision> class vecType>
32	GLM_FUNC_QUALIFIER T angle
33	(
34		vecType<T, P> const & x,
35		vecType<T, P> const & y
36	)
37	{
38		GLM_STATIC_ASSERT(std::numeric_limits<T>::is_iec559, "'angle' only accept floating-point inputs");
39
40		T const Angle(acos(clamp(dot(x, y), T(-1), T(1))));
41
42#ifdef GLM_FORCE_RADIANS
43		return Angle;
44#else
45#		pragma message("GLM: angle function returning degrees is deprecated. #define GLM_FORCE_RADIANS before including GLM headers to remove this message.")
46		return degrees(Angle);
47#endif
48	}
49
50	//! \todo epsilon is hard coded to 0.01
51	template <typename T, precision P>
52	GLM_FUNC_QUALIFIER T orientedAngle
53	(
54		detail::tvec2<T, P> const & x,
55		detail::tvec2<T, P> const & y
56	)
57	{
58		GLM_STATIC_ASSERT(std::numeric_limits<T>::is_iec559, "'orientedAngle' only accept floating-point inputs");
59
60		T const Dot = clamp(dot(x, y), T(-1), T(1));
61
62#ifdef GLM_FORCE_RADIANS
63		T const Angle(acos(Dot));
64#else
65#		pragma message("GLM: orientedAngle function returning degrees is deprecated. #define GLM_FORCE_RADIANS before including GLM headers to remove this message.")
66		T const Angle(degrees(acos(Dot)));
67#endif
68		detail::tvec2<T, P> const TransformedVector(glm::rotate(x, Angle));
69		if(all(epsilonEqual(y, TransformedVector, T(0.01))))
70			return Angle;
71		else
72			return -Angle;
73	}
74
75	template <typename T, precision P>
76	GLM_FUNC_QUALIFIER T orientedAngle
77	(
78		detail::tvec3<T, P> const & x,
79		detail::tvec3<T, P> const & y,
80		detail::tvec3<T, P> const & ref
81	)
82	{
83		GLM_STATIC_ASSERT(std::numeric_limits<T>::is_iec559, "'orientedAngle' only accept floating-point inputs");
84
85		T const Dot = clamp(dot(x, y), T(-1), T(1));
86
87#ifdef GLM_FORCE_RADIANS
88		T const Angle(acos(Dot));
89#else
90#		pragma message("GLM: orientedAngle function returning degrees is deprecated. #define GLM_FORCE_RADIANS before including GLM headers to remove this message.")
91		T const Angle(degrees(acos(Dot)));
92#endif
93
94		if(dot(ref, cross(x, y)) < T(0))
95			return -Angle;
96		else
97			return Angle;
98	}
99}//namespace glm
100