Vectorized

This commit is contained in:
Christophe Riccio 2011-10-14 13:19:15 +01:00
parent 86be6440e3
commit 7e9ca13cde

View File

@ -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 <typename T>
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 <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));
}
template <typename T>
GLM_FUNC_QUALIFIER detail::tvec2<T> fastSin(
const detail::tvec2<T>& x)
{
return detail::tvec2<T>(
fastSin(x.x),
fastSin(x.y));
}
VECTORIZE_VEC(fastSin)
template <typename T>
GLM_FUNC_QUALIFIER detail::tvec3<T> fastSin(
const detail::tvec3<T>& x)
{
return detail::tvec3<T>(
fastSin(x.x),
fastSin(x.y),
fastSin(x.z));
}
// 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));
}
template <typename T>
GLM_FUNC_QUALIFIER detail::tvec4<T> fastSin(
const detail::tvec4<T>& x)
{
return detail::tvec4<T>(
fastSin(x.x),
fastSin(x.y),
fastSin(x.z),
fastSin(x.w));
}
VECTORIZE_VEC(fastCos)
// cos
template <typename T>
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 <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));
}
template <typename T>
GLM_FUNC_QUALIFIER detail::tvec2<T> fastCos(
const detail::tvec2<T>& x)
{
return detail::tvec2<T>(
fastCos(x.x),
fastCos(x.y));
}
VECTORIZE_VEC(fastTan)
template <typename T>
GLM_FUNC_QUALIFIER detail::tvec3<T> fastCos(
const detail::tvec3<T>& x)
{
return detail::tvec3<T>(
fastCos(x.x),
fastCos(x.y),
fastCos(x.z));
}
// 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));
}
template <typename T>
GLM_FUNC_QUALIFIER detail::tvec4<T> fastCos(
const detail::tvec4<T>& x)
{
return detail::tvec4<T>(
fastCos(x.x),
fastCos(x.y),
fastCos(x.z),
fastCos(x.w));
}
VECTORIZE_VEC(fastAsin)
// tan
template <typename T>
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 <typename T>
GLM_FUNC_QUALIFIER T fastAcos(T const & x)
{
return T(1.5707963267948966192313216916398) - fastAsin(x); //(PI / 2)
}
template <typename T>
GLM_FUNC_QUALIFIER detail::tvec2<T> fastTan(
const detail::tvec2<T>& x)
{
return detail::tvec2<T>(
fastTan(x.x),
fastTan(x.y));
}
VECTORIZE_VEC(fastAcos)
template <typename T>
GLM_FUNC_QUALIFIER detail::tvec3<T> fastTan(
const detail::tvec3<T>& x)
{
return detail::tvec3<T>(
fastTan(x.x),
fastTan(x.y),
fastTan(x.z));
}
// 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;
}
template <typename T>
GLM_FUNC_QUALIFIER detail::tvec4<T> fastTan(
const detail::tvec4<T>& x)
{
return detail::tvec4<T>(
fastTan(x.x),
fastTan(x.y),
fastTan(x.z),
fastTan(x.w));
}
VECTORIZE_VEC_VEC(fastAtan)
// asin
template <typename T>
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 <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));
}
template <typename T> detail::tvec2<T> fastAsin(
const detail::tvec2<T>& x)
{
return detail::tvec2<T>(
fastAsin(x.x),
fastAsin(x.y));
}
template <typename T> detail::tvec3<T> fastAsin(
const detail::tvec3<T>& x)
{
return detail::tvec3<T>(
fastAsin(x.x),
fastAsin(x.y),
fastAsin(x.z));
}
template <typename T> detail::tvec4<T> fastAsin(
const detail::tvec4<T>& x)
{
return detail::tvec4<T>(
fastAsin(x.x),
fastAsin(x.y),
fastAsin(x.z),
fastAsin(x.w));
}
// acos
template <typename T>
GLM_FUNC_QUALIFIER T fastAcos(const T x)
{
return T(1.5707963267948966192313216916398) - fastAsin(x); //(PI / 2)
}
template <typename T> detail::tvec2<T> fastAcos(
const detail::tvec2<T>& x)
{
return detail::tvec2<T>(
fastAcos(x.x),
fastAcos(x.y));
}
template <typename T> detail::tvec3<T> fastAcos(
const detail::tvec3<T>& x)
{
return detail::tvec3<T>(
fastAcos(x.x),
fastAcos(x.y),
fastAcos(x.z));
}
template <typename T> detail::tvec4<T> fastAcos(
const detail::tvec4<T>& x)
{
return detail::tvec4<T>(
fastAcos(x.x),
fastAcos(x.y),
fastAcos(x.z),
fastAcos(x.w));
}
// atan
template <typename T>
GLM_FUNC_QUALIFIER T fastAtan(const T y, const T x)
{
T sgn = sign(y) * sign(x);
return abs(fastAtan(y / x)) * sgn;
}
template <typename T>
GLM_FUNC_QUALIFIER detail::tvec2<T> fastAtan(
const detail::tvec2<T>& y,
const detail::tvec2<T>& x)
{
return detail::tvec2<T>(
fastAtan(y.x, x.x),
fastAtan(y.y, x.y));
}
template <typename T>
GLM_FUNC_QUALIFIER detail::tvec3<T> fastAtan(
const detail::tvec3<T>& y,
const detail::tvec3<T>& x)
{
return detail::tvec3<T>(
fastAtan(y.x, x.x),
fastAtan(y.y, x.y),
fastAtan(y.z, x.z));
}
template <typename T>
GLM_FUNC_QUALIFIER detail::tvec4<T> fastAtan(
const detail::tvec4<T>& y,
const detail::tvec4<T>& x)
{
return detail::tvec4<T>(
fastAtan(y.x, x.x),
fastAtan(y.y, x.y),
fastAtan(y.z, x.z),
fastAtan(y.w, x.w));
}
template <typename T>
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 <typename T>
GLM_FUNC_QUALIFIER detail::tvec2<T> fastAtan(
const detail::tvec2<T>& x)
{
return detail::tvec2<T>(
fastAtan(x.x),
fastAtan(x.y));
}
template <typename T>
GLM_FUNC_QUALIFIER detail::tvec3<T> fastAtan(
const detail::tvec3<T>& x)
{
return detail::tvec3<T>(
fastAtan(x.x),
fastAtan(x.y),
fastAtan(x.z));
}
template <typename T>
GLM_FUNC_QUALIFIER detail::tvec4<T> fastAtan(
const detail::tvec4<T>& x)
{
return detail::tvec4<T>(
fastAtan(x.x),
fastAtan(x.y),
fastAtan(x.z),
fastAtan(x.w));
}
VECTORIZE_VEC(fastAtan)
}//namespace glm