Merge branch '0.9.3' into swizzle

This commit is contained in:
Christophe Riccio 2011-10-14 12:57:25 +01:00
commit dc7d8f5c0c
17 changed files with 3080 additions and 4365 deletions

159
glm/core/_vectorize.hpp Normal file
View File

@ -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)

View File

@ -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>

View File

@ -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

View File

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

View File

@ -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>

View File

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

View File

@ -26,27 +26,27 @@
/// @author Christophe Riccio /// @author Christophe Riccio
/////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////
namespace glm{ namespace glm
GLM_FUNC_QUALIFIER detail::uint32 packUnorm2x16(detail::tvec2<detail::float32> const & v)
{ {
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))); 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))); detail::uint16 B(detail::uint16(round(clamp(v.y, 0.0f, 1.0f) * 65535.0f)));
return detail::uint32((B << 16) | A); 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 Mask16((1 << 16) - 1);
detail::uint32 A((p >> 0) & Mask16); detail::uint32 A((p >> 0) & Mask16);
detail::uint32 B((p >> 16) & Mask16); detail::uint32 B((p >> 16) & Mask16);
return detail::tvec2<detail::float32>( return detail::tvec2<detail::float32>(
A * 1.0f / 65535.0f, A * 1.0f / 65535.0f,
B * 1.0f / 65535.0f); B * 1.0f / 65535.0f);
} }
GLM_FUNC_QUALIFIER detail::uint32 packSnorm2x16(detail::tvec2<detail::float32> const & v) GLM_FUNC_QUALIFIER detail::uint32 packSnorm2x16(detail::tvec2<detail::float32> const & v)
{ {
union iu union iu
{ {
detail::int16 i; detail::int16 i;
@ -58,10 +58,10 @@ GLM_FUNC_QUALIFIER detail::uint32 packSnorm2x16(detail::tvec2<detail::float32> c
B.i = detail::int16(round(Unpack.y)); B.i = detail::int16(round(Unpack.y));
detail::uint32 Pack = (detail::uint32(B.u) << 16) | (detail::uint32(A.u) << 0); detail::uint32 Pack = (detail::uint32(B.u) << 16) | (detail::uint32(A.u) << 0);
return Pack; return Pack;
} }
GLM_FUNC_QUALIFIER detail::tvec2<detail::float32> unpackSnorm2x16(detail::uint32 const & p) GLM_FUNC_QUALIFIER detail::tvec2<detail::float32> unpackSnorm2x16(detail::uint32 const & p)
{ {
union iu union iu
{ {
detail::int16 i; detail::int16 i;
@ -74,19 +74,19 @@ GLM_FUNC_QUALIFIER detail::tvec2<detail::float32> unpackSnorm2x16(detail::uint32
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 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 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 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::uint8 D((detail::uint8)round(clamp(v.w, 0.0f, 1.0f) * 255.0f));
return detail::uint32((D << 24) | (C << 16) | (B << 8) | A); return detail::uint32((D << 24) | (C << 16) | (B << 8) | A);
} }
GLM_FUNC_QUALIFIER detail::tvec4<detail::float32> unpackUnorm4x8(detail::uint32 const & p) GLM_FUNC_QUALIFIER detail::tvec4<detail::float32> unpackUnorm4x8(detail::uint32 const & p)
{ {
detail::uint32 Mask8((1 << 8) - 1); detail::uint32 Mask8((1 << 8) - 1);
detail::uint32 A((p >> 0) & Mask8); detail::uint32 A((p >> 0) & Mask8);
detail::uint32 B((p >> 8) & Mask8); detail::uint32 B((p >> 8) & Mask8);
@ -97,10 +97,10 @@ GLM_FUNC_QUALIFIER detail::tvec4<detail::float32> unpackUnorm4x8(detail::uint32
B * 1.0f / 255.0f, B * 1.0f / 255.0f,
C * 1.0f / 255.0f, C * 1.0f / 255.0f,
D * 1.0f / 255.0f); D * 1.0f / 255.0f);
} }
GLM_FUNC_QUALIFIER detail::uint32 packSnorm4x8(detail::tvec4<detail::float32> const & v) GLM_FUNC_QUALIFIER detail::uint32 packSnorm4x8(detail::tvec4<detail::float32> const & v)
{ {
union iu union iu
{ {
detail::int8 i; detail::int8 i;
@ -114,10 +114,10 @@ GLM_FUNC_QUALIFIER detail::uint32 packSnorm4x8(detail::tvec4<detail::float32> co
D.i = detail::int8(round(Unpack.w)); 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); 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; return Pack;
} }
GLM_FUNC_QUALIFIER detail::tvec4<detail::float32> unpackSnorm4x8(detail::uint32 const & p) GLM_FUNC_QUALIFIER detail::tvec4<detail::float32> unpackSnorm4x8(detail::uint32 const & p)
{ {
union iu union iu
{ {
detail::int8 i; detail::int8 i;
@ -132,28 +132,27 @@ GLM_FUNC_QUALIFIER detail::tvec4<detail::float32> unpackSnorm4x8(detail::uint32
detail::tvec4<detail::float32> Pack(A.i, B.i, C.i, D.i); detail::tvec4<detail::float32> Pack(A.i, B.i, C.i, D.i);
return clamp(Pack * 1.0f / 127.0f, -1.0f, 1.0f); return clamp(Pack * 1.0f / 127.0f, -1.0f, 1.0f);
} }
GLM_FUNC_QUALIFIER double packDouble2x32(detail::tvec2<detail::uint32> const & v) GLM_FUNC_QUALIFIER double packDouble2x32(detail::tvec2<detail::uint32> const & v)
{ {
return *(double*)&v; return *(double*)&v;
} }
GLM_FUNC_QUALIFIER detail::tvec2<uint> unpackDouble2x32(double const & v) GLM_FUNC_QUALIFIER detail::tvec2<uint> unpackDouble2x32(double const & v)
{ {
return *(detail::tvec2<uint>*)&v; return *(detail::tvec2<uint>*)&v;
} }
GLM_FUNC_QUALIFIER uint packHalf2x16(detail::tvec2<float> const & v) GLM_FUNC_QUALIFIER uint packHalf2x16(detail::tvec2<float> const & v)
{ {
detail::tvec2<detail::hdata> Pack(detail::toFloat16(v.x), detail::toFloat16(v.y)); detail::tvec2<detail::hdata> Pack(detail::toFloat16(v.x), detail::toFloat16(v.y));
return *(uint*)&Pack; return *(uint*)&Pack;
} }
GLM_FUNC_QUALIFIER vec2 unpackHalf2x16(uint const & v) GLM_FUNC_QUALIFIER vec2 unpackHalf2x16(uint const & v)
{ {
detail::tvec2<detail::hdata> Unpack = *(detail::tvec2<detail::hdata>*)&v; detail::tvec2<detail::hdata> Unpack = *(detail::tvec2<detail::hdata>*)&v;
return vec2(detail::toFloat32(Unpack.x), detail::toFloat32(Unpack.y)); return vec2(detail::toFloat32(Unpack.x), detail::toFloat32(Unpack.y));
} }
}//namespace glm }//namespace glm

View File

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

View File

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

View File

@ -26,40 +26,42 @@
/// @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
)
{ {
template <typename T>
GLM_FUNC_QUALIFIER detail::tmat3x3<T> affineInverse
(
detail::tmat3x3<T> const & m
)
{
detail::tmat3x3<T> Result(m); detail::tmat3x3<T> Result(m);
Result[2] = detail::tvec3<T>(0, 0, 1); Result[2] = detail::tvec3<T>(0, 0, 1);
Result = transpose(Result); Result = transpose(Result);
detail::tvec3<T> Translation = Result * detail::tvec3<T>(-detail::tvec2<T>(m[2]), m[2][2]); detail::tvec3<T> Translation = Result * detail::tvec3<T>(-detail::tvec2<T>(m[2]), m[2][2]);
Result[2] = Translation; Result[2] = Translation;
return Result; return Result;
} }
template <typename T> template <typename T>
GLM_FUNC_QUALIFIER detail::tmat4x4<T> affineInverse GLM_FUNC_QUALIFIER detail::tmat4x4<T> affineInverse
( (
detail::tmat4x4<T> const & m detail::tmat4x4<T> const & m
) )
{ {
detail::tmat4x4<T> Result(m); detail::tmat4x4<T> Result(m);
Result[3] = detail::tvec4<T>(0, 0, 0, 1); Result[3] = detail::tvec4<T>(0, 0, 0, 1);
Result = transpose(Result); Result = transpose(Result);
detail::tvec4<T> Translation = Result * detail::tvec4<T>(-detail::tvec3<T>(m[3]), m[3][3]); detail::tvec4<T> Translation = Result * detail::tvec4<T>(-detail::tvec3<T>(m[3]), m[3][3]);
Result[3] = Translation; Result[3] = Translation;
return Result; return Result;
} }
template <typename valType> template <typename valType>
GLM_FUNC_QUALIFIER detail::tmat2x2<valType> inverseTranspose( GLM_FUNC_QUALIFIER detail::tmat2x2<valType> inverseTranspose
detail::tmat2x2<valType> const & m) (
{ detail::tmat2x2<valType> const & m
)
{
valType Determinant = m[0][0] * m[1][1] - m[1][0] * m[0][1]; valType Determinant = m[0][0] * m[1][1] - m[1][0] * m[0][1];
detail::tmat2x2<valType> Inverse( detail::tmat2x2<valType> Inverse(
@ -69,12 +71,14 @@ GLM_FUNC_QUALIFIER detail::tmat2x2<valType> inverseTranspose(
+ m[0][0] / Determinant); + m[0][0] / Determinant);
return Inverse; return Inverse;
} }
template <typename valType> template <typename valType>
GLM_FUNC_QUALIFIER detail::tmat3x3<valType> inverseTranspose( GLM_FUNC_QUALIFIER detail::tmat3x3<valType> inverseTranspose
detail::tmat3x3<valType> const & m) (
{ detail::tmat3x3<valType> const & m
)
{
valType Determinant = valType Determinant =
+ m[0][0] * (m[1][1] * m[2][2] - m[1][2] * m[2][1]) + 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]) - m[0][1] * (m[1][0] * m[2][2] - m[1][2] * m[2][0])
@ -93,12 +97,14 @@ GLM_FUNC_QUALIFIER detail::tmat3x3<valType> inverseTranspose(
Inverse /= Determinant; Inverse /= Determinant;
return Inverse; return Inverse;
} }
template <typename valType> template <typename valType>
GLM_FUNC_QUALIFIER detail::tmat4x4<valType> inverseTranspose( GLM_FUNC_QUALIFIER detail::tmat4x4<valType> inverseTranspose
detail::tmat4x4<valType> const & m) (
{ detail::tmat4x4<valType> const & m
)
{
valType SubFactor00 = m[2][2] * m[3][3] - m[3][2] * m[2][3]; valType SubFactor00 = m[2][2] * m[3][3] - m[3][2] * m[2][3];
valType SubFactor01 = m[2][1] * m[3][3] - m[3][1] * m[2][3]; 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 SubFactor02 = m[2][1] * m[3][2] - m[3][1] * m[2][2];
@ -149,6 +155,5 @@ GLM_FUNC_QUALIFIER detail::tmat4x4<valType> inverseTranspose(
Inverse /= Determinant; Inverse /= Determinant;
return Inverse; return Inverse;
} }
}//namespace glm }//namespace glm

View File

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

View File

@ -15,58 +15,58 @@
// - GLM core // - GLM core
/////////////////////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////////////////////
namespace glm{ namespace glm
template <typename T>
GLM_FUNC_QUALIFIER T mod289(T const & x)
{ {
template <typename T>
GLM_FUNC_QUALIFIER T mod289(T const & x)
{
return x - floor(x * T(1.0 / 289.0)) * T(289.0); return x - floor(x * T(1.0 / 289.0)) * T(289.0);
} }
template <typename T> template <typename T>
GLM_FUNC_QUALIFIER T permute(T const & x) GLM_FUNC_QUALIFIER T permute(T const & x)
{ {
return mod289(((x * T(34)) + T(1)) * x); return mod289(((x * T(34)) + T(1)) * x);
} }
template <typename T, template<typename> class vecType> template <typename T, template<typename> class vecType>
GLM_FUNC_QUALIFIER vecType<T> permute(vecType<T> const & x) GLM_FUNC_QUALIFIER vecType<T> permute(vecType<T> const & x)
{ {
return mod289(((x * T(34)) + T(1)) * x); return mod289(((x * T(34)) + T(1)) * x);
} }
template <typename T> template <typename T>
GLM_FUNC_QUALIFIER T taylorInvSqrt(T const & r) GLM_FUNC_QUALIFIER T taylorInvSqrt(T const & r)
{ {
return T(1.79284291400159) - T(0.85373472095314) * r; return T(1.79284291400159) - T(0.85373472095314) * r;
} }
template <typename T, template<typename> class vecType> template <typename T, template<typename> class vecType>
GLM_FUNC_QUALIFIER vecType<T> taylorInvSqrt(vecType<T> const & r) GLM_FUNC_QUALIFIER vecType<T> taylorInvSqrt(vecType<T> const & r)
{ {
return T(1.79284291400159) - T(0.85373472095314) * r; return T(1.79284291400159) - T(0.85373472095314) * r;
} }
template <typename T, template <typename> class vecType> template <typename T, template <typename> class vecType>
GLM_FUNC_QUALIFIER vecType<T> fade(vecType<T> const & t) GLM_FUNC_QUALIFIER vecType<T> fade(vecType<T> const & t)
{ {
return t * t * t * (t * (t * T(6) - T(15)) + T(10)); return t * t * t * (t * (t * T(6) - T(15)) + T(10));
} }
template <typename T> template <typename T>
GLM_FUNC_QUALIFIER detail::tvec4<T> grad4(T const & j, detail::tvec4<T> const & ip) GLM_FUNC_QUALIFIER detail::tvec4<T> grad4(T const & j, detail::tvec4<T> const & ip)
{ {
detail::tvec3<T> pXYZ = floor(fract(detail::tvec3<T>(j) * detail::tvec3<T>(ip)) * T(7)) * ip[2] - T(1); detail::tvec3<T> pXYZ = floor(fract(detail::tvec3<T>(j) * detail::tvec3<T>(ip)) * T(7)) * ip[2] - T(1);
T pW = T(1.5) - dot(abs(pXYZ), detail::tvec3<T>(1)); T pW = T(1.5) - dot(abs(pXYZ), detail::tvec3<T>(1));
detail::tvec4<T> s = detail::tvec4<T>(lessThan(detail::tvec4<T>(pXYZ, pW), detail::tvec4<T>(0.0))); detail::tvec4<T> s = detail::tvec4<T>(lessThan(detail::tvec4<T>(pXYZ, pW), detail::tvec4<T>(0.0)));
pXYZ = pXYZ + (detail::tvec3<T>(s) * T(2) - T(1)) * s.w; pXYZ = pXYZ + (detail::tvec3<T>(s) * T(2) - T(1)) * s.w;
return detail::tvec4<T>(pXYZ, pW); return detail::tvec4<T>(pXYZ, pW);
} }
// Classic Perlin noise // Classic Perlin noise
template <typename T> template <typename T>
GLM_FUNC_QUALIFIER T perlin(detail::tvec2<T> const & P) GLM_FUNC_QUALIFIER T perlin(detail::tvec2<T> const & P)
{ {
detail::tvec4<T> Pi = glm::floor(detail::tvec4<T>(P.x, P.y, P.x, P.y)) + detail::tvec4<T>(0.0, 0.0, 1.0, 1.0); detail::tvec4<T> Pi = glm::floor(detail::tvec4<T>(P.x, P.y, P.x, P.y)) + detail::tvec4<T>(0.0, 0.0, 1.0, 1.0);
detail::tvec4<T> Pf = glm::fract(detail::tvec4<T>(P.x, P.y, P.x, P.y)) - detail::tvec4<T>(0.0, 0.0, 1.0, 1.0); detail::tvec4<T> Pf = glm::fract(detail::tvec4<T>(P.x, P.y, P.x, P.y)) - detail::tvec4<T>(0.0, 0.0, 1.0, 1.0);
Pi = mod(Pi, T(289)); // To avoid truncation effects in permutation Pi = mod(Pi, T(289)); // To avoid truncation effects in permutation
@ -102,12 +102,12 @@ GLM_FUNC_QUALIFIER T perlin(detail::tvec2<T> const & P)
detail::tvec2<T> n_x = mix(detail::tvec2<T>(n00, n01), detail::tvec2<T>(n10, n11), fade_xy.x); detail::tvec2<T> n_x = mix(detail::tvec2<T>(n00, n01), detail::tvec2<T>(n10, n11), fade_xy.x);
T n_xy = mix(n_x.x, n_x.y, fade_xy.y); T n_xy = mix(n_x.x, n_x.y, fade_xy.y);
return T(2.3) * n_xy; return T(2.3) * n_xy;
} }
// Classic Perlin noise // Classic Perlin noise
template <typename T> template <typename T>
GLM_FUNC_QUALIFIER T perlin(detail::tvec3<T> const & P) GLM_FUNC_QUALIFIER T perlin(detail::tvec3<T> const & P)
{ {
detail::tvec3<T> Pi0 = floor(P); // Integer part for indexing detail::tvec3<T> Pi0 = floor(P); // Integer part for indexing
detail::tvec3<T> Pi1 = Pi0 + T(1); // Integer part + 1 detail::tvec3<T> Pi1 = Pi0 + T(1); // Integer part + 1
Pi0 = mod289(Pi0); Pi0 = mod289(Pi0);
@ -173,12 +173,12 @@ GLM_FUNC_QUALIFIER T perlin(detail::tvec3<T> const & P)
detail::tvec2<T> n_yz = mix(detail::tvec2<T>(n_z.x, n_z.y), detail::tvec2<T>(n_z.z, n_z.w), fade_xyz.y); detail::tvec2<T> n_yz = mix(detail::tvec2<T>(n_z.x, n_z.y), detail::tvec2<T>(n_z.z, n_z.w), fade_xyz.y);
T n_xyz = mix(n_yz.x, n_yz.y, fade_xyz.x); T n_xyz = mix(n_yz.x, n_yz.y, fade_xyz.x);
return T(2.2) * n_xyz; return T(2.2) * n_xyz;
} }
/* /*
// Classic Perlin noise // Classic Perlin noise
template <typename T> template <typename T>
GLM_FUNC_QUALIFIER T perlin(detail::tvec3<T> const & P) GLM_FUNC_QUALIFIER T perlin(detail::tvec3<T> const & P)
{ {
detail::tvec3<T> Pi0 = floor(P); // Integer part for indexing detail::tvec3<T> Pi0 = floor(P); // Integer part for indexing
detail::tvec3<T> Pi1 = Pi0 + T(1); // Integer part + 1 detail::tvec3<T> Pi1 = Pi0 + T(1); // Integer part + 1
Pi0 = mod(Pi0, T(289)); Pi0 = mod(Pi0, T(289));
@ -246,12 +246,12 @@ GLM_FUNC_QUALIFIER T perlin(detail::tvec3<T> const & P)
detail::tvec2<T>(n_z.z, n_z.w), fade_xyz.y); detail::tvec2<T>(n_z.z, n_z.w), fade_xyz.y);
T n_xyz = mix(n_yz.x, n_yz.y, fade_xyz.x); T n_xyz = mix(n_yz.x, n_yz.y, fade_xyz.x);
return T(2.2) * n_xyz; return T(2.2) * n_xyz;
} }
*/ */
// Classic Perlin noise // Classic Perlin noise
template <typename T> template <typename T>
GLM_FUNC_QUALIFIER T perlin(detail::tvec4<T> const & P) GLM_FUNC_QUALIFIER T perlin(detail::tvec4<T> const & P)
{ {
detail::tvec4<T> Pi0 = floor(P); // Integer part for indexing detail::tvec4<T> Pi0 = floor(P); // Integer part for indexing
detail::tvec4<T> Pi1 = Pi0 + T(1); // Integer part + 1 detail::tvec4<T> Pi1 = Pi0 + T(1); // Integer part + 1
Pi0 = mod(Pi0, T(289)); Pi0 = mod(Pi0, T(289));
@ -382,12 +382,12 @@ GLM_FUNC_QUALIFIER T perlin(detail::tvec4<T> const & P)
detail::tvec2<T> n_yzw = mix(detail::tvec2<T>(n_zw.x, n_zw.y), detail::tvec2<T>(n_zw.z, n_zw.w), fade_xyzw.y); detail::tvec2<T> n_yzw = mix(detail::tvec2<T>(n_zw.x, n_zw.y), detail::tvec2<T>(n_zw.z, n_zw.w), fade_xyzw.y);
T n_xyzw = mix(n_yzw.x, n_yzw.y, fade_xyzw.x); T n_xyzw = mix(n_yzw.x, n_yzw.y, fade_xyzw.x);
return T(2.2) * n_xyzw; return T(2.2) * n_xyzw;
} }
// Classic Perlin noise, periodic variant // Classic Perlin noise, periodic variant
template <typename T> template <typename T>
GLM_FUNC_QUALIFIER T perlin(detail::tvec2<T> const & P, detail::tvec2<T> const & rep) GLM_FUNC_QUALIFIER T perlin(detail::tvec2<T> const & P, detail::tvec2<T> const & rep)
{ {
detail::tvec4<T> Pi = floor(detail::tvec4<T>(P.x, P.y, P.x, P.y)) + detail::tvec4<T>(0.0, 0.0, 1.0, 1.0); detail::tvec4<T> Pi = floor(detail::tvec4<T>(P.x, P.y, P.x, P.y)) + detail::tvec4<T>(0.0, 0.0, 1.0, 1.0);
detail::tvec4<T> Pf = fract(detail::tvec4<T>(P.x, P.y, P.x, P.y)) - detail::tvec4<T>(0.0, 0.0, 1.0, 1.0); detail::tvec4<T> Pf = fract(detail::tvec4<T>(P.x, P.y, P.x, P.y)) - detail::tvec4<T>(0.0, 0.0, 1.0, 1.0);
Pi = mod(Pi, detail::tvec4<T>(rep.x, rep.y, rep.x, rep.y)); // To create noise with explicit period Pi = mod(Pi, detail::tvec4<T>(rep.x, rep.y, rep.x, rep.y)); // To create noise with explicit period
@ -424,12 +424,12 @@ GLM_FUNC_QUALIFIER T perlin(detail::tvec2<T> const & P, detail::tvec2<T> const &
detail::tvec2<T> n_x = mix(detail::tvec2<T>(n00, n01), detail::tvec2<T>(n10, n11), fade_xy.x); detail::tvec2<T> n_x = mix(detail::tvec2<T>(n00, n01), detail::tvec2<T>(n10, n11), fade_xy.x);
T n_xy = mix(n_x.x, n_x.y, fade_xy.y); T n_xy = mix(n_x.x, n_x.y, fade_xy.y);
return T(2.3) * n_xy; return T(2.3) * n_xy;
} }
// Classic Perlin noise, periodic variant // Classic Perlin noise, periodic variant
template <typename T> template <typename T>
GLM_FUNC_QUALIFIER T perlin(detail::tvec3<T> const & P, detail::tvec3<T> const & rep) GLM_FUNC_QUALIFIER T perlin(detail::tvec3<T> const & P, detail::tvec3<T> const & rep)
{ {
detail::tvec3<T> Pi0 = mod(floor(P), rep); // Integer part, modulo period detail::tvec3<T> Pi0 = mod(floor(P), rep); // Integer part, modulo period
detail::tvec3<T> Pi1 = mod(Pi0 + detail::tvec3<T>(1.0), rep); // Integer part + 1, mod period detail::tvec3<T> Pi1 = mod(Pi0 + detail::tvec3<T>(1.0), rep); // Integer part + 1, mod period
Pi0 = mod(Pi0, T(289)); Pi0 = mod(Pi0, T(289));
@ -495,12 +495,12 @@ GLM_FUNC_QUALIFIER T perlin(detail::tvec3<T> const & P, detail::tvec3<T> const &
detail::tvec2<T> n_yz = mix(detail::tvec2<T>(n_z.x, n_z.y), detail::tvec2<T>(n_z.z, n_z.w), fade_xyz.y); detail::tvec2<T> n_yz = mix(detail::tvec2<T>(n_z.x, n_z.y), detail::tvec2<T>(n_z.z, n_z.w), fade_xyz.y);
T n_xyz = mix(n_yz.x, n_yz.y, fade_xyz.x); T n_xyz = mix(n_yz.x, n_yz.y, fade_xyz.x);
return T(2.2) * n_xyz; return T(2.2) * n_xyz;
} }
// Classic Perlin noise, periodic version // Classic Perlin noise, periodic version
template <typename T> template <typename T>
GLM_FUNC_QUALIFIER T perlin(detail::tvec4<T> const & P, detail::tvec4<T> const & rep) GLM_FUNC_QUALIFIER T perlin(detail::tvec4<T> const & P, detail::tvec4<T> const & rep)
{ {
detail::tvec4<T> Pi0 = mod(floor(P), rep); // Integer part modulo rep detail::tvec4<T> Pi0 = mod(floor(P), rep); // Integer part modulo rep
detail::tvec4<T> Pi1 = mod(Pi0 + T(1), rep); // Integer part + 1 mod rep detail::tvec4<T> Pi1 = mod(Pi0 + T(1), rep); // Integer part + 1 mod rep
detail::tvec4<T> Pf0 = fract(P); // Fractional part for interpolation detail::tvec4<T> Pf0 = fract(P); // Fractional part for interpolation
@ -629,11 +629,11 @@ GLM_FUNC_QUALIFIER T perlin(detail::tvec4<T> const & P, detail::tvec4<T> const &
detail::tvec2<T> n_yzw = mix(detail::tvec2<T>(n_zw.x, n_zw.y), detail::tvec2<T>(n_zw.z, n_zw.w), fade_xyzw.y); detail::tvec2<T> n_yzw = mix(detail::tvec2<T>(n_zw.x, n_zw.y), detail::tvec2<T>(n_zw.z, n_zw.w), fade_xyzw.y);
T n_xyzw = mix(n_yzw.x, n_yzw.y, fade_xyzw.x); T n_xyzw = mix(n_yzw.x, n_yzw.y, fade_xyzw.x);
return T(2.2) * n_xyzw; return T(2.2) * n_xyzw;
} }
template <typename T> template <typename T>
GLM_FUNC_QUALIFIER T simplex(glm::detail::tvec2<T> const & v) GLM_FUNC_QUALIFIER T simplex(glm::detail::tvec2<T> const & v)
{ {
detail::tvec4<T> const C = detail::tvec4<T>( detail::tvec4<T> const C = detail::tvec4<T>(
T( 0.211324865405187), // (3.0 - sqrt(3.0)) / 6.0 T( 0.211324865405187), // (3.0 - sqrt(3.0)) / 6.0
T( 0.366025403784439), // 0.5 * (sqrt(3.0) - 1.0) T( 0.366025403784439), // 0.5 * (sqrt(3.0) - 1.0)
@ -686,11 +686,11 @@ GLM_FUNC_QUALIFIER T simplex(glm::detail::tvec2<T> const & v)
g.y = a0.y * x12.x + h.y * x12.y; g.y = a0.y * x12.x + h.y * x12.y;
g.z = a0.z * x12.z + h.z * x12.w; g.z = a0.z * x12.z + h.z * x12.w;
return T(130) * dot(m, g); return T(130) * dot(m, g);
} }
template <typename T> template <typename T>
GLM_FUNC_QUALIFIER T simplex(detail::tvec3<T> const & v) GLM_FUNC_QUALIFIER T simplex(detail::tvec3<T> const & v)
{ {
detail::tvec2<T> const C(1.0 / 6.0, 1.0 / 3.0); detail::tvec2<T> const C(1.0 / 6.0, 1.0 / 3.0);
detail::tvec4<T> const D(0.0, 0.5, 1.0, 2.0); detail::tvec4<T> const D(0.0, 0.5, 1.0, 2.0);
@ -761,11 +761,11 @@ GLM_FUNC_QUALIFIER T simplex(detail::tvec3<T> const & v)
detail::tvec4<T> m = max(T(0.6) - detail::tvec4<T>(dot(x0, x0), dot(x1, x1), dot(x2, x2), dot(x3, x3)), T(0)); detail::tvec4<T> m = max(T(0.6) - detail::tvec4<T>(dot(x0, x0), dot(x1, x1), dot(x2, x2), dot(x3, x3)), T(0));
m = m * m; m = m * m;
return T(42) * dot(m * m, detail::tvec4<T>(dot(p0, x0), dot(p1, x1), dot(p2, x2), dot(p3, x3))); return T(42) * dot(m * m, detail::tvec4<T>(dot(p0, x0), dot(p1, x1), dot(p2, x2), dot(p3, x3)));
} }
template <typename T> template <typename T>
GLM_FUNC_QUALIFIER T simplex(detail::tvec4<T> const & v) GLM_FUNC_QUALIFIER T simplex(detail::tvec4<T> const & v)
{ {
detail::tvec4<T> const C( detail::tvec4<T> const C(
0.138196601125011, // (5 - sqrt(5))/20 G4 0.138196601125011, // (5 - sqrt(5))/20 G4
0.276393202250021, // 2 * G4 0.276393202250021, // 2 * G4
@ -847,6 +847,5 @@ GLM_FUNC_QUALIFIER T simplex(detail::tvec4<T> const & v)
return T(49) * return T(49) *
(dot(m0 * m0, detail::tvec3<T>(dot(p0, x0), dot(p1, x1), dot(p2, x2))) + (dot(m0 * m0, detail::tvec3<T>(dot(p0, x0), dot(p1, x1), dot(p2, x2))) +
dot(m1 * m1, detail::tvec2<T>(dot(p3, x3), dot(p4, x4)))); dot(m1 * m1, detail::tvec2<T>(dot(p3, x3), dot(p4, x4))));
} }
}//namespace glm }//namespace glm

View File

@ -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),

View File

@ -9,85 +9,59 @@
#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)); struct compute_linearRand
} {
template <typename T>
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.");
return Min;
}
};
template <> template <>
GLM_FUNC_QUALIFIER float linearRand GLM_FUNC_QUALIFIER half compute_linearRand::operator()<half> (half const & Min, half const & Max) const
( {
float const & Min, return half(float(std::rand()) / float(RAND_MAX) * (float(Max) - float(Min)) + float(Min));
float const & Max }
)
{ template <>
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 float(std::rand()) / float(RAND_MAX) * (Max - Min) + Min;
} }
template <> template <>
GLM_FUNC_QUALIFIER double linearRand GLM_FUNC_QUALIFIER double compute_linearRand::operator()<double> (double const & Min, double const & Max) const
( {
double const & Min,
double const & Max
)
{
return double(std::rand()) / double(RAND_MAX) * (Max - Min) + Min; return double(std::rand()) / double(RAND_MAX) * (Max - Min) + Min;
} }
}//namespace detail
template <typename T> template <typename genType>
GLM_FUNC_QUALIFIER detail::tvec2<T> linearRand GLM_FUNC_QUALIFIER genType linearRand
( (
detail::tvec2<T> const & Min, genType const & Min,
detail::tvec2<T> const & Max genType const & Max
) )
{ {
return detail::tvec2<T>( return detail::compute_linearRand()(Min, Max);
linearRand(Min.x, Max.x), }
linearRand(Min.y, Max.y));
}
template <typename T> VECTORIZE_VEC_VEC(linearRand)
GLM_FUNC_QUALIFIER detail::tvec3<T> linearRand
(
detail::tvec3<T> const & Min,
detail::tvec3<T> const & Max
)
{
return detail::tvec3<T>(
linearRand(Min.x, Max.x),
linearRand(Min.y, Max.y),
linearRand(Min.z, Max.z));
}
template <typename T> template <typename genType>
GLM_FUNC_QUALIFIER detail::tvec4<T> linearRand GLM_FUNC_QUALIFIER genType gaussRand
( (
detail::tvec4<T> const & Min,
detail::tvec4<T> const & Max
)
{
return detail::tvec4<T>(
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 & Mean,
genType const & Deviation genType const & Deviation
) )
{ {
genType w, x1, x2; genType w, x1, x2;
do do
@ -99,53 +73,16 @@ GLM_FUNC_QUALIFIER genType gaussRand
} while(w > genType(1)); } while(w > genType(1));
return x2 * Deviation * Deviation * sqrt((genType(-2) * log(w)) / w) + Mean; return x2 * Deviation * Deviation * sqrt((genType(-2) * log(w)) / w) + Mean;
} }
template <typename T> VECTORIZE_VEC_VEC(gaussRand)
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> template <typename T>
GLM_FUNC_QUALIFIER detail::tvec3<T> gaussRand GLM_FUNC_QUALIFIER detail::tvec2<T> diskRand
( (
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 T const & Radius
) )
{ {
detail::tvec2<T> Result(T(0)); detail::tvec2<T> Result(T(0));
T LenRadius(T(0)); T LenRadius(T(0));
@ -157,14 +94,14 @@ GLM_FUNC_QUALIFIER detail::tvec2<T> diskRand
while(LenRadius > Radius); while(LenRadius > Radius);
return Result; return Result;
} }
template <typename T> template <typename T>
GLM_FUNC_QUALIFIER detail::tvec3<T> ballRand GLM_FUNC_QUALIFIER detail::tvec3<T> ballRand
( (
T const & Radius T const & Radius
) )
{ {
detail::tvec3<T> Result(T(0)); detail::tvec3<T> Result(T(0));
T LenRadius(T(0)); T LenRadius(T(0));
@ -176,24 +113,24 @@ GLM_FUNC_QUALIFIER detail::tvec3<T> ballRand
while(LenRadius > Radius); while(LenRadius > Radius);
return Result; return Result;
} }
template <typename T> template <typename T>
GLM_FUNC_QUALIFIER detail::tvec2<T> circularRand GLM_FUNC_QUALIFIER detail::tvec2<T> circularRand
( (
T const & Radius T const & Radius
) )
{ {
T a = linearRand(T(0), T(6.283185307179586476925286766559f)); T a = linearRand(T(0), T(6.283185307179586476925286766559f));
return detail::tvec2<T>(cos(a), sin(a)) * Radius; return detail::tvec2<T>(cos(a), sin(a)) * Radius;
} }
template <typename T> template <typename T>
GLM_FUNC_QUALIFIER detail::tvec3<T> sphericalRand GLM_FUNC_QUALIFIER detail::tvec3<T> sphericalRand
( (
T const & Radius T const & Radius
) )
{ {
T z = linearRand(T(-1), T(1)); T z = linearRand(T(-1), T(1));
T a = linearRand(T(0), T(6.283185307179586476925286766559f)); T a = linearRand(T(0), T(6.283185307179586476925286766559f));
@ -203,6 +140,5 @@ GLM_FUNC_QUALIFIER detail::tvec3<T> sphericalRand
T y = r * sin(a); T y = r * sin(a);
return detail::tvec3<T>(x, y, z) * Radius; return detail::tvec3<T>(x, y, z) * Radius;
} }
}//namespace glm }//namespace glm

View File

@ -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

View File

@ -2,66 +2,36 @@
// 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
(
genType const & x
)
{ {
// fastSqrt
template <typename genType>
GLM_FUNC_QUALIFIER genType fastSqrt
(
genType const & x
)
{
GLM_STATIC_ASSERT(detail::type<genType>::is_float, "'fastSqrt' only accept floating-point input");
return genType(1) / fastInverseSqrt(x); return genType(1) / fastInverseSqrt(x);
} }
template <typename valType> VECTORIZE_VEC(fastSqrt)
GLM_FUNC_QUALIFIER detail::tvec2<valType> fastSqrt
(
detail::tvec2<valType> const & x
)
{
return detail::tvec2<valType>(
fastSqrt(x.x),
fastSqrt(x.y));
}
template <typename valType> // fastInversesqrt
GLM_FUNC_QUALIFIER detail::tvec3<valType> fastSqrt template <typename genType>
( GLM_FUNC_QUALIFIER genType fastInverseSqrt
detail::tvec3<valType> const & x (
)
{
return detail::tvec3<valType>(
fastSqrt(x.x),
fastSqrt(x.y),
fastSqrt(x.z));
}
template <typename valType>
GLM_FUNC_QUALIFIER detail::tvec4<valType> fastSqrt
(
detail::tvec4<valType> const & x
)
{
return detail::tvec4<valType>(
fastSqrt(x.x),
fastSqrt(x.y),
fastSqrt(x.z),
fastSqrt(x.w));
}
// fastInversesqrt
template <typename genType>
GLM_FUNC_QUALIFIER genType fastInverseSqrt
(
genType const & x genType const & x
) )
{ {
genType tmp = x; genType tmp = x;
float xhalf = 0.5f * float(tmp); float xhalf = 0.5f * float(tmp);
uint i = *(uint*)&x; uint i = *(uint*)&x;
@ -71,163 +41,98 @@ GLM_FUNC_QUALIFIER genType fastInverseSqrt
tmp = detail::uif(i).f; tmp = detail::uif(i).f;
tmp = tmp * (1.5f - xhalf * tmp * tmp); tmp = tmp * (1.5f - xhalf * tmp * tmp);
return genType(tmp); return genType(tmp);
} }
template <typename valType> VECTORIZE_VEC(fastInverseSqrt)
GLM_FUNC_QUALIFIER detail::tvec2<valType> fastInverseSqrt
(
detail::tvec2<valType> const & x
)
{
return detail::tvec2<valType>(
fastInverseSqrt(x.x),
fastInverseSqrt(x.y));
}
template <typename valType> // fastLength
GLM_FUNC_QUALIFIER detail::tvec3<valType> fastInverseSqrt template <typename genType>
( GLM_FUNC_QUALIFIER genType fastLength
detail::tvec3<valType> const & x (
)
{
return detail::tvec3<valType>(
fastInverseSqrt(x.x),
fastInverseSqrt(x.y),
fastInverseSqrt(x.z));
}
template <typename valType>
GLM_FUNC_QUALIFIER detail::tvec4<valType> fastInverseSqrt
(
detail::tvec4<valType> const & x
)
{
return detail::tvec4<valType>(
fastInverseSqrt(x.x),
fastInverseSqrt(x.y),
fastInverseSqrt(x.z),
fastInverseSqrt(x.w));
}
// fastLength
template <typename genType>
GLM_FUNC_QUALIFIER genType fastLength
(
genType const & x genType const & x
) )
{ {
return abs(x); return abs(x);
} }
template <typename valType> template <typename valType>
GLM_FUNC_QUALIFIER valType fastLength GLM_FUNC_QUALIFIER valType fastLength
( (
detail::tvec2<valType> const & x detail::tvec2<valType> const & x
) )
{ {
valType sqr = x.x * x.x + x.y * x.y; valType sqr = x.x * x.x + x.y * x.y;
return fastSqrt(sqr); return fastSqrt(sqr);
} }
template <typename valType> template <typename valType>
GLM_FUNC_QUALIFIER valType fastLength GLM_FUNC_QUALIFIER valType fastLength
( (
detail::tvec3<valType> const & x detail::tvec3<valType> const & x
) )
{ {
valType sqr = x.x * x.x + x.y * x.y + x.z * x.z; valType sqr = x.x * x.x + x.y * x.y + x.z * x.z;
return fastSqrt(sqr); return fastSqrt(sqr);
} }
template <typename valType> template <typename valType>
GLM_FUNC_QUALIFIER valType fastLength GLM_FUNC_QUALIFIER valType fastLength
( (
detail::tvec4<valType> const & x detail::tvec4<valType> const & x
) )
{ {
valType sqr = x.x * x.x + x.y * x.y + x.z * x.z + x.w * x.w; valType sqr = x.x * x.x + x.y * x.y + x.z * x.z + x.w * x.w;
return fastSqrt(sqr); return fastSqrt(sqr);
} }
// fastDistance // fastDistance
template <typename genType> template <typename genType>
GLM_FUNC_QUALIFIER genType fastDistance GLM_FUNC_QUALIFIER genType fastDistance
( (
genType const & x, genType const & x,
genType const & y genType const & y
) )
{ {
return fastLength(y - x); return fastLength(y - x);
} }
template <typename valType> // fastNormalize
GLM_FUNC_QUALIFIER valType fastDistance template <typename genType>
( GLM_FUNC_QUALIFIER genType fastNormalize
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 genType const & x
) )
{ {
return x > genType(0) ? genType(1) : -genType(1); return x > genType(0) ? genType(1) : -genType(1);
} }
template <typename valType> template <typename valType>
GLM_FUNC_QUALIFIER detail::tvec2<valType> fastNormalize GLM_FUNC_QUALIFIER detail::tvec2<valType> fastNormalize
( (
detail::tvec2<valType> const & x detail::tvec2<valType> const & x
) )
{ {
valType sqr = x.x * x.x + x.y * x.y; valType sqr = x.x * x.x + x.y * x.y;
return x * fastInverseSqrt(sqr); return x * fastInverseSqrt(sqr);
} }
template <typename valType> template <typename valType>
GLM_FUNC_QUALIFIER detail::tvec3<valType> fastNormalize GLM_FUNC_QUALIFIER detail::tvec3<valType> fastNormalize
( (
detail::tvec3<valType> const & x detail::tvec3<valType> const & x
) )
{ {
valType sqr = x.x * x.x + x.y * x.y + x.z * x.z; valType sqr = x.x * x.x + x.y * x.y + x.z * x.z;
return x * fastInverseSqrt(sqr); return x * fastInverseSqrt(sqr);
} }
template <typename valType> template <typename valType>
GLM_FUNC_QUALIFIER detail::tvec4<valType> fastNormalize GLM_FUNC_QUALIFIER detail::tvec4<valType> fastNormalize
( (
detail::tvec4<valType> const & x detail::tvec4<valType> const & x
) )
{ {
valType sqr = x.x * x.x + x.y * x.y + x.z * x.z + x.w * x.w; valType sqr = x.x * x.x + x.y * x.y + x.z * x.z + x.w * x.w;
return x * fastInverseSqrt(sqr); return x * fastInverseSqrt(sqr);
} }
}//namespace glm }//namespace glm