Commit 6e54b394 authored by Nianchen Deng's avatar Nianchen Deng
Browse files

paper committed

parent 90553bac
///////////////////////////////////////////////////////////////////////////////////
/// OpenGL Mathematics (glm.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
/// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
/// copies of the Software, and to permit persons to whom the Software is
/// furnished to do so, subject to the following conditions:
///
/// 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
/// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
/// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
/// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
/// THE SOFTWARE.
///
/// @ref core
/// @file glm/detail/func_common.inl
/// @date 2008-08-03 / 2011-06-15
/// @author Christophe Riccio
///////////////////////////////////////////////////////////////////////////////////
#include "func_vector_relational.hpp"
#include "type_vec2.hpp"
#include "type_vec3.hpp"
#include "type_vec4.hpp"
#include "_vectorize.hpp"
#include <limits>
namespace glm{
namespace detail
{
template <typename genFIType, bool /*signed*/>
struct compute_abs
{};
template <typename genFIType>
struct compute_abs<genFIType, true>
{
GLM_FUNC_QUALIFIER static genFIType call(genFIType x)
{
GLM_STATIC_ASSERT(
std::numeric_limits<genFIType>::is_iec559 || std::numeric_limits<genFIType>::is_signed,
"'abs' only accept floating-point and integer scalar or vector inputs");
return x >= genFIType(0) ? x : -x;
// TODO, perf comp with: *(((int *) &x) + 1) &= 0x7fffffff;
}
};
template <typename genFIType>
struct compute_abs<genFIType, false>
{
GLM_FUNC_QUALIFIER static genFIType call(genFIType x)
{
GLM_STATIC_ASSERT(
!std::numeric_limits<genFIType>::is_signed && std::numeric_limits<genFIType>::is_integer,
"'abs' only accept floating-point and integer scalar or vector inputs");
return x;
}
};
template <typename T, typename U, precision P, template <class, precision> class vecType>
struct compute_mix_vector
{
GLM_FUNC_QUALIFIER static vecType<T, P> call(vecType<T, P> const & x, vecType<T, P> const & y, vecType<U, P> const & a)
{
GLM_STATIC_ASSERT(std::numeric_limits<U>::is_iec559, "'mix' only accept floating-point inputs for the interpolator a");
return vecType<T, P>(vecType<U, P>(x) + a * vecType<U, P>(y - x));
}
};
template <typename T, precision P, template <class, precision> class vecType>
struct compute_mix_vector<T, bool, P, vecType>
{
GLM_FUNC_QUALIFIER static vecType<T, P> call(vecType<T, P> const & x, vecType<T, P> const & y, vecType<bool, P> const & a)
{
vecType<T, P> Result(uninitialize);
for(detail::component_count_t i = 0; i < detail::component_count(x); ++i)
Result[i] = a[i] ? y[i] : x[i];
return Result;
}
};
template <typename T, typename U, precision P, template <class, precision> class vecType>
struct compute_mix_scalar
{
GLM_FUNC_QUALIFIER static vecType<T, P> call(vecType<T, P> const & x, vecType<T, P> const & y, U const & a)
{
GLM_STATIC_ASSERT(std::numeric_limits<U>::is_iec559, "'mix' only accept floating-point inputs for the interpolator a");
return vecType<T, P>(vecType<U, P>(x) + a * vecType<U, P>(y - x));
}
};
template <typename T, precision P, template <class, precision> class vecType>
struct compute_mix_scalar<T, bool, P, vecType>
{
GLM_FUNC_QUALIFIER static vecType<T, P> call(vecType<T, P> const & x, vecType<T, P> const & y, bool const & a)
{
return a ? y : x;
}
};
template <typename T, typename U>
struct compute_mix
{
GLM_FUNC_QUALIFIER static T call(T const & x, T const & y, U const & a)
{
GLM_STATIC_ASSERT(std::numeric_limits<U>::is_iec559, "'mix' only accept floating-point inputs for the interpolator a");
return static_cast<T>(static_cast<U>(x) + a * static_cast<U>(y - x));
}
};
template <typename T>
struct compute_mix<T, bool>
{
GLM_FUNC_QUALIFIER static T call(T const & x, T const & y, bool const & a)
{
return a ? y : x;
}
};
template <typename T, precision P, template <class, precision> class vecType, bool isFloat = true, bool isSigned = true>
struct compute_sign
{
GLM_FUNC_QUALIFIER static vecType<T, P> call(vecType<T, P> const & x)
{
return vecType<T, P>(glm::lessThan(vecType<T, P>(0), x)) - vecType<T, P>(glm::lessThan(x, vecType<T, P>(0)));
}
};
template <typename T, precision P, template <class, precision> class vecType>
struct compute_sign<T, P, vecType, false, false>
{
GLM_FUNC_QUALIFIER static vecType<T, P> call(vecType<T, P> const & x)
{
return vecType<T, P>(glm::greaterThan(x , vecType<T, P>(0)));
}
};
template <typename T, precision P, template <class, precision> class vecType>
struct compute_sign<T, P, vecType, false, true>
{
GLM_FUNC_QUALIFIER static vecType<T, P> call(vecType<T, P> const & x)
{
T const Shift(static_cast<T>(sizeof(T) * 8 - 1));
vecType<T, P> const y(vecType<typename make_unsigned<T>::type, P>(-x) >> typename make_unsigned<T>::type(Shift));
return (x >> Shift) | y;
}
};
template <typename T, precision P, template <class, precision> class vecType, typename genType, bool isFloat = true>
struct compute_mod
{
GLM_FUNC_QUALIFIER static vecType<T, P> call(vecType<T, P> const & a, genType const & b)
{
GLM_STATIC_ASSERT(std::numeric_limits<T>::is_iec559, "'mod' only accept floating-point inputs. Include <glm/gtc/integer.hpp> for integer inputs.");
return a - b * floor(a / b);
}
};
}//namespace detail
// abs
template <>
GLM_FUNC_QUALIFIER int32 abs(int32 x)
{
int32 const y = x >> 31;
return (x ^ y) - y;
}
template <typename genFIType>
GLM_FUNC_QUALIFIER genFIType abs(genFIType x)
{
return detail::compute_abs<genFIType, std::numeric_limits<genFIType>::is_signed>::call(x);
}
template <typename T, precision P, template <typename, precision> class vecType>
GLM_FUNC_QUALIFIER vecType<T, P> abs(vecType<T, P> const & x)
{
return detail::functor1<T, T, P, vecType>::call(abs, x);
}
// sign
// fast and works for any type
template <typename genFIType>
GLM_FUNC_QUALIFIER genFIType sign(genFIType x)
{
GLM_STATIC_ASSERT(
std::numeric_limits<genFIType>::is_iec559 || (std::numeric_limits<genFIType>::is_signed && std::numeric_limits<genFIType>::is_integer),
"'sign' only accept signed inputs");
return detail::compute_sign<genFIType, defaultp, tvec1, std::numeric_limits<genFIType>::is_iec559>::call(tvec1<genFIType>(x)).x;
}
template <typename T, precision P, template <typename, precision> class vecType>
GLM_FUNC_QUALIFIER vecType<T, P> sign(vecType<T, P> const & x)
{
GLM_STATIC_ASSERT(
std::numeric_limits<T>::is_iec559 || (std::numeric_limits<T>::is_signed && std::numeric_limits<T>::is_integer),
"'sign' only accept signed inputs");
return detail::compute_sign<T, P, vecType, std::numeric_limits<T>::is_iec559>::call(x);
}
// floor
using ::std::floor;
template <typename T, precision P, template <typename, precision> class vecType>
GLM_FUNC_QUALIFIER vecType<T, P> floor(vecType<T, P> const & x)
{
return detail::functor1<T, T, P, vecType>::call(floor, x);
}
// trunc
# if GLM_HAS_CXX11_STL
using ::std::trunc;
# else
template <typename genType>
GLM_FUNC_QUALIFIER genType trunc(genType x)
{
GLM_STATIC_ASSERT(std::numeric_limits<genType>::is_iec559, "'trunc' only accept floating-point inputs");
return x < static_cast<genType>(0) ? -floor(-x) : floor(x);
}
# endif
template <typename T, precision P, template <typename, precision> class vecType>
GLM_FUNC_QUALIFIER vecType<T, P> trunc(vecType<T, P> const & x)
{
return detail::functor1<T, T, P, vecType>::call(trunc, x);
}
// round
# if GLM_HAS_CXX11_STL
using ::std::round;
# else
template <typename genType>
GLM_FUNC_QUALIFIER genType round(genType x)
{
GLM_STATIC_ASSERT(std::numeric_limits<genType>::is_iec559, "'round' only accept floating-point inputs");
return x < static_cast<genType>(0) ? static_cast<genType>(int(x - static_cast<genType>(0.5))) : static_cast<genType>(int(x + static_cast<genType>(0.5)));
}
# endif
template <typename T, precision P, template <typename, precision> class vecType>
GLM_FUNC_QUALIFIER vecType<T, P> round(vecType<T, P> const & x)
{
return detail::functor1<T, T, P, vecType>::call(round, x);
}
/*
// roundEven
template <typename genType>
GLM_FUNC_QUALIFIER genType roundEven(genType const& x)
{
GLM_STATIC_ASSERT(std::numeric_limits<genType>::is_iec559, "'roundEven' only accept floating-point inputs");
return genType(int(x + genType(int(x) % 2)));
}
*/
// roundEven
template <typename genType>
GLM_FUNC_QUALIFIER genType roundEven(genType x)
{
GLM_STATIC_ASSERT(std::numeric_limits<genType>::is_iec559, "'roundEven' only accept floating-point inputs");
int Integer = static_cast<int>(x);
genType IntegerPart = static_cast<genType>(Integer);
genType FractionalPart = fract(x);
if(FractionalPart > static_cast<genType>(0.5) || FractionalPart < static_cast<genType>(0.5))
{
return round(x);
}
else if((Integer % 2) == 0)
{
return IntegerPart;
}
else if(x <= static_cast<genType>(0)) // Work around...
{
return IntegerPart - static_cast<genType>(1);
}
else
{
return IntegerPart + static_cast<genType>(1);
}
//else // Bug on MinGW 4.5.2
//{
// return mix(IntegerPart + genType(-1), IntegerPart + genType(1), x <= genType(0));
//}
}
template <typename T, precision P, template <typename, precision> class vecType>
GLM_FUNC_QUALIFIER vecType<T, P> roundEven(vecType<T, P> const & x)
{
return detail::functor1<T, T, P, vecType>::call(roundEven, x);
}
// ceil
using ::std::ceil;
template <typename T, precision P, template <typename, precision> class vecType>
GLM_FUNC_QUALIFIER vecType<T, P> ceil(vecType<T, P> const & x)
{
return detail::functor1<T, T, P, vecType>::call(ceil, x);
}
// fract
template <typename genType>
GLM_FUNC_QUALIFIER genType fract(genType x)
{
GLM_STATIC_ASSERT(std::numeric_limits<genType>::is_iec559, "'fract' only accept floating-point inputs");
return fract(tvec1<genType>(x)).x;
}
template <typename T, precision P, template <typename, precision> class vecType>
GLM_FUNC_QUALIFIER vecType<T, P> fract(vecType<T, P> const & x)
{
return x - floor(x);
}
// mod
template <typename genType>
GLM_FUNC_QUALIFIER genType mod(genType x, genType y)
{
return mod(tvec1<genType>(x), y).x;
}
template <typename T, precision P, template <typename, precision> class vecType>
GLM_FUNC_QUALIFIER vecType<T, P> mod(vecType<T, P> const & x, T y)
{
return detail::compute_mod<T, P, vecType, T, std::numeric_limits<T>::is_iec559>::call(x, y);
}
template <typename T, precision P, template <typename, precision> class vecType>
GLM_FUNC_QUALIFIER vecType<T, P> mod(vecType<T, P> const & x, vecType<T, P> const & y)
{
return detail::compute_mod<T, P, vecType, vecType<T, P>, std::numeric_limits<T>::is_iec559>::call(x, y);
}
// modf
template <typename genType>
GLM_FUNC_QUALIFIER genType modf(genType x, genType & i)
{
GLM_STATIC_ASSERT(std::numeric_limits<genType>::is_iec559, "'modf' only accept floating-point inputs");
return std::modf(x, &i);
}
template <typename T, precision P>
GLM_FUNC_QUALIFIER tvec1<T, P> modf(tvec1<T, P> const & x, tvec1<T, P> & i)
{
return tvec1<T, P>(
modf(x.x, i.x));
}
template <typename T, precision P>
GLM_FUNC_QUALIFIER tvec2<T, P> modf(tvec2<T, P> const & x, tvec2<T, P> & i)
{
return tvec2<T, P>(
modf(x.x, i.x),
modf(x.y, i.y));
}
template <typename T, precision P>
GLM_FUNC_QUALIFIER tvec3<T, P> modf(tvec3<T, P> const & x, tvec3<T, P> & i)
{
return tvec3<T, P>(
modf(x.x, i.x),
modf(x.y, i.y),
modf(x.z, i.z));
}
template <typename T, precision P>
GLM_FUNC_QUALIFIER tvec4<T, P> modf(tvec4<T, P> const & x, tvec4<T, P> & i)
{
return tvec4<T, P>(
modf(x.x, i.x),
modf(x.y, i.y),
modf(x.z, i.z),
modf(x.w, i.w));
}
//// Only valid if (INT_MIN <= x-y <= INT_MAX)
//// min(x,y)
//r = y + ((x - y) & ((x - y) >> (sizeof(int) *
//CHAR_BIT - 1)));
//// max(x,y)
//r = x - ((x - y) & ((x - y) >> (sizeof(int) *
//CHAR_BIT - 1)));
// min
template <typename genType>
GLM_FUNC_QUALIFIER genType min(genType x, genType y)
{
GLM_STATIC_ASSERT(std::numeric_limits<genType>::is_iec559 || std::numeric_limits<genType>::is_integer, "'min' only accept floating-point or integer inputs");
return x < y ? x : y;
}
template <typename T, precision P, template <typename, precision> class vecType>
GLM_FUNC_QUALIFIER vecType<T, P> min(vecType<T, P> const & a, T b)
{
return detail::functor2_vec_sca<T, P, vecType>::call(min, a, b);
}
template <typename T, precision P, template <typename, precision> class vecType>
GLM_FUNC_QUALIFIER vecType<T, P> min(vecType<T, P> const & a, vecType<T, P> const & b)
{
return detail::functor2<T, P, vecType>::call(min, a, b);
}
// max
template <typename genType>
GLM_FUNC_QUALIFIER genType max(genType x, genType y)
{
GLM_STATIC_ASSERT(std::numeric_limits<genType>::is_iec559 || std::numeric_limits<genType>::is_integer, "'max' only accept floating-point or integer inputs");
return x > y ? x : y;
}
template <typename T, precision P, template <typename, precision> class vecType>
GLM_FUNC_QUALIFIER vecType<T, P> max(vecType<T, P> const & a, T b)
{
return detail::functor2_vec_sca<T, P, vecType>::call(max, a, b);
}
template <typename T, precision P, template <typename, precision> class vecType>
GLM_FUNC_QUALIFIER vecType<T, P> max(vecType<T, P> const & a, vecType<T, P> const & b)
{
return detail::functor2<T, P, vecType>::call(max, a, b);
}
// clamp
template <typename genType>
GLM_FUNC_QUALIFIER genType clamp(genType x, genType minVal, genType maxVal)
{
GLM_STATIC_ASSERT(std::numeric_limits<genType>::is_iec559 || std::numeric_limits<genType>::is_integer, "'clamp' only accept floating-point or integer inputs");
return min(max(x, minVal), maxVal);
}
template <typename T, precision P, template <typename, precision> class vecType>
GLM_FUNC_QUALIFIER vecType<T, P> clamp(vecType<T, P> const & x, T minVal, T maxVal)
{
GLM_STATIC_ASSERT(std::numeric_limits<T>::is_iec559 || std::numeric_limits<T>::is_integer, "'clamp' only accept floating-point or integer inputs");
return min(max(x, minVal), maxVal);
}
template <typename T, precision P, template <typename, precision> class vecType>
GLM_FUNC_QUALIFIER vecType<T, P> clamp(vecType<T, P> const & x, vecType<T, P> const & minVal, vecType<T, P> const & maxVal)
{
GLM_STATIC_ASSERT(std::numeric_limits<T>::is_iec559 || std::numeric_limits<T>::is_integer, "'clamp' only accept floating-point or integer inputs");
return min(max(x, minVal), maxVal);
}
template <typename genTypeT, typename genTypeU>
GLM_FUNC_QUALIFIER genTypeT mix(genTypeT x, genTypeT y, genTypeU a)
{
return detail::compute_mix<genTypeT, genTypeU>::call(x, y, a);
}
template <typename T, typename U, precision P, template <typename, precision> class vecType>
GLM_FUNC_QUALIFIER vecType<T, P> mix(vecType<T, P> const & x, vecType<T, P> const & y, U a)
{
return detail::compute_mix_scalar<T, U, P, vecType>::call(x, y, a);
}
template <typename T, typename U, precision P, template <typename, precision> class vecType>
GLM_FUNC_QUALIFIER vecType<T, P> mix(vecType<T, P> const & x, vecType<T, P> const & y, vecType<U, P> const & a)
{
return detail::compute_mix_vector<T, U, P, vecType>::call(x, y, a);
}
// step
template <typename genType>
GLM_FUNC_QUALIFIER genType step(genType edge, genType x)
{
return mix(static_cast<genType>(1), static_cast<genType>(0), glm::lessThan(x, edge));
}
template <template <typename, precision> class vecType, typename T, precision P>
GLM_FUNC_QUALIFIER vecType<T, P> step(T edge, vecType<T, P> const & x)
{
GLM_STATIC_ASSERT(std::numeric_limits<T>::is_iec559, "'step' only accept floating-point inputs");
return mix(vecType<T, P>(1), vecType<T, P>(0), glm::lessThan(x, vecType<T, P>(edge)));
}
template <template <typename, precision> class vecType, typename T, precision P>
GLM_FUNC_QUALIFIER vecType<T, P> step(vecType<T, P> const & edge, vecType<T, P> const & x)
{
return mix(vecType<T, P>(1), vecType<T, P>(0), glm::lessThan(x, edge));
}
// smoothstep
template <typename genType>
GLM_FUNC_QUALIFIER genType smoothstep(genType edge0, genType edge1, genType x)
{
GLM_STATIC_ASSERT(std::numeric_limits<genType>::is_iec559, "'smoothstep' only accept floating-point inputs");
genType const tmp(clamp((x - edge0) / (edge1 - edge0), genType(0), genType(1)));
return tmp * tmp * (genType(3) - genType(2) * tmp);
}
template <typename T, precision P, template <typename, precision> class vecType>
GLM_FUNC_QUALIFIER vecType<T, P> smoothstep(T edge0, T edge1, vecType<T, P> const & x)
{
GLM_STATIC_ASSERT(std::numeric_limits<T>::is_iec559, "'smoothstep' only accept floating-point inputs");
vecType<T, P> const tmp(clamp((x - edge0) / (edge1 - edge0), static_cast<T>(0), static_cast<T>(1)));
return tmp * tmp * (static_cast<T>(3) - static_cast<T>(2) * tmp);
}
template <typename T, precision P, template <typename, precision> class vecType>
GLM_FUNC_QUALIFIER vecType<T, P> smoothstep(vecType<T, P> const & edge0, vecType<T, P> const & edge1, vecType<T, P> const & x)
{
GLM_STATIC_ASSERT(std::numeric_limits<T>::is_iec559, "'smoothstep' only accept floating-point inputs");
vecType<T, P> const tmp(clamp((x - edge0) / (edge1 - edge0), static_cast<T>(0), static_cast<T>(1)));
return tmp * tmp * (static_cast<T>(3) - static_cast<T>(2) * tmp);
}
# if GLM_HAS_CXX11_STL
using std::isnan;
# else
template <typename genType>
GLM_FUNC_QUALIFIER bool isnan(genType x)
{
GLM_STATIC_ASSERT(std::numeric_limits<genType>::is_iec559, "'isnan' only accept floating-point inputs");
# if GLM_HAS_CXX11_STL
return std::isnan(x);
# elif GLM_COMPILER & (GLM_COMPILER_VC | GLM_COMPILER_INTEL)
return _isnan(x) != 0;
# elif GLM_COMPILER & (GLM_COMPILER_GCC | (GLM_COMPILER_APPLE_CLANG | GLM_COMPILER_LLVM))
# if GLM_PLATFORM & GLM_PLATFORM_ANDROID && __cplusplus < 201103L
return _isnan(x) != 0;
# else
return std::isnan(x);
# endif
# elif GLM_COMPILER & GLM_COMPILER_CUDA
return isnan(x) != 0;
# else
return std::isnan(x);
# endif
}
# endif
template <typename T, precision P, template <typename, precision> class vecType>
GLM_FUNC_QUALIFIER vecType<bool, P> isnan(vecType<T, P> const & x)
{
GLM_STATIC_ASSERT(std::numeric_limits<T>::is_iec559, "'isnan' only accept floating-point inputs");
return detail::functor1<bool, T, P, vecType>::call(isnan, x);
}
# if GLM_HAS_CXX11_STL
using std::isinf;
# else
template <typename genType>
GLM_FUNC_QUALIFIER bool isinf(genType x)
{
GLM_STATIC_ASSERT(std::numeric_limits<genType>::is_iec559, "'isinf' only accept floating-point inputs");
# if GLM_HAS_CXX11_STL
return std::isinf(x);
# elif GLM_COMPILER & (GLM_COMPILER_INTEL | GLM_COMPILER_VC)
return _fpclass(x) == _FPCLASS_NINF || _fpclass(x) == _FPCLASS_PINF;
# elif GLM_COMPILER & (GLM_COMPILER_GCC | (GLM_COMPILER_APPLE_CLANG | GLM_COMPILER_LLVM))
# if(GLM_PLATFORM & GLM_PLATFORM_ANDROID && __cplusplus < 201103L)
return _isinf(x) != 0;
# else
return std::isinf(x);
# endif
# elif GLM_COMPILER & GLM_COMPILER_CUDA
// http://developer.download.nvidia.com/compute/cuda/4_2/rel/toolkit/docs/online/group__CUDA__MATH__DOUBLE_g13431dd2b40b51f9139cbb7f50c18fab.html#g13431dd2b40b51f9139cbb7f50c18fab
return isinf(double(x)) != 0;
# else
return std::isinf(x);
# endif
}
# endif
template <typename T, precision P, template <typename, precision> class vecType>
GLM_FUNC_QUALIFIER vecType<bool, P> isinf(vecType<T, P> const & x)
{
GLM_STATIC_ASSERT(std::numeric_limits<T>::is_iec559, "'isnan' only accept floating-point inputs");
return detail::functor1<bool, T, P, vecType>::call(isinf, x);
}
GLM_FUNC_QUALIFIER int floatBitsToInt(float const & v)
{
return reinterpret_cast<int&>(const_cast<float&>(v));
}
template <template <typename, precision> class vecType, precision P>
GLM_FUNC_QUALIFIER vecType<int, P> floatBitsToInt(vecType<float, P> const & v)
{
return reinterpret_cast<vecType<int, P>&>(const_cast<vecType<float, P>&>(v));
}
GLM_FUNC_QUALIFIER uint floatBitsToUint(float const & v)
{
return reinterpret_cast<uint&>(const_cast<float&>(v));
}
template <template <typename, precision> class vecType, precision P>
GLM_FUNC_QUALIFIER vecType<uint, P> floatBitsToUint(vecType<float, P> const & v)
{
return reinterpret_cast<vecType<uint, P>&>(const_cast<vecType<float, P>&>(v));
}
GLM_FUNC_QUALIFIER float intBitsToFloat(int const & v)
{
return reinterpret_cast<float&>(const_cast<int&>(v));
}
template <template <typename, precision> class vecType, precision P>
GLM_FUNC_QUALIFIER vecType<float, P> intBitsToFloat(vecType<int, P> const & v)
{
return reinterpret_cast<vecType<float, P>&>(const_cast<vecType<int, P>&>(v));
}
GLM_FUNC_QUALIFIER float uintBitsToFloat(uint const & v)
{
return reinterpret_cast<float&>(const_cast<uint&>(v));
}
template <template <typename, precision> class vecType, precision P>
GLM_FUNC_QUALIFIER vecType<float, P> uintBitsToFloat(vecType<uint, P> const & v)
{
return reinterpret_cast<vecType<float, P>&>(const_cast<vecType<uint, P>&>(v));
}
template <typename genType>
GLM_FUNC_QUALIFIER genType fma(genType const & a, genType const & b, genType const & c)
{
return a * b + c;
}
template <typename genType>
GLM_FUNC_QUALIFIER genType frexp(genType x, int & exp)
{
GLM_STATIC_ASSERT(std::numeric_limits<genType>::is_iec559, "'frexp' only accept floating-point inputs");
return std::frexp(x, exp);
}
template <typename T, precision P>
GLM_FUNC_QUALIFIER tvec1<T, P> frexp(tvec1<T, P> const & x, tvec1<int, P> & exp)
{
GLM_STATIC_ASSERT(std::numeric_limits<T>::is_iec559, "'frexp' only accept floating-point inputs");
return tvec1<T, P>(std::frexp(x.x, exp.x));
}
template <typename T, precision P>
GLM_FUNC_QUALIFIER tvec2<T, P> frexp(tvec2<T, P> const & x, tvec2<int, P> & exp)
{
GLM_STATIC_ASSERT(std::numeric_limits<T>::is_iec559, "'frexp' only accept floating-point inputs");
return tvec2<T, P>(
frexp(x.x, exp.x),
frexp(x.y, exp.y));
}
template <typename T, precision P>
GLM_FUNC_QUALIFIER tvec3<T, P> frexp(tvec3<T, P> const & x, tvec3<int, P> & exp)
{
GLM_STATIC_ASSERT(std::numeric_limits<T>::is_iec559, "'frexp' only accept floating-point inputs");
return tvec3<T, P>(
frexp(x.x, exp.x),
frexp(x.y, exp.y),
frexp(x.z, exp.z));
}
template <typename T, precision P>
GLM_FUNC_QUALIFIER tvec4<T, P> frexp(tvec4<T, P> const & x, tvec4<int, P> & exp)
{
GLM_STATIC_ASSERT(std::numeric_limits<T>::is_iec559, "'frexp' only accept floating-point inputs");
return tvec4<T, P>(
frexp(x.x, exp.x),
frexp(x.y, exp.y),
frexp(x.z, exp.z),
frexp(x.w, exp.w));
}
template <typename genType, precision P>
GLM_FUNC_QUALIFIER genType ldexp(genType const & x, int const & exp)
{
GLM_STATIC_ASSERT(std::numeric_limits<genType>::is_iec559, "'ldexp' only accept floating-point inputs");
return std::ldexp(x, exp);
}
template <typename T, precision P>
GLM_FUNC_QUALIFIER tvec1<T, P> ldexp(tvec1<T, P> const & x, tvec1<int, P> const & exp)
{
GLM_STATIC_ASSERT(std::numeric_limits<T>::is_iec559, "'ldexp' only accept floating-point inputs");
return tvec1<T, P>(
ldexp(x.x, exp.x));
}
template <typename T, precision P>
GLM_FUNC_QUALIFIER tvec2<T, P> ldexp(tvec2<T, P> const & x, tvec2<int, P> const & exp)
{
GLM_STATIC_ASSERT(std::numeric_limits<T>::is_iec559, "'ldexp' only accept floating-point inputs");
return tvec2<T, P>(
ldexp(x.x, exp.x),
ldexp(x.y, exp.y));
}
template <typename T, precision P>
GLM_FUNC_QUALIFIER tvec3<T, P> ldexp(tvec3<T, P> const & x, tvec3<int, P> const & exp)
{
GLM_STATIC_ASSERT(std::numeric_limits<T>::is_iec559, "'ldexp' only accept floating-point inputs");
return tvec3<T, P>(
ldexp(x.x, exp.x),
ldexp(x.y, exp.y),
ldexp(x.z, exp.z));
}
template <typename T, precision P>
GLM_FUNC_QUALIFIER tvec4<T, P> ldexp(tvec4<T, P> const & x, tvec4<int, P> const & exp)
{
GLM_STATIC_ASSERT(std::numeric_limits<T>::is_iec559, "'ldexp' only accept floating-point inputs");
return tvec4<T, P>(
ldexp(x.x, exp.x),
ldexp(x.y, exp.y),
ldexp(x.z, exp.z),
ldexp(x.w, exp.w));
}
}//namespace glm
///////////////////////////////////////////////////////////////////////////////////
/// OpenGL Mathematics (glm.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
/// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
/// copies of the Software, and to permit persons to whom the Software is
/// furnished to do so, subject to the following conditions:
///
/// 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
/// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
/// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
/// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
/// THE SOFTWARE.
///
/// @ref core
/// @file glm/detail/func_exponential.hpp
/// @date 2008-08-08 / 2011-06-14
/// @author Christophe Riccio
///
/// @see <a href="http://www.opengl.org/registry/doc/GLSLangSpec.4.20.8.pdf">GLSL 4.20.8 specification, section 8.2 Exponential Functions</a>
///
/// @defgroup core_func_exponential Exponential functions
/// @ingroup core
///
/// These all operate component-wise. The description is per component.
///////////////////////////////////////////////////////////////////////////////////
#pragma once
#include "type_vec1.hpp"
#include "type_vec2.hpp"
#include "type_vec3.hpp"
#include "type_vec4.hpp"
#include <cmath>
namespace glm
{
/// @addtogroup core_func_exponential
/// @{
/// Returns 'base' raised to the power 'exponent'.
///
/// @param base Floating point value. pow function is defined for input values of 'base' defined in the range (inf-, inf+) in the limit of the type precision.
/// @param exponent Floating point value representing the 'exponent'.
/// @tparam genType Floating-point scalar or vector types.
///
/// @see <a href="http://www.opengl.org/sdk/docs/manglsl/xhtml/pow.xml">GLSL pow man page</a>
/// @see <a href="http://www.opengl.org/registry/doc/GLSLangSpec.4.20.8.pdf">GLSL 4.20.8 specification, section 8.2 Exponential Functions</a>
template <typename T, precision P, template <typename, precision> class vecType>
GLM_FUNC_DECL vecType<T, P> pow(vecType<T, P> const & base, vecType<T, P> const & exponent);
/// Returns the natural exponentiation of x, i.e., e^x.
///
/// @param v exp function is defined for input values of v defined in the range (inf-, inf+) in the limit of the type precision.
/// @tparam genType Floating-point scalar or vector types.
///
/// @see <a href="http://www.opengl.org/sdk/docs/manglsl/xhtml/exp.xml">GLSL exp man page</a>
/// @see <a href="http://www.opengl.org/registry/doc/GLSLangSpec.4.20.8.pdf">GLSL 4.20.8 specification, section 8.2 Exponential Functions</a>
template <typename T, precision P, template <typename, precision> class vecType>
GLM_FUNC_DECL vecType<T, P> exp(vecType<T, P> const & v);
/// Returns the natural logarithm of v, i.e.,
/// returns the value y which satisfies the equation x = e^y.
/// Results are undefined if v <= 0.
///
/// @param v log function is defined for input values of v defined in the range (0, inf+) in the limit of the type precision.
/// @tparam genType Floating-point scalar or vector types.
///
/// @see <a href="http://www.opengl.org/sdk/docs/manglsl/xhtml/log.xml">GLSL log man page</a>
/// @see <a href="http://www.opengl.org/registry/doc/GLSLangSpec.4.20.8.pdf">GLSL 4.20.8 specification, section 8.2 Exponential Functions</a>
template <typename T, precision P, template <typename, precision> class vecType>
GLM_FUNC_DECL vecType<T, P> log(vecType<T, P> const & v);
/// Returns 2 raised to the v power.
///
/// @param v exp2 function is defined for input values of v defined in the range (inf-, inf+) in the limit of the type precision.
/// @tparam genType Floating-point scalar or vector types.
///
/// @see <a href="http://www.opengl.org/sdk/docs/manglsl/xhtml/exp2.xml">GLSL exp2 man page</a>
/// @see <a href="http://www.opengl.org/registry/doc/GLSLangSpec.4.20.8.pdf">GLSL 4.20.8 specification, section 8.2 Exponential Functions</a>
template <typename T, precision P, template <typename, precision> class vecType>
GLM_FUNC_DECL vecType<T, P> exp2(vecType<T, P> const & v);
/// Returns the base 2 log of x, i.e., returns the value y,
/// which satisfies the equation x = 2 ^ y.
///
/// @param v log2 function is defined for input values of v defined in the range (0, inf+) in the limit of the type precision.
/// @tparam genType Floating-point scalar or vector types.
///
/// @see <a href="http://www.opengl.org/sdk/docs/manglsl/xhtml/log2.xml">GLSL log2 man page</a>
/// @see <a href="http://www.opengl.org/registry/doc/GLSLangSpec.4.20.8.pdf">GLSL 4.20.8 specification, section 8.2 Exponential Functions</a>
template <typename T, precision P, template <typename, precision> class vecType>
GLM_FUNC_DECL vecType<T, P> log2(vecType<T, P> const & v);
/// Returns the positive square root of v.
///
/// @param v sqrt function is defined for input values of v defined in the range [0, inf+) in the limit of the type precision.
/// @tparam genType Floating-point scalar or vector types.
///
/// @see <a href="http://www.opengl.org/sdk/docs/manglsl/xhtml/sqrt.xml">GLSL sqrt man page</a>
/// @see <a href="http://www.opengl.org/registry/doc/GLSLangSpec.4.20.8.pdf">GLSL 4.20.8 specification, section 8.2 Exponential Functions</a>
//template <typename genType>
//GLM_FUNC_DECL genType sqrt(genType const & x);
template <typename T, precision P, template <typename, precision> class vecType>
GLM_FUNC_DECL vecType<T, P> sqrt(vecType<T, P> const & v);
/// Returns the reciprocal of the positive square root of v.
///
/// @param v inversesqrt function is defined for input values of v defined in the range [0, inf+) in the limit of the type precision.
/// @tparam genType Floating-point scalar or vector types.
///
/// @see <a href="http://www.opengl.org/sdk/docs/manglsl/xhtml/inversesqrt.xml">GLSL inversesqrt man page</a>
/// @see <a href="http://www.opengl.org/registry/doc/GLSLangSpec.4.20.8.pdf">GLSL 4.20.8 specification, section 8.2 Exponential Functions</a>
template <typename T, precision P, template <typename, precision> class vecType>
GLM_FUNC_DECL vecType<T, P> inversesqrt(vecType<T, P> const & v);
/// @}
}//namespace glm
#include "func_exponential.inl"
///////////////////////////////////////////////////////////////////////////////////
/// OpenGL Mathematics (glm.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
/// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
/// copies of the Software, and to permit persons to whom the Software is
/// furnished to do so, subject to the following conditions:
///
/// 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
/// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
/// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
/// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
/// THE SOFTWARE.
///
/// @ref core
/// @file glm/detail/func_exponential.inl
/// @date 2008-08-03 / 2011-06-15
/// @author Christophe Riccio
///////////////////////////////////////////////////////////////////////////////////
#include "func_vector_relational.hpp"
#include "_vectorize.hpp"
#include <limits>
#include <cmath>
#include <cassert>
namespace glm{
namespace detail
{
# if GLM_HAS_CXX11_STL
using std::log2;
# else
template <typename genType>
genType log2(genType Value)
{
return std::log(Value) * static_cast<genType>(1.4426950408889634073599246810019);
}
# endif
template <typename T, precision P, template <class, precision> class vecType, bool isFloat = true>
struct compute_log2
{
GLM_FUNC_QUALIFIER static vecType<T, P> call(vecType<T, P> const & vec)
{
return detail::functor1<T, T, P, vecType>::call(log2, vec);
}
};
template <template <class, precision> class vecType, typename T, precision P>
struct compute_inversesqrt
{
GLM_FUNC_QUALIFIER static vecType<T, P> call(vecType<T, P> const & x)
{
return static_cast<T>(1) / sqrt(x);
}
};
template <template <class, precision> class vecType>
struct compute_inversesqrt<vecType, float, lowp>
{
GLM_FUNC_QUALIFIER static vecType<float, lowp> call(vecType<float, lowp> const & x)
{
vecType<float, lowp> tmp(x);
vecType<float, lowp> xhalf(tmp * 0.5f);
vecType<uint, lowp>* p = reinterpret_cast<vecType<uint, lowp>*>(const_cast<vecType<float, lowp>*>(&x));
vecType<uint, lowp> i = vecType<uint, lowp>(0x5f375a86) - (*p >> vecType<uint, lowp>(1));
vecType<float, lowp>* ptmp = reinterpret_cast<vecType<float, lowp>*>(&i);
tmp = *ptmp;
tmp = tmp * (1.5f - xhalf * tmp * tmp);
return tmp;
}
};
}//namespace detail
// pow
using std::pow;
template <typename T, precision P, template <typename, precision> class vecType>
GLM_FUNC_QUALIFIER vecType<T, P> pow(vecType<T, P> const & base, vecType<T, P> const & exponent)
{
return detail::functor2<T, P, vecType>::call(pow, base, exponent);
}
// exp
using std::exp;
template <typename T, precision P, template <typename, precision> class vecType>
GLM_FUNC_QUALIFIER vecType<T, P> exp(vecType<T, P> const & x)
{
return detail::functor1<T, T, P, vecType>::call(exp, x);
}
// log
using std::log;
template <typename T, precision P, template <typename, precision> class vecType>
GLM_FUNC_QUALIFIER vecType<T, P> log(vecType<T, P> const & x)
{
return detail::functor1<T, T, P, vecType>::call(log, x);
}
//exp2, ln2 = 0.69314718055994530941723212145818f
template <typename genType>
GLM_FUNC_QUALIFIER genType exp2(genType x)
{
GLM_STATIC_ASSERT(std::numeric_limits<genType>::is_iec559, "'exp2' only accept floating-point inputs");
return std::exp(static_cast<genType>(0.69314718055994530941723212145818) * x);
}
template <typename T, precision P, template <typename, precision> class vecType>
GLM_FUNC_QUALIFIER vecType<T, P> exp2(vecType<T, P> const & x)
{
return detail::functor1<T, T, P, vecType>::call(exp2, x);
}
// log2, ln2 = 0.69314718055994530941723212145818f
template <typename genType>
GLM_FUNC_QUALIFIER genType log2(genType x)
{
return log2(tvec1<genType>(x)).x;
}
template <typename T, precision P, template <typename, precision> class vecType>
GLM_FUNC_QUALIFIER vecType<T, P> log2(vecType<T, P> const & x)
{
return detail::compute_log2<T, P, vecType, std::numeric_limits<T>::is_iec559>::call(x);
}
// sqrt
using std::sqrt;
template <typename T, precision P, template <typename, precision> class vecType>
GLM_FUNC_QUALIFIER vecType<T, P> sqrt(vecType<T, P> const & x)
{
GLM_STATIC_ASSERT(std::numeric_limits<T>::is_iec559, "'sqrt' only accept floating-point inputs");
return detail::functor1<T, T, P, vecType>::call(sqrt, x);
}
// inversesqrt
template <typename genType>
GLM_FUNC_QUALIFIER genType inversesqrt(genType x)
{
return static_cast<genType>(1) / sqrt(x);
}
template <typename T, precision P, template <typename, precision> class vecType>
GLM_FUNC_QUALIFIER vecType<T, P> inversesqrt(vecType<T, P> const & x)
{
GLM_STATIC_ASSERT(std::numeric_limits<T>::is_iec559, "'inversesqrt' only accept floating-point inputs");
return detail::compute_inversesqrt<vecType, T, P>::call(x);
}
}//namespace glm
///////////////////////////////////////////////////////////////////////////////////
/// OpenGL Mathematics (glm.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
/// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
/// copies of the Software, and to permit persons to whom the Software is
/// furnished to do so, subject to the following conditions:
///
/// 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
/// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
/// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
/// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
/// THE SOFTWARE.
///
/// @ref core
/// @file glm/detail/func_geometric.hpp
/// @date 2008-08-03 / 2011-06-14
/// @author Christophe Riccio
///
/// @see <a href="http://www.opengl.org/registry/doc/GLSLangSpec.4.20.8.pdf">GLSL 4.20.8 specification, section 8.5 Geometric Functions</a>
///
/// @defgroup core_func_geometric Geometric functions
/// @ingroup core
///
/// These operate on vectors as vectors, not component-wise.
///////////////////////////////////////////////////////////////////////////////////
#pragma once
#include "type_vec3.hpp"
namespace glm
{
/// @addtogroup core_func_geometric
/// @{
/// Returns the length of x, i.e., sqrt(x * x).
///
/// @tparam genType Floating-point vector types.
///
/// @see <a href="http://www.opengl.org/sdk/docs/manglsl/xhtml/length.xml">GLSL length man page</a>
/// @see <a href="http://www.opengl.org/registry/doc/GLSLangSpec.4.20.8.pdf">GLSL 4.20.8 specification, section 8.5 Geometric Functions</a>
template <typename T, precision P, template <typename, precision> class vecType>
GLM_FUNC_DECL T length(
vecType<T, P> const & x);
/// Returns the distance betwwen p0 and p1, i.e., length(p0 - p1).
///
/// @tparam genType Floating-point vector types.
///
/// @see <a href="http://www.opengl.org/sdk/docs/manglsl/xhtml/distance.xml">GLSL distance man page</a>
/// @see <a href="http://www.opengl.org/registry/doc/GLSLangSpec.4.20.8.pdf">GLSL 4.20.8 specification, section 8.5 Geometric Functions</a>
template <typename T, precision P, template <typename, precision> class vecType>
GLM_FUNC_DECL T distance(
vecType<T, P> const & p0,
vecType<T, P> const & p1);
/// Returns the dot product of x and y, i.e., result = x * y.
///
/// @tparam genType Floating-point vector types.
///
/// @see <a href="http://www.opengl.org/sdk/docs/manglsl/xhtml/dot.xml">GLSL dot man page</a>
/// @see <a href="http://www.opengl.org/registry/doc/GLSLangSpec.4.20.8.pdf">GLSL 4.20.8 specification, section 8.5 Geometric Functions</a>
template <typename T, precision P, template <typename, precision> class vecType>
GLM_FUNC_DECL T dot(
vecType<T, P> const & x,
vecType<T, P> const & y);
/// Returns the cross product of x and y.
///
/// @tparam valType Floating-point scalar types.
///
/// @see <a href="http://www.opengl.org/sdk/docs/manglsl/xhtml/cross.xml">GLSL cross man page</a>
/// @see <a href="http://www.opengl.org/registry/doc/GLSLangSpec.4.20.8.pdf">GLSL 4.20.8 specification, section 8.5 Geometric Functions</a>
template <typename T, precision P>
GLM_FUNC_DECL tvec3<T, P> cross(
tvec3<T, P> const & x,
tvec3<T, P> const & y);
/// Returns a vector in the same direction as x but with length of 1.
/// According to issue 10 GLSL 1.10 specification, if length(x) == 0 then result is undefined and generate an error.
///
/// @see <a href="http://www.opengl.org/sdk/docs/manglsl/xhtml/normalize.xml">GLSL normalize man page</a>
/// @see <a href="http://www.opengl.org/registry/doc/GLSLangSpec.4.20.8.pdf">GLSL 4.20.8 specification, section 8.5 Geometric Functions</a>
template <typename T, precision P, template <typename, precision> class vecType>
GLM_FUNC_DECL vecType<T, P> normalize(
vecType<T, P> const & x);
/// If dot(Nref, I) < 0.0, return N, otherwise, return -N.
///
/// @tparam genType Floating-point vector types.
///
/// @see <a href="http://www.opengl.org/sdk/docs/manglsl/xhtml/faceforward.xml">GLSL faceforward man page</a>
/// @see <a href="http://www.opengl.org/registry/doc/GLSLangSpec.4.20.8.pdf">GLSL 4.20.8 specification, section 8.5 Geometric Functions</a>
template <typename T, precision P, template <typename, precision> class vecType>
GLM_FUNC_DECL vecType<T, P> faceforward(
vecType<T, P> const & N,
vecType<T, P> const & I,
vecType<T, P> const & Nref);
/// For the incident vector I and surface orientation N,
/// returns the reflection direction : result = I - 2.0 * dot(N, I) * N.
///
/// @tparam genType Floating-point vector types.
///
/// @see <a href="http://www.opengl.org/sdk/docs/manglsl/xhtml/reflect.xml">GLSL reflect man page</a>
/// @see <a href="http://www.opengl.org/registry/doc/GLSLangSpec.4.20.8.pdf">GLSL 4.20.8 specification, section 8.5 Geometric Functions</a>
template <typename genType>
GLM_FUNC_DECL genType reflect(
genType const & I,
genType const & N);
/// For the incident vector I and surface normal N,
/// and the ratio of indices of refraction eta,
/// return the refraction vector.
///
/// @tparam genType Floating-point vector types.
///
/// @see <a href="http://www.opengl.org/sdk/docs/manglsl/xhtml/refract.xml">GLSL refract man page</a>
/// @see <a href="http://www.opengl.org/registry/doc/GLSLangSpec.4.20.8.pdf">GLSL 4.20.8 specification, section 8.5 Geometric Functions</a>
template <typename T, precision P, template <typename, precision> class vecType>
GLM_FUNC_DECL vecType<T, P> refract(
vecType<T, P> const & I,
vecType<T, P> const & N,
T eta);
/// @}
}//namespace glm
#include "func_geometric.inl"
///////////////////////////////////////////////////////////////////////////////////
/// OpenGL Mathematics (glm.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
/// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
/// copies of the Software, and to permit persons to whom the Software is
/// furnished to do so, subject to the following conditions:
///
/// 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
/// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
/// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
/// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
/// THE SOFTWARE.
///
/// @ref core
/// @file glm/detail/func_geometric.inl
/// @date 2008-08-03 / 2011-06-15
/// @author Christophe Riccio
///////////////////////////////////////////////////////////////////////////////////
#include "func_exponential.hpp"
#include "func_common.hpp"
#include "type_vec2.hpp"
#include "type_vec4.hpp"
#include "type_float.hpp"
namespace glm{
namespace detail
{
template <template <class, precision> class vecType, typename T, precision P>
struct compute_dot{};
template <typename T, precision P>
struct compute_dot<tvec1, T, P>
{
GLM_FUNC_QUALIFIER static T call(tvec1<T, P> const & a, tvec1<T, P> const & b)
{
return a.x * b.x;
}
};
template <typename T, precision P>
struct compute_dot<tvec2, T, P>
{
GLM_FUNC_QUALIFIER static T call(tvec2<T, P> const & x, tvec2<T, P> const & y)
{
tvec2<T, P> tmp(x * y);
return tmp.x + tmp.y;
}
};
template <typename T, precision P>
struct compute_dot<tvec3, T, P>
{
GLM_FUNC_QUALIFIER static T call(tvec3<T, P> const & x, tvec3<T, P> const & y)
{
tvec3<T, P> tmp(x * y);
return tmp.x + tmp.y + tmp.z;
}
};
template <typename T, precision P>
struct compute_dot<tvec4, T, P>
{
GLM_FUNC_QUALIFIER static T call(tvec4<T, P> const & x, tvec4<T, P> const & y)
{
tvec4<T, P> tmp(x * y);
return (tmp.x + tmp.y) + (tmp.z + tmp.w);
}
};
}//namespace detail
// length
template <typename genType>
GLM_FUNC_QUALIFIER genType length(genType x)
{
GLM_STATIC_ASSERT(std::numeric_limits<genType>::is_iec559, "'length' only accept floating-point inputs");
return abs(x);
}
template <typename T, precision P, template <typename, precision> class vecType>
GLM_FUNC_QUALIFIER T length(vecType<T, P> const & v)
{
GLM_STATIC_ASSERT(std::numeric_limits<T>::is_iec559, "'length' only accept floating-point inputs");
return sqrt(dot(v, v));
}
// distance
template <typename genType>
GLM_FUNC_QUALIFIER genType distance(genType const & p0, genType const & p1)
{
GLM_STATIC_ASSERT(std::numeric_limits<genType>::is_iec559, "'distance' only accept floating-point inputs");
return length(p1 - p0);
}
template <typename T, precision P, template <typename, precision> class vecType>
GLM_FUNC_QUALIFIER T distance(vecType<T, P> const & p0, vecType<T, P> const & p1)
{
return length(p1 - p0);
}
// dot
template <typename T>
GLM_FUNC_QUALIFIER T dot(T x, T y)
{
GLM_STATIC_ASSERT(std::numeric_limits<T>::is_iec559, "'dot' only accept floating-point inputs");
return x * y;
}
template <typename T, precision P, template <typename, precision> class vecType>
GLM_FUNC_QUALIFIER T dot(vecType<T, P> const & x, vecType<T, P> const & y)
{
GLM_STATIC_ASSERT(std::numeric_limits<T>::is_iec559, "'dot' only accept floating-point inputs");
return detail::compute_dot<vecType, T, P>::call(x, y);
}
// cross
template <typename T, precision P>
GLM_FUNC_QUALIFIER tvec3<T, P> cross(tvec3<T, P> const & x, tvec3<T, P> const & y)
{
GLM_STATIC_ASSERT(std::numeric_limits<T>::is_iec559, "'cross' only accept floating-point inputs");
return tvec3<T, P>(
x.y * y.z - y.y * x.z,
x.z * y.x - y.z * x.x,
x.x * y.y - y.x * x.y);
}
// normalize
template <typename genType>
GLM_FUNC_QUALIFIER genType normalize(genType const & x)
{
GLM_STATIC_ASSERT(std::numeric_limits<genType>::is_iec559, "'normalize' only accept floating-point inputs");
return x < genType(0) ? genType(-1) : genType(1);
}
template <typename T, precision P, template <typename, precision> class vecType>
GLM_FUNC_QUALIFIER vecType<T, P> normalize(vecType<T, P> const & x)
{
GLM_STATIC_ASSERT(std::numeric_limits<T>::is_iec559, "'normalize' only accept floating-point inputs");
return x * inversesqrt(dot(x, x));
}
// faceforward
template <typename genType>
GLM_FUNC_QUALIFIER genType faceforward(genType const & N, genType const & I, genType const & Nref)
{
return dot(Nref, I) < static_cast<genType>(0) ? N : -N;
}
template <typename T, precision P, template <typename, precision> class vecType>
GLM_FUNC_QUALIFIER vecType<T, P> faceforward(vecType<T, P> const & N, vecType<T, P> const & I, vecType<T, P> const & Nref)
{
return dot(Nref, I) < static_cast<T>(0) ? N : -N;
}
// reflect
template <typename genType>
GLM_FUNC_QUALIFIER genType reflect(genType const & I, genType const & N)
{
return I - N * dot(N, I) * static_cast<genType>(2);
}
// refract
template <typename genType>
GLM_FUNC_QUALIFIER genType refract(genType const & I, genType const & N, genType const & eta)
{
GLM_STATIC_ASSERT(std::numeric_limits<genType>::is_iec559, "'refract' only accept floating-point inputs");
genType const dotValue(dot(N, I));
genType const k(static_cast<genType>(1) - eta * eta * (static_cast<genType>(1) - dotValue * dotValue));
return (eta * I - (eta * dotValue + sqrt(k)) * N) * static_cast<genType>(k >= static_cast<genType>(0));
}
template <typename T, precision P, template <typename, precision> class vecType>
GLM_FUNC_QUALIFIER vecType<T, P> refract(vecType<T, P> const & I, vecType<T, P> const & N, T eta)
{
GLM_STATIC_ASSERT(std::numeric_limits<T>::is_iec559, "'refract' only accept floating-point inputs");
T const dotValue(dot(N, I));
T const k(static_cast<T>(1) - eta * eta * (static_cast<T>(1) - dotValue * dotValue));
return (eta * I - (eta * dotValue + std::sqrt(k)) * N) * static_cast<T>(k >= static_cast<T>(0));
}
}//namespace glm
///////////////////////////////////////////////////////////////////////////////////
/// OpenGL Mathematics (glm.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
/// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
/// copies of the Software, and to permit persons to whom the Software is
/// furnished to do so, subject to the following conditions:
///
/// 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
/// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
/// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
/// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
/// THE SOFTWARE.
///
/// @ref core
/// @file glm/detail/func_integer.hpp
/// @date 2010-03-17 / 2011-06-18
/// @author Christophe Riccio
///
/// @see <a href="http://www.opengl.org/registry/doc/GLSLangSpec.4.20.8.pdf">GLSL 4.20.8 specification, section 8.8 Integer Functions</a>
///
/// @defgroup core_func_integer Integer functions
/// @ingroup core
///
/// These all operate component-wise. The description is per component.
/// The notation [a, b] means the set of bits from bit-number a through bit-number
/// b, inclusive. The lowest-order bit is bit 0.
///////////////////////////////////////////////////////////////////////////////////
#pragma once
#include "setup.hpp"
#include "precision.hpp"
#include "func_common.hpp"
#include "func_vector_relational.hpp"
namespace glm
{
/// @addtogroup core_func_integer
/// @{
/// Adds 32-bit unsigned integer x and y, returning the sum
/// modulo pow(2, 32). The value carry is set to 0 if the sum was
/// less than pow(2, 32), or to 1 otherwise.
///
/// @tparam genUType Unsigned integer scalar or vector types.
///
/// @see <a href="http://www.opengl.org/sdk/docs/manglsl/xhtml/uaddCarry.xml">GLSL uaddCarry man page</a>
/// @see <a href="http://www.opengl.org/registry/doc/GLSLangSpec.4.20.8.pdf">GLSL 4.20.8 specification, section 8.8 Integer Functions</a>
template <precision P, template <typename, precision> class vecType>
GLM_FUNC_DECL vecType<uint, P> uaddCarry(
vecType<uint, P> const & x,
vecType<uint, P> const & y,
vecType<uint, P> & carry);
/// Subtracts the 32-bit unsigned integer y from x, returning
/// the difference if non-negative, or pow(2, 32) plus the difference
/// otherwise. The value borrow is set to 0 if x >= y, or to 1 otherwise.
///
/// @tparam genUType Unsigned integer scalar or vector types.
///
/// @see <a href="http://www.opengl.org/sdk/docs/manglsl/xhtml/usubBorrow.xml">GLSL usubBorrow man page</a>
/// @see <a href="http://www.opengl.org/registry/doc/GLSLangSpec.4.20.8.pdf">GLSL 4.20.8 specification, section 8.8 Integer Functions</a>
template <precision P, template <typename, precision> class vecType>
GLM_FUNC_DECL vecType<uint, P> usubBorrow(
vecType<uint, P> const & x,
vecType<uint, P> const & y,
vecType<uint, P> & borrow);
/// Multiplies 32-bit integers x and y, producing a 64-bit
/// result. The 32 least-significant bits are returned in lsb.
/// The 32 most-significant bits are returned in msb.
///
/// @tparam genUType Unsigned integer scalar or vector types.
///
/// @see <a href="http://www.opengl.org/sdk/docs/manglsl/xhtml/umulExtended.xml">GLSL umulExtended man page</a>
/// @see <a href="http://www.opengl.org/registry/doc/GLSLangSpec.4.20.8.pdf">GLSL 4.20.8 specification, section 8.8 Integer Functions</a>
template <precision P, template <typename, precision> class vecType>
GLM_FUNC_DECL void umulExtended(
vecType<uint, P> const & x,
vecType<uint, P> const & y,
vecType<uint, P> & msb,
vecType<uint, P> & lsb);
/// Multiplies 32-bit integers x and y, producing a 64-bit
/// result. The 32 least-significant bits are returned in lsb.
/// The 32 most-significant bits are returned in msb.
///
/// @tparam genIType Signed integer scalar or vector types.
///
/// @see <a href="http://www.opengl.org/sdk/docs/manglsl/xhtml/imulExtended.xml">GLSL imulExtended man page</a>
/// @see <a href="http://www.opengl.org/registry/doc/GLSLangSpec.4.20.8.pdf">GLSL 4.20.8 specification, section 8.8 Integer Functions</a>
template <precision P, template <typename, precision> class vecType>
GLM_FUNC_DECL void imulExtended(
vecType<int, P> const & x,
vecType<int, P> const & y,
vecType<int, P> & msb,
vecType<int, P> & lsb);
/// Extracts bits [offset, offset + bits - 1] from value,
/// returning them in the least significant bits of the result.
/// For unsigned data types, the most significant bits of the
/// result will be set to zero. For signed data types, the
/// most significant bits will be set to the value of bit offset + base - 1.
///
/// If bits is zero, the result will be zero. The result will be
/// undefined if offset or bits is negative, or if the sum of
/// offset and bits is greater than the number of bits used
/// to store the operand.
///
/// @tparam T Signed or unsigned integer scalar or vector types.
///
/// @see <a href="http://www.opengl.org/sdk/docs/manglsl/xhtml/bitfieldExtract.xml">GLSL bitfieldExtract man page</a>
/// @see <a href="http://www.opengl.org/registry/doc/GLSLangSpec.4.20.8.pdf">GLSL 4.20.8 specification, section 8.8 Integer Functions</a>
template <typename T, precision P, template <typename, precision> class vecType>
GLM_FUNC_DECL vecType<T, P> bitfieldExtract(
vecType<T, P> const & Value,
int Offset,
int Bits);
/// Returns the insertion the bits least-significant bits of insert into base.
///
/// The result will have bits [offset, offset + bits - 1] taken
/// from bits [0, bits - 1] of insert, and all other bits taken
/// directly from the corresponding bits of base. If bits is
/// zero, the result will simply be base. The result will be
/// undefined if offset or bits is negative, or if the sum of
/// offset and bits is greater than the number of bits used to
/// store the operand.
///
/// @tparam T Signed or unsigned integer scalar or vector types.
///
/// @see <a href="http://www.opengl.org/sdk/docs/manglsl/xhtml/bitfieldInsert.xml">GLSL bitfieldInsert man page</a>
/// @see <a href="http://www.opengl.org/registry/doc/GLSLangSpec.4.20.8.pdf">GLSL 4.20.8 specification, section 8.8 Integer Functions</a>
template <typename T, precision P, template <typename, precision> class vecType>
GLM_FUNC_DECL vecType<T, P> bitfieldInsert(
vecType<T, P> const & Base,
vecType<T, P> const & Insert,
int Offset,
int Bits);
/// Returns the reversal of the bits of value.
/// The bit numbered n of the result will be taken from bit (bits - 1) - n of value,
/// where bits is the total number of bits used to represent value.
///
/// @tparam T Signed or unsigned integer scalar or vector types.
///
/// @see <a href="http://www.opengl.org/sdk/docs/manglsl/xhtml/bitfieldReverse.xml">GLSL bitfieldReverse man page</a>
/// @see <a href="http://www.opengl.org/registry/doc/GLSLangSpec.4.20.8.pdf">GLSL 4.20.8 specification, section 8.8 Integer Functions</a>
template <typename T, precision P, template <typename, precision> class vecType>
GLM_FUNC_DECL vecType<T, P> bitfieldReverse(vecType<T, P> const & v);
/// Returns the number of bits set to 1 in the binary representation of value.
///
/// @tparam T Signed or unsigned integer scalar or vector types.
///
/// @see <a href="http://www.opengl.org/sdk/docs/manglsl/xhtml/bitCount.xml">GLSL bitCount man page</a>
/// @see <a href="http://www.opengl.org/registry/doc/GLSLangSpec.4.20.8.pdf">GLSL 4.20.8 specification, section 8.8 Integer Functions</a>
template <typename genType>
GLM_FUNC_DECL int bitCount(genType v);
/// Returns the number of bits set to 1 in the binary representation of value.
///
/// @tparam T Signed or unsigned integer scalar or vector types.
///
/// @see <a href="http://www.opengl.org/sdk/docs/manglsl/xhtml/bitCount.xml">GLSL bitCount man page</a>
/// @see <a href="http://www.opengl.org/registry/doc/GLSLangSpec.4.20.8.pdf">GLSL 4.20.8 specification, section 8.8 Integer Functions</a>
template <typename T, precision P, template <typename, precision> class vecType>
GLM_FUNC_DECL vecType<int, P> bitCount(vecType<T, P> const & v);
/// Returns the bit number of the least significant bit set to
/// 1 in the binary representation of value.
/// If value is zero, -1 will be returned.
///
/// @tparam T Signed or unsigned integer scalar types.
///
/// @see <a href="http://www.opengl.org/sdk/docs/manglsl/xhtml/findLSB.xml">GLSL findLSB man page</a>
/// @see <a href="http://www.opengl.org/registry/doc/GLSLangSpec.4.20.8.pdf">GLSL 4.20.8 specification, section 8.8 Integer Functions</a>
template <typename genIUType>
GLM_FUNC_DECL int findLSB(genIUType x);
/// Returns the bit number of the least significant bit set to
/// 1 in the binary representation of value.
/// If value is zero, -1 will be returned.
///
/// @tparam T Signed or unsigned integer scalar types.
///
/// @see <a href="http://www.opengl.org/sdk/docs/manglsl/xhtml/findLSB.xml">GLSL findLSB man page</a>
/// @see <a href="http://www.opengl.org/registry/doc/GLSLangSpec.4.20.8.pdf">GLSL 4.20.8 specification, section 8.8 Integer Functions</a>
template <typename T, precision P, template <typename, precision> class vecType>
GLM_FUNC_DECL vecType<int, P> findLSB(vecType<T, P> const & v);
/// Returns the bit number of the most significant bit in the binary representation of value.
/// For positive integers, the result will be the bit number of the most significant bit set to 1.
/// For negative integers, the result will be the bit number of the most significant
/// bit set to 0. For a value of zero or negative one, -1 will be returned.
///
/// @tparam T Signed or unsigned integer scalar types.
///
/// @see <a href="http://www.opengl.org/sdk/docs/manglsl/xhtml/findMSB.xml">GLSL findMSB man page</a>
/// @see <a href="http://www.opengl.org/registry/doc/GLSLangSpec.4.20.8.pdf">GLSL 4.20.8 specification, section 8.8 Integer Functions</a>
template <typename genIUType>
GLM_FUNC_DECL int findMSB(genIUType x);
/// Returns the bit number of the most significant bit in the binary representation of value.
/// For positive integers, the result will be the bit number of the most significant bit set to 1.
/// For negative integers, the result will be the bit number of the most significant
/// bit set to 0. For a value of zero or negative one, -1 will be returned.
///
/// @tparam T Signed or unsigned integer scalar types.
///
/// @see <a href="http://www.opengl.org/sdk/docs/manglsl/xhtml/findMSB.xml">GLSL findMSB man page</a>
/// @see <a href="http://www.opengl.org/registry/doc/GLSLangSpec.4.20.8.pdf">GLSL 4.20.8 specification, section 8.8 Integer Functions</a>
template <typename T, precision P, template <typename, precision> class vecType>
GLM_FUNC_DECL vecType<int, P> findMSB(vecType<T, P> const & v);
/// @}
}//namespace glm
#include "func_integer.inl"
///////////////////////////////////////////////////////////////////////////////////
/// OpenGL Mathematics (glm.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
/// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
/// copies of the Software, and to permit persons to whom the Software is
/// furnished to do so, subject to the following conditions:
///
/// 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
/// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
/// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
/// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
/// THE SOFTWARE.
///
/// @ref core
/// @file glm/detail/func_integer.inl
/// @date 2010-03-17 / 2011-06-15
/// @author Christophe Riccio
///////////////////////////////////////////////////////////////////////////////////
#include "type_vec2.hpp"
#include "type_vec3.hpp"
#include "type_vec4.hpp"
#include "type_int.hpp"
#include "_vectorize.hpp"
#if(GLM_ARCH != GLM_ARCH_PURE)
#if(GLM_COMPILER & GLM_COMPILER_VC)
# include <intrin.h>
# pragma intrinsic(_BitScanReverse)
#endif//(GLM_COMPILER & GLM_COMPILER_VC)
#endif//(GLM_ARCH != GLM_ARCH_PURE)
#include <limits>
namespace glm{
namespace detail
{
template <typename T>
GLM_FUNC_QUALIFIER T mask(T Bits)
{
return Bits >= sizeof(T) * 8 ? ~static_cast<T>(0) : (static_cast<T>(1) << Bits) - static_cast<T>(1);
}
template <bool EXEC = false>
struct compute_bitfieldReverseStep
{
template <typename T, glm::precision P, template <class, glm::precision> class vecType>
GLM_FUNC_QUALIFIER static vecType<T, P> call(vecType<T, P> const & v, T, T)
{
return v;
}
};
template <>
struct compute_bitfieldReverseStep<true>
{
template <typename T, glm::precision P, template <class, glm::precision> class vecType>
GLM_FUNC_QUALIFIER static vecType<T, P> call(vecType<T, P> const & v, T Mask, T Shift)
{
return (v & Mask) << Shift | (v & (~Mask)) >> Shift;
}
};
template <bool EXEC = false>
struct compute_bitfieldBitCountStep
{
template <typename T, glm::precision P, template <class, glm::precision> class vecType>
GLM_FUNC_QUALIFIER static vecType<T, P> call(vecType<T, P> const & v, T, T)
{
return v;
}
};
template <>
struct compute_bitfieldBitCountStep<true>
{
template <typename T, glm::precision P, template <class, glm::precision> class vecType>
GLM_FUNC_QUALIFIER static vecType<T, P> call(vecType<T, P> const & v, T Mask, T Shift)
{
return (v & Mask) + ((v >> Shift) & Mask);
}
};
template <typename genIUType, size_t Bits>
struct compute_findLSB
{
GLM_FUNC_QUALIFIER static int call(genIUType Value)
{
if(Value == 0)
return -1;
return glm::bitCount(~Value & (Value - static_cast<genIUType>(1)));
}
};
# if GLM_HAS_BITSCAN_WINDOWS
template <typename genIUType>
struct compute_findLSB<genIUType, 32>
{
GLM_FUNC_QUALIFIER static int call(genIUType Value)
{
unsigned long Result(0);
unsigned char IsNotNull = _BitScanForward(&Result, *reinterpret_cast<unsigned long*>(&Value));
return IsNotNull ? int(Result) : -1;
}
};
# if !((GLM_COMPILER & GLM_COMPILER_VC) && (GLM_MODEL == GLM_MODEL_32))
template <typename genIUType>
struct compute_findLSB<genIUType, 64>
{
GLM_FUNC_QUALIFIER static int call(genIUType Value)
{
unsigned long Result(0);
unsigned char IsNotNull = _BitScanForward64(&Result, *reinterpret_cast<unsigned __int64*>(&Value));
return IsNotNull ? int(Result) : -1;
}
};
# endif
# endif//GLM_HAS_BITSCAN_WINDOWS
template <typename T, glm::precision P, template <class, glm::precision> class vecType, bool EXEC = true>
struct compute_findMSB_step_vec
{
GLM_FUNC_QUALIFIER static vecType<T, P> call(vecType<T, P> const & x, T Shift)
{
return x | (x >> Shift);
}
};
template <typename T, glm::precision P, template <typename, glm::precision> class vecType>
struct compute_findMSB_step_vec<T, P, vecType, false>
{
GLM_FUNC_QUALIFIER static vecType<T, P> call(vecType<T, P> const & x, T)
{
return x;
}
};
template <typename T, glm::precision P, template <typename, glm::precision> class vecType, int>
struct compute_findMSB_vec
{
GLM_FUNC_QUALIFIER static vecType<int, P> call(vecType<T, P> const & vec)
{
vecType<T, P> x(vec);
x = compute_findMSB_step_vec<T, P, vecType, sizeof(T) * 8 >= 8>::call(x, static_cast<T>( 1));
x = compute_findMSB_step_vec<T, P, vecType, sizeof(T) * 8 >= 8>::call(x, static_cast<T>( 2));
x = compute_findMSB_step_vec<T, P, vecType, sizeof(T) * 8 >= 8>::call(x, static_cast<T>( 4));
x = compute_findMSB_step_vec<T, P, vecType, sizeof(T) * 8 >= 16>::call(x, static_cast<T>( 8));
x = compute_findMSB_step_vec<T, P, vecType, sizeof(T) * 8 >= 32>::call(x, static_cast<T>(16));
x = compute_findMSB_step_vec<T, P, vecType, sizeof(T) * 8 >= 64>::call(x, static_cast<T>(32));
return vecType<int, P>(sizeof(T) * 8 - 1) - glm::bitCount(~x);
}
};
# if GLM_HAS_BITSCAN_WINDOWS
template <typename genIUType>
GLM_FUNC_QUALIFIER int compute_findMSB_32(genIUType Value)
{
unsigned long Result(0);
unsigned char IsNotNull = _BitScanReverse(&Result, *reinterpret_cast<unsigned long*>(&Value));
return IsNotNull ? int(Result) : -1;
}
template <typename T, glm::precision P, template <class, glm::precision> class vecType>
struct compute_findMSB_vec<T, P, vecType, 32>
{
GLM_FUNC_QUALIFIER static vecType<int, P> call(vecType<T, P> const & x)
{
return detail::functor1<int, T, P, vecType>::call(compute_findMSB_32, x);
}
};
# if !((GLM_COMPILER & GLM_COMPILER_VC) && (GLM_MODEL == GLM_MODEL_32))
template <typename genIUType>
GLM_FUNC_QUALIFIER int compute_findMSB_64(genIUType Value)
{
unsigned long Result(0);
unsigned char IsNotNull = _BitScanReverse64(&Result, *reinterpret_cast<unsigned __int64*>(&Value));
return IsNotNull ? int(Result) : -1;
}
template <typename T, glm::precision P, template <class, glm::precision> class vecType>
struct compute_findMSB_vec<T, P, vecType, 64>
{
GLM_FUNC_QUALIFIER static vecType<int, P> call(vecType<T, P> const & x)
{
return detail::functor1<int, T, P, vecType>::call(compute_findMSB_64, x);
}
};
# endif
# endif//GLM_HAS_BITSCAN_WINDOWS
}//namespace detail
// uaddCarry
GLM_FUNC_QUALIFIER uint uaddCarry(uint const & x, uint const & y, uint & Carry)
{
uint64 const Value64(static_cast<uint64>(x) + static_cast<uint64>(y));
uint64 const Max32((static_cast<uint64>(1) << static_cast<uint64>(32)) - static_cast<uint64>(1));
Carry = Value64 > Max32 ? 1 : 0;
return static_cast<uint32>(Value64 % (Max32 + static_cast<uint64>(1)));
}
template <precision P, template <typename, precision> class vecType>
GLM_FUNC_QUALIFIER vecType<uint, P> uaddCarry(vecType<uint, P> const & x, vecType<uint, P> const & y, vecType<uint, P> & Carry)
{
vecType<uint64, P> Value64(vecType<uint64, P>(x) + vecType<uint64, P>(y));
vecType<uint64, P> Max32((static_cast<uint64>(1) << static_cast<uint64>(32)) - static_cast<uint64>(1));
Carry = mix(vecType<uint32, P>(0), vecType<uint32, P>(1), greaterThan(Value64, Max32));
return vecType<uint32,P>(Value64 % (Max32 + static_cast<uint64>(1)));
}
// usubBorrow
GLM_FUNC_QUALIFIER uint usubBorrow(uint const & x, uint const & y, uint & Borrow)
{
GLM_STATIC_ASSERT(sizeof(uint) == sizeof(uint32), "uint and uint32 size mismatch");
Borrow = x >= y ? static_cast<uint32>(0) : static_cast<uint32>(1);
if(y >= x)
return y - x;
else
return static_cast<uint32>((static_cast<int64>(1) << static_cast<int64>(32)) + (static_cast<int64>(y) - static_cast<int64>(x)));
}
template <precision P, template <typename, precision> class vecType>
GLM_FUNC_QUALIFIER vecType<uint, P> usubBorrow(vecType<uint, P> const & x, vecType<uint, P> const & y, vecType<uint, P> & Borrow)
{
Borrow = mix(vecType<uint, P>(1), vecType<uint, P>(0), greaterThanEqual(x, y));
vecType<uint, P> const YgeX(y - x);
vecType<uint, P> const XgeY(vecType<uint32, P>((static_cast<int64>(1) << static_cast<int64>(32)) + (vecType<int64, P>(y) - vecType<int64, P>(x))));
return mix(XgeY, YgeX, greaterThanEqual(y, x));
}
// umulExtended
GLM_FUNC_QUALIFIER void umulExtended(uint const & x, uint const & y, uint & msb, uint & lsb)
{
GLM_STATIC_ASSERT(sizeof(uint) == sizeof(uint32), "uint and uint32 size mismatch");
uint64 Value64 = static_cast<uint64>(x) * static_cast<uint64>(y);
uint32* PointerMSB = (reinterpret_cast<uint32*>(&Value64) + 1);
msb = *PointerMSB;
uint32* PointerLSB = (reinterpret_cast<uint32*>(&Value64) + 0);
lsb = *PointerLSB;
}
template <precision P, template <typename, precision> class vecType>
GLM_FUNC_QUALIFIER void umulExtended(vecType<uint, P> const & x, vecType<uint, P> const & y, vecType<uint, P> & msb, vecType<uint, P> & lsb)
{
GLM_STATIC_ASSERT(sizeof(uint) == sizeof(uint32), "uint and uint32 size mismatch");
vecType<uint64, P> Value64(vecType<uint64, P>(x) * vecType<uint64, P>(y));
msb = vecType<uint32, P>(Value64 >> static_cast<uint64>(32));
lsb = vecType<uint32, P>(Value64);
}
// imulExtended
GLM_FUNC_QUALIFIER void imulExtended(int x, int y, int & msb, int & lsb)
{
GLM_STATIC_ASSERT(sizeof(int) == sizeof(int32), "int and int32 size mismatch");
int64 Value64 = static_cast<int64>(x) * static_cast<int64>(y);
int32* PointerMSB = (reinterpret_cast<int32*>(&Value64) + 1);
msb = *PointerMSB;
int32* PointerLSB = (reinterpret_cast<int32*>(&Value64));
lsb = *PointerLSB;
}
template <precision P, template <typename, precision> class vecType>
GLM_FUNC_QUALIFIER void imulExtended(vecType<int, P> const & x, vecType<int, P> const & y, vecType<int, P> & msb, vecType<int, P> & lsb)
{
GLM_STATIC_ASSERT(sizeof(int) == sizeof(int32), "int and int32 size mismatch");
vecType<int64, P> Value64(vecType<int64, P>(x) * vecType<int64, P>(y));
lsb = vecType<int32, P>(Value64 & static_cast<int64>(0xFFFFFFFF));
msb = vecType<int32, P>((Value64 >> static_cast<int64>(32)) & static_cast<int64>(0xFFFFFFFF));
}
// bitfieldExtract
template <typename genIUType>
GLM_FUNC_QUALIFIER genIUType bitfieldExtract(genIUType Value, int Offset, int Bits)
{
return bitfieldExtract(tvec1<genIUType>(Value), Offset, Bits).x;
}
template <typename T, precision P, template <typename, precision> class vecType>
GLM_FUNC_QUALIFIER vecType<T, P> bitfieldExtract(vecType<T, P> const & Value, int Offset, int Bits)
{
GLM_STATIC_ASSERT(std::numeric_limits<T>::is_integer, "'bitfieldExtract' only accept integer inputs");
return (Value >> static_cast<T>(Offset)) & static_cast<T>(detail::mask(Bits));
}
// bitfieldInsert
template <typename genIUType>
GLM_FUNC_QUALIFIER genIUType bitfieldInsert(genIUType const & Base, genIUType const & Insert, int Offset, int Bits)
{
return bitfieldInsert(tvec1<genIUType>(Base), tvec1<genIUType>(Insert), Offset, Bits).x;
}
template <typename T, precision P, template <typename, precision> class vecType>
GLM_FUNC_QUALIFIER vecType<T, P> bitfieldInsert(vecType<T, P> const & Base, vecType<T, P> const & Insert, int Offset, int Bits)
{
GLM_STATIC_ASSERT(std::numeric_limits<T>::is_integer, "'bitfieldInsert' only accept integer values");
T const Mask = static_cast<T>(detail::mask(Bits) << Offset);
return (Base & ~Mask) | (Insert & Mask);
}
// bitfieldReverse
template <typename genType>
GLM_FUNC_QUALIFIER genType bitfieldReverse(genType x)
{
return bitfieldReverse(glm::tvec1<genType, glm::defaultp>(x)).x;
}
template <typename T, glm::precision P, template <typename, glm::precision> class vecType>
GLM_FUNC_QUALIFIER vecType<T, P> bitfieldReverse(vecType<T, P> const & v)
{
vecType<T, P> x(v);
x = detail::compute_bitfieldReverseStep<sizeof(T) * 8 >= 2>::call(x, T(0x5555555555555555ull), static_cast<T>( 1));
x = detail::compute_bitfieldReverseStep<sizeof(T) * 8 >= 4>::call(x, T(0x3333333333333333ull), static_cast<T>( 2));
x = detail::compute_bitfieldReverseStep<sizeof(T) * 8 >= 8>::call(x, T(0x0F0F0F0F0F0F0F0Full), static_cast<T>( 4));
x = detail::compute_bitfieldReverseStep<sizeof(T) * 8 >= 16>::call(x, T(0x00FF00FF00FF00FFull), static_cast<T>( 8));
x = detail::compute_bitfieldReverseStep<sizeof(T) * 8 >= 32>::call(x, T(0x0000FFFF0000FFFFull), static_cast<T>(16));
x = detail::compute_bitfieldReverseStep<sizeof(T) * 8 >= 64>::call(x, T(0x00000000FFFFFFFFull), static_cast<T>(32));
return x;
}
// bitCount
template <typename genType>
GLM_FUNC_QUALIFIER int bitCount(genType x)
{
return bitCount(glm::tvec1<genType, glm::defaultp>(x)).x;
}
template <typename T, glm::precision P, template <typename, glm::precision> class vecType>
GLM_FUNC_QUALIFIER vecType<int, P> bitCount(vecType<T, P> const & v)
{
vecType<typename detail::make_unsigned<T>::type, P> x(*reinterpret_cast<vecType<typename detail::make_unsigned<T>::type, P> const *>(&v));
x = detail::compute_bitfieldBitCountStep<sizeof(T) * 8 >= 2>::call(x, typename detail::make_unsigned<T>::type(0x5555555555555555ull), typename detail::make_unsigned<T>::type( 1));
x = detail::compute_bitfieldBitCountStep<sizeof(T) * 8 >= 4>::call(x, typename detail::make_unsigned<T>::type(0x3333333333333333ull), typename detail::make_unsigned<T>::type( 2));
x = detail::compute_bitfieldBitCountStep<sizeof(T) * 8 >= 8>::call(x, typename detail::make_unsigned<T>::type(0x0F0F0F0F0F0F0F0Full), typename detail::make_unsigned<T>::type( 4));
x = detail::compute_bitfieldBitCountStep<sizeof(T) * 8 >= 16>::call(x, typename detail::make_unsigned<T>::type(0x00FF00FF00FF00FFull), typename detail::make_unsigned<T>::type( 8));
x = detail::compute_bitfieldBitCountStep<sizeof(T) * 8 >= 32>::call(x, typename detail::make_unsigned<T>::type(0x0000FFFF0000FFFFull), typename detail::make_unsigned<T>::type(16));
x = detail::compute_bitfieldBitCountStep<sizeof(T) * 8 >= 64>::call(x, typename detail::make_unsigned<T>::type(0x00000000FFFFFFFFull), typename detail::make_unsigned<T>::type(32));
return vecType<int, P>(x);
}
// findLSB
template <typename genIUType>
GLM_FUNC_QUALIFIER int findLSB(genIUType Value)
{
GLM_STATIC_ASSERT(std::numeric_limits<genIUType>::is_integer, "'findLSB' only accept integer values");
return detail::compute_findLSB<genIUType, sizeof(genIUType) * 8>::call(Value);
}
template <typename T, precision P, template <typename, precision> class vecType>
GLM_FUNC_QUALIFIER vecType<int, P> findLSB(vecType<T, P> const & x)
{
GLM_STATIC_ASSERT(std::numeric_limits<T>::is_integer, "'findLSB' only accept integer values");
return detail::functor1<int, T, P, vecType>::call(findLSB, x);
}
// findMSB
template <typename genIUType>
GLM_FUNC_QUALIFIER int findMSB(genIUType x)
{
GLM_STATIC_ASSERT(std::numeric_limits<genIUType>::is_integer, "'findMSB' only accept integer values");
return findMSB(tvec1<genIUType>(x)).x;
}
template <typename T, precision P, template <typename, precision> class vecType>
GLM_FUNC_QUALIFIER vecType<int, P> findMSB(vecType<T, P> const & x)
{
GLM_STATIC_ASSERT(std::numeric_limits<T>::is_integer, "'findMSB' only accept integer values");
return detail::compute_findMSB_vec<T, P, vecType, sizeof(T) * 8>::call(x);
}
}//namespace glm
///////////////////////////////////////////////////////////////////////////////////
/// OpenGL Mathematics (glm.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
/// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
/// copies of the Software, and to permit persons to whom the Software is
/// furnished to do so, subject to the following conditions:
///
/// 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
/// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
/// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
/// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
/// THE SOFTWARE.
///
/// @ref core
/// @file glm/detail/func_matrix.hpp
/// @date 2008-08-03 / 2011-06-15
/// @author Christophe Riccio
///
/// @see <a href="http://www.opengl.org/registry/doc/GLSLangSpec.4.20.8.pdf">GLSL 4.20.8 specification, section 8.6 Matrix Functions</a>
///
/// @defgroup core_func_matrix Matrix functions
/// @ingroup core
///
/// For each of the following built-in matrix functions, there is both a
/// single-precision floating point version, where all arguments and return values
/// are single precision, and a double-precision floating version, where all
/// arguments and return values are double precision. Only the single-precision
/// floating point version is shown.
///////////////////////////////////////////////////////////////////////////////////
#pragma once
// Dependencies
#include "../detail/precision.hpp"
#include "../detail/setup.hpp"
#include "../detail/type_mat.hpp"
#include "../vec2.hpp"
#include "../vec3.hpp"
#include "../vec4.hpp"
#include "../mat2x2.hpp"
#include "../mat2x3.hpp"
#include "../mat2x4.hpp"
#include "../mat3x2.hpp"
#include "../mat3x3.hpp"
#include "../mat3x4.hpp"
#include "../mat4x2.hpp"
#include "../mat4x3.hpp"
#include "../mat4x4.hpp"
namespace glm{
namespace detail
{
template <typename T, precision P>
struct outerProduct_trait<T, P, tvec2, tvec2>
{
typedef tmat2x2<T, P> type;
};
template <typename T, precision P>
struct outerProduct_trait<T, P, tvec2, tvec3>
{
typedef tmat2x3<T, P> type;
};
template <typename T, precision P>
struct outerProduct_trait<T, P, tvec2, tvec4>
{
typedef tmat2x4<T, P> type;
};
template <typename T, precision P>
struct outerProduct_trait<T, P, tvec3, tvec2>
{
typedef tmat3x2<T, P> type;
};
template <typename T, precision P>
struct outerProduct_trait<T, P, tvec3, tvec3>
{
typedef tmat3x3<T, P> type;
};
template <typename T, precision P>
struct outerProduct_trait<T, P, tvec3, tvec4>
{
typedef tmat3x4<T, P> type;
};
template <typename T, precision P>
struct outerProduct_trait<T, P, tvec4, tvec2>
{
typedef tmat4x2<T, P> type;
};
template <typename T, precision P>
struct outerProduct_trait<T, P, tvec4, tvec3>
{
typedef tmat4x3<T, P> type;
};
template <typename T, precision P>
struct outerProduct_trait<T, P, tvec4, tvec4>
{
typedef tmat4x4<T, P> type;
};
}//namespace detail
/// @addtogroup core_func_matrix
/// @{
/// Multiply matrix x by matrix y component-wise, i.e.,
/// result[i][j] is the scalar product of x[i][j] and y[i][j].
///
/// @tparam matType Floating-point matrix types.
///
/// @see <a href="http://www.opengl.org/sdk/docs/manglsl/xhtml/matrixCompMult.xml">GLSL matrixCompMult man page</a>
/// @see <a href="http://www.opengl.org/registry/doc/GLSLangSpec.4.20.8.pdf">GLSL 4.20.8 specification, section 8.6 Matrix Functions</a>
template <typename T, precision P, template <typename, precision> class matType>
GLM_FUNC_DECL matType<T, P> matrixCompMult(matType<T, P> const & x, matType<T, P> const & y);
/// Treats the first parameter c as a column vector
/// and the second parameter r as a row vector
/// and does a linear algebraic matrix multiply c * r.
///
/// @tparam matType Floating-point matrix types.
///
/// @see <a href="http://www.opengl.org/sdk/docs/manglsl/xhtml/outerProduct.xml">GLSL outerProduct man page</a>
/// @see <a href="http://www.opengl.org/registry/doc/GLSLangSpec.4.20.8.pdf">GLSL 4.20.8 specification, section 8.6 Matrix Functions</a>
template <typename T, precision P, template <typename, precision> class vecTypeA, template <typename, precision> class vecTypeB>
GLM_FUNC_DECL typename detail::outerProduct_trait<T, P, vecTypeA, vecTypeB>::type outerProduct(vecTypeA<T, P> const & c, vecTypeB<T, P> const & r);
/// Returns the transposed matrix of x
///
/// @tparam matType Floating-point matrix types.
///
/// @see <a href="http://www.opengl.org/sdk/docs/manglsl/xhtml/transpose.xml">GLSL transpose man page</a>
/// @see <a href="http://www.opengl.org/registry/doc/GLSLangSpec.4.20.8.pdf">GLSL 4.20.8 specification, section 8.6 Matrix Functions</a>
# if((GLM_COMPILER & GLM_COMPILER_VC) && (GLM_COMPILER >= GLM_COMPILER_VC2012))
template <typename T, precision P, template <typename, precision> class matType>
GLM_FUNC_DECL typename matType<T, P>::transpose_type transpose(matType<T, P> const & x);
# endif
/// Return the determinant of a squared matrix.
///
/// @tparam valType Floating-point scalar types.
///
/// @see <a href="http://www.opengl.org/sdk/docs/manglsl/xhtml/determinant.xml">GLSL determinant man page</a>
/// @see <a href="http://www.opengl.org/registry/doc/GLSLangSpec.4.20.8.pdf">GLSL 4.20.8 specification, section 8.6 Matrix Functions</a>
template <typename T, precision P, template <typename, precision> class matType>
GLM_FUNC_DECL T determinant(matType<T, P> const & m);
/// Return the inverse of a squared matrix.
///
/// @tparam valType Floating-point scalar types.
///
/// @see <a href="http://www.opengl.org/sdk/docs/manglsl/xhtml/inverse.xml">GLSL inverse man page</a>
/// @see <a href="http://www.opengl.org/registry/doc/GLSLangSpec.4.20.8.pdf">GLSL 4.20.8 specification, section 8.6 Matrix Functions</a>
template <typename T, precision P, template <typename, precision> class matType>
GLM_FUNC_DECL matType<T, P> inverse(matType<T, P> const & m);
/// @}
}//namespace glm
#include "func_matrix.inl"
///////////////////////////////////////////////////////////////////////////////////
/// OpenGL Mathematics (glm.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
/// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
/// copies of the Software, and to permit persons to whom the Software is
/// furnished to do so, subject to the following conditions:
///
/// 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
/// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
/// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
/// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
/// THE SOFTWARE.
///
/// @ref core
/// @file glm/detail/func_matrix.inl
/// @date 2008-03-08 / 2011-06-15
/// @author Christophe Riccio
///////////////////////////////////////////////////////////////////////////////////
#include "../geometric.hpp"
#include <limits>
namespace glm{
namespace detail
{
template <template <class, precision> class matType, typename T, precision P>
struct compute_transpose{};
template <typename T, precision P>
struct compute_transpose<tmat2x2, T, P>
{
GLM_FUNC_QUALIFIER static tmat2x2<T, P> call(tmat2x2<T, P> const & m)
{
tmat2x2<T, P> result(uninitialize);
result[0][0] = m[0][0];
result[0][1] = m[1][0];
result[1][0] = m[0][1];
result[1][1] = m[1][1];
return result;
}
};
template <typename T, precision P>
struct compute_transpose<tmat2x3, T, P>
{
GLM_FUNC_QUALIFIER static tmat3x2<T, P> call(tmat2x3<T, P> const & m)
{
tmat3x2<T, P> result(uninitialize);
result[0][0] = m[0][0];
result[0][1] = m[1][0];
result[1][0] = m[0][1];
result[1][1] = m[1][1];
result[2][0] = m[0][2];
result[2][1] = m[1][2];
return result;
}
};
template <typename T, precision P>
struct compute_transpose<tmat2x4, T, P>
{
GLM_FUNC_QUALIFIER static tmat4x2<T, P> call(tmat2x4<T, P> const & m)
{
tmat4x2<T, P> result(uninitialize);
result[0][0] = m[0][0];
result[0][1] = m[1][0];
result[1][0] = m[0][1];
result[1][1] = m[1][1];
result[2][0] = m[0][2];
result[2][1] = m[1][2];
result[3][0] = m[0][3];
result[3][1] = m[1][3];
return result;
}
};
template <typename T, precision P>
struct compute_transpose<tmat3x2, T, P>
{
GLM_FUNC_QUALIFIER static tmat2x3<T, P> call(tmat3x2<T, P> const & m)
{
tmat2x3<T, P> result(uninitialize);
result[0][0] = m[0][0];
result[0][1] = m[1][0];
result[0][2] = m[2][0];
result[1][0] = m[0][1];
result[1][1] = m[1][1];
result[1][2] = m[2][1];
return result;
}
};
template <typename T, precision P>
struct compute_transpose<tmat3x3, T, P>
{
GLM_FUNC_QUALIFIER static tmat3x3<T, P> call(tmat3x3<T, P> const & m)
{
tmat3x3<T, P> result(uninitialize);
result[0][0] = m[0][0];
result[0][1] = m[1][0];
result[0][2] = m[2][0];
result[1][0] = m[0][1];
result[1][1] = m[1][1];
result[1][2] = m[2][1];
result[2][0] = m[0][2];
result[2][1] = m[1][2];
result[2][2] = m[2][2];
return result;
}
};
template <typename T, precision P>
struct compute_transpose<tmat3x4, T, P>
{
GLM_FUNC_QUALIFIER static tmat4x3<T, P> call(tmat3x4<T, P> const & m)
{
tmat4x3<T, P> result(uninitialize);
result[0][0] = m[0][0];
result[0][1] = m[1][0];
result[0][2] = m[2][0];
result[1][0] = m[0][1];
result[1][1] = m[1][1];
result[1][2] = m[2][1];
result[2][0] = m[0][2];
result[2][1] = m[1][2];
result[2][2] = m[2][2];
result[3][0] = m[0][3];
result[3][1] = m[1][3];
result[3][2] = m[2][3];
return result;
}
};
template <typename T, precision P>
struct compute_transpose<tmat4x2, T, P>
{
GLM_FUNC_QUALIFIER static tmat2x4<T, P> call(tmat4x2<T, P> const & m)
{
tmat2x4<T, P> result(uninitialize);
result[0][0] = m[0][0];
result[0][1] = m[1][0];
result[0][2] = m[2][0];
result[0][3] = m[3][0];
result[1][0] = m[0][1];
result[1][1] = m[1][1];
result[1][2] = m[2][1];
result[1][3] = m[3][1];
return result;
}
};
template <typename T, precision P>
struct compute_transpose<tmat4x3, T, P>
{
GLM_FUNC_QUALIFIER static tmat3x4<T, P> call(tmat4x3<T, P> const & m)
{
tmat3x4<T, P> result(uninitialize);
result[0][0] = m[0][0];
result[0][1] = m[1][0];
result[0][2] = m[2][0];
result[0][3] = m[3][0];
result[1][0] = m[0][1];
result[1][1] = m[1][1];
result[1][2] = m[2][1];
result[1][3] = m[3][1];
result[2][0] = m[0][2];
result[2][1] = m[1][2];
result[2][2] = m[2][2];
result[2][3] = m[3][2];
return result;
}
};
template <typename T, precision P>
struct compute_transpose<tmat4x4, T, P>
{
GLM_FUNC_QUALIFIER static tmat4x4<T, P> call(tmat4x4<T, P> const & m)
{
tmat4x4<T, P> result(uninitialize);
result[0][0] = m[0][0];
result[0][1] = m[1][0];
result[0][2] = m[2][0];
result[0][3] = m[3][0];
result[1][0] = m[0][1];
result[1][1] = m[1][1];
result[1][2] = m[2][1];
result[1][3] = m[3][1];
result[2][0] = m[0][2];
result[2][1] = m[1][2];
result[2][2] = m[2][2];
result[2][3] = m[3][2];
result[3][0] = m[0][3];
result[3][1] = m[1][3];
result[3][2] = m[2][3];
result[3][3] = m[3][3];
return result;
}
};
template <template <class, precision> class matType, typename T, precision P>
struct compute_determinant{};
template <typename T, precision P>
struct compute_determinant<tmat2x2, T, P>
{
GLM_FUNC_QUALIFIER static T call(tmat2x2<T, P> const & m)
{
return m[0][0] * m[1][1] - m[1][0] * m[0][1];
}
};
template <typename T, precision P>
struct compute_determinant<tmat3x3, T, P>
{
GLM_FUNC_QUALIFIER static T call(tmat3x3<T, P> const & m)
{
return
+ m[0][0] * (m[1][1] * m[2][2] - m[2][1] * m[1][2])
- m[1][0] * (m[0][1] * m[2][2] - m[2][1] * m[0][2])
+ m[2][0] * (m[0][1] * m[1][2] - m[1][1] * m[0][2]);
}
};
template <typename T, precision P>
struct compute_determinant<tmat4x4, T, P>
{
GLM_FUNC_QUALIFIER static T call(tmat4x4<T, P> const & m)
{
T SubFactor00 = m[2][2] * m[3][3] - m[3][2] * m[2][3];
T SubFactor01 = m[2][1] * m[3][3] - m[3][1] * m[2][3];
T SubFactor02 = m[2][1] * m[3][2] - m[3][1] * m[2][2];
T SubFactor03 = m[2][0] * m[3][3] - m[3][0] * m[2][3];
T SubFactor04 = m[2][0] * m[3][2] - m[3][0] * m[2][2];
T SubFactor05 = m[2][0] * m[3][1] - m[3][0] * m[2][1];
tvec4<T, P> DetCof(
+ (m[1][1] * SubFactor00 - m[1][2] * SubFactor01 + m[1][3] * SubFactor02),
- (m[1][0] * SubFactor00 - m[1][2] * SubFactor03 + m[1][3] * SubFactor04),
+ (m[1][0] * SubFactor01 - m[1][1] * SubFactor03 + m[1][3] * SubFactor05),
- (m[1][0] * SubFactor02 - m[1][1] * SubFactor04 + m[1][2] * SubFactor05));
return
m[0][0] * DetCof[0] + m[0][1] * DetCof[1] +
m[0][2] * DetCof[2] + m[0][3] * DetCof[3];
}
};
}//namespace detail
template <typename T, precision P, template <typename, precision> class matType>
GLM_FUNC_QUALIFIER matType<T, P> matrixCompMult(matType<T, P> const & x, matType<T, P> const & y)
{
GLM_STATIC_ASSERT(std::numeric_limits<T>::is_iec559, "'matrixCompMult' only accept floating-point inputs");
matType<T, P> result(uninitialize);
for(detail::component_count_t i = 0; i < detail::component_count(result); ++i)
result[i] = x[i] * y[i];
return result;
}
template<typename T, precision P, template <typename, precision> class vecTypeA, template <typename, precision> class vecTypeB>
GLM_FUNC_QUALIFIER typename detail::outerProduct_trait<T, P, vecTypeA, vecTypeB>::type outerProduct(vecTypeA<T, P> const & c, vecTypeB<T, P> const & r)
{
GLM_STATIC_ASSERT(std::numeric_limits<T>::is_iec559, "'outerProduct' only accept floating-point inputs");
typename detail::outerProduct_trait<T, P, vecTypeA, vecTypeB>::type m(uninitialize);
for(detail::component_count_t i = 0; i < detail::component_count(m); ++i)
m[i] = c * r[i];
return m;
}
template <typename T, precision P, template <typename, precision> class matType>
GLM_FUNC_QUALIFIER typename matType<T, P>::transpose_type transpose(matType<T, P> const & m)
{
GLM_STATIC_ASSERT(std::numeric_limits<T>::is_iec559, "'transpose' only accept floating-point inputs");
return detail::compute_transpose<matType, T, P>::call(m);
}
template <typename T, precision P, template <typename, precision> class matType>
GLM_FUNC_QUALIFIER T determinant(matType<T, P> const & m)
{
GLM_STATIC_ASSERT(std::numeric_limits<T>::is_iec559, "'determinant' only accept floating-point inputs");
return detail::compute_determinant<matType, T, P>::call(m);
}
template <typename T, precision P, template <typename, precision> class matType>
GLM_FUNC_QUALIFIER matType<T, P> inverse(matType<T, P> const & m)
{
GLM_STATIC_ASSERT(std::numeric_limits<T>::is_iec559, "'inverse' only accept floating-point inputs");
return detail::compute_inverse(m);
}
}//namespace glm
///////////////////////////////////////////////////////////////////////////////////
/// OpenGL Mathematics (glm.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
/// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
/// copies of the Software, and to permit persons to whom the Software is
/// furnished to do so, subject to the following conditions:
///
/// 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
/// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
/// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
/// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
/// THE SOFTWARE.
///
/// @ref core
/// @file glm/detail/func_noise.hpp
/// @date 2008-08-01 / 2011-06-18
/// @author Christophe Riccio
///
/// @see <a href="http://www.opengl.org/registry/doc/GLSLangSpec.4.20.8.pdf">GLSL 4.20.8 specification, section 8.13 Noise Functions</a>
///
/// @defgroup core_func_noise Noise functions
/// @ingroup core
///
/// Noise functions are stochastic functions that can be used to increase visual
/// complexity. Values returned by the following noise functions give the
/// appearance of randomness, but are not truly random.
///////////////////////////////////////////////////////////////////////////////////
#pragma once
#include "type_vec1.hpp"
#include "type_vec2.hpp"
#include "type_vec3.hpp"
#include "setup.hpp"
namespace glm
{
/// @addtogroup core_func_noise
/// @{
/// Returns a 1D noise value based on the input value x.
///
/// @tparam genType Floating-point scalar or vector types.
///
/// @see <a href="http://www.opengl.org/sdk/docs/manglsl/xhtml/noise1.xml">GLSL noise1 man page</a>
/// @see <a href="http://www.opengl.org/registry/doc/GLSLangSpec.4.20.8.pdf">GLSL 4.20.8 specification, section 8.13 Noise Functions</a>
template <typename genType>
GLM_FUNC_DECL typename genType::value_type noise1(genType const & x);
/// Returns a 2D noise value based on the input value x.
///
/// @tparam genType Floating-point scalar or vector types.
///
/// @see <a href="http://www.opengl.org/sdk/docs/manglsl/xhtml/noise2.xml">GLSL noise2 man page</a>
/// @see <a href="http://www.opengl.org/registry/doc/GLSLangSpec.4.20.8.pdf">GLSL 4.20.8 specification, section 8.13 Noise Functions</a>
template <typename genType>
GLM_FUNC_DECL tvec2<typename genType::value_type, defaultp> noise2(genType const & x);
/// Returns a 3D noise value based on the input value x.
///
/// @tparam genType Floating-point scalar or vector types.
///
/// @see <a href="http://www.opengl.org/sdk/docs/manglsl/xhtml/noise3.xml">GLSL noise3 man page</a>
/// @see <a href="http://www.opengl.org/registry/doc/GLSLangSpec.4.20.8.pdf">GLSL 4.20.8 specification, section 8.13 Noise Functions</a>
template <typename genType>
GLM_FUNC_DECL tvec3<typename genType::value_type, defaultp> noise3(genType const & x);
/// Returns a 4D noise value based on the input value x.
///
/// @tparam genType Floating-point scalar or vector types.
///
/// @see <a href="http://www.opengl.org/sdk/docs/manglsl/xhtml/noise4.xml">GLSL noise4 man page</a>
/// @see <a href="http://www.opengl.org/registry/doc/GLSLangSpec.4.20.8.pdf">GLSL 4.20.8 specification, section 8.13 Noise Functions</a>
template <typename genType>
GLM_FUNC_DECL tvec4<typename genType::value_type, defaultp> noise4(genType const & x);
/// @}
}//namespace glm
#include "func_noise.inl"
///////////////////////////////////////////////////////////////////////////////////
/// OpenGL Mathematics (glm.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
/// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
/// copies of the Software, and to permit persons to whom the Software is
/// furnished to do so, subject to the following conditions:
///
/// 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
/// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
/// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
/// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
/// THE SOFTWARE.
///
/// @ref core
/// @file glm/detail/func_noise.inl
/// @date 2008-08-01 / 2011-09-27
/// @author Christophe Riccio
///////////////////////////////////////////////////////////////////////////////////
#include "../detail/_noise.hpp"
#include "./func_common.hpp"
namespace glm{
namespace detail
{
template <typename T, precision P>
GLM_FUNC_QUALIFIER tvec4<T, P> grad4(T const & j, tvec4<T, P> const & ip)
{
tvec3<T, P> pXYZ = floor(fract(tvec3<T, P>(j) * tvec3<T, P>(ip)) * T(7)) * ip[2] - T(1);
T pW = static_cast<T>(1.5) - dot(abs(pXYZ), tvec3<T, P>(1));
tvec4<T, P> s = tvec4<T, P>(lessThan(tvec4<T, P>(pXYZ, pW), tvec4<T, P>(0.0)));
pXYZ = pXYZ + (tvec3<T, P>(s) * T(2) - T(1)) * s.w;
return tvec4<T, P>(pXYZ, pW);
}
}//namespace detail
template <typename T>
GLM_FUNC_QUALIFIER T noise1(T const & x)
{
return noise1(tvec2<T, defaultp>(x, T(0)));
}
template <typename T>
GLM_FUNC_QUALIFIER tvec2<T, defaultp> noise2(T const & x)
{
return tvec2<T, defaultp>(
noise1(x + T(0.0)),
noise1(x + T(1.0)));
}
template <typename T>
GLM_FUNC_QUALIFIER tvec3<T, defaultp> noise3(T const & x)
{
return tvec3<T, defaultp>(
noise1(x - T(1.0)),
noise1(x + T(0.0)),
noise1(x + T(1.0)));
}
template <typename T>
GLM_FUNC_QUALIFIER tvec4<T, defaultp> noise4(T const & x)
{
return tvec4<T, defaultp>(
noise1(x - T(1.0)),
noise1(x + T(0.0)),
noise1(x + T(1.0)),
noise1(x + T(2.0)));
}
template <typename T, precision P>
GLM_FUNC_QUALIFIER T noise1(tvec2<T, P> const & v)
{
tvec4<T, P> const C = tvec4<T, P>(
T( 0.211324865405187), // (3.0 - sqrt(3.0)) / 6.0
T( 0.366025403784439), // 0.5 * (sqrt(3.0) - 1.0)
T(-0.577350269189626), // -1.0 + 2.0 * C.x
T( 0.024390243902439)); // 1.0 / 41.0
// First corner
tvec2<T, P> i = floor(v + dot(v, tvec2<T, P>(C[1])));
tvec2<T, P> x0 = v - i + dot(i, tvec2<T, P>(C[0]));
// Other corners
//i1.x = step( x0.y, x0.x ); // x0.x > x0.y ? 1.0 : 0.0
//i1.y = 1.0 - i1.x;
tvec2<T, P> i1 = (x0.x > x0.y) ? tvec2<T, P>(1, 0) : tvec2<T, P>(0, 1);
// x0 = x0 - 0.0 + 0.0 * C.xx ;
// x1 = x0 - i1 + 1.0 * C.xx ;
// x2 = x0 - 1.0 + 2.0 * C.xx ;
tvec4<T, P> x12 = tvec4<T, P>(x0.x, x0.y, x0.x, x0.y) + tvec4<T, P>(C.x, C.x, C.z, C.z);
x12 = tvec4<T, P>(tvec2<T, P>(x12) - i1, x12.z, x12.w);
// Permutations
i = mod(i, T(289)); // Avoid truncation effects in permutation
tvec3<T, P> p = detail::permute(
detail::permute(i.y + tvec3<T, P>(T(0), i1.y, T(1))) + i.x + tvec3<T, P>(T(0), i1.x, T(1)));
tvec3<T, P> m = max(T(0.5) - tvec3<T, P>(
dot(x0, x0),
dot(tvec2<T, P>(x12.x, x12.y), tvec2<T, P>(x12.x, x12.y)),
dot(tvec2<T, P>(x12.z, x12.w), tvec2<T, P>(x12.z, x12.w))), T(0));
m = m * m;
m = m * m;
// Gradients: 41 points uniformly over a line, mapped onto a diamond.
// The ring size 17*17 = 289 is close to a multiple of 41 (41*7 = 287)
tvec3<T, P> x = static_cast<T>(2) * fract(p * C.w) - T(1);
tvec3<T, P> h = abs(x) - T(0.5);
tvec3<T, P> ox = floor(x + T(0.5));
tvec3<T, P> a0 = x - ox;
// Normalise gradients implicitly by scaling m
// Inlined for speed: m *= taylorInvSqrt( a0*a0 + h*h );
m *= static_cast<T>(1.79284291400159) - T(0.85373472095314) * (a0 * a0 + h * h);
// Compute final noise value at P
tvec3<T, P> g;
g.x = a0.x * x0.x + h.x * x0.y;
//g.yz = a0.yz * x12.xz + h.yz * x12.yw;
g.y = a0.y * x12.x + h.y * x12.y;
g.z = a0.z * x12.z + h.z * x12.w;
return T(130) * dot(m, g);
}
template <typename T, precision P>
GLM_FUNC_QUALIFIER T noise1(tvec3<T, P> const & v)
{
tvec2<T, P> const C(1.0 / 6.0, 1.0 / 3.0);
tvec4<T, P> const D(0.0, 0.5, 1.0, 2.0);
// First corner
tvec3<T, P> i(floor(v + dot(v, tvec3<T, P>(C.y))));
tvec3<T, P> x0(v - i + dot(i, tvec3<T, P>(C.x)));
// Other corners
tvec3<T, P> g(step(tvec3<T, P>(x0.y, x0.z, x0.x), x0));
tvec3<T, P> l(T(1) - g);
tvec3<T, P> i1(min(g, tvec3<T, P>(l.z, l.x, l.y)));
tvec3<T, P> i2(max(g, tvec3<T, P>(l.z, l.x, l.y)));
// x0 = x0 - 0.0 + 0.0 * C.xxx;
// x1 = x0 - i1 + 1.0 * C.xxx;
// x2 = x0 - i2 + 2.0 * C.xxx;
// x3 = x0 - 1.0 + 3.0 * C.xxx;
tvec3<T, P> x1(x0 - i1 + C.x);
tvec3<T, P> x2(x0 - i2 + C.y); // 2.0*C.x = 1/3 = C.y
tvec3<T, P> x3(x0 - D.y); // -1.0+3.0*C.x = -0.5 = -D.y
// Permutations
i = mod289(i);
tvec4<T, P> p(detail::permute(detail::permute(detail::permute(
i.z + tvec4<T, P>(T(0), i1.z, i2.z, T(1))) +
i.y + tvec4<T, P>(T(0), i1.y, i2.y, T(1))) +
i.x + tvec4<T, P>(T(0), i1.x, i2.x, T(1))));
// Gradients: 7x7 points over a square, mapped onto an octahedron.
// The ring size 17*17 = 289 is close to a multiple of 49 (49*6 = 294)
T n_ = static_cast<T>(0.142857142857); // 1.0/7.0
tvec3<T, P> ns(n_ * tvec3<T, P>(D.w, D.y, D.z) - tvec3<T, P>(D.x, D.z, D.x));
tvec4<T, P> j(p - T(49) * floor(p * ns.z * ns.z)); // mod(p,7*7)
tvec4<T, P> x_(floor(j * ns.z));
tvec4<T, P> y_(floor(j - T(7) * x_)); // mod(j,N)
tvec4<T, P> x(x_ * ns.x + ns.y);
tvec4<T, P> y(y_ * ns.x + ns.y);
tvec4<T, P> h(T(1) - abs(x) - abs(y));
tvec4<T, P> b0(x.x, x.y, y.x, y.y);
tvec4<T, P> b1(x.z, x.w, y.z, y.w);
// vec4 s0 = vec4(lessThan(b0,0.0))*2.0 - 1.0;
// vec4 s1 = vec4(lessThan(b1,0.0))*2.0 - 1.0;
tvec4<T, P> s0(floor(b0) * T(2) + T(1));
tvec4<T, P> s1(floor(b1) * T(2) + T(1));
tvec4<T, P> sh(-step(h, tvec4<T, P>(0.0)));
tvec4<T, P> a0 = tvec4<T, P>(b0.x, b0.z, b0.y, b0.w) + tvec4<T, P>(s0.x, s0.z, s0.y, s0.w) * tvec4<T, P>(sh.x, sh.x, sh.y, sh.y);
tvec4<T, P> a1 = tvec4<T, P>(b1.x, b1.z, b1.y, b1.w) + tvec4<T, P>(s1.x, s1.z, s1.y, s1.w) * tvec4<T, P>(sh.z, sh.z, sh.w, sh.w);
tvec3<T, P> p0(a0.x, a0.y, h.x);
tvec3<T, P> p1(a0.z, a0.w, h.y);
tvec3<T, P> p2(a1.x, a1.y, h.z);
tvec3<T, P> p3(a1.z, a1.w, h.w);
// Normalise gradients
tvec4<T, P> norm = taylorInvSqrt(tvec4<T, P>(dot(p0, p0), dot(p1, p1), dot(p2, p2), dot(p3, p3)));
p0 *= norm.x;
p1 *= norm.y;
p2 *= norm.z;
p3 *= norm.w;
// Mix final noise value
tvec4<T, P> m = max(T(0.6) - tvec4<T, P>(dot(x0, x0), dot(x1, x1), dot(x2, x2), dot(x3, x3)), T(0));
m = m * m;
return T(42) * dot(m * m, tvec4<T, P>(dot(p0, x0), dot(p1, x1), dot(p2, x2), dot(p3, x3)));
}
template <typename T, precision P>
GLM_FUNC_QUALIFIER T noise1(tvec4<T, P> const & v)
{
tvec4<T, P> const C(
0.138196601125011, // (5 - sqrt(5))/20 G4
0.276393202250021, // 2 * G4
0.414589803375032, // 3 * G4
-0.447213595499958); // -1 + 4 * G4
// (sqrt(5) - 1)/4 = F4, used once below
T const F4 = static_cast<T>(0.309016994374947451);
// First corner
tvec4<T, P> i = floor(v + dot(v, tvec4<T, P>(F4)));
tvec4<T, P> x0 = v - i + dot(i, tvec4<T, P>(C.x));
// Other corners
// Rank sorting originally contributed by Bill Licea-Kane, AMD (formerly ATI)
tvec4<T, P> i0;
tvec3<T, P> isX = step(tvec3<T, P>(x0.y, x0.z, x0.w), tvec3<T, P>(x0.x));
tvec3<T, P> isYZ = step(tvec3<T, P>(x0.z, x0.w, x0.w), tvec3<T, P>(x0.y, x0.y, x0.z));
// i0.x = dot(isX, vec3(1.0));
//i0.x = isX.x + isX.y + isX.z;
//i0.yzw = static_cast<T>(1) - isX;
i0 = tvec4<T, P>(isX.x + isX.y + isX.z, T(1) - isX);
// i0.y += dot(isYZ.xy, vec2(1.0));
i0.y += isYZ.x + isYZ.y;
//i0.zw += 1.0 - tvec2<T, P>(isYZ.x, isYZ.y);
i0.z += static_cast<T>(1) - isYZ.x;
i0.w += static_cast<T>(1) - isYZ.y;
i0.z += isYZ.z;
i0.w += static_cast<T>(1) - isYZ.z;
// i0 now contains the unique values 0,1,2,3 in each channel
tvec4<T, P> i3 = clamp(i0, T(0), T(1));
tvec4<T, P> i2 = clamp(i0 - T(1), T(0), T(1));
tvec4<T, P> i1 = clamp(i0 - T(2), T(0), T(1));
// x0 = x0 - 0.0 + 0.0 * C.xxxx
// x1 = x0 - i1 + 0.0 * C.xxxx
// x2 = x0 - i2 + 0.0 * C.xxxx
// x3 = x0 - i3 + 0.0 * C.xxxx
// x4 = x0 - 1.0 + 4.0 * C.xxxx
tvec4<T, P> x1 = x0 - i1 + C.x;
tvec4<T, P> x2 = x0 - i2 + C.y;
tvec4<T, P> x3 = x0 - i3 + C.z;
tvec4<T, P> x4 = x0 + C.w;
// Permutations
i = mod(i, T(289));
T j0 = detail::permute(detail::permute(detail::permute(detail::permute(i.w) + i.z) + i.y) + i.x);
tvec4<T, P> j1 = detail::permute(detail::permute(detail::permute(detail::permute(
i.w + tvec4<T, P>(i1.w, i2.w, i3.w, T(1))) +
i.z + tvec4<T, P>(i1.z, i2.z, i3.z, T(1))) +
i.y + tvec4<T, P>(i1.y, i2.y, i3.y, T(1))) +
i.x + tvec4<T, P>(i1.x, i2.x, i3.x, T(1)));
// Gradients: 7x7x6 points over a cube, mapped onto a 4-cross polytope
// 7*7*6 = 294, which is close to the ring size 17*17 = 289.
tvec4<T, P> ip = tvec4<T, P>(T(1) / T(294), T(1) / T(49), T(1) / T(7), T(0));
tvec4<T, P> p0 = detail::grad4(j0, ip);
tvec4<T, P> p1 = detail::grad4(j1.x, ip);
tvec4<T, P> p2 = detail::grad4(j1.y, ip);
tvec4<T, P> p3 = detail::grad4(j1.z, ip);
tvec4<T, P> p4 = detail::grad4(j1.w, ip);
// Normalise gradients
tvec4<T, P> norm = detail::taylorInvSqrt(tvec4<T, P>(dot(p0, p0), dot(p1, p1), dot(p2, p2), dot(p3, p3)));
p0 *= norm.x;
p1 *= norm.y;
p2 *= norm.z;
p3 *= norm.w;
p4 *= taylorInvSqrt(dot(p4, p4));
// Mix contributions from the five corners
tvec3<T, P> m0 = max(T(0.6) - tvec3<T, P>(dot(x0, x0), dot(x1, x1), dot(x2, x2)), T(0));
tvec2<T, P> m1 = max(T(0.6) - tvec2<T, P>(dot(x3, x3), dot(x4, x4) ), T(0));
m0 = m0 * m0;
m1 = m1 * m1;
return T(49) * (
dot(m0 * m0, tvec3<T, P>(dot(p0, x0), dot(p1, x1), dot(p2, x2))) +
dot(m1 * m1, tvec2<T, P>(dot(p3, x3), dot(p4, x4))));
}
template <typename T, precision P>
GLM_FUNC_QUALIFIER tvec2<T, P> noise2(tvec2<T, P> const & x)
{
return tvec2<T, P>(
noise1(x + tvec2<T, P>(0.0)),
noise1(tvec2<T, P>(0.0) - x));
}
template <typename T, precision P>
GLM_FUNC_QUALIFIER tvec2<T, P> noise2(tvec3<T, P> const & x)
{
return tvec2<T, P>(
noise1(x + tvec3<T, P>(0.0)),
noise1(tvec3<T, P>(0.0) - x));
}
template <typename T, precision P>
GLM_FUNC_QUALIFIER tvec2<T, P> noise2(tvec4<T, P> const & x)
{
return tvec2<T, P>(
noise1(x + tvec4<T, P>(0)),
noise1(tvec4<T, P>(0) - x));
}
template <typename T, precision P>
GLM_FUNC_QUALIFIER tvec3<T, P> noise3(tvec2<T, P> const & x)
{
return tvec3<T, P>(
noise1(x - tvec2<T, P>(1.0)),
noise1(x + tvec2<T, P>(0.0)),
noise1(x + tvec2<T, P>(1.0)));
}
template <typename T, precision P>
GLM_FUNC_QUALIFIER tvec3<T, P> noise3(tvec3<T, P> const & x)
{
return tvec3<T, P>(
noise1(x - tvec3<T, P>(1.0)),
noise1(x + tvec3<T, P>(0.0)),
noise1(x + tvec3<T, P>(1.0)));
}
template <typename T, precision P>
GLM_FUNC_QUALIFIER tvec3<T, P> noise3(tvec4<T, P> const & x)
{
return tvec3<T, P>(
noise1(x - tvec4<T, P>(1)),
noise1(x + tvec4<T, P>(0)),
noise1(x + tvec4<T, P>(1)));
}
template <typename T, precision P>
GLM_FUNC_QUALIFIER tvec4<T, P> noise4(tvec2<T, P> const & x)
{
return tvec4<T, P>(
noise1(x - tvec2<T, P>(1)),
noise1(x + tvec2<T, P>(0)),
noise1(x + tvec2<T, P>(1)),
noise1(x + tvec2<T, P>(2)));
}
template <typename T, precision P>
GLM_FUNC_QUALIFIER tvec4<T, P> noise4(tvec3<T, P> const & x)
{
return tvec4<T, P>(
noise1(x - tvec3<T, P>(1)),
noise1(x + tvec3<T, P>(0)),
noise1(x + tvec3<T, P>(1)),
noise1(x + tvec3<T, P>(2)));
}
template <typename T, precision P>
GLM_FUNC_QUALIFIER tvec4<T, P> noise4(tvec4<T, P> const & x)
{
return tvec4<T, P>(
noise1(x - tvec4<T, P>(1)),
noise1(x + tvec4<T, P>(0)),
noise1(x + tvec4<T, P>(1)),
noise1(x + tvec4<T, P>(2)));
}
}//namespace glm
///////////////////////////////////////////////////////////////////////////////////
/// OpenGL Mathematics (glm.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
/// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
/// copies of the Software, and to permit persons to whom the Software is
/// furnished to do so, subject to the following conditions:
///
/// 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
/// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
/// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
/// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
/// THE SOFTWARE.
///
/// @ref core
/// @file glm/detail/func_packing.hpp
/// @date 2010-03-17 / 2011-06-15
/// @author Christophe Riccio
///
/// @see <a href="http://www.opengl.org/registry/doc/GLSLangSpec.4.20.8.pdf">GLSL 4.20.8 specification, section 8.4 Floating-Point Pack and Unpack Functions</a>
/// @see gtc_packing
///
/// @defgroup core_func_packing Floating-Point Pack and Unpack Functions
/// @ingroup core
///
/// These functions do not operate component-wise, rather as described in each case.
///////////////////////////////////////////////////////////////////////////////////
#pragma once
#include "type_vec2.hpp"
#include "type_vec4.hpp"
namespace glm
{
/// @addtogroup core_func_packing
/// @{
/// First, converts each component of the normalized floating-point value v into 8- or 16-bit integer values.
/// Then, the results are packed into the returned 32-bit unsigned integer.
///
/// The conversion for component c of v to fixed point is done as follows:
/// packUnorm2x16: round(clamp(c, 0, +1) * 65535.0)
///
/// The first component of the vector will be written to the least significant bits of the output;
/// the last component will be written to the most significant bits.
///
/// @see <a href="http://www.opengl.org/sdk/docs/manglsl/xhtml/packUnorm2x16.xml">GLSL packUnorm2x16 man page</a>
/// @see <a href="http://www.opengl.org/registry/doc/GLSLangSpec.4.20.8.pdf">GLSL 4.20.8 specification, section 8.4 Floating-Point Pack and Unpack Functions</a>
GLM_FUNC_DECL uint packUnorm2x16(vec2 const & v);
/// First, converts each component of the normalized floating-point value v into 8- or 16-bit integer values.
/// Then, the results are packed into the returned 32-bit unsigned integer.
///
/// The conversion for component c of v to fixed point is done as follows:
/// packSnorm2x16: round(clamp(v, -1, +1) * 32767.0)
///
/// The first component of the vector will be written to the least significant bits of the output;
/// the last component will be written to the most significant bits.
///
/// @see <a href="http://www.opengl.org/sdk/docs/manglsl/xhtml/packSnorm2x16.xml">GLSL packSnorm2x16 man page</a>
/// @see <a href="http://www.opengl.org/registry/doc/GLSLangSpec.4.20.8.pdf">GLSL 4.20.8 specification, section 8.4 Floating-Point Pack and Unpack Functions</a>
GLM_FUNC_DECL uint packSnorm2x16(vec2 const & v);
/// First, converts each component of the normalized floating-point value v into 8- or 16-bit integer values.
/// Then, the results are packed into the returned 32-bit unsigned integer.
///
/// The conversion for component c of v to fixed point is done as follows:
/// packUnorm4x8: round(clamp(c, 0, +1) * 255.0)
///
/// The first component of the vector will be written to the least significant bits of the output;
/// the last component will be written to the most significant bits.
///
/// @see <a href="http://www.opengl.org/sdk/docs/manglsl/xhtml/packUnorm4x8.xml">GLSL packUnorm4x8 man page</a>
/// @see <a href="http://www.opengl.org/registry/doc/GLSLangSpec.4.20.8.pdf">GLSL 4.20.8 specification, section 8.4 Floating-Point Pack and Unpack Functions</a>
GLM_FUNC_DECL uint packUnorm4x8(vec4 const & v);
/// First, converts each component of the normalized floating-point value v into 8- or 16-bit integer values.
/// Then, the results are packed into the returned 32-bit unsigned integer.
///
/// The conversion for component c of v to fixed point is done as follows:
/// packSnorm4x8: round(clamp(c, -1, +1) * 127.0)
///
/// The first component of the vector will be written to the least significant bits of the output;
/// the last component will be written to the most significant bits.
///
/// @see <a href="http://www.opengl.org/sdk/docs/manglsl/xhtml/packSnorm4x8.xml">GLSL packSnorm4x8 man page</a>
/// @see <a href="http://www.opengl.org/registry/doc/GLSLangSpec.4.20.8.pdf">GLSL 4.20.8 specification, section 8.4 Floating-Point Pack and Unpack Functions</a>
GLM_FUNC_DECL uint packSnorm4x8(vec4 const & v);
/// First, unpacks a single 32-bit unsigned integer p into a pair of 16-bit unsigned integers, four 8-bit unsigned integers, or four 8-bit signed integers.
/// Then, each component is converted to a normalized floating-point value to generate the returned two- or four-component vector.
///
/// The conversion for unpacked fixed-point value f to floating point is done as follows:
/// unpackUnorm2x16: f / 65535.0
///
/// The first component of the returned vector will be extracted from the least significant bits of the input;
/// the last component will be extracted from the most significant bits.
///
/// @see <a href="http://www.opengl.org/sdk/docs/manglsl/xhtml/unpackUnorm2x16.xml">GLSL unpackUnorm2x16 man page</a>
/// @see <a href="http://www.opengl.org/registry/doc/GLSLangSpec.4.20.8.pdf">GLSL 4.20.8 specification, section 8.4 Floating-Point Pack and Unpack Functions</a>
GLM_FUNC_DECL vec2 unpackUnorm2x16(uint p);
/// First, unpacks a single 32-bit unsigned integer p into a pair of 16-bit unsigned integers, four 8-bit unsigned integers, or four 8-bit signed integers.
/// Then, each component is converted to a normalized floating-point value to generate the returned two- or four-component vector.
///
/// The conversion for unpacked fixed-point value f to floating point is done as follows:
/// unpackSnorm2x16: clamp(f / 32767.0, -1, +1)
///
/// The first component of the returned vector will be extracted from the least significant bits of the input;
/// the last component will be extracted from the most significant bits.
///
/// @see <a href="http://www.opengl.org/sdk/docs/manglsl/xhtml/unpackSnorm2x16.xml">GLSL unpackSnorm2x16 man page</a>
/// @see <a href="http://www.opengl.org/registry/doc/GLSLangSpec.4.20.8.pdf">GLSL 4.20.8 specification, section 8.4 Floating-Point Pack and Unpack Functions</a>
GLM_FUNC_DECL vec2 unpackSnorm2x16(uint p);
/// First, unpacks a single 32-bit unsigned integer p into a pair of 16-bit unsigned integers, four 8-bit unsigned integers, or four 8-bit signed integers.
/// Then, each component is converted to a normalized floating-point value to generate the returned two- or four-component vector.
///
/// The conversion for unpacked fixed-point value f to floating point is done as follows:
/// unpackUnorm4x8: f / 255.0
///
/// The first component of the returned vector will be extracted from the least significant bits of the input;
/// the last component will be extracted from the most significant bits.
///
/// @see <a href="http://www.opengl.org/sdk/docs/manglsl/xhtml/unpackUnorm4x8.xml">GLSL unpackUnorm4x8 man page</a>
/// @see <a href="http://www.opengl.org/registry/doc/GLSLangSpec.4.20.8.pdf">GLSL 4.20.8 specification, section 8.4 Floating-Point Pack and Unpack Functions</a>
GLM_FUNC_DECL vec4 unpackUnorm4x8(uint p);
/// First, unpacks a single 32-bit unsigned integer p into a pair of 16-bit unsigned integers, four 8-bit unsigned integers, or four 8-bit signed integers.
/// Then, each component is converted to a normalized floating-point value to generate the returned two- or four-component vector.
///
/// The conversion for unpacked fixed-point value f to floating point is done as follows:
/// unpackSnorm4x8: clamp(f / 127.0, -1, +1)
///
/// The first component of the returned vector will be extracted from the least significant bits of the input;
/// the last component will be extracted from the most significant bits.
///
/// @see <a href="http://www.opengl.org/sdk/docs/manglsl/xhtml/unpackSnorm4x8.xml">GLSL unpackSnorm4x8 man page</a>
/// @see <a href="http://www.opengl.org/registry/doc/GLSLangSpec.4.20.8.pdf">GLSL 4.20.8 specification, section 8.4 Floating-Point Pack and Unpack Functions</a>
GLM_FUNC_DECL vec4 unpackSnorm4x8(uint p);
/// Returns a double-precision value obtained by packing the components of v into a 64-bit value.
/// If an IEEE 754 Inf or NaN is created, it will not signal, and the resulting floating point value is unspecified.
/// Otherwise, the bit- level representation of v is preserved.
/// The first vector component specifies the 32 least significant bits;
/// the second component specifies the 32 most significant bits.
///
/// @see <a href="http://www.opengl.org/sdk/docs/manglsl/xhtml/packDouble2x32.xml">GLSL packDouble2x32 man page</a>
/// @see <a href="http://www.opengl.org/registry/doc/GLSLangSpec.4.20.8.pdf">GLSL 4.20.8 specification, section 8.4 Floating-Point Pack and Unpack Functions</a>
GLM_FUNC_DECL double packDouble2x32(uvec2 const & v);
/// Returns a two-component unsigned integer vector representation of v.
/// The bit-level representation of v is preserved.
/// The first component of the vector contains the 32 least significant bits of the double;
/// the second component consists the 32 most significant bits.
///
/// @see <a href="http://www.opengl.org/sdk/docs/manglsl/xhtml/unpackDouble2x32.xml">GLSL unpackDouble2x32 man page</a>
/// @see <a href="http://www.opengl.org/registry/doc/GLSLangSpec.4.20.8.pdf">GLSL 4.20.8 specification, section 8.4 Floating-Point Pack and Unpack Functions</a>
GLM_FUNC_DECL uvec2 unpackDouble2x32(double v);
/// Returns an unsigned integer obtained by converting the components of a two-component floating-point vector
/// to the 16-bit floating-point representation found in the OpenGL Specification,
/// and then packing these two 16- bit integers into a 32-bit unsigned integer.
/// The first vector component specifies the 16 least-significant bits of the result;
/// the second component specifies the 16 most-significant bits.
///
/// @see <a href="http://www.opengl.org/sdk/docs/manglsl/xhtml/packHalf2x16.xml">GLSL packHalf2x16 man page</a>
/// @see <a href="http://www.opengl.org/registry/doc/GLSLangSpec.4.20.8.pdf">GLSL 4.20.8 specification, section 8.4 Floating-Point Pack and Unpack Functions</a>
GLM_FUNC_DECL uint packHalf2x16(vec2 const & v);
/// Returns a two-component floating-point vector with components obtained by unpacking a 32-bit unsigned integer into a pair of 16-bit values,
/// interpreting those values as 16-bit floating-point numbers according to the OpenGL Specification,
/// and converting them to 32-bit floating-point values.
/// The first component of the vector is obtained from the 16 least-significant bits of v;
/// the second component is obtained from the 16 most-significant bits of v.
///
/// @see <a href="http://www.opengl.org/sdk/docs/manglsl/xhtml/unpackHalf2x16.xml">GLSL unpackHalf2x16 man page</a>
/// @see <a href="http://www.opengl.org/registry/doc/GLSLangSpec.4.20.8.pdf">GLSL 4.20.8 specification, section 8.4 Floating-Point Pack and Unpack Functions</a>
GLM_FUNC_DECL vec2 unpackHalf2x16(uint v);
/// @}
}//namespace glm
#include "func_packing.inl"
///////////////////////////////////////////////////////////////////////////////////
/// OpenGL Mathematics (glm.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
/// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
/// copies of the Software, and to permit persons to whom the Software is
/// furnished to do so, subject to the following conditions:
///
/// 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
/// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
/// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
/// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
/// THE SOFTWARE.
///
/// @ref core
/// @file glm/detail/func_packing.inl
/// @date 2010-03-17 / 2011-06-15
/// @author Christophe Riccio
///////////////////////////////////////////////////////////////////////////////////
#include "func_common.hpp"
#include "type_half.hpp"
#include "../fwd.hpp"
namespace glm
{
GLM_FUNC_QUALIFIER uint packUnorm2x16(vec2 const & v)
{
u16vec2 const Topack(round(clamp(v, 0.0f, 1.0f) * 65535.0f));
return reinterpret_cast<uint const &>(Topack);
}
GLM_FUNC_QUALIFIER vec2 unpackUnorm2x16(uint p)
{
vec2 Unpack(reinterpret_cast<u16vec2 const &>(p));
return Unpack * float(1.5259021896696421759365224689097e-5); // 1.0 / 65535.0
}
GLM_FUNC_QUALIFIER uint packSnorm2x16(vec2 const & v)
{
i16vec2 const Topack(round(clamp(v ,-1.0f, 1.0f) * 32767.0f));
return reinterpret_cast<uint const &>(Topack);
}
GLM_FUNC_QUALIFIER vec2 unpackSnorm2x16(uint p)
{
vec2 const Unpack(reinterpret_cast<i16vec2 const &>(p));
return clamp(
Unpack * 3.0518509475997192297128208258309e-5f, //1.0f / 32767.0f,
-1.0f, 1.0f);
}
GLM_FUNC_QUALIFIER uint packUnorm4x8(vec4 const & v)
{
u8vec4 const Topack(round(clamp(v, 0.0f, 1.0f) * 255.0f));
return reinterpret_cast<uint const &>(Topack);
}
GLM_FUNC_QUALIFIER vec4 unpackUnorm4x8(uint p)
{
vec4 const Unpack(reinterpret_cast<u8vec4 const&>(p));
return Unpack * float(0.0039215686274509803921568627451); // 1 / 255
}
GLM_FUNC_QUALIFIER uint packSnorm4x8(vec4 const & v)
{
i8vec4 const Topack(round(clamp(v ,-1.0f, 1.0f) * 127.0f));
return reinterpret_cast<uint const &>(Topack);
}
GLM_FUNC_QUALIFIER glm::vec4 unpackSnorm4x8(uint p)
{
vec4 const Unpack(reinterpret_cast<i8vec4 const &>(p));
return clamp(
Unpack * 0.0078740157480315f, // 1.0f / 127.0f
-1.0f, 1.0f);
}
GLM_FUNC_QUALIFIER double packDouble2x32(uvec2 const & v)
{
return reinterpret_cast<double const &>(v);
}
GLM_FUNC_QUALIFIER uvec2 unpackDouble2x32(double v)
{
return reinterpret_cast<uvec2 const &>(v);
}
GLM_FUNC_QUALIFIER uint packHalf2x16(vec2 const & v)
{
i16vec2 const Unpack(
detail::toFloat16(v.x),
detail::toFloat16(v.y));
return reinterpret_cast<uint const &>(Unpack);
}
GLM_FUNC_QUALIFIER vec2 unpackHalf2x16(uint v)
{
i16vec2 const Unpack(reinterpret_cast<i16vec2 const &>(v));
return vec2(
detail::toFloat32(Unpack.x),
detail::toFloat32(Unpack.y));
}
}//namespace glm
///////////////////////////////////////////////////////////////////////////////////
/// OpenGL Mathematics (glm.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
/// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
/// copies of the Software, and to permit persons to whom the Software is
/// furnished to do so, subject to the following conditions:
///
/// 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
/// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
/// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
/// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
/// THE SOFTWARE.
///
/// @ref core
/// @file glm/detail/func_trigonometric.hpp
/// @date 2008-08-01 / 2011-06-15
/// @author Christophe Riccio
///
/// @see <a href="http://www.opengl.org/registry/doc/GLSLangSpec.4.20.8.pdf">GLSL 4.20.8 specification, section 8.1 Angle and Trigonometry Functions</a>
///
/// @defgroup core_func_trigonometric Angle and Trigonometry Functions
/// @ingroup core
///
/// Function parameters specified as angle are assumed to be in units of radians.
/// In no case will any of these functions result in a divide by zero error. If
/// the divisor of a ratio is 0, then results will be undefined.
///
/// These all operate component-wise. The description is per component.
///////////////////////////////////////////////////////////////////////////////////
#pragma once
#include "setup.hpp"
#include "precision.hpp"
namespace glm
{
/// @addtogroup core_func_trigonometric
/// @{
/// Converts degrees to radians and returns the result.
///
/// @tparam genType Floating-point scalar or vector types.
///
/// @see <a href="http://www.opengl.org/sdk/docs/manglsl/xhtml/radians.xml">GLSL radians man page</a>
/// @see <a href="http://www.opengl.org/registry/doc/GLSLangSpec.4.20.8.pdf">GLSL 4.20.8 specification, section 8.1 Angle and Trigonometry Functions</a>
template <typename T, precision P, template <typename, precision> class vecType>
GLM_FUNC_DECL vecType<T, P> radians(vecType<T, P> const & degrees);
/// Converts radians to degrees and returns the result.
///
/// @tparam genType Floating-point scalar or vector types.
///
/// @see <a href="http://www.opengl.org/sdk/docs/manglsl/xhtml/degrees.xml">GLSL degrees man page</a>
/// @see <a href="http://www.opengl.org/registry/doc/GLSLangSpec.4.20.8.pdf">GLSL 4.20.8 specification, section 8.1 Angle and Trigonometry Functions</a>
template <typename T, precision P, template <typename, precision> class vecType>
GLM_FUNC_DECL vecType<T, P> degrees(vecType<T, P> const & radians);
/// The standard trigonometric sine function.
/// The values returned by this function will range from [-1, 1].
///
/// @tparam genType Floating-point scalar or vector types.
///
/// @see <a href="http://www.opengl.org/sdk/docs/manglsl/xhtml/sin.xml">GLSL sin man page</a>
/// @see <a href="http://www.opengl.org/registry/doc/GLSLangSpec.4.20.8.pdf">GLSL 4.20.8 specification, section 8.1 Angle and Trigonometry Functions</a>
template <typename T, precision P, template <typename, precision> class vecType>
GLM_FUNC_DECL vecType<T, P> sin(vecType<T, P> const & angle);
/// The standard trigonometric cosine function.
/// The values returned by this function will range from [-1, 1].
///
/// @tparam genType Floating-point scalar or vector types.
///
/// @see <a href="http://www.opengl.org/sdk/docs/manglsl/xhtml/cos.xml">GLSL cos man page</a>
/// @see <a href="http://www.opengl.org/registry/doc/GLSLangSpec.4.20.8.pdf">GLSL 4.20.8 specification, section 8.1 Angle and Trigonometry Functions</a>
template <typename T, precision P, template <typename, precision> class vecType>
GLM_FUNC_DECL vecType<T, P> cos(vecType<T, P> const & angle);
/// The standard trigonometric tangent function.
///
/// @tparam genType Floating-point scalar or vector types.
///
/// @see <a href="http://www.opengl.org/sdk/docs/manglsl/xhtml/tan.xml">GLSL tan man page</a>
/// @see <a href="http://www.opengl.org/registry/doc/GLSLangSpec.4.20.8.pdf">GLSL 4.20.8 specification, section 8.1 Angle and Trigonometry Functions</a>
template <typename T, precision P, template <typename, precision> class vecType>
GLM_FUNC_DECL vecType<T, P> tan(vecType<T, P> const & angle);
/// Arc sine. Returns an angle whose sine is x.
/// The range of values returned by this function is [-PI/2, PI/2].
/// Results are undefined if |x| > 1.
///
/// @tparam genType Floating-point scalar or vector types.
///
/// @see <a href="http://www.opengl.org/sdk/docs/manglsl/xhtml/asin.xml">GLSL asin man page</a>
/// @see <a href="http://www.opengl.org/registry/doc/GLSLangSpec.4.20.8.pdf">GLSL 4.20.8 specification, section 8.1 Angle and Trigonometry Functions</a>
template <typename T, precision P, template <typename, precision> class vecType>
GLM_FUNC_DECL vecType<T, P> asin(vecType<T, P> const & x);
/// Arc cosine. Returns an angle whose sine is x.
/// The range of values returned by this function is [0, PI].
/// Results are undefined if |x| > 1.
///
/// @tparam genType Floating-point scalar or vector types.
///
/// @see <a href="http://www.opengl.org/sdk/docs/manglsl/xhtml/acos.xml">GLSL acos man page</a>
/// @see <a href="http://www.opengl.org/registry/doc/GLSLangSpec.4.20.8.pdf">GLSL 4.20.8 specification, section 8.1 Angle and Trigonometry Functions</a>
template <typename T, precision P, template <typename, precision> class vecType>
GLM_FUNC_DECL vecType<T, P> acos(vecType<T, P> const & x);
/// Arc tangent. Returns an angle whose tangent is y/x.
/// The signs of x and y are used to determine what
/// quadrant the angle is in. The range of values returned
/// by this function is [-PI, PI]. Results are undefined
/// if x and y are both 0.
///
/// @tparam genType Floating-point scalar or vector types.
///
/// @see <a href="http://www.opengl.org/sdk/docs/manglsl/xhtml/atan.xml">GLSL atan man page</a>
/// @see <a href="http://www.opengl.org/registry/doc/GLSLangSpec.4.20.8.pdf">GLSL 4.20.8 specification, section 8.1 Angle and Trigonometry Functions</a>
template <typename T, precision P, template <typename, precision> class vecType>
GLM_FUNC_DECL vecType<T, P> atan(vecType<T, P> const & y, vecType<T, P> const & x);
/// Arc tangent. Returns an angle whose tangent is y_over_x.
/// The range of values returned by this function is [-PI/2, PI/2].
///
/// @tparam genType Floating-point scalar or vector types.
///
/// @see <a href="http://www.opengl.org/sdk/docs/manglsl/xhtml/atan.xml">GLSL atan man page</a>
/// @see <a href="http://www.opengl.org/registry/doc/GLSLangSpec.4.20.8.pdf">GLSL 4.20.8 specification, section 8.1 Angle and Trigonometry Functions</a>
template <typename T, precision P, template <typename, precision> class vecType>
GLM_FUNC_DECL vecType<T, P> atan(vecType<T, P> const & y_over_x);
/// Returns the hyperbolic sine function, (exp(x) - exp(-x)) / 2
///
/// @tparam genType Floating-point scalar or vector types.
///
/// @see <a href="http://www.opengl.org/sdk/docs/manglsl/xhtml/sinh.xml">GLSL sinh man page</a>
/// @see <a href="http://www.opengl.org/registry/doc/GLSLangSpec.4.20.8.pdf">GLSL 4.20.8 specification, section 8.1 Angle and Trigonometry Functions</a>
template <typename T, precision P, template <typename, precision> class vecType>
GLM_FUNC_DECL vecType<T, P> sinh(vecType<T, P> const & angle);
/// Returns the hyperbolic cosine function, (exp(x) + exp(-x)) / 2
///
/// @tparam genType Floating-point scalar or vector types.
///
/// @see <a href="http://www.opengl.org/sdk/docs/manglsl/xhtml/cosh.xml">GLSL cosh man page</a>
/// @see <a href="http://www.opengl.org/registry/doc/GLSLangSpec.4.20.8.pdf">GLSL 4.20.8 specification, section 8.1 Angle and Trigonometry Functions</a>
template <typename T, precision P, template <typename, precision> class vecType>
GLM_FUNC_DECL vecType<T, P> cosh(vecType<T, P> const & angle);
/// Returns the hyperbolic tangent function, sinh(angle) / cosh(angle)
///
/// @tparam genType Floating-point scalar or vector types.
///
/// @see <a href="http://www.opengl.org/sdk/docs/manglsl/xhtml/tanh.xml">GLSL tanh man page</a>
/// @see <a href="http://www.opengl.org/registry/doc/GLSLangSpec.4.20.8.pdf">GLSL 4.20.8 specification, section 8.1 Angle and Trigonometry Functions</a>
template <typename T, precision P, template <typename, precision> class vecType>
GLM_FUNC_DECL vecType<T, P> tanh(vecType<T, P> const & angle);
/// Arc hyperbolic sine; returns the inverse of sinh.
///
/// @tparam genType Floating-point scalar or vector types.
///
/// @see <a href="http://www.opengl.org/sdk/docs/manglsl/xhtml/asinh.xml">GLSL asinh man page</a>
/// @see <a href="http://www.opengl.org/registry/doc/GLSLangSpec.4.20.8.pdf">GLSL 4.20.8 specification, section 8.1 Angle and Trigonometry Functions</a>
template <typename T, precision P, template <typename, precision> class vecType>
GLM_FUNC_DECL vecType<T, P> asinh(vecType<T, P> const & x);
/// Arc hyperbolic cosine; returns the non-negative inverse
/// of cosh. Results are undefined if x < 1.
///
/// @tparam genType Floating-point scalar or vector types.
///
/// @see <a href="http://www.opengl.org/sdk/docs/manglsl/xhtml/acosh.xml">GLSL acosh man page</a>
/// @see <a href="http://www.opengl.org/registry/doc/GLSLangSpec.4.20.8.pdf">GLSL 4.20.8 specification, section 8.1 Angle and Trigonometry Functions</a>
template <typename T, precision P, template <typename, precision> class vecType>
GLM_FUNC_DECL vecType<T, P> acosh(vecType<T, P> const & x);
/// Arc hyperbolic tangent; returns the inverse of tanh.
/// Results are undefined if abs(x) >= 1.
///
/// @tparam genType Floating-point scalar or vector types.
///
/// @see <a href="http://www.opengl.org/sdk/docs/manglsl/xhtml/atanh.xml">GLSL atanh man page</a>
/// @see <a href="http://www.opengl.org/registry/doc/GLSLangSpec.4.20.8.pdf">GLSL 4.20.8 specification, section 8.1 Angle and Trigonometry Functions</a>
template <typename T, precision P, template <typename, precision> class vecType>
GLM_FUNC_DECL vecType<T, P> atanh(vecType<T, P> const & x);
/// @}
}//namespace glm
#include "func_trigonometric.inl"
///////////////////////////////////////////////////////////////////////////////////
/// OpenGL Mathematics (glm.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
/// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
/// copies of the Software, and to permit persons to whom the Software is
/// furnished to do so, subject to the following conditions:
///
/// 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
/// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
/// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
/// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
/// THE SOFTWARE.
///
/// @ref core
/// @file glm/detail/func_trigonometric.inl
/// @date 2008-08-03 / 2011-06-15
/// @author Christophe Riccio
///////////////////////////////////////////////////////////////////////////////////
#include "_vectorize.hpp"
#include <cmath>
#include <limits>
namespace glm
{
// radians
template <typename genType>
GLM_FUNC_QUALIFIER genType radians(genType degrees)
{
GLM_STATIC_ASSERT(std::numeric_limits<genType>::is_iec559, "'radians' only accept floating-point input");
return degrees * static_cast<genType>(0.01745329251994329576923690768489);
}
template <typename T, precision P, template <typename, precision> class vecType>
GLM_FUNC_QUALIFIER vecType<T, P> radians(vecType<T, P> const & v)
{
return detail::functor1<T, T, P, vecType>::call(radians, v);
}
// degrees
template <typename genType>
GLM_FUNC_QUALIFIER genType degrees(genType radians)
{
GLM_STATIC_ASSERT(std::numeric_limits<genType>::is_iec559, "'degrees' only accept floating-point input");
return radians * static_cast<genType>(57.295779513082320876798154814105);
}
template <typename T, precision P, template <typename, precision> class vecType>
GLM_FUNC_QUALIFIER vecType<T, P> degrees(vecType<T, P> const & v)
{
return detail::functor1<T, T, P, vecType>::call(degrees, v);
}
// sin
using ::std::sin;
template <typename T, precision P, template <typename, precision> class vecType>
GLM_FUNC_QUALIFIER vecType<T, P> sin(vecType<T, P> const & v)
{
return detail::functor1<T, T, P, vecType>::call(sin, v);
}
// cos
using std::cos;
template <typename T, precision P, template <typename, precision> class vecType>
GLM_FUNC_QUALIFIER vecType<T, P> cos(vecType<T, P> const & v)
{
return detail::functor1<T, T, P, vecType>::call(cos, v);
}
// tan
using std::tan;
template <typename T, precision P, template <typename, precision> class vecType>
GLM_FUNC_QUALIFIER vecType<T, P> tan(vecType<T, P> const & v)
{
return detail::functor1<T, T, P, vecType>::call(tan, v);
}
// asin
using std::asin;
template <typename T, precision P, template <typename, precision> class vecType>
GLM_FUNC_QUALIFIER vecType<T, P> asin(vecType<T, P> const & v)
{
return detail::functor1<T, T, P, vecType>::call(asin, v);
}
// acos
using std::acos;
template <typename T, precision P, template <typename, precision> class vecType>
GLM_FUNC_QUALIFIER vecType<T, P> acos(vecType<T, P> const & v)
{
return detail::functor1<T, T, P, vecType>::call(acos, v);
}
// atan
template <typename genType>
GLM_FUNC_QUALIFIER genType atan(genType const & y, genType const & x)
{
GLM_STATIC_ASSERT(std::numeric_limits<genType>::is_iec559, "'atan' only accept floating-point input");
return ::std::atan2(y, x);
}
template <typename T, precision P, template <typename, precision> class vecType>
GLM_FUNC_QUALIFIER vecType<T, P> atan(vecType<T, P> const & a, vecType<T, P> const & b)
{
return detail::functor2<T, P, vecType>::call(atan2, a, b);
}
using std::atan;
template <typename T, precision P, template <typename, precision> class vecType>
GLM_FUNC_QUALIFIER vecType<T, P> atan(vecType<T, P> const & v)
{
return detail::functor1<T, T, P, vecType>::call(atan, v);
}
// sinh
using std::sinh;
template <typename T, precision P, template <typename, precision> class vecType>
GLM_FUNC_QUALIFIER vecType<T, P> sinh(vecType<T, P> const & v)
{
return detail::functor1<T, T, P, vecType>::call(sinh, v);
}
// cosh
using std::cosh;
template <typename T, precision P, template <typename, precision> class vecType>
GLM_FUNC_QUALIFIER vecType<T, P> cosh(vecType<T, P> const & v)
{
return detail::functor1<T, T, P, vecType>::call(cosh, v);
}
// tanh
using std::tanh;
template <typename T, precision P, template <typename, precision> class vecType>
GLM_FUNC_QUALIFIER vecType<T, P> tanh(vecType<T, P> const & v)
{
return detail::functor1<T, T, P, vecType>::call(tanh, v);
}
// asinh
# if GLM_HAS_CXX11_STL
using std::asinh;
# else
template <typename genType>
GLM_FUNC_QUALIFIER genType asinh(genType const & x)
{
GLM_STATIC_ASSERT(std::numeric_limits<genType>::is_iec559, "'asinh' only accept floating-point input");
return (x < static_cast<genType>(0) ? static_cast<genType>(-1) : (x > static_cast<genType>(0) ? static_cast<genType>(1) : static_cast<genType>(0))) * log(abs(x) + sqrt(static_cast<genType>(1) + x * x));
}
# endif
template <typename T, precision P, template <typename, precision> class vecType>
GLM_FUNC_QUALIFIER vecType<T, P> asinh(vecType<T, P> const & v)
{
return detail::functor1<T, T, P, vecType>::call(asinh, v);
}
// acosh
# if GLM_HAS_CXX11_STL
using std::acosh;
# else
template <typename genType>
GLM_FUNC_QUALIFIER genType acosh(genType const & x)
{
GLM_STATIC_ASSERT(std::numeric_limits<genType>::is_iec559, "'acosh' only accept floating-point input");
if(x < static_cast<genType>(1))
return static_cast<genType>(0);
return log(x + sqrt(x * x - static_cast<genType>(1)));
}
# endif
template <typename T, precision P, template <typename, precision> class vecType>
GLM_FUNC_QUALIFIER vecType<T, P> acosh(vecType<T, P> const & v)
{
return detail::functor1<T, T, P, vecType>::call(acosh, v);
}
// atanh
# if GLM_HAS_CXX11_STL
using std::atanh;
# else
template <typename genType>
GLM_FUNC_QUALIFIER genType atanh(genType const & x)
{
GLM_STATIC_ASSERT(std::numeric_limits<genType>::is_iec559, "'atanh' only accept floating-point input");
if(abs(x) >= static_cast<genType>(1))
return 0;
return static_cast<genType>(0.5) * log((static_cast<genType>(1) + x) / (static_cast<genType>(1) - x));
}
# endif
template <typename T, precision P, template <typename, precision> class vecType>
GLM_FUNC_QUALIFIER vecType<T, P> atanh(vecType<T, P> const & v)
{
return detail::functor1<T, T, P, vecType>::call(atanh, v);
}
}//namespace glm
///////////////////////////////////////////////////////////////////////////////////
/// OpenGL Mathematics (glm.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
/// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
/// copies of the Software, and to permit persons to whom the Software is
/// furnished to do so, subject to the following conditions:
///
/// 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
/// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
/// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
/// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
/// THE SOFTWARE.
///
/// @ref core
/// @file glm/detail/func_vector_relational.hpp
/// @date 2008-08-03 / 2011-06-15
/// @author Christophe Riccio
///
/// @see <a href="http://www.opengl.org/registry/doc/GLSLangSpec.4.20.8.pdf">GLSL 4.20.8 specification, section 8.7 Vector Relational Functions</a>
///
/// @defgroup core_func_vector_relational Vector Relational Functions
/// @ingroup core
///
/// Relational and equality operators (<, <=, >, >=, ==, !=) are defined to
/// operate on scalars and produce scalar Boolean results. For vector results,
/// use the following built-in functions.
///
/// In all cases, the sizes of all the input and return vectors for any particular
/// call must match.
///////////////////////////////////////////////////////////////////////////////////
#pragma once
#include "precision.hpp"
#include "setup.hpp"
namespace glm
{
/// @addtogroup core_func_vector_relational
/// @{
/// Returns the component-wise comparison result of x < y.
///
/// @tparam vecType Floating-point or integer vector types.
///
/// @see <a href="http://www.opengl.org/sdk/docs/manglsl/xhtml/lessThan.xml">GLSL lessThan man page</a>
/// @see <a href="http://www.opengl.org/registry/doc/GLSLangSpec.4.20.8.pdf">GLSL 4.20.8 specification, section 8.7 Vector Relational Functions</a>
template <typename T, precision P, template <typename, precision> class vecType>
GLM_FUNC_DECL vecType<bool, P> lessThan(vecType<T, P> const & x, vecType<T, P> const & y);
/// Returns the component-wise comparison of result x <= y.
///
/// @tparam vecType Floating-point or integer vector types.
///
/// @see <a href="http://www.opengl.org/sdk/docs/manglsl/xhtml/lessThanEqual.xml">GLSL lessThanEqual man page</a>
/// @see <a href="http://www.opengl.org/registry/doc/GLSLangSpec.4.20.8.pdf">GLSL 4.20.8 specification, section 8.7 Vector Relational Functions</a>
template <typename T, precision P, template <typename, precision> class vecType>
GLM_FUNC_DECL vecType<bool, P> lessThanEqual(vecType<T, P> const & x, vecType<T, P> const & y);
/// Returns the component-wise comparison of result x > y.
///
/// @tparam vecType Floating-point or integer vector types.
///
/// @see <a href="http://www.opengl.org/sdk/docs/manglsl/xhtml/greaterThan.xml">GLSL greaterThan man page</a>
/// @see <a href="http://www.opengl.org/registry/doc/GLSLangSpec.4.20.8.pdf">GLSL 4.20.8 specification, section 8.7 Vector Relational Functions</a>
template <typename T, precision P, template <typename, precision> class vecType>
GLM_FUNC_DECL vecType<bool, P> greaterThan(vecType<T, P> const & x, vecType<T, P> const & y);
/// Returns the component-wise comparison of result x >= y.
///
/// @tparam vecType Floating-point or integer vector types.
///
/// @see <a href="http://www.opengl.org/sdk/docs/manglsl/xhtml/greaterThanEqual.xml">GLSL greaterThanEqual man page</a>
/// @see <a href="http://www.opengl.org/registry/doc/GLSLangSpec.4.20.8.pdf">GLSL 4.20.8 specification, section 8.7 Vector Relational Functions</a>
template <typename T, precision P, template <typename, precision> class vecType>
GLM_FUNC_DECL vecType<bool, P> greaterThanEqual(vecType<T, P> const & x, vecType<T, P> const & y);
/// Returns the component-wise comparison of result x == y.
///
/// @tparam vecType Floating-point, integer or boolean vector types.
///
/// @see <a href="http://www.opengl.org/sdk/docs/manglsl/xhtml/equal.xml">GLSL equal man page</a>
/// @see <a href="http://www.opengl.org/registry/doc/GLSLangSpec.4.20.8.pdf">GLSL 4.20.8 specification, section 8.7 Vector Relational Functions</a>
template <typename T, precision P, template <typename, precision> class vecType>
GLM_FUNC_DECL vecType<bool, P> equal(vecType<T, P> const & x, vecType<T, P> const & y);
/// Returns the component-wise comparison of result x != y.
///
/// @tparam vecType Floating-point, integer or boolean vector types.
///
/// @see <a href="http://www.opengl.org/sdk/docs/manglsl/xhtml/notEqual.xml">GLSL notEqual man page</a>
/// @see <a href="http://www.opengl.org/registry/doc/GLSLangSpec.4.20.8.pdf">GLSL 4.20.8 specification, section 8.7 Vector Relational Functions</a>
template <typename T, precision P, template <typename, precision> class vecType>
GLM_FUNC_DECL vecType<bool, P> notEqual(vecType<T, P> const & x, vecType<T, P> const & y);
/// Returns true if any component of x is true.
///
/// @tparam vecType Boolean vector types.
///
/// @see <a href="http://www.opengl.org/sdk/docs/manglsl/xhtml/any.xml">GLSL any man page</a>
/// @see <a href="http://www.opengl.org/registry/doc/GLSLangSpec.4.20.8.pdf">GLSL 4.20.8 specification, section 8.7 Vector Relational Functions</a>
template <precision P, template <typename, precision> class vecType>
GLM_FUNC_DECL bool any(vecType<bool, P> const & v);
/// Returns true if all components of x are true.
///
/// @tparam vecType Boolean vector types.
///
/// @see <a href="http://www.opengl.org/sdk/docs/manglsl/xhtml/all.xml">GLSL all man page</a>
/// @see <a href="http://www.opengl.org/registry/doc/GLSLangSpec.4.20.8.pdf">GLSL 4.20.8 specification, section 8.7 Vector Relational Functions</a>
template <precision P, template <typename, precision> class vecType>
GLM_FUNC_DECL bool all(vecType<bool, P> const & v);
/// Returns the component-wise logical complement of x.
/// /!\ Because of language incompatibilities between C++ and GLSL, GLM defines the function not but not_ instead.
///
/// @tparam vecType Boolean vector types.
///
/// @see <a href="http://www.opengl.org/sdk/docs/manglsl/xhtml/not.xml">GLSL not man page</a>
/// @see <a href="http://www.opengl.org/registry/doc/GLSLangSpec.4.20.8.pdf">GLSL 4.20.8 specification, section 8.7 Vector Relational Functions</a>
template <precision P, template <typename, precision> class vecType>
GLM_FUNC_DECL vecType<bool, P> not_(vecType<bool, P> const & v);
/// @}
}//namespace glm
#include "func_vector_relational.inl"
///////////////////////////////////////////////////////////////////////////////////
/// OpenGL Mathematics (glm.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
/// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
/// copies of the Software, and to permit persons to whom the Software is
/// furnished to do so, subject to the following conditions:
///
/// 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
/// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
/// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
/// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
/// THE SOFTWARE.
///
/// @ref core
/// @file glm/detail/func_vector_relational.inl
/// @date 2008-08-03 / 2011-09-09
/// @author Christophe Riccio
///////////////////////////////////////////////////////////////////////////////////
#include <limits>
namespace glm
{
template <typename T, precision P, template <typename, precision> class vecType>
GLM_FUNC_QUALIFIER vecType<bool, P> lessThan(vecType<T, P> const & x, vecType<T, P> const & y)
{
assert(detail::component_count(x) == detail::component_count(y));
vecType<bool, P> Result(uninitialize);
for(detail::component_count_t i = 0; i < detail::component_count(x); ++i)
Result[i] = x[i] < y[i];
return Result;
}
template <typename T, precision P, template <typename, precision> class vecType>
GLM_FUNC_QUALIFIER vecType<bool, P> lessThanEqual(vecType<T, P> const & x, vecType<T, P> const & y)
{
assert(detail::component_count(x) == detail::component_count(y));
vecType<bool, P> Result(uninitialize);
for(detail::component_count_t i = 0; i < detail::component_count(x); ++i)
Result[i] = x[i] <= y[i];
return Result;
}
template <typename T, precision P, template <typename, precision> class vecType>
GLM_FUNC_QUALIFIER vecType<bool, P> greaterThan(vecType<T, P> const & x, vecType<T, P> const & y)
{
assert(detail::component_count(x) == detail::component_count(y));
vecType<bool, P> Result(uninitialize);
for(detail::component_count_t i = 0; i < detail::component_count(x); ++i)
Result[i] = x[i] > y[i];
return Result;
}
template <typename T, precision P, template <typename, precision> class vecType>
GLM_FUNC_QUALIFIER vecType<bool, P> greaterThanEqual(vecType<T, P> const & x, vecType<T, P> const & y)
{
assert(detail::component_count(x) == detail::component_count(y));
vecType<bool, P> Result(uninitialize);
for(detail::component_count_t i = 0; i < detail::component_count(x); ++i)
Result[i] = x[i] >= y[i];
return Result;
}
template <typename T, precision P, template <typename, precision> class vecType>
GLM_FUNC_QUALIFIER vecType<bool, P> equal(vecType<T, P> const & x, vecType<T, P> const & y)
{
assert(detail::component_count(x) == detail::component_count(y));
vecType<bool, P> Result(uninitialize);
for(detail::component_count_t i = 0; i < detail::component_count(x); ++i)
Result[i] = x[i] == y[i];
return Result;
}
template <typename T, precision P, template <typename, precision> class vecType>
GLM_FUNC_QUALIFIER vecType<bool, P> notEqual(vecType<T, P> const & x, vecType<T, P> const & y)
{
assert(detail::component_count(x) == detail::component_count(y));
vecType<bool, P> Result(uninitialize);
for(detail::component_count_t i = 0; i < detail::component_count(x); ++i)
Result[i] = x[i] != y[i];
return Result;
}
template <precision P, template <typename, precision> class vecType>
GLM_FUNC_QUALIFIER bool any(vecType<bool, P> const & v)
{
bool Result = false;
for(detail::component_count_t i = 0; i < detail::component_count(v); ++i)
Result = Result || v[i];
return Result;
}
template <precision P, template <typename, precision> class vecType>
GLM_FUNC_QUALIFIER bool all(vecType<bool, P> const & v)
{
bool Result = true;
for(detail::component_count_t i = 0; i < detail::component_count(v); ++i)
Result = Result && v[i];
return Result;
}
template <precision P, template <typename, precision> class vecType>
GLM_FUNC_QUALIFIER vecType<bool, P> not_(vecType<bool, P> const & v)
{
vecType<bool, P> Result(uninitialize);
for(detail::component_count_t i = 0; i < detail::component_count(v); ++i)
Result[i] = !v[i];
return Result;
}
}//namespace glm
///////////////////////////////////////////////////////////////////////////////////
/// OpenGL Mathematics (glm.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
/// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
/// copies of the Software, and to permit persons to whom the Software is
/// furnished to do so, subject to the following conditions:
///
/// 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
/// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
/// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
/// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
/// THE SOFTWARE.
///
/// @ref core
/// @file glm/glm.cpp
/// @date 2013-04-22 / 2013-04-22
/// @author Christophe Riccio
///////////////////////////////////////////////////////////////////////////////////
#include <glm/glm.hpp>
#include <glm/gtc/quaternion.hpp>
#include <glm/gtx/dual_quaternion.hpp>
namespace glm
{
// tvec1 type explicit instantiation
template struct tvec1<uint8, lowp>;
template struct tvec1<uint16, lowp>;
template struct tvec1<uint32, lowp>;
template struct tvec1<uint64, lowp>;
template struct tvec1<int8, lowp>;
template struct tvec1<int16, lowp>;
template struct tvec1<int32, lowp>;
template struct tvec1<int64, lowp>;
template struct tvec1<float32, lowp>;
template struct tvec1<float64, lowp>;
template struct tvec1<uint8, mediump>;
template struct tvec1<uint16, mediump>;
template struct tvec1<uint32, mediump>;
template struct tvec1<uint64, mediump>;
template struct tvec1<int8, mediump>;
template struct tvec1<int16, mediump>;
template struct tvec1<int32, mediump>;
template struct tvec1<int64, mediump>;
template struct tvec1<float32, mediump>;
template struct tvec1<float64, mediump>;
template struct tvec1<uint8, highp>;
template struct tvec1<uint16, highp>;
template struct tvec1<uint32, highp>;
template struct tvec1<uint64, highp>;
template struct tvec1<int8, highp>;
template struct tvec1<int16, highp>;
template struct tvec1<int32, highp>;
template struct tvec1<int64, highp>;
template struct tvec1<float32, highp>;
template struct tvec1<float64, highp>;
// tvec2 type explicit instantiation
template struct tvec2<uint8, lowp>;
template struct tvec2<uint16, lowp>;
template struct tvec2<uint32, lowp>;
template struct tvec2<uint64, lowp>;
template struct tvec2<int8, lowp>;
template struct tvec2<int16, lowp>;
template struct tvec2<int32, lowp>;
template struct tvec2<int64, lowp>;
template struct tvec2<float32, lowp>;
template struct tvec2<float64, lowp>;
template struct tvec2<uint8, mediump>;
template struct tvec2<uint16, mediump>;
template struct tvec2<uint32, mediump>;
template struct tvec2<uint64, mediump>;
template struct tvec2<int8, mediump>;
template struct tvec2<int16, mediump>;
template struct tvec2<int32, mediump>;
template struct tvec2<int64, mediump>;
template struct tvec2<float32, mediump>;
template struct tvec2<float64, mediump>;
template struct tvec2<uint8, highp>;
template struct tvec2<uint16, highp>;
template struct tvec2<uint32, highp>;
template struct tvec2<uint64, highp>;
template struct tvec2<int8, highp>;
template struct tvec2<int16, highp>;
template struct tvec2<int32, highp>;
template struct tvec2<int64, highp>;
template struct tvec2<float32, highp>;
template struct tvec2<float64, highp>;
// tvec3 type explicit instantiation
template struct tvec3<uint8, lowp>;
template struct tvec3<uint16, lowp>;
template struct tvec3<uint32, lowp>;
template struct tvec3<uint64, lowp>;
template struct tvec3<int8, lowp>;
template struct tvec3<int16, lowp>;
template struct tvec3<int32, lowp>;
template struct tvec3<int64, lowp>;
template struct tvec3<float32, lowp>;
template struct tvec3<float64, lowp>;
template struct tvec3<uint8, mediump>;
template struct tvec3<uint16, mediump>;
template struct tvec3<uint32, mediump>;
template struct tvec3<uint64, mediump>;
template struct tvec3<int8, mediump>;
template struct tvec3<int16, mediump>;
template struct tvec3<int32, mediump>;
template struct tvec3<int64, mediump>;
template struct tvec3<float32, mediump>;
template struct tvec3<float64, mediump>;
template struct tvec3<uint8, highp>;
template struct tvec3<uint16, highp>;
template struct tvec3<uint32, highp>;
template struct tvec3<uint64, highp>;
template struct tvec3<int8, highp>;
template struct tvec3<int16, highp>;
template struct tvec3<int32, highp>;
template struct tvec3<int64, highp>;
template struct tvec3<float32, highp>;
template struct tvec3<float64, highp>;
// tvec4 type explicit instantiation
template struct tvec4<uint8, lowp>;
template struct tvec4<uint16, lowp>;
template struct tvec4<uint32, lowp>;
template struct tvec4<uint64, lowp>;
template struct tvec4<int8, lowp>;
template struct tvec4<int16, lowp>;
template struct tvec4<int32, lowp>;
template struct tvec4<int64, lowp>;
template struct tvec4<float32, lowp>;
template struct tvec4<float64, lowp>;
template struct tvec4<uint8, mediump>;
template struct tvec4<uint16, mediump>;
template struct tvec4<uint32, mediump>;
template struct tvec4<uint64, mediump>;
template struct tvec4<int8, mediump>;
template struct tvec4<int16, mediump>;
template struct tvec4<int32, mediump>;
template struct tvec4<int64, mediump>;
template struct tvec4<float32, mediump>;
template struct tvec4<float64, mediump>;
template struct tvec4<uint8, highp>;
template struct tvec4<uint16, highp>;
template struct tvec4<uint32, highp>;
template struct tvec4<uint64, highp>;
template struct tvec4<int8, highp>;
template struct tvec4<int16, highp>;
template struct tvec4<int32, highp>;
template struct tvec4<int64, highp>;
template struct tvec4<float32, highp>;
template struct tvec4<float64, highp>;
// tmat2x2 type explicit instantiation
template struct tmat2x2<float32, lowp>;
template struct tmat2x2<float64, lowp>;
template struct tmat2x2<float32, mediump>;
template struct tmat2x2<float64, mediump>;
template struct tmat2x2<float32, highp>;
template struct tmat2x2<float64, highp>;
// tmat2x3 type explicit instantiation
template struct tmat2x3<float32, lowp>;
template struct tmat2x3<float64, lowp>;
template struct tmat2x3<float32, mediump>;
template struct tmat2x3<float64, mediump>;
template struct tmat2x3<float32, highp>;
template struct tmat2x3<float64, highp>;
// tmat2x4 type explicit instantiation
template struct tmat2x4<float32, lowp>;
template struct tmat2x4<float64, lowp>;
template struct tmat2x4<float32, mediump>;
template struct tmat2x4<float64, mediump>;
template struct tmat2x4<float32, highp>;
template struct tmat2x4<float64, highp>;
// tmat3x2 type explicit instantiation
template struct tmat3x2<float32, lowp>;
template struct tmat3x2<float64, lowp>;
template struct tmat3x2<float32, mediump>;
template struct tmat3x2<float64, mediump>;
template struct tmat3x2<float32, highp>;
template struct tmat3x2<float64, highp>;
// tmat3x3 type explicit instantiation
template struct tmat3x3<float32, lowp>;
template struct tmat3x3<float64, lowp>;
template struct tmat3x3<float32, mediump>;
template struct tmat3x3<float64, mediump>;
template struct tmat3x3<float32, highp>;
template struct tmat3x3<float64, highp>;
// tmat3x4 type explicit instantiation
template struct tmat3x4<float32, lowp>;
template struct tmat3x4<float64, lowp>;
template struct tmat3x4<float32, mediump>;
template struct tmat3x4<float64, mediump>;
template struct tmat3x4<float32, highp>;
template struct tmat3x4<float64, highp>;
// tmat4x2 type explicit instantiation
template struct tmat4x2<float32, lowp>;
template struct tmat4x2<float64, lowp>;
template struct tmat4x2<float32, mediump>;
template struct tmat4x2<float64, mediump>;
template struct tmat4x2<float32, highp>;
template struct tmat4x2<float64, highp>;
// tmat4x3 type explicit instantiation
template struct tmat4x3<float32, lowp>;
template struct tmat4x3<float64, lowp>;
template struct tmat4x3<float32, mediump>;
template struct tmat4x3<float64, mediump>;
template struct tmat4x3<float32, highp>;
template struct tmat4x3<float64, highp>;
// tmat4x4 type explicit instantiation
template struct tmat4x4<float32, lowp>;
template struct tmat4x4<float64, lowp>;
template struct tmat4x4<float32, mediump>;
template struct tmat4x4<float64, mediump>;
template struct tmat4x4<float32, highp>;
template struct tmat4x4<float64, highp>;
// tquat type explicit instantiation
template struct tquat<float32, lowp>;
template struct tquat<float64, lowp>;
template struct tquat<float32, mediump>;
template struct tquat<float64, mediump>;
template struct tquat<float32, highp>;
template struct tquat<float64, highp>;
//tdualquat type explicit instantiation
template struct tdualquat<float32, lowp>;
template struct tdualquat<float64, lowp>;
template struct tdualquat<float32, mediump>;
template struct tdualquat<float64, mediump>;
template struct tdualquat<float32, highp>;
template struct tdualquat<float64, highp>;
}//namespace glm
///////////////////////////////////////////////////////////////////////////////////
/// OpenGL Mathematics (glm.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
/// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
/// copies of the Software, and to permit persons to whom the Software is
/// furnished to do so, subject to the following conditions:
///
/// The above copyright notice and this permission notice shall be included in
/// all copies or substantial portions of the Software.
///
/// 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
/// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
/// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
/// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
/// THE SOFTWARE.
///
/// @ref core
/// @file glm/detail/intrinsic_common.hpp
/// @date 2009-05-11 / 2011-06-15
/// @author Christophe Riccio
///////////////////////////////////////////////////////////////////////////////////
#pragma once
#include "setup.hpp"
#if(!(GLM_ARCH & GLM_ARCH_SSE2))
# error "SSE2 instructions not supported or enabled"
#else
namespace glm{
namespace detail
{
__m128 sse_abs_ps(__m128 x);
__m128 sse_sgn_ps(__m128 x);
//floor
__m128 sse_flr_ps(__m128 v);
//trunc
__m128 sse_trc_ps(__m128 v);
//round
__m128 sse_nd_ps(__m128 v);
//roundEven
__m128 sse_rde_ps(__m128 v);
__m128 sse_rnd_ps(__m128 x);
__m128 sse_ceil_ps(__m128 v);
__m128 sse_frc_ps(__m128 x);
__m128 sse_mod_ps(__m128 x, __m128 y);
__m128 sse_modf_ps(__m128 x, __m128i & i);
//GLM_FUNC_QUALIFIER __m128 sse_min_ps(__m128 x, __m128 y)
//GLM_FUNC_QUALIFIER __m128 sse_max_ps(__m128 x, __m128 y)
__m128 sse_clp_ps(__m128 v, __m128 minVal, __m128 maxVal);
__m128 sse_mix_ps(__m128 v1, __m128 v2, __m128 a);
__m128 sse_stp_ps(__m128 edge, __m128 x);
__m128 sse_ssp_ps(__m128 edge0, __m128 edge1, __m128 x);
__m128 sse_nan_ps(__m128 x);
__m128 sse_inf_ps(__m128 x);
}//namespace detail
}//namespace glm
#include "intrinsic_common.inl"
#endif//GLM_ARCH
///////////////////////////////////////////////////////////////////////////////////
/// OpenGL Mathematics (glm.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
/// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
/// copies of the Software, and to permit persons to whom the Software is
/// furnished to do so, subject to the following conditions:
///
/// The above copyright notice and this permission notice shall be included in
/// all copies or substantial portions of the Software.
///
/// 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
/// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
/// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
/// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
/// THE SOFTWARE.
///
/// @ref core
/// @file glm/detail/intrinsic_common.inl
/// @date 2009-05-08 / 2011-06-15
/// @author Christophe Riccio
///////////////////////////////////////////////////////////////////////////////////
namespace glm{
namespace detail{
#if(GLM_COMPILER & GLM_COMPILER_VC)
#pragma warning(push)
#pragma warning(disable : 4510 4512 4610)
#endif
union ieee754_QNAN
{
const float f;
struct i
{
const unsigned int mantissa:23, exp:8, sign:1;
};
ieee754_QNAN() : f(0.0)/*, mantissa(0x7FFFFF), exp(0xFF), sign(0x0)*/ {}
};
#if(GLM_COMPILER & GLM_COMPILER_VC)
#pragma warning(pop)
#endif
static const __m128 GLM_VAR_USED zero = _mm_setzero_ps();
static const __m128 GLM_VAR_USED one = _mm_set_ps1(1.0f);
static const __m128 GLM_VAR_USED minus_one = _mm_set_ps1(-1.0f);
static const __m128 GLM_VAR_USED two = _mm_set_ps1(2.0f);
static const __m128 GLM_VAR_USED three = _mm_set_ps1(3.0f);
static const __m128 GLM_VAR_USED pi = _mm_set_ps1(3.1415926535897932384626433832795f);
static const __m128 GLM_VAR_USED hundred_eighty = _mm_set_ps1(180.f);
static const __m128 GLM_VAR_USED pi_over_hundred_eighty = _mm_set_ps1(0.017453292519943295769236907684886f);
static const __m128 GLM_VAR_USED hundred_eighty_over_pi = _mm_set_ps1(57.295779513082320876798154814105f);
static const ieee754_QNAN absMask;
static const __m128 GLM_VAR_USED abs4Mask = _mm_set_ps1(absMask.f);
static const __m128 GLM_VAR_USED _epi32_sign_mask = _mm_castsi128_ps(_mm_set1_epi32(static_cast<int>(0x80000000)));
//static const __m128 GLM_VAR_USED _epi32_inv_sign_mask = _mm_castsi128_ps(_mm_set1_epi32(0x7FFFFFFF));
//static const __m128 GLM_VAR_USED _epi32_mant_mask = _mm_castsi128_ps(_mm_set1_epi32(0x7F800000));
//static const __m128 GLM_VAR_USED _epi32_inv_mant_mask = _mm_castsi128_ps(_mm_set1_epi32(0x807FFFFF));
//static const __m128 GLM_VAR_USED _epi32_min_norm_pos = _mm_castsi128_ps(_mm_set1_epi32(0x00800000));
static const __m128 GLM_VAR_USED _epi32_0 = _mm_set_ps1(0);
static const __m128 GLM_VAR_USED _epi32_1 = _mm_set_ps1(1);
static const __m128 GLM_VAR_USED _epi32_2 = _mm_set_ps1(2);
static const __m128 GLM_VAR_USED _epi32_3 = _mm_set_ps1(3);
static const __m128 GLM_VAR_USED _epi32_4 = _mm_set_ps1(4);
static const __m128 GLM_VAR_USED _epi32_5 = _mm_set_ps1(5);
static const __m128 GLM_VAR_USED _epi32_6 = _mm_set_ps1(6);
static const __m128 GLM_VAR_USED _epi32_7 = _mm_set_ps1(7);
static const __m128 GLM_VAR_USED _epi32_8 = _mm_set_ps1(8);
static const __m128 GLM_VAR_USED _epi32_9 = _mm_set_ps1(9);
static const __m128 GLM_VAR_USED _epi32_127 = _mm_set_ps1(127);
//static const __m128 GLM_VAR_USED _epi32_ninf = _mm_castsi128_ps(_mm_set1_epi32(0xFF800000));
//static const __m128 GLM_VAR_USED _epi32_pinf = _mm_castsi128_ps(_mm_set1_epi32(0x7F800000));
static const __m128 GLM_VAR_USED _ps_1_3 = _mm_set_ps1(0.33333333333333333333333333333333f);
static const __m128 GLM_VAR_USED _ps_0p5 = _mm_set_ps1(0.5f);
static const __m128 GLM_VAR_USED _ps_1 = _mm_set_ps1(1.0f);
static const __m128 GLM_VAR_USED _ps_m1 = _mm_set_ps1(-1.0f);
static const __m128 GLM_VAR_USED _ps_2 = _mm_set_ps1(2.0f);
static const __m128 GLM_VAR_USED _ps_3 = _mm_set_ps1(3.0f);
static const __m128 GLM_VAR_USED _ps_127 = _mm_set_ps1(127.0f);
static const __m128 GLM_VAR_USED _ps_255 = _mm_set_ps1(255.0f);
static const __m128 GLM_VAR_USED _ps_2pow23 = _mm_set_ps1(8388608.0f);
static const __m128 GLM_VAR_USED _ps_1_0_0_0 = _mm_set_ps(1.0f, 0.0f, 0.0f, 0.0f);
static const __m128 GLM_VAR_USED _ps_0_1_0_0 = _mm_set_ps(0.0f, 1.0f, 0.0f, 0.0f);
static const __m128 GLM_VAR_USED _ps_0_0_1_0 = _mm_set_ps(0.0f, 0.0f, 1.0f, 0.0f);
static const __m128 GLM_VAR_USED _ps_0_0_0_1 = _mm_set_ps(0.0f, 0.0f, 0.0f, 1.0f);
static const __m128 GLM_VAR_USED _ps_pi = _mm_set_ps1(3.1415926535897932384626433832795f);
static const __m128 GLM_VAR_USED _ps_pi2 = _mm_set_ps1(6.283185307179586476925286766560f);
static const __m128 GLM_VAR_USED _ps_2_pi = _mm_set_ps1(0.63661977236758134307553505349006f);
static const __m128 GLM_VAR_USED _ps_pi_2 = _mm_set_ps1(1.5707963267948966192313216916398f);
static const __m128 GLM_VAR_USED _ps_4_pi = _mm_set_ps1(1.2732395447351626861510701069801f);
static const __m128 GLM_VAR_USED _ps_pi_4 = _mm_set_ps1(0.78539816339744830961566084581988f);
static const __m128 GLM_VAR_USED _ps_sincos_p0 = _mm_set_ps1(0.15707963267948963959e1f);
static const __m128 GLM_VAR_USED _ps_sincos_p1 = _mm_set_ps1(-0.64596409750621907082e0f);
static const __m128 GLM_VAR_USED _ps_sincos_p2 = _mm_set_ps1(0.7969262624561800806e-1f);
static const __m128 GLM_VAR_USED _ps_sincos_p3 = _mm_set_ps1(-0.468175413106023168e-2f);
static const __m128 GLM_VAR_USED _ps_tan_p0 = _mm_set_ps1(-1.79565251976484877988e7f);
static const __m128 GLM_VAR_USED _ps_tan_p1 = _mm_set_ps1(1.15351664838587416140e6f);
static const __m128 GLM_VAR_USED _ps_tan_p2 = _mm_set_ps1(-1.30936939181383777646e4f);
static const __m128 GLM_VAR_USED _ps_tan_q0 = _mm_set_ps1(-5.38695755929454629881e7f);
static const __m128 GLM_VAR_USED _ps_tan_q1 = _mm_set_ps1(2.50083801823357915839e7f);
static const __m128 GLM_VAR_USED _ps_tan_q2 = _mm_set_ps1(-1.32089234440210967447e6f);
static const __m128 GLM_VAR_USED _ps_tan_q3 = _mm_set_ps1(1.36812963470692954678e4f);
static const __m128 GLM_VAR_USED _ps_tan_poleval = _mm_set_ps1(3.68935e19f);
static const __m128 GLM_VAR_USED _ps_atan_t0 = _mm_set_ps1(-0.91646118527267623468e-1f);
static const __m128 GLM_VAR_USED _ps_atan_t1 = _mm_set_ps1(-0.13956945682312098640e1f);
static const __m128 GLM_VAR_USED _ps_atan_t2 = _mm_set_ps1(-0.94393926122725531747e2f);
static const __m128 GLM_VAR_USED _ps_atan_t3 = _mm_set_ps1(0.12888383034157279340e2f);
static const __m128 GLM_VAR_USED _ps_atan_s0 = _mm_set_ps1(0.12797564625607904396e1f);
static const __m128 GLM_VAR_USED _ps_atan_s1 = _mm_set_ps1(0.21972168858277355914e1f);
static const __m128 GLM_VAR_USED _ps_atan_s2 = _mm_set_ps1(0.68193064729268275701e1f);
static const __m128 GLM_VAR_USED _ps_atan_s3 = _mm_set_ps1(0.28205206687035841409e2f);
static const __m128 GLM_VAR_USED _ps_exp_hi = _mm_set_ps1(88.3762626647949f);
static const __m128 GLM_VAR_USED _ps_exp_lo = _mm_set_ps1(-88.3762626647949f);
static const __m128 GLM_VAR_USED _ps_exp_rln2 = _mm_set_ps1(1.4426950408889634073599f);
static const __m128 GLM_VAR_USED _ps_exp_p0 = _mm_set_ps1(1.26177193074810590878e-4f);
static const __m128 GLM_VAR_USED _ps_exp_p1 = _mm_set_ps1(3.02994407707441961300e-2f);
static const __m128 GLM_VAR_USED _ps_exp_q0 = _mm_set_ps1(3.00198505138664455042e-6f);
static const __m128 GLM_VAR_USED _ps_exp_q1 = _mm_set_ps1(2.52448340349684104192e-3f);
static const __m128 GLM_VAR_USED _ps_exp_q2 = _mm_set_ps1(2.27265548208155028766e-1f);
static const __m128 GLM_VAR_USED _ps_exp_q3 = _mm_set_ps1(2.00000000000000000009e0f);
static const __m128 GLM_VAR_USED _ps_exp_c1 = _mm_set_ps1(6.93145751953125e-1f);
static const __m128 GLM_VAR_USED _ps_exp_c2 = _mm_set_ps1(1.42860682030941723212e-6f);
static const __m128 GLM_VAR_USED _ps_exp2_hi = _mm_set_ps1(127.4999961853f);
static const __m128 GLM_VAR_USED _ps_exp2_lo = _mm_set_ps1(-127.4999961853f);
static const __m128 GLM_VAR_USED _ps_exp2_p0 = _mm_set_ps1(2.30933477057345225087e-2f);
static const __m128 GLM_VAR_USED _ps_exp2_p1 = _mm_set_ps1(2.02020656693165307700e1f);
static const __m128 GLM_VAR_USED _ps_exp2_p2 = _mm_set_ps1(1.51390680115615096133e3f);
static const __m128 GLM_VAR_USED _ps_exp2_q0 = _mm_set_ps1(2.33184211722314911771e2f);
static const __m128 GLM_VAR_USED _ps_exp2_q1 = _mm_set_ps1(4.36821166879210612817e3f);
static const __m128 GLM_VAR_USED _ps_log_p0 = _mm_set_ps1(-7.89580278884799154124e-1f);
static const __m128 GLM_VAR_USED _ps_log_p1 = _mm_set_ps1(1.63866645699558079767e1f);
static const __m128 GLM_VAR_USED _ps_log_p2 = _mm_set_ps1(-6.41409952958715622951e1f);
static const __m128 GLM_VAR_USED _ps_log_q0 = _mm_set_ps1(-3.56722798256324312549e1f);
static const __m128 GLM_VAR_USED _ps_log_q1 = _mm_set_ps1(3.12093766372244180303e2f);
static const __m128 GLM_VAR_USED _ps_log_q2 = _mm_set_ps1(-7.69691943550460008604e2f);
static const __m128 GLM_VAR_USED _ps_log_c0 = _mm_set_ps1(0.693147180559945f);
static const __m128 GLM_VAR_USED _ps_log2_c0 = _mm_set_ps1(1.44269504088896340735992f);
GLM_FUNC_QUALIFIER __m128 sse_abs_ps(__m128 x)
{
return _mm_and_ps(glm::detail::abs4Mask, x);
}
GLM_FUNC_QUALIFIER __m128 sse_sgn_ps(__m128 x)
{
__m128 Neg = _mm_set1_ps(-1.0f);
__m128 Pos = _mm_set1_ps(1.0f);
__m128 Cmp0 = _mm_cmplt_ps(x, zero);
__m128 Cmp1 = _mm_cmpgt_ps(x, zero);
__m128 And0 = _mm_and_ps(Cmp0, Neg);
__m128 And1 = _mm_and_ps(Cmp1, Pos);
return _mm_or_ps(And0, And1);
}
//floor
GLM_FUNC_QUALIFIER __m128 sse_flr_ps(__m128 x)
{
__m128 rnd0 = sse_rnd_ps(x);
__m128 cmp0 = _mm_cmplt_ps(x, rnd0);
__m128 and0 = _mm_and_ps(cmp0, glm::detail::_ps_1);
__m128 sub0 = _mm_sub_ps(rnd0, and0);
return sub0;
}
//trunc
/*
GLM_FUNC_QUALIFIER __m128 _mm_trc_ps(__m128 v)
{
return __m128();
}
*/
//round
GLM_FUNC_QUALIFIER __m128 sse_rnd_ps(__m128 x)
{
__m128 and0 = _mm_and_ps(glm::detail::_epi32_sign_mask, x);
__m128 or0 = _mm_or_ps(and0, glm::detail::_ps_2pow23);
__m128 add0 = _mm_add_ps(x, or0);
__m128 sub0 = _mm_sub_ps(add0, or0);
return sub0;
}
//roundEven
GLM_FUNC_QUALIFIER __m128 sse_rde_ps(__m128 x)
{
__m128 and0 = _mm_and_ps(glm::detail::_epi32_sign_mask, x);
__m128 or0 = _mm_or_ps(and0, glm::detail::_ps_2pow23);
__m128 add0 = _mm_add_ps(x, or0);
__m128 sub0 = _mm_sub_ps(add0, or0);
return sub0;
}
GLM_FUNC_QUALIFIER __m128 sse_ceil_ps(__m128 x)
{
__m128 rnd0 = sse_rnd_ps(x);
__m128 cmp0 = _mm_cmpgt_ps(x, rnd0);
__m128 and0 = _mm_and_ps(cmp0, glm::detail::_ps_1);
__m128 add0 = _mm_add_ps(rnd0, and0);
return add0;
}
GLM_FUNC_QUALIFIER __m128 sse_frc_ps(__m128 x)
{
__m128 flr0 = sse_flr_ps(x);
__m128 sub0 = _mm_sub_ps(x, flr0);
return sub0;
}
GLM_FUNC_QUALIFIER __m128 sse_mod_ps(__m128 x, __m128 y)
{
__m128 div0 = _mm_div_ps(x, y);
__m128 flr0 = sse_flr_ps(div0);
__m128 mul0 = _mm_mul_ps(y, flr0);
__m128 sub0 = _mm_sub_ps(x, mul0);
return sub0;
}
/// TODO
/*
GLM_FUNC_QUALIFIER __m128 sse_modf_ps(__m128 x, __m128i & i)
{
__m128 empty;
return empty;
}
*/
//GLM_FUNC_QUALIFIER __m128 _mm_min_ps(__m128 x, __m128 y)
//GLM_FUNC_QUALIFIER __m128 _mm_max_ps(__m128 x, __m128 y)
GLM_FUNC_QUALIFIER __m128 sse_clp_ps(__m128 v, __m128 minVal, __m128 maxVal)
{
__m128 min0 = _mm_min_ps(v, maxVal);
__m128 max0 = _mm_max_ps(min0, minVal);
return max0;
}
GLM_FUNC_QUALIFIER __m128 sse_mix_ps(__m128 v1, __m128 v2, __m128 a)
{
__m128 sub0 = _mm_sub_ps(glm::detail::one, a);
__m128 mul0 = _mm_mul_ps(v1, sub0);
__m128 mul1 = _mm_mul_ps(v2, a);
__m128 add0 = _mm_add_ps(mul0, mul1);
return add0;
}
GLM_FUNC_QUALIFIER __m128 sse_stp_ps(__m128 edge, __m128 x)
{
__m128 cmp = _mm_cmple_ps(x, edge);
if(_mm_movemask_ps(cmp) == 0)
return glm::detail::one;
else
return glm::detail::zero;
}
GLM_FUNC_QUALIFIER __m128 sse_ssp_ps(__m128 edge0, __m128 edge1, __m128 x)
{
__m128 sub0 = _mm_sub_ps(x, edge0);
__m128 sub1 = _mm_sub_ps(edge1, edge0);
__m128 div0 = _mm_sub_ps(sub0, sub1);
__m128 clp0 = sse_clp_ps(div0, glm::detail::zero, glm::detail::one);
__m128 mul0 = _mm_mul_ps(glm::detail::two, clp0);
__m128 sub2 = _mm_sub_ps(glm::detail::three, mul0);
__m128 mul1 = _mm_mul_ps(clp0, clp0);
__m128 mul2 = _mm_mul_ps(mul1, sub2);
return mul2;
}
/// \todo
//GLM_FUNC_QUALIFIER __m128 sse_nan_ps(__m128 x)
//{
// __m128 empty;
// return empty;
//}
/// \todo
//GLM_FUNC_QUALIFIER __m128 sse_inf_ps(__m128 x)
//{
// __m128 empty;
// return empty;
//}
// SSE scalar reciprocal sqrt using rsqrt op, plus one Newton-Rhaphson iteration
// By Elan Ruskin, http://assemblyrequired.crashworks.org/
GLM_FUNC_QUALIFIER __m128 sse_sqrt_wip_ss(__m128 const & x)
{
__m128 const recip = _mm_rsqrt_ss(x); // "estimate" opcode
__m128 const half = _mm_set_ps1(0.5f);
__m128 const halfrecip = _mm_mul_ss(half, recip);
__m128 const threeminus_xrr = _mm_sub_ss(three, _mm_mul_ss(x, _mm_mul_ss (recip, recip)));
return _mm_mul_ss(halfrecip, threeminus_xrr);
}
}//namespace detail
}//namespace glms
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment