summaryrefslogtreecommitdiff
path: root/include/gal/opengl/glm/gtx/fast_trigonometry.inl
blob: b2179a61529619953b2921419688620a7b123cf7 (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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
///////////////////////////////////////////////////////////////////////////////////////////////////
// OpenGL Mathematics Copyright (c) 2005 - 2013 G-Truc Creation (www.g-truc.net)
///////////////////////////////////////////////////////////////////////////////////////////////////
// Created : 2006-01-08
// Updated : 2011-10-14
// Licence : This source is under MIT License
// File    : glm/gtx/fast_trigonometry.inl
///////////////////////////////////////////////////////////////////////////////////////////////////

namespace glm
{
	// sin
	template <typename T> 
	GLM_FUNC_QUALIFIER T fastSin(T const & x)
	{
		return x - ((x * x * x) / T(6)) + ((x * x * x * x * x) / T(120)) - ((x * x * x * x * x * x * x) / T(5040));
	}

	VECTORIZE_VEC(fastSin)

	// cos
	template <typename T> 
	GLM_FUNC_QUALIFIER T fastCos(T const & x)
	{
		return T(1) - (x * x * T(0.5)) + (x * x * x * x * T(0.041666666666)) - (x * x * x * x * x * x * T(0.00138888888888));
	}

	VECTORIZE_VEC(fastCos)

	// tan
	template <typename T> 
	GLM_FUNC_QUALIFIER T fastTan(T const & x)
	{
		return x + (x * x * x * T(0.3333333333)) + (x * x * x * x * x * T(0.1333333333333)) + (x * x * x * x * x * x * x * T(0.0539682539));
	}

	VECTORIZE_VEC(fastTan)

	// asin
	template <typename T> 
	GLM_FUNC_QUALIFIER T fastAsin(T const & x)
	{
		return x + (x * x * x * T(0.166666667)) + (x * x * x * x * x * T(0.075)) + (x * x * x * x * x * x * x * T(0.0446428571)) + (x * x * x * x * x * x * x * x * x * T(0.0303819444));// + (x * x * x * x * x * x * x * x * x * x * x * T(0.022372159));
	}

	VECTORIZE_VEC(fastAsin)

	// acos
	template <typename T> 
	GLM_FUNC_QUALIFIER T fastAcos(T const & x)
	{
		return T(1.5707963267948966192313216916398) - fastAsin(x); //(PI / 2)
	}

	VECTORIZE_VEC(fastAcos)

	// atan
	template <typename T> 
	GLM_FUNC_QUALIFIER T fastAtan(T const & y, T const & x)
	{
		T sgn = sign(y) * sign(x);
		return abs(fastAtan(y / x)) * sgn;
	}

	VECTORIZE_VEC_VEC(fastAtan)

	template <typename T> 
	GLM_FUNC_QUALIFIER T fastAtan(T const & x)
	{
		return x - (x * x * x * T(0.333333333333)) + (x * x * x * x * x * T(0.2)) - (x * x * x * x * x * x * x * T(0.1428571429)) + (x * x * x * x * x * x * x * x * x * T(0.111111111111)) - (x * x * x * x * x * x * x * x * x * x * x * T(0.0909090909));
	}

	VECTORIZE_VEC(fastAtan)

}//namespace glm