Merge branch '0.9.3' into swizzle

master
Christophe Riccio ago%!(EXTRA string=14 years)
commit dc7d8f5c0c
  1. 159
      glm/core/_vectorize.hpp
  2. 513
      glm/core/func_common.inl
  3. 260
      glm/core/func_exponential.inl
  4. 2
      glm/core/func_geometric.inl
  5. 37
      glm/core/func_integer.inl
  6. 2
      glm/core/func_matrix.inl
  7. 235
      glm/core/func_packing.inl
  8. 943
      glm/core/func_trigonometric.inl
  9. 1946
      glm/gtc/half_float.inl
  10. 88
      glm/gtc/matrix_access.inl
  11. 253
      glm/gtc/matrix_inverse.inl
  12. 765
      glm/gtc/matrix_transform.inl
  13. 1665
      glm/gtc/noise.inl
  14. 4
      glm/gtc/quaternion.inl
  15. 290
      glm/gtc/random.inl
  16. 248
      glm/gtc/swizzle.inl
  17. 353
      glm/gtx/fast_square_root.inl

@ -0,0 +1,159 @@
///////////////////////////////////////////////////////////////////////////////////
/// OpenGL Mathematics (glm.g-truc.net)
///
/// Copyright (c) 2005 - 2011 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/core/_vectorize.hpp
/// @date 2011-10-14 / 2011-10-14
/// @author Christophe Riccio
///////////////////////////////////////////////////////////////////////////////////
#define VECTORIZE2_VEC(func) \
template <typename T> \
GLM_FUNC_QUALIFIER detail::tvec2<T> func( \
detail::tvec2<T> const & v) \
{ \
return detail::tvec2<T>( \
func(v.x), \
func(v.y)); \
}
#define VECTORIZE3_VEC(func) \
template <typename T> \
GLM_FUNC_QUALIFIER detail::tvec3<T> func( \
detail::tvec3<T> const & v) \
{ \
return detail::tvec3<T>( \
func(v.x), \
func(v.y), \
func(v.z)); \
}
#define VECTORIZE4_VEC(func) \
template <typename T> \
GLM_FUNC_QUALIFIER detail::tvec4<T> func( \
detail::tvec4<T> const & v) \
{ \
return detail::tvec4<T>( \
func(v.x), \
func(v.y), \
func(v.z), \
func(v.w)); \
}
#define VECTORIZE_VEC(func) \
VECTORIZE2_VEC(func) \
VECTORIZE3_VEC(func) \
VECTORIZE4_VEC(func)
#define VECTORIZE2_VEC_SCA(func) \
template <typename T> \
GLM_FUNC_QUALIFIER detail::tvec2<T> func \
( \
detail::tvec2<T> const & x, \
typename detail::tvec2<T>::value_type const & y \
) \
{ \
return detail::tvec2<T>( \
func(x.x, y), \
func(x.y, y)); \
}
#define VECTORIZE3_VEC_SCA(func) \
template <typename T> \
GLM_FUNC_QUALIFIER detail::tvec3<T> func \
( \
detail::tvec3<T> const & x, \
typename detail::tvec3<T>::value_type const & y \
) \
{ \
return detail::tvec3<T>( \
func(x.x, y), \
func(x.y, y), \
func(x.z, y)); \
}
#define VECTORIZE4_VEC_SCA(func) \
template <typename T> \
GLM_FUNC_QUALIFIER detail::tvec4<T> func \
( \
detail::tvec4<T> const & x, \
typename detail::tvec4<T>::value_type const & y \
) \
{ \
return detail::tvec4<T>( \
func(x.x, y), \
func(x.y, y), \
func(x.z, y), \
func(x.w, y)); \
}
#define VECTORIZE_VEC_SCA(func) \
VECTORIZE2_VEC_SCA(func) \
VECTORIZE3_VEC_SCA(func) \
VECTORIZE4_VEC_SCA(func)
#define VECTORIZE2_VEC_VEC(func) \
template <typename T> \
GLM_FUNC_QUALIFIER detail::tvec2<T> func \
( \
detail::tvec2<T> const & x, \
detail::tvec2<T> const & y \
) \
{ \
return detail::tvec2<T>( \
func(x.x, y.x), \
func(x.y, y.y)); \
}
#define VECTORIZE3_VEC_VEC(func) \
template <typename T> \
GLM_FUNC_QUALIFIER detail::tvec3<T> func \
( \
detail::tvec3<T> const & x, \
detail::tvec3<T> const & y \
) \
{ \
return detail::tvec3<T>( \
func(x.x, y.x), \
func(x.y, y.y), \
func(x.z, y.z)); \
}
#define VECTORIZE4_VEC_VEC(func) \
template <typename T> \
GLM_FUNC_QUALIFIER detail::tvec4<T> func \
( \
detail::tvec4<T> const & x, \
detail::tvec4<T> const & y \
) \
{ \
return detail::tvec4<T>( \
func(x.x, y.x), \
func(x.y, y.y), \
func(x.z, y.z), \
func(x.w, y.w)); \
}
#define VECTORIZE_VEC_VEC(func) \
VECTORIZE2_VEC_VEC(func) \
VECTORIZE3_VEC_VEC(func) \
VECTORIZE4_VEC_VEC(func)

@ -26,6 +26,8 @@
/// @author Christophe Riccio /// @author Christophe Riccio
/////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////
#include "_vectorize.hpp"
namespace glm{ namespace glm{
namespace detail namespace detail
{ {
@ -60,56 +62,23 @@ namespace detail
// abs // abs
template <typename genFIType> template <typename genFIType>
GLM_FUNC_QUALIFIER genFIType abs( GLM_FUNC_QUALIFIER genFIType abs
genFIType const & x) (
genFIType const & x
)
{ {
return detail::Abs_<genFIType, std::numeric_limits<genFIType>::is_signed>::get(x); return detail::Abs_<genFIType, std::numeric_limits<genFIType>::is_signed>::get(x);
} }
//template <typename T> VECTORIZE_VEC(abs)
//GLM_FUNC_QUALIFIER detail::tvec1<T> abs(
// detail::tvec1<T> const & v)
//{
// return detail::tvec1<T>(
// abs(v.x));
//}
template <typename T>
GLM_FUNC_QUALIFIER detail::tvec2<T> abs(
detail::tvec2<T> const & v)
{
return detail::tvec2<T>(
abs(v.x),
abs(v.y));
}
template <typename T>
GLM_FUNC_QUALIFIER detail::tvec3<T> abs(
detail::tvec3<T> const & v)
{
return detail::tvec3<T>(
abs(v.x),
abs(v.y),
abs(v.z));
}
template <typename T>
GLM_FUNC_QUALIFIER detail::tvec4<T> abs(
detail::tvec4<T> const & v)
{
return detail::tvec4<T>(
abs(v.x),
abs(v.y),
abs(v.z),
abs(v.w));
}
// sign // sign
//Try something like based on x >> 31 to get the sign bit //Try something like based on x >> 31 to get the sign bit
template <typename genFIType> template <typename genFIType>
GLM_FUNC_QUALIFIER genFIType sign( GLM_FUNC_QUALIFIER genFIType sign
genFIType const & x) (
genFIType const & x
)
{ {
GLM_STATIC_ASSERT( GLM_STATIC_ASSERT(
detail::type<genFIType>::is_float || detail::type<genFIType>::is_float ||
@ -125,35 +94,7 @@ namespace detail
return result; return result;
} }
template <typename valFIType> VECTORIZE_VEC(sign)
GLM_FUNC_QUALIFIER detail::tvec2<valFIType> sign(
detail::tvec2<valFIType> const & x)
{
return detail::tvec2<valFIType>(
sign(x.x),
sign(x.y));
}
template <typename valFIType>
GLM_FUNC_QUALIFIER detail::tvec3<valFIType> sign(
detail::tvec3<valFIType> const & x)
{
return detail::tvec3<valFIType>(
sign(x.x),
sign(x.y),
sign(x.z));
}
template <typename valFIType>
GLM_FUNC_QUALIFIER detail::tvec4<valFIType> sign(
detail::tvec4<valFIType> const & x)
{
return detail::tvec4<valFIType>(
sign(x.x),
sign(x.y),
sign(x.z),
sign(x.w));
}
// floor // floor
template <> template <>
@ -170,32 +111,7 @@ namespace detail
return ::std::floor(x); return ::std::floor(x);
} }
template <typename valType> VECTORIZE_VEC(floor)
GLM_FUNC_QUALIFIER detail::tvec2<valType> floor(detail::tvec2<valType> const& x)
{
return detail::tvec2<valType>(
floor(x.x),
floor(x.y));
}
template <typename valType>
GLM_FUNC_QUALIFIER detail::tvec3<valType> floor(detail::tvec3<valType> const& x)
{
return detail::tvec3<valType>(
floor(x.x),
floor(x.y),
floor(x.z));
}
template <typename valType>
GLM_FUNC_QUALIFIER detail::tvec4<valType> floor(detail::tvec4<valType> const& x)
{
return detail::tvec4<valType>(
floor(x.x),
floor(x.y),
floor(x.z),
floor(x.w));
}
// trunc // trunc
template <typename genType> template <typename genType>
@ -205,32 +121,7 @@ namespace detail
return x < 0 ? -floor(-x) : floor(x); return x < 0 ? -floor(-x) : floor(x);
} }
template <typename valType> VECTORIZE_VEC(trunc)
GLM_FUNC_QUALIFIER detail::tvec2<valType> trunc(detail::tvec2<valType> const & x)
{
return detail::tvec2<valType>(
trunc(x.x),
trunc(x.y));
}
template <typename valType>
GLM_FUNC_QUALIFIER detail::tvec3<valType> trunc(detail::tvec3<valType> const & x)
{
return detail::tvec3<valType>(
trunc(x.x),
trunc(x.y),
trunc(x.z));
}
template <typename valType>
GLM_FUNC_QUALIFIER detail::tvec4<valType> trunc(detail::tvec4<valType> const & x)
{
return detail::tvec4<valType>(
trunc(x.x),
trunc(x.y),
trunc(x.z),
trunc(x.w));
}
// round // round
template <typename genType> template <typename genType>
@ -243,32 +134,8 @@ namespace detail
return genType(int(x + genType(0.5))); return genType(int(x + genType(0.5)));
} }
template <typename valType> VECTORIZE_VEC(round)
GLM_FUNC_QUALIFIER detail::tvec2<valType> round(detail::tvec2<valType> const& x)
{
return detail::tvec2<valType>(
round(x.x),
round(x.y));
}
template <typename valType>
GLM_FUNC_QUALIFIER detail::tvec3<valType> round(detail::tvec3<valType> const& x)
{
return detail::tvec3<valType>(
round(x.x),
round(x.y),
round(x.z));
}
template <typename valType>
GLM_FUNC_QUALIFIER detail::tvec4<valType> round(detail::tvec4<valType> const& x)
{
return detail::tvec4<valType>(
round(x.x),
round(x.y),
round(x.z),
round(x.w));
}
/* /*
// roundEven // roundEven
template <typename genType> template <typename genType>
@ -294,32 +161,7 @@ namespace detail
return genType(int(x + RoundValue)); return genType(int(x + RoundValue));
} }
template <typename valType> VECTORIZE_VEC(roundEven)
GLM_FUNC_QUALIFIER detail::tvec2<valType> roundEven(detail::tvec2<valType> const& x)
{
return detail::tvec2<valType>(
roundEven(x.x),
roundEven(x.y));
}
template <typename valType>
GLM_FUNC_QUALIFIER detail::tvec3<valType> roundEven(detail::tvec3<valType> const& x)
{
return detail::tvec3<valType>(
roundEven(x.x),
roundEven(x.y),
roundEven(x.z));
}
template <typename valType>
GLM_FUNC_QUALIFIER detail::tvec4<valType> roundEven(detail::tvec4<valType> const& x)
{
return detail::tvec4<valType>(
roundEven(x.x),
roundEven(x.y),
roundEven(x.z),
roundEven(x.w));
}
// ceil // ceil
template <typename genType> template <typename genType>
@ -330,32 +172,7 @@ namespace detail
return ::std::ceil(x); return ::std::ceil(x);
} }
template <typename valType> VECTORIZE_VEC(ceil)
GLM_FUNC_QUALIFIER detail::tvec2<valType> ceil(detail::tvec2<valType> const & x)
{
return detail::tvec2<valType>(
ceil(x.x),
ceil(x.y));
}
template <typename valType>
GLM_FUNC_QUALIFIER detail::tvec3<valType> ceil(detail::tvec3<valType> const & x)
{
return detail::tvec3<valType>(
ceil(x.x),
ceil(x.y),
ceil(x.z));
}
template <typename valType>
GLM_FUNC_QUALIFIER detail::tvec4<valType> ceil(detail::tvec4<valType> const & x)
{
return detail::tvec4<valType>(
ceil(x.x),
ceil(x.y),
ceil(x.z),
ceil(x.w));
}
// fract // fract
template <typename genType> template <typename genType>
@ -369,41 +186,7 @@ namespace detail
return x - ::std::floor(x); return x - ::std::floor(x);
} }
template <typename valType> VECTORIZE_VEC(fract)
GLM_FUNC_QUALIFIER detail::tvec2<valType> fract
(
detail::tvec2<valType> const & x
)
{
return detail::tvec2<valType>(
fract(x.x),
fract(x.y));
}
template <typename valType>
GLM_FUNC_QUALIFIER detail::tvec3<valType> fract
(
detail::tvec3<valType> const & x
)
{
return detail::tvec3<valType>(
fract(x.x),
fract(x.y),
fract(x.z));
}
template <typename valType>
GLM_FUNC_QUALIFIER detail::tvec4<valType> fract
(
detail::tvec4<valType> const & x
)
{
return detail::tvec4<valType>(
fract(x.x),
fract(x.y),
fract(x.z),
fract(x.w));
}
// mod // mod
template <typename genType> template <typename genType>
@ -418,83 +201,8 @@ namespace detail
return x - y * floor(x / y); return x - y * floor(x / y);
} }
template <typename T> VECTORIZE_VEC_SCA(mod)
GLM_FUNC_QUALIFIER detail::tvec2<T> mod VECTORIZE_VEC_VEC(mod)
(
detail::tvec2<T> const & x,
typename detail::tvec2<T>::value_type const & y
)
{
return detail::tvec2<T>(
mod(x.x, y),
mod(x.y, y));
}
template <typename T>
GLM_FUNC_QUALIFIER detail::tvec3<T> mod
(
detail::tvec3<T> const & x,
typename detail::tvec3<T>::value_type const & y
)
{
return detail::tvec3<T>(
mod(x.x, y),
mod(x.y, y),
mod(x.z, y));
}
template <typename T>
GLM_FUNC_QUALIFIER detail::tvec4<T> mod
(
detail::tvec4<T> const & x,
typename detail::tvec4<T>::value_type const & y
)
{
return detail::tvec4<T>(
mod(x.x, y),
mod(x.y, y),
mod(x.z, y),
mod(x.w, y));
}
template <typename T>
GLM_FUNC_QUALIFIER detail::tvec2<T> mod
(
detail::tvec2<T> const & x,
detail::tvec2<T> const & y
)
{
return detail::tvec2<T>(
mod(x.x, y.x),
mod(x.y, y.y));
}
template <typename T>
GLM_FUNC_QUALIFIER detail::tvec3<T> mod
(
detail::tvec3<T> const & x,
detail::tvec3<T> const & y
)
{
return detail::tvec3<T>(
mod(x.x, y.x),
mod(x.y, y.y),
mod(x.z, y.z));
}
template <typename T>
GLM_FUNC_QUALIFIER detail::tvec4<T> mod
(
detail::tvec4<T> const & x,
detail::tvec4<T> const & y
)
{
return detail::tvec4<T>(
mod(x.x, y.x),
mod(x.y, y.y),
mod(x.z, y.z),
mod(x.w, y.w));
}
// modf // modf
template <typename genType> template <typename genType>
@ -515,39 +223,39 @@ namespace detail
GLM_FUNC_QUALIFIER detail::tvec2<valType> modf GLM_FUNC_QUALIFIER detail::tvec2<valType> modf
( (
detail::tvec2<valType> const & x, detail::tvec2<valType> const & x,
detail::tvec2<valType> const & y detail::tvec2<valType> & i
) )
{ {
return detail::tvec2<valType>( return detail::tvec2<valType>(
modf(x.x, y.x), modf(x.x, i.x),
modf(x.y, y.y)); modf(x.y, i.y));
} }
template <typename valType> template <typename valType>
GLM_FUNC_QUALIFIER detail::tvec3<valType> modf GLM_FUNC_QUALIFIER detail::tvec3<valType> modf
( (
detail::tvec3<valType> const & x, detail::tvec3<valType> const & x,
detail::tvec3<valType> const & y detail::tvec3<valType> & i
) )
{ {
return detail::tvec3<valType>( return detail::tvec3<valType>(
modf(x.x, y.x), modf(x.x, i.x),
modf(x.y, y.y), modf(x.y, i.y),
modf(x.z, y.z)); modf(x.z, i.z));
} }
template <typename valType> template <typename valType>
GLM_FUNC_QUALIFIER detail::tvec4<valType> modf GLM_FUNC_QUALIFIER detail::tvec4<valType> modf
( (
detail::tvec4<valType> const & x, detail::tvec4<valType> const & x,
detail::tvec4<valType> const & y detail::tvec4<valType> & i
) )
{ {
return detail::tvec4<valType>( return detail::tvec4<valType>(
modf(x.x, y.x), modf(x.x, i.x),
modf(x.y, y.y), modf(x.y, i.y),
modf(x.z, y.z), modf(x.z, i.z),
modf(x.w, y.w)); modf(x.w, i.w));
} }
//// Only valid if (INT_MIN <= x-y <= INT_MAX) //// Only valid if (INT_MIN <= x-y <= INT_MAX)
@ -574,83 +282,8 @@ namespace detail
return x < y ? x : y; return x < y ? x : y;
} }
template <typename T> VECTORIZE_VEC_SCA(min)
GLM_FUNC_QUALIFIER detail::tvec2<T> min VECTORIZE_VEC_VEC(min)
(
detail::tvec2<T> const & x,
typename detail::tvec2<T>::value_type const & y
)
{
return detail::tvec2<T>(
min(x.x, y),
min(x.y, y));
}
template <typename T>
GLM_FUNC_QUALIFIER detail::tvec3<T> min
(
detail::tvec3<T> const & x,
typename detail::tvec3<T>::value_type const & y
)
{
return detail::tvec3<T>(
min(x.x, y),
min(x.y, y),
min(x.z, y));
}
template <typename T>
GLM_FUNC_QUALIFIER detail::tvec4<T> min
(
detail::tvec4<T> const & x,
typename detail::tvec4<T>::value_type const & y
)
{
return detail::tvec4<T>(
min(x.x, y),
min(x.y, y),
min(x.z, y),
min(x.w, y));
}
template <typename T>
GLM_FUNC_QUALIFIER detail::tvec2<T> min
(
detail::tvec2<T> const & x,
detail::tvec2<T> const & y
)
{
return detail::tvec2<T>(
min(x.x, y.x),
min(x.y, y.y));
}
template <typename T>
GLM_FUNC_QUALIFIER detail::tvec3<T> min
(
detail::tvec3<T> const & x,
detail::tvec3<T> const & y
)
{
return detail::tvec3<T>(
min(x.x, y.x),
min(x.y, y.y),
min(x.z, y.z));
}
template <typename T>
GLM_FUNC_QUALIFIER detail::tvec4<T> min
(
detail::tvec4<T> const & x,
detail::tvec4<T> const & y
)
{
return detail::tvec4<T>(
min(x.x, y.x),
min(x.y, y.y),
min(x.z, y.z),
min(x.w, y.w));
}
// max // max
template <typename genType> template <typename genType>
@ -668,82 +301,8 @@ namespace detail
return x > y ? x : y; return x > y ? x : y;
} }
template <typename T> VECTORIZE_VEC_SCA(max)
GLM_FUNC_QUALIFIER detail::tvec2<T> max VECTORIZE_VEC_VEC(max)
(
detail::tvec2<T> const & x,
typename detail::tvec2<T>::value_type y
)
{
return detail::tvec2<T>(
max(x.x, y),
max(x.y, y));
}
template <typename T>
GLM_FUNC_QUALIFIER detail::tvec3<T> max
(
detail::tvec3<T> const & x,
typename detail::tvec3<T>::value_type y
)
{
return detail::tvec3<T>(
max(x.x, y),
max(x.y, y),
max(x.z, y));
}
template <typename T>
GLM_FUNC_QUALIFIER detail::tvec4<T> max
(
detail::tvec4<T> const & x,
typename detail::tvec4<T>::value_type y
)
{
return detail::tvec4<T>(
max(x.x, y),
max(x.y, y),
max(x.z, y),
max(x.w, y));
}
template <typename T>
GLM_FUNC_QUALIFIER detail::tvec2<T> max
(
detail::tvec2<T> const & x,
detail::tvec2<T> const & y
)
{
return detail::tvec2<T>(
max(x.x, y.x),
max(x.y, y.y));
}
template <typename T>
GLM_FUNC_QUALIFIER detail::tvec3<T> max
(
detail::tvec3<T> const & x,
detail::tvec3<T> const & y
)
{
return detail::tvec3<T>(
max(x.x, y.x),
max(x.y, y.y),
max(x.z, y.z));
}
template <typename T>
GLM_FUNC_QUALIFIER detail::tvec4<T> max
(
detail::tvec4<T> const & x,
detail::tvec4<T> const & y)
{
return detail::tvec4<T>(
max(x.x, y.x),
max(x.y, y.y),
max(x.z, y.z),
max(x.w, y.w));
}
// clamp // clamp
template <typename valType> template <typename valType>

@ -26,6 +26,8 @@
/// @author Christophe Riccio /// @author Christophe Riccio
/////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////
#include "_vectorize.hpp"
namespace glm namespace glm
{ {
// pow // pow
@ -41,44 +43,7 @@ namespace glm
return ::std::pow(x, y); return ::std::pow(x, y);
} }
template <typename T> VECTORIZE_VEC_VEC(pow)
GLM_FUNC_QUALIFIER detail::tvec2<T> pow
(
detail::tvec2<T> const & x,
detail::tvec2<T> const & y
)
{
return detail::tvec2<T>(
pow(x.x, y.x),
pow(x.y, y.y));
}
template <typename T>
GLM_FUNC_QUALIFIER detail::tvec3<T> pow
(
detail::tvec3<T> const & x,
detail::tvec3<T> const & y
)
{
return detail::tvec3<T>(
pow(x.x, y.x),
pow(x.y, y.y),
pow(x.z, y.z));
}
template <typename T>
GLM_FUNC_QUALIFIER detail::tvec4<T> pow
(
detail::tvec4<T> const & x,
detail::tvec4<T> const & y
)
{
return detail::tvec4<T>(
pow(x.x, y.x),
pow(x.y, y.y),
pow(x.z, y.z),
pow(x.w, y.w));
}
// exp // exp
template <typename genType> template <typename genType>
@ -92,41 +57,7 @@ namespace glm
return ::std::exp(x); return ::std::exp(x);
} }
template <typename T> VECTORIZE_VEC(exp)
GLM_FUNC_QUALIFIER detail::tvec2<T> exp
(
detail::tvec2<T> const & x
)
{
return detail::tvec2<T>(
exp(x.x),
exp(x.y));
}
template <typename T>
GLM_FUNC_QUALIFIER detail::tvec3<T> exp
(
detail::tvec3<T> const & x
)
{
return detail::tvec3<T>(
exp(x.x),
exp(x.y),
exp(x.z));
}
template <typename T>
GLM_FUNC_QUALIFIER detail::tvec4<T> exp
(
detail::tvec4<T> const & x
)
{
return detail::tvec4<T>(
exp(x.x),
exp(x.y),
exp(x.z),
exp(x.w));
}
// log // log
template <typename genType> template <typename genType>
@ -140,41 +71,7 @@ namespace glm
return ::std::log(x); return ::std::log(x);
} }
template <typename T> VECTORIZE_VEC(log)
GLM_FUNC_QUALIFIER detail::tvec2<T> log
(
detail::tvec2<T> const & x
)
{
return detail::tvec2<T>(
log(x.x),
log(x.y));
}
template <typename T>
GLM_FUNC_QUALIFIER detail::tvec3<T> log
(
detail::tvec3<T> const & x
)
{
return detail::tvec3<T>(
log(x.x),
log(x.y),
log(x.z));
}
template <typename T>
GLM_FUNC_QUALIFIER detail::tvec4<T> log
(
detail::tvec4<T> const & x
)
{
return detail::tvec4<T>(
log(x.x),
log(x.y),
log(x.z),
log(x.w));
}
//exp2, ln2 = 0.69314718055994530941723212145818f //exp2, ln2 = 0.69314718055994530941723212145818f
template <typename genType> template <typename genType>
@ -188,41 +85,7 @@ namespace glm
return ::std::exp(genType(0.69314718055994530941723212145818) * x); return ::std::exp(genType(0.69314718055994530941723212145818) * x);
} }
template <typename T> VECTORIZE_VEC(exp2)
GLM_FUNC_QUALIFIER detail::tvec2<T> exp2
(
detail::tvec2<T> const & x
)
{
return detail::tvec2<T>(
exp2(x.x),
exp2(x.y));
}
template <typename T>
GLM_FUNC_QUALIFIER detail::tvec3<T> exp2
(
detail::tvec3<T> const & x
)
{
return detail::tvec3<T>(
exp2(x.x),
exp2(x.y),
exp2(x.z));
}
template <typename T>
GLM_FUNC_QUALIFIER detail::tvec4<T> exp2
(
detail::tvec4<T> const & x
)
{
return detail::tvec4<T>(
exp2(x.x),
exp2(x.y),
exp2(x.z),
exp2(x.w));
}
namespace detail namespace detail
{ {
@ -232,7 +95,7 @@ namespace detail
template <typename T> template <typename T>
T operator() (T const & Value) const T operator() (T const & Value) const
{ {
static_assert(0, "'log2' parameter has an invalid template parameter type"); GLM_STATIC_ASSERT(0, "'log2' parameter has an invalid template parameter type. GLM core features only supports floating-point types, include <glm/gtx/integer.hpp> for integer types support. Others types are not supported.");
return Value; return Value;
} }
}; };
@ -255,44 +118,11 @@ namespace detail
genType const & x genType const & x
) )
{ {
assert(x > genType(0)); // log2 is only defined on the range (0, inf]
return detail::compute_log2<detail::float_or_int_trait<genType>::ID>()(x); return detail::compute_log2<detail::float_or_int_trait<genType>::ID>()(x);
} }
template <typename T> VECTORIZE_VEC(log2)
GLM_FUNC_QUALIFIER detail::tvec2<T> log2
(
detail::tvec2<T> const & x
)
{
return detail::tvec2<T>(
log2(x.x),
log2(x.y));
}
template <typename T>
GLM_FUNC_QUALIFIER detail::tvec3<T> log2
(
detail::tvec3<T> const & x
)
{
return detail::tvec3<T>(
log2(x.x),
log2(x.y),
log2(x.z));
}
template <typename T>
GLM_FUNC_QUALIFIER detail::tvec4<T> log2
(
detail::tvec4<T> const & x
)
{
return detail::tvec4<T>(
log2(x.x),
log2(x.y),
log2(x.z),
log2(x.w));
}
// sqrt // sqrt
template <typename genType> template <typename genType>
@ -306,41 +136,7 @@ namespace detail
return genType(::std::sqrt(x)); return genType(::std::sqrt(x));
} }
template <typename T> VECTORIZE_VEC(sqrt)
GLM_FUNC_QUALIFIER detail::tvec2<T> sqrt
(
detail::tvec2<T> const & x
)
{
return detail::tvec2<T>(
glm::sqrt(x.x),
glm::sqrt(x.y));
}
template <typename T>
GLM_FUNC_QUALIFIER detail::tvec3<T> sqrt
(
detail::tvec3<T> const & x
)
{
return detail::tvec3<T>(
glm::sqrt(x.x),
glm::sqrt(x.y),
glm::sqrt(x.z));
}
template <typename T>
GLM_FUNC_QUALIFIER detail::tvec4<T> sqrt
(
detail::tvec4<T> const & x
)
{
return detail::tvec4<T>(
glm::sqrt(x.x),
glm::sqrt(x.y),
glm::sqrt(x.z),
glm::sqrt(x.w));
}
template <typename genType> template <typename genType>
GLM_FUNC_QUALIFIER genType inversesqrt GLM_FUNC_QUALIFIER genType inversesqrt
@ -353,40 +149,6 @@ namespace detail
return genType(1) / ::std::sqrt(x); return genType(1) / ::std::sqrt(x);
} }
template <typename T> VECTORIZE_VEC(inversesqrt)
GLM_FUNC_QUALIFIER detail::tvec2<T> inversesqrt
(
detail::tvec2<T> const & x
)
{
return detail::tvec2<T>(
inversesqrt(x.x),
inversesqrt(x.y));
}
template <typename T>
GLM_FUNC_QUALIFIER detail::tvec3<T> inversesqrt
(
detail::tvec3<T> const & x
)
{
return detail::tvec3<T>(
inversesqrt(x.x),
inversesqrt(x.y),
inversesqrt(x.z));
}
template <typename T>
GLM_FUNC_QUALIFIER detail::tvec4<T> inversesqrt
(
detail::tvec4<T> const & x
)
{
return detail::tvec4<T>(
inversesqrt(x.x),
inversesqrt(x.y),
inversesqrt(x.z),
inversesqrt(x.w));
}
}//namespace glm }//namespace glm

@ -26,6 +26,8 @@
/// @author Christophe Riccio /// @author Christophe Riccio
/////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////
#include "_vectorize.hpp"
namespace glm namespace glm
{ {
// length // length

@ -26,6 +26,7 @@
/// @author Christophe Riccio /// @author Christophe Riccio
/////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////
#include "_vectorize.hpp"
#if(GLM_COMPILER & GLM_COMPILER_VC) #if(GLM_COMPILER & GLM_COMPILER_VC)
#include <intrin.h> #include <intrin.h>
#pragma intrinsic(_BitScanReverse) #pragma intrinsic(_BitScanReverse)
@ -415,41 +416,7 @@ namespace glm
return Out; return Out;
} }
template <typename T> VECTORIZE_VEC(bitfieldReverse)
GLM_FUNC_QUALIFIER detail::tvec2<T> bitfieldReverse
(
detail::tvec2<T> const & value
)
{
return detail::tvec2<T>(
bitfieldReverse(value[0]),
bitfieldReverse(value[1]));
}
template <typename T>
GLM_FUNC_QUALIFIER detail::tvec3<T> bitfieldReverse
(
detail::tvec3<T> const & value
)
{
return detail::tvec3<T>(
bitfieldReverse(value[0]),
bitfieldReverse(value[1]),
bitfieldReverse(value[2]));
}
template <typename T>
GLM_FUNC_QUALIFIER detail::tvec4<T> bitfieldReverse
(
detail::tvec4<T> const & value
)
{
return detail::tvec4<T>(
bitfieldReverse(value[0]),
bitfieldReverse(value[1]),
bitfieldReverse(value[2]),
bitfieldReverse(value[3]));
}
// bitCount // bitCount
template <typename genIUType> template <typename genIUType>

@ -26,6 +26,8 @@
/// @author Christophe Riccio /// @author Christophe Riccio
/////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////
#include "_vectorize.hpp"
namespace glm namespace glm
{ {
// matrixCompMult // matrixCompMult

@ -26,134 +26,133 @@
/// @author Christophe Riccio /// @author Christophe Riccio
/////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////
namespace glm{ namespace glm
GLM_FUNC_QUALIFIER detail::uint32 packUnorm2x16(detail::tvec2<detail::float32> const & v)
{ {
detail::uint16 A(detail::uint16(round(clamp(v.x, 0.0f, 1.0f) * 65535.0f))); GLM_FUNC_QUALIFIER detail::uint32 packUnorm2x16(detail::tvec2<detail::float32> const & v)
detail::uint16 B(detail::uint16(round(clamp(v.y, 0.0f, 1.0f) * 65535.0f))); {
return detail::uint32((B << 16) | A); detail::uint16 A(detail::uint16(round(clamp(v.x, 0.0f, 1.0f) * 65535.0f)));
} detail::uint16 B(detail::uint16(round(clamp(v.y, 0.0f, 1.0f) * 65535.0f)));
return detail::uint32((B << 16) | A);
}
GLM_FUNC_QUALIFIER detail::tvec2<detail::float32> unpackUnorm2x16(detail::uint32 const & p) GLM_FUNC_QUALIFIER detail::tvec2<detail::float32> unpackUnorm2x16(detail::uint32 const & p)
{
detail::uint32 Mask16((1 << 16) - 1);
detail::uint32 A((p >> 0) & Mask16);
detail::uint32 B((p >> 16) & Mask16);
return detail::tvec2<detail::float32>(
A * 1.0f / 65535.0f,
B * 1.0f / 65535.0f);
}
GLM_FUNC_QUALIFIER detail::uint32 packSnorm2x16(detail::tvec2<detail::float32> const & v)
{
union iu
{ {
detail::int16 i; detail::uint32 Mask16((1 << 16) - 1);
detail::uint16 u; detail::uint32 A((p >> 0) & Mask16);
} A, B; detail::uint32 B((p >> 16) & Mask16);
return detail::tvec2<detail::float32>(
detail::tvec2<detail::float32> Unpack = clamp(v ,-1.0f, 1.0f) * 32767.0f; A * 1.0f / 65535.0f,
A.i = detail::int16(round(Unpack.x)); B * 1.0f / 65535.0f);
B.i = detail::int16(round(Unpack.y)); }
detail::uint32 Pack = (detail::uint32(B.u) << 16) | (detail::uint32(A.u) << 0);
return Pack; GLM_FUNC_QUALIFIER detail::uint32 packSnorm2x16(detail::tvec2<detail::float32> const & v)
} {
union iu
GLM_FUNC_QUALIFIER detail::tvec2<detail::float32> unpackSnorm2x16(detail::uint32 const & p) {
{ detail::int16 i;
union iu detail::uint16 u;
} A, B;
detail::tvec2<detail::float32> Unpack = clamp(v ,-1.0f, 1.0f) * 32767.0f;
A.i = detail::int16(round(Unpack.x));
B.i = detail::int16(round(Unpack.y));
detail::uint32 Pack = (detail::uint32(B.u) << 16) | (detail::uint32(A.u) << 0);
return Pack;
}
GLM_FUNC_QUALIFIER detail::tvec2<detail::float32> unpackSnorm2x16(detail::uint32 const & p)
{ {
detail::int16 i; union iu
detail::uint16 u; {
} A, B; detail::int16 i;
detail::uint16 u;
} A, B;
detail::uint32 Mask16((1 << 16) - 1); detail::uint32 Mask16((1 << 16) - 1);
A.u = detail::uint16((p >> 0) & Mask16); A.u = detail::uint16((p >> 0) & Mask16);
B.u = detail::uint16((p >> 16) & Mask16); B.u = detail::uint16((p >> 16) & Mask16);
detail::tvec2<detail::float32> Pack(A.i, B.i); detail::tvec2<detail::float32> Pack(A.i, B.i);
return clamp(Pack * 1.0f / 32767.0f, -1.0f, 1.0f); return clamp(Pack * 1.0f / 32767.0f, -1.0f, 1.0f);
} }
GLM_FUNC_QUALIFIER detail::uint32 packUnorm4x8(detail::tvec4<detail::float32> const & v) GLM_FUNC_QUALIFIER detail::uint32 packUnorm4x8(detail::tvec4<detail::float32> const & v)
{
detail::uint8 A((detail::uint8)round(clamp(v.x, 0.0f, 1.0f) * 255.0f));
detail::uint8 B((detail::uint8)round(clamp(v.y, 0.0f, 1.0f) * 255.0f));
detail::uint8 C((detail::uint8)round(clamp(v.z, 0.0f, 1.0f) * 255.0f));
detail::uint8 D((detail::uint8)round(clamp(v.w, 0.0f, 1.0f) * 255.0f));
return detail::uint32((D << 24) | (C << 16) | (B << 8) | A);
}
GLM_FUNC_QUALIFIER detail::tvec4<detail::float32> unpackUnorm4x8(detail::uint32 const & p)
{
detail::uint32 Mask8((1 << 8) - 1);
detail::uint32 A((p >> 0) & Mask8);
detail::uint32 B((p >> 8) & Mask8);
detail::uint32 C((p >> 16) & Mask8);
detail::uint32 D((p >> 24) & Mask8);
return detail::tvec4<detail::float32>(
A * 1.0f / 255.0f,
B * 1.0f / 255.0f,
C * 1.0f / 255.0f,
D * 1.0f / 255.0f);
}
GLM_FUNC_QUALIFIER detail::uint32 packSnorm4x8(detail::tvec4<detail::float32> const & v)
{
union iu
{ {
detail::int8 i; detail::uint8 A((detail::uint8)round(clamp(v.x, 0.0f, 1.0f) * 255.0f));
detail::uint8 u; detail::uint8 B((detail::uint8)round(clamp(v.y, 0.0f, 1.0f) * 255.0f));
} A, B, C, D; detail::uint8 C((detail::uint8)round(clamp(v.z, 0.0f, 1.0f) * 255.0f));
detail::uint8 D((detail::uint8)round(clamp(v.w, 0.0f, 1.0f) * 255.0f));
detail::tvec4<detail::float32> Unpack = clamp(v ,-1.0f, 1.0f) * 127.0f; return detail::uint32((D << 24) | (C << 16) | (B << 8) | A);
A.i = detail::int8(round(Unpack.x)); }
B.i = detail::int8(round(Unpack.y));
C.i = detail::int8(round(Unpack.z)); GLM_FUNC_QUALIFIER detail::tvec4<detail::float32> unpackUnorm4x8(detail::uint32 const & p)
D.i = detail::int8(round(Unpack.w));
detail::uint32 Pack = (detail::uint32(D.u) << 24) | (detail::uint32(C.u) << 16) | (detail::uint32(B.u) << 8) | (detail::uint32(A.u) << 0);
return Pack;
}
GLM_FUNC_QUALIFIER detail::tvec4<detail::float32> unpackSnorm4x8(detail::uint32 const & p)
{
union iu
{ {
detail::int8 i; detail::uint32 Mask8((1 << 8) - 1);
detail::uint8 u; detail::uint32 A((p >> 0) & Mask8);
} A, B, C, D; detail::uint32 B((p >> 8) & Mask8);
detail::uint32 C((p >> 16) & Mask8);
detail::uint32 Mask8((1 << 8) - 1); detail::uint32 D((p >> 24) & Mask8);
A.u = detail::uint8((p >> 0) & Mask8); return detail::tvec4<detail::float32>(
B.u = detail::uint8((p >> 8) & Mask8); A * 1.0f / 255.0f,
C.u = detail::uint8((p >> 16) & Mask8); B * 1.0f / 255.0f,
D.u = detail::uint8((p >> 24) & Mask8); C * 1.0f / 255.0f,
detail::tvec4<detail::float32> Pack(A.i, B.i, C.i, D.i); D * 1.0f / 255.0f);
}
return clamp(Pack * 1.0f / 127.0f, -1.0f, 1.0f);
} GLM_FUNC_QUALIFIER detail::uint32 packSnorm4x8(detail::tvec4<detail::float32> const & v)
{
GLM_FUNC_QUALIFIER double packDouble2x32(detail::tvec2<detail::uint32> const & v) union iu
{ {
return *(double*)&v; detail::int8 i;
} detail::uint8 u;
} A, B, C, D;
GLM_FUNC_QUALIFIER detail::tvec2<uint> unpackDouble2x32(double const & v)
{ detail::tvec4<detail::float32> Unpack = clamp(v ,-1.0f, 1.0f) * 127.0f;
return *(detail::tvec2<uint>*)&v; A.i = detail::int8(round(Unpack.x));
} B.i = detail::int8(round(Unpack.y));
C.i = detail::int8(round(Unpack.z));
D.i = detail::int8(round(Unpack.w));
detail::uint32 Pack = (detail::uint32(D.u) << 24) | (detail::uint32(C.u) << 16) | (detail::uint32(B.u) << 8) | (detail::uint32(A.u) << 0);
return Pack;
}
GLM_FUNC_QUALIFIER detail::tvec4<detail::float32> unpackSnorm4x8(detail::uint32 const & p)
{
union iu
{
detail::int8 i;
detail::uint8 u;
} A, B, C, D;
detail::uint32 Mask8((1 << 8) - 1);
A.u = detail::uint8((p >> 0) & Mask8);
B.u = detail::uint8((p >> 8) & Mask8);
C.u = detail::uint8((p >> 16) & Mask8);
D.u = detail::uint8((p >> 24) & Mask8);
detail::tvec4<detail::float32> Pack(A.i, B.i, C.i, D.i);
return clamp(Pack * 1.0f / 127.0f, -1.0f, 1.0f);
}
GLM_FUNC_QUALIFIER double packDouble2x32(detail::tvec2<detail::uint32> const & v)
{
return *(double*)&v;
}
GLM_FUNC_QUALIFIER uint packHalf2x16(detail::tvec2<float> const & v) GLM_FUNC_QUALIFIER detail::tvec2<uint> unpackDouble2x32(double const & v)
{ {
detail::tvec2<detail::hdata> Pack(detail::toFloat16(v.x), detail::toFloat16(v.y)); return *(detail::tvec2<uint>*)&v;
return *(uint*)&Pack; }
}
GLM_FUNC_QUALIFIER vec2 unpackHalf2x16(uint const & v) GLM_FUNC_QUALIFIER uint packHalf2x16(detail::tvec2<float> const & v)
{ {
detail::tvec2<detail::hdata> Unpack = *(detail::tvec2<detail::hdata>*)&v; detail::tvec2<detail::hdata> Pack(detail::toFloat16(v.x), detail::toFloat16(v.y));
return vec2(detail::toFloat32(Unpack.x), detail::toFloat32(Unpack.y)); return *(uint*)&Pack;
} }
GLM_FUNC_QUALIFIER vec2 unpackHalf2x16(uint const & v)
{
detail::tvec2<detail::hdata> Unpack = *(detail::tvec2<detail::hdata>*)&v;
return vec2(detail::toFloat32(Unpack.x), detail::toFloat32(Unpack.y));
}
}//namespace glm }//namespace glm

@ -26,732 +26,221 @@
/// @author Christophe Riccio /// @author Christophe Riccio
/////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////
namespace glm{ #include "_vectorize.hpp"
// radians namespace glm
template <typename genType> {
GLM_FUNC_QUALIFIER genType radians // radians
( template <typename genType>
genType const & degrees GLM_FUNC_QUALIFIER genType radians
) (
{ genType const & degrees
GLM_STATIC_ASSERT(detail::type<genType>::is_float, "'radians' only accept floating-point input"); )
{
const genType pi = genType(3.1415926535897932384626433832795); GLM_STATIC_ASSERT(detail::type<genType>::is_float, "'radians' only accept floating-point input");
return degrees * (pi / genType(180));
} genType const pi = genType(3.1415926535897932384626433832795);
return degrees * (pi / genType(180));
template <typename T> }
GLM_FUNC_QUALIFIER detail::tvec2<T> radians
( VECTORIZE_VEC(radians)
detail::tvec2<T> const & degrees
) // degrees
{ template <typename genType>
return detail::tvec2<T>( GLM_FUNC_QUALIFIER genType degrees
radians(degrees.x), (
radians(degrees.y)); genType const & radians
} )
{
template <typename T> GLM_STATIC_ASSERT(detail::type<genType>::is_float, "'degrees' only accept floating-point input");
GLM_FUNC_QUALIFIER detail::tvec3<T> radians
( const genType pi = genType(3.1415926535897932384626433832795);
detail::tvec3<T> const & degrees return radians * (genType(180) / pi);
) }
{
return detail::tvec3<T>( VECTORIZE_VEC(degrees)
radians(degrees.x),
radians(degrees.y), // sin
radians(degrees.z)); template <typename genType>
} GLM_FUNC_QUALIFIER genType sin
(
template <typename T> genType const & angle
GLM_FUNC_QUALIFIER detail::tvec4<T> radians )
( {
detail::tvec4<T> const & degrees GLM_STATIC_ASSERT(detail::type<genType>::is_float, "'sin' only accept floating-point input");
)
{ return ::std::sin(angle);
return detail::tvec4<T>( }
radians(degrees.x),
radians(degrees.y), VECTORIZE_VEC(sin)
radians(degrees.z),
radians(degrees.w)); // cos
} template <typename genType>
GLM_FUNC_QUALIFIER genType cos(genType const & angle)
// degrees {
template <typename genType> GLM_STATIC_ASSERT(detail::type<genType>::is_float, "'cos' only accept floating-point input");
GLM_FUNC_QUALIFIER genType degrees
( return ::std::cos(angle);
genType const & radians }
)
{ VECTORIZE_VEC(cos)
GLM_STATIC_ASSERT(detail::type<genType>::is_float, "'degrees' only accept floating-point input");
// tan
const genType pi = genType(3.1415926535897932384626433832795); template <typename genType>
return radians * (genType(180) / pi); GLM_FUNC_QUALIFIER genType tan
} (
genType const & angle
template <typename T> )
GLM_FUNC_QUALIFIER detail::tvec2<T> degrees {
( GLM_STATIC_ASSERT(detail::type<genType>::is_float, "'tan' only accept floating-point input");
detail::tvec2<T> const & radians
) return ::std::tan(angle);
{ }
return detail::tvec2<T>(
degrees(radians.x), VECTORIZE_VEC(tan)
degrees(radians.y));
} // asin
template <typename genType>
template <typename T> GLM_FUNC_QUALIFIER genType asin
GLM_FUNC_QUALIFIER detail::tvec3<T> degrees (
( genType const & x
detail::tvec3<T> const & radians )
) {
{ GLM_STATIC_ASSERT(detail::type<genType>::is_float, "'asin' only accept floating-point input");
return detail::tvec3<T>(
degrees(radians.x), return ::std::asin(x);
degrees(radians.y), }
degrees(radians.z));
} VECTORIZE_VEC(asin)
template <typename T> // acos
GLM_FUNC_QUALIFIER detail::tvec4<T> degrees template <typename genType>
( GLM_FUNC_QUALIFIER genType acos
detail::tvec4<T> const & radians (
) genType const & x
{ )
return detail::tvec4<T>( {
degrees(radians.x), GLM_STATIC_ASSERT(detail::type<genType>::is_float, "'acos' only accept floating-point input");
degrees(radians.y),
degrees(radians.z), return ::std::acos(x);
degrees(radians.w)); }
}
VECTORIZE_VEC(acos)
// sin
template <typename genType> // atan
GLM_FUNC_QUALIFIER genType sin template <typename genType>
( GLM_FUNC_QUALIFIER genType atan
genType const & angle (
) genType const & y,
{ genType const & x
GLM_STATIC_ASSERT(detail::type<genType>::is_float, "'sin' only accept floating-point input"); )
{
return ::std::sin(angle); GLM_STATIC_ASSERT(detail::type<genType>::is_float, "'atan' only accept floating-point input");
}
return ::std::atan2(y, x);
template <typename T> }
GLM_FUNC_QUALIFIER detail::tvec2<T> sin
( VECTORIZE_VEC_VEC(atan)
detail::tvec2<T> const & angle
) template <typename genType>
{ GLM_FUNC_QUALIFIER genType atan
return detail::tvec2<T>( (
sin(angle.x), genType const & x
sin(angle.y)); )
} {
GLM_STATIC_ASSERT(detail::type<genType>::is_float, "'atan' only accept floating-point input");
template <typename T>
GLM_FUNC_QUALIFIER detail::tvec3<T> sin return ::std::atan(x);
( }
detail::tvec3<T> const & angle
) VECTORIZE_VEC(atan)
{
return detail::tvec3<T>( // sinh
sin(angle.x), template <typename genType>
sin(angle.y), GLM_FUNC_QUALIFIER genType sinh
sin(angle.z)); (
} genType const & angle
)
template <typename T> {
GLM_FUNC_QUALIFIER detail::tvec4<T> sin GLM_STATIC_ASSERT(detail::type<genType>::is_float, "'sinh' only accept floating-point input");
(
detail::tvec4<T> const & angle return std::sinh(angle);
) }
{
return detail::tvec4<T>( VECTORIZE_VEC(sinh)
sin(angle.x),
sin(angle.y), // cosh
sin(angle.z), template <typename genType>
sin(angle.w)); GLM_FUNC_QUALIFIER genType cosh
} (
genType const & angle
// cos )
template <typename genType> {
GLM_FUNC_QUALIFIER genType cos(genType const & angle) GLM_STATIC_ASSERT(detail::type<genType>::is_float, "'cosh' only accept floating-point input");
{
GLM_STATIC_ASSERT(detail::type<genType>::is_float, "'cos' only accept floating-point input"); return std::cosh(angle);
}
return ::std::cos(angle);
} VECTORIZE_VEC(cosh)
template <typename T> // tanh
GLM_FUNC_QUALIFIER detail::tvec2<T> cos template <typename genType>
( GLM_FUNC_QUALIFIER genType tanh
detail::tvec2<T> const & angle (
) genType const & angle
{ )
return detail::tvec2<T>( {
cos(angle.x), GLM_STATIC_ASSERT(detail::type<genType>::is_float, "'tanh' only accept floating-point input");
cos(angle.y));
} return std::tanh(angle);
}
template <typename T>
GLM_FUNC_QUALIFIER detail::tvec3<T> cos VECTORIZE_VEC(tanh)
(
detail::tvec3<T> const & angle // asinh
) template <typename genType>
{ GLM_FUNC_QUALIFIER genType asinh
return detail::tvec3<T>( (
cos(angle.x), genType const & x
cos(angle.y), )
cos(angle.z)); {
} GLM_STATIC_ASSERT(detail::type<genType>::is_float, "'asinh' only accept floating-point input");
template <typename T> return (x < genType(0) ? genType(-1) : (x > genType(0) ? genType(1) : genType(0))) * log(abs(x) + sqrt(genType(1) + x * x));
GLM_FUNC_QUALIFIER detail::tvec4<T> cos }
(
detail::tvec4<T> const & angle VECTORIZE_VEC(asinh)
)
{ // acosh
return detail::tvec4<T>( template <typename genType>
cos(angle.x), GLM_FUNC_QUALIFIER genType acosh
cos(angle.y), (
cos(angle.z), genType const & x
cos(angle.w)); )
} {
GLM_STATIC_ASSERT(detail::type<genType>::is_float, "'acosh' only accept floating-point input");
// tan
template <typename genType> if(x < genType(1))
GLM_FUNC_QUALIFIER genType tan return genType(0);
( return log(x + sqrt(x * x - genType(1)));
genType const & angle }
)
{ VECTORIZE_VEC(acosh)
GLM_STATIC_ASSERT(detail::type<genType>::is_float, "'tan' only accept floating-point input");
// atanh
return ::std::tan(angle); template <typename genType>
} GLM_FUNC_QUALIFIER genType atanh
(
template <typename T> genType const & x
GLM_FUNC_QUALIFIER detail::tvec2<T> tan )
( {
detail::tvec2<T> const & angle GLM_STATIC_ASSERT(detail::type<genType>::is_float, "'atanh' only accept floating-point input");
)
{ if(abs(x) >= genType(1))
return detail::tvec2<T>( return 0;
tan(angle.x), return genType(0.5) * log((genType(1) + x) / (genType(1) - x));
tan(angle.y)); }
}
VECTORIZE_VEC(atanh)
template <typename T>
GLM_FUNC_QUALIFIER detail::tvec3<T> tan
(
detail::tvec3<T> const & angle
)
{
return detail::tvec3<T>(
tan(angle.x),
tan(angle.y),
tan(angle.z));
}
template <typename T>
GLM_FUNC_QUALIFIER detail::tvec4<T> tan
(
detail::tvec4<T> const & angle
)
{
return detail::tvec4<T>(
tan(angle.x),
tan(angle.y),
tan(angle.z),
tan(angle.w));
}
// asin
template <typename genType>
GLM_FUNC_QUALIFIER genType asin
(
genType const & x
)
{
GLM_STATIC_ASSERT(detail::type<genType>::is_float, "'asin' only accept floating-point input");
return ::std::asin(x);
}
template <typename T>
GLM_FUNC_QUALIFIER detail::tvec2<T> asin
(
detail::tvec2<T> const & x
)
{
return detail::tvec2<T>(
asin(x.x),
asin(x.y));
}
template <typename T>
GLM_FUNC_QUALIFIER detail::tvec3<T> asin
(
detail::tvec3<T> const & x
)
{
return detail::tvec3<T>(
asin(x.x),
asin(x.y),
asin(x.z));
}
template <typename T>
GLM_FUNC_QUALIFIER detail::tvec4<T> asin
(
detail::tvec4<T> const & x
)
{
return detail::tvec4<T>(
asin(x.x),
asin(x.y),
asin(x.z),
asin(x.w));
}
// acos
template <typename genType>
GLM_FUNC_QUALIFIER genType acos
(
genType const & x
)
{
GLM_STATIC_ASSERT(detail::type<genType>::is_float, "'acos' only accept floating-point input");
return ::std::acos(x);
}
template <typename T>
GLM_FUNC_QUALIFIER detail::tvec2<T> acos
(
detail::tvec2<T> const & x
)
{
return detail::tvec2<T>(
acos(x.x),
acos(x.y));
}
template <typename T>
GLM_FUNC_QUALIFIER detail::tvec3<T> acos
(
detail::tvec3<T> const & x
)
{
return detail::tvec3<T>(
acos(x.x),
acos(x.y),
acos(x.z));
}
template <typename T>
GLM_FUNC_QUALIFIER detail::tvec4<T> acos
(
detail::tvec4<T> const & x
)
{
return detail::tvec4<T>(
acos(x.x),
acos(x.y),
acos(x.z),
acos(x.w));
}
// atan
template <typename genType>
GLM_FUNC_QUALIFIER genType atan
(
genType const & y,
genType const & x
)
{
GLM_STATIC_ASSERT(detail::type<genType>::is_float, "'atan' only accept floating-point input");
return ::std::atan2(y, x);
}
template <typename T>
GLM_FUNC_QUALIFIER detail::tvec2<T> atan
(
detail::tvec2<T> const & y,
detail::tvec2<T> const & x
)
{
return detail::tvec2<T>(
atan(y.x, x.x),
atan(y.y, x.y));
}
template <typename T>
GLM_FUNC_QUALIFIER detail::tvec3<T> atan
(
detail::tvec3<T> const & y,
detail::tvec3<T> const & x
)
{
return detail::tvec3<T>(
atan(y.x, x.x),
atan(y.y, x.y),
atan(y.z, x.z));
}
template <typename T>
GLM_FUNC_QUALIFIER detail::tvec4<T> atan
(
detail::tvec4<T> const & y,
detail::tvec4<T> const & x
)
{
return detail::tvec4<T>(
atan(y.x, x.x),
atan(y.y, x.y),
atan(y.z, x.z),
atan(y.w, x.w));
}
template <typename genType>
GLM_FUNC_QUALIFIER genType atan
(
genType const & x
)
{
GLM_STATIC_ASSERT(detail::type<genType>::is_float, "'atan' only accept floating-point input");
return ::std::atan(x);
}
template <typename T>
GLM_FUNC_QUALIFIER detail::tvec2<T> atan
(
detail::tvec2<T> const & x
)
{
return detail::tvec2<T>(
atan(x.x),
atan(x.y));
}
template <typename T>
GLM_FUNC_QUALIFIER detail::tvec3<T> atan
(
detail::tvec3<T> const & x
)
{
return detail::tvec3<T>(
atan(x.x),
atan(x.y),
atan(x.z));
}
template <typename T>
GLM_FUNC_QUALIFIER detail::tvec4<T> atan
(
detail::tvec4<T> const & x
)
{
return detail::tvec4<T>(
atan(x.x),
atan(x.y),
atan(x.z),
atan(x.w));
}
// sinh
template <typename genType>
GLM_FUNC_QUALIFIER genType sinh
(
genType const & angle
)
{
GLM_STATIC_ASSERT(detail::type<genType>::is_float, "'sinh' only accept floating-point input");
return std::sinh(angle);
}
template <typename T>
GLM_FUNC_QUALIFIER detail::tvec2<T> sinh
(
detail::tvec2<T> const & angle
)
{
return detail::tvec2<T>(
sinh(angle.x),
sinh(angle.y));
}
template <typename T>
GLM_FUNC_QUALIFIER detail::tvec3<T> sinh
(
detail::tvec3<T> const & angle
)
{
return detail::tvec3<T>(
sinh(angle.x),
sinh(angle.y),
sinh(angle.z));
}
template <typename T>
GLM_FUNC_QUALIFIER detail::tvec4<T> sinh
(
detail::tvec4<T> const & angle
)
{
return detail::tvec4<T>(
sinh(angle.x),
sinh(angle.y),
sinh(angle.z),
sinh(angle.w));
}
// cosh
template <typename genType>
GLM_FUNC_QUALIFIER genType cosh
(
genType const & angle
)
{
GLM_STATIC_ASSERT(detail::type<genType>::is_float, "'cosh' only accept floating-point input");
return std::cosh(angle);
}
template <typename T>
GLM_FUNC_QUALIFIER detail::tvec2<T> cosh
(
detail::tvec2<T> const & angle
)
{
return detail::tvec2<T>(
cosh(angle.x),
cosh(angle.y));
}
template <typename T>
GLM_FUNC_QUALIFIER detail::tvec3<T> cosh
(
detail::tvec3<T> const & angle
)
{
return detail::tvec3<T>(
cosh(angle.x),
cosh(angle.y),
cosh(angle.z));
}
template <typename T>
GLM_FUNC_QUALIFIER detail::tvec4<T> cosh
(
detail::tvec4<T> const & angle
)
{
return detail::tvec4<T>(
cosh(angle.x),
cosh(angle.y),
cosh(angle.z),
cosh(angle.w));
}
// tanh
template <typename genType>
GLM_FUNC_QUALIFIER genType tanh
(
genType const & angle
)
{
GLM_STATIC_ASSERT(detail::type<genType>::is_float, "'tanh' only accept floating-point input");
return std::tanh(angle);
}
template <typename T>
GLM_FUNC_QUALIFIER detail::tvec2<T> tanh
(
detail::tvec2<T> const & angle
)
{
return detail::tvec2<T>(
tanh(angle.x),
tanh(angle.y));
}
template <typename T>
GLM_FUNC_QUALIFIER detail::tvec3<T> tanh
(
detail::tvec3<T> const & angle
)
{
return detail::tvec3<T>(
tanh(angle.x),
tanh(angle.y),
tanh(angle.z));
}
template <typename T>
GLM_FUNC_QUALIFIER detail::tvec4<T> tanh
(
detail::tvec4<T> const & angle
)
{
return detail::tvec4<T>(
tanh(angle.x),
tanh(angle.y),
tanh(angle.z),
tanh(angle.w));
}
// asinh
template <typename genType>
GLM_FUNC_QUALIFIER genType asinh
(
genType const & x
)
{
GLM_STATIC_ASSERT(detail::type<genType>::is_float, "'asinh' only accept floating-point input");
return (x < genType(0) ? genType(-1) : (x > genType(0) ? genType(1) : genType(0))) * log(abs(x) + sqrt(genType(1) + x * x));
}
template <typename T>
GLM_FUNC_QUALIFIER detail::tvec2<T> asinh
(
detail::tvec2<T> const & x
)
{
return detail::tvec2<T>(
asinh(x.x),
asinh(x.y));
}
template <typename T>
GLM_FUNC_QUALIFIER detail::tvec3<T> asinh
(
detail::tvec3<T> const & x
)
{
return detail::tvec3<T>(
asinh(x.x),
asinh(x.y),
asinh(x.z));
}
template <typename T>
GLM_FUNC_QUALIFIER detail::tvec4<T> asinh
(
detail::tvec4<T> const & x
)
{
return detail::tvec4<T>(
asinh(x.x),
asinh(x.y),
asinh(x.z),
asinh(x.w));
}
// acosh
template <typename genType>
GLM_FUNC_QUALIFIER genType acosh
(
genType const & x
)
{
GLM_STATIC_ASSERT(detail::type<genType>::is_float, "'acosh' only accept floating-point input");
if(x < genType(1))
return genType(0);
return log(x + sqrt(x * x - genType(1)));
}
template <typename T>
GLM_FUNC_QUALIFIER detail::tvec2<T> acosh
(
detail::tvec2<T> const & x
)
{
return detail::tvec2<T>(
acosh(x.x),
acosh(x.y));
}
template <typename T>
GLM_FUNC_QUALIFIER detail::tvec3<T> acosh
(
detail::tvec3<T> const & x
)
{
return detail::tvec3<T>(
acosh(x.x),
acosh(x.y),
acosh(x.z));
}
template <typename T>
GLM_FUNC_QUALIFIER detail::tvec4<T> acosh
(
detail::tvec4<T> const & x
)
{
return detail::tvec4<T>(
acosh(x.x),
acosh(x.y),
acosh(x.z),
acosh(x.w));
}
// atanh
template <typename genType>
GLM_FUNC_QUALIFIER genType atanh
(
genType const & x
)
{
GLM_STATIC_ASSERT(detail::type<genType>::is_float, "'atanh' only accept floating-point input");
if(abs(x) >= genType(1))
return 0;
return genType(0.5) * log((genType(1) + x) / (genType(1) - x));
}
template <typename T>
GLM_FUNC_QUALIFIER detail::tvec2<T> atanh
(
detail::tvec2<T> const & x
)
{
return detail::tvec2<T>(
atanh(x.x),
atanh(x.y));
}
template <typename T>
GLM_FUNC_QUALIFIER detail::tvec3<T> atanh
(
detail::tvec3<T> const & x
)
{
return detail::tvec3<T>(
atanh(x.x),
atanh(x.y),
atanh(x.z));
}
template <typename T>
GLM_FUNC_QUALIFIER detail::tvec4<T> atanh
(
detail::tvec4<T> const & x
)
{
return detail::tvec4<T>(
atanh(x.x),
atanh(x.y),
atanh(x.z),
atanh(x.w));
}
}//namespace glm }//namespace glm

File diff suppressed because it is too large Load Diff

@ -26,49 +26,55 @@
/// @author Christophe Riccio /// @author Christophe Riccio
/////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////
namespace glm{ namespace glm
template <typename genType>
GLM_FUNC_QUALIFIER genType row(
genType const & m,
int index,
typename genType::row_type const & x)
{
genType Result = m;
for(typename genType::size_type i = 0; i < genType::row_size(); ++i)
Result[i][index] = x[i];
return Result;
}
template <typename genType>
GLM_FUNC_QUALIFIER typename genType::row_type row(
genType const & m,
int index)
{ {
typename genType::row_type Result; template <typename genType>
for(typename genType::size_type i = 0; i < genType::row_size(); ++i) GLM_FUNC_QUALIFIER genType row
Result[i] = m[i][index]; (
return Result; genType const & m,
} int index,
typename genType::row_type const & x
)
{
genType Result = m;
for(typename genType::size_type i = 0; i < genType::row_size(); ++i)
Result[i][index] = x[i];
return Result;
}
template <typename genType> template <typename genType>
GLM_FUNC_QUALIFIER genType column( GLM_FUNC_QUALIFIER typename genType::row_type row
genType const & m, (
int index, genType const & m,
typename genType::col_type const & x) int index
{ )
genType Result = m; {
Result[index] = x; typename genType::row_type Result;
return Result; for(typename genType::size_type i = 0; i < genType::row_size(); ++i)
} Result[i] = m[i][index];
return Result;
}
template <typename genType> template <typename genType>
GLM_FUNC_QUALIFIER typename genType::col_type column( GLM_FUNC_QUALIFIER genType column
genType const & m, (
int index) genType const & m,
{ int index,
return m[index]; typename genType::col_type const & x
} )
{
genType Result = m;
Result[index] = x;
return Result;
}
template <typename genType>
GLM_FUNC_QUALIFIER typename genType::col_type column
(
genType const & m,
int index
)
{
return m[index];
}
}//namespace glm }//namespace glm

@ -26,129 +26,134 @@
/// @author Christophe Riccio /// @author Christophe Riccio
/////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////
namespace glm{ namespace glm
template <typename T>
GLM_FUNC_QUALIFIER detail::tmat3x3<T> affineInverse
(
detail::tmat3x3<T> const & m
)
{
detail::tmat3x3<T> Result(m);
Result[2] = detail::tvec3<T>(0, 0, 1);
Result = transpose(Result);
detail::tvec3<T> Translation = Result * detail::tvec3<T>(-detail::tvec2<T>(m[2]), m[2][2]);
Result[2] = Translation;
return Result;
}
template <typename T>
GLM_FUNC_QUALIFIER detail::tmat4x4<T> affineInverse
(
detail::tmat4x4<T> const & m
)
{
detail::tmat4x4<T> Result(m);
Result[3] = detail::tvec4<T>(0, 0, 0, 1);
Result = transpose(Result);
detail::tvec4<T> Translation = Result * detail::tvec4<T>(-detail::tvec3<T>(m[3]), m[3][3]);
Result[3] = Translation;
return Result;
}
template <typename valType>
GLM_FUNC_QUALIFIER detail::tmat2x2<valType> inverseTranspose(
detail::tmat2x2<valType> const & m)
{ {
valType Determinant = m[0][0] * m[1][1] - m[1][0] * m[0][1]; template <typename T>
GLM_FUNC_QUALIFIER detail::tmat3x3<T> affineInverse
detail::tmat2x2<valType> Inverse( (
+ m[1][1] / Determinant, detail::tmat3x3<T> const & m
- m[0][1] / Determinant, )
- m[1][0] / Determinant, {
+ m[0][0] / Determinant); detail::tmat3x3<T> Result(m);
Result[2] = detail::tvec3<T>(0, 0, 1);
return Inverse; Result = transpose(Result);
} detail::tvec3<T> Translation = Result * detail::tvec3<T>(-detail::tvec2<T>(m[2]), m[2][2]);
Result[2] = Translation;
template <typename valType> return Result;
GLM_FUNC_QUALIFIER detail::tmat3x3<valType> inverseTranspose( }
detail::tmat3x3<valType> const & m)
{ template <typename T>
valType Determinant = GLM_FUNC_QUALIFIER detail::tmat4x4<T> affineInverse
+ m[0][0] * (m[1][1] * m[2][2] - m[1][2] * m[2][1]) (
- m[0][1] * (m[1][0] * m[2][2] - m[1][2] * m[2][0]) detail::tmat4x4<T> const & m
+ m[0][2] * (m[1][0] * m[2][1] - m[1][1] * m[2][0]); )
{
detail::tmat3x3<valType> Inverse; detail::tmat4x4<T> Result(m);
Inverse[0][0] = + (m[1][1] * m[2][2] - m[2][1] * m[1][2]); Result[3] = detail::tvec4<T>(0, 0, 0, 1);
Inverse[0][1] = - (m[1][0] * m[2][2] - m[2][0] * m[1][2]); Result = transpose(Result);
Inverse[0][2] = + (m[1][0] * m[2][1] - m[2][0] * m[1][1]); detail::tvec4<T> Translation = Result * detail::tvec4<T>(-detail::tvec3<T>(m[3]), m[3][3]);
Inverse[1][0] = - (m[0][1] * m[2][2] - m[2][1] * m[0][2]); Result[3] = Translation;
Inverse[1][1] = + (m[0][0] * m[2][2] - m[2][0] * m[0][2]); return Result;
Inverse[1][2] = - (m[0][0] * m[2][1] - m[2][0] * m[0][1]); }
Inverse[2][0] = + (m[0][1] * m[1][2] - m[1][1] * m[0][2]);
Inverse[2][1] = - (m[0][0] * m[1][2] - m[1][0] * m[0][2]); template <typename valType>
Inverse[2][2] = + (m[0][0] * m[1][1] - m[1][0] * m[0][1]); GLM_FUNC_QUALIFIER detail::tmat2x2<valType> inverseTranspose
Inverse /= Determinant; (
detail::tmat2x2<valType> const & m
return Inverse; )
} {
valType Determinant = m[0][0] * m[1][1] - m[1][0] * m[0][1];
template <typename valType>
GLM_FUNC_QUALIFIER detail::tmat4x4<valType> inverseTranspose( detail::tmat2x2<valType> Inverse(
detail::tmat4x4<valType> const & m) + m[1][1] / Determinant,
{ - m[0][1] / Determinant,
valType SubFactor00 = m[2][2] * m[3][3] - m[3][2] * m[2][3]; - m[1][0] / Determinant,
valType SubFactor01 = m[2][1] * m[3][3] - m[3][1] * m[2][3]; + m[0][0] / Determinant);
valType SubFactor02 = m[2][1] * m[3][2] - m[3][1] * m[2][2];
valType SubFactor03 = m[2][0] * m[3][3] - m[3][0] * m[2][3]; return Inverse;
valType SubFactor04 = m[2][0] * m[3][2] - m[3][0] * m[2][2]; }
valType SubFactor05 = m[2][0] * m[3][1] - m[3][0] * m[2][1];
valType SubFactor06 = m[1][2] * m[3][3] - m[3][2] * m[1][3]; template <typename valType>
valType SubFactor07 = m[1][1] * m[3][3] - m[3][1] * m[1][3]; GLM_FUNC_QUALIFIER detail::tmat3x3<valType> inverseTranspose
valType SubFactor08 = m[1][1] * m[3][2] - m[3][1] * m[1][2]; (
valType SubFactor09 = m[1][0] * m[3][3] - m[3][0] * m[1][3]; detail::tmat3x3<valType> const & m
valType SubFactor10 = m[1][0] * m[3][2] - m[3][0] * m[1][2]; )
valType SubFactor11 = m[1][1] * m[3][3] - m[3][1] * m[1][3]; {
valType SubFactor12 = m[1][0] * m[3][1] - m[3][0] * m[1][1]; valType Determinant =
valType SubFactor13 = m[1][2] * m[2][3] - m[2][2] * m[1][3]; + m[0][0] * (m[1][1] * m[2][2] - m[1][2] * m[2][1])
valType SubFactor14 = m[1][1] * m[2][3] - m[2][1] * m[1][3]; - m[0][1] * (m[1][0] * m[2][2] - m[1][2] * m[2][0])
valType SubFactor15 = m[1][1] * m[2][2] - m[2][1] * m[1][2]; + m[0][2] * (m[1][0] * m[2][1] - m[1][1] * m[2][0]);
valType SubFactor16 = m[1][0] * m[2][3] - m[2][0] * m[1][3];
valType SubFactor17 = m[1][0] * m[2][2] - m[2][0] * m[1][2]; detail::tmat3x3<valType> Inverse;
valType SubFactor18 = m[1][0] * m[2][1] - m[2][0] * m[1][1]; Inverse[0][0] = + (m[1][1] * m[2][2] - m[2][1] * m[1][2]);
Inverse[0][1] = - (m[1][0] * m[2][2] - m[2][0] * m[1][2]);
detail::tmat4x4<valType> Inverse; Inverse[0][2] = + (m[1][0] * m[2][1] - m[2][0] * m[1][1]);
Inverse[0][0] = + (m[1][1] * SubFactor00 - m[1][2] * SubFactor01 + m[1][3] * SubFactor02); Inverse[1][0] = - (m[0][1] * m[2][2] - m[2][1] * m[0][2]);
Inverse[0][1] = - (m[1][0] * SubFactor00 - m[1][2] * SubFactor03 + m[1][3] * SubFactor04); Inverse[1][1] = + (m[0][0] * m[2][2] - m[2][0] * m[0][2]);
Inverse[0][2] = + (m[1][0] * SubFactor01 - m[1][1] * SubFactor03 + m[1][3] * SubFactor05); Inverse[1][2] = - (m[0][0] * m[2][1] - m[2][0] * m[0][1]);
Inverse[0][3] = - (m[1][0] * SubFactor02 - m[1][1] * SubFactor04 + m[1][2] * SubFactor05); Inverse[2][0] = + (m[0][1] * m[1][2] - m[1][1] * m[0][2]);
Inverse[2][1] = - (m[0][0] * m[1][2] - m[1][0] * m[0][2]);
Inverse[1][0] = - (m[0][1] * SubFactor00 - m[0][2] * SubFactor01 + m[0][3] * SubFactor02); Inverse[2][2] = + (m[0][0] * m[1][1] - m[1][0] * m[0][1]);
Inverse[1][1] = + (m[0][0] * SubFactor00 - m[0][2] * SubFactor03 + m[0][3] * SubFactor04); Inverse /= Determinant;
Inverse[1][2] = - (m[0][0] * SubFactor01 - m[0][1] * SubFactor03 + m[0][3] * SubFactor05);
Inverse[1][3] = + (m[0][0] * SubFactor02 - m[0][1] * SubFactor04 + m[0][2] * SubFactor05); return Inverse;
}
Inverse[2][0] = + (m[0][1] * SubFactor06 - m[0][2] * SubFactor07 + m[0][3] * SubFactor08);
Inverse[2][1] = - (m[0][0] * SubFactor06 - m[0][2] * SubFactor09 + m[0][3] * SubFactor10); template <typename valType>
Inverse[2][2] = + (m[0][0] * SubFactor11 - m[0][1] * SubFactor09 + m[0][3] * SubFactor12); GLM_FUNC_QUALIFIER detail::tmat4x4<valType> inverseTranspose
Inverse[2][3] = - (m[0][0] * SubFactor08 - m[0][1] * SubFactor10 + m[0][2] * SubFactor12); (
detail::tmat4x4<valType> const & m
Inverse[3][0] = - (m[0][1] * SubFactor13 - m[0][2] * SubFactor14 + m[0][3] * SubFactor15); )
Inverse[3][1] = + (m[0][0] * SubFactor13 - m[0][2] * SubFactor16 + m[0][3] * SubFactor17); {
Inverse[3][2] = - (m[0][0] * SubFactor14 - m[0][1] * SubFactor16 + m[0][3] * SubFactor18); valType SubFactor00 = m[2][2] * m[3][3] - m[3][2] * m[2][3];
Inverse[3][3] = + (m[0][0] * SubFactor15 - m[0][1] * SubFactor17 + m[0][2] * SubFactor18); valType SubFactor01 = m[2][1] * m[3][3] - m[3][1] * m[2][3];
valType SubFactor02 = m[2][1] * m[3][2] - m[3][1] * m[2][2];
valType Determinant = valType SubFactor03 = m[2][0] * m[3][3] - m[3][0] * m[2][3];
+ m[0][0] * Inverse[0][0] valType SubFactor04 = m[2][0] * m[3][2] - m[3][0] * m[2][2];
+ m[0][1] * Inverse[0][1] valType SubFactor05 = m[2][0] * m[3][1] - m[3][0] * m[2][1];
+ m[0][2] * Inverse[0][2] valType SubFactor06 = m[1][2] * m[3][3] - m[3][2] * m[1][3];
+ m[0][3] * Inverse[0][3]; valType SubFactor07 = m[1][1] * m[3][3] - m[3][1] * m[1][3];
valType SubFactor08 = m[1][1] * m[3][2] - m[3][1] * m[1][2];
Inverse /= Determinant; valType SubFactor09 = m[1][0] * m[3][3] - m[3][0] * m[1][3];
valType SubFactor10 = m[1][0] * m[3][2] - m[3][0] * m[1][2];
return Inverse; valType SubFactor11 = m[1][1] * m[3][3] - m[3][1] * m[1][3];
} valType SubFactor12 = m[1][0] * m[3][1] - m[3][0] * m[1][1];
valType SubFactor13 = m[1][2] * m[2][3] - m[2][2] * m[1][3];
valType SubFactor14 = m[1][1] * m[2][3] - m[2][1] * m[1][3];
valType SubFactor15 = m[1][1] * m[2][2] - m[2][1] * m[1][2];
valType SubFactor16 = m[1][0] * m[2][3] - m[2][0] * m[1][3];
valType SubFactor17 = m[1][0] * m[2][2] - m[2][0] * m[1][2];
valType SubFactor18 = m[1][0] * m[2][1] - m[2][0] * m[1][1];
detail::tmat4x4<valType> Inverse;
Inverse[0][0] = + (m[1][1] * SubFactor00 - m[1][2] * SubFactor01 + m[1][3] * SubFactor02);
Inverse[0][1] = - (m[1][0] * SubFactor00 - m[1][2] * SubFactor03 + m[1][3] * SubFactor04);
Inverse[0][2] = + (m[1][0] * SubFactor01 - m[1][1] * SubFactor03 + m[1][3] * SubFactor05);
Inverse[0][3] = - (m[1][0] * SubFactor02 - m[1][1] * SubFactor04 + m[1][2] * SubFactor05);
Inverse[1][0] = - (m[0][1] * SubFactor00 - m[0][2] * SubFactor01 + m[0][3] * SubFactor02);
Inverse[1][1] = + (m[0][0] * SubFactor00 - m[0][2] * SubFactor03 + m[0][3] * SubFactor04);
Inverse[1][2] = - (m[0][0] * SubFactor01 - m[0][1] * SubFactor03 + m[0][3] * SubFactor05);
Inverse[1][3] = + (m[0][0] * SubFactor02 - m[0][1] * SubFactor04 + m[0][2] * SubFactor05);
Inverse[2][0] = + (m[0][1] * SubFactor06 - m[0][2] * SubFactor07 + m[0][3] * SubFactor08);
Inverse[2][1] = - (m[0][0] * SubFactor06 - m[0][2] * SubFactor09 + m[0][3] * SubFactor10);
Inverse[2][2] = + (m[0][0] * SubFactor11 - m[0][1] * SubFactor09 + m[0][3] * SubFactor12);
Inverse[2][3] = - (m[0][0] * SubFactor08 - m[0][1] * SubFactor10 + m[0][2] * SubFactor12);
Inverse[3][0] = - (m[0][1] * SubFactor13 - m[0][2] * SubFactor14 + m[0][3] * SubFactor15);
Inverse[3][1] = + (m[0][0] * SubFactor13 - m[0][2] * SubFactor16 + m[0][3] * SubFactor17);
Inverse[3][2] = - (m[0][0] * SubFactor14 - m[0][1] * SubFactor16 + m[0][3] * SubFactor18);
Inverse[3][3] = + (m[0][0] * SubFactor15 - m[0][1] * SubFactor17 + m[0][2] * SubFactor18);
valType Determinant =
+ m[0][0] * Inverse[0][0]
+ m[0][1] * Inverse[0][1]
+ m[0][2] * Inverse[0][2]
+ m[0][3] * Inverse[0][3];
Inverse /= Determinant;
return Inverse;
}
}//namespace glm }//namespace glm

@ -26,388 +26,387 @@
/// @author Christophe Riccio /// @author Christophe Riccio
/////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////
namespace glm{ namespace glm
template <typename T>
GLM_FUNC_QUALIFIER detail::tmat4x4<T> translate
(
detail::tmat4x4<T> const & m,
detail::tvec3<T> const & v
)
{ {
detail::tmat4x4<T> Result(m); template <typename T>
Result[3] = m[0] * v[0] + m[1] * v[1] + m[2] * v[2] + m[3]; GLM_FUNC_QUALIFIER detail::tmat4x4<T> translate
return Result; (
} detail::tmat4x4<T> const & m,
detail::tvec3<T> const & v
template <typename T> )
GLM_FUNC_QUALIFIER detail::tmat4x4<T> rotate {
( detail::tmat4x4<T> Result(m);
detail::tmat4x4<T> const & m, Result[3] = m[0] * v[0] + m[1] * v[1] + m[2] * v[2] + m[3];
T const & angle, return Result;
detail::tvec3<T> const & v }
)
{ template <typename T>
T a = radians(angle); GLM_FUNC_QUALIFIER detail::tmat4x4<T> rotate
T c = cos(a); (
T s = sin(a); detail::tmat4x4<T> const & m,
T const & angle,
detail::tvec3<T> axis = normalize(v); detail::tvec3<T> const & v
)
detail::tvec3<T> temp = (T(1) - c) * axis; {
T a = radians(angle);
detail::tmat4x4<T> Rotate(detail::tmat4x4<T>::null); T c = cos(a);
Rotate[0][0] = c + temp[0] * axis[0]; T s = sin(a);
Rotate[0][1] = 0 + temp[0] * axis[1] + s * axis[2];
Rotate[0][2] = 0 + temp[0] * axis[2] - s * axis[1]; detail::tvec3<T> axis = normalize(v);
Rotate[1][0] = 0 + temp[1] * axis[0] - s * axis[2]; detail::tvec3<T> temp = (T(1) - c) * axis;
Rotate[1][1] = c + temp[1] * axis[1];
Rotate[1][2] = 0 + temp[1] * axis[2] + s * axis[0]; detail::tmat4x4<T> Rotate(detail::tmat4x4<T>::null);
Rotate[0][0] = c + temp[0] * axis[0];
Rotate[2][0] = 0 + temp[2] * axis[0] + s * axis[1]; Rotate[0][1] = 0 + temp[0] * axis[1] + s * axis[2];
Rotate[2][1] = 0 + temp[2] * axis[1] - s * axis[0]; Rotate[0][2] = 0 + temp[0] * axis[2] - s * axis[1];
Rotate[2][2] = c + temp[2] * axis[2];
Rotate[1][0] = 0 + temp[1] * axis[0] - s * axis[2];
detail::tmat4x4<T> Result(detail::tmat4x4<T>::null); Rotate[1][1] = c + temp[1] * axis[1];
Result[0] = m[0] * Rotate[0][0] + m[1] * Rotate[0][1] + m[2] * Rotate[0][2]; Rotate[1][2] = 0 + temp[1] * axis[2] + s * axis[0];
Result[1] = m[0] * Rotate[1][0] + m[1] * Rotate[1][1] + m[2] * Rotate[1][2];
Result[2] = m[0] * Rotate[2][0] + m[1] * Rotate[2][1] + m[2] * Rotate[2][2]; Rotate[2][0] = 0 + temp[2] * axis[0] + s * axis[1];
Result[3] = m[3]; Rotate[2][1] = 0 + temp[2] * axis[1] - s * axis[0];
return Result; Rotate[2][2] = c + temp[2] * axis[2];
}
detail::tmat4x4<T> Result(detail::tmat4x4<T>::null);
template <typename T> Result[0] = m[0] * Rotate[0][0] + m[1] * Rotate[0][1] + m[2] * Rotate[0][2];
GLM_FUNC_QUALIFIER detail::tmat4x4<T> scale Result[1] = m[0] * Rotate[1][0] + m[1] * Rotate[1][1] + m[2] * Rotate[1][2];
( Result[2] = m[0] * Rotate[2][0] + m[1] * Rotate[2][1] + m[2] * Rotate[2][2];
detail::tmat4x4<T> const & m, Result[3] = m[3];
detail::tvec3<T> const & v return Result;
) }
{
detail::tmat4x4<T> Result(detail::tmat4x4<T>::null); template <typename T>
Result[0] = m[0] * v[0]; GLM_FUNC_QUALIFIER detail::tmat4x4<T> scale
Result[1] = m[1] * v[1]; (
Result[2] = m[2] * v[2]; detail::tmat4x4<T> const & m,
Result[3] = m[3]; detail::tvec3<T> const & v
return Result; )
} {
detail::tmat4x4<T> Result(detail::tmat4x4<T>::null);
template <typename T> Result[0] = m[0] * v[0];
GLM_FUNC_QUALIFIER detail::tmat4x4<T> translate_slow Result[1] = m[1] * v[1];
( Result[2] = m[2] * v[2];
detail::tmat4x4<T> const & m, Result[3] = m[3];
detail::tvec3<T> const & v return Result;
) }
{
detail::tmat4x4<T> Result(T(1)); template <typename T>
Result[3] = detail::tvec4<T>(v, T(1)); GLM_FUNC_QUALIFIER detail::tmat4x4<T> translate_slow
return m * Result; (
detail::tmat4x4<T> const & m,
//detail::tmat4x4<valType> Result(m); detail::tvec3<T> const & v
Result[3] = m[0] * v[0] + m[1] * v[1] + m[2] * v[2] + m[3]; )
//Result[3][0] = m[0][0] * v[0] + m[1][0] * v[1] + m[2][0] * v[2] + m[3][0]; {
//Result[3][1] = m[0][1] * v[0] + m[1][1] * v[1] + m[2][1] * v[2] + m[3][1]; detail::tmat4x4<T> Result(T(1));
//Result[3][2] = m[0][2] * v[0] + m[1][2] * v[1] + m[2][2] * v[2] + m[3][2]; Result[3] = detail::tvec4<T>(v, T(1));
//Result[3][3] = m[0][3] * v[0] + m[1][3] * v[1] + m[2][3] * v[2] + m[3][3]; return m * Result;
//return Result;
} //detail::tmat4x4<valType> Result(m);
Result[3] = m[0] * v[0] + m[1] * v[1] + m[2] * v[2] + m[3];
template <typename T> //Result[3][0] = m[0][0] * v[0] + m[1][0] * v[1] + m[2][0] * v[2] + m[3][0];
GLM_FUNC_QUALIFIER detail::tmat4x4<T> rotate_slow //Result[3][1] = m[0][1] * v[0] + m[1][1] * v[1] + m[2][1] * v[2] + m[3][1];
( //Result[3][2] = m[0][2] * v[0] + m[1][2] * v[1] + m[2][2] * v[2] + m[3][2];
detail::tmat4x4<T> const & m, //Result[3][3] = m[0][3] * v[0] + m[1][3] * v[1] + m[2][3] * v[2] + m[3][3];
T const & angle, //return Result;
detail::tvec3<T> const & v }
)
{ template <typename T>
T a = radians(angle); GLM_FUNC_QUALIFIER detail::tmat4x4<T> rotate_slow
T c = cos(a); (
T s = sin(a); detail::tmat4x4<T> const & m,
detail::tmat4x4<T> Result; T const & angle,
detail::tvec3<T> const & v
detail::tvec3<T> axis = normalize(v); )
{
Result[0][0] = c + (1 - c) * axis.x * axis.x; T a = radians(angle);
Result[0][1] = (1 - c) * axis.x * axis.y + s * axis.z; T c = cos(a);
Result[0][2] = (1 - c) * axis.x * axis.z - s * axis.y; T s = sin(a);
Result[0][3] = 0; detail::tmat4x4<T> Result;
Result[1][0] = (1 - c) * axis.y * axis.x - s * axis.z; detail::tvec3<T> axis = normalize(v);
Result[1][1] = c + (1 - c) * axis.y * axis.y;
Result[1][2] = (1 - c) * axis.y * axis.z + s * axis.x; Result[0][0] = c + (1 - c) * axis.x * axis.x;
Result[1][3] = 0; Result[0][1] = (1 - c) * axis.x * axis.y + s * axis.z;
Result[0][2] = (1 - c) * axis.x * axis.z - s * axis.y;
Result[2][0] = (1 - c) * axis.z * axis.x + s * axis.y; Result[0][3] = 0;
Result[2][1] = (1 - c) * axis.z * axis.y - s * axis.x;
Result[2][2] = c + (1 - c) * axis.z * axis.z; Result[1][0] = (1 - c) * axis.y * axis.x - s * axis.z;
Result[2][3] = 0; Result[1][1] = c + (1 - c) * axis.y * axis.y;
Result[1][2] = (1 - c) * axis.y * axis.z + s * axis.x;
Result[3] = detail::tvec4<T>(0, 0, 0, 1); Result[1][3] = 0;
return m * Result;
} Result[2][0] = (1 - c) * axis.z * axis.x + s * axis.y;
Result[2][1] = (1 - c) * axis.z * axis.y - s * axis.x;
template <typename T> Result[2][2] = c + (1 - c) * axis.z * axis.z;
GLM_FUNC_QUALIFIER detail::tmat4x4<T> scale_slow Result[2][3] = 0;
(
detail::tmat4x4<T> const & m, Result[3] = detail::tvec4<T>(0, 0, 0, 1);
detail::tvec3<T> const & v return m * Result;
) }
{
detail::tmat4x4<T> Result(T(1)); template <typename T>
Result[0][0] = v.x; GLM_FUNC_QUALIFIER detail::tmat4x4<T> scale_slow
Result[1][1] = v.y; (
Result[2][2] = v.z; detail::tmat4x4<T> const & m,
return m * Result; detail::tvec3<T> const & v
} )
{
template <typename valType> detail::tmat4x4<T> Result(T(1));
GLM_FUNC_QUALIFIER detail::tmat4x4<valType> ortho Result[0][0] = v.x;
( Result[1][1] = v.y;
valType const & left, Result[2][2] = v.z;
valType const & right, return m * Result;
valType const & bottom, }
valType const & top,
valType const & zNear, template <typename valType>
valType const & zFar GLM_FUNC_QUALIFIER detail::tmat4x4<valType> ortho
) (
{ valType const & left,
detail::tmat4x4<valType> Result(1); valType const & right,
Result[0][0] = valType(2) / (right - left); valType const & bottom,
Result[1][1] = valType(2) / (top - bottom); valType const & top,
Result[2][2] = - valType(2) / (zFar - zNear); valType const & zNear,
Result[3][0] = - (right + left) / (right - left); valType const & zFar
Result[3][1] = - (top + bottom) / (top - bottom); )
Result[3][2] = - (zFar + zNear) / (zFar - zNear); {
return Result; detail::tmat4x4<valType> Result(1);
} Result[0][0] = valType(2) / (right - left);
Result[1][1] = valType(2) / (top - bottom);
template <typename valType> Result[2][2] = - valType(2) / (zFar - zNear);
GLM_FUNC_QUALIFIER detail::tmat4x4<valType> ortho( Result[3][0] = - (right + left) / (right - left);
valType const & left, Result[3][1] = - (top + bottom) / (top - bottom);
valType const & right, Result[3][2] = - (zFar + zNear) / (zFar - zNear);
valType const & bottom, return Result;
valType const & top) }
{
detail::tmat4x4<valType> Result(1); template <typename valType>
Result[0][0] = valType(2) / (right - left); GLM_FUNC_QUALIFIER detail::tmat4x4<valType> ortho(
Result[1][1] = valType(2) / (top - bottom); valType const & left,
Result[2][2] = - valType(1); valType const & right,
Result[3][0] = - (right + left) / (right - left); valType const & bottom,
Result[3][1] = - (top + bottom) / (top - bottom); valType const & top)
return Result; {
} detail::tmat4x4<valType> Result(1);
Result[0][0] = valType(2) / (right - left);
template <typename valType> Result[1][1] = valType(2) / (top - bottom);
GLM_FUNC_QUALIFIER detail::tmat4x4<valType> frustum Result[2][2] = - valType(1);
( Result[3][0] = - (right + left) / (right - left);
valType const & left, Result[3][1] = - (top + bottom) / (top - bottom);
valType const & right, return Result;
valType const & bottom, }
valType const & top,
valType const & nearVal, template <typename valType>
valType const & farVal GLM_FUNC_QUALIFIER detail::tmat4x4<valType> frustum
) (
{ valType const & left,
detail::tmat4x4<valType> Result(0); valType const & right,
Result[0][0] = (valType(2) * nearVal) / (right - left); valType const & bottom,
Result[1][1] = (valType(2) * nearVal) / (top - bottom); valType const & top,
Result[2][0] = (right + left) / (right - left); valType const & nearVal,
Result[2][1] = (top + bottom) / (top - bottom); valType const & farVal
Result[2][2] = -(farVal + nearVal) / (farVal - nearVal); )
Result[2][3] = valType(-1); {
Result[3][2] = -(valType(2) * farVal * nearVal) / (farVal - nearVal); detail::tmat4x4<valType> Result(0);
return Result; Result[0][0] = (valType(2) * nearVal) / (right - left);
} Result[1][1] = (valType(2) * nearVal) / (top - bottom);
Result[2][0] = (right + left) / (right - left);
template <typename valType> Result[2][1] = (top + bottom) / (top - bottom);
GLM_FUNC_QUALIFIER detail::tmat4x4<valType> perspective Result[2][2] = -(farVal + nearVal) / (farVal - nearVal);
( Result[2][3] = valType(-1);
valType const & fovy, Result[3][2] = -(valType(2) * farVal * nearVal) / (farVal - nearVal);
valType const & aspect, return Result;
valType const & zNear, }
valType const & zFar
) template <typename valType>
{ GLM_FUNC_QUALIFIER detail::tmat4x4<valType> perspective
valType range = tan(radians(fovy / valType(2))) * zNear; (
valType left = -range * aspect; valType const & fovy,
valType right = range * aspect; valType const & aspect,
valType bottom = -range; valType const & zNear,
valType top = range; valType const & zFar
)
detail::tmat4x4<valType> Result(valType(0)); {
Result[0][0] = (valType(2) * zNear) / (right - left); valType range = tan(radians(fovy / valType(2))) * zNear;
Result[1][1] = (valType(2) * zNear) / (top - bottom); valType left = -range * aspect;
Result[2][2] = - (zFar + zNear) / (zFar - zNear); valType right = range * aspect;
Result[2][3] = - valType(1); valType bottom = -range;
Result[3][2] = - (valType(2) * zFar * zNear) / (zFar - zNear); valType top = range;
return Result;
} detail::tmat4x4<valType> Result(valType(0));
Result[0][0] = (valType(2) * zNear) / (right - left);
template <typename valType> Result[1][1] = (valType(2) * zNear) / (top - bottom);
GLM_FUNC_QUALIFIER detail::tmat4x4<valType> perspectiveFov Result[2][2] = - (zFar + zNear) / (zFar - zNear);
( Result[2][3] = - valType(1);
valType const & fov, Result[3][2] = - (valType(2) * zFar * zNear) / (zFar - zNear);
valType const & width, return Result;
valType const & height, }
valType const & zNear,
valType const & zFar template <typename valType>
) GLM_FUNC_QUALIFIER detail::tmat4x4<valType> perspectiveFov
{ (
valType rad = glm::radians(fov); valType const & fov,
valType h = glm::cos(valType(0.5) * rad) / glm::sin(valType(0.5) * rad); valType const & width,
valType w = h * height / width; valType const & height,
valType const & zNear,
detail::tmat4x4<valType> Result(valType(0)); valType const & zFar
Result[0][0] = w; )
Result[1][1] = h; {
Result[2][2] = (zFar + zNear) / (zFar - zNear); valType rad = glm::radians(fov);
Result[2][3] = valType(1); valType h = glm::cos(valType(0.5) * rad) / glm::sin(valType(0.5) * rad);
Result[3][2] = -(valType(2) * zFar * zNear) / (zFar - zNear); valType w = h * height / width;
return Result;
} detail::tmat4x4<valType> Result(valType(0));
Result[0][0] = w;
template <typename T> Result[1][1] = h;
GLM_FUNC_QUALIFIER detail::tmat4x4<T> infinitePerspective Result[2][2] = (zFar + zNear) / (zFar - zNear);
( Result[2][3] = valType(1);
T fovy, Result[3][2] = -(valType(2) * zFar * zNear) / (zFar - zNear);
T aspect, return Result;
T zNear }
)
{ template <typename T>
T range = tan(radians(fovy / T(2))) * zNear; GLM_FUNC_QUALIFIER detail::tmat4x4<T> infinitePerspective
T left = -range * aspect; (
T right = range * aspect; T fovy,
T bottom = -range; T aspect,
T top = range; T zNear
)
detail::tmat4x4<T> Result(T(0)); {
Result[0][0] = (T(2) * zNear) / (right - left); T range = tan(radians(fovy / T(2))) * zNear;
Result[1][1] = (T(2) * zNear) / (top - bottom); T left = -range * aspect;
Result[2][2] = - T(1); T right = range * aspect;
Result[2][3] = - T(1); T bottom = -range;
Result[3][2] = - T(2) * zNear; T top = range;
return Result;
} detail::tmat4x4<T> Result(T(0));
Result[0][0] = (T(2) * zNear) / (right - left);
template <typename T> Result[1][1] = (T(2) * zNear) / (top - bottom);
GLM_FUNC_QUALIFIER detail::tmat4x4<T> tweakedInfinitePerspective Result[2][2] = - T(1);
( Result[2][3] = - T(1);
T fovy, Result[3][2] = - T(2) * zNear;
T aspect, return Result;
T zNear }
)
{ template <typename T>
T range = tan(radians(fovy / T(2))) * zNear; GLM_FUNC_QUALIFIER detail::tmat4x4<T> tweakedInfinitePerspective
T left = -range * aspect; (
T right = range * aspect; T fovy,
T bottom = -range; T aspect,
T top = range; T zNear
)
detail::tmat4x4<T> Result(T(0)); {
Result[0][0] = (T(2) * zNear) / (right - left); T range = tan(radians(fovy / T(2))) * zNear;
Result[1][1] = (T(2) * zNear) / (top - bottom); T left = -range * aspect;
Result[2][2] = T(0.0001) - T(1); T right = range * aspect;
Result[2][3] = T(-1); T bottom = -range;
Result[3][2] = - (T(0.0001) - T(2)) * zNear; T top = range;
return Result;
} detail::tmat4x4<T> Result(T(0));
Result[0][0] = (T(2) * zNear) / (right - left);
template <typename T, typename U> Result[1][1] = (T(2) * zNear) / (top - bottom);
GLM_FUNC_QUALIFIER detail::tvec3<T> project Result[2][2] = T(0.0001) - T(1);
( Result[2][3] = T(-1);
detail::tvec3<T> const & obj, Result[3][2] = - (T(0.0001) - T(2)) * zNear;
detail::tmat4x4<T> const & model, return Result;
detail::tmat4x4<T> const & proj, }
detail::tvec4<U> const & viewport
) template <typename T, typename U>
{ GLM_FUNC_QUALIFIER detail::tvec3<T> project
detail::tvec4<T> tmp = detail::tvec4<T>(obj, T(1)); (
tmp = model * tmp; detail::tvec3<T> const & obj,
tmp = proj * tmp; detail::tmat4x4<T> const & model,
detail::tmat4x4<T> const & proj,
tmp /= tmp.w; detail::tvec4<U> const & viewport
tmp = tmp * T(0.5) + T(0.5); )
tmp[0] = tmp[0] * T(viewport[2]) + T(viewport[0]); {
tmp[1] = tmp[1] * T(viewport[3]) + T(viewport[1]); detail::tvec4<T> tmp = detail::tvec4<T>(obj, T(1));
tmp = model * tmp;
return detail::tvec3<T>(tmp); tmp = proj * tmp;
}
tmp /= tmp.w;
template <typename T, typename U> tmp = tmp * T(0.5) + T(0.5);
GLM_FUNC_QUALIFIER detail::tvec3<T> unProject tmp[0] = tmp[0] * T(viewport[2]) + T(viewport[0]);
( tmp[1] = tmp[1] * T(viewport[3]) + T(viewport[1]);
detail::tvec3<T> const & win,
detail::tmat4x4<T> const & model, return detail::tvec3<T>(tmp);
detail::tmat4x4<T> const & proj, }
detail::tvec4<U> const & viewport
) template <typename T, typename U>
{ GLM_FUNC_QUALIFIER detail::tvec3<T> unProject
detail::tmat4x4<T> inverse = glm::inverse(proj * model); (
detail::tvec3<T> const & win,
detail::tvec4<T> tmp = detail::tvec4<T>(win, T(1)); detail::tmat4x4<T> const & model,
tmp.x = (tmp.x - T(viewport[0])) / T(viewport[2]); detail::tmat4x4<T> const & proj,
tmp.y = (tmp.y - T(viewport[1])) / T(viewport[3]); detail::tvec4<U> const & viewport
tmp = tmp * T(2) - T(1); )
{
detail::tvec4<T> obj = inverse * tmp; detail::tmat4x4<T> inverse = glm::inverse(proj * model);
obj /= obj.w;
detail::tvec4<T> tmp = detail::tvec4<T>(win, T(1));
return detail::tvec3<T>(obj); tmp.x = (tmp.x - T(viewport[0])) / T(viewport[2]);
} tmp.y = (tmp.y - T(viewport[1])) / T(viewport[3]);
tmp = tmp * T(2) - T(1);
template <typename T, typename U>
detail::tmat4x4<T> pickMatrix detail::tvec4<T> obj = inverse * tmp;
( obj /= obj.w;
detail::tvec2<T> const & center,
detail::tvec2<T> const & delta, return detail::tvec3<T>(obj);
detail::tvec4<U> const & viewport }
)
{ template <typename T, typename U>
assert(delta.x > T(0) && delta.y > T(0)); detail::tmat4x4<T> pickMatrix
detail::tmat4x4<T> Result(1.0f); (
detail::tvec2<T> const & center,
if(!(delta.x > T(0) && delta.y > T(0))) detail::tvec2<T> const & delta,
return Result; // Error detail::tvec4<U> const & viewport
)
detail::tvec3<T> Temp( {
(T(viewport[2]) - T(2) * (center.x - T(viewport[0]))) / delta.x, assert(delta.x > T(0) && delta.y > T(0));
(T(viewport[3]) - T(2) * (center.y - T(viewport[1]))) / delta.y, detail::tmat4x4<T> Result(1.0f);
T(0));
if(!(delta.x > T(0) && delta.y > T(0)))
// Translate and scale the picked region to the entire window return Result; // Error
Result = translate(Result, Temp);
return scale(Result, detail::tvec3<T>(T(viewport[2]) / delta.x, T(viewport[3]) / delta.y, T(1))); detail::tvec3<T> Temp(
} (T(viewport[2]) - T(2) * (center.x - T(viewport[0]))) / delta.x,
(T(viewport[3]) - T(2) * (center.y - T(viewport[1]))) / delta.y,
template <typename T> T(0));
GLM_FUNC_QUALIFIER detail::tmat4x4<T> lookAt
( // Translate and scale the picked region to the entire window
detail::tvec3<T> const & eye, Result = translate(Result, Temp);
detail::tvec3<T> const & center, return scale(Result, detail::tvec3<T>(T(viewport[2]) / delta.x, T(viewport[3]) / delta.y, T(1)));
detail::tvec3<T> const & up }
)
{ template <typename T>
detail::tvec3<T> f = normalize(center - eye); GLM_FUNC_QUALIFIER detail::tmat4x4<T> lookAt
detail::tvec3<T> u = normalize(up); (
detail::tvec3<T> s = normalize(cross(f, u)); detail::tvec3<T> const & eye,
u = cross(s, f); detail::tvec3<T> const & center,
detail::tvec3<T> const & up
detail::tmat4x4<T> Result(1); )
Result[0][0] = s.x; {
Result[1][0] = s.y; detail::tvec3<T> f = normalize(center - eye);
Result[2][0] = s.z; detail::tvec3<T> u = normalize(up);
Result[0][1] = u.x; detail::tvec3<T> s = normalize(cross(f, u));
Result[1][1] = u.y; u = cross(s, f);
Result[2][1] = u.z;
Result[0][2] =-f.x; detail::tmat4x4<T> Result(1);
Result[1][2] =-f.y; Result[0][0] = s.x;
Result[2][2] =-f.z; Result[1][0] = s.y;
/* Test this instead of translate3D Result[2][0] = s.z;
Result[3][0] =-dot(s, eye); Result[0][1] = u.x;
Result[3][1] =-dot(y, eye); Result[1][1] = u.y;
Result[3][2] = dot(f, eye); Result[2][1] = u.z;
*/ Result[0][2] =-f.x;
return translate(Result, -eye); Result[1][2] =-f.y;
} Result[2][2] =-f.z;
/* Test this instead of translate3D
Result[3][0] =-dot(s, eye);
Result[3][1] =-dot(y, eye);
Result[3][2] = dot(f, eye);
*/
return translate(Result, -eye);
}
}//namespace glm }//namespace glm

File diff suppressed because it is too large Load Diff

@ -29,8 +29,8 @@
#include <limits> #include <limits>
namespace glm{ namespace glm{
namespace detail{ namespace detail
{
template <typename T> template <typename T>
GLM_FUNC_QUALIFIER tquat<T>::tquat() : GLM_FUNC_QUALIFIER tquat<T>::tquat() :
x(0), x(0),

@ -9,200 +9,136 @@
#include <ctime> #include <ctime>
#include <cassert> #include <cassert>
#include "../core/_vectorize.hpp"
namespace glm{ namespace glm{
namespace detail
template <>
GLM_FUNC_QUALIFIER glm::half linearRand
(
glm::half const & Min,
glm::half const & Max
)
{
return glm::half(float(std::rand()) / float(RAND_MAX) * (float(Max) - float(Min)) + float(Min));
}
template <>
GLM_FUNC_QUALIFIER float linearRand
(
float const & Min,
float const & Max
)
{
return float(std::rand()) / float(RAND_MAX) * (Max - Min) + Min;
}
template <>
GLM_FUNC_QUALIFIER double linearRand
(
double const & Min,
double const & Max
)
{
return double(std::rand()) / double(RAND_MAX) * (Max - Min) + Min;
}
template <typename T>
GLM_FUNC_QUALIFIER detail::tvec2<T> linearRand
(
detail::tvec2<T> const & Min,
detail::tvec2<T> const & Max
)
{
return detail::tvec2<T>(
linearRand(Min.x, Max.x),
linearRand(Min.y, Max.y));
}
template <typename T>
GLM_FUNC_QUALIFIER detail::tvec3<T> linearRand
(
detail::tvec3<T> const & Min,
detail::tvec3<T> const & Max
)
{ {
return detail::tvec3<T>( struct compute_linearRand
linearRand(Min.x, Max.x), {
linearRand(Min.y, Max.y), template <typename T>
linearRand(Min.z, Max.z)); GLM_FUNC_QUALIFIER T operator() (T const & Min, T const & Max) const
} {
GLM_STATIC_ASSERT(0, "'linearRand' invalid template parameter type. GLM_GTC_random only supports floating-point template types.");
template <typename T> return Min;
GLM_FUNC_QUALIFIER detail::tvec4<T> linearRand }
( };
detail::tvec4<T> const & Min,
detail::tvec4<T> const & Max template <>
) GLM_FUNC_QUALIFIER half compute_linearRand::operator()<half> (half const & Min, half const & Max) const
{ {
return detail::tvec4<T>( return half(float(std::rand()) / float(RAND_MAX) * (float(Max) - float(Min)) + float(Min));
linearRand(Min.x, Max.x), }
linearRand(Min.y, Max.y),
linearRand(Min.z, Max.z),
linearRand(Min.w, Max.w));
}
template <typename genType>
GLM_FUNC_QUALIFIER genType gaussRand
(
genType const & Mean,
genType const & Deviation
)
{
genType w, x1, x2;
do
{
x1 = linearRand(genType(-1), genType(1));
x2 = linearRand(genType(-1), genType(1));
w = x1 * x1 + x2 * x2; template <>
} while(w > genType(1)); GLM_FUNC_QUALIFIER float compute_linearRand::operator()<float> (float const & Min, float const & Max) const
{
return float(std::rand()) / float(RAND_MAX) * (Max - Min) + Min;
}
return x2 * Deviation * Deviation * sqrt((genType(-2) * log(w)) / w) + Mean; template <>
} GLM_FUNC_QUALIFIER double compute_linearRand::operator()<double> (double const & Min, double const & Max) const
{
return double(std::rand()) / double(RAND_MAX) * (Max - Min) + Min;
}
}//namespace detail
template <typename genType>
GLM_FUNC_QUALIFIER genType linearRand
(
genType const & Min,
genType const & Max
)
{
return detail::compute_linearRand()(Min, Max);
}
template <typename T> VECTORIZE_VEC_VEC(linearRand)
GLM_FUNC_QUALIFIER detail::tvec2<T> gaussRand
(
detail::tvec2<T> const & Mean,
detail::tvec2<T> const & Deviation
)
{
return detail::tvec2<T>(
gaussRand(Mean.x, Deviation.x),
gaussRand(Mean.y, Deviation.y));
}
template <typename T>
GLM_FUNC_QUALIFIER detail::tvec3<T> gaussRand
(
detail::tvec3<T> const & Mean,
detail::tvec3<T> const & Deviation
)
{
return detail::tvec3<T>(
gaussRand(Mean.x, Deviation.x),
gaussRand(Mean.y, Deviation.y),
gaussRand(Mean.z, Deviation.z));
}
template <typename T>
GLM_FUNC_QUALIFIER detail::tvec4<T> gaussRand
(
detail::tvec4<T> const & Mean,
detail::tvec4<T> const & Deviation
)
{
return detail::tvec4<T>(
gaussRand(Mean.x, Deviation.x),
gaussRand(Mean.y, Deviation.y),
gaussRand(Mean.z, Deviation.z),
gaussRand(Mean.w, Deviation.w));
}
template <typename T>
GLM_FUNC_QUALIFIER detail::tvec2<T> diskRand
(
T const & Radius
)
{
detail::tvec2<T> Result(T(0));
T LenRadius(T(0));
do template <typename genType>
GLM_FUNC_QUALIFIER genType gaussRand
(
genType const & Mean,
genType const & Deviation
)
{ {
Result = linearRand(detail::tvec2<T>(-Radius), detail::tvec2<T>(Radius)); genType w, x1, x2;
LenRadius = length(Result);
}
while(LenRadius > Radius);
return Result; do
} {
x1 = linearRand(genType(-1), genType(1));
x2 = linearRand(genType(-1), genType(1));
template <typename T> w = x1 * x1 + x2 * x2;
GLM_FUNC_QUALIFIER detail::tvec3<T> ballRand } while(w > genType(1));
(
T const & Radius return x2 * Deviation * Deviation * sqrt((genType(-2) * log(w)) / w) + Mean;
) }
{
detail::tvec3<T> Result(T(0)); VECTORIZE_VEC_VEC(gaussRand)
T LenRadius(T(0));
do template <typename T>
GLM_FUNC_QUALIFIER detail::tvec2<T> diskRand
(
T const & Radius
)
{ {
Result = linearRand(detail::tvec3<T>(-Radius), detail::tvec3<T>(Radius)); detail::tvec2<T> Result(T(0));
LenRadius = length(Result); T LenRadius(T(0));
do
{
Result = linearRand(detail::tvec2<T>(-Radius), detail::tvec2<T>(Radius));
LenRadius = length(Result);
}
while(LenRadius > Radius);
return Result;
} }
while(LenRadius > Radius);
return Result; template <typename T>
} GLM_FUNC_QUALIFIER detail::tvec3<T> ballRand
(
T const & Radius
)
{
detail::tvec3<T> Result(T(0));
T LenRadius(T(0));
template <typename T> do
GLM_FUNC_QUALIFIER detail::tvec2<T> circularRand {
( Result = linearRand(detail::tvec3<T>(-Radius), detail::tvec3<T>(Radius));
T const & Radius LenRadius = length(Result);
) }
{ while(LenRadius > Radius);
T a = linearRand(T(0), T(6.283185307179586476925286766559f));
return detail::tvec2<T>(cos(a), sin(a)) * Radius;
}
template <typename T>
GLM_FUNC_QUALIFIER detail::tvec3<T> sphericalRand
(
T const & Radius
)
{
T z = linearRand(T(-1), T(1));
T a = linearRand(T(0), T(6.283185307179586476925286766559f));
T r = sqrt(T(1) - z * z); return Result;
}
T x = r * cos(a); template <typename T>
T y = r * sin(a); GLM_FUNC_QUALIFIER detail::tvec2<T> circularRand
(
T const & Radius
)
{
T a = linearRand(T(0), T(6.283185307179586476925286766559f));
return detail::tvec2<T>(cos(a), sin(a)) * Radius;
}
return detail::tvec3<T>(x, y, z) * Radius; template <typename T>
} GLM_FUNC_QUALIFIER detail::tvec3<T> sphericalRand
(
T const & Radius
)
{
T z = linearRand(T(-1), T(1));
T a = linearRand(T(0), T(6.283185307179586476925286766559f));
T r = sqrt(T(1) - z * z);
T x = r * cos(a);
T y = r * sin(a);
return detail::tvec3<T>(x, y, z) * Radius;
}
}//namespace glm }//namespace glm

@ -26,165 +26,91 @@
/// @author Christophe Riccio /// @author Christophe Riccio
/////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////
namespace glm{ namespace glm
{
template <typename T, template <typename> class vecType> template <typename T, template <typename> class vecType>
GLM_FUNC_QUALIFIER T swizzle GLM_FUNC_QUALIFIER T swizzle
( (
vecType<T> const & v, vecType<T> const & v,
comp x comp x
) )
{ {
assert(int(x) < int(vecType<T>::value_size)); assert(int(x) < int(vecType<T>::value_size));
return v[x]; return v[x];
} }
template <typename T, template <typename> class vecType> template <typename T, template <typename> class vecType>
GLM_FUNC_QUALIFIER detail::tvec2<T> swizzle GLM_FUNC_QUALIFIER detail::tvec2<T> swizzle
( (
vecType<T> const & v, vecType<T> const & v,
comp x, comp y comp x, comp y
) )
{ {
return detail::tvec2<T>( return detail::tvec2<T>(
v[x], v[x],
v[y]); v[y]);
} }
template <typename T, template <typename> class vecType> template <typename T, template <typename> class vecType>
GLM_FUNC_QUALIFIER detail::tvec3<T> swizzle GLM_FUNC_QUALIFIER detail::tvec3<T> swizzle
( (
vecType<T> const & v, vecType<T> const & v,
comp x, comp y, comp z comp x, comp y, comp z
) )
{ {
return detail::tvec3<T>( return detail::tvec3<T>(
v[x], v[x],
v[y], v[y],
v[z]); v[z]);
} }
template <typename T, template <typename> class vecType> template <typename T, template <typename> class vecType>
GLM_FUNC_QUALIFIER detail::tvec4<T> swizzle GLM_FUNC_QUALIFIER detail::tvec4<T> swizzle
( (
vecType<T> const & v, vecType<T> const & v,
comp x, comp y, comp z, comp w comp x, comp y, comp z, comp w
) )
{ {
return detail::tvec4<T>(v[x], v[y], v[z], v[w]); return detail::tvec4<T>(v[x], v[y], v[z], v[w]);
} }
template <typename T> template <typename T>
GLM_FUNC_QUALIFIER T& swizzle GLM_FUNC_QUALIFIER T& swizzle
( (
detail::tvec4<T> & v, detail::tvec4<T> & v,
comp x comp x
) )
{ {
return v[x]; return v[x];
} }
template <typename T> template <typename T>
GLM_FUNC_QUALIFIER detail::tref2<T> swizzle GLM_FUNC_QUALIFIER detail::tref2<T> swizzle
( (
detail::tvec4<T> & v, detail::tvec4<T> & v,
comp x, comp y comp x, comp y
) )
{ {
return detail::tref2<T>(v[x], v[y]); return detail::tref2<T>(v[x], v[y]);
} }
template <typename T> template <typename T>
GLM_FUNC_QUALIFIER detail::tref3<T> swizzle GLM_FUNC_QUALIFIER detail::tref3<T> swizzle
( (
detail::tvec4<T> & v, detail::tvec4<T> & v,
comp x, comp y, comp z comp x, comp y, comp z
) )
{ {
return detail::tref3<T>(v[x], v[y], v[z]); return detail::tref3<T>(v[x], v[y], v[z]);
} }
template <typename T> template <typename T>
GLM_FUNC_QUALIFIER detail::tref4<T> swizzle GLM_FUNC_QUALIFIER detail::tref4<T> swizzle
( (
detail::tvec4<T> & v, detail::tvec4<T> & v,
comp x, comp y, comp z, comp w comp x, comp y, comp z, comp w
) )
{ {
return detail::tref4<T>(v[x], v[y], v[z], v[w]); return detail::tref4<T>(v[x], v[y], v[z], v[w]);
} }
/*
template <comp x>
GLM_FUNC_QUALIFIER float& swizzle
(
detail::tvec4<float> & v
)
{
return v[x];
}
template <comp x>
GLM_FUNC_QUALIFIER int& swizzle
(
detail::tvec4<int> & v
)
{
return v[x];
}
template <comp x, comp y>
GLM_FUNC_QUALIFIER detail::tref2<float> swizzle
(
detail::tvec4<float> & v
)
{
return detail::tref2<float>(v[x], v[y]);
}
template <comp x, comp y>
GLM_FUNC_QUALIFIER detail::tref2<int> swizzle
(
detail::tvec4<int> & v
)
{
return detail::tref2<int>(v[x], v[y]);
}
template <comp x, comp y, comp z>
GLM_FUNC_QUALIFIER detail::tref3<float> swizzle
(
detail::tvec4<float> & v
)
{
return detail::tref3<float>(v[x], v[y], v[z]);
}
template <comp x, comp y, comp z>
GLM_FUNC_QUALIFIER detail::tref3<int> swizzle
(
detail::tvec4<int> & v
)
{
return detail::tref3<int>(v[x], v[y], v[z]);
}
template <comp x, comp y, comp z, comp w>
GLM_FUNC_QUALIFIER detail::tref4<float> swizzle
(
detail::tvec4<float> & v
)
{
return detail::tref4<float>(v[x], v[y], v[z], v[w]);
}
template <comp x, comp y, comp z, comp w>
GLM_FUNC_QUALIFIER detail::tref4<int> swizzle
(
detail::tvec4<int> & v
)
{
return detail::tref4<int>(v[x], v[y], v[z], v[w]);
}
*/
}//namespace glm }//namespace glm

@ -2,232 +2,137 @@
// OpenGL Mathematics Copyright (c) 2005 - 2011 G-Truc Creation (www.g-truc.net) // OpenGL Mathematics Copyright (c) 2005 - 2011 G-Truc Creation (www.g-truc.net)
/////////////////////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////////////////////
// Created : 2006-01-04 // Created : 2006-01-04
// Updated : 2008-10-07 // Updated : 2011-10-14
// Licence : This source is under MIT License // Licence : This source is under MIT License
// File : glm/gtx/fast_square_root.inl // File : glm/gtx/fast_square_root.inl
/////////////////////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////////////////////
namespace glm{ #include "../core/_vectorize.hpp"
// fastSqrt namespace glm
template <typename genType> {
GLM_FUNC_QUALIFIER genType fastSqrt // fastSqrt
( template <typename genType>
genType const & x GLM_FUNC_QUALIFIER genType fastSqrt
) (
{ genType const & x
return genType(1) / fastInverseSqrt(x); )
} {
GLM_STATIC_ASSERT(detail::type<genType>::is_float, "'fastSqrt' only accept floating-point input");
template <typename valType>
GLM_FUNC_QUALIFIER detail::tvec2<valType> fastSqrt return genType(1) / fastInverseSqrt(x);
( }
detail::tvec2<valType> const & x
) VECTORIZE_VEC(fastSqrt)
{
return detail::tvec2<valType>( // fastInversesqrt
fastSqrt(x.x), template <typename genType>
fastSqrt(x.y)); GLM_FUNC_QUALIFIER genType fastInverseSqrt
} (
genType const & x
template <typename valType> )
GLM_FUNC_QUALIFIER detail::tvec3<valType> fastSqrt {
( genType tmp = x;
detail::tvec3<valType> const & x float xhalf = 0.5f * float(tmp);
) uint i = *(uint*)&x;
{ i = 0x5f375a86 - (i >> 1);
return detail::tvec3<valType>( //x = *(float*)&i;
fastSqrt(x.x), //x = *((float*)(char*)&i);
fastSqrt(x.y), tmp = detail::uif(i).f;
fastSqrt(x.z)); tmp = tmp * (1.5f - xhalf * tmp * tmp);
} return genType(tmp);
}
template <typename valType>
GLM_FUNC_QUALIFIER detail::tvec4<valType> fastSqrt VECTORIZE_VEC(fastInverseSqrt)
(
detail::tvec4<valType> const & x // fastLength
) template <typename genType>
{ GLM_FUNC_QUALIFIER genType fastLength
return detail::tvec4<valType>( (
fastSqrt(x.x), genType const & x
fastSqrt(x.y), )
fastSqrt(x.z), {
fastSqrt(x.w)); return abs(x);
} }
// fastInversesqrt template <typename valType>
template <typename genType> GLM_FUNC_QUALIFIER valType fastLength
GLM_FUNC_QUALIFIER genType fastInverseSqrt (
( detail::tvec2<valType> const & x
genType const & x )
) {
{ valType sqr = x.x * x.x + x.y * x.y;
genType tmp = x; return fastSqrt(sqr);
float xhalf = 0.5f * float(tmp); }
uint i = *(uint*)&x;
i = 0x5f375a86 - (i >> 1); template <typename valType>
//x = *(float*)&i; GLM_FUNC_QUALIFIER valType fastLength
//x = *((float*)(char*)&i); (
tmp = detail::uif(i).f; detail::tvec3<valType> const & x
tmp = tmp * (1.5f - xhalf * tmp * tmp); )
return genType(tmp); {
} valType sqr = x.x * x.x + x.y * x.y + x.z * x.z;
return fastSqrt(sqr);
template <typename valType> }
GLM_FUNC_QUALIFIER detail::tvec2<valType> fastInverseSqrt
( template <typename valType>
detail::tvec2<valType> const & x GLM_FUNC_QUALIFIER valType fastLength
) (
{ detail::tvec4<valType> const & x
return detail::tvec2<valType>( )
fastInverseSqrt(x.x), {
fastInverseSqrt(x.y)); valType sqr = x.x * x.x + x.y * x.y + x.z * x.z + x.w * x.w;
} return fastSqrt(sqr);
}
template <typename valType>
GLM_FUNC_QUALIFIER detail::tvec3<valType> fastInverseSqrt // fastDistance
( template <typename genType>
detail::tvec3<valType> const & x GLM_FUNC_QUALIFIER genType fastDistance
) (
{ genType const & x,
return detail::tvec3<valType>( genType const & y
fastInverseSqrt(x.x), )
fastInverseSqrt(x.y), {
fastInverseSqrt(x.z)); return fastLength(y - x);
} }
template <typename valType> // fastNormalize
GLM_FUNC_QUALIFIER detail::tvec4<valType> fastInverseSqrt template <typename genType>
( GLM_FUNC_QUALIFIER genType fastNormalize
detail::tvec4<valType> const & x (
) genType const & x
{ )
return detail::tvec4<valType>( {
fastInverseSqrt(x.x), return x > genType(0) ? genType(1) : -genType(1);
fastInverseSqrt(x.y), }
fastInverseSqrt(x.z),
fastInverseSqrt(x.w)); template <typename valType>
} GLM_FUNC_QUALIFIER detail::tvec2<valType> fastNormalize
(
// fastLength detail::tvec2<valType> const & x
template <typename genType> )
GLM_FUNC_QUALIFIER genType fastLength {
( valType sqr = x.x * x.x + x.y * x.y;
genType const & x return x * fastInverseSqrt(sqr);
) }
{
return abs(x); template <typename valType>
} GLM_FUNC_QUALIFIER detail::tvec3<valType> fastNormalize
(
template <typename valType> detail::tvec3<valType> const & x
GLM_FUNC_QUALIFIER valType fastLength )
( {
detail::tvec2<valType> const & x valType sqr = x.x * x.x + x.y * x.y + x.z * x.z;
) return x * fastInverseSqrt(sqr);
{ }
valType sqr = x.x * x.x + x.y * x.y;
return fastSqrt(sqr); template <typename valType>
} GLM_FUNC_QUALIFIER detail::tvec4<valType> fastNormalize
(
template <typename valType> detail::tvec4<valType> const & x
GLM_FUNC_QUALIFIER valType fastLength )
( {
detail::tvec3<valType> const & x valType sqr = x.x * x.x + x.y * x.y + x.z * x.z + x.w * x.w;
) return x * fastInverseSqrt(sqr);
{ }
valType sqr = x.x * x.x + x.y * x.y + x.z * x.z;
return fastSqrt(sqr);
}
template <typename valType>
GLM_FUNC_QUALIFIER valType fastLength
(
detail::tvec4<valType> const & x
)
{
valType sqr = x.x * x.x + x.y * x.y + x.z * x.z + x.w * x.w;
return fastSqrt(sqr);
}
// fastDistance
template <typename genType>
GLM_FUNC_QUALIFIER genType fastDistance
(
genType const & x,
genType const & y
)
{
return fastLength(y - x);
}
template <typename valType>
GLM_FUNC_QUALIFIER valType fastDistance
(
detail::tvec2<valType> const & x,
detail::tvec2<valType> const & y
)
{
return fastLength(y - x);
}
template <typename valType>
GLM_FUNC_QUALIFIER valType fastDistance
(
detail::tvec3<valType> const & x,
detail::tvec3<valType> const & y
)
{
return fastLength(y - x);
}
template <typename valType>
GLM_FUNC_QUALIFIER valType fastDistance
(
detail::tvec4<valType> const & x,
detail::tvec4<valType> const & y
)
{
return fastLength(y - x);
}
// fastNormalize
template <typename genType>
GLM_FUNC_QUALIFIER genType fastNormalize
(
genType const & x
)
{
return x > genType(0) ? genType(1) : -genType(1);
}
template <typename valType>
GLM_FUNC_QUALIFIER detail::tvec2<valType> fastNormalize
(
detail::tvec2<valType> const & x
)
{
valType sqr = x.x * x.x + x.y * x.y;
return x * fastInverseSqrt(sqr);
}
template <typename valType>
GLM_FUNC_QUALIFIER detail::tvec3<valType> fastNormalize
(
detail::tvec3<valType> const & x
)
{
valType sqr = x.x * x.x + x.y * x.y + x.z * x.z;
return x * fastInverseSqrt(sqr);
}
template <typename valType>
GLM_FUNC_QUALIFIER detail::tvec4<valType> fastNormalize
(
detail::tvec4<valType> const & x
)
{
valType sqr = x.x * x.x + x.y * x.y + x.z * x.z + x.w * x.w;
return x * fastInverseSqrt(sqr);
}
}//namespace glm }//namespace glm

Loading…
Cancel
Save