Updated GLM version w/ now standard radians as angles.

This commit is contained in:
J. de Vries
2016-05-11 20:04:52 +02:00
parent 336df22af5
commit a4c2bb2498
321 changed files with 42426 additions and 35972 deletions

View File

@@ -1,7 +1,7 @@
///////////////////////////////////////////////////////////////////////////////////
/// OpenGL Mathematics (glm.g-truc.net)
///
/// Copyright (c) 2005 - 2013 G-Truc Creation (www.g-truc.net)
/// Copyright (c) 2005 - 2015 G-Truc Creation (www.g-truc.net)
/// Permission is hereby granted, free of charge, to any person obtaining a copy
/// of this software and associated documentation files (the "Software"), to deal
/// in the Software without restriction, including without limitation the rights
@@ -12,6 +12,10 @@
/// The above copyright notice and this permission notice shall be included in
/// all copies or substantial portions of the Software.
///
/// Restrictions:
/// By making use of the Software for military purposes, you choose to make
/// a Bunny unhappy.
///
/// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
/// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
/// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
@@ -33,8 +37,10 @@
/// is preserved.
///////////////////////////////////////////////////////////////////////////////////
#include "../detail/type_int.hpp"
#include <cmath>
#include <cfloat>
#include <limits>
#if(GLM_COMPILER & GLM_COMPILER_VC)
# pragma warning(push)
@@ -58,34 +64,34 @@ typedef union
} parts;
} ieee_double_shape_type;
#define GLM_EXTRACT_WORDS(ix0,ix1,d) \
do { \
ieee_double_shape_type ew_u; \
ew_u.value = (d); \
(ix0) = ew_u.parts.msw; \
(ix1) = ew_u.parts.lsw; \
#define GLM_EXTRACT_WORDS(ix0,ix1,d) \
do { \
ieee_double_shape_type ew_u; \
ew_u.value = (d); \
(ix0) = ew_u.parts.msw; \
(ix1) = ew_u.parts.lsw; \
} while (0)
#define GLM_GET_FLOAT_WORD(i,d) \
do { \
ieee_float_shape_type gf_u; \
gf_u.value = (d); \
(i) = gf_u.word; \
#define GLM_GET_FLOAT_WORD(i,d) \
do { \
ieee_float_shape_type gf_u; \
gf_u.value = (d); \
(i) = gf_u.word; \
} while (0)
#define GLM_SET_FLOAT_WORD(d,i) \
do { \
ieee_float_shape_type sf_u; \
sf_u.word = (i); \
(d) = sf_u.value; \
#define GLM_SET_FLOAT_WORD(d,i) \
do { \
ieee_float_shape_type sf_u; \
sf_u.word = (i); \
(d) = sf_u.value; \
} while (0)
#define GLM_INSERT_WORDS(d,ix0,ix1) \
do { \
ieee_double_shape_type iw_u; \
iw_u.parts.msw = (ix0); \
iw_u.parts.lsw = (ix1); \
(d) = iw_u.value; \
#define GLM_INSERT_WORDS(d,ix0,ix1) \
do { \
ieee_double_shape_type iw_u; \
iw_u.parts.msw = (ix0); \
iw_u.parts.lsw = (ix1); \
(d) = iw_u.value; \
} while (0)
namespace glm{
@@ -98,28 +104,28 @@ namespace detail
GLM_GET_FLOAT_WORD(hx, x);
GLM_GET_FLOAT_WORD(hy, y);
ix = hx&0x7fffffff; // |x|
iy = hy&0x7fffffff; // |y|
ix = hx&0x7fffffff; // |x|
iy = hy&0x7fffffff; // |y|
if((ix>0x7f800000) || // x is nan
(iy>0x7f800000)) // y is nan
if((ix>0x7f800000) || // x is nan
(iy>0x7f800000)) // y is nan
return x+y;
if(x==y) return y; // x=y, return y
if(ix==0) { // x == 0
if(x==y) return y; // x=y, return y
if(ix==0) { // x == 0
GLM_SET_FLOAT_WORD(x,(hy&0x80000000)|1);// return +-minsubnormal
t = x*x;
if(t==x) return t; else return x; // raise underflow flag
if(t==x) return t; else return x; // raise underflow flag
}
if(hx>=0) { // x > 0
if(hx>hy) { // x > y, x -= ulp
if(hx>=0) { // x > 0
if(hx>hy) { // x > y, x -= ulp
hx -= 1;
} else { // x < y, x += ulp
} else { // x < y, x += ulp
hx += 1;
}
} else { // x < 0
if(hy>=0||hx>hy){ // x < y, x -= ulp
} else { // x < 0
if(hy>=0||hx>hy){ // x < y, x -= ulp
hx -= 1;
} else { // x > y, x += ulp
} else { // x > y, x += ulp
hx += 1;
}
}
@@ -192,50 +198,76 @@ namespace detail
# pragma warning(pop)
#endif
#if((GLM_COMPILER & GLM_COMPILER_VC) || ((GLM_COMPILER & GLM_COMPILER_INTEL) && (GLM_PLATFORM & GLM_PLATFORM_WINDOWS)))
# define GLM_NEXT_AFTER_FLT(x, toward) glm::detail::nextafterf((x), (toward))
# define GLM_NEXT_AFTER_DBL(x, toward) _nextafter((x), (toward))
#else
# define GLM_NEXT_AFTER_FLT(x, toward) nextafterf((x), (toward))
# define GLM_NEXT_AFTER_DBL(x, toward) nextafter((x), (toward))
#endif
namespace glm
{
template <>
GLM_FUNC_QUALIFIER float next_float(float const & x)
{
return GLM_NEXT_AFTER_FLT(x, std::numeric_limits<float>::max());
# if GLM_HAS_CXX11_STL
return std::nextafter(x, std::numeric_limits<float>::max());
# elif((GLM_COMPILER & GLM_COMPILER_VC) || ((GLM_COMPILER & GLM_COMPILER_INTEL) && (GLM_PLATFORM & GLM_PLATFORM_WINDOWS)))
return detail::nextafterf(x, FLT_MAX);
# elif(GLM_PLATFORM & GLM_PLATFORM_ANDROID)
return __builtin_nextafterf(x, FLT_MAX);
# else
return nextafterf(x, FLT_MAX);
# endif
}
template <>
GLM_FUNC_QUALIFIER double next_float(double const & x)
{
return GLM_NEXT_AFTER_DBL(x, std::numeric_limits<double>::max());
# if GLM_HAS_CXX11_STL
return std::nextafter(x, std::numeric_limits<double>::max());
# elif((GLM_COMPILER & GLM_COMPILER_VC) || ((GLM_COMPILER & GLM_COMPILER_INTEL) && (GLM_PLATFORM & GLM_PLATFORM_WINDOWS)))
return detail::nextafter(x, std::numeric_limits<double>::max());
# elif(GLM_PLATFORM & GLM_PLATFORM_ANDROID)
return __builtin_nextafter(x, FLT_MAX);
# else
return nextafter(x, DBL_MAX);
# endif
}
template<typename T, template<typename> class vecType>
GLM_FUNC_QUALIFIER vecType<T> next_float(vecType<T> const & x)
template<typename T, precision P, template<typename, precision> class vecType>
GLM_FUNC_QUALIFIER vecType<T, P> next_float(vecType<T, P> const & x)
{
vecType<T> Result;
for(std::size_t i = 0; i < Result.length(); ++i)
vecType<T, P> Result(uninitialize);
for(detail::component_count_t i = 0; i < detail::component_count(Result); ++i)
Result[i] = next_float(x[i]);
return Result;
}
GLM_FUNC_QUALIFIER float prev_float(float const & x)
{
return GLM_NEXT_AFTER_FLT(x, std::numeric_limits<float>::min());
# if GLM_HAS_CXX11_STL
return std::nextafter(x, std::numeric_limits<float>::min());
# elif((GLM_COMPILER & GLM_COMPILER_VC) || ((GLM_COMPILER & GLM_COMPILER_INTEL) && (GLM_PLATFORM & GLM_PLATFORM_WINDOWS)))
return detail::nextafterf(x, FLT_MIN);
# elif(GLM_PLATFORM & GLM_PLATFORM_ANDROID)
return __builtin_nextafterf(x, FLT_MIN);
# else
return nextafterf(x, FLT_MIN);
# endif
}
GLM_FUNC_QUALIFIER double prev_float(double const & x)
{
return GLM_NEXT_AFTER_DBL(x, std::numeric_limits<double>::min());
# if GLM_HAS_CXX11_STL
return std::nextafter(x, std::numeric_limits<double>::min());
# elif((GLM_COMPILER & GLM_COMPILER_VC) || ((GLM_COMPILER & GLM_COMPILER_INTEL) && (GLM_PLATFORM & GLM_PLATFORM_WINDOWS)))
return _nextafter(x, DBL_MIN);
# elif(GLM_PLATFORM & GLM_PLATFORM_ANDROID)
return __builtin_nextafter(x, DBL_MIN);
# else
return nextafter(x, DBL_MIN);
# endif
}
template<typename T, template<typename> class vecType>
GLM_FUNC_QUALIFIER vecType<T> prev_float(vecType<T> const & x)
template<typename T, precision P, template<typename, precision> class vecType>
GLM_FUNC_QUALIFIER vecType<T, P> prev_float(vecType<T, P> const & x)
{
vecType<T> Result;
for(std::size_t i = 0; i < Result.length(); ++i)
vecType<T, P> Result(uninitialize);
for(detail::component_count_t i = 0; i < detail::component_count(Result); ++i)
Result[i] = prev_float(x[i]);
return Result;
}
@@ -244,16 +276,16 @@ namespace glm
GLM_FUNC_QUALIFIER T next_float(T const & x, uint const & ulps)
{
T temp = x;
for(std::size_t i = 0; i < ulps; ++i)
for(uint i = 0; i < ulps; ++i)
temp = next_float(temp);
return temp;
}
template<typename T, template<typename> class vecType>
GLM_FUNC_QUALIFIER vecType<T> next_float(vecType<T> const & x, vecType<uint> const & ulps)
template<typename T, precision P, template<typename, precision> class vecType>
GLM_FUNC_QUALIFIER vecType<T, P> next_float(vecType<T, P> const & x, vecType<uint, P> const & ulps)
{
vecType<T> Result;
for(std::size_t i = 0; i < Result.length(); ++i)
vecType<T, P> Result(uninitialize);
for(detail::component_count_t i = 0; i < detail::component_count(Result); ++i)
Result[i] = next_float(x[i], ulps[i]);
return Result;
}
@@ -262,16 +294,16 @@ namespace glm
GLM_FUNC_QUALIFIER T prev_float(T const & x, uint const & ulps)
{
T temp = x;
for(std::size_t i = 0; i < ulps; ++i)
for(uint i = 0; i < ulps; ++i)
temp = prev_float(temp);
return temp;
}
template<typename T, template<typename> class vecType>
GLM_FUNC_QUALIFIER vecType<T> prev_float(vecType<T> const & x, vecType<uint> const & ulps)
template<typename T, precision P, template<typename, precision> class vecType>
GLM_FUNC_QUALIFIER vecType<T, P> prev_float(vecType<T, P> const & x, vecType<uint, P> const & ulps)
{
vecType<T> Result;
for(std::size_t i = 0; i < Result.length(); ++i)
vecType<T, P> Result(uninitialize);
for(detail::component_count_t i = 0; i < detail::component_count(Result); ++i)
Result[i] = prev_float(x[i], ulps[i]);
return Result;
}
@@ -284,7 +316,7 @@ namespace glm
if(x < y)
{
T temp = x;
while(temp != y && ulp < std::numeric_limits<std::size_t>::max())
while(temp != y)// && ulp < std::numeric_limits<std::size_t>::max())
{
++ulp;
temp = next_float(temp);
@@ -293,7 +325,7 @@ namespace glm
else if(y < x)
{
T temp = y;
while(temp != x && ulp < std::numeric_limits<std::size_t>::max())
while(temp != x)// && ulp < std::numeric_limits<std::size_t>::max())
{
++ulp;
temp = next_float(temp);
@@ -307,11 +339,11 @@ namespace glm
return ulp;
}
template<typename T, template<typename> class vecType>
GLM_FUNC_QUALIFIER vecType<uint> float_distance(vecType<T> const & x, vecType<T> const & y)
template<typename T, precision P, template<typename, precision> class vecType>
GLM_FUNC_QUALIFIER vecType<uint, P> float_distance(vecType<T, P> const & x, vecType<T, P> const & y)
{
vecType<uint> Result;
for(std::size_t i = 0; i < Result.length(); ++i)
vecType<uint, P> Result(uninitialize);
for(detail::component_count_t i = 0; i < detail::component_count(Result); ++i)
Result[i] = float_distance(x[i], y[i]);
return Result;
}