mirror of
https://github.com/g-truc/glm.git
synced 2025-04-15 01:18:14 +00:00
Removed macros
This commit is contained in:
parent
86eae996e4
commit
4b4b6f6cac
11 changed files with 218 additions and 427 deletions
|
@ -155,54 +155,6 @@ namespace detail
|
|||
}//namespace detail
|
||||
}//namespace glm
|
||||
|
||||
#define VECTORIZE1_VEC(func) \
|
||||
template <typename T, precision P> \
|
||||
GLM_FUNC_QUALIFIER tvec1<T, P> func( \
|
||||
tvec1<T, P> const & v) \
|
||||
{ \
|
||||
return tvec1<T, P>( \
|
||||
func(v.x)); \
|
||||
}
|
||||
|
||||
#define VECTORIZE2_VEC(func) \
|
||||
template <typename T, precision P> \
|
||||
GLM_FUNC_QUALIFIER tvec2<T, P> func( \
|
||||
tvec2<T, P> const & v) \
|
||||
{ \
|
||||
return tvec2<T, P>( \
|
||||
func(v.x), \
|
||||
func(v.y)); \
|
||||
}
|
||||
|
||||
#define VECTORIZE3_VEC(func) \
|
||||
template <typename T, precision P> \
|
||||
GLM_FUNC_QUALIFIER tvec3<T, P> func( \
|
||||
tvec3<T, P> const & v) \
|
||||
{ \
|
||||
return tvec3<T, P>( \
|
||||
func(v.x), \
|
||||
func(v.y), \
|
||||
func(v.z)); \
|
||||
}
|
||||
|
||||
#define VECTORIZE4_VEC(func) \
|
||||
template <typename T, precision P> \
|
||||
GLM_FUNC_QUALIFIER tvec4<T, P> func( \
|
||||
tvec4<T, P> const & v) \
|
||||
{ \
|
||||
return tvec4<T, P>( \
|
||||
func(v.x), \
|
||||
func(v.y), \
|
||||
func(v.z), \
|
||||
func(v.w)); \
|
||||
}
|
||||
|
||||
#define VECTORIZE_VEC(func) \
|
||||
VECTORIZE1_VEC(func) \
|
||||
VECTORIZE2_VEC(func) \
|
||||
VECTORIZE3_VEC(func) \
|
||||
VECTORIZE4_VEC(func)
|
||||
|
||||
#define VECTORIZE1_VEC_SCA(func) \
|
||||
template <typename T, precision P> \
|
||||
GLM_FUNC_QUALIFIER tvec1<T, P> func \
|
||||
|
@ -263,66 +215,6 @@ namespace detail
|
|||
VECTORIZE3_VEC_SCA(func) \
|
||||
VECTORIZE4_VEC_SCA(func)
|
||||
|
||||
#define VECTORIZE1_VEC_VEC(func) \
|
||||
template <typename T, precision P> \
|
||||
GLM_FUNC_QUALIFIER tvec1<T, P> func \
|
||||
( \
|
||||
tvec1<T, P> const & x, \
|
||||
tvec1<T, P> const & y \
|
||||
) \
|
||||
{ \
|
||||
return tvec1<T, P>( \
|
||||
func(x.x, y.x)); \
|
||||
}
|
||||
|
||||
#define VECTORIZE2_VEC_VEC(func) \
|
||||
template <typename T, precision P> \
|
||||
GLM_FUNC_QUALIFIER tvec2<T, P> func \
|
||||
( \
|
||||
tvec2<T, P> const & x, \
|
||||
tvec2<T, P> const & y \
|
||||
) \
|
||||
{ \
|
||||
return tvec2<T, P>( \
|
||||
func(x.x, y.x), \
|
||||
func(x.y, y.y)); \
|
||||
}
|
||||
|
||||
#define VECTORIZE3_VEC_VEC(func) \
|
||||
template <typename T, precision P> \
|
||||
GLM_FUNC_QUALIFIER tvec3<T, P> func \
|
||||
( \
|
||||
tvec3<T, P> const & x, \
|
||||
tvec3<T, P> const & y \
|
||||
) \
|
||||
{ \
|
||||
return tvec3<T, P>( \
|
||||
func(x.x, y.x), \
|
||||
func(x.y, y.y), \
|
||||
func(x.z, y.z)); \
|
||||
}
|
||||
|
||||
#define VECTORIZE4_VEC_VEC(func) \
|
||||
template <typename T, precision P> \
|
||||
GLM_FUNC_QUALIFIER tvec4<T, P> func \
|
||||
( \
|
||||
tvec4<T, P> const & x, \
|
||||
tvec4<T, P> const & y \
|
||||
) \
|
||||
{ \
|
||||
return tvec4<T, P>( \
|
||||
func(x.x, y.x), \
|
||||
func(x.y, y.y), \
|
||||
func(x.z, y.z), \
|
||||
func(x.w, y.w)); \
|
||||
}
|
||||
|
||||
#define VECTORIZE_VEC_VEC(func) \
|
||||
VECTORIZE1_VEC_VEC(func) \
|
||||
VECTORIZE2_VEC_VEC(func) \
|
||||
VECTORIZE3_VEC_VEC(func) \
|
||||
VECTORIZE4_VEC_VEC(func)
|
||||
|
||||
namespace glm{
|
||||
namespace detail
|
||||
{
|
||||
|
|
|
@ -60,8 +60,8 @@ namespace glm
|
|||
/// @see gtc_random
|
||||
template <typename genTYpe>
|
||||
GLM_FUNC_DECL genTYpe linearRand(
|
||||
genTYpe const & Min,
|
||||
genTYpe const & Max);
|
||||
genTYpe Min,
|
||||
genTYpe Max);
|
||||
|
||||
template <typename T, precision P, template <typename, precision> class vecType>
|
||||
GLM_FUNC_DECL vecType<T, P> linearRand(
|
||||
|
@ -75,8 +75,8 @@ namespace glm
|
|||
/// @see gtc_random
|
||||
template <typename genType>
|
||||
GLM_FUNC_DECL genType gaussRand(
|
||||
genType const & Mean,
|
||||
genType const & Deviation);
|
||||
genType Mean,
|
||||
genType Deviation);
|
||||
|
||||
/// Generate a random 2D vector which coordinates are regulary distributed on a circle of a given radius
|
||||
///
|
||||
|
@ -84,7 +84,7 @@ namespace glm
|
|||
/// @see gtc_random
|
||||
template <typename T>
|
||||
GLM_FUNC_DECL tvec2<T, defaultp> circularRand(
|
||||
T const & Radius);
|
||||
T Radius);
|
||||
|
||||
/// Generate a random 3D vector which coordinates are regulary distributed on a sphere of a given radius
|
||||
///
|
||||
|
@ -92,7 +92,7 @@ namespace glm
|
|||
/// @see gtc_random
|
||||
template <typename T>
|
||||
GLM_FUNC_DECL tvec3<T, defaultp> sphericalRand(
|
||||
T const & Radius);
|
||||
T Radius);
|
||||
|
||||
/// Generate a random 2D vector which coordinates are regulary distributed within the area of a disk of a given radius
|
||||
///
|
||||
|
@ -100,7 +100,7 @@ namespace glm
|
|||
/// @see gtc_random
|
||||
template <typename T>
|
||||
GLM_FUNC_DECL tvec2<T, defaultp> diskRand(
|
||||
T const & Radius);
|
||||
T Radius);
|
||||
|
||||
/// Generate a random 3D vector which coordinates are regulary distributed within the volume of a ball of a given radius
|
||||
///
|
||||
|
@ -108,7 +108,7 @@ namespace glm
|
|||
/// @see gtc_random
|
||||
template <typename T>
|
||||
GLM_FUNC_DECL tvec3<T, defaultp> ballRand(
|
||||
T const & Radius);
|
||||
T Radius);
|
||||
|
||||
/// @}
|
||||
}//namespace glm
|
||||
|
|
|
@ -280,46 +280,22 @@ namespace detail
|
|||
};
|
||||
}//namespace detail
|
||||
|
||||
template <typename genType>
|
||||
GLM_FUNC_QUALIFIER genType linearRand(genType Min, genType Max)
|
||||
{
|
||||
return detail::compute_linearRand<genType, highp, tvec1>::call(
|
||||
tvec1<genType, highp>(Min),
|
||||
tvec1<genType, highp>(Max)).x;
|
||||
}
|
||||
|
||||
template <typename T, precision P, template <typename, precision> class vecType>
|
||||
GLM_FUNC_QUALIFIER vecType<T, P> linearRand
|
||||
(
|
||||
vecType<T, P> const & Min,
|
||||
vecType<T, P> const & Max
|
||||
)
|
||||
GLM_FUNC_QUALIFIER vecType<T, P> linearRand(vecType<T, P> const & Min, vecType<T, P> const & Max)
|
||||
{
|
||||
return detail::compute_linearRand<T, P, vecType>::call(Min, Max);
|
||||
}
|
||||
|
||||
template <>
|
||||
GLM_FUNC_QUALIFIER float linearRand<float>
|
||||
(
|
||||
float const & Min,
|
||||
float const & Max
|
||||
)
|
||||
{
|
||||
return detail::compute_linearRand<float, highp, tvec1>::call(
|
||||
tvec1<float, highp>(Min),
|
||||
tvec1<float, highp>(Max)).x;
|
||||
}
|
||||
|
||||
template <>
|
||||
GLM_FUNC_QUALIFIER double linearRand<double>
|
||||
(
|
||||
double const & Min,
|
||||
double const & Max
|
||||
)
|
||||
{
|
||||
return detail::compute_linearRand<double, highp, tvec1>::call(
|
||||
tvec1<double, highp>(Min),
|
||||
tvec1<double, highp>(Max)).x;
|
||||
}
|
||||
|
||||
template <typename genType>
|
||||
GLM_FUNC_QUALIFIER genType gaussRand
|
||||
(
|
||||
genType const & Mean,
|
||||
genType const & Deviation
|
||||
)
|
||||
GLM_FUNC_QUALIFIER genType gaussRand(genType Mean, genType Deviation)
|
||||
{
|
||||
genType w, x1, x2;
|
||||
|
||||
|
@ -334,13 +310,14 @@ namespace detail
|
|||
return x2 * Deviation * Deviation * sqrt((genType(-2) * log(w)) / w) + Mean;
|
||||
}
|
||||
|
||||
VECTORIZE_VEC_VEC(gaussRand)
|
||||
template <typename T, precision P, template <typename, precision> class vecType>
|
||||
GLM_FUNC_QUALIFIER vecType<T, P> gaussRand(vecType<T, P> const & Mean, vecType<T, P> const & Deviation)
|
||||
{
|
||||
return detail::functor2<T, T, P, vecType>::call(gaussRand, Mean, Deviation);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
GLM_FUNC_QUALIFIER tvec2<T, defaultp> diskRand
|
||||
(
|
||||
T const & Radius
|
||||
)
|
||||
GLM_FUNC_QUALIFIER tvec2<T, defaultp> diskRand(T Radius)
|
||||
{
|
||||
tvec2<T, defaultp> Result(T(0));
|
||||
T LenRadius(T(0));
|
||||
|
@ -358,10 +335,7 @@ namespace detail
|
|||
}
|
||||
|
||||
template <typename T>
|
||||
GLM_FUNC_QUALIFIER tvec3<T, defaultp> ballRand
|
||||
(
|
||||
T const & Radius
|
||||
)
|
||||
GLM_FUNC_QUALIFIER tvec3<T, defaultp> ballRand(T Radius)
|
||||
{
|
||||
tvec3<T, defaultp> Result(T(0));
|
||||
T LenRadius(T(0));
|
||||
|
@ -379,20 +353,14 @@ namespace detail
|
|||
}
|
||||
|
||||
template <typename T>
|
||||
GLM_FUNC_QUALIFIER tvec2<T, defaultp> circularRand
|
||||
(
|
||||
T const & Radius
|
||||
)
|
||||
GLM_FUNC_QUALIFIER tvec2<T, defaultp> circularRand(T Radius)
|
||||
{
|
||||
T a = linearRand(T(0), T(6.283185307179586476925286766559f));
|
||||
return tvec2<T, defaultp>(cos(a), sin(a)) * Radius;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
GLM_FUNC_QUALIFIER tvec3<T, defaultp> sphericalRand
|
||||
(
|
||||
T const & Radius
|
||||
)
|
||||
GLM_FUNC_QUALIFIER tvec3<T, defaultp> sphericalRand(T Radius)
|
||||
{
|
||||
T z = linearRand(T(-1), T(1));
|
||||
T a = linearRand(T(0), T(6.283185307179586476925286766559f));
|
||||
|
|
|
@ -52,42 +52,63 @@ namespace glm
|
|||
|
||||
/// Faster than the common pow function but less accurate.
|
||||
/// @see gtx_fast_exponential
|
||||
template <typename genType>
|
||||
GLM_FUNC_DECL genType fastPow(
|
||||
genType const & x,
|
||||
genType const & y);
|
||||
template <typename genType>
|
||||
GLM_FUNC_DECL genType fastPow(genType x, genType y);
|
||||
|
||||
/// Faster than the common pow function but less accurate.
|
||||
/// @see gtx_fast_exponential
|
||||
template <typename genTypeT, typename genTypeU>
|
||||
GLM_FUNC_DECL genTypeT fastPow(
|
||||
genTypeT const & x,
|
||||
genTypeU const & y);
|
||||
|
||||
template <typename T, precision P, template <typename, precision> class vecType>
|
||||
GLM_FUNC_DECL vecType<T, P> fastPow(vecType<T, P> const & x, vecType<T, P> const & y);
|
||||
|
||||
/// Faster than the common pow function but less accurate.
|
||||
/// @see gtx_fast_exponential
|
||||
template <typename genTypeT, typename genTypeU>
|
||||
GLM_FUNC_DECL genTypeT fastPow(genTypeT x, genTypeU y);
|
||||
|
||||
/// Faster than the common pow function but less accurate.
|
||||
/// @see gtx_fast_exponential
|
||||
template <typename T, precision P, template <typename, precision> class vecType>
|
||||
GLM_FUNC_DECL vecType<T, P> fastPow(vecType<T, P> const & x);
|
||||
|
||||
/// Faster than the common exp function but less accurate.
|
||||
/// @see gtx_fast_exponential
|
||||
template <typename T>
|
||||
GLM_FUNC_DECL T fastExp(const T& x);
|
||||
|
||||
template <typename T>
|
||||
GLM_FUNC_DECL T fastExp(T x);
|
||||
|
||||
/// Faster than the common exp function but less accurate.
|
||||
/// @see gtx_fast_exponential
|
||||
template <typename T, precision P, template <typename, precision> class vecType>
|
||||
GLM_FUNC_DECL vecType<T, P> fastExp(vecType<T, P> const & x);
|
||||
|
||||
/// Faster than the common log function but less accurate.
|
||||
/// @see gtx_fast_exponential
|
||||
template <typename T>
|
||||
GLM_FUNC_DECL T fastLog(const T& x);
|
||||
template <typename T>
|
||||
GLM_FUNC_DECL T fastLog(T x);
|
||||
|
||||
/// Faster than the common exp2 function but less accurate.
|
||||
/// @see gtx_fast_exponential
|
||||
template <typename T>
|
||||
GLM_FUNC_DECL T fastExp2(const T& x);
|
||||
|
||||
template <typename T, precision P, template <typename, precision> class vecType>
|
||||
GLM_FUNC_DECL vecType<T, P> fastLog(vecType<T, P> const & x);
|
||||
|
||||
/// Faster than the common exp2 function but less accurate.
|
||||
/// @see gtx_fast_exponential
|
||||
template <typename T>
|
||||
GLM_FUNC_DECL T fastExp2(T x);
|
||||
|
||||
/// Faster than the common exp2 function but less accurate.
|
||||
/// @see gtx_fast_exponential
|
||||
template <typename T, precision P, template <typename, precision> class vecType>
|
||||
GLM_FUNC_DECL vecType<T, P> fastExp2(vecType<T, P> const & x);
|
||||
|
||||
/// Faster than the common log2 function but less accurate.
|
||||
/// @see gtx_fast_exponential
|
||||
template <typename T>
|
||||
GLM_FUNC_DECL T fastLog2(const T& x);
|
||||
template <typename T>
|
||||
GLM_FUNC_DECL T fastLog2(T x);
|
||||
|
||||
/// Faster than the common ln function but less accurate.
|
||||
/// Faster than the common log2 function but less accurate.
|
||||
/// @see gtx_fast_exponential
|
||||
template <typename T>
|
||||
GLM_FUNC_DECL T fastLn(const T& x);
|
||||
template <typename T, precision P, template <typename, precision> class vecType>
|
||||
GLM_FUNC_DECL vecType<T, P> fastLog2(vecType<T, P> const & x);
|
||||
|
||||
/// @}
|
||||
}//namespace glm
|
||||
|
|
|
@ -11,15 +11,19 @@ namespace glm
|
|||
{
|
||||
// fastPow:
|
||||
template <typename genType>
|
||||
GLM_FUNC_QUALIFIER genType fastPow(genType const & x, genType const & y)
|
||||
GLM_FUNC_QUALIFIER genType fastPow(genType x, genType y)
|
||||
{
|
||||
return exp(y * log(x));
|
||||
}
|
||||
|
||||
VECTORIZE_VEC_VEC(fastPow)
|
||||
template <typename T, precision P, template <typename, precision> class vecType>
|
||||
GLM_FUNC_QUALIFIER vecType<T, P> fastPow(vecType<T, P> const & x, vecType<T, P> const & y)
|
||||
{
|
||||
return exp(y * log(x));
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
GLM_FUNC_QUALIFIER T fastPow(const T x, int y)
|
||||
GLM_FUNC_QUALIFIER T fastPow(T x, int y)
|
||||
{
|
||||
T f = static_cast<T>(1);
|
||||
for(int i = 0; i < y; ++i)
|
||||
|
@ -27,43 +31,19 @@ namespace glm
|
|||
return f;
|
||||
}
|
||||
|
||||
template <typename T, precision P>
|
||||
GLM_FUNC_QUALIFIER tvec2<T, P> fastPow(
|
||||
const tvec2<T, P>& x,
|
||||
const tvec2<int, P>& y)
|
||||
template <typename T, precision P, template <typename, precision> class vecType>
|
||||
GLM_FUNC_QUALIFIER vecType<T, P> fastPow(vecType<T, P> const & x, vecType<int, P> const & y)
|
||||
{
|
||||
return tvec2<T, P>(
|
||||
fastPow(x.x, y.x),
|
||||
fastPow(x.y, y.y));
|
||||
}
|
||||
|
||||
template <typename T, precision P>
|
||||
GLM_FUNC_QUALIFIER tvec3<T, P> fastPow(
|
||||
const tvec3<T, P>& x,
|
||||
const tvec3<int, P>& y)
|
||||
{
|
||||
return tvec3<T, P>(
|
||||
fastPow(x.x, y.x),
|
||||
fastPow(x.y, y.y),
|
||||
fastPow(x.z, y.z));
|
||||
}
|
||||
|
||||
template <typename T, precision P>
|
||||
GLM_FUNC_QUALIFIER tvec4<T, P> fastPow(
|
||||
const tvec4<T, P>& x,
|
||||
const tvec4<int, P>& y)
|
||||
{
|
||||
return tvec4<T, P>(
|
||||
fastPow(x.x, y.x),
|
||||
fastPow(x.y, y.y),
|
||||
fastPow(x.z, y.z),
|
||||
fastPow(x.w, y.w));
|
||||
vecType<T, P> Result(uninitialize);
|
||||
for(detail::component_count_t i = 0; i < detail::component_count(x); ++i)
|
||||
Result[i] = fastPow(x[i], y[i]);
|
||||
return Result;
|
||||
}
|
||||
|
||||
// fastExp
|
||||
// Note: This function provides accurate results only for value between -1 and 1, else avoid it.
|
||||
template <typename T>
|
||||
GLM_FUNC_QUALIFIER T fastExp(const T x)
|
||||
GLM_FUNC_QUALIFIER T fastExp(T x)
|
||||
{
|
||||
// This has a better looking and same performance in release mode than the following code. However, in debug mode it's slower.
|
||||
// return 1.0f + x * (1.0f + x * 0.5f * (1.0f + x * 0.3333333333f * (1.0f + x * 0.25 * (1.0f + x * 0.2f))));
|
||||
|
@ -107,11 +87,15 @@ namespace glm
|
|||
}
|
||||
*/
|
||||
|
||||
VECTORIZE_VEC(fastExp)
|
||||
template <typename T, precision P, template <typename, precision> class vecType>
|
||||
GLM_FUNC_QUALIFIER vecType<T, P> fastExp(vecType<T, P> const & x)
|
||||
{
|
||||
return detail::functor1<T, T, P, vecType>::call(fastExp, x);
|
||||
}
|
||||
|
||||
// fastLog
|
||||
template <typename genType>
|
||||
GLM_FUNC_QUALIFIER genType fastLog(genType const & x)
|
||||
GLM_FUNC_QUALIFIER genType fastLog(genType x)
|
||||
{
|
||||
return std::log(x);
|
||||
}
|
||||
|
@ -125,24 +109,35 @@ namespace glm
|
|||
}
|
||||
*/
|
||||
|
||||
VECTORIZE_VEC(fastLog)
|
||||
template <typename T, precision P, template <typename, precision> class vecType>
|
||||
GLM_FUNC_QUALIFIER vecType<T, P> fastLog(vecType<T, P> const & x)
|
||||
{
|
||||
return detail::functor1<T, T, P, vecType>::call(fastLog, x);
|
||||
}
|
||||
|
||||
//fastExp2, ln2 = 0.69314718055994530941723212145818f
|
||||
template <typename genType>
|
||||
GLM_FUNC_QUALIFIER genType fastExp2(genType const & x)
|
||||
GLM_FUNC_QUALIFIER genType fastExp2(genType x)
|
||||
{
|
||||
return fastExp(0.69314718055994530941723212145818f * x);
|
||||
}
|
||||
|
||||
VECTORIZE_VEC(fastExp2)
|
||||
template <typename T, precision P, template <typename, precision> class vecType>
|
||||
GLM_FUNC_QUALIFIER vecType<T, P> fastExp2(vecType<T, P> const & x)
|
||||
{
|
||||
return detail::functor1<T, T, P, vecType>::call(fastExp2, x);
|
||||
}
|
||||
|
||||
// fastLog2, ln2 = 0.69314718055994530941723212145818f
|
||||
template <typename genType>
|
||||
GLM_FUNC_QUALIFIER genType fastLog2(genType const & x)
|
||||
GLM_FUNC_QUALIFIER genType fastLog2(genType x)
|
||||
{
|
||||
return fastLog(x) / 0.69314718055994530941723212145818f;
|
||||
}
|
||||
|
||||
VECTORIZE_VEC(fastLog2)
|
||||
|
||||
template <typename T, precision P, template <typename, precision> class vecType>
|
||||
GLM_FUNC_QUALIFIER vecType<T, P> fastLog2(vecType<T, P> const & x)
|
||||
{
|
||||
return detail::functor1<T, T, P, vecType>::call(fastLog2, x);
|
||||
}
|
||||
}//namespace glm
|
||||
|
|
|
@ -54,12 +54,12 @@ namespace glm
|
|||
//! Faster than the common sqrt function but less accurate.
|
||||
//! From GLM_GTX_fast_square_root extension.
|
||||
template <typename genType>
|
||||
GLM_FUNC_DECL genType fastSqrt(genType const & x);
|
||||
GLM_FUNC_DECL genType fastSqrt(genType x);
|
||||
|
||||
//! Faster than the common inversesqrt function but less accurate.
|
||||
//! From GLM_GTX_fast_square_root extension.
|
||||
template <typename genType>
|
||||
GLM_FUNC_DECL genType fastInverseSqrt(genType const & x);
|
||||
GLM_FUNC_DECL genType fastInverseSqrt(genType x);
|
||||
|
||||
//! Faster than the common inversesqrt function but less accurate.
|
||||
//! From GLM_GTX_fast_square_root extension.
|
||||
|
@ -73,8 +73,13 @@ namespace glm
|
|||
|
||||
//! Faster than the common distance function but less accurate.
|
||||
//! From GLM_GTX_fast_square_root extension.
|
||||
template <typename genType>
|
||||
GLM_FUNC_DECL typename genType::value_type fastDistance(genType const & x, genType const & y);
|
||||
template <typename genType>
|
||||
GLM_FUNC_DECL genType fastDistance(genType x, genType y);
|
||||
|
||||
//! Faster than the common distance function but less accurate.
|
||||
//! From GLM_GTX_fast_square_root extension.
|
||||
template <typename T, precision P, template <typename, precision> class vecType>
|
||||
GLM_FUNC_DECL T fastDistance(vecType<T, P> const & x, vecType<T, P> const & y);
|
||||
|
||||
//! Faster than the common normalize function but less accurate.
|
||||
//! From GLM_GTX_fast_square_root extension.
|
||||
|
|
|
@ -11,170 +11,77 @@ namespace glm
|
|||
{
|
||||
// fastSqrt
|
||||
template <typename genType>
|
||||
GLM_FUNC_QUALIFIER genType fastSqrt
|
||||
(
|
||||
genType const & x
|
||||
)
|
||||
GLM_FUNC_QUALIFIER genType fastSqrt(genType x)
|
||||
{
|
||||
GLM_STATIC_ASSERT(std::numeric_limits<genType>::is_iec559, "'fastSqrt' only accept floating-point input");
|
||||
|
||||
return genType(1) / fastInverseSqrt(x);
|
||||
}
|
||||
|
||||
VECTORIZE_VEC(fastSqrt)
|
||||
template <typename T, precision P, template <typename, precision> class vecType>
|
||||
GLM_FUNC_QUALIFIER vecType<T, P> fastSqrt(vecType<T, P> const & x)
|
||||
{
|
||||
return detail::functor1<T, T, P, vecType>::call(fastSqrt, x);
|
||||
}
|
||||
|
||||
// fastInversesqrt
|
||||
template <>
|
||||
GLM_FUNC_QUALIFIER float fastInverseSqrt<float>(float const & x)
|
||||
template <typename genType>
|
||||
GLM_FUNC_QUALIFIER genType fastInverseSqrt(genType x)
|
||||
{
|
||||
# ifdef __CUDACC__ // Wordaround for a CUDA compiler bug up to CUDA6
|
||||
tvec1<T, P> tmp(detail::compute_inversesqrt<tvec1, float, lowp>::call(tvec1<float, lowp>(x)));
|
||||
tvec1<T, P> tmp(detail::compute_inversesqrt<tvec1, genType, lowp>::call(tvec1<genType, lowp>(x)));
|
||||
return tmp.x;
|
||||
# else
|
||||
return detail::compute_inversesqrt<tvec1, float, lowp>::call(tvec1<float, lowp>(x)).x;
|
||||
return detail::compute_inversesqrt<tvec1, genType, lowp>::call(tvec1<genType, lowp>(x)).x;
|
||||
# endif
|
||||
}
|
||||
|
||||
template <>
|
||||
GLM_FUNC_QUALIFIER double fastInverseSqrt<double>(double const & x)
|
||||
{
|
||||
# ifdef __CUDACC__ // Wordaround for a CUDA compiler bug up to CUDA6
|
||||
tvec1<T, P> tmp(detail::compute_inversesqrt<tvec1, double, lowp>::call(tvec1<double, lowp>(x)));
|
||||
return tmp.x;
|
||||
# else
|
||||
return detail::compute_inversesqrt<tvec1, double, lowp>::call(tvec1<double, lowp>(x)).x;
|
||||
# endif
|
||||
}
|
||||
|
||||
template <template <class, precision> class vecType, typename T, precision P>
|
||||
GLM_FUNC_QUALIFIER vecType<T, P> fastInverseSqrt
|
||||
(
|
||||
vecType<T, P> const & x
|
||||
)
|
||||
template <typename T, precision P, template <typename, precision> class vecType>
|
||||
GLM_FUNC_QUALIFIER vecType<T, P> fastInverseSqrt(vecType<T, P> const & x)
|
||||
{
|
||||
return detail::compute_inversesqrt<vecType, T, P>::call(x);
|
||||
}
|
||||
|
||||
VECTORIZE_VEC(fastInverseSqrt)
|
||||
|
||||
// fastLength
|
||||
template <typename genType>
|
||||
GLM_FUNC_QUALIFIER genType fastLength
|
||||
(
|
||||
genType const & x
|
||||
)
|
||||
GLM_FUNC_QUALIFIER genType fastLength(genType x)
|
||||
{
|
||||
GLM_STATIC_ASSERT(std::numeric_limits<genType>::is_iec559, "'fastLength' only accept floating-point inputs");
|
||||
|
||||
return abs(x);
|
||||
}
|
||||
|
||||
template <typename valType, precision P>
|
||||
GLM_FUNC_QUALIFIER valType fastLength
|
||||
(
|
||||
tvec2<valType, P> const & x
|
||||
)
|
||||
template <typename T, precision P, template <typename, precision> class vecType>
|
||||
GLM_FUNC_QUALIFIER T fastLength(vecType<T, P> const & x)
|
||||
{
|
||||
valType sqr = x.x * x.x + x.y * x.y;
|
||||
return fastSqrt(sqr);
|
||||
}
|
||||
GLM_STATIC_ASSERT(std::numeric_limits<T>::is_iec559, "'fastLength' only accept floating-point inputs");
|
||||
|
||||
template <typename valType, precision P>
|
||||
GLM_FUNC_QUALIFIER valType fastLength
|
||||
(
|
||||
tvec3<valType, P> const & x
|
||||
)
|
||||
{
|
||||
valType sqr = x.x * x.x + x.y * x.y + x.z * x.z;
|
||||
return fastSqrt(sqr);
|
||||
}
|
||||
|
||||
template <typename valType, precision P>
|
||||
GLM_FUNC_QUALIFIER valType fastLength
|
||||
(
|
||||
tvec4<valType, P> const & x
|
||||
)
|
||||
{
|
||||
valType sqr = x.x * x.x + x.y * x.y + x.z * x.z + x.w * x.w;
|
||||
return fastSqrt(sqr);
|
||||
return fastSqrt(dot(x, x));
|
||||
}
|
||||
|
||||
// fastDistance
|
||||
template <typename genType>
|
||||
GLM_FUNC_QUALIFIER genType fastDistance
|
||||
(
|
||||
genType const & x,
|
||||
genType const & y
|
||||
)
|
||||
GLM_FUNC_QUALIFIER genType fastDistance(genType x, genType y)
|
||||
{
|
||||
return fastLength(y - x);
|
||||
}
|
||||
|
||||
template <typename valType, precision P>
|
||||
GLM_FUNC_QUALIFIER valType fastDistance
|
||||
(
|
||||
tvec2<valType, P> const & x,
|
||||
tvec2<valType, P> const & y
|
||||
)
|
||||
{
|
||||
return fastLength(y - x);
|
||||
}
|
||||
|
||||
template <typename valType, precision P>
|
||||
GLM_FUNC_QUALIFIER valType fastDistance
|
||||
(
|
||||
tvec3<valType, P> const & x,
|
||||
tvec3<valType, P> const & y
|
||||
)
|
||||
{
|
||||
return fastLength(y - x);
|
||||
}
|
||||
|
||||
template <typename valType, precision P>
|
||||
GLM_FUNC_QUALIFIER valType fastDistance
|
||||
(
|
||||
tvec4<valType, P> const & x,
|
||||
tvec4<valType, P> const & y
|
||||
)
|
||||
template <typename T, precision P, template <typename, precision> class vecType>
|
||||
GLM_FUNC_QUALIFIER T fastDistance(vecType<T, P> const & x, vecType<T, P> const & y)
|
||||
{
|
||||
return fastLength(y - x);
|
||||
}
|
||||
|
||||
// fastNormalize
|
||||
template <typename genType>
|
||||
GLM_FUNC_QUALIFIER genType fastNormalize
|
||||
(
|
||||
genType const & x
|
||||
)
|
||||
GLM_FUNC_QUALIFIER genType fastNormalize(genType x)
|
||||
{
|
||||
return x > genType(0) ? genType(1) : -genType(1);
|
||||
}
|
||||
|
||||
template <typename valType, precision P>
|
||||
GLM_FUNC_QUALIFIER tvec2<valType, P> fastNormalize
|
||||
(
|
||||
tvec2<valType, P> const & x
|
||||
)
|
||||
template <typename T, precision P, template <typename, precision> class vecType>
|
||||
GLM_FUNC_QUALIFIER vecType<T, P> fastNormalize(vecType<T, P> const & x)
|
||||
{
|
||||
valType sqr = x.x * x.x + x.y * x.y;
|
||||
return x * fastInverseSqrt(sqr);
|
||||
}
|
||||
|
||||
template <typename valType, precision P>
|
||||
GLM_FUNC_QUALIFIER tvec3<valType, P> fastNormalize
|
||||
(
|
||||
tvec3<valType, P> const & x
|
||||
)
|
||||
{
|
||||
valType sqr = x.x * x.x + x.y * x.y + x.z * x.z;
|
||||
return x * fastInverseSqrt(sqr);
|
||||
}
|
||||
|
||||
template <typename valType, precision P>
|
||||
GLM_FUNC_QUALIFIER tvec4<valType, P> fastNormalize
|
||||
(
|
||||
tvec4<valType, P> const & x
|
||||
)
|
||||
{
|
||||
valType sqr = x.x * x.x + x.y * x.y + x.z * x.z + x.w * x.w;
|
||||
return x * fastInverseSqrt(sqr);
|
||||
return x * fastInverseSqrt(dot(x, x));
|
||||
}
|
||||
}//namespace glm
|
||||
|
|
|
@ -53,43 +53,43 @@ namespace glm
|
|||
//! Defined between -2pi and 2pi.
|
||||
//! From GLM_GTX_fast_trigonometry extension.
|
||||
template <typename T>
|
||||
GLM_FUNC_DECL T fastSin(const T& angle);
|
||||
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.
|
||||
template <typename T>
|
||||
GLM_FUNC_DECL T fastCos(const T& angle);
|
||||
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.
|
||||
template <typename T>
|
||||
GLM_FUNC_DECL T fastTan(const T& angle);
|
||||
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.
|
||||
template <typename T>
|
||||
GLM_FUNC_DECL T fastAsin(const T& angle);
|
||||
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.
|
||||
template <typename T>
|
||||
GLM_FUNC_DECL T fastAcos(const T& angle);
|
||||
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.
|
||||
template <typename T>
|
||||
GLM_FUNC_DECL T fastAtan(const T& y, const T& x);
|
||||
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.
|
||||
template <typename T>
|
||||
GLM_FUNC_DECL T fastAtan(const T& angle);
|
||||
GLM_FUNC_DECL T fastAtan(T angle);
|
||||
|
||||
/// @}
|
||||
}//namespace glm
|
||||
|
|
|
@ -11,65 +11,92 @@ namespace glm
|
|||
{
|
||||
// sin
|
||||
template <typename T>
|
||||
GLM_FUNC_QUALIFIER T fastSin(T const & x)
|
||||
GLM_FUNC_QUALIFIER T fastSin(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));
|
||||
}
|
||||
|
||||
VECTORIZE_VEC(fastSin)
|
||||
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);
|
||||
}
|
||||
|
||||
// cos
|
||||
template <typename T>
|
||||
GLM_FUNC_QUALIFIER T fastCos(T const & x)
|
||||
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));
|
||||
}
|
||||
|
||||
VECTORIZE_VEC(fastCos)
|
||||
template <typename T, precision P, template <typename, precision> class vecType>
|
||||
GLM_FUNC_QUALIFIER vecType<T, P> fastCos(vecType<T, P> const & x)
|
||||
{
|
||||
return detail::functor1<T, T, P, vecType>::call(fastCos, x);
|
||||
}
|
||||
|
||||
// tan
|
||||
template <typename T>
|
||||
GLM_FUNC_QUALIFIER T fastTan(T const & x)
|
||||
GLM_FUNC_QUALIFIER T fastTan(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));
|
||||
}
|
||||
|
||||
VECTORIZE_VEC(fastTan)
|
||||
template <typename T, precision P, template <typename, precision> class vecType>
|
||||
GLM_FUNC_QUALIFIER vecType<T, P> fastTan(vecType<T, P> const & x)
|
||||
{
|
||||
return detail::functor1<T, T, P, vecType>::call(fastTan, x);
|
||||
}
|
||||
|
||||
// asin
|
||||
template <typename T>
|
||||
GLM_FUNC_QUALIFIER T fastAsin(T const & x)
|
||||
GLM_FUNC_QUALIFIER T fastAsin(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));
|
||||
}
|
||||
|
||||
VECTORIZE_VEC(fastAsin)
|
||||
template <typename T, precision P, template <typename, precision> class vecType>
|
||||
GLM_FUNC_QUALIFIER vecType<T, P> fastAsin(vecType<T, P> const & x)
|
||||
{
|
||||
return detail::functor1<T, T, P, vecType>::call(fastAsin, x);
|
||||
}
|
||||
|
||||
// acos
|
||||
template <typename T>
|
||||
GLM_FUNC_QUALIFIER T fastAcos(T const & x)
|
||||
GLM_FUNC_QUALIFIER T fastAcos(T x)
|
||||
{
|
||||
return T(1.5707963267948966192313216916398) - fastAsin(x); //(PI / 2)
|
||||
}
|
||||
|
||||
VECTORIZE_VEC(fastAcos)
|
||||
template <typename T, precision P, template <typename, precision> class vecType>
|
||||
GLM_FUNC_QUALIFIER vecType<T, P> fastAcos(vecType<T, P> const & x)
|
||||
{
|
||||
return detail::functor1<T, T, P, vecType>::call(fastAcos, x);
|
||||
}
|
||||
|
||||
// atan
|
||||
template <typename T>
|
||||
GLM_FUNC_QUALIFIER T fastAtan(T const & y, T const & x)
|
||||
GLM_FUNC_QUALIFIER T fastAtan(T y, T x)
|
||||
{
|
||||
T sgn = sign(y) * sign(x);
|
||||
return abs(fastAtan(y / x)) * sgn;
|
||||
}
|
||||
|
||||
VECTORIZE_VEC_VEC(fastAtan)
|
||||
template <typename T, precision P, template <typename, precision> class vecType>
|
||||
GLM_FUNC_QUALIFIER vecType<T, P> fastAtan(vecType<T, P> const & y, vecType<T, P> const & x)
|
||||
{
|
||||
return detail::functor2<T, T, P, vecType>::call(fastAtan, y, x);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
GLM_FUNC_QUALIFIER T fastAtan(T const & x)
|
||||
GLM_FUNC_QUALIFIER T fastAtan(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));
|
||||
}
|
||||
|
||||
VECTORIZE_VEC(fastAtan)
|
||||
|
||||
template <typename T, precision P, template <typename, precision> class vecType>
|
||||
GLM_FUNC_QUALIFIER vecType<T, P> fastAtan(vecType<T, P> const & x)
|
||||
{
|
||||
return detail::functor1<T, T, P, vecType>::call(fastAtan, x);
|
||||
}
|
||||
}//namespace glm
|
||||
|
|
|
@ -59,8 +59,8 @@ namespace glm
|
|||
/// @see gtx_multiple
|
||||
template <typename genType>
|
||||
GLM_FUNC_DECL genType higherMultiple(
|
||||
genType const & Source,
|
||||
genType const & Multiple);
|
||||
genType Source,
|
||||
genType Multiple);
|
||||
|
||||
/// Lower multiple number of Source.
|
||||
///
|
||||
|
@ -71,8 +71,8 @@ namespace glm
|
|||
/// @see gtx_multiple
|
||||
template <typename genType>
|
||||
GLM_FUNC_DECL genType lowerMultiple(
|
||||
genType const & Source,
|
||||
genType const & Multiple);
|
||||
genType Source,
|
||||
genType Multiple);
|
||||
|
||||
/// @}
|
||||
}//namespace glm
|
||||
|
|
|
@ -17,13 +17,9 @@ namespace detail
|
|||
struct higherMultiple
|
||||
{
|
||||
template <typename genType>
|
||||
GLM_FUNC_QUALIFIER genType operator()
|
||||
(
|
||||
genType const & Source,
|
||||
genType const & Multiple
|
||||
)
|
||||
GLM_FUNC_QUALIFIER genType operator()(genType Source, genType Multiple)
|
||||
{
|
||||
if (Source > genType(0))
|
||||
if(Source > genType(0))
|
||||
{
|
||||
genType Tmp = Source - genType(1);
|
||||
return Tmp + (Multiple - (Tmp % Multiple));
|
||||
|
@ -37,11 +33,7 @@ namespace detail
|
|||
struct higherMultiple<false>
|
||||
{
|
||||
template <typename genType>
|
||||
GLM_FUNC_QUALIFIER genType operator()
|
||||
(
|
||||
genType const & Source,
|
||||
genType const & Multiple
|
||||
)
|
||||
GLM_FUNC_QUALIFIER genType operator()(genType Source, genType Multiple)
|
||||
{
|
||||
genType Tmp = Source - genType(1);
|
||||
return Tmp + (Multiple - (Tmp % Multiple));
|
||||
|
@ -53,24 +45,16 @@ namespace detail
|
|||
// higherMultiple
|
||||
|
||||
template <typename genType>
|
||||
GLM_FUNC_QUALIFIER genType higherMultiple
|
||||
(
|
||||
genType const & Source,
|
||||
genType const & Multiple
|
||||
)
|
||||
GLM_FUNC_QUALIFIER genType higherMultiple(genType Source, genType Multiple)
|
||||
{
|
||||
detail::higherMultiple<std::numeric_limits<genType>::is_signed> Compute;
|
||||
return Compute(Source, Multiple);
|
||||
}
|
||||
|
||||
template <>
|
||||
GLM_FUNC_QUALIFIER float higherMultiple
|
||||
(
|
||||
float const & Source,
|
||||
float const & Multiple
|
||||
)
|
||||
GLM_FUNC_QUALIFIER float higherMultiple(float Source, float Multiple)
|
||||
{
|
||||
if (Source > float(0))
|
||||
if(Source > float(0))
|
||||
{
|
||||
float Tmp = Source - float(1);
|
||||
return Tmp + (Multiple - std::fmod(Tmp, Multiple));
|
||||
|
@ -80,13 +64,9 @@ namespace detail
|
|||
}
|
||||
|
||||
template <>
|
||||
GLM_FUNC_QUALIFIER double higherMultiple
|
||||
(
|
||||
double const & Source,
|
||||
double const & Multiple
|
||||
)
|
||||
GLM_FUNC_QUALIFIER double higherMultiple(double Source, double Multiple)
|
||||
{
|
||||
if (Source > double(0))
|
||||
if(Source > double(0))
|
||||
{
|
||||
double Tmp = Source - double(1);
|
||||
return Tmp + (Multiple - std::fmod(Tmp, Multiple));
|
||||
|
@ -95,19 +75,19 @@ namespace detail
|
|||
return Source + std::fmod(-Source, Multiple);
|
||||
}
|
||||
|
||||
VECTORIZE_VEC_VEC(higherMultiple)
|
||||
template <typename T, precision P, template <typename, precision> class vecType>
|
||||
GLM_FUNC_QUALIFIER vecType<T, P> higherMultiple(vecType<T, P> const & Source, vecType<T, P> const & Multiple)
|
||||
{
|
||||
return detail::functor2<T, T, P, vecType>::call(higherMultiple, Source, Multiple);
|
||||
}
|
||||
|
||||
//////////////////////
|
||||
// lowerMultiple
|
||||
|
||||
template <typename genType>
|
||||
GLM_FUNC_QUALIFIER genType lowerMultiple
|
||||
(
|
||||
genType const & Source,
|
||||
genType const & Multiple
|
||||
)
|
||||
GLM_FUNC_QUALIFIER genType lowerMultiple(genType Source, genType Multiple)
|
||||
{
|
||||
if (Source >= genType(0))
|
||||
if(Source >= genType(0))
|
||||
return Source - Source % Multiple;
|
||||
else
|
||||
{
|
||||
|
@ -117,13 +97,9 @@ namespace detail
|
|||
}
|
||||
|
||||
template <>
|
||||
GLM_FUNC_QUALIFIER float lowerMultiple
|
||||
(
|
||||
float const & Source,
|
||||
float const & Multiple
|
||||
)
|
||||
GLM_FUNC_QUALIFIER float lowerMultiple(float Source, float Multiple)
|
||||
{
|
||||
if (Source >= float(0))
|
||||
if(Source >= float(0))
|
||||
return Source - std::fmod(Source, Multiple);
|
||||
else
|
||||
{
|
||||
|
@ -133,11 +109,7 @@ namespace detail
|
|||
}
|
||||
|
||||
template <>
|
||||
GLM_FUNC_QUALIFIER double lowerMultiple
|
||||
(
|
||||
double const & Source,
|
||||
double const & Multiple
|
||||
)
|
||||
GLM_FUNC_QUALIFIER double lowerMultiple(double Source, double Multiple)
|
||||
{
|
||||
if (Source >= double(0))
|
||||
return Source - std::fmod(Source, Multiple);
|
||||
|
@ -148,5 +120,9 @@ namespace detail
|
|||
}
|
||||
}
|
||||
|
||||
VECTORIZE_VEC_VEC(lowerMultiple)
|
||||
template <typename T, precision P, template <typename, precision> class vecType>
|
||||
GLM_FUNC_QUALIFIER vecType<T, P> lowerMultiple(vecType<T, P> const & Source, vecType<T, P> const & Multiple)
|
||||
{
|
||||
return detail::functor2<T, T, P, vecType>::call(lowerMultiple, Source, Multiple);
|
||||
}
|
||||
}//namespace glm
|
||||
|
|
Loading…
Add table
Reference in a new issue