From 7e9ca13cde94f5b1de5dc31b15b9ce41dffea197 Mon Sep 17 00:00:00 2001 From: Christophe Riccio Date: Fri, 14 Oct 2011 13:19:15 +0100 Subject: [PATCH] Vectorized --- glm/gtx/fast_trigonometry.inl | 295 ++++++---------------------------- 1 file changed, 52 insertions(+), 243 deletions(-) diff --git a/glm/gtx/fast_trigonometry.inl b/glm/gtx/fast_trigonometry.inl index 65293909..c516ea36 100644 --- a/glm/gtx/fast_trigonometry.inl +++ b/glm/gtx/fast_trigonometry.inl @@ -2,267 +2,76 @@ // OpenGL Mathematics Copyright (c) 2005 - 2011 G-Truc Creation (www.g-truc.net) /////////////////////////////////////////////////////////////////////////////////////////////////// // Created : 2006-01-08 -// Updated : 2006-01-08 +// Updated : 2011-10-14 // Licence : This source is under MIT License // File : glm/gtx/fast_trigonometry.inl /////////////////////////////////////////////////////////////////////////////////////////////////// -namespace glm{ +#include "../core/_vectorize.hpp" -// sin -template -GLM_FUNC_QUALIFIER T fastSin(const T x) +namespace glm { - return x - ((x * x * x) / T(6)) + ((x * x * x * x * x) / T(120)) - ((x * x * x * x * x * x * x) / T(5040)); -} + // sin + template + 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)); + } -template -GLM_FUNC_QUALIFIER detail::tvec2 fastSin( - const detail::tvec2& x) -{ - return detail::tvec2( - fastSin(x.x), - fastSin(x.y)); -} + VECTORIZE_VEC(fastSin) -template -GLM_FUNC_QUALIFIER detail::tvec3 fastSin( - const detail::tvec3& x) -{ - return detail::tvec3( - fastSin(x.x), - fastSin(x.y), - fastSin(x.z)); -} + // cos + template + 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)); + } -template -GLM_FUNC_QUALIFIER detail::tvec4 fastSin( - const detail::tvec4& x) -{ - return detail::tvec4( - fastSin(x.x), - fastSin(x.y), - fastSin(x.z), - fastSin(x.w)); -} + VECTORIZE_VEC(fastCos) -// cos -template -GLM_FUNC_QUALIFIER T fastCos(const T 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)); -} + // tan + template + 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)); + } -template -GLM_FUNC_QUALIFIER detail::tvec2 fastCos( - const detail::tvec2& x) -{ - return detail::tvec2( - fastCos(x.x), - fastCos(x.y)); -} + VECTORIZE_VEC(fastTan) -template -GLM_FUNC_QUALIFIER detail::tvec3 fastCos( - const detail::tvec3& x) -{ - return detail::tvec3( - fastCos(x.x), - fastCos(x.y), - fastCos(x.z)); -} + // asin + template + 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)); + } -template -GLM_FUNC_QUALIFIER detail::tvec4 fastCos( - const detail::tvec4& x) -{ - return detail::tvec4( - fastCos(x.x), - fastCos(x.y), - fastCos(x.z), - fastCos(x.w)); -} + VECTORIZE_VEC(fastAsin) -// tan -template -GLM_FUNC_QUALIFIER T fastTan(const T 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)); -} + // acos + template + GLM_FUNC_QUALIFIER T fastAcos(T const & x) + { + return T(1.5707963267948966192313216916398) - fastAsin(x); //(PI / 2) + } -template -GLM_FUNC_QUALIFIER detail::tvec2 fastTan( - const detail::tvec2& x) -{ - return detail::tvec2( - fastTan(x.x), - fastTan(x.y)); -} + VECTORIZE_VEC(fastAcos) -template -GLM_FUNC_QUALIFIER detail::tvec3 fastTan( - const detail::tvec3& x) -{ - return detail::tvec3( - fastTan(x.x), - fastTan(x.y), - fastTan(x.z)); -} + // atan + template + GLM_FUNC_QUALIFIER T fastAtan(T const & y, T const & x) + { + T sgn = sign(y) * sign(x); + return abs(fastAtan(y / x)) * sgn; + } -template -GLM_FUNC_QUALIFIER detail::tvec4 fastTan( - const detail::tvec4& x) -{ - return detail::tvec4( - fastTan(x.x), - fastTan(x.y), - fastTan(x.z), - fastTan(x.w)); -} + VECTORIZE_VEC_VEC(fastAtan) -// asin -template -GLM_FUNC_QUALIFIER T fastAsin(const T 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)); -} + template + 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)); + } -template detail::tvec2 fastAsin( - const detail::tvec2& x) -{ - return detail::tvec2( - fastAsin(x.x), - fastAsin(x.y)); -} - -template detail::tvec3 fastAsin( - const detail::tvec3& x) -{ - return detail::tvec3( - fastAsin(x.x), - fastAsin(x.y), - fastAsin(x.z)); -} - -template detail::tvec4 fastAsin( - const detail::tvec4& x) -{ - return detail::tvec4( - fastAsin(x.x), - fastAsin(x.y), - fastAsin(x.z), - fastAsin(x.w)); -} - -// acos -template -GLM_FUNC_QUALIFIER T fastAcos(const T x) -{ - return T(1.5707963267948966192313216916398) - fastAsin(x); //(PI / 2) -} - -template detail::tvec2 fastAcos( - const detail::tvec2& x) -{ - return detail::tvec2( - fastAcos(x.x), - fastAcos(x.y)); -} - -template detail::tvec3 fastAcos( - const detail::tvec3& x) -{ - return detail::tvec3( - fastAcos(x.x), - fastAcos(x.y), - fastAcos(x.z)); -} - -template detail::tvec4 fastAcos( - const detail::tvec4& x) -{ - return detail::tvec4( - fastAcos(x.x), - fastAcos(x.y), - fastAcos(x.z), - fastAcos(x.w)); -} - -// atan -template -GLM_FUNC_QUALIFIER T fastAtan(const T y, const T x) -{ - T sgn = sign(y) * sign(x); - return abs(fastAtan(y / x)) * sgn; -} - -template -GLM_FUNC_QUALIFIER detail::tvec2 fastAtan( - const detail::tvec2& y, - const detail::tvec2& x) -{ - return detail::tvec2( - fastAtan(y.x, x.x), - fastAtan(y.y, x.y)); -} - -template -GLM_FUNC_QUALIFIER detail::tvec3 fastAtan( - const detail::tvec3& y, - const detail::tvec3& x) -{ - return detail::tvec3( - fastAtan(y.x, x.x), - fastAtan(y.y, x.y), - fastAtan(y.z, x.z)); -} - -template -GLM_FUNC_QUALIFIER detail::tvec4 fastAtan( - const detail::tvec4& y, - const detail::tvec4& x) -{ - return detail::tvec4( - fastAtan(y.x, x.x), - fastAtan(y.y, x.y), - fastAtan(y.z, x.z), - fastAtan(y.w, x.w)); -} - -template -GLM_FUNC_QUALIFIER T fastAtan(const T 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)); -} - -template -GLM_FUNC_QUALIFIER detail::tvec2 fastAtan( - const detail::tvec2& x) -{ - return detail::tvec2( - fastAtan(x.x), - fastAtan(x.y)); -} - -template -GLM_FUNC_QUALIFIER detail::tvec3 fastAtan( - const detail::tvec3& x) -{ - return detail::tvec3( - fastAtan(x.x), - fastAtan(x.y), - fastAtan(x.z)); -} - -template -GLM_FUNC_QUALIFIER detail::tvec4 fastAtan( - const detail::tvec4& x) -{ - return detail::tvec4( - fastAtan(x.x), - fastAtan(x.y), - fastAtan(x.z), - fastAtan(x.w)); -} + VECTORIZE_VEC(fastAtan) }//namespace glm