summaryrefslogtreecommitdiff
path: root/include/gal/opengl/glm/gtx/vector_angle.inl
blob: ad221b15ddd536e293fb6e0176d0d881c4575022 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
///////////////////////////////////////////////////////////////////////////////////////////////////
// OpenGL Mathematics Copyright (c) 2005 - 2013 G-Truc Creation (www.g-truc.net)
///////////////////////////////////////////////////////////////////////////////////////////////////
// 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> 
	GLM_FUNC_QUALIFIER typename genType::value_type angle
	(
		genType const & x, 
		genType const & y
	)
	{
		return degrees(acos(dot(x, y)));
	}

	//! \todo epsilon is hard coded to 0.01
	template <typename valType> 
	GLM_FUNC_QUALIFIER valType orientedAngle
	(
		detail::tvec2<valType> const & x, 
		detail::tvec2<valType> const & y
	)
	{
#ifdef GLM_FORCE_RADIANS
		valType const Angle(acos(dot(x, y)));
#else
		valType const Angle(glm::degrees(acos(dot(x, y))));
#endif
		detail::tvec2<valType> const TransformedVector(glm::rotate(x, Angle));
		if(all(epsilonEqual(y, TransformedVector, valType(0.01))))
			return Angle;
		else
			return -Angle;
	}

	template <typename valType>
	GLM_FUNC_QUALIFIER valType orientedAngle
	(
		detail::tvec3<valType> const & x,
		detail::tvec3<valType> const & y,
		detail::tvec3<valType> const & ref
	)
	{
		valType const Angle(glm::degrees(glm::acos(glm::dot(x, y))));

		if(glm::dot(ref, glm::cross(x, y)) < valType(0))
			return -Angle;
		else
			return Angle;
	}
}//namespace glm