mirror of
https://github.com/g-truc/glm.git
synced 2024-11-27 02:34:35 +00:00
Merge branch '0.9.3' of ssh://ogl-math.git.sourceforge.net/gitroot/ogl-math/ogl-math into swizzle
This commit is contained in:
commit
34d88adde0
98
glm/core/_vectorize.hpp
Normal file
98
glm/core/_vectorize.hpp
Normal file
@ -0,0 +1,98 @@
|
|||||||
|
///////////////////////////////////////////////////////////////////////////////////
|
||||||
|
/// 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 VECTORIZE_1PARAM(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)); \
|
||||||
|
} \
|
||||||
|
\
|
||||||
|
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)); \
|
||||||
|
} \
|
||||||
|
\
|
||||||
|
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_2PARAMS(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)); \
|
||||||
|
} \
|
||||||
|
\
|
||||||
|
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)); \
|
||||||
|
} \
|
||||||
|
\
|
||||||
|
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)); \
|
||||||
|
}
|
@ -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_1PARAM(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_1PARAM(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_1PARAM(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_1PARAM(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_1PARAM(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_1PARAM(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_1PARAM(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_1PARAM(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>
|
||||||
|
@ -232,7 +232,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;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user