mirror of
https://github.com/g-truc/glm.git
synced 2024-11-23 01:14:34 +00:00
Merge more precision for fastCos and fastSin #264
This commit is contained in:
commit
cfce5f436c
@ -297,7 +297,7 @@ namespace detail
|
||||
template <typename genType>
|
||||
GLM_FUNC_QUALIFIER genType mod(genType x, genType y)
|
||||
{
|
||||
return tvec1<genType>(x, y).x;
|
||||
return mod(tvec1<genType>(x), y).x;
|
||||
}
|
||||
|
||||
template <typename T, precision P, template <typename, precision> class vecType>
|
||||
|
@ -71,6 +71,11 @@ namespace glm
|
||||
template <typename genType>
|
||||
GLM_FUNC_DECL genType pi();
|
||||
|
||||
/// Return pi * 2.
|
||||
/// @see gtc_constants
|
||||
template <typename genType>
|
||||
GLM_FUNC_DECL genType two_pi();
|
||||
|
||||
/// Return square root of pi.
|
||||
/// @see gtc_constants
|
||||
template <typename genType>
|
||||
@ -81,6 +86,11 @@ namespace glm
|
||||
template <typename genType>
|
||||
GLM_FUNC_DECL genType half_pi();
|
||||
|
||||
/// Return pi / 2 * 3.
|
||||
/// @see gtc_constants
|
||||
template <typename genType>
|
||||
GLM_FUNC_DECL genType three_over_two_pi();
|
||||
|
||||
/// Return pi / 4.
|
||||
/// @see gtc_constants
|
||||
template <typename genType>
|
||||
@ -91,11 +101,21 @@ namespace glm
|
||||
template <typename genType>
|
||||
GLM_FUNC_DECL genType one_over_pi();
|
||||
|
||||
/// Return 1 / (pi * 2).
|
||||
/// @see gtc_constants
|
||||
template <typename genType>
|
||||
GLM_FUNC_DECL genType one_over_two_pi();
|
||||
|
||||
/// Return 2 / pi.
|
||||
/// @see gtc_constants
|
||||
template <typename genType>
|
||||
GLM_FUNC_DECL genType two_over_pi();
|
||||
|
||||
/// Return 4 / pi.
|
||||
/// @see gtc_constants
|
||||
template <typename genType>
|
||||
GLM_FUNC_DECL genType four_over_pi();
|
||||
|
||||
/// Return 2 / sqrt(pi).
|
||||
/// @see gtc_constants
|
||||
template <typename genType>
|
||||
|
@ -54,6 +54,12 @@ namespace glm
|
||||
return genType(3.14159265358979323846264338327950288);
|
||||
}
|
||||
|
||||
template <typename genType>
|
||||
GLM_FUNC_QUALIFIER genType two_pi()
|
||||
{
|
||||
return genType(6.28318530717958647692528676655900576);
|
||||
}
|
||||
|
||||
template <typename genType>
|
||||
GLM_FUNC_QUALIFIER genType root_pi()
|
||||
{
|
||||
@ -66,6 +72,12 @@ namespace glm
|
||||
return genType(1.57079632679489661923132169163975144);
|
||||
}
|
||||
|
||||
template <typename genType>
|
||||
GLM_FUNC_QUALIFIER genType three_over_two_pi()
|
||||
{
|
||||
return genType(4.71238898038468985769396507491925432);
|
||||
}
|
||||
|
||||
template <typename genType>
|
||||
GLM_FUNC_QUALIFIER genType quarter_pi()
|
||||
{
|
||||
@ -78,12 +90,24 @@ namespace glm
|
||||
return genType(0.318309886183790671537767526745028724);
|
||||
}
|
||||
|
||||
template <typename genType>
|
||||
GLM_FUNC_QUALIFIER genType one_over_two_pi()
|
||||
{
|
||||
return genType(0.159154943091895335768883763372514362);
|
||||
}
|
||||
|
||||
template <typename genType>
|
||||
GLM_FUNC_QUALIFIER genType two_over_pi()
|
||||
{
|
||||
return genType(0.636619772367581343075535053490057448);
|
||||
}
|
||||
|
||||
template <typename genType>
|
||||
GLM_FUNC_QUALIFIER genType four_over_pi()
|
||||
{
|
||||
return genType(1.273239544735162686151070106980114898);
|
||||
}
|
||||
|
||||
template <typename genType>
|
||||
GLM_FUNC_QUALIFIER genType two_over_root_pi()
|
||||
{
|
||||
|
@ -39,6 +39,7 @@
|
||||
|
||||
// Dependency:
|
||||
#include "../glm.hpp"
|
||||
#include "../gtc/constants.hpp"
|
||||
|
||||
#if(defined(GLM_MESSAGES) && !defined(GLM_EXT_INCLUDED))
|
||||
# pragma message("GLM: GLM_GTX_fast_trigonometry extension included")
|
||||
@ -49,45 +50,48 @@ namespace glm
|
||||
/// @addtogroup gtx_fast_trigonometry
|
||||
/// @{
|
||||
|
||||
//! Faster than the common sin function but less accurate.
|
||||
//! Defined between -2pi and 2pi.
|
||||
//! From GLM_GTX_fast_trigonometry extension.
|
||||
/// Wrap an angle to [0 2pi[
|
||||
/// From GLM_GTX_fast_trigonometry extension.
|
||||
template <typename T>
|
||||
GLM_FUNC_DECL T wrapAngle(T angle);
|
||||
|
||||
/// Faster than the common sin function but less accurate.
|
||||
/// From GLM_GTX_fast_trigonometry extension.
|
||||
template <typename T>
|
||||
GLM_FUNC_DECL T fastSin(T angle);
|
||||
|
||||
//! Faster than the common cos function but less accurate.
|
||||
//! Defined between -2pi and 2pi.
|
||||
//! From GLM_GTX_fast_trigonometry extension.
|
||||
/// Faster than the common cos function but less accurate.
|
||||
/// From GLM_GTX_fast_trigonometry extension.
|
||||
template <typename T>
|
||||
GLM_FUNC_DECL T fastCos(T angle);
|
||||
|
||||
//! Faster than the common tan function but less accurate.
|
||||
//! Defined between -2pi and 2pi.
|
||||
//! From GLM_GTX_fast_trigonometry extension.
|
||||
/// Faster than the common tan function but less accurate.
|
||||
/// Defined between -2pi and 2pi.
|
||||
/// From GLM_GTX_fast_trigonometry extension.
|
||||
template <typename T>
|
||||
GLM_FUNC_DECL T fastTan(T angle);
|
||||
|
||||
//! Faster than the common asin function but less accurate.
|
||||
//! Defined between -2pi and 2pi.
|
||||
//! From GLM_GTX_fast_trigonometry extension.
|
||||
/// Faster than the common asin function but less accurate.
|
||||
/// Defined between -2pi and 2pi.
|
||||
/// From GLM_GTX_fast_trigonometry extension.
|
||||
template <typename T>
|
||||
GLM_FUNC_DECL T fastAsin(T angle);
|
||||
|
||||
//! Faster than the common acos function but less accurate.
|
||||
//! Defined between -2pi and 2pi.
|
||||
//! From GLM_GTX_fast_trigonometry extension.
|
||||
/// Faster than the common acos function but less accurate.
|
||||
/// Defined between -2pi and 2pi.
|
||||
/// From GLM_GTX_fast_trigonometry extension.
|
||||
template <typename T>
|
||||
GLM_FUNC_DECL T fastAcos(T angle);
|
||||
|
||||
//! Faster than the common atan function but less accurate.
|
||||
//! Defined between -2pi and 2pi.
|
||||
//! From GLM_GTX_fast_trigonometry extension.
|
||||
/// Faster than the common atan function but less accurate.
|
||||
/// Defined between -2pi and 2pi.
|
||||
/// From GLM_GTX_fast_trigonometry extension.
|
||||
template <typename T>
|
||||
GLM_FUNC_DECL T fastAtan(T y, T x);
|
||||
|
||||
//! Faster than the common atan function but less accurate.
|
||||
//! Defined between -2pi and 2pi.
|
||||
//! From GLM_GTX_fast_trigonometry extension.
|
||||
/// Faster than the common atan function but less accurate.
|
||||
/// Defined between -2pi and 2pi.
|
||||
/// From GLM_GTX_fast_trigonometry extension.
|
||||
template <typename T>
|
||||
GLM_FUNC_DECL T fastAtan(T angle);
|
||||
|
||||
|
@ -7,26 +7,50 @@
|
||||
// File : glm/gtx/fast_trigonometry.inl
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
namespace glm
|
||||
namespace glm{
|
||||
namespace detail
|
||||
{
|
||||
// sin
|
||||
template <typename T>
|
||||
GLM_FUNC_QUALIFIER T fastSin(T x)
|
||||
template <typename T>
|
||||
GLM_FUNC_QUALIFIER T cos_52s(T x)
|
||||
{
|
||||
return x - ((x * x * x) / T(6)) + ((x * x * x * x * x) / T(120)) - ((x * x * x * x * x * x * x) / T(5040));
|
||||
T const xx(x * x);
|
||||
return (T(0.9999932946) + xx * (T(-0.4999124376) + xx * (T(0.0414877472) + xx * T(-0.0012712095))));
|
||||
}
|
||||
|
||||
template <typename T, precision P, template <typename, precision> class vecType>
|
||||
GLM_FUNC_QUALIFIER vecType<T, P> fastSin(vecType<T, P> const & x)
|
||||
GLM_FUNC_QUALIFIER vecType<T, P> cos_52s(vecType<T, P> const & x)
|
||||
{
|
||||
return detail::functor1<T, T, P, vecType>::call(fastSin, x);
|
||||
return detail::functor1<T, T, P, vecType>::call(cos_52s, x);
|
||||
}
|
||||
}//namespace detail
|
||||
|
||||
// wrapAngle
|
||||
template <typename T>
|
||||
GLM_FUNC_QUALIFIER T wrapAngle(T angle)
|
||||
{
|
||||
return abs<T>(mod<T>(angle, two_pi<T>()));
|
||||
}
|
||||
|
||||
template <typename T, precision P, template <typename, precision> class vecType>
|
||||
GLM_FUNC_QUALIFIER vecType<T, P> wrapAngle(vecType<T, P> const & x)
|
||||
{
|
||||
return detail::functor1<T, T, P, vecType>::call(wrapAngle, x);
|
||||
}
|
||||
|
||||
// cos
|
||||
template <typename T>
|
||||
GLM_FUNC_QUALIFIER T fastCos(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));
|
||||
T const angle(wrapAngle<T>(x));
|
||||
|
||||
if(angle<half_pi<T>())
|
||||
return detail::cos_52s(angle);
|
||||
if(angle<pi<T>())
|
||||
return -detail::cos_52s(pi<T>() - angle);
|
||||
if(angle<(T(3) * half_pi<T>()))
|
||||
return -detail::cos_52s(angle - pi<T>());
|
||||
|
||||
return detail::cos_52s(two_pi<T>() - angle);
|
||||
}
|
||||
|
||||
template <typename T, precision P, template <typename, precision> class vecType>
|
||||
@ -35,6 +59,19 @@ namespace glm
|
||||
return detail::functor1<T, T, P, vecType>::call(fastCos, x);
|
||||
}
|
||||
|
||||
// sin
|
||||
template <typename T>
|
||||
GLM_FUNC_QUALIFIER T fastSin(T x)
|
||||
{
|
||||
return fastCos<T>(half_pi<T>() - x);
|
||||
}
|
||||
|
||||
template <typename T, precision P, template <typename, precision> class vecType>
|
||||
GLM_FUNC_QUALIFIER vecType<T, P> fastSin(vecType<T, P> const & x)
|
||||
{
|
||||
return detail::functor1<T, T, P, vecType>::call(fastSin, x);
|
||||
}
|
||||
|
||||
// tan
|
||||
template <typename T>
|
||||
GLM_FUNC_QUALIFIER T fastTan(T x)
|
||||
|
Loading…
Reference in New Issue
Block a user