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

paper committed

parent 90553bac
/////////////////////////////////////////////////////////////////////////////////////////
/// OpenGL Mathematics (glm.g-truc.net)
///
/// Copyright (c) 2005 - 2015 G-Truc Creation (www.g-truc.net)
/// Permission is hereby granted, free of charge, to any person obtaining a copy
/// of this software and associated documentation files (the "Software"), to deal
/// in the Software without restriction, including without limitation the rights
/// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
/// copies of the Software, and to permit persons to whom the Software is
/// furnished to do so, subject to the following conditions:
///
/// The above copyright notice and this permission notice shall be included in
/// all copies or substantial portions of the Software.
///
/// Restrictions:
/// By making use of the Software for military purposes, you choose to make
/// a Bunny unhappy.
///
/// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
/// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
/// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
/// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
/// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
/// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
/// THE SOFTWARE.
///
/// @ref gtx_color_space
/// @file glm/gtx/color_space.inl
/// @date 2005-12-21 / 2011-06-07
/// @author Christophe Riccio
///////////////////////////////////////////////////////////////////////////////////////////////////
namespace glm
{
template <typename T, precision P>
GLM_FUNC_QUALIFIER tvec3<T, P> rgbColor(const tvec3<T, P>& hsvColor)
{
tvec3<T, P> hsv = hsvColor;
tvec3<T, P> rgbColor;
if(hsv.y == static_cast<T>(0))
// achromatic (grey)
rgbColor = tvec3<T, P>(hsv.z);
else
{
T sector = floor(hsv.x / T(60));
T frac = (hsv.x / T(60)) - sector;
// factorial part of h
T o = hsv.z * (T(1) - hsv.y);
T p = hsv.z * (T(1) - hsv.y * frac);
T q = hsv.z * (T(1) - hsv.y * (T(1) - frac));
switch(int(sector))
{
default:
case 0:
rgbColor.r = hsv.z;
rgbColor.g = q;
rgbColor.b = o;
break;
case 1:
rgbColor.r = p;
rgbColor.g = hsv.z;
rgbColor.b = o;
break;
case 2:
rgbColor.r = o;
rgbColor.g = hsv.z;
rgbColor.b = q;
break;
case 3:
rgbColor.r = o;
rgbColor.g = p;
rgbColor.b = hsv.z;
break;
case 4:
rgbColor.r = q;
rgbColor.g = o;
rgbColor.b = hsv.z;
break;
case 5:
rgbColor.r = hsv.z;
rgbColor.g = o;
rgbColor.b = p;
break;
}
}
return rgbColor;
}
template <typename T, precision P>
GLM_FUNC_QUALIFIER tvec3<T, P> hsvColor(const tvec3<T, P>& rgbColor)
{
tvec3<T, P> hsv = rgbColor;
float Min = min(min(rgbColor.r, rgbColor.g), rgbColor.b);
float Max = max(max(rgbColor.r, rgbColor.g), rgbColor.b);
float Delta = Max - Min;
hsv.z = Max;
if(Max != static_cast<T>(0))
{
hsv.y = Delta / hsv.z;
T h = static_cast<T>(0);
if(rgbColor.r == Max)
// between yellow & magenta
h = static_cast<T>(0) + T(60) * (rgbColor.g - rgbColor.b) / Delta;
else if(rgbColor.g == Max)
// between cyan & yellow
h = static_cast<T>(120) + T(60) * (rgbColor.b - rgbColor.r) / Delta;
else
// between magenta & cyan
h = static_cast<T>(240) + T(60) * (rgbColor.r - rgbColor.g) / Delta;
if(h < T(0))
hsv.x = h + T(360);
else
hsv.x = h;
}
else
{
// If r = g = b = 0 then s = 0, h is undefined
hsv.y = static_cast<T>(0);
hsv.x = static_cast<T>(0);
}
return hsv;
}
template <typename T>
GLM_FUNC_QUALIFIER tmat4x4<T, defaultp> saturation(T const s)
{
tvec3<T, defaultp> rgbw = tvec3<T, defaultp>(T(0.2126), T(0.7152), T(0.0722));
T col0 = (T(1) - s) * rgbw.r;
T col1 = (T(1) - s) * rgbw.g;
T col2 = (T(1) - s) * rgbw.b;
tmat4x4<T, defaultp> result(T(1));
result[0][0] = col0 + s;
result[0][1] = col0;
result[0][2] = col0;
result[1][0] = col1;
result[1][1] = col1 + s;
result[1][2] = col1;
result[2][0] = col2;
result[2][1] = col2;
result[2][2] = col2 + s;
return result;
}
template <typename T, precision P>
GLM_FUNC_QUALIFIER tvec3<T, P> saturation(const T s, const tvec3<T, P>& color)
{
return tvec3<T, P>(saturation(s) * tvec4<T, P>(color, T(0)));
}
template <typename T, precision P>
GLM_FUNC_QUALIFIER tvec4<T, P> saturation(const T s, const tvec4<T, P>& color)
{
return saturation(s) * color;
}
template <typename T, precision P>
GLM_FUNC_QUALIFIER T luminosity(const tvec3<T, P>& color)
{
const tvec3<T, P> tmp = tvec3<T, P>(0.33, 0.59, 0.11);
return dot(color, tmp);
}
}//namespace glm
///////////////////////////////////////////////////////////////////////////////////
/// OpenGL Mathematics (glm.g-truc.net)
///
/// Copyright (c) 2005 - 2015 G-Truc Creation (www.g-truc.net)
/// Permission is hereby granted, free of charge, to any person obtaining a copy
/// of this software and associated documentation files (the "Software"), to deal
/// in the Software without restriction, including without limitation the rights
/// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
/// copies of the Software, and to permit persons to whom the Software is
/// furnished to do so, subject to the following conditions:
///
/// The above copyright notice and this permission notice shall be included in
/// all copies or substantial portions of the Software.
///
/// Restrictions:
/// By making use of the Software for military purposes, you choose to make
/// a Bunny unhappy.
///
/// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
/// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
/// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
/// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
/// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
/// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
/// THE SOFTWARE.
///
/// @ref gtx_color_space_YCoCg
/// @file glm/gtx/color_space_YCoCg.hpp
/// @date 2008-10-28 / 2011-06-07
/// @author Christophe Riccio
///
/// @see core (dependence)
///
/// @defgroup gtx_color_space_YCoCg GLM_GTX_color_space_YCoCg
/// @ingroup gtx
///
/// @brief RGB to YCoCg conversions and operations
///
/// <glm/gtx/color_space_YCoCg.hpp> need to be included to use these functionalities.
///////////////////////////////////////////////////////////////////////////////////
#pragma once
// Dependency:
#include "../glm.hpp"
#if(defined(GLM_MESSAGES) && !defined(GLM_EXT_INCLUDED))
# pragma message("GLM: GLM_GTX_color_space_YCoCg extension included")
#endif
namespace glm
{
/// @addtogroup gtx_color_space_YCoCg
/// @{
/// Convert a color from RGB color space to YCoCg color space.
/// @see gtx_color_space_YCoCg
template <typename T, precision P>
GLM_FUNC_DECL tvec3<T, P> rgb2YCoCg(
tvec3<T, P> const & rgbColor);
/// Convert a color from YCoCg color space to RGB color space.
/// @see gtx_color_space_YCoCg
template <typename T, precision P>
GLM_FUNC_DECL tvec3<T, P> YCoCg2rgb(
tvec3<T, P> const & YCoCgColor);
/// Convert a color from RGB color space to YCoCgR color space.
/// @see "YCoCg-R: A Color Space with RGB Reversibility and Low Dynamic Range"
/// @see gtx_color_space_YCoCg
template <typename T, precision P>
GLM_FUNC_DECL tvec3<T, P> rgb2YCoCgR(
tvec3<T, P> const & rgbColor);
/// Convert a color from YCoCgR color space to RGB color space.
/// @see "YCoCg-R: A Color Space with RGB Reversibility and Low Dynamic Range"
/// @see gtx_color_space_YCoCg
template <typename T, precision P>
GLM_FUNC_DECL tvec3<T, P> YCoCgR2rgb(
tvec3<T, P> const & YCoCgColor);
/// @}
}//namespace glm
#include "color_space_YCoCg.inl"
///////////////////////////////////////////////////////////////////////////////////
/// OpenGL Mathematics (glm.g-truc.net)
///
/// Copyright (c) 2005 - 2015 G-Truc Creation (www.g-truc.net)
/// Permission is hereby granted, free of charge, to any person obtaining a copy
/// of this software and associated documentation files (the "Software"), to deal
/// in the Software without restriction, including without limitation the rights
/// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
/// copies of the Software, and to permit persons to whom the Software is
/// furnished to do so, subject to the following conditions:
///
/// The above copyright notice and this permission notice shall be included in
/// all copies or substantial portions of the Software.
///
/// Restrictions:
/// By making use of the Software for military purposes, you choose to make
/// a Bunny unhappy.
///
/// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
/// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
/// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
/// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
/// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
/// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
/// THE SOFTWARE.
///
/// @ref gtx_color_space_YCoCg
/// @file glm/gtx/color_space_YCoCg.inl
/// @date 2008-10-28 / 2011-06-07
/// @author Christophe Riccio
///////////////////////////////////////////////////////////////////////////////////////////////////
namespace glm
{
template <typename T, precision P>
GLM_FUNC_QUALIFIER tvec3<T, P> rgb2YCoCg
(
tvec3<T, P> const & rgbColor
)
{
tvec3<T, P> result;
result.x/*Y */ = rgbColor.r / T(4) + rgbColor.g / T(2) + rgbColor.b / T(4);
result.y/*Co*/ = rgbColor.r / T(2) + rgbColor.g * T(0) - rgbColor.b / T(2);
result.z/*Cg*/ = - rgbColor.r / T(4) + rgbColor.g / T(2) - rgbColor.b / T(4);
return result;
}
template <typename T, precision P>
GLM_FUNC_QUALIFIER tvec3<T, P> rgb2YCoCgR
(
tvec3<T, P> const & rgbColor
)
{
tvec3<T, P> result;
result.x/*Y */ = rgbColor.g / T(2) + (rgbColor.r + rgbColor.b) / T(4);
result.y/*Co*/ = rgbColor.r - rgbColor.b;
result.z/*Cg*/ = rgbColor.g - (rgbColor.r + rgbColor.b) / T(2);
return result;
}
template <typename T, precision P>
GLM_FUNC_QUALIFIER tvec3<T, P> YCoCg2rgb
(
tvec3<T, P> const & YCoCgColor
)
{
tvec3<T, P> result;
result.r = YCoCgColor.x + YCoCgColor.y - YCoCgColor.z;
result.g = YCoCgColor.x + YCoCgColor.z;
result.b = YCoCgColor.x - YCoCgColor.y - YCoCgColor.z;
return result;
}
template <typename T, precision P>
GLM_FUNC_QUALIFIER tvec3<T, P> YCoCgR2rgb
(
tvec3<T, P> const & YCoCgRColor
)
{
tvec3<T, P> result;
T tmp = YCoCgRColor.x - (YCoCgRColor.z / T(2));
result.g = YCoCgRColor.z + tmp;
result.b = tmp - (YCoCgRColor.y / T(2));
result.r = result.b + YCoCgRColor.y;
return result;
}
}//namespace glm
///////////////////////////////////////////////////////////////////////////////////
/// OpenGL Mathematics (glm.g-truc.net)
///
/// Copyright (c) 2005 - 2015 G-Truc Creation (www.g-truc.net)
/// Permission is hereby granted, free of charge, to any person obtaining a copy
/// of this software and associated documentation files (the "Software"), to deal
/// in the Software without restriction, including without limitation the rights
/// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
/// copies of the Software, and to permit persons to whom the Software is
/// furnished to do so, subject to the following conditions:
///
/// The above copyright notice and this permission notice shall be included in
/// all copies or substantial portions of the Software.
///
/// Restrictions:
/// By making use of the Software for military purposes, you choose to make
/// a Bunny unhappy.
///
/// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
/// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
/// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
/// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
/// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
/// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
/// THE SOFTWARE.
///
/// @ref gtx_common
/// @file glm/gtx/common.hpp
/// @date 2014-09-08 / 2014-09-08
/// @author Christophe Riccio
///
/// @see core (dependence)
/// @see gtc_half_float (dependence)
///
/// @defgroup gtx_common GLM_GTX_common
/// @ingroup gtx
///
/// @brief Provide functions to increase the compatibility with Cg and HLSL languages
///
/// <glm/gtx/common.hpp> need to be included to use these functionalities.
///////////////////////////////////////////////////////////////////////////////////
#pragma once
// Dependencies:
#include "../vec2.hpp"
#include "../vec3.hpp"
#include "../vec4.hpp"
#include "../gtc/vec1.hpp"
#if(defined(GLM_MESSAGES) && !defined(GLM_EXT_INCLUDED))
# pragma message("GLM: GLM_GTX_common extension included")
#endif
namespace glm
{
/// @addtogroup gtx_common
/// @{
/// Returns true if x is a denormalized number
/// Numbers whose absolute value is too small to be represented in the normal format are represented in an alternate, denormalized format.
/// This format is less precise but can represent values closer to zero.
///
/// @tparam genType Floating-point scalar or vector types.
///
/// @see <a href="http://www.opengl.org/sdk/docs/manglsl/xhtml/isnan.xml">GLSL isnan man page</a>
/// @see <a href="http://www.opengl.org/registry/doc/GLSLangSpec.4.20.8.pdf">GLSL 4.20.8 specification, section 8.3 Common Functions</a>
template <typename genType>
GLM_FUNC_DECL typename genType::bool_type isdenormal(genType const & x);
/// @}
}//namespace glm
#include "common.inl"
///////////////////////////////////////////////////////////////////////////////////
/// OpenGL Mathematics (glm.g-truc.net)
///
/// Copyright (c) 2005 - 2015 G-Truc Creation (www.g-truc.net)
/// Permission is hereby granted, free of charge, to any person obtaining a copy
/// of this software and associated documentation files (the "Software"), to deal
/// in the Software without restriction, including without limitation the rights
/// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
/// copies of the Software, and to permit persons to whom the Software is
/// furnished to do so, subject to the following conditions:
///
/// The above copyright notice and this permission notice shall be included in
/// all copies or substantial portions of the Software.
///
/// Restrictions:
/// By making use of the Software for military purposes, you choose to make
/// a Bunny unhappy.
///
/// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
/// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
/// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
/// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
/// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
/// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
/// THE SOFTWARE.
///
/// @ref gtx_common
/// @file glm/gtx/common.inl
/// @date 2014-09-08 / 2014-09-08
/// @author Christophe Riccio
///////////////////////////////////////////////////////////////////////////////////
#include <cmath>
namespace glm
{
template <typename T>
GLM_FUNC_QUALIFIER bool isdenormal(T const & x)
{
GLM_STATIC_ASSERT(std::numeric_limits<T>::is_iec559, "'isdenormal' only accept floating-point inputs");
# if GLM_HAS_CXX11_STL
return std::fpclassify(x) == FP_SUBNORMAL;
# else
return x != static_cast<T>(0) && std::fabs(x) < std::numeric_limits<T>::min();
# endif
}
template <typename T, precision P>
GLM_FUNC_QUALIFIER typename tvec1<T, P>::bool_type isdenormal
(
tvec1<T, P> const & x
)
{
GLM_STATIC_ASSERT(std::numeric_limits<T>::is_iec559, "'isdenormal' only accept floating-point inputs");
return typename tvec1<T, P>::bool_type(
isdenormal(x.x));
}
template <typename T, precision P>
GLM_FUNC_QUALIFIER typename tvec2<T, P>::bool_type isdenormal
(
tvec2<T, P> const & x
)
{
GLM_STATIC_ASSERT(std::numeric_limits<T>::is_iec559, "'isdenormal' only accept floating-point inputs");
return typename tvec2<T, P>::bool_type(
isdenormal(x.x),
isdenormal(x.y));
}
template <typename T, precision P>
GLM_FUNC_QUALIFIER typename tvec3<T, P>::bool_type isdenormal
(
tvec3<T, P> const & x
)
{
GLM_STATIC_ASSERT(std::numeric_limits<T>::is_iec559, "'isdenormal' only accept floating-point inputs");
return typename tvec3<T, P>::bool_type(
isdenormal(x.x),
isdenormal(x.y),
isdenormal(x.z));
}
template <typename T, precision P>
GLM_FUNC_QUALIFIER typename tvec4<T, P>::bool_type isdenormal
(
tvec4<T, P> const & x
)
{
GLM_STATIC_ASSERT(std::numeric_limits<T>::is_iec559, "'isdenormal' only accept floating-point inputs");
return typename tvec4<T, P>::bool_type(
isdenormal(x.x),
isdenormal(x.y),
isdenormal(x.z),
isdenormal(x.w));
}
}//namespace glm
///////////////////////////////////////////////////////////////////////////////////
/// OpenGL Mathematics (glm.g-truc.net)
///
/// Copyright (c) 2005 - 2015 G-Truc Creation (www.g-truc.net)
/// Permission is hereby granted, free of charge, to any person obtaining a copy
/// of this software and associated documentation files (the "Software"), to deal
/// in the Software without restriction, including without limitation the rights
/// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
/// copies of the Software, and to permit persons to whom the Software is
/// furnished to do so, subject to the following conditions:
///
/// The above copyright notice and this permission notice shall be included in
/// all copies or substantial portions of the Software.
///
/// Restrictions:
/// By making use of the Software for military purposes, you choose to make
/// a Bunny unhappy.
///
/// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
/// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
/// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
/// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
/// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
/// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
/// THE SOFTWARE.
///
/// @ref gtx_compatibility
/// @file glm/gtx/compatibility.hpp
/// @date 2007-01-24 / 2011-06-07
/// @author Christophe Riccio
///
/// @see core (dependence)
/// @see gtc_half_float (dependence)
///
/// @defgroup gtx_compatibility GLM_GTX_compatibility
/// @ingroup gtx
///
/// @brief Provide functions to increase the compatibility with Cg and HLSL languages
///
/// <glm/gtx/compatibility.hpp> need to be included to use these functionalities.
///////////////////////////////////////////////////////////////////////////////////
#pragma once
// Dependency:
#include "../glm.hpp"
#include "../gtc/quaternion.hpp"
#if(defined(GLM_MESSAGES) && !defined(GLM_EXT_INCLUDED))
# pragma message("GLM: GLM_GTX_compatibility extension included")
#endif
#if(GLM_COMPILER & GLM_COMPILER_VC)
# include <cfloat>
#elif(GLM_COMPILER & GLM_COMPILER_GCC)
# include <cmath>
# if(GLM_PLATFORM & GLM_PLATFORM_ANDROID)
# undef isfinite
# endif
#endif//GLM_COMPILER
namespace glm
{
/// @addtogroup gtx_compatibility
/// @{
template <typename T> GLM_FUNC_QUALIFIER T lerp(T x, T y, T a){return mix(x, y, a);} //!< \brief Returns x * (1.0 - a) + y * a, i.e., the linear blend of x and y using the floating-point value a. The value for a is not restricted to the range [0, 1]. (From GLM_GTX_compatibility)
template <typename T, precision P> GLM_FUNC_QUALIFIER tvec2<T, P> lerp(const tvec2<T, P>& x, const tvec2<T, P>& y, T a){return mix(x, y, a);} //!< \brief Returns x * (1.0 - a) + y * a, i.e., the linear blend of x and y using the floating-point value a. The value for a is not restricted to the range [0, 1]. (From GLM_GTX_compatibility)
template <typename T, precision P> GLM_FUNC_QUALIFIER tvec3<T, P> lerp(const tvec3<T, P>& x, const tvec3<T, P>& y, T a){return mix(x, y, a);} //!< \brief Returns x * (1.0 - a) + y * a, i.e., the linear blend of x and y using the floating-point value a. The value for a is not restricted to the range [0, 1]. (From GLM_GTX_compatibility)
template <typename T, precision P> GLM_FUNC_QUALIFIER tvec4<T, P> lerp(const tvec4<T, P>& x, const tvec4<T, P>& y, T a){return mix(x, y, a);} //!< \brief Returns x * (1.0 - a) + y * a, i.e., the linear blend of x and y using the floating-point value a. The value for a is not restricted to the range [0, 1]. (From GLM_GTX_compatibility)
template <typename T, precision P> GLM_FUNC_QUALIFIER tvec2<T, P> lerp(const tvec2<T, P>& x, const tvec2<T, P>& y, const tvec2<T, P>& a){return mix(x, y, a);} //!< \brief Returns the component-wise result of x * (1.0 - a) + y * a, i.e., the linear blend of x and y using vector a. The value for a is not restricted to the range [0, 1]. (From GLM_GTX_compatibility)
template <typename T, precision P> GLM_FUNC_QUALIFIER tvec3<T, P> lerp(const tvec3<T, P>& x, const tvec3<T, P>& y, const tvec3<T, P>& a){return mix(x, y, a);} //!< \brief Returns the component-wise result of x * (1.0 - a) + y * a, i.e., the linear blend of x and y using vector a. The value for a is not restricted to the range [0, 1]. (From GLM_GTX_compatibility)
template <typename T, precision P> GLM_FUNC_QUALIFIER tvec4<T, P> lerp(const tvec4<T, P>& x, const tvec4<T, P>& y, const tvec4<T, P>& a){return mix(x, y, a);} //!< \brief Returns the component-wise result of x * (1.0 - a) + y * a, i.e., the linear blend of x and y using vector a. The value for a is not restricted to the range [0, 1]. (From GLM_GTX_compatibility)
template <typename T, precision P> GLM_FUNC_QUALIFIER T saturate(T x){return clamp(x, T(0), T(1));} //!< \brief Returns clamp(x, 0, 1) for each component in x. (From GLM_GTX_compatibility)
template <typename T, precision P> GLM_FUNC_QUALIFIER tvec2<T, P> saturate(const tvec2<T, P>& x){return clamp(x, T(0), T(1));} //!< \brief Returns clamp(x, 0, 1) for each component in x. (From GLM_GTX_compatibility)
template <typename T, precision P> GLM_FUNC_QUALIFIER tvec3<T, P> saturate(const tvec3<T, P>& x){return clamp(x, T(0), T(1));} //!< \brief Returns clamp(x, 0, 1) for each component in x. (From GLM_GTX_compatibility)
template <typename T, precision P> GLM_FUNC_QUALIFIER tvec4<T, P> saturate(const tvec4<T, P>& x){return clamp(x, T(0), T(1));} //!< \brief Returns clamp(x, 0, 1) for each component in x. (From GLM_GTX_compatibility)
template <typename T, precision P> GLM_FUNC_QUALIFIER T atan2(T x, T y){return atan(x, y);} //!< \brief Arc tangent. Returns an angle whose tangent is y/x. The signs of x and y are used to determine what quadrant the angle is in. The range of values returned by this function is [-PI, PI]. Results are undefined if x and y are both 0. (From GLM_GTX_compatibility)
template <typename T, precision P> GLM_FUNC_QUALIFIER tvec2<T, P> atan2(const tvec2<T, P>& x, const tvec2<T, P>& y){return atan(x, y);} //!< \brief Arc tangent. Returns an angle whose tangent is y/x. The signs of x and y are used to determine what quadrant the angle is in. The range of values returned by this function is [-PI, PI]. Results are undefined if x and y are both 0. (From GLM_GTX_compatibility)
template <typename T, precision P> GLM_FUNC_QUALIFIER tvec3<T, P> atan2(const tvec3<T, P>& x, const tvec3<T, P>& y){return atan(x, y);} //!< \brief Arc tangent. Returns an angle whose tangent is y/x. The signs of x and y are used to determine what quadrant the angle is in. The range of values returned by this function is [-PI, PI]. Results are undefined if x and y are both 0. (From GLM_GTX_compatibility)
template <typename T, precision P> GLM_FUNC_QUALIFIER tvec4<T, P> atan2(const tvec4<T, P>& x, const tvec4<T, P>& y){return atan(x, y);} //!< \brief Arc tangent. Returns an angle whose tangent is y/x. The signs of x and y are used to determine what quadrant the angle is in. The range of values returned by this function is [-PI, PI]. Results are undefined if x and y are both 0. (From GLM_GTX_compatibility)
template <typename genType> GLM_FUNC_DECL bool isfinite(genType const & x); //!< \brief Test whether or not a scalar or each vector component is a finite value. (From GLM_GTX_compatibility)
template <typename T, precision P> GLM_FUNC_DECL tvec2<bool, P> isfinite(const tvec2<T, P>& x); //!< \brief Test whether or not a scalar or each vector component is a finite value. (From GLM_GTX_compatibility)
template <typename T, precision P> GLM_FUNC_DECL tvec3<bool, P> isfinite(const tvec3<T, P>& x); //!< \brief Test whether or not a scalar or each vector component is a finite value. (From GLM_GTX_compatibility)
template <typename T, precision P> GLM_FUNC_DECL tvec4<bool, P> isfinite(const tvec4<T, P>& x); //!< \brief Test whether or not a scalar or each vector component is a finite value. (From GLM_GTX_compatibility)
typedef bool bool1; //!< \brief boolean type with 1 component. (From GLM_GTX_compatibility extension)
typedef tvec2<bool, highp> bool2; //!< \brief boolean type with 2 components. (From GLM_GTX_compatibility extension)
typedef tvec3<bool, highp> bool3; //!< \brief boolean type with 3 components. (From GLM_GTX_compatibility extension)
typedef tvec4<bool, highp> bool4; //!< \brief boolean type with 4 components. (From GLM_GTX_compatibility extension)
typedef bool bool1x1; //!< \brief boolean matrix with 1 x 1 component. (From GLM_GTX_compatibility extension)
typedef tmat2x2<bool, highp> bool2x2; //!< \brief boolean matrix with 2 x 2 components. (From GLM_GTX_compatibility extension)
typedef tmat2x3<bool, highp> bool2x3; //!< \brief boolean matrix with 2 x 3 components. (From GLM_GTX_compatibility extension)
typedef tmat2x4<bool, highp> bool2x4; //!< \brief boolean matrix with 2 x 4 components. (From GLM_GTX_compatibility extension)
typedef tmat3x2<bool, highp> bool3x2; //!< \brief boolean matrix with 3 x 2 components. (From GLM_GTX_compatibility extension)
typedef tmat3x3<bool, highp> bool3x3; //!< \brief boolean matrix with 3 x 3 components. (From GLM_GTX_compatibility extension)
typedef tmat3x4<bool, highp> bool3x4; //!< \brief boolean matrix with 3 x 4 components. (From GLM_GTX_compatibility extension)
typedef tmat4x2<bool, highp> bool4x2; //!< \brief boolean matrix with 4 x 2 components. (From GLM_GTX_compatibility extension)
typedef tmat4x3<bool, highp> bool4x3; //!< \brief boolean matrix with 4 x 3 components. (From GLM_GTX_compatibility extension)
typedef tmat4x4<bool, highp> bool4x4; //!< \brief boolean matrix with 4 x 4 components. (From GLM_GTX_compatibility extension)
typedef int int1; //!< \brief integer vector with 1 component. (From GLM_GTX_compatibility extension)
typedef tvec2<int, highp> int2; //!< \brief integer vector with 2 components. (From GLM_GTX_compatibility extension)
typedef tvec3<int, highp> int3; //!< \brief integer vector with 3 components. (From GLM_GTX_compatibility extension)
typedef tvec4<int, highp> int4; //!< \brief integer vector with 4 components. (From GLM_GTX_compatibility extension)
typedef int int1x1; //!< \brief integer matrix with 1 component. (From GLM_GTX_compatibility extension)
typedef tmat2x2<int, highp> int2x2; //!< \brief integer matrix with 2 x 2 components. (From GLM_GTX_compatibility extension)
typedef tmat2x3<int, highp> int2x3; //!< \brief integer matrix with 2 x 3 components. (From GLM_GTX_compatibility extension)
typedef tmat2x4<int, highp> int2x4; //!< \brief integer matrix with 2 x 4 components. (From GLM_GTX_compatibility extension)
typedef tmat3x2<int, highp> int3x2; //!< \brief integer matrix with 3 x 2 components. (From GLM_GTX_compatibility extension)
typedef tmat3x3<int, highp> int3x3; //!< \brief integer matrix with 3 x 3 components. (From GLM_GTX_compatibility extension)
typedef tmat3x4<int, highp> int3x4; //!< \brief integer matrix with 3 x 4 components. (From GLM_GTX_compatibility extension)
typedef tmat4x2<int, highp> int4x2; //!< \brief integer matrix with 4 x 2 components. (From GLM_GTX_compatibility extension)
typedef tmat4x3<int, highp> int4x3; //!< \brief integer matrix with 4 x 3 components. (From GLM_GTX_compatibility extension)
typedef tmat4x4<int, highp> int4x4; //!< \brief integer matrix with 4 x 4 components. (From GLM_GTX_compatibility extension)
typedef float float1; //!< \brief single-precision floating-point vector with 1 component. (From GLM_GTX_compatibility extension)
typedef tvec2<float, highp> float2; //!< \brief single-precision floating-point vector with 2 components. (From GLM_GTX_compatibility extension)
typedef tvec3<float, highp> float3; //!< \brief single-precision floating-point vector with 3 components. (From GLM_GTX_compatibility extension)
typedef tvec4<float, highp> float4; //!< \brief single-precision floating-point vector with 4 components. (From GLM_GTX_compatibility extension)
typedef float float1x1; //!< \brief single-precision floating-point matrix with 1 component. (From GLM_GTX_compatibility extension)
typedef tmat2x2<float, highp> float2x2; //!< \brief single-precision floating-point matrix with 2 x 2 components. (From GLM_GTX_compatibility extension)
typedef tmat2x3<float, highp> float2x3; //!< \brief single-precision floating-point matrix with 2 x 3 components. (From GLM_GTX_compatibility extension)
typedef tmat2x4<float, highp> float2x4; //!< \brief single-precision floating-point matrix with 2 x 4 components. (From GLM_GTX_compatibility extension)
typedef tmat3x2<float, highp> float3x2; //!< \brief single-precision floating-point matrix with 3 x 2 components. (From GLM_GTX_compatibility extension)
typedef tmat3x3<float, highp> float3x3; //!< \brief single-precision floating-point matrix with 3 x 3 components. (From GLM_GTX_compatibility extension)
typedef tmat3x4<float, highp> float3x4; //!< \brief single-precision floating-point matrix with 3 x 4 components. (From GLM_GTX_compatibility extension)
typedef tmat4x2<float, highp> float4x2; //!< \brief single-precision floating-point matrix with 4 x 2 components. (From GLM_GTX_compatibility extension)
typedef tmat4x3<float, highp> float4x3; //!< \brief single-precision floating-point matrix with 4 x 3 components. (From GLM_GTX_compatibility extension)
typedef tmat4x4<float, highp> float4x4; //!< \brief single-precision floating-point matrix with 4 x 4 components. (From GLM_GTX_compatibility extension)
typedef double double1; //!< \brief double-precision floating-point vector with 1 component. (From GLM_GTX_compatibility extension)
typedef tvec2<double, highp> double2; //!< \brief double-precision floating-point vector with 2 components. (From GLM_GTX_compatibility extension)
typedef tvec3<double, highp> double3; //!< \brief double-precision floating-point vector with 3 components. (From GLM_GTX_compatibility extension)
typedef tvec4<double, highp> double4; //!< \brief double-precision floating-point vector with 4 components. (From GLM_GTX_compatibility extension)
typedef double double1x1; //!< \brief double-precision floating-point matrix with 1 component. (From GLM_GTX_compatibility extension)
typedef tmat2x2<double, highp> double2x2; //!< \brief double-precision floating-point matrix with 2 x 2 components. (From GLM_GTX_compatibility extension)
typedef tmat2x3<double, highp> double2x3; //!< \brief double-precision floating-point matrix with 2 x 3 components. (From GLM_GTX_compatibility extension)
typedef tmat2x4<double, highp> double2x4; //!< \brief double-precision floating-point matrix with 2 x 4 components. (From GLM_GTX_compatibility extension)
typedef tmat3x2<double, highp> double3x2; //!< \brief double-precision floating-point matrix with 3 x 2 components. (From GLM_GTX_compatibility extension)
typedef tmat3x3<double, highp> double3x3; //!< \brief double-precision floating-point matrix with 3 x 3 components. (From GLM_GTX_compatibility extension)
typedef tmat3x4<double, highp> double3x4; //!< \brief double-precision floating-point matrix with 3 x 4 components. (From GLM_GTX_compatibility extension)
typedef tmat4x2<double, highp> double4x2; //!< \brief double-precision floating-point matrix with 4 x 2 components. (From GLM_GTX_compatibility extension)
typedef tmat4x3<double, highp> double4x3; //!< \brief double-precision floating-point matrix with 4 x 3 components. (From GLM_GTX_compatibility extension)
typedef tmat4x4<double, highp> double4x4; //!< \brief double-precision floating-point matrix with 4 x 4 components. (From GLM_GTX_compatibility extension)
/// @}
}//namespace glm
#include "compatibility.inl"
///////////////////////////////////////////////////////////////////////////////////
/// OpenGL Mathematics (glm.g-truc.net)
///
/// Copyright (c) 2005 - 2015 G-Truc Creation (www.g-truc.net)
/// Permission is hereby granted, free of charge, to any person obtaining a copy
/// of this software and associated documentation files (the "Software"), to deal
/// in the Software without restriction, including without limitation the rights
/// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
/// copies of the Software, and to permit persons to whom the Software is
/// furnished to do so, subject to the following conditions:
///
/// The above copyright notice and this permission notice shall be included in
/// all copies or substantial portions of the Software.
///
/// Restrictions:
/// By making use of the Software for military purposes, you choose to make
/// a Bunny unhappy.
///
/// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
/// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
/// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
/// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
/// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
/// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
/// THE SOFTWARE.
///
/// @ref gtx_compatibility
/// @file glm/gtx/compatibility.inl
/// @date 2007-01-24 / 2011-06-07
/// @author Christophe Riccio
///////////////////////////////////////////////////////////////////////////////////////////////////
#include <limits>
namespace glm
{
// isfinite
template <typename genType>
GLM_FUNC_QUALIFIER bool isfinite(
genType const & x)
{
# if GLM_HAS_CXX11_STL
return std::isfinite(x) != 0;
# elif GLM_COMPILER & GLM_COMPILER_VC
return _finite(x);
# elif GLM_COMPILER & GLM_COMPILER_GCC && GLM_PLATFORM & GLM_PLATFORM_ANDROID
return _isfinite(x) != 0;
# else
return x >= std::numeric_limits<genType>::min() && x <= std::numeric_limits<genType>::max();
# endif
}
template <typename T, precision P>
GLM_FUNC_QUALIFIER tvec2<bool, P> isfinite(
tvec2<T, P> const & x)
{
return tvec2<bool, P>(
isfinite(x.x),
isfinite(x.y));
}
template <typename T, precision P>
GLM_FUNC_QUALIFIER tvec3<bool, P> isfinite(
tvec3<T, P> const & x)
{
return tvec3<bool, P>(
isfinite(x.x),
isfinite(x.y),
isfinite(x.z));
}
template <typename T, precision P>
GLM_FUNC_QUALIFIER tvec4<bool, P> isfinite(
tvec4<T, P> const & x)
{
return tvec4<bool, P>(
isfinite(x.x),
isfinite(x.y),
isfinite(x.z),
isfinite(x.w));
}
}//namespace glm
///////////////////////////////////////////////////////////////////////////////////
/// OpenGL Mathematics (glm.g-truc.net)
///
/// Copyright (c) 2005 - 2015 G-Truc Creation (www.g-truc.net)
/// Permission is hereby granted, free of charge, to any person obtaining a copy
/// of this software and associated documentation files (the "Software"), to deal
/// in the Software without restriction, including without limitation the rights
/// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
/// copies of the Software, and to permit persons to whom the Software is
/// furnished to do so, subject to the following conditions:
///
/// The above copyright notice and this permission notice shall be included in
/// all copies or substantial portions of the Software.
///
/// Restrictions:
/// By making use of the Software for military purposes, you choose to make
/// a Bunny unhappy.
///
/// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
/// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
/// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
/// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
/// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
/// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
/// THE SOFTWARE.
///
/// @ref gtx_component_wise
/// @file glm/gtx/component_wise.hpp
/// @date 2007-05-21 / 2011-06-07
/// @author Christophe Riccio
///
/// @see core (dependence)
///
/// @defgroup gtx_component_wise GLM_GTX_component_wise
/// @ingroup gtx
///
/// @brief Operations between components of a type
///
/// <glm/gtx/component_wise.hpp> need to be included to use these functionalities.
///////////////////////////////////////////////////////////////////////////////////
#pragma once
// Dependencies
#include "../detail/setup.hpp"
#include "../detail/precision.hpp"
#if(defined(GLM_MESSAGES) && !defined(GLM_EXT_INCLUDED))
# pragma message("GLM: GLM_GTX_component_wise extension included")
#endif
namespace glm
{
/// @addtogroup gtx_component_wise
/// @{
/// Add all vector components together.
/// @see gtx_component_wise
template <typename genType>
GLM_FUNC_DECL typename genType::value_type compAdd(
genType const & v);
/// Multiply all vector components together.
/// @see gtx_component_wise
template <typename genType>
GLM_FUNC_DECL typename genType::value_type compMul(
genType const & v);
/// Find the minimum value between single vector components.
/// @see gtx_component_wise
template <typename genType>
GLM_FUNC_DECL typename genType::value_type compMin(
genType const & v);
/// Find the maximum value between single vector components.
/// @see gtx_component_wise
template <typename genType>
GLM_FUNC_DECL typename genType::value_type compMax(
genType const & v);
/// @}
}//namespace glm
#include "component_wise.inl"
///////////////////////////////////////////////////////////////////////////////////
/// OpenGL Mathematics (glm.g-truc.net)
///
/// Copyright (c) 2005 - 2015 G-Truc Creation (www.g-truc.net)
/// Permission is hereby granted, free of charge, to any person obtaining a copy
/// of this software and associated documentation files (the "Software"), to deal
/// in the Software without restriction, including without limitation the rights
/// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
/// copies of the Software, and to permit persons to whom the Software is
/// furnished to do so, subject to the following conditions:
///
/// The above copyright notice and this permission notice shall be included in
/// all copies or substantial portions of the Software.
///
/// Restrictions:
/// By making use of the Software for military purposes, you choose to make
/// a Bunny unhappy.
///
/// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
/// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
/// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
/// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
/// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
/// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
/// THE SOFTWARE.
///
/// @ref gtx_component_wise
/// @file glm/gtx/component_wise.inl
/// @date 2007-05-21 / 2011-06-07
/// @author Christophe Riccio
///////////////////////////////////////////////////////////////////////////////////////////////////
namespace glm
{
template <typename T, precision P, template <typename, precision> class vecType>
GLM_FUNC_QUALIFIER T compAdd(vecType<T, P> const & v)
{
T result(0);
for(detail::component_count_t i = 0; i < detail::component_count(v); ++i)
result += v[i];
return result;
}
template <typename T, precision P, template <typename, precision> class vecType>
GLM_FUNC_QUALIFIER T compMul(vecType<T, P> const & v)
{
T result(1);
for(detail::component_count_t i = 0; i < detail::component_count(v); ++i)
result *= v[i];
return result;
}
template <typename T, precision P, template <typename, precision> class vecType>
GLM_FUNC_QUALIFIER T compMin(vecType<T, P> const & v)
{
T result(v[0]);
for(detail::component_count_t i = 1; i < detail::component_count(v); ++i)
result = min(result, v[i]);
return result;
}
template <typename T, precision P, template <typename, precision> class vecType>
GLM_FUNC_QUALIFIER T compMax(vecType<T, P> const & v)
{
T result(v[0]);
for(detail::component_count_t i = 1; i < detail::component_count(v); ++i)
result = max(result, v[i]);
return result;
}
}//namespace glm
///////////////////////////////////////////////////////////////////////////////////
/// OpenGL Mathematics (glm.g-truc.net)
///
/// Copyright (c) 2005 - 2015 G-Truc Creation (www.g-truc.net)
/// Permission is hereby granted, free of charge, to any person obtaining a copy
/// of this software and associated documentation files (the "Software"), to deal
/// in the Software without restriction, including without limitation the rights
/// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
/// copies of the Software, and to permit persons to whom the Software is
/// furnished to do so, subject to the following conditions:
///
/// The above copyright notice and this permission notice shall be included in
/// all copies or substantial portions of the Software.
///
/// Restrictions:
/// By making use of the Software for military purposes, you choose to make
/// a Bunny unhappy.
///
/// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
/// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
/// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
/// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
/// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
/// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
/// THE SOFTWARE.
///
/// @ref gtx_dual_quaternion
/// @file glm/gtx/dual_quaternion.hpp
/// @date 2013-02-10 / 2013-02-20
/// @author Maksim Vorobiev (msomeone@gmail.com)
///
/// @see core (dependence)
/// @see gtc_half_float (dependence)
/// @see gtc_constants (dependence)
/// @see gtc_quaternion (dependence)
///
/// @defgroup gtx_dual_quaternion GLM_GTX_dual_quaternion
/// @ingroup gtx
///
/// @brief Defines a templated dual-quaternion type and several dual-quaternion operations.
///
/// <glm/gtx/dual_quaternion.hpp> need to be included to use these functionalities.
///////////////////////////////////////////////////////////////////////////////////
#pragma once
// Dependency:
#include "../glm.hpp"
#include "../gtc/constants.hpp"
#include "../gtc/quaternion.hpp"
#if(defined(GLM_MESSAGES) && !defined(GLM_EXT_INCLUDED))
# pragma message("GLM: GLM_GTX_dual_quaternion extension included")
#endif
namespace glm
{
/// @addtogroup gtx_dual_quaternion
/// @{
template <typename T, precision P>
struct tdualquat
{
typedef T value_type;
typedef glm::tquat<T, P> part_type;
public:
glm::tquat<T, P> real, dual;
//////////////////////////////////////
// Component accesses
# ifdef GLM_FORCE_SIZE_FUNC
typedef size_t size_type;
/// Return the count of components of a dual quaternion
GLM_FUNC_DECL GLM_CONSTEXPR size_type size() const;
GLM_FUNC_DECL part_type & operator[](size_type i);
GLM_FUNC_DECL part_type const & operator[](size_type i) const;
# else
typedef length_t length_type;
/// Return the count of components of a dual quaternion
GLM_FUNC_DECL GLM_CONSTEXPR length_type length() const;
GLM_FUNC_DECL part_type & operator[](length_type i);
GLM_FUNC_DECL part_type const & operator[](length_type i) const;
# endif//GLM_FORCE_SIZE_FUNC
//////////////////////////////////////
// Implicit basic constructors
GLM_FUNC_DECL tdualquat();
GLM_FUNC_DECL tdualquat(tdualquat<T, P> const & d);
template <precision Q>
GLM_FUNC_DECL tdualquat(tdualquat<T, Q> const & d);
//////////////////////////////////////
// Explicit basic constructors
GLM_FUNC_DECL explicit tdualquat(ctor);
GLM_FUNC_DECL explicit tdualquat(tquat<T, P> const & real);
GLM_FUNC_DECL tdualquat(tquat<T, P> const & orientation, tvec3<T, P> const & translation);
GLM_FUNC_DECL tdualquat(tquat<T, P> const & real, tquat<T, P> const & dual);
//////////////////////////////////////////////////////////////
// tdualquat conversions
# ifdef GLM_FORCE_EXPLICIT_CTOR
template <typename U, precision Q>
GLM_FUNC_DECL explicit tdualquat(tdualquat<U, Q> const & q);
# else
template <typename U, precision Q>
GLM_FUNC_DECL tdualquat(tdualquat<U, Q> const & q);
# endif
GLM_FUNC_DECL explicit tdualquat(tmat2x4<T, P> const & holder_mat);
GLM_FUNC_DECL explicit tdualquat(tmat3x4<T, P> const & aug_mat);
// Operators
GLM_FUNC_DECL tdualquat<T, P> & operator=(tdualquat<T, P> const & m);
template <typename U>
GLM_FUNC_DECL tdualquat<T, P> & operator=(tdualquat<U, P> const & m);
template <typename U>
GLM_FUNC_DECL tdualquat<T, P> & operator*=(U s);
template <typename U>
GLM_FUNC_DECL tdualquat<T, P> & operator/=(U s);
};
template <typename T, precision P>
GLM_FUNC_DECL tquat<T, P> operator- (
tquat<T, P> const & q);
template <typename T, precision P>
GLM_FUNC_DECL tdualquat<T, P> operator+ (
tdualquat<T, P> const & q,
tdualquat<T, P> const & p);
template <typename T, precision P>
GLM_FUNC_DECL tdualquat<T, P> operator* (
tdualquat<T, P> const & q,
tdualquat<T, P> const & p);
template <typename T, precision P>
GLM_FUNC_DECL tvec3<T, P> operator* (
tquat<T, P> const & q,
tvec3<T, P> const & v);
template <typename T, precision P>
GLM_FUNC_DECL tvec3<T, P> operator* (
tvec3<T, P> const & v,
tquat<T, P> const & q);
template <typename T, precision P>
GLM_FUNC_DECL tvec4<T, P> operator* (
tquat<T, P> const & q,
tvec4<T, P> const & v);
template <typename T, precision P>
GLM_FUNC_DECL tvec4<T, P> operator* (
tvec4<T, P> const & v,
tquat<T, P> const & q);
template <typename T, precision P>
GLM_FUNC_DECL tdualquat<T, P> operator* (
tdualquat<T, P> const & q,
T const & s);
template <typename T, precision P>
GLM_FUNC_DECL tdualquat<T, P> operator* (
T const & s,
tdualquat<T, P> const & q);
template <typename T, precision P>
GLM_FUNC_DECL tdualquat<T, P> operator/ (
tdualquat<T, P> const & q,
T const & s);
/// Returns the normalized quaternion.
///
/// @see gtx_dual_quaternion
template <typename T, precision P>
GLM_FUNC_DECL tdualquat<T, P> normalize(
tdualquat<T, P> const & q);
/// Returns the linear interpolation of two dual quaternion.
///
/// @see gtc_dual_quaternion
template <typename T, precision P>
GLM_FUNC_DECL tdualquat<T, P> lerp(
tdualquat<T, P> const & x,
tdualquat<T, P> const & y,
T const & a);
/// Returns the q inverse.
///
/// @see gtx_dual_quaternion
template <typename T, precision P>
GLM_FUNC_DECL tdualquat<T, P> inverse(
tdualquat<T, P> const & q);
/// Converts a quaternion to a 2 * 4 matrix.
///
/// @see gtx_dual_quaternion
template <typename T, precision P>
GLM_FUNC_DECL tmat2x4<T, P> mat2x4_cast(
tdualquat<T, P> const & x);
/// Converts a quaternion to a 3 * 4 matrix.
///
/// @see gtx_dual_quaternion
template <typename T, precision P>
GLM_FUNC_DECL tmat3x4<T, P> mat3x4_cast(
tdualquat<T, P> const & x);
/// Converts a 2 * 4 matrix (matrix which holds real and dual parts) to a quaternion.
///
/// @see gtx_dual_quaternion
template <typename T, precision P>
GLM_FUNC_DECL tdualquat<T, P> dualquat_cast(
tmat2x4<T, P> const & x);
/// Converts a 3 * 4 matrix (augmented matrix rotation + translation) to a quaternion.
///
/// @see gtx_dual_quaternion
template <typename T, precision P>
GLM_FUNC_DECL tdualquat<T, P> dualquat_cast(
tmat3x4<T, P> const & x);
/// Dual-quaternion of low single-precision floating-point numbers.
///
/// @see gtx_dual_quaternion
typedef tdualquat<float, lowp> lowp_dualquat;
/// Dual-quaternion of medium single-precision floating-point numbers.
///
/// @see gtx_dual_quaternion
typedef tdualquat<float, mediump> mediump_dualquat;
/// Dual-quaternion of high single-precision floating-point numbers.
///
/// @see gtx_dual_quaternion
typedef tdualquat<float, highp> highp_dualquat;
/// Dual-quaternion of low single-precision floating-point numbers.
///
/// @see gtx_dual_quaternion
typedef tdualquat<float, lowp> lowp_fdualquat;
/// Dual-quaternion of medium single-precision floating-point numbers.
///
/// @see gtx_dual_quaternion
typedef tdualquat<float, mediump> mediump_fdualquat;
/// Dual-quaternion of high single-precision floating-point numbers.
///
/// @see gtx_dual_quaternion
typedef tdualquat<float, highp> highp_fdualquat;
/// Dual-quaternion of low double-precision floating-point numbers.
///
/// @see gtx_dual_quaternion
typedef tdualquat<double, lowp> lowp_ddualquat;
/// Dual-quaternion of medium double-precision floating-point numbers.
///
/// @see gtx_dual_quaternion
typedef tdualquat<double, mediump> mediump_ddualquat;
/// Dual-quaternion of high double-precision floating-point numbers.
///
/// @see gtx_dual_quaternion
typedef tdualquat<double, highp> highp_ddualquat;
#if(!defined(GLM_PRECISION_HIGHP_FLOAT) && !defined(GLM_PRECISION_MEDIUMP_FLOAT) && !defined(GLM_PRECISION_LOWP_FLOAT))
/// Dual-quaternion of floating-point numbers.
///
/// @see gtx_dual_quaternion
typedef highp_fdualquat dualquat;
/// Dual-quaternion of single-precision floating-point numbers.
///
/// @see gtx_dual_quaternion
typedef highp_fdualquat fdualquat;
#elif(defined(GLM_PRECISION_HIGHP_FLOAT) && !defined(GLM_PRECISION_MEDIUMP_FLOAT) && !defined(GLM_PRECISION_LOWP_FLOAT))
typedef highp_fdualquat dualquat;
typedef highp_fdualquat fdualquat;
#elif(!defined(GLM_PRECISION_HIGHP_FLOAT) && defined(GLM_PRECISION_MEDIUMP_FLOAT) && !defined(GLM_PRECISION_LOWP_FLOAT))
typedef mediump_fdualquat dualquat;
typedef mediump_fdualquat fdualquat;
#elif(!defined(GLM_PRECISION_HIGHP_FLOAT) && !defined(GLM_PRECISION_MEDIUMP_FLOAT) && defined(GLM_PRECISION_LOWP_FLOAT))
typedef lowp_fdualquat dualquat;
typedef lowp_fdualquat fdualquat;
#else
# error "GLM error: multiple default precision requested for single-precision floating-point types"
#endif
#if(!defined(GLM_PRECISION_HIGHP_DOUBLE) && !defined(GLM_PRECISION_MEDIUMP_DOUBLE) && !defined(GLM_PRECISION_LOWP_DOUBLE))
/// Dual-quaternion of default double-precision floating-point numbers.
///
/// @see gtx_dual_quaternion
typedef highp_ddualquat ddualquat;
#elif(defined(GLM_PRECISION_HIGHP_DOUBLE) && !defined(GLM_PRECISION_MEDIUMP_DOUBLE) && !defined(GLM_PRECISION_LOWP_DOUBLE))
typedef highp_ddualquat ddualquat;
#elif(!defined(GLM_PRECISION_HIGHP_DOUBLE) && defined(GLM_PRECISION_MEDIUMP_DOUBLE) && !defined(GLM_PRECISION_LOWP_DOUBLE))
typedef mediump_ddualquat ddualquat;
#elif(!defined(GLM_PRECISION_HIGHP_DOUBLE) && !defined(GLM_PRECISION_MEDIUMP_DOUBLE) && defined(GLM_PRECISION_LOWP_DOUBLE))
typedef lowp_ddualquat ddualquat;
#else
# error "GLM error: Multiple default precision requested for double-precision floating-point types"
#endif
/// @}
} //namespace glm
#include "dual_quaternion.inl"
///////////////////////////////////////////////////////////////////////////////////
/// OpenGL Mathematics (glm.g-truc.net)
///
/// Copyright (c) 2005 - 2015 G-Truc Creation (www.g-truc.net)
/// Permission is hereby granted, free of charge, to any person obtaining a copy
/// of this software and associated documentation files (the "Software"), to deal
/// in the Software without restriction, including without limitation the rights
/// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
/// copies of the Software, and to permit persons to whom the Software is
/// furnished to do so, subject to the following conditions:
///
/// The above copyright notice and this permission notice shall be included in
/// all copies or substantial portions of the Software.
///
/// Restrictions:
/// By making use of the Software for military purposes, you choose to make
/// a Bunny unhappy.
///
/// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
/// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
/// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
/// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
/// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
/// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
/// THE SOFTWARE.
///
/// @ref gtx_dual_quaternion
/// @file glm/gtx/dual_quaternion.inl
/// @date 2013-02-10 / 2013-02-13
/// @author Maksim Vorobiev (msomeone@gmail.com)
///////////////////////////////////////////////////////////////////////////////////
#include "../geometric.hpp"
#include <limits>
namespace glm
{
//////////////////////////////////////
// Component accesses
# ifdef GLM_FORCE_SIZE_FUNC
template <typename T, precision P>
GLM_FUNC_QUALIFIER GLM_CONSTEXPR typename tdualquat<T, P>::size_type tdualquat<T, P>::size() const
{
return 2;
}
template <typename T, precision P>
GLM_FUNC_QUALIFIER typename tdualquat<T, P>::part_type & tdualquat<T, P>::operator[](typename tdualquat<T, P>::size_type i)
{
assert(i >= 0 && static_cast<detail::component_count_t>(i) < detail::component_count(*this));
return (&real)[i];
}
template <typename T, precision P>
GLM_FUNC_QUALIFIER typename tdualquat<T, P>::part_type const & tdualquat<T, P>::operator[](typename tdualquat<T, P>::size_type i) const
{
assert(i >= 0 && static_cast<detail::component_count_t>(i) < detail::component_count(*this));
return (&real)[i];
}
# else
template <typename T, precision P>
GLM_FUNC_QUALIFIER GLM_CONSTEXPR typename tdualquat<T, P>::length_type tdualquat<T, P>::length() const
{
return 2;
}
template <typename T, precision P>
GLM_FUNC_QUALIFIER typename tdualquat<T, P>::part_type & tdualquat<T, P>::operator[](typename tdualquat<T, P>::length_type i)
{
assert(i >= 0 && static_cast<detail::component_count_t>(i) < detail::component_count(*this));
return (&real)[i];
}
template <typename T, precision P>
GLM_FUNC_QUALIFIER typename tdualquat<T, P>::part_type const & tdualquat<T, P>::operator[](typename tdualquat<T, P>::length_type i) const
{
assert(i >= 0 && static_cast<detail::component_count_t>(i) < detail::component_count(*this));
return (&real)[i];
}
# endif//GLM_FORCE_SIZE_FUNC
//////////////////////////////////////
// Implicit basic constructors
template <typename T, precision P>
GLM_FUNC_QUALIFIER tdualquat<T, P>::tdualquat()
# ifndef GLM_FORCE_NO_CTOR_INIT
: real(tquat<T, P>())
, dual(tquat<T, P>(0, 0, 0, 0))
# endif
{}
template <typename T, precision P>
GLM_FUNC_QUALIFIER tdualquat<T, P>::tdualquat(tdualquat<T, P> const & d)
: real(d.real)
, dual(d.dual)
{}
template <typename T, precision P>
template <precision Q>
GLM_FUNC_QUALIFIER tdualquat<T, P>::tdualquat(tdualquat<T, Q> const & d)
: real(d.real)
, dual(d.dual)
{}
//////////////////////////////////////
// Explicit basic constructors
template <typename T, precision P>
GLM_FUNC_QUALIFIER tdualquat<T, P>::tdualquat(ctor)
{}
template <typename T, precision P>
GLM_FUNC_QUALIFIER tdualquat<T, P>::tdualquat(tquat<T, P> const & r)
: real(r), dual(tquat<T, P>(0, 0, 0, 0))
{}
template <typename T, precision P>
GLM_FUNC_QUALIFIER tdualquat<T, P>::tdualquat(tquat<T, P> const & q, tvec3<T, P> const& p)
: real(q), dual(
T(-0.5) * ( p.x*q.x + p.y*q.y + p.z*q.z),
T(+0.5) * ( p.x*q.w + p.y*q.z - p.z*q.y),
T(+0.5) * (-p.x*q.z + p.y*q.w + p.z*q.x),
T(+0.5) * ( p.x*q.y - p.y*q.x + p.z*q.w))
{}
template <typename T, precision P>
GLM_FUNC_QUALIFIER tdualquat<T, P>::tdualquat(tquat<T, P> const & r, tquat<T, P> const & d)
: real(r), dual(d)
{}
//////////////////////////////////////////////////////////////
// tdualquat conversions
template <typename T, precision P>
template <typename U, precision Q>
GLM_FUNC_QUALIFIER tdualquat<T, P>::tdualquat(tdualquat<U, Q> const & q)
: real(q.real)
, dual(q.dual)
{}
template <typename T, precision P>
GLM_FUNC_QUALIFIER tdualquat<T, P>::tdualquat(tmat2x4<T, P> const & m)
{
*this = dualquat_cast(m);
}
template <typename T, precision P>
GLM_FUNC_QUALIFIER tdualquat<T, P>::tdualquat(tmat3x4<T, P> const & m)
{
*this = dualquat_cast(m);
}
//////////////////////////////////////////////////////////////
// tdualquat operators
template <typename T, precision P>
GLM_FUNC_QUALIFIER tdualquat<T, P> & tdualquat<T, P>::operator=(tdualquat<T, P> const & q)
{
this->real = q.real;
this->dual = q.dual;
return *this;
}
template <typename T, precision P>
template <typename U>
GLM_FUNC_QUALIFIER tdualquat<T, P> & tdualquat<T, P>::operator=(tdualquat<U, P> const & q)
{
this->real = q.real;
this->dual = q.dual;
return *this;
}
template <typename T, precision P>
template <typename U>
GLM_FUNC_QUALIFIER tdualquat<T, P> & tdualquat<T, P>::operator*=(U s)
{
this->real *= static_cast<T>(s);
this->dual *= static_cast<T>(s);
return *this;
}
template <typename T, precision P>
template <typename U>
GLM_FUNC_QUALIFIER tdualquat<T, P> & tdualquat<T, P>::operator/=(U s)
{
this->real /= static_cast<T>(s);
this->dual /= static_cast<T>(s);
return *this;
}
//////////////////////////////////////////////////////////////
// tquat<valType> external operators
template <typename T, precision P>
GLM_FUNC_QUALIFIER tdualquat<T, P> operator-(tdualquat<T, P> const & q)
{
return tdualquat<T, P>(-q.real,-q.dual);
}
template <typename T, precision P>
GLM_FUNC_QUALIFIER tdualquat<T, P> operator+(tdualquat<T, P> const & q, tdualquat<T, P> const & p)
{
return tdualquat<T, P>(q.real + p.real,q.dual + p.dual);
}
template <typename T, precision P>
GLM_FUNC_QUALIFIER tdualquat<T, P> operator*(tdualquat<T, P> const & p, tdualquat<T, P> const & o)
{
return tdualquat<T, P>(p.real * o.real,p.real * o.dual + p.dual * o.real);
}
// Transformation
template <typename T, precision P>
GLM_FUNC_QUALIFIER tvec3<T, P> operator*(tdualquat<T, P> const & q, tvec3<T, P> const & v)
{
tvec3<T, P> const real_v3(q.real.x,q.real.y,q.real.z);
tvec3<T, P> const dual_v3(q.dual.x,q.dual.y,q.dual.z);
return (cross(real_v3, cross(real_v3,v) + v * q.real.w + dual_v3) + dual_v3 * q.real.w - real_v3 * q.dual.w) * T(2) + v;
}
template <typename T, precision P>
GLM_FUNC_QUALIFIER tvec3<T, P> operator*(tvec3<T, P> const & v, tdualquat<T, P> const & q)
{
return glm::inverse(q) * v;
}
template <typename T, precision P>
GLM_FUNC_QUALIFIER tvec4<T, P> operator*(tdualquat<T, P> const & q, tvec4<T, P> const & v)
{
return tvec4<T, P>(q * tvec3<T, P>(v), v.w);
}
template <typename T, precision P>
GLM_FUNC_QUALIFIER tvec4<T, P> operator*(tvec4<T, P> const & v, tdualquat<T, P> const & q)
{
return glm::inverse(q) * v;
}
template <typename T, precision P>
GLM_FUNC_QUALIFIER tdualquat<T, P> operator*(tdualquat<T, P> const & q, T const & s)
{
return tdualquat<T, P>(q.real * s, q.dual * s);
}
template <typename T, precision P>
GLM_FUNC_QUALIFIER tdualquat<T, P> operator*(T const & s, tdualquat<T, P> const & q)
{
return q * s;
}
template <typename T, precision P>
GLM_FUNC_QUALIFIER tdualquat<T, P> operator/(tdualquat<T, P> const & q, T const & s)
{
return tdualquat<T, P>(q.real / s, q.dual / s);
}
//////////////////////////////////////
// Boolean operators
template <typename T, precision P>
GLM_FUNC_QUALIFIER bool operator==(tdualquat<T, P> const & q1, tdualquat<T, P> const & q2)
{
return (q1.real == q2.real) && (q1.dual == q2.dual);
}
template <typename T, precision P>
GLM_FUNC_QUALIFIER bool operator!=(tdualquat<T, P> const & q1, tdualquat<T, P> const & q2)
{
return (q1.real != q2.dual) || (q1.real != q2.dual);
}
////////////////////////////////////////////////////////
template <typename T, precision P>
GLM_FUNC_QUALIFIER tdualquat<T, P> normalize(tdualquat<T, P> const & q)
{
return q / length(q.real);
}
template <typename T, precision P>
GLM_FUNC_QUALIFIER tdualquat<T, P> lerp(tdualquat<T, P> const & x, tdualquat<T, P> const & y, T const & a)
{
// Dual Quaternion Linear blend aka DLB:
// Lerp is only defined in [0, 1]
assert(a >= static_cast<T>(0));
assert(a <= static_cast<T>(1));
T const k = dot(x.real,y.real) < static_cast<T>(0) ? -a : a;
T const one(1);
return tdualquat<T, P>(x * (one - a) + y * k);
}
template <typename T, precision P>
GLM_FUNC_QUALIFIER tdualquat<T, P> inverse(tdualquat<T, P> const & q)
{
const glm::tquat<T, P> real = conjugate(q.real);
const glm::tquat<T, P> dual = conjugate(q.dual);
return tdualquat<T, P>(real, dual + (real * (-2.0f * dot(real,dual))));
}
template <typename T, precision P>
GLM_FUNC_QUALIFIER tmat2x4<T, P> mat2x4_cast(tdualquat<T, P> const & x)
{
return tmat2x4<T, P>( x[0].x, x[0].y, x[0].z, x[0].w, x[1].x, x[1].y, x[1].z, x[1].w );
}
template <typename T, precision P>
GLM_FUNC_QUALIFIER tmat3x4<T, P> mat3x4_cast(tdualquat<T, P> const & x)
{
tquat<T, P> r = x.real / length2(x.real);
tquat<T, P> const rr(r.w * x.real.w, r.x * x.real.x, r.y * x.real.y, r.z * x.real.z);
r *= static_cast<T>(2);
T const xy = r.x * x.real.y;
T const xz = r.x * x.real.z;
T const yz = r.y * x.real.z;
T const wx = r.w * x.real.x;
T const wy = r.w * x.real.y;
T const wz = r.w * x.real.z;
tvec4<T, P> const a(
rr.w + rr.x - rr.y - rr.z,
xy - wz,
xz + wy,
-(x.dual.w * r.x - x.dual.x * r.w + x.dual.y * r.z - x.dual.z * r.y));
tvec4<T, P> const b(
xy + wz,
rr.w + rr.y - rr.x - rr.z,
yz - wx,
-(x.dual.w * r.y - x.dual.x * r.z - x.dual.y * r.w + x.dual.z * r.x));
tvec4<T, P> const c(
xz - wy,
yz + wx,
rr.w + rr.z - rr.x - rr.y,
-(x.dual.w * r.z + x.dual.x * r.y - x.dual.y * r.x - x.dual.z * r.w));
return tmat3x4<T, P>(a, b, c);
}
template <typename T, precision P>
GLM_FUNC_QUALIFIER tdualquat<T, P> dualquat_cast(tmat2x4<T, P> const & x)
{
return tdualquat<T, P>(
tquat<T, P>( x[0].w, x[0].x, x[0].y, x[0].z ),
tquat<T, P>( x[1].w, x[1].x, x[1].y, x[1].z ));
}
template <typename T, precision P>
GLM_FUNC_QUALIFIER tdualquat<T, P> dualquat_cast(tmat3x4<T, P> const & x)
{
tquat<T, P> real(uninitialize);
T const trace = x[0].x + x[1].y + x[2].z;
if(trace > static_cast<T>(0))
{
T const r = sqrt(T(1) + trace);
T const invr = static_cast<T>(0.5) / r;
real.w = static_cast<T>(0.5) * r;
real.x = (x[2].y - x[1].z) * invr;
real.y = (x[0].z - x[2].x) * invr;
real.z = (x[1].x - x[0].y) * invr;
}
else if(x[0].x > x[1].y && x[0].x > x[2].z)
{
T const r = sqrt(T(1) + x[0].x - x[1].y - x[2].z);
T const invr = static_cast<T>(0.5) / r;
real.x = static_cast<T>(0.5)*r;
real.y = (x[1].x + x[0].y) * invr;
real.z = (x[0].z + x[2].x) * invr;
real.w = (x[2].y - x[1].z) * invr;
}
else if(x[1].y > x[2].z)
{
T const r = sqrt(T(1) + x[1].y - x[0].x - x[2].z);
T const invr = static_cast<T>(0.5) / r;
real.x = (x[1].x + x[0].y) * invr;
real.y = static_cast<T>(0.5) * r;
real.z = (x[2].y + x[1].z) * invr;
real.w = (x[0].z - x[2].x) * invr;
}
else
{
T const r = sqrt(T(1) + x[2].z - x[0].x - x[1].y);
T const invr = static_cast<T>(0.5) / r;
real.x = (x[0].z + x[2].x) * invr;
real.y = (x[2].y + x[1].z) * invr;
real.z = static_cast<T>(0.5) * r;
real.w = (x[1].x - x[0].y) * invr;
}
tquat<T, P> dual(uninitialize);
dual.x = static_cast<T>(0.5) * ( x[0].w * real.w + x[1].w * real.z - x[2].w * real.y);
dual.y = static_cast<T>(0.5) * (-x[0].w * real.z + x[1].w * real.w + x[2].w * real.x);
dual.z = static_cast<T>(0.5) * ( x[0].w * real.y - x[1].w * real.x + x[2].w * real.w);
dual.w = -static_cast<T>(0.5) * ( x[0].w * real.x + x[1].w * real.y + x[2].w * real.z);
return tdualquat<T, P>(real, dual);
}
}//namespace glm
///////////////////////////////////////////////////////////////////////////////////
/// OpenGL Mathematics (glm.g-truc.net)
///
/// Copyright (c) 2005 - 2015 G-Truc Creation (www.g-truc.net)
/// Permission is hereby granted, free of charge, to any person obtaining a copy
/// of this software and associated documentation files (the "Software"), to deal
/// in the Software without restriction, including without limitation the rights
/// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
/// copies of the Software, and to permit persons to whom the Software is
/// furnished to do so, subject to the following conditions:
///
/// The above copyright notice and this permission notice shall be included in
/// all copies or substantial portions of the Software.
///
/// Restrictions:
/// By making use of the Software for military purposes, you choose to make
/// a Bunny unhappy.
///
/// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
/// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
/// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
/// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
/// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
/// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
/// THE SOFTWARE.
///
/// @ref gtx_euler_angles
/// @file glm/gtx/euler_angles.hpp
/// @date 2005-12-21 / 2011-06-07
/// @author Christophe Riccio
///
/// @see core (dependence)
/// @see gtc_half_float (dependence)
///
/// @defgroup gtx_euler_angles GLM_GTX_euler_angles
/// @ingroup gtx
///
/// @brief Build matrices from Euler angles.
///
/// <glm/gtx/euler_angles.hpp> need to be included to use these functionalities.
///////////////////////////////////////////////////////////////////////////////////
#pragma once
// Dependency:
#include "../glm.hpp"
#if(defined(GLM_MESSAGES) && !defined(GLM_EXT_INCLUDED))
# pragma message("GLM: GLM_GTX_euler_angles extension included")
#endif
namespace glm
{
/// @addtogroup gtx_euler_angles
/// @{
/// Creates a 3D 4 * 4 homogeneous rotation matrix from an euler angle X.
/// @see gtx_euler_angles
template <typename T>
GLM_FUNC_DECL tmat4x4<T, defaultp> eulerAngleX(
T const & angleX);
/// Creates a 3D 4 * 4 homogeneous rotation matrix from an euler angle Y.
/// @see gtx_euler_angles
template <typename T>
GLM_FUNC_DECL tmat4x4<T, defaultp> eulerAngleY(
T const & angleY);
/// Creates a 3D 4 * 4 homogeneous rotation matrix from an euler angle Z.
/// @see gtx_euler_angles
template <typename T>
GLM_FUNC_DECL tmat4x4<T, defaultp> eulerAngleZ(
T const & angleZ);
/// Creates a 3D 4 * 4 homogeneous rotation matrix from euler angles (X * Y).
/// @see gtx_euler_angles
template <typename T>
GLM_FUNC_DECL tmat4x4<T, defaultp> eulerAngleXY(
T const & angleX,
T const & angleY);
/// Creates a 3D 4 * 4 homogeneous rotation matrix from euler angles (Y * X).
/// @see gtx_euler_angles
template <typename T>
GLM_FUNC_DECL tmat4x4<T, defaultp> eulerAngleYX(
T const & angleY,
T const & angleX);
/// Creates a 3D 4 * 4 homogeneous rotation matrix from euler angles (X * Z).
/// @see gtx_euler_angles
template <typename T>
GLM_FUNC_DECL tmat4x4<T, defaultp> eulerAngleXZ(
T const & angleX,
T const & angleZ);
/// Creates a 3D 4 * 4 homogeneous rotation matrix from euler angles (Z * X).
/// @see gtx_euler_angles
template <typename T>
GLM_FUNC_DECL tmat4x4<T, defaultp> eulerAngleZX(
T const & angle,
T const & angleX);
/// Creates a 3D 4 * 4 homogeneous rotation matrix from euler angles (Y * Z).
/// @see gtx_euler_angles
template <typename T>
GLM_FUNC_DECL tmat4x4<T, defaultp> eulerAngleYZ(
T const & angleY,
T const & angleZ);
/// Creates a 3D 4 * 4 homogeneous rotation matrix from euler angles (Z * Y).
/// @see gtx_euler_angles
template <typename T>
GLM_FUNC_DECL tmat4x4<T, defaultp> eulerAngleZY(
T const & angleZ,
T const & angleY);
/// Creates a 3D 4 * 4 homogeneous rotation matrix from euler angles (Y * X * Z).
/// @see gtx_euler_angles
template <typename T>
GLM_FUNC_DECL tmat4x4<T, defaultp> eulerAngleYXZ(
T const & yaw,
T const & pitch,
T const & roll);
/// Creates a 3D 4 * 4 homogeneous rotation matrix from euler angles (Y * X * Z).
/// @see gtx_euler_angles
template <typename T>
GLM_FUNC_DECL tmat4x4<T, defaultp> yawPitchRoll(
T const & yaw,
T const & pitch,
T const & roll);
/// Creates a 2D 2 * 2 rotation matrix from an euler angle.
/// @see gtx_euler_angles
template <typename T>
GLM_FUNC_DECL tmat2x2<T, defaultp> orientate2(T const & angle);
/// Creates a 2D 4 * 4 homogeneous rotation matrix from an euler angle.
/// @see gtx_euler_angles
template <typename T>
GLM_FUNC_DECL tmat3x3<T, defaultp> orientate3(T const & angle);
/// Creates a 3D 3 * 3 rotation matrix from euler angles (Y * X * Z).
/// @see gtx_euler_angles
template <typename T, precision P>
GLM_FUNC_DECL tmat3x3<T, P> orientate3(tvec3<T, P> const & angles);
/// Creates a 3D 4 * 4 homogeneous rotation matrix from euler angles (Y * X * Z).
/// @see gtx_euler_angles
template <typename T, precision P>
GLM_FUNC_DECL tmat4x4<T, P> orientate4(tvec3<T, P> const & angles);
/// @}
}//namespace glm
#include "euler_angles.inl"
///////////////////////////////////////////////////////////////////////////////////
/// OpenGL Mathematics (glm.g-truc.net)
///
/// Copyright (c) 2005 - 2015 G-Truc Creation (www.g-truc.net)
/// Permission is hereby granted, free of charge, to any person obtaining a copy
/// of this software and associated documentation files (the "Software"), to deal
/// in the Software without restriction, including without limitation the rights
/// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
/// copies of the Software, and to permit persons to whom the Software is
/// furnished to do so, subject to the following conditions:
///
/// The above copyright notice and this permission notice shall be included in
/// all copies or substantial portions of the Software.
///
/// Restrictions:
/// By making use of the Software for military purposes, you choose to make
/// a Bunny unhappy.
///
/// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
/// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
/// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
/// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
/// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
/// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
/// THE SOFTWARE.
///
/// @ref gtx_euler_angles
/// @file glm/gtx/euler_angles.inl
/// @date 2005-12-21 / 2011-06-07
/// @author Christophe Riccio
///////////////////////////////////////////////////////////////////////////////////////////////////
namespace glm
{
template <typename T>
GLM_FUNC_QUALIFIER tmat4x4<T, defaultp> eulerAngleX
(
T const & angleX
)
{
T cosX = glm::cos(angleX);
T sinX = glm::sin(angleX);
return tmat4x4<T, defaultp>(
T(1), T(0), T(0), T(0),
T(0), cosX, sinX, T(0),
T(0),-sinX, cosX, T(0),
T(0), T(0), T(0), T(1));
}
template <typename T>
GLM_FUNC_QUALIFIER tmat4x4<T, defaultp> eulerAngleY
(
T const & angleY
)
{
T cosY = glm::cos(angleY);
T sinY = glm::sin(angleY);
return tmat4x4<T, defaultp>(
cosY, T(0), -sinY, T(0),
T(0), T(1), T(0), T(0),
sinY, T(0), cosY, T(0),
T(0), T(0), T(0), T(1));
}
template <typename T>
GLM_FUNC_QUALIFIER tmat4x4<T, defaultp> eulerAngleZ
(
T const & angleZ
)
{
T cosZ = glm::cos(angleZ);
T sinZ = glm::sin(angleZ);
return tmat4x4<T, defaultp>(
cosZ, sinZ, T(0), T(0),
-sinZ, cosZ, T(0), T(0),
T(0), T(0), T(1), T(0),
T(0), T(0), T(0), T(1));
}
template <typename T>
GLM_FUNC_QUALIFIER tmat4x4<T, defaultp> eulerAngleXY
(
T const & angleX,
T const & angleY
)
{
T cosX = glm::cos(angleX);
T sinX = glm::sin(angleX);
T cosY = glm::cos(angleY);
T sinY = glm::sin(angleY);
return tmat4x4<T, defaultp>(
cosY, -sinX * -sinY, cosX * -sinY, T(0),
T(0), cosX, sinX, T(0),
sinY, -sinX * cosY, cosX * cosY, T(0),
T(0), T(0), T(0), T(1));
}
template <typename T>
GLM_FUNC_QUALIFIER tmat4x4<T, defaultp> eulerAngleYX
(
T const & angleY,
T const & angleX
)
{
T cosX = glm::cos(angleX);
T sinX = glm::sin(angleX);
T cosY = glm::cos(angleY);
T sinY = glm::sin(angleY);
return tmat4x4<T, defaultp>(
cosY, 0, -sinY, T(0),
sinY * sinX, cosX, cosY * sinX, T(0),
sinY * cosX, -sinX, cosY * cosX, T(0),
T(0), T(0), T(0), T(1));
}
template <typename T>
GLM_FUNC_QUALIFIER tmat4x4<T, defaultp> eulerAngleXZ
(
T const & angleX,
T const & angleZ
)
{
return eulerAngleX(angleX) * eulerAngleZ(angleZ);
}
template <typename T>
GLM_FUNC_QUALIFIER tmat4x4<T, defaultp> eulerAngleZX
(
T const & angleZ,
T const & angleX
)
{
return eulerAngleZ(angleZ) * eulerAngleX(angleX);
}
template <typename T>
GLM_FUNC_QUALIFIER tmat4x4<T, defaultp> eulerAngleYZ
(
T const & angleY,
T const & angleZ
)
{
return eulerAngleY(angleY) * eulerAngleZ(angleZ);
}
template <typename T>
GLM_FUNC_QUALIFIER tmat4x4<T, defaultp> eulerAngleZY
(
T const & angleZ,
T const & angleY
)
{
return eulerAngleZ(angleZ) * eulerAngleY(angleY);
}
template <typename T>
GLM_FUNC_QUALIFIER tmat4x4<T, defaultp> eulerAngleYXZ
(
T const & yaw,
T const & pitch,
T const & roll
)
{
T tmp_ch = glm::cos(yaw);
T tmp_sh = glm::sin(yaw);
T tmp_cp = glm::cos(pitch);
T tmp_sp = glm::sin(pitch);
T tmp_cb = glm::cos(roll);
T tmp_sb = glm::sin(roll);
tmat4x4<T, defaultp> Result;
Result[0][0] = tmp_ch * tmp_cb + tmp_sh * tmp_sp * tmp_sb;
Result[0][1] = tmp_sb * tmp_cp;
Result[0][2] = -tmp_sh * tmp_cb + tmp_ch * tmp_sp * tmp_sb;
Result[0][3] = static_cast<T>(0);
Result[1][0] = -tmp_ch * tmp_sb + tmp_sh * tmp_sp * tmp_cb;
Result[1][1] = tmp_cb * tmp_cp;
Result[1][2] = tmp_sb * tmp_sh + tmp_ch * tmp_sp * tmp_cb;
Result[1][3] = static_cast<T>(0);
Result[2][0] = tmp_sh * tmp_cp;
Result[2][1] = -tmp_sp;
Result[2][2] = tmp_ch * tmp_cp;
Result[2][3] = static_cast<T>(0);
Result[3][0] = static_cast<T>(0);
Result[3][1] = static_cast<T>(0);
Result[3][2] = static_cast<T>(0);
Result[3][3] = static_cast<T>(1);
return Result;
}
template <typename T>
GLM_FUNC_QUALIFIER tmat4x4<T, defaultp> yawPitchRoll
(
T const & yaw,
T const & pitch,
T const & roll
)
{
T tmp_ch = glm::cos(yaw);
T tmp_sh = glm::sin(yaw);
T tmp_cp = glm::cos(pitch);
T tmp_sp = glm::sin(pitch);
T tmp_cb = glm::cos(roll);
T tmp_sb = glm::sin(roll);
tmat4x4<T, defaultp> Result;
Result[0][0] = tmp_ch * tmp_cb + tmp_sh * tmp_sp * tmp_sb;
Result[0][1] = tmp_sb * tmp_cp;
Result[0][2] = -tmp_sh * tmp_cb + tmp_ch * tmp_sp * tmp_sb;
Result[0][3] = static_cast<T>(0);
Result[1][0] = -tmp_ch * tmp_sb + tmp_sh * tmp_sp * tmp_cb;
Result[1][1] = tmp_cb * tmp_cp;
Result[1][2] = tmp_sb * tmp_sh + tmp_ch * tmp_sp * tmp_cb;
Result[1][3] = static_cast<T>(0);
Result[2][0] = tmp_sh * tmp_cp;
Result[2][1] = -tmp_sp;
Result[2][2] = tmp_ch * tmp_cp;
Result[2][3] = static_cast<T>(0);
Result[3][0] = static_cast<T>(0);
Result[3][1] = static_cast<T>(0);
Result[3][2] = static_cast<T>(0);
Result[3][3] = static_cast<T>(1);
return Result;
}
template <typename T>
GLM_FUNC_QUALIFIER tmat2x2<T, defaultp> orientate2
(
T const & angle
)
{
T c = glm::cos(angle);
T s = glm::sin(angle);
tmat2x2<T, defaultp> Result;
Result[0][0] = c;
Result[0][1] = s;
Result[1][0] = -s;
Result[1][1] = c;
return Result;
}
template <typename T>
GLM_FUNC_QUALIFIER tmat3x3<T, defaultp> orientate3
(
T const & angle
)
{
T c = glm::cos(angle);
T s = glm::sin(angle);
tmat3x3<T, defaultp> Result;
Result[0][0] = c;
Result[0][1] = s;
Result[0][2] = 0.0f;
Result[1][0] = -s;
Result[1][1] = c;
Result[1][2] = 0.0f;
Result[2][0] = 0.0f;
Result[2][1] = 0.0f;
Result[2][2] = 1.0f;
return Result;
}
template <typename T, precision P>
GLM_FUNC_QUALIFIER tmat3x3<T, P> orientate3
(
tvec3<T, P> const & angles
)
{
return tmat3x3<T, P>(yawPitchRoll(angles.z, angles.x, angles.y));
}
template <typename T, precision P>
GLM_FUNC_QUALIFIER tmat4x4<T, P> orientate4
(
tvec3<T, P> const & angles
)
{
return yawPitchRoll(angles.z, angles.x, angles.y);
}
}//namespace glm
///////////////////////////////////////////////////////////////////////////////////
/// OpenGL Mathematics (glm.g-truc.net)
///
/// Copyright (c) 2005 - 2015 G-Truc Creation (www.g-truc.net)
/// Permission is hereby granted, free of charge, to any person obtaining a copy
/// of this software and associated documentation files (the "Software"), to deal
/// in the Software without restriction, including without limitation the rights
/// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
/// copies of the Software, and to permit persons to whom the Software is
/// furnished to do so, subject to the following conditions:
///
/// The above copyright notice and this permission notice shall be included in
/// all copies or substantial portions of the Software.
///
/// Restrictions:
/// By making use of the Software for military purposes, you choose to make
/// a Bunny unhappy.
///
/// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
/// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
/// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
/// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
/// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
/// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
/// THE SOFTWARE.
///
/// @ref gtx_extend
/// @file glm/gtx/extend.hpp
/// @date 2006-01-07 / 2011-06-07
/// @author Christophe Riccio
///
/// @see core (dependence)
///
/// @defgroup gtx_extend GLM_GTX_extend
/// @ingroup gtx
///
/// @brief Extend a position from a source to a position at a defined length.
///
/// <glm/gtx/extend.hpp> need to be included to use these functionalities.
///////////////////////////////////////////////////////////////////////////////////
#pragma once
// Dependency:
#include "../glm.hpp"
#if(defined(GLM_MESSAGES) && !defined(GLM_EXT_INCLUDED))
# pragma message("GLM: GLM_GTX_extend extension included")
#endif
namespace glm
{
/// @addtogroup gtx_extend
/// @{
/// Extends of Length the Origin position using the (Source - Origin) direction.
/// @see gtx_extend
template <typename genType>
GLM_FUNC_DECL genType extend(
genType const & Origin,
genType const & Source,
typename genType::value_type const Length);
/// @}
}//namespace glm
#include "extend.inl"
///////////////////////////////////////////////////////////////////////////////////
/// OpenGL Mathematics (glm.g-truc.net)
///
/// Copyright (c) 2005 - 2015 G-Truc Creation (www.g-truc.net)
/// Permission is hereby granted, free of charge, to any person obtaining a copy
/// of this software and associated documentation files (the "Software"), to deal
/// in the Software without restriction, including without limitation the rights
/// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
/// copies of the Software, and to permit persons to whom the Software is
/// furnished to do so, subject to the following conditions:
///
/// The above copyright notice and this permission notice shall be included in
/// all copies or substantial portions of the Software.
///
/// Restrictions:
/// By making use of the Software for military purposes, you choose to make
/// a Bunny unhappy.
///
/// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
/// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
/// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
/// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
/// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
/// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
/// THE SOFTWARE.
///
/// @ref gtx_extend
/// @file glm/gtx/extend.inl
/// @date 2006-01-07 / 2011-06-07
/// @author Christophe Riccio
///////////////////////////////////////////////////////////////////////////////////////////////////
namespace glm
{
template <typename genType>
GLM_FUNC_QUALIFIER genType extend
(
genType const & Origin,
genType const & Source,
genType const & Distance
)
{
return Origin + (Source - Origin) * Distance;
}
template <typename T, precision P>
GLM_FUNC_QUALIFIER tvec2<T, P> extend
(
tvec2<T, P> const & Origin,
tvec2<T, P> const & Source,
T const & Distance
)
{
return Origin + (Source - Origin) * Distance;
}
template <typename T, precision P>
GLM_FUNC_QUALIFIER tvec3<T, P> extend
(
tvec3<T, P> const & Origin,
tvec3<T, P> const & Source,
T const & Distance
)
{
return Origin + (Source - Origin) * Distance;
}
template <typename T, precision P>
GLM_FUNC_QUALIFIER tvec4<T, P> extend
(
tvec4<T, P> const & Origin,
tvec4<T, P> const & Source,
T const & Distance
)
{
return Origin + (Source - Origin) * Distance;
}
}//namespace glm
///////////////////////////////////////////////////////////////////////////////////
/// OpenGL Mathematics (glm.g-truc.net)
///
/// Copyright (c) 2005 - 2015 G-Truc Creation (www.g-truc.net)
/// Permission is hereby granted, free of charge, to any person obtaining a copy
/// of this software and associated documentation files (the "Software"), to deal
/// in the Software without restriction, including without limitation the rights
/// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
/// copies of the Software, and to permit persons to whom the Software is
/// furnished to do so, subject to the following conditions:
///
/// The above copyright notice and this permission notice shall be included in
/// all copies or substantial portions of the Software.
///
/// Restrictions:
/// By making use of the Software for military purposes, you choose to make
/// a Bunny unhappy.
///
/// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
/// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
/// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
/// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
/// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
/// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
/// THE SOFTWARE.
///
/// @ref gtx_extented_min_max
/// @file glm/gtx/extented_min_max.hpp
/// @date 2007-03-14 / 2011-06-07
/// @author Christophe Riccio
///
/// @see core (dependence)
/// @see gtx_half_float (dependence)
///
/// @defgroup gtx_extented_min_max GLM_GTX_extented_min_max
/// @ingroup gtx
///
/// Min and max functions for 3 to 4 parameters.
///
/// <glm/gtx/extented_min_max.hpp> need to be included to use these functionalities.
///////////////////////////////////////////////////////////////////////////////////
#pragma once
// Dependency:
#include "../glm.hpp"
#if(defined(GLM_MESSAGES) && !defined(GLM_EXT_INCLUDED))
# pragma message("GLM: GLM_GTX_extented_min_max extension included")
#endif
namespace glm
{
/// @addtogroup gtx_extented_min_max
/// @{
/// Return the minimum component-wise values of 3 inputs
/// @see gtx_extented_min_max
template <typename T>
GLM_FUNC_DECL T min(
T const & x,
T const & y,
T const & z);
/// Return the minimum component-wise values of 3 inputs
/// @see gtx_extented_min_max
template <typename T, template <typename> class C>
GLM_FUNC_DECL C<T> min(
C<T> const & x,
typename C<T>::T const & y,
typename C<T>::T const & z);
/// Return the minimum component-wise values of 3 inputs
/// @see gtx_extented_min_max
template <typename T, template <typename> class C>
GLM_FUNC_DECL C<T> min(
C<T> const & x,
C<T> const & y,
C<T> const & z);
/// Return the minimum component-wise values of 4 inputs
/// @see gtx_extented_min_max
template <typename T>
GLM_FUNC_DECL T min(
T const & x,
T const & y,
T const & z,
T const & w);
/// Return the minimum component-wise values of 4 inputs
/// @see gtx_extented_min_max
template <typename T, template <typename> class C>
GLM_FUNC_DECL C<T> min(
C<T> const & x,
typename C<T>::T const & y,
typename C<T>::T const & z,
typename C<T>::T const & w);
/// Return the minimum component-wise values of 4 inputs
/// @see gtx_extented_min_max
template <typename T, template <typename> class C>
GLM_FUNC_DECL C<T> min(
C<T> const & x,
C<T> const & y,
C<T> const & z,
C<T> const & w);
/// Return the maximum component-wise values of 3 inputs
/// @see gtx_extented_min_max
template <typename T>
GLM_FUNC_DECL T max(
T const & x,
T const & y,
T const & z);
/// Return the maximum component-wise values of 3 inputs
/// @see gtx_extented_min_max
template <typename T, template <typename> class C>
GLM_FUNC_DECL C<T> max(
C<T> const & x,
typename C<T>::T const & y,
typename C<T>::T const & z);
/// Return the maximum component-wise values of 3 inputs
/// @see gtx_extented_min_max
template <typename T, template <typename> class C>
GLM_FUNC_DECL C<T> max(
C<T> const & x,
C<T> const & y,
C<T> const & z);
/// Return the maximum component-wise values of 4 inputs
/// @see gtx_extented_min_max
template <typename T>
GLM_FUNC_DECL T max(
T const & x,
T const & y,
T const & z,
T const & w);
/// Return the maximum component-wise values of 4 inputs
/// @see gtx_extented_min_max
template <typename T, template <typename> class C>
GLM_FUNC_DECL C<T> max(
C<T> const & x,
typename C<T>::T const & y,
typename C<T>::T const & z,
typename C<T>::T const & w);
/// Return the maximum component-wise values of 4 inputs
/// @see gtx_extented_min_max
template <typename T, template <typename> class C>
GLM_FUNC_DECL C<T> max(
C<T> const & x,
C<T> const & y,
C<T> const & z,
C<T> const & w);
/// @}
}//namespace glm
#include "extented_min_max.inl"
///////////////////////////////////////////////////////////////////////////////////
/// OpenGL Mathematics (glm.g-truc.net)
///
/// Copyright (c) 2005 - 2015 G-Truc Creation (www.g-truc.net)
/// Permission is hereby granted, free of charge, to any person obtaining a copy
/// of this software and associated documentation files (the "Software"), to deal
/// in the Software without restriction, including without limitation the rights
/// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
/// copies of the Software, and to permit persons to whom the Software is
/// furnished to do so, subject to the following conditions:
///
/// The above copyright notice and this permission notice shall be included in
/// all copies or substantial portions of the Software.
///
/// Restrictions:
/// By making use of the Software for military purposes, you choose to make
/// a Bunny unhappy.
///
/// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
/// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
/// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
/// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
/// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
/// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
/// THE SOFTWARE.
///
/// @ref gtx_extented_min_max
/// @file glm/gtx/extented_min_max.inl
/// @date 2007-03-14 / 2011-06-07
/// @author Christophe Riccio
///////////////////////////////////////////////////////////////////////////////////////////////////
namespace glm
{
template <typename T>
GLM_FUNC_QUALIFIER T min(
T const & x,
T const & y,
T const & z)
{
return glm::min(glm::min(x, y), z);
}
template <typename T, template <typename> class C>
GLM_FUNC_QUALIFIER C<T> min
(
C<T> const & x,
typename C<T>::T const & y,
typename C<T>::T const & z
)
{
return glm::min(glm::min(x, y), z);
}
template <typename T, template <typename> class C>
GLM_FUNC_QUALIFIER C<T> min
(
C<T> const & x,
C<T> const & y,
C<T> const & z
)
{
return glm::min(glm::min(x, y), z);
}
template <typename T>
GLM_FUNC_QUALIFIER T min
(
T const & x,
T const & y,
T const & z,
T const & w
)
{
return glm::min(glm::min(x, y), glm::min(z, w));
}
template <typename T, template <typename> class C>
GLM_FUNC_QUALIFIER C<T> min
(
C<T> const & x,
typename C<T>::T const & y,
typename C<T>::T const & z,
typename C<T>::T const & w
)
{
return glm::min(glm::min(x, y), glm::min(z, w));
}
template <typename T, template <typename> class C>
GLM_FUNC_QUALIFIER C<T> min
(
C<T> const & x,
C<T> const & y,
C<T> const & z,
C<T> const & w
)
{
return glm::min(glm::min(x, y), glm::min(z, w));
}
template <typename T>
GLM_FUNC_QUALIFIER T max(
T const & x,
T const & y,
T const & z)
{
return glm::max(glm::max(x, y), z);
}
template <typename T, template <typename> class C>
GLM_FUNC_QUALIFIER C<T> max
(
C<T> const & x,
typename C<T>::T const & y,
typename C<T>::T const & z
)
{
return glm::max(glm::max(x, y), z);
}
template <typename T, template <typename> class C>
GLM_FUNC_QUALIFIER C<T> max
(
C<T> const & x,
C<T> const & y,
C<T> const & z
)
{
return glm::max(glm::max(x, y), z);
}
template <typename T>
GLM_FUNC_QUALIFIER T max
(
T const & x,
T const & y,
T const & z,
T const & w
)
{
return glm::max(glm::max(x, y), glm::max(z, w));
}
template <typename T, template <typename> class C>
GLM_FUNC_QUALIFIER C<T> max
(
C<T> const & x,
typename C<T>::T const & y,
typename C<T>::T const & z,
typename C<T>::T const & w
)
{
return glm::max(glm::max(x, y), glm::max(z, w));
}
template <typename T, template <typename> class C>
GLM_FUNC_QUALIFIER C<T> max
(
C<T> const & x,
C<T> const & y,
C<T> const & z,
C<T> const & w
)
{
return glm::max(glm::max(x, y), glm::max(z, w));
}
}//namespace glm
///////////////////////////////////////////////////////////////////////////////////
/// OpenGL Mathematics (glm.g-truc.net)
///
/// Copyright (c) 2005 - 2015 G-Truc Creation (www.g-truc.net)
/// Permission is hereby granted, free of charge, to any person obtaining a copy
/// of this software and associated documentation files (the "Software"), to deal
/// in the Software without restriction, including without limitation the rights
/// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
/// copies of the Software, and to permit persons to whom the Software is
/// furnished to do so, subject to the following conditions:
///
/// The above copyright notice and this permission notice shall be included in
/// all copies or substantial portions of the Software.
///
/// Restrictions:
/// By making use of the Software for military purposes, you choose to make
/// a Bunny unhappy.
///
/// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
/// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
/// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
/// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
/// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
/// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
/// THE SOFTWARE.
///
/// @ref gtx_fast_exponential
/// @file glm/gtx/fast_exponential.hpp
/// @date 2006-01-09 / 2011-06-07
/// @author Christophe Riccio
///
/// @see core (dependence)
/// @see gtx_half_float (dependence)
///
/// @defgroup gtx_fast_exponential GLM_GTX_fast_exponential
/// @ingroup gtx
///
/// @brief Fast but less accurate implementations of exponential based functions.
///
/// <glm/gtx/fast_exponential.hpp> need to be included to use these functionalities.
///////////////////////////////////////////////////////////////////////////////////
#pragma once
// Dependency:
#include "../glm.hpp"
#if(defined(GLM_MESSAGES) && !defined(GLM_EXT_INCLUDED))
# pragma message("GLM: GLM_GTX_fast_exponential extension included")
#endif
namespace glm
{
/// @addtogroup gtx_fast_exponential
/// @{
/// Faster than the common pow function but less accurate.
/// @see gtx_fast_exponential
template <typename genType>
GLM_FUNC_DECL genType fastPow(genType x, genType y);
/// Faster than the common pow function but less accurate.
/// @see gtx_fast_exponential
template <typename T, precision P, template <typename, precision> class vecType>
GLM_FUNC_DECL vecType<T, P> fastPow(vecType<T, P> const & x, vecType<T, P> const & y);
/// Faster than the common pow function but less accurate.
/// @see gtx_fast_exponential
template <typename genTypeT, typename genTypeU>
GLM_FUNC_DECL genTypeT fastPow(genTypeT x, genTypeU y);
/// Faster than the common pow function but less accurate.
/// @see gtx_fast_exponential
template <typename T, precision P, template <typename, precision> class vecType>
GLM_FUNC_DECL vecType<T, P> fastPow(vecType<T, P> const & x);
/// Faster than the common exp function but less accurate.
/// @see gtx_fast_exponential
template <typename T>
GLM_FUNC_DECL T fastExp(T x);
/// Faster than the common exp function but less accurate.
/// @see gtx_fast_exponential
template <typename T, precision P, template <typename, precision> class vecType>
GLM_FUNC_DECL vecType<T, P> fastExp(vecType<T, P> const & x);
/// Faster than the common log function but less accurate.
/// @see gtx_fast_exponential
template <typename T>
GLM_FUNC_DECL T fastLog(T x);
/// Faster than the common exp2 function but less accurate.
/// @see gtx_fast_exponential
template <typename T, precision P, template <typename, precision> class vecType>
GLM_FUNC_DECL vecType<T, P> fastLog(vecType<T, P> const & x);
/// Faster than the common exp2 function but less accurate.
/// @see gtx_fast_exponential
template <typename T>
GLM_FUNC_DECL T fastExp2(T x);
/// Faster than the common exp2 function but less accurate.
/// @see gtx_fast_exponential
template <typename T, precision P, template <typename, precision> class vecType>
GLM_FUNC_DECL vecType<T, P> fastExp2(vecType<T, P> const & x);
/// Faster than the common log2 function but less accurate.
/// @see gtx_fast_exponential
template <typename T>
GLM_FUNC_DECL T fastLog2(T x);
/// Faster than the common log2 function but less accurate.
/// @see gtx_fast_exponential
template <typename T, precision P, template <typename, precision> class vecType>
GLM_FUNC_DECL vecType<T, P> fastLog2(vecType<T, P> const & x);
/// @}
}//namespace glm
#include "fast_exponential.inl"
///////////////////////////////////////////////////////////////////////////////////
/// OpenGL Mathematics (glm.g-truc.net)
///
/// Copyright (c) 2005 - 2015 G-Truc Creation (www.g-truc.net)
/// Permission is hereby granted, free of charge, to any person obtaining a copy
/// of this software and associated documentation files (the "Software"), to deal
/// in the Software without restriction, including without limitation the rights
/// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
/// copies of the Software, and to permit persons to whom the Software is
/// furnished to do so, subject to the following conditions:
///
/// The above copyright notice and this permission notice shall be included in
/// all copies or substantial portions of the Software.
///
/// Restrictions:
/// By making use of the Software for military purposes, you choose to make
/// a Bunny unhappy.
///
/// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
/// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
/// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
/// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
/// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
/// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
/// THE SOFTWARE.
///
/// @ref gtx_fast_exponential
/// @file glm/gtx/fast_exponential.inl
/// @date 2006-01-09 / 2011-06-07
/// @author Christophe Riccio
///////////////////////////////////////////////////////////////////////////////////////////////////
namespace glm
{
// fastPow:
template <typename genType>
GLM_FUNC_QUALIFIER genType fastPow(genType x, genType y)
{
return exp(y * log(x));
}
template <typename T, precision P, template <typename, precision> class vecType>
GLM_FUNC_QUALIFIER vecType<T, P> fastPow(vecType<T, P> const & x, vecType<T, P> const & y)
{
return exp(y * log(x));
}
template <typename T>
GLM_FUNC_QUALIFIER T fastPow(T x, int y)
{
T f = static_cast<T>(1);
for(int i = 0; i < y; ++i)
f *= x;
return f;
}
template <typename T, precision P, template <typename, precision> class vecType>
GLM_FUNC_QUALIFIER vecType<T, P> fastPow(vecType<T, P> const & x, vecType<int, P> const & y)
{
vecType<T, P> Result(uninitialize);
for(detail::component_count_t i = 0; i < detail::component_count(x); ++i)
Result[i] = fastPow(x[i], y[i]);
return Result;
}
// fastExp
// Note: This function provides accurate results only for value between -1 and 1, else avoid it.
template <typename T>
GLM_FUNC_QUALIFIER T fastExp(T x)
{
// This has a better looking and same performance in release mode than the following code. However, in debug mode it's slower.
// return 1.0f + x * (1.0f + x * 0.5f * (1.0f + x * 0.3333333333f * (1.0f + x * 0.25 * (1.0f + x * 0.2f))));
T x2 = x * x;
T x3 = x2 * x;
T x4 = x3 * x;
T x5 = x4 * x;
return T(1) + x + (x2 * T(0.5)) + (x3 * T(0.1666666667)) + (x4 * T(0.041666667)) + (x5 * T(0.008333333333));
}
/* // Try to handle all values of float... but often shower than std::exp, glm::floor and the loop kill the performance
GLM_FUNC_QUALIFIER float fastExp(float x)
{
const float e = 2.718281828f;
const float IntegerPart = floor(x);
const float FloatPart = x - IntegerPart;
float z = 1.f;
for(int i = 0; i < int(IntegerPart); ++i)
z *= e;
const float x2 = FloatPart * FloatPart;
const float x3 = x2 * FloatPart;
const float x4 = x3 * FloatPart;
const float x5 = x4 * FloatPart;
return z * (1.0f + FloatPart + (x2 * 0.5f) + (x3 * 0.1666666667f) + (x4 * 0.041666667f) + (x5 * 0.008333333333f));
}
// Increase accuracy on number bigger that 1 and smaller than -1 but it's not enough for high and negative numbers
GLM_FUNC_QUALIFIER float fastExp(float x)
{
// This has a better looking and same performance in release mode than the following code. However, in debug mode it's slower.
// return 1.0f + x * (1.0f + x * 0.5f * (1.0f + x * 0.3333333333f * (1.0f + x * 0.25 * (1.0f + x * 0.2f))));
float x2 = x * x;
float x3 = x2 * x;
float x4 = x3 * x;
float x5 = x4 * x;
float x6 = x5 * x;
float x7 = x6 * x;
float x8 = x7 * x;
return 1.0f + x + (x2 * 0.5f) + (x3 * 0.1666666667f) + (x4 * 0.041666667f) + (x5 * 0.008333333333f)+ (x6 * 0.00138888888888f) + (x7 * 0.000198412698f) + (x8 * 0.0000248015873f);;
}
*/
template <typename T, precision P, template <typename, precision> class vecType>
GLM_FUNC_QUALIFIER vecType<T, P> fastExp(vecType<T, P> const & x)
{
return detail::functor1<T, T, P, vecType>::call(fastExp, x);
}
// fastLog
template <typename genType>
GLM_FUNC_QUALIFIER genType fastLog(genType x)
{
return std::log(x);
}
/* Slower than the VC7.1 function...
GLM_FUNC_QUALIFIER float fastLog(float x)
{
float y1 = (x - 1.0f) / (x + 1.0f);
float y2 = y1 * y1;
return 2.0f * y1 * (1.0f + y2 * (0.3333333333f + y2 * (0.2f + y2 * 0.1428571429f)));
}
*/
template <typename T, precision P, template <typename, precision> class vecType>
GLM_FUNC_QUALIFIER vecType<T, P> fastLog(vecType<T, P> const & x)
{
return detail::functor1<T, T, P, vecType>::call(fastLog, x);
}
//fastExp2, ln2 = 0.69314718055994530941723212145818f
template <typename genType>
GLM_FUNC_QUALIFIER genType fastExp2(genType x)
{
return fastExp(0.69314718055994530941723212145818f * x);
}
template <typename T, precision P, template <typename, precision> class vecType>
GLM_FUNC_QUALIFIER vecType<T, P> fastExp2(vecType<T, P> const & x)
{
return detail::functor1<T, T, P, vecType>::call(fastExp2, x);
}
// fastLog2, ln2 = 0.69314718055994530941723212145818f
template <typename genType>
GLM_FUNC_QUALIFIER genType fastLog2(genType x)
{
return fastLog(x) / 0.69314718055994530941723212145818f;
}
template <typename T, precision P, template <typename, precision> class vecType>
GLM_FUNC_QUALIFIER vecType<T, P> fastLog2(vecType<T, P> const & x)
{
return detail::functor1<T, T, P, vecType>::call(fastLog2, x);
}
}//namespace glm
///////////////////////////////////////////////////////////////////////////////////
/// OpenGL Mathematics (glm.g-truc.net)
///
/// Copyright (c) 2005 - 2015 G-Truc Creation (www.g-truc.net)
/// Permission is hereby granted, free of charge, to any person obtaining a copy
/// of this software and associated documentation files (the "Software"), to deal
/// in the Software without restriction, including without limitation the rights
/// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
/// copies of the Software, and to permit persons to whom the Software is
/// furnished to do so, subject to the following conditions:
///
/// The above copyright notice and this permission notice shall be included in
/// all copies or substantial portions of the Software.
///
/// Restrictions:
/// By making use of the Software for military purposes, you choose to make
/// a Bunny unhappy.
///
/// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
/// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
/// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
/// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
/// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
/// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
/// THE SOFTWARE.
///
/// @ref gtx_fast_square_root
/// @file glm/gtx/fast_square_root.hpp
/// @date 2006-01-04 / 2011-06-07
/// @author Christophe Riccio
///
/// @see core (dependence)
///
/// @defgroup gtx_fast_square_root GLM_GTX_fast_square_root
/// @ingroup gtx
///
/// @brief Fast but less accurate implementations of square root based functions.
/// - Sqrt optimisation based on Newton's method,
/// www.gamedev.net/community/forums/topic.asp?topic id=139956
///
/// <glm/gtx/fast_square_root.hpp> need to be included to use these functionalities.
///////////////////////////////////////////////////////////////////////////////////
#pragma once
// Dependency:
#include "../common.hpp"
#include "../exponential.hpp"
#include "../geometric.hpp"
#if(defined(GLM_MESSAGES) && !defined(GLM_EXT_INCLUDED))
# pragma message("GLM: GLM_GTX_fast_square_root extension included")
#endif
namespace glm
{
/// @addtogroup gtx_fast_square_root
/// @{
/// Faster than the common sqrt function but less accurate.
///
/// @see gtx_fast_square_root extension.
template <typename genType>
GLM_FUNC_DECL genType fastSqrt(genType x);
/// Faster than the common sqrt function but less accurate.
///
/// @see gtx_fast_square_root extension.
template <typename T, precision P, template <typename, precision> class vecType>
GLM_FUNC_DECL vecType<T, P> fastSqrt(vecType<T, P> const & x);
/// Faster than the common inversesqrt function but less accurate.
///
/// @see gtx_fast_square_root extension.
template <typename genType>
GLM_FUNC_DECL genType fastInverseSqrt(genType x);
/// Faster than the common inversesqrt function but less accurate.
///
/// @see gtx_fast_square_root extension.
template <typename T, precision P, template <typename, precision> class vecType>
GLM_FUNC_DECL vecType<T, P> fastInverseSqrt(vecType<T, P> const & x);
/// Faster than the common length function but less accurate.
///
/// @see gtx_fast_square_root extension.
template <typename genType>
GLM_FUNC_DECL genType fastLength(genType x);
/// Faster than the common length function but less accurate.
///
/// @see gtx_fast_square_root extension.
template <typename T, precision P, template <typename, precision> class vecType>
GLM_FUNC_DECL T fastLength(vecType<T, P> const & x);
/// Faster than the common distance function but less accurate.
///
/// @see gtx_fast_square_root extension.
template <typename genType>
GLM_FUNC_DECL genType fastDistance(genType x, genType y);
/// Faster than the common distance function but less accurate.
///
/// @see gtx_fast_square_root extension.
template <typename T, precision P, template <typename, precision> class vecType>
GLM_FUNC_DECL T fastDistance(vecType<T, P> const & x, vecType<T, P> const & y);
/// Faster than the common normalize function but less accurate.
///
/// @see gtx_fast_square_root extension.
template <typename genType>
GLM_FUNC_DECL genType fastNormalize(genType const & x);
/// @}
}// namespace glm
#include "fast_square_root.inl"
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment