Initial Commit

This commit is contained in:
Pierre Cholet 2018-09-12 18:53:34 +02:00
commit 54eaed1ca0
284 changed files with 55022 additions and 0 deletions

View file

@ -0,0 +1,206 @@
/// @ref gtx_associated_min_max
/// @file glm/gtx/associated_min_max.hpp
///
/// @see core (dependence)
/// @see gtx_extented_min_max (dependence)
///
/// @defgroup gtx_associated_min_max GLM_GTX_associated_min_max
/// @ingroup gtx
///
/// @brief Min and max functions that return associated values not the compared onces.
/// <glm/gtx/associated_min_max.hpp> need to be included to use these functionalities.
#pragma once
// Dependency:
#include "../glm.hpp"
#ifndef GLM_ENABLE_EXPERIMENTAL
# error "GLM: GTX_associated_min_max is an experimental extension and may change in the future. Use #define GLM_ENABLE_EXPERIMENTAL before including it, if you really want to use it."
#endif
#if GLM_MESSAGES == GLM_MESSAGES_ENABLED && !defined(GLM_EXT_INCLUDED)
# pragma message("GLM: GLM_GTX_associated_min_max extension included")
#endif
namespace glm
{
/// @addtogroup gtx_associated_min_max
/// @{
/// Minimum comparison between 2 variables and returns 2 associated variable values
/// @see gtx_associated_min_max
template<typename T, typename U, precision P>
GLM_FUNC_DECL U associatedMin(T x, U a, T y, U b);
/// Minimum comparison between 2 variables and returns 2 associated variable values
/// @see gtx_associated_min_max
template<length_t L, typename T, typename U, precision P, template<length_t, typename, precision> class vecType>
GLM_FUNC_DECL vec<2, U, P> associatedMin(
vecType<L, T, P> const& x, vecType<L, U, P> const & a,
vecType<L, T, P> const& y, vecType<L, U, P> const & b);
/// Minimum comparison between 2 variables and returns 2 associated variable values
/// @see gtx_associated_min_max
template<length_t L, typename T, typename U, precision P, template<length_t, typename, precision> class vecType>
GLM_FUNC_DECL vecType<L, U, P> associatedMin(
T x, const vecType<L, U, P>& a,
T y, const vecType<L, U, P>& b);
/// Minimum comparison between 2 variables and returns 2 associated variable values
/// @see gtx_associated_min_max
template<length_t L, typename T, typename U, precision P, template<length_t, typename, precision> class vecType>
GLM_FUNC_DECL vecType<L, U, P> associatedMin(
vecType<L, T, P> const& x, U a,
vecType<L, T, P> const& y, U b);
/// Minimum comparison between 3 variables and returns 3 associated variable values
/// @see gtx_associated_min_max
template<typename T, typename U>
GLM_FUNC_DECL U associatedMin(
T x, U a,
T y, U b,
T z, U c);
/// Minimum comparison between 3 variables and returns 3 associated variable values
/// @see gtx_associated_min_max
template<length_t L, typename T, typename U, precision P, template<length_t, typename, precision> class vecType>
GLM_FUNC_DECL vecType<L, U, P> associatedMin(
vecType<L, T, P> const& x, vecType<L, U, P> const & a,
vecType<L, T, P> const& y, vecType<L, U, P> const & b,
vecType<L, T, P> const& z, vecType<L, U, P> const & c);
/// Minimum comparison between 4 variables and returns 4 associated variable values
/// @see gtx_associated_min_max
template<typename T, typename U>
GLM_FUNC_DECL U associatedMin(
T x, U a,
T y, U b,
T z, U c,
T w, U d);
/// Minimum comparison between 4 variables and returns 4 associated variable values
/// @see gtx_associated_min_max
template<length_t L, typename T, typename U, precision P, template<length_t, typename, precision> class vecType>
GLM_FUNC_DECL vecType<L, U, P> associatedMin(
vecType<L, T, P> const& x, vecType<L, U, P> const & a,
vecType<L, T, P> const& y, vecType<L, U, P> const & b,
vecType<L, T, P> const& z, vecType<L, U, P> const & c,
vecType<L, T, P> const& w, vecType<L, U, P> const & d);
/// Minimum comparison between 4 variables and returns 4 associated variable values
/// @see gtx_associated_min_max
template<length_t L, typename T, typename U, precision P, template<length_t, typename, precision> class vecType>
GLM_FUNC_DECL vecType<L, U, P> associatedMin(
T x, vecType<L, U, P> const & a,
T y, vecType<L, U, P> const & b,
T z, vecType<L, U, P> const & c,
T w, vecType<L, U, P> const & d);
/// Minimum comparison between 4 variables and returns 4 associated variable values
/// @see gtx_associated_min_max
template<length_t L, typename T, typename U, precision P, template<length_t, typename, precision> class vecType>
GLM_FUNC_DECL vecType<L, U, P> associatedMin(
vecType<L, T, P> const& x, U a,
vecType<L, T, P> const& y, U b,
vecType<L, T, P> const& z, U c,
vecType<L, T, P> const& w, U d);
/// Maximum comparison between 2 variables and returns 2 associated variable values
/// @see gtx_associated_min_max
template<typename T, typename U>
GLM_FUNC_DECL U associatedMax(T x, U a, T y, U b);
/// Maximum comparison between 2 variables and returns 2 associated variable values
/// @see gtx_associated_min_max
template<length_t L, typename T, typename U, precision P, template<length_t, typename, precision> class vecType>
GLM_FUNC_DECL vec<2, U, P> associatedMax(
vecType<L, T, P> const& x, vecType<L, U, P> const & a,
vecType<L, T, P> const& y, vecType<L, U, P> const & b);
/// Maximum comparison between 2 variables and returns 2 associated variable values
/// @see gtx_associated_min_max
template<length_t L, typename T, typename U, precision P, template<length_t, typename, precision> class vecType>
GLM_FUNC_DECL vecType<L, T, P> associatedMax(
T x, vecType<L, U, P> const & a,
T y, vecType<L, U, P> const & b);
/// Maximum comparison between 2 variables and returns 2 associated variable values
/// @see gtx_associated_min_max
template<length_t L, typename T, typename U, precision P, template<length_t, typename, precision> class vecType>
GLM_FUNC_DECL vecType<L, U, P> associatedMax(
vecType<L, T, P> const& x, U a,
vecType<L, T, P> const& y, U b);
/// Maximum comparison between 3 variables and returns 3 associated variable values
/// @see gtx_associated_min_max
template<typename T, typename U>
GLM_FUNC_DECL U associatedMax(
T x, U a,
T y, U b,
T z, U c);
/// Maximum comparison between 3 variables and returns 3 associated variable values
/// @see gtx_associated_min_max
template<length_t L, typename T, typename U, precision P, template<length_t, typename, precision> class vecType>
GLM_FUNC_DECL vecType<L, U, P> associatedMax(
vecType<L, T, P> const& x, vecType<L, U, P> const & a,
vecType<L, T, P> const& y, vecType<L, U, P> const & b,
vecType<L, T, P> const& z, vecType<L, U, P> const & c);
/// Maximum comparison between 3 variables and returns 3 associated variable values
/// @see gtx_associated_min_max
template<length_t L, typename T, typename U, precision P, template<length_t, typename, precision> class vecType>
GLM_FUNC_DECL vecType<L, T, P> associatedMax(
T x, vecType<L, U, P> const & a,
T y, vecType<L, U, P> const & b,
T z, vecType<L, U, P> const & c);
/// Maximum comparison between 3 variables and returns 3 associated variable values
/// @see gtx_associated_min_max
template<length_t L, typename T, typename U, precision P, template<length_t, typename, precision> class vecType>
GLM_FUNC_DECL vecType<L, U, P> associatedMax(
vecType<L, T, P> const& x, U a,
vecType<L, T, P> const& y, U b,
vecType<L, T, P> const& z, U c);
/// Maximum comparison between 4 variables and returns 4 associated variable values
/// @see gtx_associated_min_max
template<typename T, typename U>
GLM_FUNC_DECL U associatedMax(
T x, U a,
T y, U b,
T z, U c,
T w, U d);
/// Maximum comparison between 4 variables and returns 4 associated variable values
/// @see gtx_associated_min_max
template<length_t L, typename T, typename U, precision P, template<length_t, typename, precision> class vecType>
GLM_FUNC_DECL vecType<L, U, P> associatedMax(
vecType<L, T, P> const& x, vecType<L, U, P> const & a,
vecType<L, T, P> const& y, vecType<L, U, P> const & b,
vecType<L, T, P> const& z, vecType<L, U, P> const & c,
vecType<L, T, P> const& w, vecType<L, U, P> const & d);
/// Maximum comparison between 4 variables and returns 4 associated variable values
/// @see gtx_associated_min_max
template<length_t L, typename T, typename U, precision P, template<length_t, typename, precision> class vecType>
GLM_FUNC_DECL vecType<L, U, P> associatedMax(
T x, vecType<L, U, P> const & a,
T y, vecType<L, U, P> const & b,
T z, vecType<L, U, P> const & c,
T w, vecType<L, U, P> const & d);
/// Maximum comparison between 4 variables and returns 4 associated variable values
/// @see gtx_associated_min_max
template<length_t L, typename T, typename U, precision P, template<length_t, typename, precision> class vecType>
GLM_FUNC_DECL vecType<L, U, P> associatedMax(
vecType<L, T, P> const& x, U a,
vecType<L, T, P> const& y, U b,
vecType<L, T, P> const& z, U c,
vecType<L, T, P> const& w, U d);
/// @}
} //namespace glm
#include "associated_min_max.inl"

View file

@ -0,0 +1,355 @@
/// @ref gtx_associated_min_max
/// @file glm/gtx/associated_min_max.inl
namespace glm{
// Min comparison between 2 variables
template<typename T, typename U, precision P>
GLM_FUNC_QUALIFIER U associatedMin(T x, U a, T y, U b)
{
return x < y ? a : b;
}
template<length_t L, typename T, typename U, precision P, template<length_t, typename, precision> class vecType>
GLM_FUNC_QUALIFIER vec<2, U, P> associatedMin
(
vecType<L, T, P> const& x, vecType<L, U, P> const & a,
vecType<L, T, P> const& y, vecType<L, U, P> const & b
)
{
vecType<L, U, P> Result(uninitialize);
for(length_t i = 0, n = Result.length(); i < n; ++i)
Result[i] = x[i] < y[i] ? a[i] : b[i];
return Result;
}
template<length_t L, typename T, typename U, precision P, template<length_t, typename, precision> class vecType>
GLM_FUNC_QUALIFIER vecType<L, U, P> associatedMin
(
T x, const vecType<L, U, P>& a,
T y, const vecType<L, U, P>& b
)
{
vecType<L, U, P> Result(uninitialize);
for(length_t i = 0, n = Result.length(); i < n; ++i)
Result[i] = x < y ? a[i] : b[i];
return Result;
}
template<length_t L, typename T, typename U, precision P, template<length_t, typename, precision> class vecType>
GLM_FUNC_QUALIFIER vecType<L, U, P> associatedMin
(
vecType<L, T, P> const& x, U a,
vecType<L, T, P> const& y, U b
)
{
vecType<L, U, P> Result(uninitialize);
for(length_t i = 0, n = Result.length(); i < n; ++i)
Result[i] = x[i] < y[i] ? a : b;
return Result;
}
// Min comparison between 3 variables
template<typename T, typename U>
GLM_FUNC_QUALIFIER U associatedMin
(
T x, U a,
T y, U b,
T z, U c
)
{
U Result = x < y ? (x < z ? a : c) : (y < z ? b : c);
return Result;
}
template<length_t L, typename T, typename U, precision P, template<length_t, typename, precision> class vecType>
GLM_FUNC_QUALIFIER vecType<L, U, P> associatedMin
(
vecType<L, T, P> const& x, vecType<L, U, P> const & a,
vecType<L, T, P> const& y, vecType<L, U, P> const & b,
vecType<L, T, P> const& z, vecType<L, U, P> const & c
)
{
vecType<L, U, P> Result(uninitialize);
for(length_t i = 0, n = Result.length(); i < n; ++i)
Result[i] = x[i] < y[i] ? (x[i] < z[i] ? a[i] : c[i]) : (y[i] < z[i] ? b[i] : c[i]);
return Result;
}
// Min comparison between 4 variables
template<typename T, typename U>
GLM_FUNC_QUALIFIER U associatedMin
(
T x, U a,
T y, U b,
T z, U c,
T w, U d
)
{
T Test1 = min(x, y);
T Test2 = min(z, w);;
U Result1 = x < y ? a : b;
U Result2 = z < w ? c : d;
U Result = Test1 < Test2 ? Result1 : Result2;
return Result;
}
// Min comparison between 4 variables
template<length_t L, typename T, typename U, precision P, template<length_t, typename, precision> class vecType>
GLM_FUNC_QUALIFIER vecType<L, U, P> associatedMin
(
vecType<L, T, P> const& x, vecType<L, U, P> const & a,
vecType<L, T, P> const& y, vecType<L, U, P> const & b,
vecType<L, T, P> const& z, vecType<L, U, P> const & c,
vecType<L, T, P> const& w, vecType<L, U, P> const & d
)
{
vecType<L, U, P> Result(uninitialize);
for(length_t i = 0, n = Result.length(); i < n; ++i)
{
T Test1 = min(x[i], y[i]);
T Test2 = min(z[i], w[i]);
U Result1 = x[i] < y[i] ? a[i] : b[i];
U Result2 = z[i] < w[i] ? c[i] : d[i];
Result[i] = Test1 < Test2 ? Result1 : Result2;
}
return Result;
}
// Min comparison between 4 variables
template<length_t L, typename T, typename U, precision P, template<length_t, typename, precision> class vecType>
GLM_FUNC_QUALIFIER vecType<L, U, P> associatedMin
(
T x, vecType<L, U, P> const & a,
T y, vecType<L, U, P> const & b,
T z, vecType<L, U, P> const & c,
T w, vecType<L, U, P> const & d
)
{
T Test1 = min(x, y);
T Test2 = min(z, w);
vecType<L, U, P> Result(uninitialize);
for(length_t i = 0, n = Result.length(); i < n; ++i)
{
U Result1 = x < y ? a[i] : b[i];
U Result2 = z < w ? c[i] : d[i];
Result[i] = Test1 < Test2 ? Result1 : Result2;
}
return Result;
}
// Min comparison between 4 variables
template<length_t L, typename T, typename U, precision P, template<length_t, typename, precision> class vecType>
GLM_FUNC_QUALIFIER vecType<L, U, P> associatedMin
(
vecType<L, T, P> const& x, U a,
vecType<L, T, P> const& y, U b,
vecType<L, T, P> const& z, U c,
vecType<L, T, P> const& w, U d
)
{
vecType<L, U, P> Result(uninitialize);
for(length_t i = 0, n = Result.length(); i < n; ++i)
{
T Test1 = min(x[i], y[i]);
T Test2 = min(z[i], w[i]);;
U Result1 = x[i] < y[i] ? a : b;
U Result2 = z[i] < w[i] ? c : d;
Result[i] = Test1 < Test2 ? Result1 : Result2;
}
return Result;
}
// Max comparison between 2 variables
template<typename T, typename U>
GLM_FUNC_QUALIFIER U associatedMax(T x, U a, T y, U b)
{
return x > y ? a : b;
}
// Max comparison between 2 variables
template<length_t L, typename T, typename U, precision P, template<length_t, typename, precision> class vecType>
GLM_FUNC_QUALIFIER vec<2, U, P> associatedMax
(
vecType<L, T, P> const& x, vecType<L, U, P> const & a,
vecType<L, T, P> const& y, vecType<L, U, P> const & b
)
{
vecType<L, U, P> Result(uninitialize);
for(length_t i = 0, n = Result.length(); i < n; ++i)
Result[i] = x[i] > y[i] ? a[i] : b[i];
return Result;
}
// Max comparison between 2 variables
template<length_t L, typename T, typename U, precision P, template<length_t, typename, precision> class vecType>
GLM_FUNC_QUALIFIER vecType<L, T, P> associatedMax
(
T x, vecType<L, U, P> const & a,
T y, vecType<L, U, P> const & b
)
{
vecType<L, U, P> Result(uninitialize);
for(length_t i = 0, n = Result.length(); i < n; ++i)
Result[i] = x > y ? a[i] : b[i];
return Result;
}
// Max comparison between 2 variables
template<length_t L, typename T, typename U, precision P, template<length_t, typename, precision> class vecType>
GLM_FUNC_QUALIFIER vecType<L, U, P> associatedMax
(
vecType<L, T, P> const& x, U a,
vecType<L, T, P> const& y, U b
)
{
vecType<L, T, P> Result(uninitialize);
for(length_t i = 0, n = Result.length(); i < n; ++i)
Result[i] = x[i] > y[i] ? a : b;
return Result;
}
// Max comparison between 3 variables
template<typename T, typename U>
GLM_FUNC_QUALIFIER U associatedMax
(
T x, U a,
T y, U b,
T z, U c
)
{
U Result = x > y ? (x > z ? a : c) : (y > z ? b : c);
return Result;
}
// Max comparison between 3 variables
template<length_t L, typename T, typename U, precision P, template<length_t, typename, precision> class vecType>
GLM_FUNC_QUALIFIER vecType<L, U, P> associatedMax
(
vecType<L, T, P> const& x, vecType<L, U, P> const & a,
vecType<L, T, P> const& y, vecType<L, U, P> const & b,
vecType<L, T, P> const& z, vecType<L, U, P> const & c
)
{
vecType<L, U, P> Result(uninitialize);
for(length_t i = 0, n = Result.length(); i < n; ++i)
Result[i] = x[i] > y[i] ? (x[i] > z[i] ? a[i] : c[i]) : (y[i] > z[i] ? b[i] : c[i]);
return Result;
}
// Max comparison between 3 variables
template<length_t L, typename T, typename U, precision P, template<length_t, typename, precision> class vecType>
GLM_FUNC_QUALIFIER vecType<L, T, P> associatedMax
(
T x, vecType<L, U, P> const & a,
T y, vecType<L, U, P> const & b,
T z, vecType<L, U, P> const & c
)
{
vecType<L, U, P> Result(uninitialize);
for(length_t i = 0, n = Result.length(); i < n; ++i)
Result[i] = x > y ? (x > z ? a[i] : c[i]) : (y > z ? b[i] : c[i]);
return Result;
}
// Max comparison between 3 variables
template<length_t L, typename T, typename U, precision P, template<length_t, typename, precision> class vecType>
GLM_FUNC_QUALIFIER vecType<L, U, P> associatedMax
(
vecType<L, T, P> const& x, U a,
vecType<L, T, P> const& y, U b,
vecType<L, T, P> const& z, U c
)
{
vecType<L, T, P> Result(uninitialize);
for(length_t i = 0, n = Result.length(); i < n; ++i)
Result[i] = x[i] > y[i] ? (x[i] > z[i] ? a : c) : (y[i] > z[i] ? b : c);
return Result;
}
// Max comparison between 4 variables
template<typename T, typename U>
GLM_FUNC_QUALIFIER U associatedMax
(
T x, U a,
T y, U b,
T z, U c,
T w, U d
)
{
T Test1 = max(x, y);
T Test2 = max(z, w);;
U Result1 = x > y ? a : b;
U Result2 = z > w ? c : d;
U Result = Test1 > Test2 ? Result1 : Result2;
return Result;
}
// Max comparison between 4 variables
template<length_t L, typename T, typename U, precision P, template<length_t, typename, precision> class vecType>
GLM_FUNC_QUALIFIER vecType<L, U, P> associatedMax
(
vecType<L, T, P> const& x, vecType<L, U, P> const & a,
vecType<L, T, P> const& y, vecType<L, U, P> const & b,
vecType<L, T, P> const& z, vecType<L, U, P> const & c,
vecType<L, T, P> const& w, vecType<L, U, P> const & d
)
{
vecType<L, U, P> Result(uninitialize);
for(length_t i = 0, n = Result.length(); i < n; ++i)
{
T Test1 = max(x[i], y[i]);
T Test2 = max(z[i], w[i]);
U Result1 = x[i] > y[i] ? a[i] : b[i];
U Result2 = z[i] > w[i] ? c[i] : d[i];
Result[i] = Test1 > Test2 ? Result1 : Result2;
}
return Result;
}
// Max comparison between 4 variables
template<length_t L, typename T, typename U, precision P, template<length_t, typename, precision> class vecType>
GLM_FUNC_QUALIFIER vecType<L, U, P> associatedMax
(
T x, vecType<L, U, P> const & a,
T y, vecType<L, U, P> const & b,
T z, vecType<L, U, P> const & c,
T w, vecType<L, U, P> const & d
)
{
T Test1 = max(x, y);
T Test2 = max(z, w);
vecType<L, U, P> Result(uninitialize);
for(length_t i = 0, n = Result.length(); i < n; ++i)
{
U Result1 = x > y ? a[i] : b[i];
U Result2 = z > w ? c[i] : d[i];
Result[i] = Test1 > Test2 ? Result1 : Result2;
}
return Result;
}
// Max comparison between 4 variables
template<length_t L, typename T, typename U, precision P, template<length_t, typename, precision> class vecType>
GLM_FUNC_QUALIFIER vecType<L, U, P> associatedMax
(
vecType<L, T, P> const& x, U a,
vecType<L, T, P> const& y, U b,
vecType<L, T, P> const& z, U c,
vecType<L, T, P> const& w, U d
)
{
vecType<L, U, P> Result(uninitialize);
for(length_t i = 0, n = Result.length(); i < n; ++i)
{
T Test1 = max(x[i], y[i]);
T Test2 = max(z[i], w[i]);;
U Result1 = x[i] > y[i] ? a : b;
U Result2 = z[i] > w[i] ? c : d;
Result[i] = Test1 > Test2 ? Result1 : Result2;
}
return Result;
}
}//namespace glm

98
glm/gtx/bit.hpp Normal file
View file

@ -0,0 +1,98 @@
/// @ref gtx_bit
/// @file glm/gtx/bit.hpp
///
/// @see core (dependence)
///
/// @defgroup gtx_bit GLM_GTX_bit
/// @ingroup gtx
///
/// @brief Allow to perform bit operations on integer values
///
/// <glm/gtx/bit.hpp> need to be included to use these functionalities.
#pragma once
// Dependencies
#include "../gtc/bitfield.hpp"
#ifndef GLM_ENABLE_EXPERIMENTAL
# error "GLM: GLM_GTX_bit is an experimental extension and may change in the future. Use #define GLM_ENABLE_EXPERIMENTAL before including it, if you really want to use it."
#endif
#if GLM_MESSAGES == GLM_MESSAGES_ENABLED && !defined(GLM_EXT_INCLUDED)
# pragma message("GLM: GLM_GTX_bit extension is deprecated, include GLM_GTC_bitfield and GLM_GTC_integer instead")
#endif
namespace glm
{
/// @addtogroup gtx_bit
/// @{
/// @see gtx_bit
template<typename genIUType>
GLM_FUNC_DECL genIUType highestBitValue(genIUType Value);
/// @see gtx_bit
template<typename genIUType>
GLM_FUNC_DECL genIUType lowestBitValue(genIUType Value);
/// Find the highest bit set to 1 in a integer variable and return its value.
///
/// @see gtx_bit
template<length_t L, typename T, precision P, template<length_t, typename, precision> class vecType>
GLM_FUNC_DECL vecType<L, T, P> highestBitValue(vecType<L, T, P> const & value);
/// Return the power of two number which value is just higher the input value.
/// Deprecated, use ceilPowerOfTwo from GTC_round instead
///
/// @see gtc_round
/// @see gtx_bit
template<typename genIUType>
GLM_DEPRECATED GLM_FUNC_DECL genIUType powerOfTwoAbove(genIUType Value);
/// Return the power of two number which value is just higher the input value.
/// Deprecated, use ceilPowerOfTwo from GTC_round instead
///
/// @see gtc_round
/// @see gtx_bit
template<length_t L, typename T, precision P, template<length_t, typename, precision> class vecType>
GLM_DEPRECATED GLM_FUNC_DECL vecType<L, T, P> powerOfTwoAbove(vecType<L, T, P> const & value);
/// Return the power of two number which value is just lower the input value.
/// Deprecated, use floorPowerOfTwo from GTC_round instead
///
/// @see gtc_round
/// @see gtx_bit
template<typename genIUType>
GLM_DEPRECATED GLM_FUNC_DECL genIUType powerOfTwoBelow(genIUType Value);
/// Return the power of two number which value is just lower the input value.
/// Deprecated, use floorPowerOfTwo from GTC_round instead
///
/// @see gtc_round
/// @see gtx_bit
template<length_t L, typename T, precision P, template<length_t, typename, precision> class vecType>
GLM_DEPRECATED GLM_FUNC_DECL vecType<L, T, P> powerOfTwoBelow(vecType<L, T, P> const & value);
/// Return the power of two number which value is the closet to the input value.
/// Deprecated, use roundPowerOfTwo from GTC_round instead
///
/// @see gtc_round
/// @see gtx_bit
template<typename genIUType>
GLM_DEPRECATED GLM_FUNC_DECL genIUType powerOfTwoNearest(genIUType Value);
/// Return the power of two number which value is the closet to the input value.
/// Deprecated, use roundPowerOfTwo from GTC_round instead
///
/// @see gtc_round
/// @see gtx_bit
template<length_t L, typename T, precision P, template<length_t, typename, precision> class vecType>
GLM_DEPRECATED GLM_FUNC_DECL vecType<L, T, P> powerOfTwoNearest(vecType<L, T, P> const & value);
/// @}
} //namespace glm
#include "bit.inl"

93
glm/gtx/bit.inl Normal file
View file

@ -0,0 +1,93 @@
/// @ref gtx_bit
/// @file glm/gtx/bit.inl
namespace glm
{
///////////////////
// highestBitValue
template<typename genIUType>
GLM_FUNC_QUALIFIER genIUType highestBitValue(genIUType Value)
{
genIUType tmp = Value;
genIUType result = genIUType(0);
while(tmp)
{
result = (tmp & (~tmp + 1)); // grab lowest bit
tmp &= ~result; // clear lowest bit
}
return result;
}
template<length_t L, typename T, precision P, template<length_t, typename, precision> class vecType>
GLM_FUNC_QUALIFIER vecType<L, T, P> highestBitValue(vecType<L, T, P> const & v)
{
return detail::functor1<L, T, T, P>::call(highestBitValue, v);
}
///////////////////
// lowestBitValue
template<typename genIUType>
GLM_FUNC_QUALIFIER genIUType lowestBitValue(genIUType Value)
{
return (Value & (~Value + 1));
}
template<length_t L, typename T, precision P, template<length_t, typename, precision> class vecType>
GLM_FUNC_QUALIFIER vecType<L, T, P> lowestBitValue(vecType<L, T, P> const & v)
{
return detail::functor1<L, T, T, P>::call(lowestBitValue, v);
}
///////////////////
// powerOfTwoAbove
template<typename genType>
GLM_FUNC_QUALIFIER genType powerOfTwoAbove(genType value)
{
return isPowerOfTwo(value) ? value : highestBitValue(value) << 1;
}
template<length_t L, typename T, precision P, template<length_t, typename, precision> class vecType>
GLM_FUNC_QUALIFIER vecType<L, T, P> powerOfTwoAbove(vecType<L, T, P> const & v)
{
return detail::functor1<L, T, T, P>::call(powerOfTwoAbove, v);
}
///////////////////
// powerOfTwoBelow
template<typename genType>
GLM_FUNC_QUALIFIER genType powerOfTwoBelow(genType value)
{
return isPowerOfTwo(value) ? value : highestBitValue(value);
}
template<length_t L, typename T, precision P, template<length_t, typename, precision> class vecType>
GLM_FUNC_QUALIFIER vecType<L, T, P> powerOfTwoBelow(vecType<L, T, P> const & v)
{
return detail::functor1<L, T, T, P>::call(powerOfTwoBelow, v);
}
/////////////////////
// powerOfTwoNearest
template<typename genType>
GLM_FUNC_QUALIFIER genType powerOfTwoNearest(genType value)
{
if(isPowerOfTwo(value))
return value;
genType const prev = highestBitValue(value);
genType const next = prev << 1;
return (next - value) < (value - prev) ? next : prev;
}
template<length_t L, typename T, precision P, template<length_t, typename, precision> class vecType>
GLM_FUNC_QUALIFIER vecType<L, T, P> powerOfTwoNearest(vecType<L, T, P> const & v)
{
return detail::functor1<L, T, T, P>::call(powerOfTwoNearest, v);
}
}//namespace glm

49
glm/gtx/closest_point.hpp Normal file
View file

@ -0,0 +1,49 @@
/// @ref gtx_closest_point
/// @file glm/gtx/closest_point.hpp
///
/// @see core (dependence)
///
/// @defgroup gtx_closest_point GLM_GTX_closest_point
/// @ingroup gtx
///
/// @brief Find the point on a straight line which is the closet of a point.
///
/// <glm/gtx/closest_point.hpp> need to be included to use these functionalities.
#pragma once
// Dependency:
#include "../glm.hpp"
#ifndef GLM_ENABLE_EXPERIMENTAL
# error "GLM: GLM_GTX_closest_point is an experimental extension and may change in the future. Use #define GLM_ENABLE_EXPERIMENTAL before including it, if you really want to use it."
#endif
#if GLM_MESSAGES == GLM_MESSAGES_ENABLED && !defined(GLM_EXT_INCLUDED)
# pragma message("GLM: GLM_GTX_closest_point extension included")
#endif
namespace glm
{
/// @addtogroup gtx_closest_point
/// @{
/// Find the point on a straight line which is the closet of a point.
/// @see gtx_closest_point
template<typename T, precision P>
GLM_FUNC_DECL vec<3, T, P> closestPointOnLine(
vec<3, T, P> const & point,
vec<3, T, P> const & a,
vec<3, T, P> const & b);
/// 2d lines work as well
template<typename T, precision P>
GLM_FUNC_DECL vec<2, T, P> closestPointOnLine(
vec<2, T, P> const & point,
vec<2, T, P> const & a,
vec<2, T, P> const & b);
/// @}
}// namespace glm
#include "closest_point.inl"

46
glm/gtx/closest_point.inl Normal file
View file

@ -0,0 +1,46 @@
/// @ref gtx_closest_point
/// @file glm/gtx/closest_point.inl
namespace glm
{
template<typename T, precision P>
GLM_FUNC_QUALIFIER vec<3, T, P> closestPointOnLine
(
vec<3, T, P> const & point,
vec<3, T, P> const & a,
vec<3, T, P> const & b
)
{
T LineLength = distance(a, b);
vec<3, T, P> Vector = point - a;
vec<3, T, P> LineDirection = (b - a) / LineLength;
// Project Vector to LineDirection to get the distance of point from a
T Distance = dot(Vector, LineDirection);
if(Distance <= T(0)) return a;
if(Distance >= LineLength) return b;
return a + LineDirection * Distance;
}
template<typename T, precision P>
GLM_FUNC_QUALIFIER vec<2, T, P> closestPointOnLine
(
vec<2, T, P> const & point,
vec<2, T, P> const & a,
vec<2, T, P> const & b
)
{
T LineLength = distance(a, b);
vec<2, T, P> Vector = point - a;
vec<2, T, P> LineDirection = (b - a) / LineLength;
// Project Vector to LineDirection to get the distance of point from a
T Distance = dot(Vector, LineDirection);
if(Distance <= T(0)) return a;
if(Distance >= LineLength) return b;
return a + LineDirection * Distance;
}
}//namespace glm

View file

@ -0,0 +1,50 @@
/// @ref gtx_color_encoding
/// @file glm/gtx/color_encoding.hpp
///
/// @see core (dependence)
/// @see gtx_color_encoding (dependence)
///
/// @defgroup gtx_color_encoding GLM_GTX_color_encoding
/// @ingroup gtx
///
/// @brief Allow to perform bit operations on integer values
///
/// <glm/gtc/color_encoding.hpp> need to be included to use these functionalities.
#pragma once
// Dependencies
#include "../detail/setup.hpp"
#include "../detail/precision.hpp"
#include "../vec3.hpp"
#include <limits>
#if GLM_MESSAGES == GLM_MESSAGES_ENABLED && !defined(GLM_EXT_INCLUDED)
# pragma message("GLM: GLM_GTC_color_encoding extension included")
#endif
namespace glm
{
/// @addtogroup gtx_color_encoding
/// @{
/// Convert a linear sRGB color to D65 YUV.
template<typename T, precision P>
GLM_FUNC_DECL vec<3, T, P> convertLinearSRGBToD65XYZ(vec<3, T, P> const& ColorLinearSRGB);
/// Convert a linear sRGB color to D50 YUV.
template<typename T, precision P>
GLM_FUNC_DECL vec<3, T, P> convertLinearSRGBToD50XYZ(vec<3, T, P> const& ColorLinearSRGB);
/// Convert a D65 YUV color to linear sRGB.
template<typename T, precision P>
GLM_FUNC_DECL vec<3, T, P> convertD65XYZToLinearSRGB(vec<3, T, P> const& ColorD65XYZ);
/// Convert a D65 YUV color to D50 YUV.
template<typename T, precision P>
GLM_FUNC_DECL vec<3, T, P> convertD65XYZToD50XYZ(vec<3, T, P> const& ColorD65XYZ);
/// @}
} //namespace glm
#include "color_encoding.inl"

View file

@ -0,0 +1,46 @@
/// @ref gtx_color_encoding
/// @file glm/gtx/color_encoding.inl
namespace glm
{
template<typename T, precision P>
GLM_FUNC_QUALIFIER vec<3, T, P> convertLinearSRGBToD65XYZ(vec<3, T, P> const& ColorLinearSRGB)
{
vec<3, T, P> const M(0.490f, 0.17697f, 0.2f);
vec<3, T, P> const N(0.31f, 0.8124f, 0.01063f);
vec<3, T, P> const O(0.490f, 0.01f, 0.99f);
return (M * ColorLinearSRGB + N * ColorLinearSRGB + O * ColorLinearSRGB) * static_cast<T>(5.650675255693055f);
}
template<typename T, precision P>
GLM_FUNC_QUALIFIER vec<3, T, P> convertLinearSRGBToD50XYZ(vec<3, T, P> const& ColorLinearSRGB)
{
vec<3, T, P> const M(0.436030342570117f, 0.222438466210245f, 0.013897440074263f);
vec<3, T, P> const N(0.385101860087134f, 0.716942745571917f, 0.097076381494207f);
vec<3, T, P> const O(0.143067806654203f, 0.060618777416563f, 0.713926257896652f);
return M * ColorLinearSRGB + N * ColorLinearSRGB + O * ColorLinearSRGB;
}
template<typename T, precision P>
GLM_FUNC_QUALIFIER vec<3, T, P> convertD65XYZToLinearSRGB(vec<3, T, P> const& ColorD65XYZ)
{
vec<3, T, P> const M(0.41847f, -0.091169f, 0.0009209f);
vec<3, T, P> const N(-0.15866f, 0.25243f, 0.015708f);
vec<3, T, P> const O(0.0009209f, -0.0025498f, 0.1786f);
return M * ColorD65XYZ + N * ColorD65XYZ + O * ColorD65XYZ;
}
template<typename T, precision P>
GLM_FUNC_QUALIFIER vec<3, T, P> convertD65XYZToD50XYZ(vec<3, T, P> const& ColorD65XYZ)
{
vec<3, T, P> const M(+1.047844353856414f, +0.029549007606644f, -0.009250984365223f);
vec<3, T, P> const N(+0.022898981050086f, +0.990508028941971f, +0.015072338237051f);
vec<3, T, P> const O(-0.050206647741605f, -0.017074711360960f, +0.751717835079977f);
return M * ColorD65XYZ + N * ColorD65XYZ + O * ColorD65XYZ;
}
}//namespace glm

72
glm/gtx/color_space.hpp Normal file
View file

@ -0,0 +1,72 @@
/// @ref gtx_color_space
/// @file glm/gtx/color_space.hpp
///
/// @see core (dependence)
///
/// @defgroup gtx_color_space GLM_GTX_color_space
/// @ingroup gtx
///
/// @brief Related to RGB to HSV conversions and operations.
///
/// <glm/gtx/color_space.hpp> need to be included to use these functionalities.
#pragma once
// Dependency:
#include "../glm.hpp"
#ifndef GLM_ENABLE_EXPERIMENTAL
# error "GLM: GLM_GTX_color_space is an experimental extension and may change in the future. Use #define GLM_ENABLE_EXPERIMENTAL before including it, if you really want to use it."
#endif
#if GLM_MESSAGES == GLM_MESSAGES_ENABLED && !defined(GLM_EXT_INCLUDED)
# pragma message("GLM: GLM_GTX_color_space extension included")
#endif
namespace glm
{
/// @addtogroup gtx_color_space
/// @{
/// Converts a color from HSV color space to its color in RGB color space.
/// @see gtx_color_space
template<typename T, precision P>
GLM_FUNC_DECL vec<3, T, P> rgbColor(
vec<3, T, P> const & hsvValue);
/// Converts a color from RGB color space to its color in HSV color space.
/// @see gtx_color_space
template<typename T, precision P>
GLM_FUNC_DECL vec<3, T, P> hsvColor(
vec<3, T, P> const & rgbValue);
/// Build a saturation matrix.
/// @see gtx_color_space
template<typename T>
GLM_FUNC_DECL mat<4, 4, T, defaultp> saturation(
T const s);
/// Modify the saturation of a color.
/// @see gtx_color_space
template<typename T, precision P>
GLM_FUNC_DECL vec<3, T, P> saturation(
T const s,
vec<3, T, P> const & color);
/// Modify the saturation of a color.
/// @see gtx_color_space
template<typename T, precision P>
GLM_FUNC_DECL vec<4, T, P> saturation(
T const s,
vec<4, T, P> const & color);
/// Compute color luminosity associating ratios (0.33, 0.59, 0.11) to RGB canals.
/// @see gtx_color_space
template<typename T, precision P>
GLM_FUNC_DECL T luminosity(
vec<3, T, P> const & color);
/// @}
}//namespace glm
#include "color_space.inl"

142
glm/gtx/color_space.inl Normal file
View file

@ -0,0 +1,142 @@
/// @ref gtx_color_space
/// @file glm/gtx/color_space.inl
namespace glm
{
template<typename T, precision P>
GLM_FUNC_QUALIFIER vec<3, T, P> rgbColor(const vec<3, T, P>& hsvColor)
{
vec<3, T, P> hsv = hsvColor;
vec<3, T, P> rgbColor;
if(hsv.y == static_cast<T>(0))
// achromatic (grey)
rgbColor = vec<3, T, P>(hsv.z);
else
{
T sector = floor(hsv.x * (T(1) / T(60)));
T frac = (hsv.x * (T(1) / 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 vec<3, T, P> hsvColor(const vec<3, T, P>& rgbColor)
{
vec<3, 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 mat<4, 4, T, defaultp> saturation(T const s)
{
vec<3, T, defaultp> rgbw = vec<3, T, defaultp>(T(0.2126), T(0.7152), T(0.0722));
vec<3, T, defaultp> const col((T(1) - s) * rgbw);
mat<4, 4, T, defaultp> result(T(1));
result[0][0] = col.x + s;
result[0][1] = col.x;
result[0][2] = col.x;
result[1][0] = col.y;
result[1][1] = col.y + s;
result[1][2] = col.y;
result[2][0] = col.z;
result[2][1] = col.z;
result[2][2] = col.z + s;
return result;
}
template<typename T, precision P>
GLM_FUNC_QUALIFIER vec<3, T, P> saturation(const T s, const vec<3, T, P>& color)
{
return vec<3, T, P>(saturation(s) * vec<4, T, P>(color, T(0)));
}
template<typename T, precision P>
GLM_FUNC_QUALIFIER vec<4, T, P> saturation(const T s, const vec<4, T, P>& color)
{
return saturation(s) * color;
}
template<typename T, precision P>
GLM_FUNC_QUALIFIER T luminosity(const vec<3, T, P>& color)
{
const vec<3, T, P> tmp = vec<3, T, P>(0.33, 0.59, 0.11);
return dot(color, tmp);
}
}//namespace glm

View file

@ -0,0 +1,60 @@
/// @ref gtx_color_space_YCoCg
/// @file glm/gtx/color_space_YCoCg.hpp
///
/// @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"
#ifndef GLM_ENABLE_EXPERIMENTAL
# error "GLM: GLM_GTX_color_space_YCoCg is an experimental extension and may change in the future. Use #define GLM_ENABLE_EXPERIMENTAL before including it, if you really want to use it."
#endif
#if GLM_MESSAGES == GLM_MESSAGES_ENABLED && !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 vec<3, T, P> rgb2YCoCg(
vec<3, 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 vec<3, T, P> YCoCg2rgb(
vec<3, 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 vec<3, T, P> rgb2YCoCgR(
vec<3, 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 vec<3, T, P> YCoCgR2rgb(
vec<3, T, P> const & YCoCgColor);
/// @}
}//namespace glm
#include "color_space_YCoCg.inl"

View file

@ -0,0 +1,108 @@
/// @ref gtx_color_space_YCoCg
/// @file glm/gtx/color_space_YCoCg.inl
namespace glm
{
template<typename T, precision P>
GLM_FUNC_QUALIFIER vec<3, T, P> rgb2YCoCg
(
vec<3, T, P> const & rgbColor
)
{
vec<3, 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 vec<3, T, P> YCoCg2rgb
(
vec<3, T, P> const & YCoCgColor
)
{
vec<3, 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, bool isInteger>
class compute_YCoCgR {
public:
static GLM_FUNC_QUALIFIER vec<3, T, P> rgb2YCoCgR
(
vec<3, T, P> const & rgbColor
)
{
vec<3, T, P> result;
result.x/*Y */ = rgbColor.g * static_cast<T>(0.5) + (rgbColor.r + rgbColor.b) * static_cast<T>(0.25);
result.y/*Co*/ = rgbColor.r - rgbColor.b;
result.z/*Cg*/ = rgbColor.g - (rgbColor.r + rgbColor.b) * static_cast<T>(0.5);
return result;
}
static GLM_FUNC_QUALIFIER vec<3, T, P> YCoCgR2rgb
(
vec<3, T, P> const & YCoCgRColor
)
{
vec<3, T, P> result;
T tmp = YCoCgRColor.x - (YCoCgRColor.z * static_cast<T>(0.5));
result.g = YCoCgRColor.z + tmp;
result.b = tmp - (YCoCgRColor.y * static_cast<T>(0.5));
result.r = result.b + YCoCgRColor.y;
return result;
}
};
template<typename T, precision P>
class compute_YCoCgR<T, P, true> {
public:
static GLM_FUNC_QUALIFIER vec<3, T, P> rgb2YCoCgR
(
vec<3, T, P> const & rgbColor
)
{
vec<3, T, P> result;
result.y/*Co*/ = rgbColor.r - rgbColor.b;
T tmp = rgbColor.b + (result.y >> 1);
result.z/*Cg*/ = rgbColor.g - tmp;
result.x/*Y */ = tmp + (result.z >> 1);
return result;
}
static GLM_FUNC_QUALIFIER vec<3, T, P> YCoCgR2rgb
(
vec<3, T, P> const & YCoCgRColor
)
{
vec<3, T, P> result;
T tmp = YCoCgRColor.x - (YCoCgRColor.z >> 1);
result.g = YCoCgRColor.z + tmp;
result.b = tmp - (YCoCgRColor.y >> 1);
result.r = result.b + YCoCgRColor.y;
return result;
}
};
template<typename T, precision P>
GLM_FUNC_QUALIFIER vec<3, T, P> rgb2YCoCgR
(
vec<3, T, P> const & rgbColor
)
{
return compute_YCoCgR<T, P, std::numeric_limits<T>::is_integer>::rgb2YCoCgR(rgbColor);
}
template<typename T, precision P>
GLM_FUNC_QUALIFIER vec<3, T, P> YCoCgR2rgb
(
vec<3, T, P> const & YCoCgRColor
)
{
return compute_YCoCgR<T, P, std::numeric_limits<T>::is_integer>::YCoCgR2rgb(YCoCgRColor);
}
}//namespace glm

56
glm/gtx/common.hpp Normal file
View file

@ -0,0 +1,56 @@
/// @ref gtx_common
/// @file glm/gtx/common.hpp
///
/// @see core (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"
#ifndef GLM_ENABLE_EXPERIMENTAL
# error "GLM: GLM_GTX_common is an experimental extension and may change in the future. Use #define GLM_ENABLE_EXPERIMENTAL before including it, if you really want to use it."
#endif
#if GLM_MESSAGES == GLM_MESSAGES_ENABLED && !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);
/// Similar to 'mod' but with a different rounding and integer support.
/// Returns 'x - y * trunc(x/y)' instead of 'x - y * floor(x/y)'
///
/// @see <a href="http://stackoverflow.com/questions/7610631/glsl-mod-vs-hlsl-fmod">GLSL mod vs HLSL fmod</a>
/// @see <a href="http://www.opengl.org/sdk/docs/manglsl/xhtml/mod.xml">GLSL mod man page</a>
template<length_t L, typename T, precision P, template<length_t, typename, precision> class vecType>
GLM_FUNC_DECL vecType<L, T, P> fmod(vecType<L, T, P> const & v);
/// @}
}//namespace glm
#include "common.inl"

112
glm/gtx/common.inl Normal file
View file

@ -0,0 +1,112 @@
/// @ref gtx_common
/// @file glm/gtx/common.inl
#include <cmath>
namespace glm{
namespace detail
{
template<length_t L, typename T, precision P, template<length_t, typename, precision> class vecType, bool isFloat = true>
struct compute_fmod
{
GLM_FUNC_QUALIFIER static vecType<L, T, P> call(vecType<L, T, P> const & a, vecType<L, T, P> const & b)
{
return detail::functor2<L, T, P>::call(std::fmod, a, b);
}
};
template<length_t L, typename T, precision P, template<length_t, typename, precision> class vecType>
struct compute_fmod<L, T, P, vecType, false>
{
GLM_FUNC_QUALIFIER static vecType<L, T, P> call(vecType<L, T, P> const & a, vecType<L, T, P> const & b)
{
return a % b;
}
};
}//namespace detail
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 vec<1, T, P>::bool_type isdenormal
(
vec<1, T, P> const & x
)
{
GLM_STATIC_ASSERT(std::numeric_limits<T>::is_iec559, "'isdenormal' only accept floating-point inputs");
return typename vec<1, T, P>::bool_type(
isdenormal(x.x));
}
template<typename T, precision P>
GLM_FUNC_QUALIFIER typename vec<2, T, P>::bool_type isdenormal
(
vec<2, T, P> const & x
)
{
GLM_STATIC_ASSERT(std::numeric_limits<T>::is_iec559, "'isdenormal' only accept floating-point inputs");
return typename vec<2, T, P>::bool_type(
isdenormal(x.x),
isdenormal(x.y));
}
template<typename T, precision P>
GLM_FUNC_QUALIFIER typename vec<3, T, P>::bool_type isdenormal
(
vec<3, T, P> const & x
)
{
GLM_STATIC_ASSERT(std::numeric_limits<T>::is_iec559, "'isdenormal' only accept floating-point inputs");
return typename vec<3, T, P>::bool_type(
isdenormal(x.x),
isdenormal(x.y),
isdenormal(x.z));
}
template<typename T, precision P>
GLM_FUNC_QUALIFIER typename vec<4, T, P>::bool_type isdenormal
(
vec<4, T, P> const & x
)
{
GLM_STATIC_ASSERT(std::numeric_limits<T>::is_iec559, "'isdenormal' only accept floating-point inputs");
return typename vec<4, T, P>::bool_type(
isdenormal(x.x),
isdenormal(x.y),
isdenormal(x.z),
isdenormal(x.w));
}
// fmod
template<typename genType>
GLM_FUNC_QUALIFIER genType fmod(genType x, genType y)
{
return fmod(vec<1, genType>(x), y).x;
}
template<length_t L, typename T, precision P, template<length_t, typename, precision> class vecType>
GLM_FUNC_QUALIFIER vecType<L, T, P> fmod(vecType<L, T, P> const & x, T y)
{
return detail::compute_fmod<L, T, P, vecType, std::numeric_limits<T>::is_iec559>::call(x, vecType<L, T, P>(y));
}
template<length_t L, typename T, precision P, template<length_t, typename, precision> class vecType>
GLM_FUNC_QUALIFIER vecType<L, T, P> fmod(vecType<L, T, P> const & x, vecType<L, T, P> const & y)
{
return detail::compute_fmod<L, T, P, vecType, std::numeric_limits<T>::is_iec559>::call(x, y);
}
}//namespace glm

133
glm/gtx/compatibility.hpp Normal file
View file

@ -0,0 +1,133 @@
/// @ref gtx_compatibility
/// @file glm/gtx/compatibility.hpp
///
/// @see core (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"
#ifndef GLM_ENABLE_EXPERIMENTAL
# error "GLM: GLM_GTX_compatibility is an experimental extension and may change in the future. Use #define GLM_ENABLE_EXPERIMENTAL before including it, if you really want to use it."
#endif
#if GLM_MESSAGES == GLM_MESSAGES_ENABLED && !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 vec<2, T, P> lerp(const vec<2, T, P>& x, const vec<2, 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 vec<3, T, P> lerp(const vec<3, T, P>& x, const vec<3, 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 vec<4, T, P> lerp(const vec<4, T, P>& x, const vec<4, 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 vec<2, T, P> lerp(const vec<2, T, P>& x, const vec<2, T, P>& y, const vec<2, 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 vec<3, T, P> lerp(const vec<3, T, P>& x, const vec<3, T, P>& y, const vec<3, 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 vec<4, T, P> lerp(const vec<4, T, P>& x, const vec<4, T, P>& y, const vec<4, 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 vec<2, T, P> saturate(const vec<2, 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 vec<3, T, P> saturate(const vec<3, 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 vec<4, T, P> saturate(const vec<4, 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 vec<2, T, P> atan2(const vec<2, T, P>& x, const vec<2, 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 vec<3, T, P> atan2(const vec<3, T, P>& x, const vec<3, 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 vec<4, T, P> atan2(const vec<4, T, P>& x, const vec<4, 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 vec<1, bool, P> isfinite(const vec<1, 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 vec<2, bool, P> isfinite(const vec<2, 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 vec<3, bool, P> isfinite(const vec<3, 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 vec<4, bool, P> isfinite(const vec<4, 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 vec<2, bool, highp> bool2; //!< \brief boolean type with 2 components. (From GLM_GTX_compatibility extension)
typedef vec<3, bool, highp> bool3; //!< \brief boolean type with 3 components. (From GLM_GTX_compatibility extension)
typedef vec<4, 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 mat<2, 2, bool, highp> bool2x2; //!< \brief boolean matrix with 2 x 2 components. (From GLM_GTX_compatibility extension)
typedef mat<2, 3, bool, highp> bool2x3; //!< \brief boolean matrix with 2 x 3 components. (From GLM_GTX_compatibility extension)
typedef mat<2, 4, bool, highp> bool2x4; //!< \brief boolean matrix with 2 x 4 components. (From GLM_GTX_compatibility extension)
typedef mat<3, 2, bool, highp> bool3x2; //!< \brief boolean matrix with 3 x 2 components. (From GLM_GTX_compatibility extension)
typedef mat<3, 3, bool, highp> bool3x3; //!< \brief boolean matrix with 3 x 3 components. (From GLM_GTX_compatibility extension)
typedef mat<3, 4, bool, highp> bool3x4; //!< \brief boolean matrix with 3 x 4 components. (From GLM_GTX_compatibility extension)
typedef mat<4, 2, bool, highp> bool4x2; //!< \brief boolean matrix with 4 x 2 components. (From GLM_GTX_compatibility extension)
typedef mat<4, 3, bool, highp> bool4x3; //!< \brief boolean matrix with 4 x 3 components. (From GLM_GTX_compatibility extension)
typedef mat<4, 4, 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 vec<2, int, highp> int2; //!< \brief integer vector with 2 components. (From GLM_GTX_compatibility extension)
typedef vec<3, int, highp> int3; //!< \brief integer vector with 3 components. (From GLM_GTX_compatibility extension)
typedef vec<4, 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 mat<2, 2, int, highp> int2x2; //!< \brief integer matrix with 2 x 2 components. (From GLM_GTX_compatibility extension)
typedef mat<2, 3, int, highp> int2x3; //!< \brief integer matrix with 2 x 3 components. (From GLM_GTX_compatibility extension)
typedef mat<2, 4, int, highp> int2x4; //!< \brief integer matrix with 2 x 4 components. (From GLM_GTX_compatibility extension)
typedef mat<3, 2, int, highp> int3x2; //!< \brief integer matrix with 3 x 2 components. (From GLM_GTX_compatibility extension)
typedef mat<3, 3, int, highp> int3x3; //!< \brief integer matrix with 3 x 3 components. (From GLM_GTX_compatibility extension)
typedef mat<3, 4, int, highp> int3x4; //!< \brief integer matrix with 3 x 4 components. (From GLM_GTX_compatibility extension)
typedef mat<4, 2, int, highp> int4x2; //!< \brief integer matrix with 4 x 2 components. (From GLM_GTX_compatibility extension)
typedef mat<4, 3, int, highp> int4x3; //!< \brief integer matrix with 4 x 3 components. (From GLM_GTX_compatibility extension)
typedef mat<4, 4, 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 vec<2, float, highp> float2; //!< \brief single-precision floating-point vector with 2 components. (From GLM_GTX_compatibility extension)
typedef vec<3, float, highp> float3; //!< \brief single-precision floating-point vector with 3 components. (From GLM_GTX_compatibility extension)
typedef vec<4, 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 mat<2, 2, float, highp> float2x2; //!< \brief single-precision floating-point matrix with 2 x 2 components. (From GLM_GTX_compatibility extension)
typedef mat<2, 3, float, highp> float2x3; //!< \brief single-precision floating-point matrix with 2 x 3 components. (From GLM_GTX_compatibility extension)
typedef mat<2, 4, float, highp> float2x4; //!< \brief single-precision floating-point matrix with 2 x 4 components. (From GLM_GTX_compatibility extension)
typedef mat<3, 2, float, highp> float3x2; //!< \brief single-precision floating-point matrix with 3 x 2 components. (From GLM_GTX_compatibility extension)
typedef mat<3, 3, float, highp> float3x3; //!< \brief single-precision floating-point matrix with 3 x 3 components. (From GLM_GTX_compatibility extension)
typedef mat<3, 4, float, highp> float3x4; //!< \brief single-precision floating-point matrix with 3 x 4 components. (From GLM_GTX_compatibility extension)
typedef mat<4, 2, float, highp> float4x2; //!< \brief single-precision floating-point matrix with 4 x 2 components. (From GLM_GTX_compatibility extension)
typedef mat<4, 3, float, highp> float4x3; //!< \brief single-precision floating-point matrix with 4 x 3 components. (From GLM_GTX_compatibility extension)
typedef mat<4, 4, 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 vec<2, double, highp> double2; //!< \brief double-precision floating-point vector with 2 components. (From GLM_GTX_compatibility extension)
typedef vec<3, double, highp> double3; //!< \brief double-precision floating-point vector with 3 components. (From GLM_GTX_compatibility extension)
typedef vec<4, 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 mat<2, 2, double, highp> double2x2; //!< \brief double-precision floating-point matrix with 2 x 2 components. (From GLM_GTX_compatibility extension)
typedef mat<2, 3, double, highp> double2x3; //!< \brief double-precision floating-point matrix with 2 x 3 components. (From GLM_GTX_compatibility extension)
typedef mat<2, 4, double, highp> double2x4; //!< \brief double-precision floating-point matrix with 2 x 4 components. (From GLM_GTX_compatibility extension)
typedef mat<3, 2, double, highp> double3x2; //!< \brief double-precision floating-point matrix with 3 x 2 components. (From GLM_GTX_compatibility extension)
typedef mat<3, 3, double, highp> double3x3; //!< \brief double-precision floating-point matrix with 3 x 3 components. (From GLM_GTX_compatibility extension)
typedef mat<3, 4, double, highp> double3x4; //!< \brief double-precision floating-point matrix with 3 x 4 components. (From GLM_GTX_compatibility extension)
typedef mat<4, 2, double, highp> double4x2; //!< \brief double-precision floating-point matrix with 4 x 2 components. (From GLM_GTX_compatibility extension)
typedef mat<4, 3, double, highp> double4x3; //!< \brief double-precision floating-point matrix with 4 x 3 components. (From GLM_GTX_compatibility extension)
typedef mat<4, 4, double, highp> double4x4; //!< \brief double-precision floating-point matrix with 4 x 4 components. (From GLM_GTX_compatibility extension)
/// @}
}//namespace glm
#include "compatibility.inl"

65
glm/gtx/compatibility.inl Normal file
View file

@ -0,0 +1,65 @@
/// @ref gtx_compatibility
/// @file glm/gtx/compatibility.inl
#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
if (std::numeric_limits<genType>::is_integer || std::denorm_absent == std::numeric_limits<genType>::has_denorm)
return std::numeric_limits<genType>::min() <= x && std::numeric_limits<genType>::max() >= x;
else
return -std::numeric_limits<genType>::max() <= x && std::numeric_limits<genType>::max() >= x;
# endif
}
template<typename T, precision P>
GLM_FUNC_QUALIFIER vec<1, bool, P> isfinite(
vec<1, T, P> const & x)
{
return vec<1, bool, P>(
isfinite(x.x));
}
template<typename T, precision P>
GLM_FUNC_QUALIFIER vec<2, bool, P> isfinite(
vec<2, T, P> const & x)
{
return vec<2, bool, P>(
isfinite(x.x),
isfinite(x.y));
}
template<typename T, precision P>
GLM_FUNC_QUALIFIER vec<3, bool, P> isfinite(
vec<3, T, P> const & x)
{
return vec<3, bool, P>(
isfinite(x.x),
isfinite(x.y),
isfinite(x.z));
}
template<typename T, precision P>
GLM_FUNC_QUALIFIER vec<4, bool, P> isfinite(
vec<4, T, P> const & x)
{
return vec<4, bool, P>(
isfinite(x.x),
isfinite(x.y),
isfinite(x.z),
isfinite(x.w));
}
}//namespace glm

View file

@ -0,0 +1,69 @@
/// @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"
#ifndef GLM_ENABLE_EXPERIMENTAL
# error "GLM: GLM_GTX_component_wise is an experimental extension and may change in the future. Use #define GLM_ENABLE_EXPERIMENTAL before including it, if you really want to use it."
#endif
#if GLM_MESSAGES == GLM_MESSAGES_ENABLED && !defined(GLM_EXT_INCLUDED)
# pragma message("GLM: GLM_GTX_component_wise extension included")
#endif
namespace glm
{
/// @addtogroup gtx_component_wise
/// @{
/// Convert an integer vector to a normalized float vector.
/// If the parameter value type is already a floating precision type, the value is passed through.
/// @see gtx_component_wise
template<typename floatType, length_t L, typename T, precision P, template<length_t, typename, precision> class vecType>
GLM_FUNC_DECL vecType<L, floatType, P> compNormalize(vecType<L, T, P> const & v);
/// Convert a normalized float vector to an integer vector.
/// If the parameter value type is already a floating precision type, the value is passed through.
/// @see gtx_component_wise
template<length_t L, typename T, typename floatType, precision P, template<length_t, typename, precision> class vecType>
GLM_FUNC_DECL vecType<L, T, P> compScale(vecType<L, floatType, P> const & v);
/// 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"

128
glm/gtx/component_wise.inl Normal file
View file

@ -0,0 +1,128 @@
/// @ref gtx_component_wise
/// @file glm/gtx/component_wise.inl
#include <limits>
namespace glm{
namespace detail
{
template<length_t L, typename T, typename floatType, precision P, template<length_t, typename, precision> class vecType, bool isInteger, bool signedType>
struct compute_compNormalize
{};
template<length_t L, typename T, typename floatType, precision P, template<length_t, typename, precision> class vecType>
struct compute_compNormalize<L, T, floatType, P, vecType, true, true>
{
GLM_FUNC_QUALIFIER static vecType<L, floatType, P> call(vecType<L, T, P> const & v)
{
floatType const Min = static_cast<floatType>(std::numeric_limits<T>::min());
floatType const Max = static_cast<floatType>(std::numeric_limits<T>::max());
return (vecType<L, floatType, P>(v) - Min) / (Max - Min) * static_cast<floatType>(2) - static_cast<floatType>(1);
}
};
template<length_t L, typename T, typename floatType, precision P, template<length_t, typename, precision> class vecType>
struct compute_compNormalize<L, T, floatType, P, vecType, true, false>
{
GLM_FUNC_QUALIFIER static vecType<L, floatType, P> call(vecType<L, T, P> const & v)
{
return vecType<L, floatType, P>(v) / static_cast<floatType>(std::numeric_limits<T>::max());
}
};
template<length_t L, typename T, typename floatType, precision P, template<length_t, typename, precision> class vecType>
struct compute_compNormalize<L, T, floatType, P, vecType, false, true>
{
GLM_FUNC_QUALIFIER static vecType<L, floatType, P> call(vecType<L, T, P> const & v)
{
return v;
}
};
template<length_t L, typename T, typename floatType, precision P, template<length_t, typename, precision> class vecType, bool isInteger, bool signedType>
struct compute_compScale
{};
template<length_t L, typename T, typename floatType, precision P, template<length_t, typename, precision> class vecType>
struct compute_compScale<L, T, floatType, P, vecType, true, true>
{
GLM_FUNC_QUALIFIER static vecType<L, T, P> call(vecType<L, floatType, P> const & v)
{
floatType const Max = static_cast<floatType>(std::numeric_limits<T>::max()) + static_cast<floatType>(0.5);
vecType<L, floatType, P> const Scaled(v * Max);
vecType<L, T, P> const Result(Scaled - static_cast<floatType>(0.5));
return Result;
}
};
template<length_t L, typename T, typename floatType, precision P, template<length_t, typename, precision> class vecType>
struct compute_compScale<L, T, floatType, P, vecType, true, false>
{
GLM_FUNC_QUALIFIER static vecType<L, T, P> call(vecType<L, floatType, P> const & v)
{
return vecType<L, T, P>(vecType<L, floatType, P>(v) * static_cast<floatType>(std::numeric_limits<T>::max()));
}
};
template<length_t L, typename T, typename floatType, precision P, template<length_t, typename, precision> class vecType>
struct compute_compScale<L, T, floatType, P, vecType, false, true>
{
GLM_FUNC_QUALIFIER static vecType<L, T, P> call(vecType<L, floatType, P> const & v)
{
return v;
}
};
}//namespace detail
template<typename floatType, length_t L, typename T, precision P, template<length_t, typename, precision> class vecType>
GLM_FUNC_QUALIFIER vecType<L, floatType, P> compNormalize(vecType<L, T, P> const & v)
{
GLM_STATIC_ASSERT(std::numeric_limits<floatType>::is_iec559, "'compNormalize' accepts only floating-point types for 'floatType' template parameter");
return detail::compute_compNormalize<L, T, floatType, P, vecType, std::numeric_limits<T>::is_integer, std::numeric_limits<T>::is_signed>::call(v);
}
template<typename T, length_t L, typename floatType, precision P, template<length_t, typename, precision> class vecType>
GLM_FUNC_QUALIFIER vecType<L, T, P> compScale(vecType<L, floatType, P> const & v)
{
GLM_STATIC_ASSERT(std::numeric_limits<floatType>::is_iec559, "'compScale' accepts only floating-point types for 'floatType' template parameter");
return detail::compute_compScale<L, T, floatType, P, vecType, std::numeric_limits<T>::is_integer, std::numeric_limits<T>::is_signed>::call(v);
}
template<length_t L, typename T, precision P, template<length_t, typename, precision> class vecType>
GLM_FUNC_QUALIFIER T compAdd(vecType<L, T, P> const & v)
{
T Result(0);
for(length_t i = 0, n = v.length(); i < n; ++i)
Result += v[i];
return Result;
}
template<length_t L, typename T, precision P, template<length_t, typename, precision> class vecType>
GLM_FUNC_QUALIFIER T compMul(vecType<L, T, P> const & v)
{
T Result(1);
for(length_t i = 0, n = v.length(); i < n; ++i)
Result *= v[i];
return Result;
}
template<length_t L, typename T, precision P, template<length_t, typename, precision> class vecType>
GLM_FUNC_QUALIFIER T compMin(vecType<L, T, P> const & v)
{
T Result(v[0]);
for(length_t i = 1, n = v.length(); i < n; ++i)
Result = min(Result, v[i]);
return Result;
}
template<length_t L, typename T, precision P, template<length_t, typename, precision> class vecType>
GLM_FUNC_QUALIFIER T compMax(vecType<L, T, P> const & v)
{
T Result(v[0]);
for(length_t i = 1, n = v.length(); i < n; ++i)
Result = max(Result, v[i]);
return Result;
}
}//namespace glm

269
glm/gtx/dual_quaternion.hpp Normal file
View file

@ -0,0 +1,269 @@
/// @ref gtx_dual_quaternion
/// @file glm/gtx/dual_quaternion.hpp
/// @author Maksim Vorobiev (msomeone@gmail.com)
///
/// @see core (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"
#ifndef GLM_ENABLE_EXPERIMENTAL
# error "GLM: GLM_GTX_dual_quaternion is an experimental extension and may change in the future. Use #define GLM_ENABLE_EXPERIMENTAL before including it, if you really want to use it."
#endif
#if GLM_MESSAGES == GLM_MESSAGES_ENABLED && !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 = defaultp>
struct tdualquat
{
// -- Implementation detail --
typedef T value_type;
typedef glm::tquat<T, P> part_type;
// -- Data --
glm::tquat<T, P> real, dual;
// -- Component accesses --
typedef length_t length_type;
/// Return the count of components of a dual quaternion
GLM_FUNC_DECL static length_type length(){return 2;}
GLM_FUNC_DECL part_type & operator[](length_type i);
GLM_FUNC_DECL part_type const & operator[](length_type i) const;
// -- Implicit basic constructors --
GLM_FUNC_DECL GLM_CONSTEXPR tdualquat() GLM_DEFAULT_CTOR;
GLM_FUNC_DECL GLM_CONSTEXPR tdualquat(tdualquat<T, P> const & d) GLM_DEFAULT;
template<precision Q>
GLM_FUNC_DECL GLM_CONSTEXPR tdualquat(tdualquat<T, Q> const & d);
// -- Explicit basic constructors --
GLM_FUNC_DECL GLM_CONSTEXPR_CTOR explicit tdualquat(ctor);
GLM_FUNC_DECL GLM_CONSTEXPR tdualquat(tquat<T, P> const & real);
GLM_FUNC_DECL GLM_CONSTEXPR tdualquat(tquat<T, P> const & orientation, vec<3, T, P> const & translation);
GLM_FUNC_DECL GLM_CONSTEXPR tdualquat(tquat<T, P> const & real, tquat<T, P> const & dual);
// -- Conversion constructors --
template<typename U, precision Q>
GLM_FUNC_DECL GLM_CONSTEXPR GLM_EXPLICIT tdualquat(tdualquat<U, Q> const & q);
GLM_FUNC_DECL GLM_EXPLICIT tdualquat(mat<2, 4, T, P> const & holder_mat);
GLM_FUNC_DECL GLM_EXPLICIT tdualquat(mat<3, 4, T, P> const & aug_mat);
// -- Unary arithmetic operators --
GLM_FUNC_DECL tdualquat<T, P> & operator=(tdualquat<T, P> const & m) GLM_DEFAULT;
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);
};
// -- Unary bit operators --
template<typename T, precision P>
GLM_FUNC_DECL tdualquat<T, P> operator+(tdualquat<T, P> const & q);
template<typename T, precision P>
GLM_FUNC_DECL tdualquat<T, P> operator-(tdualquat<T, P> const & q);
// -- Binary operators --
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 vec<3, T, P> operator*(tdualquat<T, P> const & q, vec<3, T, P> const & v);
template<typename T, precision P>
GLM_FUNC_DECL vec<3, T, P> operator*(vec<3, T, P> const & v, tdualquat<T, P> const & q);
template<typename T, precision P>
GLM_FUNC_DECL vec<4, T, P> operator*(tdualquat<T, P> const & q, vec<4, T, P> const & v);
template<typename T, precision P>
GLM_FUNC_DECL vec<4, T, P> operator*(vec<4, T, P> const & v, 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);
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);
// -- Boolean operators --
template<typename T, precision P>
GLM_FUNC_DECL bool operator==(tdualquat<T, P> const & q1, tdualquat<T, P> const & q2);
template<typename T, precision P>
GLM_FUNC_DECL bool operator!=(tdualquat<T, P> const & q1, tdualquat<T, P> const & q2);
/// 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 mat<2, 4, 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 mat<3, 4, 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(mat<2, 4, 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(mat<3, 4, 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"

351
glm/gtx/dual_quaternion.inl Normal file
View file

@ -0,0 +1,351 @@
/// @ref gtx_dual_quaternion
/// @file glm/gtx/dual_quaternion.inl
#include "../geometric.hpp"
#include <limits>
namespace glm
{
// -- Component accesses --
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 && i < this->length());
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 && i < this->length());
return (&real)[i];
}
// -- Implicit basic constructors --
# if !GLM_HAS_DEFAULTED_FUNCTIONS || !defined(GLM_FORCE_NO_CTOR_INIT)
template<typename T, precision P>
GLM_FUNC_QUALIFIER GLM_CONSTEXPR tdualquat<T, P>::tdualquat()
# ifndef GLM_FORCE_NO_CTOR_INIT
: real(tquat<T, P>())
, dual(tquat<T, P>(0, 0, 0, 0))
# endif
{}
# endif
# if !GLM_HAS_DEFAULTED_FUNCTIONS
template<typename T, precision P>
GLM_FUNC_QUALIFIER GLM_CONSTEXPR tdualquat<T, P>::tdualquat(tdualquat<T, P> const & d)
: real(d.real)
, dual(d.dual)
{}
# endif//!GLM_HAS_DEFAULTED_FUNCTIONS
template<typename T, precision P>
template<precision Q>
GLM_FUNC_QUALIFIER GLM_CONSTEXPR 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 GLM_CONSTEXPR_CTOR tdualquat<T, P>::tdualquat(ctor)
{}
template<typename T, precision P>
GLM_FUNC_QUALIFIER GLM_CONSTEXPR 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 GLM_CONSTEXPR tdualquat<T, P>::tdualquat(tquat<T, P> const & q, vec<3, 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 GLM_CONSTEXPR tdualquat<T, P>::tdualquat(tquat<T, P> const & r, tquat<T, P> const & d)
: real(r), dual(d)
{}
// -- Conversion constructors --
template<typename T, precision P>
template<typename U, precision Q>
GLM_FUNC_QUALIFIER GLM_CONSTEXPR 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(mat<2, 4, T, P> const & m)
{
*this = dualquat_cast(m);
}
template<typename T, precision P>
GLM_FUNC_QUALIFIER tdualquat<T, P>::tdualquat(mat<3, 4, T, P> const & m)
{
*this = dualquat_cast(m);
}
// -- Unary arithmetic operators --
# if !GLM_HAS_DEFAULTED_FUNCTIONS
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;
}
# endif//!GLM_HAS_DEFAULTED_FUNCTIONS
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;
}
// -- Unary bit operators --
template<typename T, precision P>
GLM_FUNC_QUALIFIER tdualquat<T, P> operator+(tdualquat<T, P> const & q)
{
return q;
}
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);
}
// -- Binary operators --
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);
}
template<typename T, precision P>
GLM_FUNC_QUALIFIER vec<3, T, P> operator*(tdualquat<T, P> const & q, vec<3, T, P> const & v)
{
vec<3, T, P> const real_v3(q.real.x,q.real.y,q.real.z);
vec<3, 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 vec<3, T, P> operator*(vec<3, T, P> const & v, tdualquat<T, P> const & q)
{
return glm::inverse(q) * v;
}
template<typename T, precision P>
GLM_FUNC_QUALIFIER vec<4, T, P> operator*(tdualquat<T, P> const & q, vec<4, T, P> const & v)
{
return vec<4, T, P>(q * vec<3, T, P>(v), v.w);
}
template<typename T, precision P>
GLM_FUNC_QUALIFIER vec<4, T, P> operator*(vec<4, 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);
}
// -- Operations --
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 mat<2, 4, T, P> mat2x4_cast(tdualquat<T, P> const & x)
{
return mat<2, 4, 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 mat<3, 4, 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;
vec<4, 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));
vec<4, 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));
vec<4, 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 mat<3, 4, T, P>(a, b, c);
}
template<typename T, precision P>
GLM_FUNC_QUALIFIER tdualquat<T, P> dualquat_cast(mat<2, 4, 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(mat<3, 4, 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

146
glm/gtx/euler_angles.hpp Normal file
View file

@ -0,0 +1,146 @@
/// @ref gtx_euler_angles
/// @file glm/gtx/euler_angles.hpp
///
/// @see core (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"
#ifndef GLM_ENABLE_EXPERIMENTAL
# error "GLM: GLM_GTX_euler_angles is an experimental extension and may change in the future. Use #define GLM_ENABLE_EXPERIMENTAL before including it, if you really want to use it."
#endif
#if GLM_MESSAGES == GLM_MESSAGES_ENABLED && !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 mat<4, 4, 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 mat<4, 4, 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 mat<4, 4, 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 mat<4, 4, 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 mat<4, 4, 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 mat<4, 4, 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 mat<4, 4, 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 mat<4, 4, 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 mat<4, 4, T, defaultp> eulerAngleZY(
T const & angleZ,
T const & angleY);
/// Creates a 3D 4 * 4 homogeneous rotation matrix from euler angles (X * Y * Z).
/// @see gtx_euler_angles
template<typename T>
GLM_FUNC_DECL mat<4, 4, T, defaultp> eulerAngleXYZ(
T const & t1,
T const & t2,
T const & t3);
/// Creates a 3D 4 * 4 homogeneous rotation matrix from euler angles (Y * X * Z).
/// @see gtx_euler_angles
template<typename T>
GLM_FUNC_DECL mat<4, 4, 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 mat<4, 4, 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 mat<2, 2, 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 mat<3, 3, 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 mat<3, 3, T, P> orientate3(vec<3, 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 mat<4, 4, T, P> orientate4(vec<3, T, P> const & angles);
/// Extracts the (X * Y * Z) Euler angles from the rotation matrix M
/// @see gtx_euler_angles
template<typename T>
GLM_FUNC_DECL void extractEulerAngleXYZ(mat<4, 4, T, defaultp> const & M,
T & t1,
T & t2,
T & t3);
/// @}
}//namespace glm
#include "euler_angles.inl"

312
glm/gtx/euler_angles.inl Normal file
View file

@ -0,0 +1,312 @@
/// @ref gtx_euler_angles
/// @file glm/gtx/euler_angles.inl
#include "compatibility.hpp" // glm::atan2
namespace glm
{
template<typename T>
GLM_FUNC_QUALIFIER mat<4, 4, T, defaultp> eulerAngleX
(
T const & angleX
)
{
T cosX = glm::cos(angleX);
T sinX = glm::sin(angleX);
return mat<4, 4, 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 mat<4, 4, T, defaultp> eulerAngleY
(
T const & angleY
)
{
T cosY = glm::cos(angleY);
T sinY = glm::sin(angleY);
return mat<4, 4, 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 mat<4, 4, T, defaultp> eulerAngleZ
(
T const & angleZ
)
{
T cosZ = glm::cos(angleZ);
T sinZ = glm::sin(angleZ);
return mat<4, 4, 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 mat<4, 4, 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 mat<4, 4, 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 mat<4, 4, 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 mat<4, 4, 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 mat<4, 4, T, defaultp> eulerAngleXZ
(
T const & angleX,
T const & angleZ
)
{
return eulerAngleX(angleX) * eulerAngleZ(angleZ);
}
template<typename T>
GLM_FUNC_QUALIFIER mat<4, 4, T, defaultp> eulerAngleZX
(
T const & angleZ,
T const & angleX
)
{
return eulerAngleZ(angleZ) * eulerAngleX(angleX);
}
template<typename T>
GLM_FUNC_QUALIFIER mat<4, 4, T, defaultp> eulerAngleYZ
(
T const & angleY,
T const & angleZ
)
{
return eulerAngleY(angleY) * eulerAngleZ(angleZ);
}
template<typename T>
GLM_FUNC_QUALIFIER mat<4, 4, T, defaultp> eulerAngleZY
(
T const & angleZ,
T const & angleY
)
{
return eulerAngleZ(angleZ) * eulerAngleY(angleY);
}
template<typename T>
GLM_FUNC_QUALIFIER mat<4, 4, T, defaultp> eulerAngleXYZ
(
T const & t1,
T const & t2,
T const & t3
)
{
T c1 = glm::cos(-t1);
T c2 = glm::cos(-t2);
T c3 = glm::cos(-t3);
T s1 = glm::sin(-t1);
T s2 = glm::sin(-t2);
T s3 = glm::sin(-t3);
mat<4, 4, T, defaultp> Result;
Result[0][0] = c2 * c3;
Result[0][1] =-c1 * s3 + s1 * s2 * c3;
Result[0][2] = s1 * s3 + c1 * s2 * c3;
Result[0][3] = static_cast<T>(0);
Result[1][0] = c2 * s3;
Result[1][1] = c1 * c3 + s1 * s2 * s3;
Result[1][2] =-s1 * c3 + c1 * s2 * s3;
Result[1][3] = static_cast<T>(0);
Result[2][0] =-s2;
Result[2][1] = s1 * c2;
Result[2][2] = c1 * c2;
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 mat<4, 4, 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);
mat<4, 4, 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 mat<4, 4, 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);
mat<4, 4, 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 mat<2, 2, T, defaultp> orientate2
(
T const & angle
)
{
T c = glm::cos(angle);
T s = glm::sin(angle);
mat<2, 2, 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 mat<3, 3, T, defaultp> orientate3
(
T const & angle
)
{
T c = glm::cos(angle);
T s = glm::sin(angle);
mat<3, 3, 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 mat<3, 3, T, P> orientate3
(
vec<3, T, P> const & angles
)
{
return mat<3, 3, T, P>(yawPitchRoll(angles.z, angles.x, angles.y));
}
template<typename T, precision P>
GLM_FUNC_QUALIFIER mat<4, 4, T, P> orientate4
(
vec<3, T, P> const & angles
)
{
return yawPitchRoll(angles.z, angles.x, angles.y);
}
template<typename T>
GLM_FUNC_DECL void extractEulerAngleXYZ(mat<4, 4, T, defaultp> const & M,
T & t1,
T & t2,
T & t3)
{
float T1 = glm::atan2<T, defaultp>(M[2][1], M[2][2]);
float C2 = glm::sqrt(M[0][0]*M[0][0] + M[1][0]*M[1][0]);
float T2 = glm::atan2<T, defaultp>(-M[2][0], C2);
float S1 = glm::sin(T1);
float C1 = glm::cos(T1);
float T3 = glm::atan2<T, defaultp>(S1*M[0][2] - C1*M[0][1], C1*M[1][1] - S1*M[1][2 ]);
t1 = -T1;
t2 = -T2;
t3 = -T3;
}
}//namespace glm

42
glm/gtx/extend.hpp Normal file
View file

@ -0,0 +1,42 @@
/// @ref gtx_extend
/// @file glm/gtx/extend.hpp
///
/// @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"
#ifndef GLM_ENABLE_EXPERIMENTAL
# error "GLM: GLM_GTX_extend is an experimental extension and may change in the future. Use #define GLM_ENABLE_EXPERIMENTAL before including it, if you really want to use it."
#endif
#if GLM_MESSAGES == GLM_MESSAGES_ENABLED && !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"

49
glm/gtx/extend.inl Normal file
View file

@ -0,0 +1,49 @@
/// @ref gtx_extend
/// @file glm/gtx/extend.inl
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 vec<2, T, P> extend
(
vec<2, T, P> const & Origin,
vec<2, T, P> const & Source,
T const & Distance
)
{
return Origin + (Source - Origin) * Distance;
}
template<typename T, precision P>
GLM_FUNC_QUALIFIER vec<3, T, P> extend
(
vec<3, T, P> const & Origin,
vec<3, T, P> const & Source,
T const & Distance
)
{
return Origin + (Source - Origin) * Distance;
}
template<typename T, precision P>
GLM_FUNC_QUALIFIER vec<4, T, P> extend
(
vec<4, T, P> const & Origin,
vec<4, T, P> const & Source,
T const & Distance
)
{
return Origin + (Source - Origin) * Distance;
}
}//namespace glm

View file

@ -0,0 +1,136 @@
/// @ref gtx_extended_min_max
/// @file glm/gtx/extended_min_max.hpp
///
/// @see core (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"
#ifndef GLM_ENABLE_EXPERIMENTAL
# error "GLM: GLM_GTX_extented_min_max is an experimental extension and may change in the future. Use #define GLM_ENABLE_EXPERIMENTAL before including it, if you really want to use it."
#endif
#if GLM_MESSAGES == GLM_MESSAGES_ENABLED && !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 "extended_min_max.inl"

View file

@ -0,0 +1,140 @@
/// @ref gtx_extended_min_max
/// @file glm/gtx/extended_min_max.inl
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

View file

@ -0,0 +1,95 @@
/// @ref gtx_fast_exponential
/// @file glm/gtx/fast_exponential.hpp
///
/// @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"
#ifndef GLM_ENABLE_EXPERIMENTAL
# error "GLM: GLM_GTX_fast_exponential is an experimental extension and may change in the future. Use #define GLM_ENABLE_EXPERIMENTAL before including it, if you really want to use it."
#endif
#if GLM_MESSAGES == GLM_MESSAGES_ENABLED && !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<length_t L, typename T, precision P, template<length_t, typename, precision> class vecType>
GLM_FUNC_DECL vecType<L, T, P> fastPow(vecType<L, T, P> const & x, vecType<L, 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<length_t L, typename T, precision P, template<length_t, typename, precision> class vecType>
GLM_FUNC_DECL vecType<L, T, P> fastPow(vecType<L, 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<length_t L, typename T, precision P, template<length_t, typename, precision> class vecType>
GLM_FUNC_DECL vecType<L, T, P> fastExp(vecType<L, 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<length_t L, typename T, precision P, template<length_t, typename, precision> class vecType>
GLM_FUNC_DECL vecType<L, T, P> fastLog(vecType<L, 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<length_t L, typename T, precision P, template<length_t, typename, precision> class vecType>
GLM_FUNC_DECL vecType<L, T, P> fastExp2(vecType<L, 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<length_t L, typename T, precision P, template<length_t, typename, precision> class vecType>
GLM_FUNC_DECL vecType<L, T, P> fastLog2(vecType<L, T, P> const & x);
/// @}
}//namespace glm
#include "fast_exponential.inl"

View file

@ -0,0 +1,137 @@
/// @ref gtx_fast_exponential
/// @file glm/gtx/fast_exponential.inl
namespace glm
{
// fastPow:
template<typename genType>
GLM_FUNC_QUALIFIER genType fastPow(genType x, genType y)
{
return exp(y * log(x));
}
template<length_t L, typename T, precision P, template<length_t, typename, precision> class vecType>
GLM_FUNC_QUALIFIER vecType<L, T, P> fastPow(vecType<L, T, P> const & x, vecType<L, 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<length_t L, typename T, precision P, template<length_t, typename, precision> class vecType>
GLM_FUNC_QUALIFIER vecType<L, T, P> fastPow(vecType<L, T, P> const & x, vecType<L, int, P> const & y)
{
vecType<L, T, P> Result(uninitialize);
for(length_t i = 0, n = x.length(); i < n; ++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<length_t L, typename T, precision P, template<length_t, typename, precision> class vecType>
GLM_FUNC_QUALIFIER vecType<L, T, P> fastExp(vecType<L, T, P> const & x)
{
return detail::functor1<L, T, T, P>::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<length_t L, typename T, precision P, template<length_t, typename, precision> class vecType>
GLM_FUNC_QUALIFIER vecType<L, T, P> fastLog(vecType<L, T, P> const & x)
{
return detail::functor1<L, T, T, P>::call(fastLog, x);
}
//fastExp2, ln2 = 0.69314718055994530941723212145818f
template<typename genType>
GLM_FUNC_QUALIFIER genType fastExp2(genType x)
{
return fastExp(0.69314718055994530941723212145818f * x);
}
template<length_t L, typename T, precision P, template<length_t, typename, precision> class vecType>
GLM_FUNC_QUALIFIER vecType<L, T, P> fastExp2(vecType<L, T, P> const & x)
{
return detail::functor1<L, T, T, P>::call(fastExp2, x);
}
// fastLog2, ln2 = 0.69314718055994530941723212145818f
template<typename genType>
GLM_FUNC_QUALIFIER genType fastLog2(genType x)
{
return fastLog(x) / 0.69314718055994530941723212145818f;
}
template<length_t L, typename T, precision P, template<length_t, typename, precision> class vecType>
GLM_FUNC_QUALIFIER vecType<L, T, P> fastLog2(vecType<L, T, P> const & x)
{
return detail::functor1<L, T, T, P>::call(fastLog2, x);
}
}//namespace glm

View file

@ -0,0 +1,92 @@
/// @ref gtx_fast_square_root
/// @file glm/gtx/fast_square_root.hpp
///
/// @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"
#ifndef GLM_ENABLE_EXPERIMENTAL
# error "GLM: GLM_GTX_fast_square_root is an experimental extension and may change in the future. Use #define GLM_ENABLE_EXPERIMENTAL before including it, if you really want to use it."
#endif
#if GLM_MESSAGES == GLM_MESSAGES_ENABLED && !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<length_t L, typename T, precision P, template<length_t, typename, precision> class vecType>
GLM_FUNC_DECL vecType<L, T, P> fastSqrt(vecType<L, 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<length_t L, typename T, precision P, template<length_t, typename, precision> class vecType>
GLM_FUNC_DECL vecType<L, T, P> fastInverseSqrt(vecType<L, 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<length_t L, typename T, precision P, template<length_t, typename, precision> class vecType>
GLM_FUNC_DECL T fastLength(vecType<L, 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<length_t L, typename T, precision P, template<length_t, typename, precision> class vecType>
GLM_FUNC_DECL T fastDistance(vecType<L, T, P> const & x, vecType<L, 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"

View file

@ -0,0 +1,81 @@
/// @ref gtx_fast_square_root
/// @file glm/gtx/fast_square_root.inl
namespace glm
{
// fastSqrt
template<typename genType>
GLM_FUNC_QUALIFIER genType fastSqrt(genType x)
{
GLM_STATIC_ASSERT(std::numeric_limits<genType>::is_iec559, "'fastSqrt' only accept floating-point input");
return genType(1) / fastInverseSqrt(x);
}
template<length_t L, typename T, precision P, template<length_t, typename, precision> class vecType>
GLM_FUNC_QUALIFIER vecType<L, T, P> fastSqrt(vecType<L, T, P> const & x)
{
return detail::functor1<L, T, T, P>::call(fastSqrt, x);
}
// fastInversesqrt
template<typename genType>
GLM_FUNC_QUALIFIER genType fastInverseSqrt(genType x)
{
# ifdef __CUDACC__ // Wordaround for a CUDA compiler bug up to CUDA6
vec<1, T, P> tmp(detail::compute_inversesqrt<tvec1, genType, lowp, detail::is_aligned<lowp>::value>::call(vec<1, genType, lowp>(x)));
return tmp.x;
# else
return detail::compute_inversesqrt<1, genType, highp, detail::is_aligned<highp>::value>::call(vec<1, genType, lowp>(x)).x;
# endif
}
template<length_t L, typename T, precision P, template<length_t, typename, precision> class vecType>
GLM_FUNC_QUALIFIER vecType<L, T, P> fastInverseSqrt(vecType<L, T, P> const & x)
{
return detail::compute_inversesqrt<L, T, P, detail::is_aligned<P>::value>::call(x);
}
// fastLength
template<typename genType>
GLM_FUNC_QUALIFIER genType fastLength(genType x)
{
GLM_STATIC_ASSERT(std::numeric_limits<genType>::is_iec559, "'fastLength' only accept floating-point inputs");
return abs(x);
}
template<length_t L, typename T, precision P, template<length_t, typename, precision> class vecType>
GLM_FUNC_QUALIFIER T fastLength(vecType<L, T, P> const & x)
{
GLM_STATIC_ASSERT(std::numeric_limits<T>::is_iec559, "'fastLength' only accept floating-point inputs");
return fastSqrt(dot(x, x));
}
// fastDistance
template<typename genType>
GLM_FUNC_QUALIFIER genType fastDistance(genType x, genType y)
{
return fastLength(y - x);
}
template<length_t L, typename T, precision P, template<length_t, typename, precision> class vecType>
GLM_FUNC_QUALIFIER T fastDistance(vecType<L, T, P> const & x, vecType<L, T, P> const & y)
{
return fastLength(y - x);
}
// fastNormalize
template<typename genType>
GLM_FUNC_QUALIFIER genType fastNormalize(genType x)
{
return x > genType(0) ? genType(1) : -genType(1);
}
template<length_t L, typename T, precision P, template<length_t, typename, precision> class vecType>
GLM_FUNC_QUALIFIER vecType<L, T, P> fastNormalize(vecType<L, T, P> const & x)
{
return x * fastInverseSqrt(dot(x, x));
}
}//namespace glm

View file

@ -0,0 +1,79 @@
/// @ref gtx_fast_trigonometry
/// @file glm/gtx/fast_trigonometry.hpp
///
/// @see core (dependence)
///
/// @defgroup gtx_fast_trigonometry GLM_GTX_fast_trigonometry
/// @ingroup gtx
///
/// @brief Fast but less accurate implementations of trigonometric functions.
///
/// <glm/gtx/fast_trigonometry.hpp> need to be included to use these functionalities.
#pragma once
// Dependency:
#include "../gtc/constants.hpp"
#ifndef GLM_ENABLE_EXPERIMENTAL
# error "GLM: GLM_GTX_fast_trigonometry is an experimental extension and may change in the future. Use #define GLM_ENABLE_EXPERIMENTAL before including it, if you really want to use it."
#endif
#if GLM_MESSAGES == GLM_MESSAGES_ENABLED && !defined(GLM_EXT_INCLUDED)
# pragma message("GLM: GLM_GTX_fast_trigonometry extension included")
#endif
namespace glm
{
/// @addtogroup gtx_fast_trigonometry
/// @{
/// Wrap an angle to [0 2pi[
/// From GLM_GTX_fast_trigonometry extension.
template<typename T>
GLM_FUNC_DECL T wrapAngle(T angle);
/// Faster than the common sin function but less accurate.
/// From GLM_GTX_fast_trigonometry extension.
template<typename T>
GLM_FUNC_DECL T fastSin(T angle);
/// Faster than the common cos function but less accurate.
/// From GLM_GTX_fast_trigonometry extension.
template<typename T>
GLM_FUNC_DECL T fastCos(T angle);
/// Faster than the common tan function but less accurate.
/// Defined between -2pi and 2pi.
/// From GLM_GTX_fast_trigonometry extension.
template<typename T>
GLM_FUNC_DECL T fastTan(T angle);
/// Faster than the common asin function but less accurate.
/// Defined between -2pi and 2pi.
/// From GLM_GTX_fast_trigonometry extension.
template<typename T>
GLM_FUNC_DECL T fastAsin(T angle);
/// Faster than the common acos function but less accurate.
/// Defined between -2pi and 2pi.
/// From GLM_GTX_fast_trigonometry extension.
template<typename T>
GLM_FUNC_DECL T fastAcos(T angle);
/// Faster than the common atan function but less accurate.
/// Defined between -2pi and 2pi.
/// From GLM_GTX_fast_trigonometry extension.
template<typename T>
GLM_FUNC_DECL T fastAtan(T y, T x);
/// Faster than the common atan function but less accurate.
/// Defined between -2pi and 2pi.
/// From GLM_GTX_fast_trigonometry extension.
template<typename T>
GLM_FUNC_DECL T fastAtan(T angle);
/// @}
}//namespace glm
#include "fast_trigonometry.inl"

View file

@ -0,0 +1,143 @@
/// @ref gtx_fast_trigonometry
/// @file glm/gtx/fast_trigonometry.inl
namespace glm{
namespace detail
{
template<length_t L, typename T, precision P, template<length_t, typename, precision> class vecType>
GLM_FUNC_QUALIFIER vecType<L, T, P> taylorCos(vecType<L, T, P> const & x)
{
return static_cast<T>(1)
- (x * x) * (1.f / 2.f)
+ ((x * x) * (x * x)) * (1.f / 24.f)
- (((x * x) * (x * x)) * (x * x)) * (1.f / 720.f)
+ (((x * x) * (x * x)) * ((x * x) * (x * x))) * (1.f / 40320.f);
}
template<typename T>
GLM_FUNC_QUALIFIER T cos_52s(T x)
{
T const xx(x * x);
return (T(0.9999932946) + xx * (T(-0.4999124376) + xx * (T(0.0414877472) + xx * T(-0.0012712095))));
}
template<length_t L, typename T, precision P, template<length_t, typename, precision> class vecType>
GLM_FUNC_QUALIFIER vecType<L, T, P> cos_52s(vecType<L, T, P> const & x)
{
return detail::functor1<L, T, T, P>::call(cos_52s, x);
}
}//namespace detail
// wrapAngle
template<typename T>
GLM_FUNC_QUALIFIER T wrapAngle(T angle)
{
return abs<T>(mod<T>(angle, two_pi<T>()));
}
template<length_t L, typename T, precision P, template<length_t, typename, precision> class vecType>
GLM_FUNC_QUALIFIER vecType<L, T, P> wrapAngle(vecType<L, T, P> const & x)
{
return detail::functor1<L, T, T, P>::call(wrapAngle, x);
}
// cos
template<typename T>
GLM_FUNC_QUALIFIER T fastCos(T x)
{
T const angle(wrapAngle<T>(x));
if(angle < half_pi<T>())
return detail::cos_52s(angle);
if(angle < pi<T>())
return -detail::cos_52s(pi<T>() - angle);
if(angle < (T(3) * half_pi<T>()))
return -detail::cos_52s(angle - pi<T>());
return detail::cos_52s(two_pi<T>() - angle);
}
template<length_t L, typename T, precision P, template<length_t, typename, precision> class vecType>
GLM_FUNC_QUALIFIER vecType<L, T, P> fastCos(vecType<L, T, P> const & x)
{
return detail::functor1<L, T, T, P>::call(fastCos, x);
}
// sin
template<typename T>
GLM_FUNC_QUALIFIER T fastSin(T x)
{
return fastCos<T>(half_pi<T>() - x);
}
template<length_t L, typename T, precision P, template<length_t, typename, precision> class vecType>
GLM_FUNC_QUALIFIER vecType<L, T, P> fastSin(vecType<L, T, P> const & x)
{
return detail::functor1<L, T, T, P>::call(fastSin, x);
}
// tan
template<typename T>
GLM_FUNC_QUALIFIER T fastTan(T x)
{
return x + (x * x * x * T(0.3333333333)) + (x * x * x * x * x * T(0.1333333333333)) + (x * x * x * x * x * x * x * T(0.0539682539));
}
template<length_t L, typename T, precision P, template<length_t, typename, precision> class vecType>
GLM_FUNC_QUALIFIER vecType<L, T, P> fastTan(vecType<L, T, P> const & x)
{
return detail::functor1<L, T, T, P>::call(fastTan, x);
}
// asin
template<typename T>
GLM_FUNC_QUALIFIER T fastAsin(T x)
{
return x + (x * x * x * T(0.166666667)) + (x * x * x * x * x * T(0.075)) + (x * x * x * x * x * x * x * T(0.0446428571)) + (x * x * x * x * x * x * x * x * x * T(0.0303819444));// + (x * x * x * x * x * x * x * x * x * x * x * T(0.022372159));
}
template<length_t L, typename T, precision P, template<length_t, typename, precision> class vecType>
GLM_FUNC_QUALIFIER vecType<L, T, P> fastAsin(vecType<L, T, P> const & x)
{
return detail::functor1<L, T, T, P>::call(fastAsin, x);
}
// acos
template<typename T>
GLM_FUNC_QUALIFIER T fastAcos(T x)
{
return T(1.5707963267948966192313216916398) - fastAsin(x); //(PI / 2)
}
template<length_t L, typename T, precision P, template<length_t, typename, precision> class vecType>
GLM_FUNC_QUALIFIER vecType<L, T, P> fastAcos(vecType<L, T, P> const & x)
{
return detail::functor1<L, T, T, P>::call(fastAcos, x);
}
// atan
template<typename T>
GLM_FUNC_QUALIFIER T fastAtan(T y, T x)
{
T sgn = sign(y) * sign(x);
return abs(fastAtan(y / x)) * sgn;
}
template<length_t L, typename T, precision P, template<length_t, typename, precision> class vecType>
GLM_FUNC_QUALIFIER vecType<L, T, P> fastAtan(vecType<L, T, P> const & y, vecType<L, T, P> const & x)
{
return detail::functor2<L, T, P>::call(fastAtan, y, x);
}
template<typename T>
GLM_FUNC_QUALIFIER T fastAtan(T x)
{
return x - (x * x * x * T(0.333333333333)) + (x * x * x * x * x * T(0.2)) - (x * x * x * x * x * x * x * T(0.1428571429)) + (x * x * x * x * x * x * x * x * x * T(0.111111111111)) - (x * x * x * x * x * x * x * x * x * x * x * T(0.0909090909));
}
template<length_t L, typename T, precision P, template<length_t, typename, precision> class vecType>
GLM_FUNC_QUALIFIER vecType<L, T, P> fastAtan(vecType<L, T, P> const & x)
{
return detail::functor1<L, T, T, P>::call(fastAtan, x);
}
}//namespace glm

View file

@ -0,0 +1,14 @@
/// @ref gtx_float_normalize
/// @file glm/gtx/float_normalize.inl
#include <limits>
namespace glm
{
template<length_t L, typename T, precision P, template<length_t, typename, precision> class vecType>
GLM_FUNC_QUALIFIER vecType<L, float, P> floatNormalize(vecType<L, T, P> const & v)
{
return vecType<L, float, P>(v) / static_cast<float>(std::numeric_limits<T>::max());
}
}//namespace glm

View file

@ -0,0 +1,52 @@
/// @ref gtx_gradient_paint
/// @file glm/gtx/gradient_paint.hpp
///
/// @see core (dependence)
/// @see gtx_optimum_pow (dependence)
///
/// @defgroup gtx_gradient_paint GLM_GTX_gradient_paint
/// @ingroup gtx
///
/// @brief Functions that return the color of procedural gradient for specific coordinates.
/// <glm/gtx/gradient_paint.hpp> need to be included to use these functionalities.
#pragma once
// Dependency:
#include "../glm.hpp"
#include "../gtx/optimum_pow.hpp"
#ifndef GLM_ENABLE_EXPERIMENTAL
# error "GLM: GLM_GTX_gradient_paint is an experimental extension and may change in the future. Use #define GLM_ENABLE_EXPERIMENTAL before including it, if you really want to use it."
#endif
#if GLM_MESSAGES == GLM_MESSAGES_ENABLED && !defined(GLM_EXT_INCLUDED)
# pragma message("GLM: GLM_GTX_gradient_paint extension included")
#endif
namespace glm
{
/// @addtogroup gtx_gradient_paint
/// @{
/// Return a color from a radial gradient.
/// @see - gtx_gradient_paint
template<typename T, precision P>
GLM_FUNC_DECL T radialGradient(
vec<2, T, P> const & Center,
T const & Radius,
vec<2, T, P> const & Focal,
vec<2, T, P> const & Position);
/// Return a color from a linear gradient.
/// @see - gtx_gradient_paint
template<typename T, precision P>
GLM_FUNC_DECL T linearGradient(
vec<2, T, P> const & Point0,
vec<2, T, P> const & Point1,
vec<2, T, P> const & Position);
/// @}
}// namespace glm
#include "gradient_paint.inl"

View file

@ -0,0 +1,37 @@
/// @ref gtx_gradient_paint
/// @file glm/gtx/gradient_paint.inl
namespace glm
{
template<typename T, precision P>
GLM_FUNC_QUALIFIER T radialGradient
(
vec<2, T, P> const & Center,
T const & Radius,
vec<2, T, P> const & Focal,
vec<2, T, P> const & Position
)
{
vec<2, T, P> F = Focal - Center;
vec<2, T, P> D = Position - Focal;
T Radius2 = pow2(Radius);
T Fx2 = pow2(F.x);
T Fy2 = pow2(F.y);
T Numerator = (D.x * F.x + D.y * F.y) + sqrt(Radius2 * (pow2(D.x) + pow2(D.y)) - pow2(D.x * F.y - D.y * F.x));
T Denominator = Radius2 - (Fx2 + Fy2);
return Numerator / Denominator;
}
template<typename T, precision P>
GLM_FUNC_QUALIFIER T linearGradient
(
vec<2, T, P> const & Point0,
vec<2, T, P> const & Point1,
vec<2, T, P> const & Position
)
{
vec<2, T, P> Dist = Point1 - Point0;
return (Dist.x * (Position.x - Point0.x) + Dist.y * (Position.y - Point0.y)) / glm::dot(Dist, Dist);
}
}//namespace glm

View file

@ -0,0 +1,50 @@
/// @ref gtx_handed_coordinate_space
/// @file glm/gtx/handed_coordinate_space.hpp
///
/// @see core (dependence)
///
/// @defgroup gtx_handed_coordinate_space GLM_GTX_handed_coordinate_space
/// @ingroup gtx
///
/// @brief To know if a set of three basis vectors defines a right or left-handed coordinate system.
///
/// <glm/gtx/handed_coordinate_system.hpp> need to be included to use these functionalities.
#pragma once
// Dependency:
#include "../glm.hpp"
#ifndef GLM_ENABLE_EXPERIMENTAL
# error "GLM: GLM_GTX_handed_coordinate_space is an experimental extension and may change in the future. Use #define GLM_ENABLE_EXPERIMENTAL before including it, if you really want to use it."
#endif
#if GLM_MESSAGES == GLM_MESSAGES_ENABLED && !defined(GLM_EXT_INCLUDED)
# pragma message("GLM: GLM_GTX_handed_coordinate_space extension included")
#endif
namespace glm
{
/// @addtogroup gtx_handed_coordinate_space
/// @{
//! Return if a trihedron right handed or not.
//! From GLM_GTX_handed_coordinate_space extension.
template<typename T, precision P>
GLM_FUNC_DECL bool rightHanded(
vec<3, T, P> const & tangent,
vec<3, T, P> const & binormal,
vec<3, T, P> const & normal);
//! Return if a trihedron left handed or not.
//! From GLM_GTX_handed_coordinate_space extension.
template<typename T, precision P>
GLM_FUNC_DECL bool leftHanded(
vec<3, T, P> const & tangent,
vec<3, T, P> const & binormal,
vec<3, T, P> const & normal);
/// @}
}// namespace glm
#include "handed_coordinate_space.inl"

View file

@ -0,0 +1,27 @@
/// @ref gtx_handed_coordinate_space
/// @file glm/gtx/handed_coordinate_space.inl
namespace glm
{
template<typename T, precision P>
GLM_FUNC_QUALIFIER bool rightHanded
(
vec<3, T, P> const & tangent,
vec<3, T, P> const & binormal,
vec<3, T, P> const & normal
)
{
return dot(cross(normal, tangent), binormal) > T(0);
}
template<typename T, precision P>
GLM_FUNC_QUALIFIER bool leftHanded
(
vec<3, T, P> const & tangent,
vec<3, T, P> const & binormal,
vec<3, T, P> const & normal
)
{
return dot(cross(normal, tangent), binormal) < T(0);
}
}//namespace glm

138
glm/gtx/hash.hpp Normal file
View file

@ -0,0 +1,138 @@
/// @ref gtx_hash
/// @file glm/gtx/hash.hpp
///
/// @see core (dependence)
///
/// @defgroup gtx_hash GLM_GTX_hash
/// @ingroup gtx
///
/// @brief Add std::hash support for glm types
///
/// <glm/gtx/hash.hpp> need to be included to use these functionalities.
#pragma once
#ifndef GLM_ENABLE_EXPERIMENTAL
# error "GLM: GLM_GTX_hash is an experimental extension and may change in the future. Use #define GLM_ENABLE_EXPERIMENTAL before including it, if you really want to use it."
#endif
#include <functional>
#include "../vec2.hpp"
#include "../vec3.hpp"
#include "../vec4.hpp"
#include "../gtc/vec1.hpp"
#include "../gtc/quaternion.hpp"
#include "../gtx/dual_quaternion.hpp"
#include "../mat2x2.hpp"
#include "../mat2x3.hpp"
#include "../mat2x4.hpp"
#include "../mat3x2.hpp"
#include "../mat3x3.hpp"
#include "../mat3x4.hpp"
#include "../mat4x2.hpp"
#include "../mat4x3.hpp"
#include "../mat4x4.hpp"
#if !GLM_HAS_CXX11_STL
# error "GLM_GTX_hash requires C++11 standard library support"
#endif
namespace std
{
template<typename T, glm::precision P>
struct hash<glm::vec<1, T,P> >
{
GLM_FUNC_DECL size_t operator()(glm::vec<1, T, P> const & v) const;
};
template<typename T, glm::precision P>
struct hash<glm::vec<2, T,P> >
{
GLM_FUNC_DECL size_t operator()(glm::vec<2, T, P> const & v) const;
};
template<typename T, glm::precision P>
struct hash<glm::vec<3, T,P> >
{
GLM_FUNC_DECL size_t operator()(glm::vec<3, T, P> const & v) const;
};
template<typename T, glm::precision P>
struct hash<glm::vec<4, T,P> >
{
GLM_FUNC_DECL size_t operator()(glm::vec<4, T, P> const & v) const;
};
template<typename T, glm::precision P>
struct hash<glm::tquat<T,P>>
{
GLM_FUNC_DECL size_t operator()(glm::tquat<T, P> const & q) const;
};
template<typename T, glm::precision P>
struct hash<glm::tdualquat<T,P> >
{
GLM_FUNC_DECL size_t operator()(glm::tdualquat<T,P> const & q) const;
};
template<typename T, glm::precision P>
struct hash<glm::mat<2, 2, T,P> >
{
GLM_FUNC_DECL size_t operator()(glm::mat<2, 2, T,P> const & m) const;
};
template<typename T, glm::precision P>
struct hash<glm::mat<2, 3, T,P> >
{
GLM_FUNC_DECL size_t operator()(glm::mat<2, 3, T,P> const & m) const;
};
template<typename T, glm::precision P>
struct hash<glm::mat<2, 4, T,P> >
{
GLM_FUNC_DECL size_t operator()(glm::mat<2, 4, T,P> const & m) const;
};
template<typename T, glm::precision P>
struct hash<glm::mat<3, 2, T,P> >
{
GLM_FUNC_DECL size_t operator()(glm::mat<3, 2, T,P> const & m) const;
};
template<typename T, glm::precision P>
struct hash<glm::mat<3, 3, T,P> >
{
GLM_FUNC_DECL size_t operator()(glm::mat<3, 3, T,P> const & m) const;
};
template<typename T, glm::precision P>
struct hash<glm::mat<3, 4, T,P> >
{
GLM_FUNC_DECL size_t operator()(glm::mat<3, 4, T,P> const & m) const;
};
template<typename T, glm::precision P>
struct hash<glm::mat<4, 2, T,P> >
{
GLM_FUNC_DECL size_t operator()(glm::mat<4, 2, T,P> const & m) const;
};
template<typename T, glm::precision P>
struct hash<glm::mat<4, 3, T,P> >
{
GLM_FUNC_DECL size_t operator()(glm::mat<4, 3, T,P> const & m) const;
};
template<typename T, glm::precision P>
struct hash<glm::mat<4, 4, T,P> >
{
GLM_FUNC_DECL size_t operator()(glm::mat<4, 4, T,P> const & m) const;
};
} // namespace std
#include "hash.inl"

185
glm/gtx/hash.inl Normal file
View file

@ -0,0 +1,185 @@
/// @ref gtx_hash
/// @file glm/gtx/hash.inl
///
/// @see core (dependence)
///
/// @defgroup gtx_hash GLM_GTX_hash
/// @ingroup gtx
///
/// @brief Add std::hash support for glm types
///
/// <glm/gtx/hash.inl> need to be included to use these functionalities.
namespace glm {
namespace detail
{
GLM_INLINE void hash_combine(size_t &seed, size_t hash)
{
hash += 0x9e3779b9 + (seed << 6) + (seed >> 2);
seed ^= hash;
}
}}
namespace std
{
template<typename T, glm::precision P>
GLM_FUNC_QUALIFIER size_t hash<glm::vec<1, T, P>>::operator()(glm::vec<1, T, P> const & v) const
{
hash<T> hasher;
return hasher(v.x);
}
template<typename T, glm::precision P>
GLM_FUNC_QUALIFIER size_t hash<glm::vec<2, T, P>>::operator()(glm::vec<2, T, P> const & v) const
{
size_t seed = 0;
hash<T> hasher;
glm::detail::hash_combine(seed, hasher(v.x));
glm::detail::hash_combine(seed, hasher(v.y));
return seed;
}
template<typename T, glm::precision P>
GLM_FUNC_QUALIFIER size_t hash<glm::vec<3, T, P>>::operator()(glm::vec<3, T, P> const & v) const
{
size_t seed = 0;
hash<T> hasher;
glm::detail::hash_combine(seed, hasher(v.x));
glm::detail::hash_combine(seed, hasher(v.y));
glm::detail::hash_combine(seed, hasher(v.z));
return seed;
}
template<typename T, glm::precision P>
GLM_FUNC_QUALIFIER size_t hash<glm::vec<4, T, P>>::operator()(glm::vec<4, T, P> const & v) const
{
size_t seed = 0;
hash<T> hasher;
glm::detail::hash_combine(seed, hasher(v.x));
glm::detail::hash_combine(seed, hasher(v.y));
glm::detail::hash_combine(seed, hasher(v.z));
glm::detail::hash_combine(seed, hasher(v.w));
return seed;
}
template<typename T, glm::precision P>
GLM_FUNC_QUALIFIER size_t hash<glm::tquat<T, P>>::operator()(glm::tquat<T,P> const & q) const
{
size_t seed = 0;
hash<T> hasher;
glm::detail::hash_combine(seed, hasher(q.x));
glm::detail::hash_combine(seed, hasher(q.y));
glm::detail::hash_combine(seed, hasher(q.z));
glm::detail::hash_combine(seed, hasher(q.w));
return seed;
}
template<typename T, glm::precision P>
GLM_FUNC_QUALIFIER size_t hash<glm::tdualquat<T, P>>::operator()(glm::tdualquat<T, P> const & q) const
{
size_t seed = 0;
hash<glm::tquat<T, P>> hasher;
glm::detail::hash_combine(seed, hasher(q.real));
glm::detail::hash_combine(seed, hasher(q.dual));
return seed;
}
template<typename T, glm::precision P>
GLM_FUNC_QUALIFIER size_t hash<glm::mat<2, 2, T, P>>::operator()(glm::mat<2, 2, T, P> const& m) const
{
size_t seed = 0;
hash<glm::vec<2, T, P>> hasher;
glm::detail::hash_combine(seed, hasher(m[0]));
glm::detail::hash_combine(seed, hasher(m[1]));
return seed;
}
template<typename T, glm::precision P>
GLM_FUNC_QUALIFIER size_t hash<glm::mat<2, 3, T, P>>::operator()(glm::mat<2, 3, T, P> const& m) const
{
size_t seed = 0;
hash<glm::vec<3, T, P>> hasher;
glm::detail::hash_combine(seed, hasher(m[0]));
glm::detail::hash_combine(seed, hasher(m[1]));
return seed;
}
template<typename T, glm::precision P>
GLM_FUNC_QUALIFIER size_t hash<glm::mat<2, 4, T, P>>::operator()(glm::mat<2, 4, T, P> const& m) const
{
size_t seed = 0;
hash<glm::vec<4, T, P>> hasher;
glm::detail::hash_combine(seed, hasher(m[0]));
glm::detail::hash_combine(seed, hasher(m[1]));
return seed;
}
template<typename T, glm::precision P>
GLM_FUNC_QUALIFIER size_t hash<glm::mat<3, 2, T, P>>::operator()(glm::mat<3, 2, T, P> const& m) const
{
size_t seed = 0;
hash<glm::vec<2, T, P>> hasher;
glm::detail::hash_combine(seed, hasher(m[0]));
glm::detail::hash_combine(seed, hasher(m[1]));
glm::detail::hash_combine(seed, hasher(m[2]));
return seed;
}
template<typename T, glm::precision P>
GLM_FUNC_QUALIFIER size_t hash<glm::mat<3, 3, T, P>>::operator()(glm::mat<3, 3, T, P> const& m) const
{
size_t seed = 0;
hash<glm::vec<3, T, P>> hasher;
glm::detail::hash_combine(seed, hasher(m[0]));
glm::detail::hash_combine(seed, hasher(m[1]));
glm::detail::hash_combine(seed, hasher(m[2]));
return seed;
}
template<typename T, glm::precision P>
GLM_FUNC_QUALIFIER size_t hash<glm::mat<3, 4, T, P>>::operator()(glm::mat<3, 4, T, P> const& m) const
{
size_t seed = 0;
hash<glm::vec<4, T, P>> hasher;
glm::detail::hash_combine(seed, hasher(m[0]));
glm::detail::hash_combine(seed, hasher(m[1]));
glm::detail::hash_combine(seed, hasher(m[2]));
return seed;
}
template<typename T, glm::precision P>
GLM_FUNC_QUALIFIER size_t hash<glm::mat<4, 2, T,P>>::operator()(glm::mat<4, 2, T,P> const & m) const
{
size_t seed = 0;
hash<glm::vec<2, T, P>> hasher;
glm::detail::hash_combine(seed, hasher(m[0]));
glm::detail::hash_combine(seed, hasher(m[1]));
glm::detail::hash_combine(seed, hasher(m[2]));
glm::detail::hash_combine(seed, hasher(m[3]));
return seed;
}
template<typename T, glm::precision P>
GLM_FUNC_QUALIFIER size_t hash<glm::mat<4, 3, T,P>>::operator()(glm::mat<4, 3, T,P> const & m) const
{
size_t seed = 0;
hash<glm::vec<3, T, P>> hasher;
glm::detail::hash_combine(seed, hasher(m[0]));
glm::detail::hash_combine(seed, hasher(m[1]));
glm::detail::hash_combine(seed, hasher(m[2]));
glm::detail::hash_combine(seed, hasher(m[3]));
return seed;
}
template<typename T, glm::precision P>
GLM_FUNC_QUALIFIER size_t hash<glm::mat<4, 4, T,P>>::operator()(glm::mat<4, 4, T, P> const& m) const
{
size_t seed = 0;
hash<glm::vec<4, T, P>> hasher;
glm::detail::hash_combine(seed, hasher(m[0]));
glm::detail::hash_combine(seed, hasher(m[1]));
glm::detail::hash_combine(seed, hasher(m[2]));
glm::detail::hash_combine(seed, hasher(m[3]));
return seed;
}
}

76
glm/gtx/integer.hpp Normal file
View file

@ -0,0 +1,76 @@
/// @ref gtx_integer
/// @file glm/gtx/integer.hpp
///
/// @see core (dependence)
///
/// @defgroup gtx_integer GLM_GTX_integer
/// @ingroup gtx
///
/// @brief Add support for integer for core functions
///
/// <glm/gtx/integer.hpp> need to be included to use these functionalities.
#pragma once
// Dependency:
#include "../glm.hpp"
#include "../gtc/integer.hpp"
#ifndef GLM_ENABLE_EXPERIMENTAL
# error "GLM: GLM_GTX_integer is an experimental extension and may change in the future. Use #define GLM_ENABLE_EXPERIMENTAL before including it, if you really want to use it."
#endif
#if GLM_MESSAGES == GLM_MESSAGES_ENABLED && !defined(GLM_EXT_INCLUDED)
# pragma message("GLM: GLM_GTX_integer extension included")
#endif
namespace glm
{
/// @addtogroup gtx_integer
/// @{
//! Returns x raised to the y power.
//! From GLM_GTX_integer extension.
GLM_FUNC_DECL int pow(int x, int y);
//! Returns the positive square root of x.
//! From GLM_GTX_integer extension.
GLM_FUNC_DECL int sqrt(int x);
//! Returns the floor log2 of x.
//! From GLM_GTX_integer extension.
GLM_FUNC_DECL unsigned int floor_log2(unsigned int x);
//! Modulus. Returns x - y * floor(x / y) for each component in x using the floating point value y.
//! From GLM_GTX_integer extension.
GLM_FUNC_DECL int mod(int x, int y);
//! Return the factorial value of a number (!12 max, integer only)
//! From GLM_GTX_integer extension.
template<typename genType>
GLM_FUNC_DECL genType factorial(genType const & x);
//! 32bit signed integer.
//! From GLM_GTX_integer extension.
typedef signed int sint;
//! Returns x raised to the y power.
//! From GLM_GTX_integer extension.
GLM_FUNC_DECL uint pow(uint x, uint y);
//! Returns the positive square root of x.
//! From GLM_GTX_integer extension.
GLM_FUNC_DECL uint sqrt(uint x);
//! Modulus. Returns x - y * floor(x / y) for each component in x using the floating point value y.
//! From GLM_GTX_integer extension.
GLM_FUNC_DECL uint mod(uint x, uint y);
//! Returns the number of leading zeros.
//! From GLM_GTX_integer extension.
GLM_FUNC_DECL uint nlz(uint x);
/// @}
}//namespace glm
#include "integer.inl"

182
glm/gtx/integer.inl Normal file
View file

@ -0,0 +1,182 @@
/// @ref gtx_integer
/// @file glm/gtx/integer.inl
namespace glm
{
// pow
GLM_FUNC_QUALIFIER int pow(int x, int y)
{
if(y == 0)
return 1;
int result = x;
for(int i = 1; i < y; ++i)
result *= x;
return result;
}
// sqrt: From Christopher J. Musial, An integer square root, Graphics Gems, 1990, page 387
GLM_FUNC_QUALIFIER int sqrt(int x)
{
if(x <= 1) return x;
int NextTrial = x >> 1;
int CurrentAnswer;
do
{
CurrentAnswer = NextTrial;
NextTrial = (NextTrial + x / NextTrial) >> 1;
} while(NextTrial < CurrentAnswer);
return CurrentAnswer;
}
// Henry Gordon Dietz: http://aggregate.org/MAGIC/
namespace detail
{
GLM_FUNC_QUALIFIER unsigned int ones32(unsigned int x)
{
/* 32-bit recursive reduction using SWAR...
but first step is mapping 2-bit values
into sum of 2 1-bit values in sneaky way
*/
x -= ((x >> 1) & 0x55555555);
x = (((x >> 2) & 0x33333333) + (x & 0x33333333));
x = (((x >> 4) + x) & 0x0f0f0f0f);
x += (x >> 8);
x += (x >> 16);
return(x & 0x0000003f);
}
}//namespace detail
// Henry Gordon Dietz: http://aggregate.org/MAGIC/
/*
GLM_FUNC_QUALIFIER unsigned int floor_log2(unsigned int x)
{
x |= (x >> 1);
x |= (x >> 2);
x |= (x >> 4);
x |= (x >> 8);
x |= (x >> 16);
return _detail::ones32(x) >> 1;
}
*/
// mod
GLM_FUNC_QUALIFIER int mod(int x, int y)
{
return x - y * (x / y);
}
// factorial (!12 max, integer only)
template<typename genType>
GLM_FUNC_QUALIFIER genType factorial(genType const & x)
{
genType Temp = x;
genType Result;
for(Result = 1; Temp > 1; --Temp)
Result *= Temp;
return Result;
}
template<typename T, precision P>
GLM_FUNC_QUALIFIER vec<2, T, P> factorial(
vec<2, T, P> const & x)
{
return vec<2, T, P>(
factorial(x.x),
factorial(x.y));
}
template<typename T, precision P>
GLM_FUNC_QUALIFIER vec<3, T, P> factorial(
vec<3, T, P> const & x)
{
return vec<3, T, P>(
factorial(x.x),
factorial(x.y),
factorial(x.z));
}
template<typename T, precision P>
GLM_FUNC_QUALIFIER vec<4, T, P> factorial(
vec<4, T, P> const & x)
{
return vec<4, T, P>(
factorial(x.x),
factorial(x.y),
factorial(x.z),
factorial(x.w));
}
GLM_FUNC_QUALIFIER uint pow(uint x, uint y)
{
uint result = x;
for(uint i = 1; i < y; ++i)
result *= x;
return result;
}
GLM_FUNC_QUALIFIER uint sqrt(uint x)
{
if(x <= 1) return x;
uint NextTrial = x >> 1;
uint CurrentAnswer;
do
{
CurrentAnswer = NextTrial;
NextTrial = (NextTrial + x / NextTrial) >> 1;
} while(NextTrial < CurrentAnswer);
return CurrentAnswer;
}
GLM_FUNC_QUALIFIER uint mod(uint x, uint y)
{
return x - y * (x / y);
}
#if(GLM_COMPILER & (GLM_COMPILER_VC | GLM_COMPILER_GCC))
GLM_FUNC_QUALIFIER unsigned int nlz(unsigned int x)
{
return 31u - findMSB(x);
}
#else
// Hackers Delight: http://www.hackersdelight.org/HDcode/nlz.c.txt
GLM_FUNC_QUALIFIER unsigned int nlz(unsigned int x)
{
int y, m, n;
y = -int(x >> 16); // If left half of x is 0,
m = (y >> 16) & 16; // set n = 16. If left half
n = 16 - m; // is nonzero, set n = 0 and
x = x >> m; // shift x right 16.
// Now x is of the form 0000xxxx.
y = x - 0x100; // If positions 8-15 are 0,
m = (y >> 16) & 8; // add 8 to n and shift x left 8.
n = n + m;
x = x << m;
y = x - 0x1000; // If positions 12-15 are 0,
m = (y >> 16) & 4; // add 4 to n and shift x left 4.
n = n + m;
x = x << m;
y = x - 0x4000; // If positions 14-15 are 0,
m = (y >> 16) & 2; // add 2 to n and shift x left 2.
n = n + m;
x = x << m;
y = x >> 14; // Set y = 0, 1, 2, or 3.
m = y & ~(y >> 1); // Set m = 0, 1, 2, or 2 resp.
return unsigned(n + 2 - m);
}
#endif//(GLM_COMPILER)
}//namespace glm

92
glm/gtx/intersect.hpp Normal file
View file

@ -0,0 +1,92 @@
/// @ref gtx_intersect
/// @file glm/gtx/intersect.hpp
///
/// @see core (dependence)
/// @see gtx_closest_point (dependence)
///
/// @defgroup gtx_intersect GLM_GTX_intersect
/// @ingroup gtx
///
/// @brief Add intersection functions
///
/// <glm/gtx/intersect.hpp> need to be included to use these functionalities.
#pragma once
// Dependency:
#include <cfloat>
#include <limits>
#include "../glm.hpp"
#include "../geometric.hpp"
#include "../gtx/closest_point.hpp"
#include "../gtx/vector_query.hpp"
#ifndef GLM_ENABLE_EXPERIMENTAL
# error "GLM: GLM_GTX_closest_point is an experimental extension and may change in the future. Use #define GLM_ENABLE_EXPERIMENTAL before including it, if you really want to use it."
#endif
#if GLM_MESSAGES == GLM_MESSAGES_ENABLED && !defined(GLM_EXT_INCLUDED)
# pragma message("GLM: GLM_GTX_closest_point extension included")
#endif
namespace glm
{
/// @addtogroup gtx_intersect
/// @{
//! Compute the intersection of a ray and a plane.
//! Ray direction and plane normal must be unit length.
//! From GLM_GTX_intersect extension.
template<typename genType>
GLM_FUNC_DECL bool intersectRayPlane(
genType const & orig, genType const & dir,
genType const & planeOrig, genType const & planeNormal,
typename genType::value_type & intersectionDistance);
//! Compute the intersection of a ray and a triangle.
/// Based om Tomas Möller implementation http://fileadmin.cs.lth.se/cs/Personal/Tomas_Akenine-Moller/raytri/
//! From GLM_GTX_intersect extension.
template<typename T, precision P>
GLM_FUNC_DECL bool intersectRayTriangle(
vec<3, T, P> const& orig, vec<3, T, P> const& dir,
vec<3, T, P> const& v0, vec<3, T, P> const& v1, vec<3, T, P> const& v2,
vec<3, T, P>& baryPosition, T& distance);
//! Compute the intersection of a line and a triangle.
//! From GLM_GTX_intersect extension.
template<typename genType>
GLM_FUNC_DECL bool intersectLineTriangle(
genType const & orig, genType const & dir,
genType const & vert0, genType const & vert1, genType const & vert2,
genType & position);
//! Compute the intersection distance of a ray and a sphere.
//! The ray direction vector is unit length.
//! From GLM_GTX_intersect extension.
template<typename genType>
GLM_FUNC_DECL bool intersectRaySphere(
genType const & rayStarting, genType const & rayNormalizedDirection,
genType const & sphereCenter, typename genType::value_type const sphereRadiusSquered,
typename genType::value_type & intersectionDistance);
//! Compute the intersection of a ray and a sphere.
//! From GLM_GTX_intersect extension.
template<typename genType>
GLM_FUNC_DECL bool intersectRaySphere(
genType const & rayStarting, genType const & rayNormalizedDirection,
genType const & sphereCenter, const typename genType::value_type sphereRadius,
genType & intersectionPosition, genType & intersectionNormal);
//! Compute the intersection of a line and a sphere.
//! From GLM_GTX_intersect extension
template<typename genType>
GLM_FUNC_DECL bool intersectLineSphere(
genType const & point0, genType const & point1,
genType const & sphereCenter, typename genType::value_type sphereRadius,
genType & intersectionPosition1, genType & intersectionNormal1,
genType & intersectionPosition2 = genType(), genType & intersectionNormal2 = genType());
/// @}
}//namespace glm
#include "intersect.inl"

225
glm/gtx/intersect.inl Normal file
View file

@ -0,0 +1,225 @@
/// @ref gtx_intersect
/// @file glm/gtx/intersect.inl
namespace glm
{
template<typename genType>
GLM_FUNC_QUALIFIER bool intersectRayPlane
(
genType const & orig, genType const & dir,
genType const & planeOrig, genType const & planeNormal,
typename genType::value_type & intersectionDistance
)
{
typename genType::value_type d = glm::dot(dir, planeNormal);
typename genType::value_type Epsilon = std::numeric_limits<typename genType::value_type>::epsilon();
if(d < -Epsilon)
{
intersectionDistance = glm::dot(planeOrig - orig, planeNormal) / d;
return true;
}
return false;
}
template<typename T, precision P>
GLM_FUNC_QUALIFIER bool intersectRayTriangle
(
vec<3, T, P> const& orig, vec<3, T, P> const& dir,
vec<3, T, P> const& vert0, vec<3, T, P> const& vert1, vec<3, T, P> const& vert2,
vec<2, T, P>& baryPosition, T& distance
)
{
// find vectors for two edges sharing vert0
vec<3, T, P> const edge1 = vert1 - vert0;
vec<3, T, P> const edge2 = vert2 - vert0;
// begin calculating determinant - also used to calculate U parameter
vec<3, T, P> const p = glm::cross(dir, edge2);
// if determinant is near zero, ray lies in plane of triangle
T const det = glm::dot(edge1, p);
vec<3, T, P> qvec;
if(det > std::numeric_limits<T>::epsilon())
{
// calculate distance from vert0 to ray origin
vec<3, T, P> const tvec = orig - vert0;
// calculate U parameter and test bounds
baryPosition.x = glm::dot(tvec, p);
if(baryPosition.x < static_cast<T>(0) || baryPosition.x > det)
return false;
// prepare to test V parameter
qvec = glm::cross(tvec, edge1);
// calculate V parameter and test bounds
baryPosition.y = glm::dot(dir, qvec);
if((baryPosition.y < static_cast<T>(0)) || ((baryPosition.x + baryPosition.y) > det))
return false;
}
else if(det < -std::numeric_limits<T>::epsilon())
{
// calculate distance from vert0 to ray origin
vec<3, T, P> const tvec = orig - vert0;
// calculate U parameter and test bounds
baryPosition.x = glm::dot(tvec, p);
if((baryPosition.x > static_cast<T>(0)) || (baryPosition.x < det))
return false;
// prepare to test V parameter
qvec = glm::cross(tvec, edge1);
// calculate V parameter and test bounds
baryPosition.y = glm::dot(dir, qvec);
if((baryPosition.y > static_cast<T>(0)) || (baryPosition.x + baryPosition.y < det))
return false;
}
else
return false; // ray is parallel to the plane of the triangle
T inv_det = static_cast<T>(1) / det;
// calculate distance, ray intersects triangle
distance = glm::dot(edge2, qvec) * inv_det;
baryPosition *= inv_det;
return true;
}
/*
typename genType::value_type Epsilon = std::numeric_limits<typename genType::value_type>::epsilon();
if(a < Epsilon && a > -Epsilon)
return false;
typename genType::value_type f = typename genType::value_type(1.0f) / a;
genType s = orig - v0;
baryPosition.x = f * glm::dot(s, p);
if(baryPosition.x < typename genType::value_type(0.0f))
return false;
if(baryPosition.x > typename genType::value_type(1.0f))
return false;
genType q = glm::cross(s, e1);
baryPosition.y = f * glm::dot(dir, q);
if(baryPosition.y < typename genType::value_type(0.0f))
return false;
if(baryPosition.y + baryPosition.x > typename genType::value_type(1.0f))
return false;
baryPosition.z = f * glm::dot(e2, q);
return baryPosition.z >= typename genType::value_type(0.0f);
}
*/
template<typename genType>
GLM_FUNC_QUALIFIER bool intersectLineTriangle
(
genType const & orig, genType const & dir,
genType const & vert0, genType const & vert1, genType const & vert2,
genType & position
)
{
typename genType::value_type Epsilon = std::numeric_limits<typename genType::value_type>::epsilon();
genType edge1 = vert1 - vert0;
genType edge2 = vert2 - vert0;
genType pvec = cross(dir, edge2);
float det = dot(edge1, pvec);
if (det > -Epsilon && det < Epsilon)
return false;
float inv_det = typename genType::value_type(1) / det;
genType tvec = orig - vert0;
position.y = dot(tvec, pvec) * inv_det;
if (position.y < typename genType::value_type(0) || position.y > typename genType::value_type(1))
return false;
genType qvec = cross(tvec, edge1);
position.z = dot(dir, qvec) * inv_det;
if (position.z < typename genType::value_type(0) || position.y + position.z > typename genType::value_type(1))
return false;
position.x = dot(edge2, qvec) * inv_det;
return true;
}
template<typename genType>
GLM_FUNC_QUALIFIER bool intersectRaySphere
(
genType const & rayStarting, genType const & rayNormalizedDirection,
genType const & sphereCenter, const typename genType::value_type sphereRadiusSquered,
typename genType::value_type & intersectionDistance
)
{
typename genType::value_type Epsilon = std::numeric_limits<typename genType::value_type>::epsilon();
genType diff = sphereCenter - rayStarting;
typename genType::value_type t0 = dot(diff, rayNormalizedDirection);
typename genType::value_type dSquared = dot(diff, diff) - t0 * t0;
if( dSquared > sphereRadiusSquered )
{
return false;
}
typename genType::value_type t1 = sqrt( sphereRadiusSquered - dSquared );
intersectionDistance = t0 > t1 + Epsilon ? t0 - t1 : t0 + t1;
return intersectionDistance > Epsilon;
}
template<typename genType>
GLM_FUNC_QUALIFIER bool intersectRaySphere
(
genType const & rayStarting, genType const & rayNormalizedDirection,
genType const & sphereCenter, const typename genType::value_type sphereRadius,
genType & intersectionPosition, genType & intersectionNormal
)
{
typename genType::value_type distance;
if( intersectRaySphere( rayStarting, rayNormalizedDirection, sphereCenter, sphereRadius * sphereRadius, distance ) )
{
intersectionPosition = rayStarting + rayNormalizedDirection * distance;
intersectionNormal = (intersectionPosition - sphereCenter) / sphereRadius;
return true;
}
return false;
}
template<typename genType>
GLM_FUNC_QUALIFIER bool intersectLineSphere
(
genType const & point0, genType const & point1,
genType const & sphereCenter, typename genType::value_type sphereRadius,
genType & intersectionPoint1, genType & intersectionNormal1,
genType & intersectionPoint2, genType & intersectionNormal2
)
{
typename genType::value_type Epsilon = std::numeric_limits<typename genType::value_type>::epsilon();
genType dir = normalize(point1 - point0);
genType diff = sphereCenter - point0;
typename genType::value_type t0 = dot(diff, dir);
typename genType::value_type dSquared = dot(diff, diff) - t0 * t0;
if( dSquared > sphereRadius * sphereRadius )
{
return false;
}
typename genType::value_type t1 = sqrt( sphereRadius * sphereRadius - dSquared );
if( t0 < t1 + Epsilon )
t1 = -t1;
intersectionPoint1 = point0 + dir * (t0 - t1);
intersectionNormal1 = (intersectionPoint1 - sphereCenter) / sphereRadius;
intersectionPoint2 = point0 + dir * (t0 + t1);
intersectionNormal2 = (intersectionPoint2 - sphereCenter) / sphereRadius;
return true;
}
}//namespace glm

201
glm/gtx/io.hpp Normal file
View file

@ -0,0 +1,201 @@
/// @ref gtx_io
/// @file glm/gtx/io.hpp
/// @author Jan P Springer (regnirpsj@gmail.com)
///
/// @see core (dependence)
/// @see gtc_matrix_access (dependence)
/// @see gtc_quaternion (dependence)
///
/// @defgroup gtx_io GLM_GTX_io
/// @ingroup gtx
///
/// @brief std::[w]ostream support for glm types
///
/// std::[w]ostream support for glm types + precision/width/etc. manipulators
/// based on howard hinnant's std::chrono io proposal
/// [http://home.roadrunner.com/~hinnant/bloomington/chrono_io.html]
///
/// <glm/gtx/io.hpp> needs to be included to use these functionalities.
#pragma once
// Dependency:
#include "../glm.hpp"
#include "../gtx/quaternion.hpp"
#ifndef GLM_ENABLE_EXPERIMENTAL
# error "GLM: GLM_GTX_io is an experimental extension and may change in the future. Use #define GLM_ENABLE_EXPERIMENTAL before including it, if you really want to use it."
#endif
#if GLM_MESSAGES == GLM_MESSAGES_ENABLED && !defined(GLM_EXT_INCLUDED)
# pragma message("GLM: GLM_GTX_io extension included")
#endif
#include <iosfwd> // std::basic_ostream<> (fwd)
#include <locale> // std::locale, std::locale::facet, std::locale::id
#include <utility> // std::pair<>
namespace glm
{
/// @addtogroup gtx_io
/// @{
namespace io
{
enum order_type { column_major, row_major};
template<typename CTy>
class format_punct : public std::locale::facet
{
typedef CTy char_type;
public:
static std::locale::id id;
bool formatted;
unsigned precision;
unsigned width;
char_type separator;
char_type delim_left;
char_type delim_right;
char_type space;
char_type newline;
order_type order;
GLM_FUNC_DECL explicit format_punct(size_t a = 0);
GLM_FUNC_DECL explicit format_punct(format_punct const&);
};
template<typename CTy, typename CTr = std::char_traits<CTy> >
class basic_state_saver {
public:
GLM_FUNC_DECL explicit basic_state_saver(std::basic_ios<CTy,CTr>&);
GLM_FUNC_DECL ~basic_state_saver();
private:
typedef ::std::basic_ios<CTy,CTr> state_type;
typedef typename state_type::char_type char_type;
typedef ::std::ios_base::fmtflags flags_type;
typedef ::std::streamsize streamsize_type;
typedef ::std::locale const locale_type;
state_type& state_;
flags_type flags_;
streamsize_type precision_;
streamsize_type width_;
char_type fill_;
locale_type locale_;
GLM_FUNC_DECL basic_state_saver& operator=(basic_state_saver const&);
};
typedef basic_state_saver<char> state_saver;
typedef basic_state_saver<wchar_t> wstate_saver;
template<typename CTy, typename CTr = std::char_traits<CTy> >
class basic_format_saver
{
public:
GLM_FUNC_DECL explicit basic_format_saver(std::basic_ios<CTy,CTr>&);
GLM_FUNC_DECL ~basic_format_saver();
private:
basic_state_saver<CTy> const bss_;
GLM_FUNC_DECL basic_format_saver& operator=(basic_format_saver const&);
};
typedef basic_format_saver<char> format_saver;
typedef basic_format_saver<wchar_t> wformat_saver;
struct precision
{
unsigned value;
GLM_FUNC_DECL explicit precision(unsigned);
};
struct width
{
unsigned value;
GLM_FUNC_DECL explicit width(unsigned);
};
template<typename CTy>
struct delimeter
{
CTy value[3];
GLM_FUNC_DECL explicit delimeter(CTy /* left */, CTy /* right */, CTy /* separator */ = ',');
};
struct order
{
order_type value;
GLM_FUNC_DECL explicit order(order_type);
};
// functions, inlined (inline)
template<typename FTy, typename CTy, typename CTr>
FTy const& get_facet(std::basic_ios<CTy,CTr>&);
template<typename FTy, typename CTy, typename CTr>
std::basic_ios<CTy,CTr>& formatted(std::basic_ios<CTy,CTr>&);
template<typename FTy, typename CTy, typename CTr>
std::basic_ios<CTy,CTr>& unformattet(std::basic_ios<CTy,CTr>&);
template<typename CTy, typename CTr>
std::basic_ostream<CTy, CTr>& operator<<(std::basic_ostream<CTy, CTr>&, precision const&);
template<typename CTy, typename CTr>
std::basic_ostream<CTy, CTr>& operator<<(std::basic_ostream<CTy, CTr>&, width const&);
template<typename CTy, typename CTr>
std::basic_ostream<CTy, CTr>& operator<<(std::basic_ostream<CTy, CTr>&, delimeter<CTy> const&);
template<typename CTy, typename CTr>
std::basic_ostream<CTy, CTr>& operator<<(std::basic_ostream<CTy, CTr>&, order const&);
}//namespace io
template<typename CTy, typename CTr, typename T, precision P>
GLM_FUNC_DECL std::basic_ostream<CTy,CTr>& operator<<(std::basic_ostream<CTy,CTr>&, tquat<T,P> const&);
template<typename CTy, typename CTr, typename T, precision P>
GLM_FUNC_DECL std::basic_ostream<CTy,CTr>& operator<<(std::basic_ostream<CTy,CTr>&, vec<1, T,P> const&);
template<typename CTy, typename CTr, typename T, precision P>
GLM_FUNC_DECL std::basic_ostream<CTy,CTr>& operator<<(std::basic_ostream<CTy,CTr>&, vec<2, T,P> const&);
template<typename CTy, typename CTr, typename T, precision P>
GLM_FUNC_DECL std::basic_ostream<CTy,CTr>& operator<<(std::basic_ostream<CTy,CTr>&, vec<3, T,P> const&);
template<typename CTy, typename CTr, typename T, precision P>
GLM_FUNC_DECL std::basic_ostream<CTy,CTr>& operator<<(std::basic_ostream<CTy,CTr>&, vec<4, T,P> const&);
template<typename CTy, typename CTr, typename T, precision P>
GLM_FUNC_DECL std::basic_ostream<CTy,CTr>& operator<<(std::basic_ostream<CTy,CTr>&, mat<2, 2, T,P> const&);
template<typename CTy, typename CTr, typename T, precision P>
GLM_FUNC_DECL std::basic_ostream<CTy,CTr>& operator<<(std::basic_ostream<CTy,CTr>&, mat<2, 3, T,P> const&);
template<typename CTy, typename CTr, typename T, precision P>
GLM_FUNC_DECL std::basic_ostream<CTy,CTr>& operator<<(std::basic_ostream<CTy,CTr>&, mat<2, 4, T,P> const&);
template<typename CTy, typename CTr, typename T, precision P>
GLM_FUNC_DECL std::basic_ostream<CTy,CTr>& operator<<(std::basic_ostream<CTy,CTr>&, mat<3, 2, T,P> const&);
template<typename CTy, typename CTr, typename T, precision P>
GLM_FUNC_DECL std::basic_ostream<CTy,CTr>& operator<<(std::basic_ostream<CTy,CTr>&, mat<3, 3, T,P> const&);
template<typename CTy, typename CTr, typename T, precision P>
GLM_FUNC_DECL std::basic_ostream<CTy,CTr>& operator<<(std::basic_ostream<CTy,CTr>&, mat<3, 4, T,P> const&);
template<typename CTy, typename CTr, typename T, precision P>
GLM_FUNC_DECL std::basic_ostream<CTy,CTr>& operator<<(std::basic_ostream<CTy,CTr>&, mat<4, 2, T,P> const&);
template<typename CTy, typename CTr, typename T, precision P>
GLM_FUNC_DECL std::basic_ostream<CTy,CTr>& operator<<(std::basic_ostream<CTy,CTr>&, mat<4, 3, T,P> const&);
template<typename CTy, typename CTr, typename T, precision P>
GLM_FUNC_DECL std::basic_ostream<CTy,CTr>& operator<<(std::basic_ostream<CTy,CTr>&, mat<4, 4, T,P> const&);
template<typename CTy, typename CTr, typename T, precision P>
GLM_FUNC_DECL std::basic_ostream<CTy,CTr> & operator<<(std::basic_ostream<CTy,CTr> &,
std::pair<mat<4, 4, T,P> const, mat<4, 4, T,P> const> const &);
/// @}
}//namespace glm
#include "io.inl"

441
glm/gtx/io.inl Normal file
View file

@ -0,0 +1,441 @@
/// @ref gtx_io
/// @file glm/gtx/io.inl
/// @author Jan P Springer (regnirpsj@gmail.com)
#include <iomanip> // std::fixed, std::setfill<>, std::setprecision, std::right, std::setw
#include <ostream> // std::basic_ostream<>
#include "../gtc/matrix_access.hpp" // glm::col, glm::row
#include "../gtx/type_trait.hpp" // glm::type<>
namespace glm{
namespace io
{
template<typename CTy>
GLM_FUNC_QUALIFIER format_punct<CTy>::format_punct(size_t a)
: std::locale::facet(a)
, formatted(true)
, precision(3)
, width(1 + 4 + 1 + precision)
, separator(',')
, delim_left('[')
, delim_right(']')
, space(' ')
, newline('\n')
, order(column_major)
{}
template<typename CTy>
GLM_FUNC_QUALIFIER format_punct<CTy>::format_punct(format_punct const& a)
: std::locale::facet(0)
, formatted(a.formatted)
, precision(a.precision)
, width(a.width)
, separator(a.separator)
, delim_left(a.delim_left)
, delim_right(a.delim_right)
, space(a.space)
, newline(a.newline)
, order(a.order)
{}
template<typename CTy> std::locale::id format_punct<CTy>::id;
template<typename CTy, typename CTr>
GLM_FUNC_QUALIFIER basic_state_saver<CTy, CTr>::basic_state_saver(std::basic_ios<CTy, CTr>& a)
: state_(a)
, flags_(a.flags())
, precision_(a.precision())
, width_(a.width())
, fill_(a.fill())
, locale_(a.getloc())
{}
template<typename CTy, typename CTr>
GLM_FUNC_QUALIFIER basic_state_saver<CTy, CTr>::~basic_state_saver()
{
state_.imbue(locale_);
state_.fill(fill_);
state_.width(width_);
state_.precision(precision_);
state_.flags(flags_);
}
template<typename CTy, typename CTr>
GLM_FUNC_QUALIFIER basic_format_saver<CTy, CTr>::basic_format_saver(std::basic_ios<CTy, CTr>& a)
: bss_(a)
{
a.imbue(std::locale(a.getloc(), new format_punct<CTy>(get_facet<format_punct<CTy> >(a))));
}
template<typename CTy, typename CTr>
GLM_FUNC_QUALIFIER
basic_format_saver<CTy, CTr>::~basic_format_saver()
{}
GLM_FUNC_QUALIFIER precision::precision(unsigned a)
: value(a)
{}
GLM_FUNC_QUALIFIER width::width(unsigned a)
: value(a)
{}
template<typename CTy>
GLM_FUNC_QUALIFIER delimeter<CTy>::delimeter(CTy a, CTy b, CTy c)
: value()
{
value[0] = a;
value[1] = b;
value[2] = c;
}
GLM_FUNC_QUALIFIER order::order(order_type a)
: value(a)
{}
template<typename FTy, typename CTy, typename CTr>
GLM_FUNC_QUALIFIER FTy const& get_facet(std::basic_ios<CTy, CTr>& ios)
{
if(!std::has_facet<FTy>(ios.getloc()))
ios.imbue(std::locale(ios.getloc(), new FTy));
return std::use_facet<FTy>(ios.getloc());
}
template<typename CTy, typename CTr>
GLM_FUNC_QUALIFIER std::basic_ios<CTy, CTr>& formatted(std::basic_ios<CTy, CTr>& ios)
{
const_cast<format_punct<CTy>&>(get_facet<format_punct<CTy> >(ios)).formatted = true;
return ios;
}
template<typename CTy, typename CTr>
GLM_FUNC_QUALIFIER std::basic_ios<CTy, CTr>& unformatted(std::basic_ios<CTy, CTr>& ios)
{
const_cast<format_punct<CTy>&>(get_facet<format_punct<CTy> >(ios)).formatted = false;
return ios;
}
template<typename CTy, typename CTr>
GLM_FUNC_QUALIFIER std::basic_ostream<CTy, CTr>& operator<<(std::basic_ostream<CTy, CTr>& os, precision const& a)
{
const_cast<format_punct<CTy>&>(get_facet<format_punct<CTy> >(os)).precision = a.value;
return os;
}
template<typename CTy, typename CTr>
GLM_FUNC_QUALIFIER std::basic_ostream<CTy, CTr>& operator<<(std::basic_ostream<CTy, CTr>& os, width const& a)
{
const_cast<format_punct<CTy>&>(get_facet<format_punct<CTy> >(os)).width = a.value;
return os;
}
template<typename CTy, typename CTr>
GLM_FUNC_QUALIFIER std::basic_ostream<CTy, CTr>& operator<<(std::basic_ostream<CTy, CTr>& os, delimeter<CTy> const& a)
{
format_punct<CTy> & fmt(const_cast<format_punct<CTy>&>(get_facet<format_punct<CTy> >(os)));
fmt.delim_left = a.value[0];
fmt.delim_right = a.value[1];
fmt.separator = a.value[2];
return os;
}
template<typename CTy, typename CTr>
GLM_FUNC_QUALIFIER std::basic_ostream<CTy, CTr>& operator<<(std::basic_ostream<CTy, CTr>& os, order const& a)
{
const_cast<format_punct<CTy>&>(get_facet<format_punct<CTy> >(os)).order = a.value;
return os;
}
} // namespace io
namespace detail
{
template<typename CTy, typename CTr, typename V>
GLM_FUNC_QUALIFIER std::basic_ostream<CTy, CTr>&
print_vector_on(std::basic_ostream<CTy, CTr>& os, V const& a)
{
typename std::basic_ostream<CTy, CTr>::sentry const cerberus(os);
if(cerberus)
{
io::format_punct<CTy> const & fmt(io::get_facet<io::format_punct<CTy> >(os));
length_t const& components(type<V>::components);
if(fmt.formatted)
{
io::basic_state_saver<CTy> const bss(os);
os << std::fixed << std::right << std::setprecision(fmt.precision) << std::setfill(fmt.space) << fmt.delim_left;
for(length_t i(0); i < components; ++i)
{
os << std::setw(fmt.width) << a[i];
if(components-1 != i)
os << fmt.separator;
}
os << fmt.delim_right;
}
else
{
for(length_t i(0); i < components; ++i)
{
os << a[i];
if(components-1 != i)
os << fmt.space;
}
}
}
return os;
}
}//namespace detail
template<typename CTy, typename CTr, typename T, precision P>
GLM_FUNC_QUALIFIER std::basic_ostream<CTy,CTr>& operator<<(std::basic_ostream<CTy,CTr>& os, tquat<T,P> const& a)
{
return detail::print_vector_on(os, a);
}
template<typename CTy, typename CTr, typename T, precision P>
GLM_FUNC_QUALIFIER std::basic_ostream<CTy,CTr>& operator<<(std::basic_ostream<CTy,CTr>& os, vec<1, T,P> const& a)
{
return detail::print_vector_on(os, a);
}
template<typename CTy, typename CTr, typename T, precision P>
GLM_FUNC_QUALIFIER std::basic_ostream<CTy,CTr>& operator<<(std::basic_ostream<CTy,CTr>& os, vec<2, T,P> const& a)
{
return detail::print_vector_on(os, a);
}
template<typename CTy, typename CTr, typename T, precision P>
GLM_FUNC_QUALIFIER std::basic_ostream<CTy,CTr>& operator<<(std::basic_ostream<CTy,CTr>& os, vec<3, T,P> const& a)
{
return detail::print_vector_on(os, a);
}
template<typename CTy, typename CTr, typename T, precision P>
GLM_FUNC_QUALIFIER std::basic_ostream<CTy,CTr>& operator<<(std::basic_ostream<CTy,CTr>& os, vec<4, T,P> const& a)
{
return detail::print_vector_on(os, a);
}
namespace detail
{
template<typename CTy, typename CTr, template<length_t, length_t, typename, precision> class M, length_t C, length_t R, typename T, precision P>
GLM_FUNC_QUALIFIER std::basic_ostream<CTy, CTr>& print_matrix_on(std::basic_ostream<CTy, CTr>& os, M<C, R, T, P> const& a)
{
typename std::basic_ostream<CTy,CTr>::sentry const cerberus(os);
if(cerberus)
{
io::format_punct<CTy> const & fmt(io::get_facet<io::format_punct<CTy> >(os));
length_t const& cols(type<M<C, R, T, P> >::cols);
length_t const& rows(type<M<C, R, T, P> >::rows);
if(fmt.formatted)
{
os << fmt.newline << fmt.delim_left;
switch(fmt.order)
{
case io::column_major:
{
for(length_t i(0); i < rows; ++i)
{
if (0 != i)
os << fmt.space;
os << row(a, i);
if(rows-1 != i)
os << fmt.newline;
}
}
break;
case io::row_major:
{
for(length_t i(0); i < cols; ++i)
{
if(0 != i)
os << fmt.space;
os << column(a, i);
if(cols-1 != i)
os << fmt.newline;
}
}
break;
}
os << fmt.delim_right;
}
else
{
switch (fmt.order)
{
case io::column_major:
{
for(length_t i(0); i < cols; ++i)
{
os << column(a, i);
if(cols - 1 != i)
os << fmt.space;
}
}
break;
case io::row_major:
{
for (length_t i(0); i < rows; ++i)
{
os << row(a, i);
if (rows-1 != i)
os << fmt.space;
}
}
break;
}
}
}
return os;
}
}//namespace detail
template<typename CTy, typename CTr, typename T, precision P>
GLM_FUNC_QUALIFIER std::basic_ostream<CTy,CTr>& operator<<(std::basic_ostream<CTy,CTr>& os, mat<2, 2, T, P> const& a)
{
return detail::print_matrix_on(os, a);
}
template<typename CTy, typename CTr, typename T, precision P>
GLM_FUNC_QUALIFIER std::basic_ostream<CTy,CTr>& operator<<(std::basic_ostream<CTy,CTr>& os, mat<2, 3, T, P> const& a)
{
return detail::print_matrix_on(os, a);
}
template<typename CTy, typename CTr, typename T, precision P>
GLM_FUNC_QUALIFIER std::basic_ostream<CTy,CTr>& operator<<(std::basic_ostream<CTy,CTr>& os, mat<2, 4, T, P> const& a)
{
return detail::print_matrix_on(os, a);
}
template<typename CTy, typename CTr, typename T, precision P>
GLM_FUNC_QUALIFIER std::basic_ostream<CTy,CTr>& operator<<(std::basic_ostream<CTy,CTr>& os, mat<3, 2, T,P> const& a)
{
return detail::print_matrix_on(os, a);
}
template<typename CTy, typename CTr, typename T, precision P>
GLM_FUNC_QUALIFIER std::basic_ostream<CTy,CTr>& operator<<(std::basic_ostream<CTy,CTr>& os, mat<3, 3, T,P> const& a)
{
return detail::print_matrix_on(os, a);
}
template<typename CTy, typename CTr, typename T, precision P>
GLM_FUNC_QUALIFIER std::basic_ostream<CTy,CTr> & operator<<(std::basic_ostream<CTy,CTr>& os, mat<3, 4, T,P> const& a)
{
return detail::print_matrix_on(os, a);
}
template<typename CTy, typename CTr, typename T, precision P>
GLM_FUNC_QUALIFIER std::basic_ostream<CTy,CTr> & operator<<(std::basic_ostream<CTy,CTr>& os, mat<4, 2, T,P> const& a)
{
return detail::print_matrix_on(os, a);
}
template<typename CTy, typename CTr, typename T, precision P>
GLM_FUNC_QUALIFIER std::basic_ostream<CTy,CTr> & operator<<(std::basic_ostream<CTy,CTr>& os, mat<4, 3, T,P> const& a)
{
return detail::print_matrix_on(os, a);
}
template<typename CTy, typename CTr, typename T, precision P>
GLM_FUNC_QUALIFIER std::basic_ostream<CTy,CTr> & operator<<(std::basic_ostream<CTy,CTr>& os, mat<4, 4, T,P> const& a)
{
return detail::print_matrix_on(os, a);
}
namespace detail
{
template<typename CTy, typename CTr, template<length_t, length_t, typename, precision> class M, length_t C, length_t R, typename T, precision P>
GLM_FUNC_QUALIFIER std::basic_ostream<CTy, CTr>& print_matrix_pair_on(std::basic_ostream<CTy, CTr>& os, std::pair<M<C, R, T, P> const, M<C, R, T, P> const> const& a)
{
typename std::basic_ostream<CTy,CTr>::sentry const cerberus(os);
if(cerberus)
{
io::format_punct<CTy> const& fmt(io::get_facet<io::format_punct<CTy> >(os));
M<C, R, T,P> const& ml(a.first);
M<C, R, T,P> const& mr(a.second);
length_t const& cols(type<M<C, R, T, P> >::cols);
length_t const& rows(type<M<C, R, T, P> >::rows);
if(fmt.formatted)
{
os << fmt.newline << fmt.delim_left;
switch(fmt.order)
{
case io::column_major:
{
for(length_t i(0); i < rows; ++i)
{
if(0 != i)
os << fmt.space;
os << row(ml, i) << ((rows-1 != i) ? fmt.space : fmt.delim_right) << fmt.space << ((0 != i) ? fmt.space : fmt.delim_left) << row(mr, i);
if(rows-1 != i)
os << fmt.newline;
}
}
break;
case io::row_major:
{
for(length_t i(0); i < cols; ++i)
{
if(0 != i)
os << fmt.space;
os << column(ml, i) << ((cols-1 != i) ? fmt.space : fmt.delim_right) << fmt.space << ((0 != i) ? fmt.space : fmt.delim_left) << column(mr, i);
if(cols-1 != i)
os << fmt.newline;
}
}
break;
}
os << fmt.delim_right;
}
else
{
os << ml << fmt.space << mr;
}
}
return os;
}
}//namespace detail
template<typename CTy, typename CTr, typename T, precision P>
GLM_FUNC_QUALIFIER std::basic_ostream<CTy, CTr>& operator<<(
std::basic_ostream<CTy, CTr> & os,
std::pair<mat<4, 4, T, P> const,
mat<4, 4, T, P> const> const& a)
{
return detail::print_matrix_pair_on(os, a);
}
}//namespace glm

48
glm/gtx/log_base.hpp Normal file
View file

@ -0,0 +1,48 @@
/// @ref gtx_log_base
/// @file glm/gtx/log_base.hpp
///
/// @see core (dependence)
///
/// @defgroup gtx_log_base GLM_GTX_log_base
/// @ingroup gtx
///
/// @brief Logarithm for any base. base can be a vector or a scalar.
///
/// <glm/gtx/log_base.hpp> need to be included to use these functionalities.
#pragma once
// Dependency:
#include "../glm.hpp"
#ifndef GLM_ENABLE_EXPERIMENTAL
# error "GLM: GLM_GTX_log_base is an experimental extension and may change in the future. Use #define GLM_ENABLE_EXPERIMENTAL before including it, if you really want to use it."
#endif
#if GLM_MESSAGES == GLM_MESSAGES_ENABLED && !defined(GLM_EXT_INCLUDED)
# pragma message("GLM: GLM_GTX_log_base extension included")
#endif
namespace glm
{
/// @addtogroup gtx_log_base
/// @{
/// Logarithm for any base.
/// From GLM_GTX_log_base.
template<typename genType>
GLM_FUNC_DECL genType log(
genType const & x,
genType const & base);
/// Logarithm for any base.
/// From GLM_GTX_log_base.
template<length_t L, typename T, precision P, template<length_t, typename, precision> class vecType>
GLM_FUNC_DECL vecType<L, T, P> sign(
vecType<L, T, P> const& x,
vecType<L, T, P> const& base);
/// @}
}//namespace glm
#include "log_base.inl"

18
glm/gtx/log_base.inl Normal file
View file

@ -0,0 +1,18 @@
/// @ref gtx_log_base
/// @file glm/gtx/log_base.inl
namespace glm
{
template<typename genType>
GLM_FUNC_QUALIFIER genType log(genType const & x, genType const & base)
{
assert(x != genType(0));
return glm::log(x) / glm::log(base);
}
template<length_t L, typename T, precision P, template<length_t, typename, precision> class vecType>
GLM_FUNC_QUALIFIER vecType<L, T, P> log(vecType<L, T, P> const & x, vecType<L, T, P> const & base)
{
return glm::log(x) / glm::log(base);
}
}//namespace glm

View file

@ -0,0 +1,47 @@
/// @ref gtx_matrix_cross_product
/// @file glm/gtx/matrix_cross_product.hpp
///
/// @see core (dependence)
/// @see gtx_extented_min_max (dependence)
///
/// @defgroup gtx_matrix_cross_product GLM_GTX_matrix_cross_product
/// @ingroup gtx
///
/// @brief Build cross product matrices
///
/// <glm/gtx/matrix_cross_product.hpp> need to be included to use these functionalities.
#pragma once
// Dependency:
#include "../glm.hpp"
#ifndef GLM_ENABLE_EXPERIMENTAL
# error "GLM: GLM_GTX_matrix_cross_product is an experimental extension and may change in the future. Use #define GLM_ENABLE_EXPERIMENTAL before including it, if you really want to use it."
#endif
#if GLM_MESSAGES == GLM_MESSAGES_ENABLED && !defined(GLM_EXT_INCLUDED)
# pragma message("GLM: GLM_GTX_matrix_cross_product extension included")
#endif
namespace glm
{
/// @addtogroup gtx_matrix_cross_product
/// @{
//! Build a cross product matrix.
//! From GLM_GTX_matrix_cross_product extension.
template<typename T, precision P>
GLM_FUNC_DECL mat<3, 3, T, P> matrixCross3(
vec<3, T, P> const & x);
//! Build a cross product matrix.
//! From GLM_GTX_matrix_cross_product extension.
template<typename T, precision P>
GLM_FUNC_DECL mat<4, 4, T, P> matrixCross4(
vec<3, T, P> const & x);
/// @}
}//namespace glm
#include "matrix_cross_product.inl"

View file

@ -0,0 +1,38 @@
/// @ref gtx_matrix_cross_product
/// @file glm/gtx/matrix_cross_product.inl
namespace glm
{
template<typename T, precision P>
GLM_FUNC_QUALIFIER mat<3, 3, T, P> matrixCross3
(
vec<3, T, P> const & x
)
{
mat<3, 3, T, P> Result(T(0));
Result[0][1] = x.z;
Result[1][0] = -x.z;
Result[0][2] = -x.y;
Result[2][0] = x.y;
Result[1][2] = x.x;
Result[2][1] = -x.x;
return Result;
}
template<typename T, precision P>
GLM_FUNC_QUALIFIER mat<4, 4, T, P> matrixCross4
(
vec<3, T, P> const & x
)
{
mat<4, 4, T, P> Result(T(0));
Result[0][1] = x.z;
Result[1][0] = -x.z;
Result[0][2] = -x.y;
Result[2][0] = x.y;
Result[1][2] = x.x;
Result[2][1] = -x.x;
return Result;
}
}//namespace glm

View file

@ -0,0 +1,46 @@
/// @ref gtx_matrix_decompose
/// @file glm/gtx/matrix_decompose.hpp
///
/// @see core (dependence)
///
/// @defgroup gtx_matrix_decompose GLM_GTX_matrix_decompose
/// @ingroup gtx
///
/// @brief Decomposes a model matrix to translations, rotation and scale components
///
/// <glm/gtx/matrix_decompose.hpp> need to be included to use these functionalities.
#pragma once
// Dependencies
#include "../mat4x4.hpp"
#include "../vec3.hpp"
#include "../vec4.hpp"
#include "../geometric.hpp"
#include "../gtc/quaternion.hpp"
#include "../gtc/matrix_transform.hpp"
#ifndef GLM_ENABLE_EXPERIMENTAL
# error "GLM: GLM_GTX_matrix_decompose is an experimental extension and may change in the future. Use #define GLM_ENABLE_EXPERIMENTAL before including it, if you really want to use it."
#endif
#if GLM_MESSAGES == GLM_MESSAGES_ENABLED && !defined(GLM_EXT_INCLUDED)
# pragma message("GLM: GLM_GTX_matrix_decompose extension included")
#endif
namespace glm
{
/// @addtogroup gtx_matrix_decompose
/// @{
/// Decomposes a model matrix to translations, rotation and scale components
/// @see gtx_matrix_decompose
template<typename T, precision P>
GLM_FUNC_DECL bool decompose(
mat<4, 4, T, P> const& modelMatrix,
vec<3, T, P> & scale, tquat<T, P> & orientation, vec<3, T, P> & translation, vec<3, T, P> & skew, vec<4, T, P> & perspective);
/// @}
}//namespace glm
#include "matrix_decompose.inl"

View file

@ -0,0 +1,181 @@
/// @ref gtx_matrix_decompose
/// @file glm/gtx/matrix_decompose.inl
namespace glm{
namespace detail
{
/// Make a linear combination of two vectors and return the result.
// result = (a * ascl) + (b * bscl)
template<typename T, precision P>
GLM_FUNC_QUALIFIER vec<3, T, P> combine(
vec<3, T, P> const & a,
vec<3, T, P> const & b,
T ascl, T bscl)
{
return (a * ascl) + (b * bscl);
}
template<typename T, precision P>
GLM_FUNC_QUALIFIER vec<3, T, P> scale(vec<3, T, P> const& v, T desiredLength)
{
return v * desiredLength / length(v);
}
}//namespace detail
// Matrix decompose
// http://www.opensource.apple.com/source/WebCore/WebCore-514/platform/graphics/transforms/TransformationMatrix.cpp
// Decomposes the mode matrix to translations,rotation scale components
template<typename T, precision P>
GLM_FUNC_QUALIFIER bool decompose(mat<4, 4, T, P> const & ModelMatrix, vec<3, T, P> & Scale, tquat<T, P> & Orientation, vec<3, T, P> & Translation, vec<3, T, P> & Skew, vec<4, T, P> & Perspective)
{
mat<4, 4, T, P> LocalMatrix(ModelMatrix);
// Normalize the matrix.
if(LocalMatrix[3][3] == static_cast<T>(0))
return false;
for(length_t i = 0; i < 4; ++i)
for(length_t j = 0; j < 4; ++j)
LocalMatrix[i][j] /= LocalMatrix[3][3];
// perspectiveMatrix is used to solve for perspective, but it also provides
// an easy way to test for singularity of the upper 3x3 component.
mat<4, 4, T, P> PerspectiveMatrix(LocalMatrix);
for(length_t i = 0; i < 3; i++)
PerspectiveMatrix[i][3] = static_cast<T>(0);
PerspectiveMatrix[3][3] = static_cast<T>(1);
/// TODO: Fixme!
if(determinant(PerspectiveMatrix) == static_cast<T>(0))
return false;
// First, isolate perspective. This is the messiest.
if(LocalMatrix[0][3] != static_cast<T>(0) || LocalMatrix[1][3] != static_cast<T>(0) || LocalMatrix[2][3] != static_cast<T>(0))
{
// rightHandSide is the right hand side of the equation.
vec<4, T, P> RightHandSide;
RightHandSide[0] = LocalMatrix[0][3];
RightHandSide[1] = LocalMatrix[1][3];
RightHandSide[2] = LocalMatrix[2][3];
RightHandSide[3] = LocalMatrix[3][3];
// Solve the equation by inverting PerspectiveMatrix and multiplying
// rightHandSide by the inverse. (This is the easiest way, not
// necessarily the best.)
mat<4, 4, T, P> InversePerspectiveMatrix = glm::inverse(PerspectiveMatrix);// inverse(PerspectiveMatrix, inversePerspectiveMatrix);
mat<4, 4, T, P> TransposedInversePerspectiveMatrix = glm::transpose(InversePerspectiveMatrix);// transposeMatrix4(inversePerspectiveMatrix, transposedInversePerspectiveMatrix);
Perspective = TransposedInversePerspectiveMatrix * RightHandSide;
// v4MulPointByMatrix(rightHandSide, transposedInversePerspectiveMatrix, perspectivePoint);
// Clear the perspective partition
LocalMatrix[0][3] = LocalMatrix[1][3] = LocalMatrix[2][3] = static_cast<T>(0);
LocalMatrix[3][3] = static_cast<T>(1);
}
else
{
// No perspective.
Perspective = vec<4, T, P>(0, 0, 0, 1);
}
// Next take care of translation (easy).
Translation = vec<3, T, P>(LocalMatrix[3]);
LocalMatrix[3] = vec<4, T, P>(0, 0, 0, LocalMatrix[3].w);
vec<3, T, P> Row[3], Pdum3;
// Now get scale and shear.
for(length_t i = 0; i < 3; ++i)
for(int j = 0; j < 3; ++j)
Row[i][j] = LocalMatrix[i][j];
// Compute X scale factor and normalize first row.
Scale.x = length(Row[0]);// v3Length(Row[0]);
Row[0] = detail::scale(Row[0], static_cast<T>(1));
// Compute XY shear factor and make 2nd row orthogonal to 1st.
Skew.z = dot(Row[0], Row[1]);
Row[1] = detail::combine(Row[1], Row[0], static_cast<T>(1), -Skew.z);
// Now, compute Y scale and normalize 2nd row.
Scale.y = length(Row[1]);
Row[1] = detail::scale(Row[1], static_cast<T>(1));
Skew.z /= Scale.y;
// Compute XZ and YZ shears, orthogonalize 3rd row.
Skew.y = glm::dot(Row[0], Row[2]);
Row[2] = detail::combine(Row[2], Row[0], static_cast<T>(1), -Skew.y);
Skew.x = glm::dot(Row[1], Row[2]);
Row[2] = detail::combine(Row[2], Row[1], static_cast<T>(1), -Skew.x);
// Next, get Z scale and normalize 3rd row.
Scale.z = length(Row[2]);
Row[2] = detail::scale(Row[2], static_cast<T>(1));
Skew.y /= Scale.z;
Skew.x /= Scale.z;
// At this point, the matrix (in rows[]) is orthonormal.
// Check for a coordinate system flip. If the determinant
// is -1, then negate the matrix and the scaling factors.
Pdum3 = cross(Row[1], Row[2]); // v3Cross(row[1], row[2], Pdum3);
if(dot(Row[0], Pdum3) < 0)
{
for(length_t i = 0; i < 3; i++)
{
Scale[i] *= static_cast<T>(-1);
Row[i] *= static_cast<T>(-1);
}
}
// Now, get the rotations out, as described in the gem.
// FIXME - Add the ability to return either quaternions (which are
// easier to recompose with) or Euler angles (rx, ry, rz), which
// are easier for authors to deal with. The latter will only be useful
// when we fix https://bugs.webkit.org/show_bug.cgi?id=23799, so I
// will leave the Euler angle code here for now.
// ret.rotateY = asin(-Row[0][2]);
// if (cos(ret.rotateY) != 0) {
// ret.rotateX = atan2(Row[1][2], Row[2][2]);
// ret.rotateZ = atan2(Row[0][1], Row[0][0]);
// } else {
// ret.rotateX = atan2(-Row[2][0], Row[1][1]);
// ret.rotateZ = 0;
// }
int i, j, k = 0;
float root, trace = Row[0].x + Row[1].y + Row[2].z;
if(trace > static_cast<T>(0))
{
root = sqrt(trace + static_cast<T>(1.0));
Orientation.w = static_cast<T>(0.5) * root;
root = static_cast<T>(0.5) / root;
Orientation.x = root * (Row[1].z - Row[2].y);
Orientation.y = root * (Row[2].x - Row[0].z);
Orientation.z = root * (Row[0].y - Row[1].x);
} // End if > 0
else
{
static int Next[3] = {1, 2, 0};
i = 0;
if(Row[1].y > Row[0].x) i = 1;
if(Row[2].z > Row[i][i]) i = 2;
j = Next[i];
k = Next[j];
root = sqrt(Row[i][i] - Row[j][j] - Row[k][k] + static_cast<T>(1.0));
Orientation[i] = static_cast<T>(0.5) * root;
root = static_cast<T>(0.5) / root;
Orientation[j] = root * (Row[i][j] + Row[j][i]);
Orientation[k] = root * (Row[i][k] + Row[k][i]);
Orientation.w = root * (Row[j][k] - Row[k][j]);
} // End if <= 0
return true;
}
}//namespace glm

View file

@ -0,0 +1,65 @@
/// @ref gtx_matrix_interpolation
/// @file glm/gtx/matrix_interpolation.hpp
/// @author Ghenadii Ursachi (the.asteroth@gmail.com)
///
/// @see core (dependence)
///
/// @defgroup gtx_matrix_interpolation GLM_GTX_matrix_interpolation
/// @ingroup gtx
///
/// @brief Allows to directly interpolate two exiciting matrices.
///
/// <glm/gtx/matrix_interpolation.hpp> need to be included to use these functionalities.
#pragma once
// Dependency:
#include "../glm.hpp"
#ifndef GLM_ENABLE_EXPERIMENTAL
# error "GLM: GLM_GTX_matrix_interpolation is an experimental extension and may change in the future. Use #define GLM_ENABLE_EXPERIMENTAL before including it, if you really want to use it."
#endif
#if GLM_MESSAGES == GLM_MESSAGES_ENABLED && !defined(GLM_EXT_INCLUDED)
# pragma message("GLM: GLM_GTX_matrix_interpolation extension included")
#endif
namespace glm
{
/// @addtogroup gtx_matrix_interpolation
/// @{
/// Get the axis and angle of the rotation from a matrix.
/// From GLM_GTX_matrix_interpolation extension.
template<typename T, precision P>
GLM_FUNC_DECL void axisAngle(
mat<4, 4, T, P> const& mat,
vec<3, T, P> & axis,
T & angle);
/// Build a matrix from axis and angle.
/// From GLM_GTX_matrix_interpolation extension.
template<typename T, precision P>
GLM_FUNC_DECL mat<4, 4, T, P> axisAngleMatrix(
vec<3, T, P> const & axis,
T const angle);
/// Extracts the rotation part of a matrix.
/// From GLM_GTX_matrix_interpolation extension.
template<typename T, precision P>
GLM_FUNC_DECL mat<4, 4, T, P> extractMatrixRotation(
mat<4, 4, T, P> const& mat);
/// Build a interpolation of 4 * 4 matrixes.
/// From GLM_GTX_matrix_interpolation extension.
/// Warning! works only with rotation and/or translation matrixes, scale will generate unexpected results.
template<typename T, precision P>
GLM_FUNC_DECL mat<4, 4, T, P> interpolate(
mat<4, 4, T, P> const& m1,
mat<4, 4, T, P> const& m2,
T const delta);
/// @}
}//namespace glm
#include "matrix_interpolation.inl"

View file

@ -0,0 +1,132 @@
/// @ref gtx_matrix_interpolation
/// @file glm/gtx/matrix_interpolation.hpp
namespace glm
{
template<typename T, precision P>
GLM_FUNC_QUALIFIER void axisAngle
(
mat<4, 4, T, P> const& mat,
vec<3, T, P> & axis,
T & angle
)
{
T epsilon = (T)0.01;
T epsilon2 = (T)0.1;
if((abs(mat[1][0] - mat[0][1]) < epsilon) && (abs(mat[2][0] - mat[0][2]) < epsilon) && (abs(mat[2][1] - mat[1][2]) < epsilon))
{
if ((abs(mat[1][0] + mat[0][1]) < epsilon2) && (abs(mat[2][0] + mat[0][2]) < epsilon2) && (abs(mat[2][1] + mat[1][2]) < epsilon2) && (abs(mat[0][0] + mat[1][1] + mat[2][2] - (T)3.0) < epsilon2))
{
angle = (T)0.0;
axis.x = (T)1.0;
axis.y = (T)0.0;
axis.z = (T)0.0;
return;
}
angle = static_cast<T>(3.1415926535897932384626433832795);
T xx = (mat[0][0] + (T)1.0) * (T)0.5;
T yy = (mat[1][1] + (T)1.0) * (T)0.5;
T zz = (mat[2][2] + (T)1.0) * (T)0.5;
T xy = (mat[1][0] + mat[0][1]) * (T)0.25;
T xz = (mat[2][0] + mat[0][2]) * (T)0.25;
T yz = (mat[2][1] + mat[1][2]) * (T)0.25;
if((xx > yy) && (xx > zz))
{
if (xx < epsilon) {
axis.x = (T)0.0;
axis.y = (T)0.7071;
axis.z = (T)0.7071;
} else {
axis.x = sqrt(xx);
axis.y = xy / axis.x;
axis.z = xz / axis.x;
}
}
else if (yy > zz)
{
if (yy < epsilon) {
axis.x = (T)0.7071;
axis.y = (T)0.0;
axis.z = (T)0.7071;
} else {
axis.y = sqrt(yy);
axis.x = xy / axis.y;
axis.z = yz / axis.y;
}
}
else
{
if (zz < epsilon) {
axis.x = (T)0.7071;
axis.y = (T)0.7071;
axis.z = (T)0.0;
} else {
axis.z = sqrt(zz);
axis.x = xz / axis.z;
axis.y = yz / axis.z;
}
}
return;
}
T s = sqrt((mat[2][1] - mat[1][2]) * (mat[2][1] - mat[1][2]) + (mat[2][0] - mat[0][2]) * (mat[2][0] - mat[0][2]) + (mat[1][0] - mat[0][1]) * (mat[1][0] - mat[0][1]));
if (glm::abs(s) < T(0.001))
s = (T)1.0;
angle = acos((mat[0][0] + mat[1][1] + mat[2][2] - (T)1.0) * (T)0.5);
axis.x = (mat[1][2] - mat[2][1]) / s;
axis.y = (mat[2][0] - mat[0][2]) / s;
axis.z = (mat[0][1] - mat[1][0]) / s;
}
template<typename T, precision P>
GLM_FUNC_QUALIFIER mat<4, 4, T, P> axisAngleMatrix
(
vec<3, T, P> const & axis,
T const angle
)
{
T c = cos(angle);
T s = sin(angle);
T t = static_cast<T>(1) - c;
vec<3, T, P> n = normalize(axis);
return mat<4, 4, T, P>(
t * n.x * n.x + c, t * n.x * n.y + n.z * s, t * n.x * n.z - n.y * s, T(0),
t * n.x * n.y - n.z * s, t * n.y * n.y + c, t * n.y * n.z + n.x * s, T(0),
t * n.x * n.z + n.y * s, t * n.y * n.z - n.x * s, t * n.z * n.z + c, T(0),
T(0), T(0), T(0), T(1));
}
template<typename T, precision P>
GLM_FUNC_QUALIFIER mat<4, 4, T, P> extractMatrixRotation
(
mat<4, 4, T, P> const& m
)
{
return mat<4, 4, T, P>(
m[0][0], m[0][1], m[0][2], 0.0,
m[1][0], m[1][1], m[1][2], 0.0,
m[2][0], m[2][1], m[2][2], 0.0,
0.0, 0.0, 0.0, 1.0);
}
template<typename T, precision P>
GLM_FUNC_QUALIFIER mat<4, 4, T, P> interpolate
(
mat<4, 4, T, P> const& m1,
mat<4, 4, T, P> const& m2,
T const delta
)
{
mat<4, 4, T, P> m1rot = extractMatrixRotation(m1);
mat<4, 4, T, P> dltRotation = m2 * transpose(m1rot);
vec<3, T, P> dltAxis;
T dltAngle;
axisAngle(dltRotation, dltAxis, dltAngle);
mat<4, 4, T, P> out = axisAngleMatrix(dltAxis, dltAngle * delta) * m1rot;
out[3][0] = m1[3][0] + delta * (m2[3][0] - m1[3][0]);
out[3][1] = m1[3][1] + delta * (m2[3][1] - m1[3][1]);
out[3][2] = m1[3][2] + delta * (m2[3][2] - m1[3][2]);
return out;
}
}//namespace glm

View file

@ -0,0 +1,119 @@
/// @ref gtx_matrix_major_storage
/// @file glm/gtx/matrix_major_storage.hpp
///
/// @see core (dependence)
/// @see gtx_extented_min_max (dependence)
///
/// @defgroup gtx_matrix_major_storage GLM_GTX_matrix_major_storage
/// @ingroup gtx
///
/// @brief Build matrices with specific matrix order, row or column
///
/// <glm/gtx/matrix_major_storage.hpp> need to be included to use these functionalities.
#pragma once
// Dependency:
#include "../glm.hpp"
#ifndef GLM_ENABLE_EXPERIMENTAL
# error "GLM: GLM_GTX_matrix_major_storage is an experimental extension and may change in the future. Use #define GLM_ENABLE_EXPERIMENTAL before including it, if you really want to use it."
#endif
#if GLM_MESSAGES == GLM_MESSAGES_ENABLED && !defined(GLM_EXT_INCLUDED)
# pragma message("GLM: GLM_GTX_matrix_major_storage extension included")
#endif
namespace glm
{
/// @addtogroup gtx_matrix_major_storage
/// @{
//! Build a row major matrix from row vectors.
//! From GLM_GTX_matrix_major_storage extension.
template<typename T, precision P>
GLM_FUNC_DECL mat<2, 2, T, P> rowMajor2(
vec<2, T, P> const & v1,
vec<2, T, P> const & v2);
//! Build a row major matrix from other matrix.
//! From GLM_GTX_matrix_major_storage extension.
template<typename T, precision P>
GLM_FUNC_DECL mat<2, 2, T, P> rowMajor2(
mat<2, 2, T, P> const& m);
//! Build a row major matrix from row vectors.
//! From GLM_GTX_matrix_major_storage extension.
template<typename T, precision P>
GLM_FUNC_DECL mat<3, 3, T, P> rowMajor3(
vec<3, T, P> const & v1,
vec<3, T, P> const & v2,
vec<3, T, P> const & v3);
//! Build a row major matrix from other matrix.
//! From GLM_GTX_matrix_major_storage extension.
template<typename T, precision P>
GLM_FUNC_DECL mat<3, 3, T, P> rowMajor3(
mat<3, 3, T, P> const& m);
//! Build a row major matrix from row vectors.
//! From GLM_GTX_matrix_major_storage extension.
template<typename T, precision P>
GLM_FUNC_DECL mat<4, 4, T, P> rowMajor4(
vec<4, T, P> const & v1,
vec<4, T, P> const & v2,
vec<4, T, P> const & v3,
vec<4, T, P> const & v4);
//! Build a row major matrix from other matrix.
//! From GLM_GTX_matrix_major_storage extension.
template<typename T, precision P>
GLM_FUNC_DECL mat<4, 4, T, P> rowMajor4(
mat<4, 4, T, P> const& m);
//! Build a column major matrix from column vectors.
//! From GLM_GTX_matrix_major_storage extension.
template<typename T, precision P>
GLM_FUNC_DECL mat<2, 2, T, P> colMajor2(
vec<2, T, P> const & v1,
vec<2, T, P> const & v2);
//! Build a column major matrix from other matrix.
//! From GLM_GTX_matrix_major_storage extension.
template<typename T, precision P>
GLM_FUNC_DECL mat<2, 2, T, P> colMajor2(
mat<2, 2, T, P> const& m);
//! Build a column major matrix from column vectors.
//! From GLM_GTX_matrix_major_storage extension.
template<typename T, precision P>
GLM_FUNC_DECL mat<3, 3, T, P> colMajor3(
vec<3, T, P> const & v1,
vec<3, T, P> const & v2,
vec<3, T, P> const & v3);
//! Build a column major matrix from other matrix.
//! From GLM_GTX_matrix_major_storage extension.
template<typename T, precision P>
GLM_FUNC_DECL mat<3, 3, T, P> colMajor3(
mat<3, 3, T, P> const& m);
//! Build a column major matrix from column vectors.
//! From GLM_GTX_matrix_major_storage extension.
template<typename T, precision P>
GLM_FUNC_DECL mat<4, 4, T, P> colMajor4(
vec<4, T, P> const & v1,
vec<4, T, P> const & v2,
vec<4, T, P> const & v3,
vec<4, T, P> const & v4);
//! Build a column major matrix from other matrix.
//! From GLM_GTX_matrix_major_storage extension.
template<typename T, precision P>
GLM_FUNC_DECL mat<4, 4, T, P> colMajor4(
mat<4, 4, T, P> const& m);
/// @}
}//namespace glm
#include "matrix_major_storage.inl"

View file

@ -0,0 +1,167 @@
/// @ref gtx_matrix_major_storage
/// @file glm/gtx/matrix_major_storage.hpp
namespace glm
{
template<typename T, precision P>
GLM_FUNC_QUALIFIER mat<2, 2, T, P> rowMajor2
(
vec<2, T, P> const & v1,
vec<2, T, P> const & v2
)
{
mat<2, 2, T, P> Result;
Result[0][0] = v1.x;
Result[1][0] = v1.y;
Result[0][1] = v2.x;
Result[1][1] = v2.y;
return Result;
}
template<typename T, precision P>
GLM_FUNC_QUALIFIER mat<2, 2, T, P> rowMajor2(
const mat<2, 2, T, P>& m)
{
mat<2, 2, T, P> Result;
Result[0][0] = m[0][0];
Result[0][1] = m[1][0];
Result[1][0] = m[0][1];
Result[1][1] = m[1][1];
return Result;
}
template<typename T, precision P>
GLM_FUNC_QUALIFIER mat<3, 3, T, P> rowMajor3(
const vec<3, T, P>& v1,
const vec<3, T, P>& v2,
const vec<3, T, P>& v3)
{
mat<3, 3, T, P> Result;
Result[0][0] = v1.x;
Result[1][0] = v1.y;
Result[2][0] = v1.z;
Result[0][1] = v2.x;
Result[1][1] = v2.y;
Result[2][1] = v2.z;
Result[0][2] = v3.x;
Result[1][2] = v3.y;
Result[2][2] = v3.z;
return Result;
}
template<typename T, precision P>
GLM_FUNC_QUALIFIER mat<3, 3, T, P> rowMajor3(
const mat<3, 3, T, P>& m)
{
mat<3, 3, T, P> Result;
Result[0][0] = m[0][0];
Result[0][1] = m[1][0];
Result[0][2] = m[2][0];
Result[1][0] = m[0][1];
Result[1][1] = m[1][1];
Result[1][2] = m[2][1];
Result[2][0] = m[0][2];
Result[2][1] = m[1][2];
Result[2][2] = m[2][2];
return Result;
}
template<typename T, precision P>
GLM_FUNC_QUALIFIER mat<4, 4, T, P> rowMajor4(
const vec<4, T, P>& v1,
const vec<4, T, P>& v2,
const vec<4, T, P>& v3,
const vec<4, T, P>& v4)
{
mat<4, 4, T, P> Result;
Result[0][0] = v1.x;
Result[1][0] = v1.y;
Result[2][0] = v1.z;
Result[3][0] = v1.w;
Result[0][1] = v2.x;
Result[1][1] = v2.y;
Result[2][1] = v2.z;
Result[3][1] = v2.w;
Result[0][2] = v3.x;
Result[1][2] = v3.y;
Result[2][2] = v3.z;
Result[3][2] = v3.w;
Result[0][3] = v4.x;
Result[1][3] = v4.y;
Result[2][3] = v4.z;
Result[3][3] = v4.w;
return Result;
}
template<typename T, precision P>
GLM_FUNC_QUALIFIER mat<4, 4, T, P> rowMajor4(
const mat<4, 4, T, P>& m)
{
mat<4, 4, T, P> Result;
Result[0][0] = m[0][0];
Result[0][1] = m[1][0];
Result[0][2] = m[2][0];
Result[0][3] = m[3][0];
Result[1][0] = m[0][1];
Result[1][1] = m[1][1];
Result[1][2] = m[2][1];
Result[1][3] = m[3][1];
Result[2][0] = m[0][2];
Result[2][1] = m[1][2];
Result[2][2] = m[2][2];
Result[2][3] = m[3][2];
Result[3][0] = m[0][3];
Result[3][1] = m[1][3];
Result[3][2] = m[2][3];
Result[3][3] = m[3][3];
return Result;
}
template<typename T, precision P>
GLM_FUNC_QUALIFIER mat<2, 2, T, P> colMajor2(
const vec<2, T, P>& v1,
const vec<2, T, P>& v2)
{
return mat<2, 2, T, P>(v1, v2);
}
template<typename T, precision P>
GLM_FUNC_QUALIFIER mat<2, 2, T, P> colMajor2(
const mat<2, 2, T, P>& m)
{
return mat<2, 2, T, P>(m);
}
template<typename T, precision P>
GLM_FUNC_QUALIFIER mat<3, 3, T, P> colMajor3(
const vec<3, T, P>& v1,
const vec<3, T, P>& v2,
const vec<3, T, P>& v3)
{
return mat<3, 3, T, P>(v1, v2, v3);
}
template<typename T, precision P>
GLM_FUNC_QUALIFIER mat<3, 3, T, P> colMajor3(
const mat<3, 3, T, P>& m)
{
return mat<3, 3, T, P>(m);
}
template<typename T, precision P>
GLM_FUNC_QUALIFIER mat<4, 4, T, P> colMajor4(
const vec<4, T, P>& v1,
const vec<4, T, P>& v2,
const vec<4, T, P>& v3,
const vec<4, T, P>& v4)
{
return mat<4, 4, T, P>(v1, v2, v3, v4);
}
template<typename T, precision P>
GLM_FUNC_QUALIFIER mat<4, 4, T, P> colMajor4(
const mat<4, 4, T, P>& m)
{
return mat<4, 4, T, P>(m);
}
}//namespace glm

View file

@ -0,0 +1,88 @@
/// @ref gtx_matrix_operation
/// @file glm/gtx/matrix_operation.hpp
///
/// @see core (dependence)
///
/// @defgroup gtx_matrix_operation GLM_GTX_matrix_operation
/// @ingroup gtx
///
/// @brief Build diagonal matrices from vectors.
///
/// <glm/gtx/matrix_operation.hpp> need to be included to use these functionalities.
#pragma once
// Dependency:
#include "../glm.hpp"
#ifndef GLM_ENABLE_EXPERIMENTAL
# error "GLM: GLM_GTX_matrix_operation is an experimental extension and may change in the future. Use #define GLM_ENABLE_EXPERIMENTAL before including it, if you really want to use it."
#endif
#if GLM_MESSAGES == GLM_MESSAGES_ENABLED && !defined(GLM_EXT_INCLUDED)
# pragma message("GLM: GLM_GTX_matrix_operation extension included")
#endif
namespace glm
{
/// @addtogroup gtx_matrix_operation
/// @{
//! Build a diagonal matrix.
//! From GLM_GTX_matrix_operation extension.
template<typename T, precision P>
GLM_FUNC_DECL mat<2, 2, T, P> diagonal2x2(
vec<2, T, P> const & v);
//! Build a diagonal matrix.
//! From GLM_GTX_matrix_operation extension.
template<typename T, precision P>
GLM_FUNC_DECL mat<2, 3, T, P> diagonal2x3(
vec<2, T, P> const & v);
//! Build a diagonal matrix.
//! From GLM_GTX_matrix_operation extension.
template<typename T, precision P>
GLM_FUNC_DECL mat<2, 4, T, P> diagonal2x4(
vec<2, T, P> const & v);
//! Build a diagonal matrix.
//! From GLM_GTX_matrix_operation extension.
template<typename T, precision P>
GLM_FUNC_DECL mat<3, 2, T, P> diagonal3x2(
vec<2, T, P> const & v);
//! Build a diagonal matrix.
//! From GLM_GTX_matrix_operation extension.
template<typename T, precision P>
GLM_FUNC_DECL mat<3, 3, T, P> diagonal3x3(
vec<3, T, P> const & v);
//! Build a diagonal matrix.
//! From GLM_GTX_matrix_operation extension.
template<typename T, precision P>
GLM_FUNC_DECL mat<3, 4, T, P> diagonal3x4(
vec<3, T, P> const & v);
//! Build a diagonal matrix.
//! From GLM_GTX_matrix_operation extension.
template<typename T, precision P>
GLM_FUNC_DECL mat<4, 2, T, P> diagonal4x2(
vec<2, T, P> const & v);
//! Build a diagonal matrix.
//! From GLM_GTX_matrix_operation extension.
template<typename T, precision P>
GLM_FUNC_DECL mat<4, 3, T, P> diagonal4x3(
vec<3, T, P> const & v);
//! Build a diagonal matrix.
//! From GLM_GTX_matrix_operation extension.
template<typename T, precision P>
GLM_FUNC_DECL mat<4, 4, T, P> diagonal4x4(
vec<4, T, P> const & v);
/// @}
}//namespace glm
#include "matrix_operation.inl"

View file

@ -0,0 +1,118 @@
/// @ref gtx_matrix_operation
/// @file glm/gtx/matrix_operation.inl
namespace glm
{
template<typename T, precision P>
GLM_FUNC_QUALIFIER mat<2, 2, T, P> diagonal2x2
(
vec<2, T, P> const & v
)
{
mat<2, 2, T, P> Result(static_cast<T>(1));
Result[0][0] = v[0];
Result[1][1] = v[1];
return Result;
}
template<typename T, precision P>
GLM_FUNC_QUALIFIER mat<2, 3, T, P> diagonal2x3
(
vec<2, T, P> const & v
)
{
mat<2, 3, T, P> Result(static_cast<T>(1));
Result[0][0] = v[0];
Result[1][1] = v[1];
return Result;
}
template<typename T, precision P>
GLM_FUNC_QUALIFIER mat<2, 4, T, P> diagonal2x4
(
vec<2, T, P> const & v
)
{
mat<2, 4, T, P> Result(static_cast<T>(1));
Result[0][0] = v[0];
Result[1][1] = v[1];
return Result;
}
template<typename T, precision P>
GLM_FUNC_QUALIFIER mat<3, 2, T, P> diagonal3x2
(
vec<2, T, P> const & v
)
{
mat<3, 2, T, P> Result(static_cast<T>(1));
Result[0][0] = v[0];
Result[1][1] = v[1];
return Result;
}
template<typename T, precision P>
GLM_FUNC_QUALIFIER mat<3, 3, T, P> diagonal3x3
(
vec<3, T, P> const & v
)
{
mat<3, 3, T, P> Result(static_cast<T>(1));
Result[0][0] = v[0];
Result[1][1] = v[1];
Result[2][2] = v[2];
return Result;
}
template<typename T, precision P>
GLM_FUNC_QUALIFIER mat<3, 4, T, P> diagonal3x4
(
vec<3, T, P> const & v
)
{
mat<3, 4, T, P> Result(static_cast<T>(1));
Result[0][0] = v[0];
Result[1][1] = v[1];
Result[2][2] = v[2];
return Result;
}
template<typename T, precision P>
GLM_FUNC_QUALIFIER mat<4, 4, T, P> diagonal4x4
(
vec<4, T, P> const & v
)
{
mat<4, 4, T, P> Result(static_cast<T>(1));
Result[0][0] = v[0];
Result[1][1] = v[1];
Result[2][2] = v[2];
Result[3][3] = v[3];
return Result;
}
template<typename T, precision P>
GLM_FUNC_QUALIFIER mat<4, 3, T, P> diagonal4x3
(
vec<3, T, P> const & v
)
{
mat<4, 3, T, P> Result(static_cast<T>(1));
Result[0][0] = v[0];
Result[1][1] = v[1];
Result[2][2] = v[2];
return Result;
}
template<typename T, precision P>
GLM_FUNC_QUALIFIER mat<4, 2, T, P> diagonal4x2
(
vec<2, T, P> const & v
)
{
mat<4, 2, T, P> Result(static_cast<T>(1));
Result[0][0] = v[0];
Result[1][1] = v[1];
return Result;
}
}//namespace glm

77
glm/gtx/matrix_query.hpp Normal file
View file

@ -0,0 +1,77 @@
/// @ref gtx_matrix_query
/// @file glm/gtx/matrix_query.hpp
///
/// @see core (dependence)
/// @see gtx_vector_query (dependence)
///
/// @defgroup gtx_matrix_query GLM_GTX_matrix_query
/// @ingroup gtx
///
/// @brief Query to evaluate matrix properties
///
/// <glm/gtx/matrix_query.hpp> need to be included to use these functionalities.
#pragma once
// Dependency:
#include "../glm.hpp"
#include "../gtx/vector_query.hpp"
#include <limits>
#ifndef GLM_ENABLE_EXPERIMENTAL
# error "GLM: GLM_GTX_matrix_query is an experimental extension and may change in the future. Use #define GLM_ENABLE_EXPERIMENTAL before including it, if you really want to use it."
#endif
#if GLM_MESSAGES == GLM_MESSAGES_ENABLED && !defined(GLM_EXT_INCLUDED)
# pragma message("GLM: GLM_GTX_matrix_query extension included")
#endif
namespace glm
{
/// @addtogroup gtx_matrix_query
/// @{
/// Return whether a matrix a null matrix.
/// From GLM_GTX_matrix_query extension.
template<typename T, precision P>
GLM_FUNC_DECL bool isNull(mat<2, 2, T, P> const & m, T const & epsilon);
/// Return whether a matrix a null matrix.
/// From GLM_GTX_matrix_query extension.
template<typename T, precision P>
GLM_FUNC_DECL bool isNull(mat<3, 3, T, P> const & m, T const & epsilon);
/// Return whether a matrix is a null matrix.
/// From GLM_GTX_matrix_query extension.
template<typename T, precision P>
GLM_FUNC_DECL bool isNull(mat<4, 4, T, P> const & m, T const & epsilon);
/// Return whether a matrix is an identity matrix.
/// From GLM_GTX_matrix_query extension.
template<length_t C, length_t R, typename T, precision P, template<length_t, length_t, typename, precision> class matType>
GLM_FUNC_DECL bool isIdentity(matType<C, R, T, P> const & m, T const & epsilon);
/// Return whether a matrix is a normalized matrix.
/// From GLM_GTX_matrix_query extension.
template<typename T, precision P>
GLM_FUNC_DECL bool isNormalized(mat<2, 2, T, P> const & m, T const & epsilon);
/// Return whether a matrix is a normalized matrix.
/// From GLM_GTX_matrix_query extension.
template<typename T, precision P>
GLM_FUNC_DECL bool isNormalized(mat<3, 3, T, P> const & m, T const & epsilon);
/// Return whether a matrix is a normalized matrix.
/// From GLM_GTX_matrix_query extension.
template<typename T, precision P>
GLM_FUNC_DECL bool isNormalized(mat<4, 4, T, P> const & m, T const & epsilon);
/// Return whether a matrix is an orthonormalized matrix.
/// From GLM_GTX_matrix_query extension.
template<length_t C, length_t R, typename T, precision P, template<length_t, length_t, typename, precision> class matType>
GLM_FUNC_DECL bool isOrthogonal(matType<C, R, T, P> const & m, T const & epsilon);
/// @}
}//namespace glm
#include "matrix_query.inl"

114
glm/gtx/matrix_query.inl Normal file
View file

@ -0,0 +1,114 @@
/// @ref gtx_matrix_query
/// @file glm/gtx/matrix_query.inl
namespace glm
{
template<typename T, precision P>
GLM_FUNC_QUALIFIER bool isNull(mat<2, 2, T, P> const & m, T const & epsilon)
{
bool result = true;
for(length_t i = 0; result && i < m.length() ; ++i)
result = isNull(m[i], epsilon);
return result;
}
template<typename T, precision P>
GLM_FUNC_QUALIFIER bool isNull(mat<3, 3, T, P> const & m, T const & epsilon)
{
bool result = true;
for(length_t i = 0; result && i < m.length() ; ++i)
result = isNull(m[i], epsilon);
return result;
}
template<typename T, precision P>
GLM_FUNC_QUALIFIER bool isNull(mat<4, 4, T, P> const & m, T const & epsilon)
{
bool result = true;
for(length_t i = 0; result && i < m.length() ; ++i)
result = isNull(m[i], epsilon);
return result;
}
template<length_t C, length_t R, typename T, precision P, template<length_t, length_t, typename, precision> class matType>
GLM_FUNC_QUALIFIER bool isIdentity(matType<C, R, T, P> const & m, T const & epsilon)
{
bool result = true;
for(length_t i = 0; result && i < m[0].length() ; ++i)
{
for(length_t j = 0; result && j < i ; ++j)
result = abs(m[i][j]) <= epsilon;
if(result)
result = abs(m[i][i] - 1) <= epsilon;
for(length_t j = i + 1; result && j < m.length(); ++j)
result = abs(m[i][j]) <= epsilon;
}
return result;
}
template<typename T, precision P>
GLM_FUNC_QUALIFIER bool isNormalized(mat<2, 2, T, P> const & m, T const & epsilon)
{
bool result(true);
for(length_t i = 0; result && i < m.length(); ++i)
result = isNormalized(m[i], epsilon);
for(length_t i = 0; result && i < m.length(); ++i)
{
typename mat<2, 2, T, P>::col_type v;
for(length_t j = 0; j < m.length(); ++j)
v[j] = m[j][i];
result = isNormalized(v, epsilon);
}
return result;
}
template<typename T, precision P>
GLM_FUNC_QUALIFIER bool isNormalized(mat<3, 3, T, P> const & m, T const & epsilon)
{
bool result(true);
for(length_t i = 0; result && i < m.length(); ++i)
result = isNormalized(m[i], epsilon);
for(length_t i = 0; result && i < m.length(); ++i)
{
typename mat<3, 3, T, P>::col_type v;
for(length_t j = 0; j < m.length(); ++j)
v[j] = m[j][i];
result = isNormalized(v, epsilon);
}
return result;
}
template<typename T, precision P>
GLM_FUNC_QUALIFIER bool isNormalized(mat<4, 4, T, P> const & m, T const & epsilon)
{
bool result(true);
for(length_t i = 0; result && i < m.length(); ++i)
result = isNormalized(m[i], epsilon);
for(length_t i = 0; result && i < m.length(); ++i)
{
typename mat<4, 4, T, P>::col_type v;
for(length_t j = 0; j < m.length(); ++j)
v[j] = m[j][i];
result = isNormalized(v, epsilon);
}
return result;
}
template<length_t C, length_t R, typename T, precision P, template<length_t, length_t, typename, precision> class matType>
GLM_FUNC_QUALIFIER bool isOrthogonal(matType<C, R, T, P> const & m, T const & epsilon)
{
bool result(true);
for(length_t i(0); result && i < m.length() - 1; ++i)
for(length_t j(i + 1); result && j < m.length(); ++j)
result = areOrthogonal(m[i], m[j], epsilon);
if(result)
{
matType<C, R, T, P> tmp = transpose(m);
for(length_t i(0); result && i < m.length() - 1 ; ++i)
for(length_t j(i + 1); result && j < m.length(); ++j)
result = areOrthogonal(tmp[i], tmp[j], epsilon);
}
return result;
}
}//namespace glm

View file

@ -0,0 +1,81 @@
/// @ref gtx_matrix_transform_2d
/// @file glm/gtx/matrix_transform_2d.hpp
/// @author Miguel Ángel Pérez Martínez
///
/// @see core (dependence)
///
/// @defgroup gtx_matrix_transform_2d GLM_GTX_matrix_transform_2d
/// @ingroup gtx
///
/// @brief Defines functions that generate common 2d transformation matrices.
///
/// <glm/gtx/matrix_transform_2d.hpp> need to be included to use these functionalities.
#pragma once
// Dependency:
#include "../mat3x3.hpp"
#include "../vec2.hpp"
#ifndef GLM_ENABLE_EXPERIMENTAL
# error "GLM: GLM_GTX_matrix_transform_2d is an experimental extension and may change in the future. Use #define GLM_ENABLE_EXPERIMENTAL before including it, if you really want to use it."
#endif
#if GLM_MESSAGES == GLM_MESSAGES_ENABLED && !defined(GLM_EXT_INCLUDED)
# pragma message("GLM: GLM_GTX_matrix_transform_2d extension included")
#endif
namespace glm
{
/// @addtogroup gtx_matrix_transform_2d
/// @{
/// Builds a translation 3 * 3 matrix created from a vector of 2 components.
///
/// @param m Input matrix multiplied by this translation matrix.
/// @param v Coordinates of a translation vector.
template<typename T, precision P>
GLM_FUNC_QUALIFIER mat<3, 3, T, P> translate(
mat<3, 3, T, P> const& m,
vec<2, T, P> const & v);
/// Builds a rotation 3 * 3 matrix created from an angle.
///
/// @param m Input matrix multiplied by this translation matrix.
/// @param angle Rotation angle expressed in radians if GLM_FORCE_RADIANS is defined or degrees otherwise.
template<typename T, precision P>
GLM_FUNC_QUALIFIER mat<3, 3, T, P> rotate(
mat<3, 3, T, P> const& m,
T angle);
/// Builds a scale 3 * 3 matrix created from a vector of 2 components.
///
/// @param m Input matrix multiplied by this translation matrix.
/// @param v Coordinates of a scale vector.
template<typename T, precision P>
GLM_FUNC_QUALIFIER mat<3, 3, T, P> scale(
mat<3, 3, T, P> const& m,
vec<2, T, P> const & v);
/// Builds an horizontal (parallel to the x axis) shear 3 * 3 matrix.
///
/// @param m Input matrix multiplied by this translation matrix.
/// @param y Shear factor.
template<typename T, precision P>
GLM_FUNC_QUALIFIER mat<3, 3, T, P> shearX(
mat<3, 3, T, P> const& m,
T y);
/// Builds a vertical (parallel to the y axis) shear 3 * 3 matrix.
///
/// @param m Input matrix multiplied by this translation matrix.
/// @param x Shear factor.
template<typename T, precision P>
GLM_FUNC_QUALIFIER mat<3, 3, T, P> shearY(
mat<3, 3, T, P> const& m,
T x);
/// @}
}//namespace glm
#include "matrix_transform_2d.inl"

View file

@ -0,0 +1,69 @@
/// @ref gtx_matrix_transform_2d
/// @file glm/gtc/matrix_transform_2d.inl
/// @author Miguel Ángel Pérez Martínez
#include "../trigonometric.hpp"
namespace glm
{
template<typename T, precision P>
GLM_FUNC_QUALIFIER mat<3, 3, T, P> translate(
mat<3, 3, T, P> const& m,
vec<2, T, P> const & v)
{
mat<3, 3, T, P> Result(m);
Result[2] = m[0] * v[0] + m[1] * v[1] + m[2];
return Result;
}
template<typename T, precision P>
GLM_FUNC_QUALIFIER mat<3, 3, T, P> rotate(
mat<3, 3, T, P> const& m,
T angle)
{
T const a = angle;
T const c = cos(a);
T const s = sin(a);
mat<3, 3, T, P> Result(uninitialize);
Result[0] = m[0] * c + m[1] * s;
Result[1] = m[0] * -s + m[1] * c;
Result[2] = m[2];
return Result;
}
template<typename T, precision P>
GLM_FUNC_QUALIFIER mat<3, 3, T, P> scale(
mat<3, 3, T, P> const& m,
vec<2, T, P> const & v)
{
mat<3, 3, T, P> Result(uninitialize);
Result[0] = m[0] * v[0];
Result[1] = m[1] * v[1];
Result[2] = m[2];
return Result;
}
template<typename T, precision P>
GLM_FUNC_QUALIFIER mat<3, 3, T, P> shearX(
mat<3, 3, T, P> const& m,
T y)
{
mat<3, 3, T, P> Result(1);
Result[0][1] = y;
return m * Result;
}
template<typename T, precision P>
GLM_FUNC_QUALIFIER mat<3, 3, T, P> shearY(
mat<3, 3, T, P> const& m,
T x)
{
mat<3, 3, T, P> Result(1);
Result[1][0] = x;
return m * Result;
}
}//namespace glm

41
glm/gtx/mixed_product.hpp Normal file
View file

@ -0,0 +1,41 @@
/// @ref gtx_mixed_product
/// @file glm/gtx/mixed_product.hpp
///
/// @see core (dependence)
///
/// @defgroup gtx_mixed_product GLM_GTX_mixed_producte
/// @ingroup gtx
///
/// @brief Mixed product of 3 vectors.
///
/// <glm/gtx/mixed_product.hpp> need to be included to use these functionalities.
#pragma once
// Dependency:
#include "../glm.hpp"
#ifndef GLM_ENABLE_EXPERIMENTAL
# error "GLM: GLM_GTX_mixed_product is an experimental extension and may change in the future. Use #define GLM_ENABLE_EXPERIMENTAL before including it, if you really want to use it."
#endif
#if GLM_MESSAGES == GLM_MESSAGES_ENABLED && !defined(GLM_EXT_INCLUDED)
# pragma message("GLM: GLM_GTX_mixed_product extension included")
#endif
namespace glm
{
/// @addtogroup gtx_mixed_product
/// @{
/// @brief Mixed product of 3 vectors (from GLM_GTX_mixed_product extension)
template<typename T, precision P>
GLM_FUNC_DECL T mixedProduct(
vec<3, T, P> const & v1,
vec<3, T, P> const & v2,
vec<3, T, P> const & v3);
/// @}
}// namespace glm
#include "mixed_product.inl"

16
glm/gtx/mixed_product.inl Normal file
View file

@ -0,0 +1,16 @@
/// @ref gtx_mixed_product
/// @file glm/gtx/mixed_product.inl
namespace glm
{
template<typename T, precision P>
GLM_FUNC_QUALIFIER T mixedProduct
(
vec<3, T, P> const & v1,
vec<3, T, P> const & v2,
vec<3, T, P> const & v3
)
{
return dot(cross(v1, v2), v3);
}
}//namespace glm

90
glm/gtx/norm.hpp Normal file
View file

@ -0,0 +1,90 @@
/// @ref gtx_norm
/// @file glm/gtx/norm.hpp
///
/// @see core (dependence)
/// @see gtx_quaternion (dependence)
///
/// @defgroup gtx_norm GLM_GTX_norm
/// @ingroup gtx
///
/// @brief Various ways to compute vector norms.
///
/// <glm/gtx/norm.hpp> need to be included to use these functionalities.
#pragma once
// Dependency:
#include "../detail/func_geometric.hpp"
#include "../gtx/quaternion.hpp"
#ifndef GLM_ENABLE_EXPERIMENTAL
# error "GLM: GLM_GTX_norm is an experimental extension and may change in the future. Use #define GLM_ENABLE_EXPERIMENTAL before including it, if you really want to use it."
#endif
#if GLM_MESSAGES == GLM_MESSAGES_ENABLED && !defined(GLM_EXT_INCLUDED)
# pragma message("GLM: GLM_GTX_norm extension included")
#endif
namespace glm
{
/// @addtogroup gtx_norm
/// @{
/// Returns the squared length of x.
/// From GLM_GTX_norm extension.
template<length_t L, typename T, precision P, template<length_t, typename, precision> class vecType>
GLM_FUNC_DECL T length2(
vecType<L, T, P> const& x);
/// Returns the squared distance between p0 and p1, i.e., length2(p0 - p1).
/// From GLM_GTX_norm extension.
template<length_t L, typename T, precision P, template<length_t, typename, precision> class vecType>
GLM_FUNC_DECL T distance2(
vecType<L, T, P> const& p0,
vecType<L, T, P> const& p1);
//! Returns the L1 norm between x and y.
//! From GLM_GTX_norm extension.
template<typename T, precision P>
GLM_FUNC_DECL T l1Norm(
vec<3, T, P> const & x,
vec<3, T, P> const & y);
//! Returns the L1 norm of v.
//! From GLM_GTX_norm extension.
template<typename T, precision P>
GLM_FUNC_DECL T l1Norm(
vec<3, T, P> const & v);
//! Returns the L2 norm between x and y.
//! From GLM_GTX_norm extension.
template<typename T, precision P>
GLM_FUNC_DECL T l2Norm(
vec<3, T, P> const & x,
vec<3, T, P> const & y);
//! Returns the L2 norm of v.
//! From GLM_GTX_norm extension.
template<typename T, precision P>
GLM_FUNC_DECL T l2Norm(
vec<3, T, P> const & x);
//! Returns the L norm between x and y.
//! From GLM_GTX_norm extension.
template<typename T, precision P>
GLM_FUNC_DECL T lxNorm(
vec<3, T, P> const & x,
vec<3, T, P> const & y,
unsigned int Depth);
//! Returns the L norm of v.
//! From GLM_GTX_norm extension.
template<typename T, precision P>
GLM_FUNC_DECL T lxNorm(
vec<3, T, P> const & x,
unsigned int Depth);
/// @}
}//namespace glm
#include "norm.inl"

106
glm/gtx/norm.inl Normal file
View file

@ -0,0 +1,106 @@
/// @ref gtx_norm
/// @file glm/gtx/norm.inl
#include "../detail/precision.hpp"
namespace glm{
namespace detail
{
template<template<length_t, typename, precision> class vecType, length_t L, typename T, precision P, bool Aligned>
struct compute_length2
{
GLM_FUNC_QUALIFIER static T call(vecType<L, T, P> const & v)
{
return dot(v, v);
}
};
}//namespace detail
template<typename genType>
GLM_FUNC_QUALIFIER genType length2(genType x)
{
GLM_STATIC_ASSERT(std::numeric_limits<genType>::is_iec559, "'length2' accepts only floating-point inputs");
return x * x;
}
template<length_t L, typename T, precision P, template<length_t, typename, precision> class vecType>
GLM_FUNC_QUALIFIER T length2(vecType<L, T, P> const & v)
{
GLM_STATIC_ASSERT(std::numeric_limits<T>::is_iec559, "'length2' accepts only floating-point inputs");
return detail::compute_length2<vecType, L, T, P, detail::is_aligned<P>::value>::call(v);
}
template<typename T>
GLM_FUNC_QUALIFIER T distance2(T p0, T p1)
{
GLM_STATIC_ASSERT(std::numeric_limits<T>::is_iec559, "'distance2' accepts only floating-point inputs");
return length2(p1 - p0);
}
template<length_t L, typename T, precision P, template<length_t, typename, precision> class vecType>
GLM_FUNC_QUALIFIER T distance2(vecType<L, T, P> const & p0, vecType<L, T, P> const & p1)
{
GLM_STATIC_ASSERT(std::numeric_limits<T>::is_iec559, "'distance2' accepts only floating-point inputs");
return length2(p1 - p0);
}
template<typename T, precision P>
GLM_FUNC_QUALIFIER T l1Norm
(
vec<3, T, P> const & a,
vec<3, T, P> const & b
)
{
return abs(b.x - a.x) + abs(b.y - a.y) + abs(b.z - a.z);
}
template<typename T, precision P>
GLM_FUNC_QUALIFIER T l1Norm
(
vec<3, T, P> const & v
)
{
return abs(v.x) + abs(v.y) + abs(v.z);
}
template<typename T, precision P>
GLM_FUNC_QUALIFIER T l2Norm
(
vec<3, T, P> const & a,
vec<3, T, P> const & b
)
{
return length(b - a);
}
template<typename T, precision P>
GLM_FUNC_QUALIFIER T l2Norm
(
vec<3, T, P> const & v
)
{
return length(v);
}
template<typename T, precision P>
GLM_FUNC_QUALIFIER T lxNorm
(
vec<3, T, P> const & x,
vec<3, T, P> const & y,
unsigned int Depth
)
{
return pow(pow(y.x - x.x, T(Depth)) + pow(y.y - x.y, T(Depth)) + pow(y.z - x.z, T(Depth)), T(1) / T(Depth));
}
template<typename T, precision P>
GLM_FUNC_QUALIFIER T lxNorm
(
vec<3, T, P> const & v,
unsigned int Depth
)
{
return pow(pow(v.x, T(Depth)) + pow(v.y, T(Depth)) + pow(v.z, T(Depth)), T(1) / T(Depth));
}
}//namespace glm

43
glm/gtx/normal.hpp Normal file
View file

@ -0,0 +1,43 @@
/// @ref gtx_normal
/// @file glm/gtx/normal.hpp
///
/// @see core (dependence)
/// @see gtx_extented_min_max (dependence)
///
/// @defgroup gtx_normal GLM_GTX_normal
/// @ingroup gtx
///
/// @brief Compute the normal of a triangle.
///
/// <glm/gtx/normal.hpp> need to be included to use these functionalities.
#pragma once
// Dependency:
#include "../glm.hpp"
#ifndef GLM_ENABLE_EXPERIMENTAL
# error "GLM: GLM_GTX_normal is an experimental extension and may change in the future. Use #define GLM_ENABLE_EXPERIMENTAL before including it, if you really want to use it."
#endif
#if GLM_MESSAGES == GLM_MESSAGES_ENABLED && !defined(GLM_EXT_INCLUDED)
# pragma message("GLM: GLM_GTX_normal extension included")
#endif
namespace glm
{
/// @addtogroup gtx_normal
/// @{
//! Computes triangle normal from triangle points.
//! From GLM_GTX_normal extension.
template<typename T, precision P>
GLM_FUNC_DECL vec<3, T, P> triangleNormal(
vec<3, T, P> const & p1,
vec<3, T, P> const & p2,
vec<3, T, P> const & p3);
/// @}
}//namespace glm
#include "normal.inl"

16
glm/gtx/normal.inl Normal file
View file

@ -0,0 +1,16 @@
/// @ref gtx_normal
/// @file glm/gtx/normal.inl
namespace glm
{
template<typename T, precision P>
GLM_FUNC_QUALIFIER vec<3, T, P> triangleNormal
(
vec<3, T, P> const & p1,
vec<3, T, P> const & p2,
vec<3, T, P> const & p3
)
{
return normalize(cross(p1 - p2, p1 - p3));
}
}//namespace glm

49
glm/gtx/normalize_dot.hpp Normal file
View file

@ -0,0 +1,49 @@
/// @ref gtx_normalize_dot
/// @file glm/gtx/normalize_dot.hpp
///
/// @see core (dependence)
/// @see gtx_fast_square_root (dependence)
///
/// @defgroup gtx_normalize_dot GLM_GTX_normalize_dot
/// @ingroup gtx
///
/// @brief Dot product of vectors that need to be normalize with a single square root.
///
/// <glm/gtx/normalized_dot.hpp> need to be included to use these functionalities.
#pragma once
// Dependency:
#include "../gtx/fast_square_root.hpp"
#ifndef GLM_ENABLE_EXPERIMENTAL
# error "GLM: GLM_GTX_normalize_dot is an experimental extension and may change in the future. Use #define GLM_ENABLE_EXPERIMENTAL before including it, if you really want to use it."
#endif
#if GLM_MESSAGES == GLM_MESSAGES_ENABLED && !defined(GLM_EXT_INCLUDED)
# pragma message("GLM: GLM_GTX_normalize_dot extension included")
#endif
namespace glm
{
/// @addtogroup gtx_normalize_dot
/// @{
/// Normalize parameters and returns the dot product of x and y.
/// It's faster that dot(normalize(x), normalize(y)).
///
/// @see gtx_normalize_dot extension.
template<length_t L, typename T, precision P, template<length_t, typename, precision> class vecType>
GLM_FUNC_DECL T normalizeDot(vecType<L, T, P> const & x, vecType<L, T, P> const & y);
/// Normalize parameters and returns the dot product of x and y.
/// Faster that dot(fastNormalize(x), fastNormalize(y)).
///
/// @see gtx_normalize_dot extension.
template<length_t L, typename T, precision P, template<length_t, typename, precision> class vecType>
GLM_FUNC_DECL T fastNormalizeDot(vecType<L, T, P> const & x, vecType<L, T, P> const & y);
/// @}
}//namespace glm
#include "normalize_dot.inl"

17
glm/gtx/normalize_dot.inl Normal file
View file

@ -0,0 +1,17 @@
/// @ref gtx_normalize_dot
/// @file glm/gtx/normalize_dot.inl
namespace glm
{
template<length_t L, typename T, precision P, template<length_t, typename, precision> class vecType>
GLM_FUNC_QUALIFIER T normalizeDot(vecType<L, T, P> const & x, vecType<L, T, P> const & y)
{
return glm::dot(x, y) * glm::inversesqrt(glm::dot(x, x) * glm::dot(y, y));
}
template<length_t L, typename T, precision P, template<length_t, typename, precision> class vecType>
GLM_FUNC_QUALIFIER T fastNormalizeDot(vecType<L, T, P> const & x, vecType<L, T, P> const & y)
{
return glm::dot(x, y) * glm::fastInverseSqrt(glm::dot(x, x) * glm::dot(y, y));
}
}//namespace glm

View file

@ -0,0 +1,61 @@
/// @ref gtx_number_precision
/// @file glm/gtx/number_precision.hpp
///
/// @see core (dependence)
/// @see gtc_type_precision (dependence)
/// @see gtc_quaternion (dependence)
///
/// @defgroup gtx_number_precision GLM_GTX_number_precision
/// @ingroup gtx
///
/// @brief Defined size types.
///
/// <glm/gtx/number_precision.hpp> need to be included to use these functionalities.
#pragma once
// Dependency:
#include "../glm.hpp"
#include "../gtc/type_precision.hpp"
#ifndef GLM_ENABLE_EXPERIMENTAL
# error "GLM: GLM_GTX_number_precision is an experimental extension and may change in the future. Use #define GLM_ENABLE_EXPERIMENTAL before including it, if you really want to use it."
#endif
#if GLM_MESSAGES == GLM_MESSAGES_ENABLED && !defined(GLM_EXT_INCLUDED)
# pragma message("GLM: GLM_GTX_number_precision extension included")
#endif
namespace glm{
namespace gtx
{
/////////////////////////////
// Unsigned int vector types
/// @addtogroup gtx_number_precision
/// @{
typedef u8 u8vec1; //!< \brief 8bit unsigned integer scalar. (from GLM_GTX_number_precision extension)
typedef u16 u16vec1; //!< \brief 16bit unsigned integer scalar. (from GLM_GTX_number_precision extension)
typedef u32 u32vec1; //!< \brief 32bit unsigned integer scalar. (from GLM_GTX_number_precision extension)
typedef u64 u64vec1; //!< \brief 64bit unsigned integer scalar. (from GLM_GTX_number_precision extension)
//////////////////////
// Float vector types
typedef f32 f32vec1; //!< \brief Single-precision floating-point scalar. (from GLM_GTX_number_precision extension)
typedef f64 f64vec1; //!< \brief Single-precision floating-point scalar. (from GLM_GTX_number_precision extension)
//////////////////////
// Float matrix types
typedef f32 f32mat1; //!< \brief Single-precision floating-point scalar. (from GLM_GTX_number_precision extension)
typedef f32 f32mat1x1; //!< \brief Single-precision floating-point scalar. (from GLM_GTX_number_precision extension)
typedef f64 f64mat1; //!< \brief Double-precision floating-point scalar. (from GLM_GTX_number_precision extension)
typedef f64 f64mat1x1; //!< \brief Double-precision floating-point scalar. (from GLM_GTX_number_precision extension)
/// @}
}//namespace gtx
}//namespace glm
#include "number_precision.inl"

View file

@ -0,0 +1,7 @@
/// @ref gtx_number_precision
/// @file glm/gtx/number_precision.inl
namespace glm
{
}

54
glm/gtx/optimum_pow.hpp Normal file
View file

@ -0,0 +1,54 @@
/// @ref gtx_optimum_pow
/// @file glm/gtx/optimum_pow.hpp
///
/// @see core (dependence)
///
/// @defgroup gtx_optimum_pow GLM_GTX_optimum_pow
/// @ingroup gtx
///
/// @brief Integer exponentiation of power functions.
///
/// <glm/gtx/optimum_pow.hpp> need to be included to use these functionalities.
#pragma once
// Dependency:
#include "../glm.hpp"
#ifndef GLM_ENABLE_EXPERIMENTAL
# error "GLM: GLM_GTX_optimum_pow is an experimental extension and may change in the future. Use #define GLM_ENABLE_EXPERIMENTAL before including it, if you really want to use it."
#endif
#if GLM_MESSAGES == GLM_MESSAGES_ENABLED && !defined(GLM_EXT_INCLUDED)
# pragma message("GLM: GLM_GTX_optimum_pow extension included")
#endif
namespace glm{
namespace gtx
{
/// @addtogroup gtx_optimum_pow
/// @{
/// Returns x raised to the power of 2.
///
/// @see gtx_optimum_pow
template<typename genType>
GLM_FUNC_DECL genType pow2(genType const & x);
/// Returns x raised to the power of 3.
///
/// @see gtx_optimum_pow
template<typename genType>
GLM_FUNC_DECL genType pow3(genType const & x);
/// Returns x raised to the power of 4.
///
/// @see gtx_optimum_pow
template<typename genType>
GLM_FUNC_DECL genType pow4(genType const & x);
/// @}
}//namespace gtx
}//namespace glm
#include "optimum_pow.inl"

23
glm/gtx/optimum_pow.inl Normal file
View file

@ -0,0 +1,23 @@
/// @ref gtx_optimum_pow
/// @file glm/gtx/optimum_pow.inl
namespace glm
{
template<typename genType>
GLM_FUNC_QUALIFIER genType pow2(genType const & x)
{
return x * x;
}
template<typename genType>
GLM_FUNC_QUALIFIER genType pow3(genType const & x)
{
return x * x * x;
}
template<typename genType>
GLM_FUNC_QUALIFIER genType pow4(genType const & x)
{
return (x * x) * (x * x);
}
}//namespace glm

View file

@ -0,0 +1,49 @@
/// @ref gtx_orthonormalize
/// @file glm/gtx/orthonormalize.hpp
///
/// @see core (dependence)
/// @see gtx_extented_min_max (dependence)
///
/// @defgroup gtx_orthonormalize GLM_GTX_orthonormalize
/// @ingroup gtx
///
/// @brief Orthonormalize matrices.
///
/// <glm/gtx/orthonormalize.hpp> need to be included to use these functionalities.
#pragma once
// Dependency:
#include "../vec3.hpp"
#include "../mat3x3.hpp"
#include "../geometric.hpp"
#ifndef GLM_ENABLE_EXPERIMENTAL
# error "GLM: GLM_GTX_orthonormalize is an experimental extension and may change in the future. Use #define GLM_ENABLE_EXPERIMENTAL before including it, if you really want to use it."
#endif
#if GLM_MESSAGES == GLM_MESSAGES_ENABLED && !defined(GLM_EXT_INCLUDED)
# pragma message("GLM: GLM_GTX_orthonormalize extension included")
#endif
namespace glm
{
/// @addtogroup gtx_orthonormalize
/// @{
/// Returns the orthonormalized matrix of m.
///
/// @see gtx_orthonormalize
template<typename T, precision P>
GLM_FUNC_DECL mat<3, 3, T, P> orthonormalize(mat<3, 3, T, P> const & m);
/// Orthonormalizes x according y.
///
/// @see gtx_orthonormalize
template<typename T, precision P>
GLM_FUNC_DECL vec<3, T, P> orthonormalize(vec<3, T, P> const & x, vec<3, T, P> const & y);
/// @}
}//namespace glm
#include "orthonormalize.inl"

View file

@ -0,0 +1,30 @@
/// @ref gtx_orthonormalize
/// @file glm/gtx/orthonormalize.inl
namespace glm
{
template<typename T, precision P>
GLM_FUNC_QUALIFIER mat<3, 3, T, P> orthonormalize(mat<3, 3, T, P> const & m)
{
mat<3, 3, T, P> r = m;
r[0] = normalize(r[0]);
T d0 = dot(r[0], r[1]);
r[1] -= r[0] * d0;
r[1] = normalize(r[1]);
T d1 = dot(r[1], r[2]);
d0 = dot(r[0], r[2]);
r[2] -= r[0] * d0 + r[1] * d1;
r[2] = normalize(r[2]);
return r;
}
template<typename T, precision P>
GLM_FUNC_QUALIFIER vec<3, T, P> orthonormalize(vec<3, T, P> const & x, vec<3, T, P> const & y)
{
return normalize(x - y * dot(y, x));
}
}//namespace glm

43
glm/gtx/perpendicular.hpp Normal file
View file

@ -0,0 +1,43 @@
/// @ref gtx_perpendicular
/// @file glm/gtx/perpendicular.hpp
///
/// @see core (dependence)
/// @see gtx_projection (dependence)
///
/// @defgroup gtx_perpendicular GLM_GTX_perpendicular
/// @ingroup gtx
///
/// @brief Perpendicular of a vector from other one
///
/// <glm/gtx/perpendicular.hpp> need to be included to use these functionalities.
#pragma once
// Dependency:
#include "../glm.hpp"
#include "../gtx/projection.hpp"
#ifndef GLM_ENABLE_EXPERIMENTAL
# error "GLM: GLM_GTX_perpendicular is an experimental extension and may change in the future. Use #define GLM_ENABLE_EXPERIMENTAL before including it, if you really want to use it."
#endif
#if GLM_MESSAGES == GLM_MESSAGES_ENABLED && !defined(GLM_EXT_INCLUDED)
# pragma message("GLM: GLM_GTX_perpendicular extension included")
#endif
namespace glm
{
/// @addtogroup gtx_perpendicular
/// @{
//! Projects x a perpendicular axis of Normal.
//! From GLM_GTX_perpendicular extension.
template<typename vecType>
GLM_FUNC_DECL vecType perp(
vecType const & x,
vecType const & Normal);
/// @}
}//namespace glm
#include "perpendicular.inl"

15
glm/gtx/perpendicular.inl Normal file
View file

@ -0,0 +1,15 @@
/// @ref gtx_perpendicular
/// @file glm/gtx/perpendicular.inl
namespace glm
{
template<typename vecType>
GLM_FUNC_QUALIFIER vecType perp
(
vecType const & x,
vecType const & Normal
)
{
return x - proj(x, Normal);
}
}//namespace glm

View file

@ -0,0 +1,48 @@
/// @ref gtx_polar_coordinates
/// @file glm/gtx/polar_coordinates.hpp
///
/// @see core (dependence)
///
/// @defgroup gtx_polar_coordinates GLM_GTX_polar_coordinates
/// @ingroup gtx
///
/// @brief Conversion from Euclidean space to polar space and revert.
///
/// <glm/gtx/polar_coordinates.hpp> need to be included to use these functionalities.
#pragma once
// Dependency:
#include "../glm.hpp"
#ifndef GLM_ENABLE_EXPERIMENTAL
# error "GLM: GLM_GTX_polar_coordinates is an experimental extension and may change in the future. Use #define GLM_ENABLE_EXPERIMENTAL before including it, if you really want to use it."
#endif
#if GLM_MESSAGES == GLM_MESSAGES_ENABLED && !defined(GLM_EXT_INCLUDED)
# pragma message("GLM: GLM_GTX_polar_coordinates extension included")
#endif
namespace glm
{
/// @addtogroup gtx_polar_coordinates
/// @{
/// Convert Euclidean to Polar coordinates, x is the xz distance, y, the latitude and z the longitude.
///
/// @see gtx_polar_coordinates
template<typename T, precision P>
GLM_FUNC_DECL vec<3, T, P> polar(
vec<3, T, P> const & euclidean);
/// Convert Polar to Euclidean coordinates.
///
/// @see gtx_polar_coordinates
template<typename T, precision P>
GLM_FUNC_DECL vec<3, T, P> euclidean(
vec<2, T, P> const & polar);
/// @}
}//namespace glm
#include "polar_coordinates.inl"

View file

@ -0,0 +1,37 @@
/// @ref gtx_polar_coordinates
/// @file glm/gtx/polar_coordinates.inl
namespace glm
{
template<typename T, precision P>
GLM_FUNC_QUALIFIER vec<3, T, P> polar
(
vec<3, T, P> const & euclidean
)
{
T const Length(length(euclidean));
vec<3, T, P> const tmp(euclidean / Length);
T const xz_dist(sqrt(tmp.x * tmp.x + tmp.z * tmp.z));
return vec<3, T, P>(
asin(tmp.y), // latitude
atan(tmp.x, tmp.z), // longitude
xz_dist); // xz distance
}
template<typename T, precision P>
GLM_FUNC_QUALIFIER vec<3, T, P> euclidean
(
vec<2, T, P> const & polar
)
{
T const latitude(polar.x);
T const longitude(polar.y);
return vec<3, T, P>(
cos(latitude) * sin(longitude),
sin(latitude),
cos(latitude) * cos(longitude));
}
}//namespace glm

40
glm/gtx/projection.hpp Normal file
View file

@ -0,0 +1,40 @@
/// @ref gtx_projection
/// @file glm/gtx/projection.hpp
///
/// @see core (dependence)
///
/// @defgroup gtx_projection GLM_GTX_projection
/// @ingroup gtx
///
/// @brief Projection of a vector to other one
///
/// <glm/gtx/projection.hpp> need to be included to use these functionalities.
#pragma once
// Dependency:
#include "../geometric.hpp"
#ifndef GLM_ENABLE_EXPERIMENTAL
# error "GLM: GLM_GTX_projection is an experimental extension and may change in the future. Use #define GLM_ENABLE_EXPERIMENTAL before including it, if you really want to use it."
#endif
#if GLM_MESSAGES == GLM_MESSAGES_ENABLED && !defined(GLM_EXT_INCLUDED)
# pragma message("GLM: GLM_GTX_projection extension included")
#endif
namespace glm
{
/// @addtogroup gtx_projection
/// @{
/// Projects x on Normal.
///
/// @see gtx_projection
template<typename vecType>
GLM_FUNC_DECL vecType proj(vecType const & x, vecType const & Normal);
/// @}
}//namespace glm
#include "projection.inl"

11
glm/gtx/projection.inl Normal file
View file

@ -0,0 +1,11 @@
/// @ref gtx_projection
/// @file glm/gtx/projection.inl
namespace glm
{
template<typename vecType>
GLM_FUNC_QUALIFIER vecType proj(vecType const & x, vecType const & Normal)
{
return glm::dot(x, Normal) / glm::dot(Normal, Normal) * Normal;
}
}//namespace glm

189
glm/gtx/quaternion.hpp Normal file
View file

@ -0,0 +1,189 @@
/// @ref gtx_quaternion
/// @file glm/gtx/quaternion.hpp
///
/// @see core (dependence)
/// @see gtx_extented_min_max (dependence)
///
/// @defgroup gtx_quaternion GLM_GTX_quaternion
/// @ingroup gtx
///
/// @brief Extented quaternion types and functions
///
/// <glm/gtx/quaternion.hpp> need to be included to use these functionalities.
#pragma once
// Dependency:
#include "../glm.hpp"
#include "../gtc/constants.hpp"
#include "../gtc/quaternion.hpp"
#include "../gtx/norm.hpp"
#ifndef GLM_ENABLE_EXPERIMENTAL
# error "GLM: GLM_GTX_quaternion is an experimental extension and may change in the future. Use #define GLM_ENABLE_EXPERIMENTAL before including it, if you really want to use it."
#endif
#if GLM_MESSAGES == GLM_MESSAGES_ENABLED && !defined(GLM_EXT_INCLUDED)
# pragma message("GLM: GLM_GTX_quaternion extension included")
#endif
namespace glm
{
/// @addtogroup gtx_quaternion
/// @{
/// Compute a cross product between a quaternion and a vector.
///
/// @see gtx_quaternion
template<typename T, precision P>
GLM_FUNC_DECL vec<3, T, P> cross(
tquat<T, P> const & q,
vec<3, T, P> const & v);
//! Compute a cross product between a vector and a quaternion.
///
/// @see gtx_quaternion
template<typename T, precision P>
GLM_FUNC_DECL vec<3, T, P> cross(
vec<3, T, P> const & v,
tquat<T, P> const & q);
//! Compute a point on a path according squad equation.
//! q1 and q2 are control points; s1 and s2 are intermediate control points.
///
/// @see gtx_quaternion
template<typename T, precision P>
GLM_FUNC_DECL tquat<T, P> squad(
tquat<T, P> const & q1,
tquat<T, P> const & q2,
tquat<T, P> const & s1,
tquat<T, P> const & s2,
T const & h);
//! Returns an intermediate control point for squad interpolation.
///
/// @see gtx_quaternion
template<typename T, precision P>
GLM_FUNC_DECL tquat<T, P> intermediate(
tquat<T, P> const & prev,
tquat<T, P> const & curr,
tquat<T, P> const & next);
//! Returns a exp of a quaternion.
///
/// @see gtx_quaternion
template<typename T, precision P>
GLM_FUNC_DECL tquat<T, P> exp(
tquat<T, P> const & q);
//! Returns a log of a quaternion.
///
/// @see gtx_quaternion
template<typename T, precision P>
GLM_FUNC_DECL tquat<T, P> log(
tquat<T, P> const & q);
/// Returns x raised to the y power.
///
/// @see gtx_quaternion
template<typename T, precision P>
GLM_FUNC_DECL tquat<T, P> pow(
tquat<T, P> const & x,
T const & y);
//! Returns quarternion square root.
///
/// @see gtx_quaternion
//template<typename T, precision P>
//tquat<T, P> sqrt(
// tquat<T, P> const & q);
//! Rotates a 3 components vector by a quaternion.
///
/// @see gtx_quaternion
template<typename T, precision P>
GLM_FUNC_DECL vec<3, T, P> rotate(
tquat<T, P> const & q,
vec<3, T, P> const & v);
/// Rotates a 4 components vector by a quaternion.
///
/// @see gtx_quaternion
template<typename T, precision P>
GLM_FUNC_DECL vec<4, T, P> rotate(
tquat<T, P> const & q,
vec<4, T, P> const & v);
/// Extract the real component of a quaternion.
///
/// @see gtx_quaternion
template<typename T, precision P>
GLM_FUNC_DECL T extractRealComponent(
tquat<T, P> const & q);
/// Converts a quaternion to a 3 * 3 matrix.
///
/// @see gtx_quaternion
template<typename T, precision P>
GLM_FUNC_DECL mat<3, 3, T, P> toMat3(
tquat<T, P> const & x){return mat3_cast(x);}
/// Converts a quaternion to a 4 * 4 matrix.
///
/// @see gtx_quaternion
template<typename T, precision P>
GLM_FUNC_DECL mat<4, 4, T, P> toMat4(
tquat<T, P> const & x){return mat4_cast(x);}
/// Converts a 3 * 3 matrix to a quaternion.
///
/// @see gtx_quaternion
template<typename T, precision P>
GLM_FUNC_DECL tquat<T, P> toQuat(
mat<3, 3, T, P> const& x){return quat_cast(x);}
/// Converts a 4 * 4 matrix to a quaternion.
///
/// @see gtx_quaternion
template<typename T, precision P>
GLM_FUNC_DECL tquat<T, P> toQuat(
mat<4, 4, T, P> const& x){return quat_cast(x);}
/// Quaternion interpolation using the rotation short path.
///
/// @see gtx_quaternion
template<typename T, precision P>
GLM_FUNC_DECL tquat<T, P> shortMix(
tquat<T, P> const & x,
tquat<T, P> const & y,
T const & a);
/// Quaternion normalized linear interpolation.
///
/// @see gtx_quaternion
template<typename T, precision P>
GLM_FUNC_DECL tquat<T, P> fastMix(
tquat<T, P> const & x,
tquat<T, P> const & y,
T const & a);
/// Compute the rotation between two vectors.
/// param orig vector, needs to be normalized
/// param dest vector, needs to be normalized
///
/// @see gtx_quaternion
template<typename T, precision P>
GLM_FUNC_DECL tquat<T, P> rotation(
vec<3, T, P> const & orig,
vec<3, T, P> const & dest);
/// Returns the squared length of x.
///
/// @see gtx_quaternion
template<typename T, precision P>
GLM_FUNC_DECL T length2(tquat<T, P> const & q);
/// @}
}//namespace glm
#include "quaternion.inl"

212
glm/gtx/quaternion.inl Normal file
View file

@ -0,0 +1,212 @@
/// @ref gtx_quaternion
/// @file glm/gtx/quaternion.inl
#include <limits>
#include "../gtc/constants.hpp"
namespace glm
{
template<typename T, precision P>
GLM_FUNC_QUALIFIER vec<3, T, P> cross(vec<3, T, P> const& v, tquat<T, P> const& q)
{
return inverse(q) * v;
}
template<typename T, precision P>
GLM_FUNC_QUALIFIER vec<3, T, P> cross(tquat<T, P> const& q, vec<3, T, P> const& v)
{
return q * v;
}
template<typename T, precision P>
GLM_FUNC_QUALIFIER tquat<T, P> squad
(
tquat<T, P> const & q1,
tquat<T, P> const & q2,
tquat<T, P> const & s1,
tquat<T, P> const & s2,
T const & h)
{
return mix(mix(q1, q2, h), mix(s1, s2, h), static_cast<T>(2) * (static_cast<T>(1) - h) * h);
}
template<typename T, precision P>
GLM_FUNC_QUALIFIER tquat<T, P> intermediate
(
tquat<T, P> const & prev,
tquat<T, P> const & curr,
tquat<T, P> const & next
)
{
tquat<T, P> invQuat = inverse(curr);
return exp((log(next + invQuat) + log(prev + invQuat)) / static_cast<T>(-4)) * curr;
}
template<typename T, precision P>
GLM_FUNC_QUALIFIER tquat<T, P> exp(tquat<T, P> const& q)
{
vec<3, T, P> u(q.x, q.y, q.z);
T const Angle = glm::length(u);
if (Angle < epsilon<T>())
return tquat<T, P>();
vec<3, T, P> const v(u / Angle);
return tquat<T, P>(cos(Angle), sin(Angle) * v);
}
template<typename T, precision P>
GLM_FUNC_QUALIFIER tquat<T, P> log(tquat<T, P> const& q)
{
vec<3, T, P> u(q.x, q.y, q.z);
T Vec3Len = length(u);
if (Vec3Len < epsilon<T>())
{
if(q.w > static_cast<T>(0))
return tquat<T, P>(log(q.w), static_cast<T>(0), static_cast<T>(0), static_cast<T>(0));
else if(q.w < static_cast<T>(0))
return tquat<T, P>(log(-q.w), pi<T>(), static_cast<T>(0), static_cast<T>(0));
else
return tquat<T, P>(std::numeric_limits<T>::infinity(), std::numeric_limits<T>::infinity(), std::numeric_limits<T>::infinity(), std::numeric_limits<T>::infinity());
}
else
{
T t = atan(Vec3Len, T(q.w)) / Vec3Len;
T QuatLen2 = Vec3Len * Vec3Len + q.w * q.w;
return tquat<T, P>(static_cast<T>(0.5) * log(QuatLen2), t * q.x, t * q.y, t * q.z);
}
}
template<typename T, precision P>
GLM_FUNC_QUALIFIER tquat<T, P> pow(tquat<T, P> const & x, T const & y)
{
//Raising to the power of 0 should yield 1
//Needed to prevent a division by 0 error later on
if(y > -epsilon<T>() && y < epsilon<T>())
return tquat<T, P>(1,0,0,0);
//To deal with non-unit quaternions
T magnitude = sqrt(x.x * x.x + x.y * x.y + x.z * x.z + x.w *x.w);
//Equivalent to raising a real number to a power
//Needed to prevent a division by 0 error later on
if(abs(x.w / magnitude) > static_cast<T>(1) - epsilon<T>() && abs(x.w / magnitude) < static_cast<T>(1) + epsilon<T>())
return tquat<T, P>(pow(x.w, y),0,0,0);
T Angle = acos(x.w / magnitude);
T NewAngle = Angle * y;
T Div = sin(NewAngle) / sin(Angle);
T Mag = pow(magnitude, y - static_cast<T>(1));
return tquat<T, P>(cos(NewAngle) * magnitude * Mag, x.x * Div * Mag, x.y * Div * Mag, x.z * Div * Mag);
}
template<typename T, precision P>
GLM_FUNC_QUALIFIER vec<3, T, P> rotate(tquat<T, P> const& q, vec<3, T, P> const& v)
{
return q * v;
}
template<typename T, precision P>
GLM_FUNC_QUALIFIER vec<4, T, P> rotate(tquat<T, P> const& q, vec<4, T, P> const& v)
{
return q * v;
}
template<typename T, precision P>
GLM_FUNC_QUALIFIER T extractRealComponent(tquat<T, P> const& q)
{
T w = static_cast<T>(1) - q.x * q.x - q.y * q.y - q.z * q.z;
if(w < T(0))
return T(0);
else
return -sqrt(w);
}
template<typename T, precision P>
GLM_FUNC_QUALIFIER T length2(tquat<T, P> const& q)
{
return q.x * q.x + q.y * q.y + q.z * q.z + q.w * q.w;
}
template<typename T, precision P>
GLM_FUNC_QUALIFIER tquat<T, P> shortMix(tquat<T, P> const& x, tquat<T, P> const& y, T const& a)
{
if(a <= static_cast<T>(0)) return x;
if(a >= static_cast<T>(1)) return y;
T fCos = dot(x, y);
tquat<T, P> y2(y); //BUG!!! tquat<T> y2;
if(fCos < static_cast<T>(0))
{
y2 = -y;
fCos = -fCos;
}
//if(fCos > 1.0f) // problem
T k0, k1;
if(fCos > (static_cast<T>(1) - epsilon<T>()))
{
k0 = static_cast<T>(1) - a;
k1 = static_cast<T>(0) + a; //BUG!!! 1.0f + a;
}
else
{
T fSin = sqrt(T(1) - fCos * fCos);
T fAngle = atan(fSin, fCos);
T fOneOverSin = static_cast<T>(1) / fSin;
k0 = sin((static_cast<T>(1) - a) * fAngle) * fOneOverSin;
k1 = sin((static_cast<T>(0) + a) * fAngle) * fOneOverSin;
}
return tquat<T, P>(
k0 * x.w + k1 * y2.w,
k0 * x.x + k1 * y2.x,
k0 * x.y + k1 * y2.y,
k0 * x.z + k1 * y2.z);
}
template<typename T, precision P>
GLM_FUNC_QUALIFIER tquat<T, P> fastMix(tquat<T, P> const& x, tquat<T, P> const& y, T const & a)
{
return glm::normalize(x * (static_cast<T>(1) - a) + (y * a));
}
template<typename T, precision P>
GLM_FUNC_QUALIFIER tquat<T, P> rotation(vec<3, T, P> const& orig, vec<3, T, P> const& dest)
{
T cosTheta = dot(orig, dest);
vec<3, T, P> rotationAxis;
if(cosTheta >= static_cast<T>(1) - epsilon<T>())
return quat();
if(cosTheta < static_cast<T>(-1) + epsilon<T>())
{
// special case when vectors in opposite directions :
// there is no "ideal" rotation axis
// So guess one; any will do as long as it's perpendicular to start
// This implementation favors a rotation around the Up axis (Y),
// since it's often what you want to do.
rotationAxis = cross(vec<3, T, P>(0, 0, 1), orig);
if(length2(rotationAxis) < epsilon<T>()) // bad luck, they were parallel, try again!
rotationAxis = cross(vec<3, T, P>(1, 0, 0), orig);
rotationAxis = normalize(rotationAxis);
return angleAxis(pi<T>(), rotationAxis);
}
// Implementation from Stan Melax's Game Programming Gems 1 article
rotationAxis = cross(orig, dest);
T s = sqrt((T(1) + cosTheta) * static_cast<T>(2));
T invs = static_cast<T>(1) / s;
return tquat<T, P>(
s * static_cast<T>(0.5f),
rotationAxis.x * invs,
rotationAxis.y * invs,
rotationAxis.z * invs);
}
}//namespace glm

89
glm/gtx/range.hpp Normal file
View file

@ -0,0 +1,89 @@
/// @ref gtx_range
/// @file glm/gtx/range.hpp
/// @author Joshua Moerman
///
/// @defgroup gtx_range GLM_GTX_range
/// @ingroup gtx
///
/// @brief Defines begin and end for vectors and matrices. Useful for range-based for loop.
/// The range is defined over the elements, not over columns or rows (e.g. mat4 has 16 elements).
///
/// <glm/gtx/range.hpp> need to be included to use these functionalities.
#pragma once
// Dependencies
#include "../detail/setup.hpp"
#ifndef GLM_ENABLE_EXPERIMENTAL
# error "GLM: GLM_GTX_range is an experimental extension and may change in the future. Use #define GLM_ENABLE_EXPERIMENTAL before including it, if you really want to use it."
#endif
#if !GLM_HAS_RANGE_FOR
# error "GLM_GTX_range requires C++11 suppport or 'range for'"
#endif
#include "../gtc/type_ptr.hpp"
#include "../gtc/vec1.hpp"
namespace glm
{
/// @addtogroup gtx_range
/// @{
template<typename T, precision P>
inline length_t components(vec<1, T, P> const & v)
{
return v.length();
}
template<typename T, precision P>
inline length_t components(vec<2, T, P> const & v)
{
return v.length();
}
template<typename T, precision P>
inline length_t components(vec<3, T, P> const & v)
{
return v.length();
}
template<typename T, precision P>
inline length_t components(vec<4, T, P> const & v)
{
return v.length();
}
template<typename genType>
inline length_t components(genType const & m)
{
return m.length() * m[0].length();
}
template<typename genType>
inline typename genType::value_type const * begin(genType const & v)
{
return value_ptr(v);
}
template<typename genType>
inline typename genType::value_type const * end(genType const & v)
{
return begin(v) + components(v);
}
template<typename genType>
inline typename genType::value_type * begin(genType& v)
{
return value_ptr(v);
}
template<typename genType>
inline typename genType::value_type * end(genType& v)
{
return begin(v) + components(v);
}
/// @}
}//namespace glm

51
glm/gtx/raw_data.hpp Normal file
View file

@ -0,0 +1,51 @@
/// @ref gtx_raw_data
/// @file glm/gtx/raw_data.hpp
///
/// @see core (dependence)
///
/// @defgroup gtx_raw_data GLM_GTX_raw_data
/// @ingroup gtx
///
/// @brief Projection of a vector to other one
///
/// <glm/gtx/raw_data.hpp> need to be included to use these functionalities.
#pragma once
// Dependencies
#include "../detail/setup.hpp"
#include "../detail/type_int.hpp"
#ifndef GLM_ENABLE_EXPERIMENTAL
# error "GLM: GLM_GTX_raw_data is an experimental extension and may change in the future. Use #define GLM_ENABLE_EXPERIMENTAL before including it, if you really want to use it."
#endif
#if GLM_MESSAGES == GLM_MESSAGES_ENABLED && !defined(GLM_EXT_INCLUDED)
# pragma message("GLM: GLM_GTX_raw_data extension included")
#endif
namespace glm
{
/// @addtogroup gtx_raw_data
/// @{
//! Type for byte numbers.
//! From GLM_GTX_raw_data extension.
typedef detail::uint8 byte;
//! Type for word numbers.
//! From GLM_GTX_raw_data extension.
typedef detail::uint16 word;
//! Type for dword numbers.
//! From GLM_GTX_raw_data extension.
typedef detail::uint32 dword;
//! Type for qword numbers.
//! From GLM_GTX_raw_data extension.
typedef detail::uint64 qword;
/// @}
}// namespace glm
#include "raw_data.inl"

2
glm/gtx/raw_data.inl Normal file
View file

@ -0,0 +1,2 @@
/// @ref gtx_raw_data
/// @file glm/gtx/raw_data.inl

View file

@ -0,0 +1,68 @@
/// @ref gtx_rotate_normalized_axis
/// @file glm/gtx/rotate_normalized_axis.hpp
///
/// @see core (dependence)
/// @see gtc_matrix_transform
/// @see gtc_quaternion
///
/// @defgroup gtx_rotate_normalized_axis GLM_GTX_rotate_normalized_axis
/// @ingroup gtx
///
/// @brief Quaternions and matrices rotations around normalized axis.
///
/// <glm/gtx/rotate_normalized_axis.hpp> need to be included to use these functionalities.
#pragma once
// Dependency:
#include "../glm.hpp"
#include "../gtc/epsilon.hpp"
#include "../gtc/quaternion.hpp"
#ifndef GLM_ENABLE_EXPERIMENTAL
# error "GLM: GLM_GTX_rotate_normalized_axis is an experimental extension and may change in the future. Use #define GLM_ENABLE_EXPERIMENTAL before including it, if you really want to use it."
#endif
#if GLM_MESSAGES == GLM_MESSAGES_ENABLED && !defined(GLM_EXT_INCLUDED)
# pragma message("GLM: GLM_GTX_rotate_normalized_axis extension included")
#endif
namespace glm
{
/// @addtogroup gtx_rotate_normalized_axis
/// @{
/// Builds a rotation 4 * 4 matrix created from a normalized axis and an angle.
///
/// @param m Input matrix multiplied by this rotation matrix.
/// @param angle Rotation angle expressed in radians if GLM_FORCE_RADIANS is define or degrees otherwise.
/// @param axis Rotation axis, must be normalized.
/// @tparam T Value type used to build the matrix. Currently supported: half (not recommanded), float or double.
///
/// @see gtx_rotate_normalized_axis
/// @see - rotate(T angle, T x, T y, T z)
/// @see - rotate(mat<4, 4, T, P> const & m, T angle, T x, T y, T z)
/// @see - rotate(T angle, vec<3, T, P> const & v)
template<typename T, precision P>
GLM_FUNC_DECL mat<4, 4, T, P> rotateNormalizedAxis(
mat<4, 4, T, P> const& m,
T const & angle,
vec<3, T, P> const & axis);
/// Rotates a quaternion from a vector of 3 components normalized axis and an angle.
///
/// @param q Source orientation
/// @param angle Angle expressed in radians if GLM_FORCE_RADIANS is define or degrees otherwise.
/// @param axis Normalized axis of the rotation, must be normalized.
///
/// @see gtx_rotate_normalized_axis
template<typename T, precision P>
GLM_FUNC_DECL tquat<T, P> rotateNormalizedAxis(
tquat<T, P> const & q,
T const & angle,
vec<3, T, P> const & axis);
/// @}
}//namespace glm
#include "rotate_normalized_axis.inl"

View file

@ -0,0 +1,59 @@
/// @ref gtx_rotate_normalized_axis
/// @file glm/gtx/rotate_normalized_axis.inl
namespace glm
{
template<typename T, precision P>
GLM_FUNC_QUALIFIER mat<4, 4, T, P> rotateNormalizedAxis
(
mat<4, 4, T, P> const& m,
T const & angle,
vec<3, T, P> const & v
)
{
T const a = angle;
T const c = cos(a);
T const s = sin(a);
vec<3, T, P> const axis(v);
vec<3, T, P> const temp((static_cast<T>(1) - c) * axis);
mat<4, 4, T, P> Rotate(uninitialize);
Rotate[0][0] = c + temp[0] * axis[0];
Rotate[0][1] = 0 + temp[0] * axis[1] + s * axis[2];
Rotate[0][2] = 0 + temp[0] * axis[2] - s * axis[1];
Rotate[1][0] = 0 + temp[1] * axis[0] - s * axis[2];
Rotate[1][1] = c + temp[1] * axis[1];
Rotate[1][2] = 0 + temp[1] * axis[2] + s * axis[0];
Rotate[2][0] = 0 + temp[2] * axis[0] + s * axis[1];
Rotate[2][1] = 0 + temp[2] * axis[1] - s * axis[0];
Rotate[2][2] = c + temp[2] * axis[2];
mat<4, 4, T, P> Result(uninitialize);
Result[0] = m[0] * Rotate[0][0] + m[1] * Rotate[0][1] + m[2] * Rotate[0][2];
Result[1] = m[0] * Rotate[1][0] + m[1] * Rotate[1][1] + m[2] * Rotate[1][2];
Result[2] = m[0] * Rotate[2][0] + m[1] * Rotate[2][1] + m[2] * Rotate[2][2];
Result[3] = m[3];
return Result;
}
template<typename T, precision P>
GLM_FUNC_QUALIFIER tquat<T, P> rotateNormalizedAxis
(
tquat<T, P> const & q,
T const & angle,
vec<3, T, P> const & v
)
{
vec<3, T, P> const Tmp(v);
T const AngleRad(angle);
T const Sin = sin(AngleRad * T(0.5));
return q * tquat<T, P>(cos(AngleRad * static_cast<T>(0.5)), Tmp.x * Sin, Tmp.y * Sin, Tmp.z * Sin);
//return gtc::quaternion::cross(q, tquat<T, P>(cos(AngleRad * T(0.5)), Tmp.x * fSin, Tmp.y * fSin, Tmp.z * fSin));
}
}//namespace glm

121
glm/gtx/rotate_vector.hpp Normal file
View file

@ -0,0 +1,121 @@
/// @ref gtx_rotate_vector
/// @file glm/gtx/rotate_vector.hpp
///
/// @see core (dependence)
/// @see gtx_transform (dependence)
///
/// @defgroup gtx_rotate_vector GLM_GTX_rotate_vector
/// @ingroup gtx
///
/// @brief Function to directly rotate a vector
///
/// <glm/gtx/rotate_vector.hpp> need to be included to use these functionalities.
#pragma once
// Dependency:
#include "../glm.hpp"
#include "../gtx/transform.hpp"
#ifndef GLM_ENABLE_EXPERIMENTAL
# error "GLM: GLM_GTX_rotate_vector is an experimental extension and may change in the future. Use #define GLM_ENABLE_EXPERIMENTAL before including it, if you really want to use it."
#endif
#if GLM_MESSAGES == GLM_MESSAGES_ENABLED && !defined(GLM_EXT_INCLUDED)
# pragma message("GLM: GLM_GTX_rotate_vector extension included")
#endif
namespace glm
{
/// @addtogroup gtx_rotate_vector
/// @{
/// Returns Spherical interpolation between two vectors
///
/// @param x A first vector
/// @param y A second vector
/// @param a Interpolation factor. The interpolation is defined beyond the range [0, 1].
///
/// @see gtx_rotate_vector
template<typename T, precision P>
GLM_FUNC_DECL vec<3, T, P> slerp(
vec<3, T, P> const & x,
vec<3, T, P> const & y,
T const & a);
//! Rotate a two dimensional vector.
//! From GLM_GTX_rotate_vector extension.
template<typename T, precision P>
GLM_FUNC_DECL vec<2, T, P> rotate(
vec<2, T, P> const & v,
T const & angle);
//! Rotate a three dimensional vector around an axis.
//! From GLM_GTX_rotate_vector extension.
template<typename T, precision P>
GLM_FUNC_DECL vec<3, T, P> rotate(
vec<3, T, P> const & v,
T const & angle,
vec<3, T, P> const & normal);
//! Rotate a four dimensional vector around an axis.
//! From GLM_GTX_rotate_vector extension.
template<typename T, precision P>
GLM_FUNC_DECL vec<4, T, P> rotate(
vec<4, T, P> const & v,
T const & angle,
vec<3, T, P> const & normal);
//! Rotate a three dimensional vector around the X axis.
//! From GLM_GTX_rotate_vector extension.
template<typename T, precision P>
GLM_FUNC_DECL vec<3, T, P> rotateX(
vec<3, T, P> const & v,
T const & angle);
//! Rotate a three dimensional vector around the Y axis.
//! From GLM_GTX_rotate_vector extension.
template<typename T, precision P>
GLM_FUNC_DECL vec<3, T, P> rotateY(
vec<3, T, P> const & v,
T const & angle);
//! Rotate a three dimensional vector around the Z axis.
//! From GLM_GTX_rotate_vector extension.
template<typename T, precision P>
GLM_FUNC_DECL vec<3, T, P> rotateZ(
vec<3, T, P> const & v,
T const & angle);
//! Rotate a four dimentionnals vector around the X axis.
//! From GLM_GTX_rotate_vector extension.
template<typename T, precision P>
GLM_FUNC_DECL vec<4, T, P> rotateX(
vec<4, T, P> const & v,
T const & angle);
//! Rotate a four dimensional vector around the X axis.
//! From GLM_GTX_rotate_vector extension.
template<typename T, precision P>
GLM_FUNC_DECL vec<4, T, P> rotateY(
vec<4, T, P> const & v,
T const & angle);
//! Rotate a four dimensional vector around the X axis.
//! From GLM_GTX_rotate_vector extension.
template<typename T, precision P>
GLM_FUNC_DECL vec<4, T, P> rotateZ(
vec<4, T, P> const & v,
T const & angle);
//! Build a rotation matrix from a normal and a up vector.
//! From GLM_GTX_rotate_vector extension.
template<typename T, precision P>
GLM_FUNC_DECL mat<4, 4, T, P> orientation(
vec<3, T, P> const & Normal,
vec<3, T, P> const & Up);
/// @}
}//namespace glm
#include "rotate_vector.inl"

188
glm/gtx/rotate_vector.inl Normal file
View file

@ -0,0 +1,188 @@
/// @ref gtx_rotate_vector
/// @file glm/gtx/rotate_vector.inl
namespace glm
{
template<typename T, precision P>
GLM_FUNC_QUALIFIER vec<3, T, P> slerp
(
vec<3, T, P> const & x,
vec<3, T, P> const & y,
T const & a
)
{
// get cosine of angle between vectors (-1 -> 1)
T CosAlpha = dot(x, y);
// get angle (0 -> pi)
T Alpha = acos(CosAlpha);
// get sine of angle between vectors (0 -> 1)
T SinAlpha = sin(Alpha);
// this breaks down when SinAlpha = 0, i.e. Alpha = 0 or pi
T t1 = sin((static_cast<T>(1) - a) * Alpha) / SinAlpha;
T t2 = sin(a * Alpha) / SinAlpha;
// interpolate src vectors
return x * t1 + y * t2;
}
template<typename T, precision P>
GLM_FUNC_QUALIFIER vec<2, T, P> rotate
(
vec<2, T, P> const & v,
T const & angle
)
{
vec<2, T, P> Result;
T const Cos(cos(angle));
T const Sin(sin(angle));
Result.x = v.x * Cos - v.y * Sin;
Result.y = v.x * Sin + v.y * Cos;
return Result;
}
template<typename T, precision P>
GLM_FUNC_QUALIFIER vec<3, T, P> rotate
(
vec<3, T, P> const & v,
T const & angle,
vec<3, T, P> const & normal
)
{
return mat<3, 3, T, P>(glm::rotate(angle, normal)) * v;
}
/*
template<typename T, precision P>
GLM_FUNC_QUALIFIER vec<3, T, P> rotateGTX(
const vec<3, T, P>& x,
T angle,
const vec<3, T, P>& normal)
{
const T Cos = cos(radians(angle));
const T Sin = sin(radians(angle));
return x * Cos + ((x * normal) * (T(1) - Cos)) * normal + cross(x, normal) * Sin;
}
*/
template<typename T, precision P>
GLM_FUNC_QUALIFIER vec<4, T, P> rotate
(
vec<4, T, P> const & v,
T const & angle,
vec<3, T, P> const & normal
)
{
return rotate(angle, normal) * v;
}
template<typename T, precision P>
GLM_FUNC_QUALIFIER vec<3, T, P> rotateX
(
vec<3, T, P> const & v,
T const & angle
)
{
vec<3, T, P> Result(v);
T const Cos(cos(angle));
T const Sin(sin(angle));
Result.y = v.y * Cos - v.z * Sin;
Result.z = v.y * Sin + v.z * Cos;
return Result;
}
template<typename T, precision P>
GLM_FUNC_QUALIFIER vec<3, T, P> rotateY
(
vec<3, T, P> const & v,
T const & angle
)
{
vec<3, T, P> Result = v;
T const Cos(cos(angle));
T const Sin(sin(angle));
Result.x = v.x * Cos + v.z * Sin;
Result.z = -v.x * Sin + v.z * Cos;
return Result;
}
template<typename T, precision P>
GLM_FUNC_QUALIFIER vec<3, T, P> rotateZ
(
vec<3, T, P> const & v,
T const & angle
)
{
vec<3, T, P> Result = v;
T const Cos(cos(angle));
T const Sin(sin(angle));
Result.x = v.x * Cos - v.y * Sin;
Result.y = v.x * Sin + v.y * Cos;
return Result;
}
template<typename T, precision P>
GLM_FUNC_QUALIFIER vec<4, T, P> rotateX
(
vec<4, T, P> const & v,
T const & angle
)
{
vec<4, T, P> Result = v;
T const Cos(cos(angle));
T const Sin(sin(angle));
Result.y = v.y * Cos - v.z * Sin;
Result.z = v.y * Sin + v.z * Cos;
return Result;
}
template<typename T, precision P>
GLM_FUNC_QUALIFIER vec<4, T, P> rotateY
(
vec<4, T, P> const & v,
T const & angle
)
{
vec<4, T, P> Result = v;
T const Cos(cos(angle));
T const Sin(sin(angle));
Result.x = v.x * Cos + v.z * Sin;
Result.z = -v.x * Sin + v.z * Cos;
return Result;
}
template<typename T, precision P>
GLM_FUNC_QUALIFIER vec<4, T, P> rotateZ
(
vec<4, T, P> const & v,
T const & angle
)
{
vec<4, T, P> Result = v;
T const Cos(cos(angle));
T const Sin(sin(angle));
Result.x = v.x * Cos - v.y * Sin;
Result.y = v.x * Sin + v.y * Cos;
return Result;
}
template<typename T, precision P>
GLM_FUNC_QUALIFIER mat<4, 4, T, P> orientation
(
vec<3, T, P> const & Normal,
vec<3, T, P> const & Up
)
{
if(all(equal(Normal, Up)))
return mat<4, 4, T, P>(T(1));
vec<3, T, P> RotationAxis = cross(Up, Normal);
T Angle = acos(dot(Normal, Up));
return rotate(Angle, RotationAxis);
}
}//namespace glm

View file

@ -0,0 +1,73 @@
/// @ref gtx
/// @file glm/gtx/scalar_multiplication.hpp
/// @author Joshua Moerman
///
/// @brief Enables scalar multiplication for all types
///
/// Since GLSL is very strict about types, the following (often used) combinations do not work:
/// double * vec4
/// int * vec4
/// vec4 / int
/// So we'll fix that! Of course "float * vec4" should remain the same (hence the enable_if magic)
#pragma once
#include "../detail/setup.hpp"
#ifndef GLM_ENABLE_EXPERIMENTAL
# error "GLM: GLM_GTX_scalar_multiplication is an experimental extension and may change in the future. Use #define GLM_ENABLE_EXPERIMENTAL before including it, if you really want to use it."
#endif
#if !GLM_HAS_TEMPLATE_ALIASES && !(GLM_COMPILER & GLM_COMPILER_GCC)
# error "GLM_GTX_scalar_multiplication requires C++11 support or alias templates and if not support for GCC"
#endif
#include "../vec2.hpp"
#include "../vec3.hpp"
#include "../vec4.hpp"
#include "../mat2x2.hpp"
#include <type_traits>
namespace glm
{
template<typename T, typename Vec>
using return_type_scalar_multiplication = typename std::enable_if<
!std::is_same<T, float>::value // T may not be a float
&& std::is_arithmetic<T>::value, Vec // But it may be an int or double (no vec3 or mat3, ...)
>::type;
#define GLM_IMPLEMENT_SCAL_MULT(Vec) \
template<typename T> \
return_type_scalar_multiplication<T, Vec> \
operator*(T const & s, Vec rh){ \
return rh *= static_cast<float>(s); \
} \
\
template<typename T> \
return_type_scalar_multiplication<T, Vec> \
operator*(Vec lh, T const & s){ \
return lh *= static_cast<float>(s); \
} \
\
template<typename T> \
return_type_scalar_multiplication<T, Vec> \
operator/(Vec lh, T const & s){ \
return lh *= 1.0f / s; \
}
GLM_IMPLEMENT_SCAL_MULT(vec2)
GLM_IMPLEMENT_SCAL_MULT(vec3)
GLM_IMPLEMENT_SCAL_MULT(vec4)
GLM_IMPLEMENT_SCAL_MULT(mat2)
GLM_IMPLEMENT_SCAL_MULT(mat2x3)
GLM_IMPLEMENT_SCAL_MULT(mat2x4)
GLM_IMPLEMENT_SCAL_MULT(mat3x2)
GLM_IMPLEMENT_SCAL_MULT(mat3)
GLM_IMPLEMENT_SCAL_MULT(mat3x4)
GLM_IMPLEMENT_SCAL_MULT(mat4x2)
GLM_IMPLEMENT_SCAL_MULT(mat4x3)
GLM_IMPLEMENT_SCAL_MULT(mat4)
#undef GLM_IMPLEMENT_SCAL_MULT
} // namespace glm

View file

@ -0,0 +1,36 @@
/// @ref gtx_scalar_relational
/// @file glm/gtx/scalar_relational.hpp
///
/// @see core (dependence)
///
/// @defgroup gtx_scalar_relational GLM_GTX_scalar_relational
/// @ingroup gtx
///
/// @brief Extend a position from a source to a position at a defined length.
///
/// <glm/gtx/scalar_relational.hpp> need to be included to use these functionalities.
#pragma once
// Dependency:
#include "../glm.hpp"
#ifndef GLM_ENABLE_EXPERIMENTAL
# error "GLM: GLM_GTX_extend is an experimental extension and may change in the future. Use #define GLM_ENABLE_EXPERIMENTAL before including it, if you really want to use it."
#endif
#if GLM_MESSAGES == GLM_MESSAGES_ENABLED && !defined(GLM_EXT_INCLUDED)
# pragma message("GLM: GLM_GTX_extend extension included")
#endif
namespace glm
{
/// @addtogroup gtx_scalar_relational
/// @{
/// @}
}//namespace glm
#include "scalar_relational.inl"

View file

@ -0,0 +1,89 @@
/// @ref gtx_scalar_relational
/// @file glm/gtx/scalar_relational.inl
namespace glm
{
template<typename T>
GLM_FUNC_QUALIFIER bool lessThan
(
T const & x,
T const & y
)
{
return x < y;
}
template<typename T>
GLM_FUNC_QUALIFIER bool lessThanEqual
(
T const & x,
T const & y
)
{
return x <= y;
}
template<typename T>
GLM_FUNC_QUALIFIER bool greaterThan
(
T const & x,
T const & y
)
{
return x > y;
}
template<typename T>
GLM_FUNC_QUALIFIER bool greaterThanEqual
(
T const & x,
T const & y
)
{
return x >= y;
}
template<typename T>
GLM_FUNC_QUALIFIER bool equal
(
T const & x,
T const & y
)
{
return x == y;
}
template<typename T>
GLM_FUNC_QUALIFIER bool notEqual
(
T const & x,
T const & y
)
{
return x != y;
}
GLM_FUNC_QUALIFIER bool any
(
bool const & x
)
{
return x;
}
GLM_FUNC_QUALIFIER bool all
(
bool const & x
)
{
return x;
}
GLM_FUNC_QUALIFIER bool not_
(
bool const & x
)
{
return !x;
}
}//namespace glm

65
glm/gtx/spline.hpp Normal file
View file

@ -0,0 +1,65 @@
/// @ref gtx_spline
/// @file glm/gtx/spline.hpp
///
/// @see core (dependence)
///
/// @defgroup gtx_spline GLM_GTX_spline
/// @ingroup gtx
///
/// @brief Spline functions
///
/// <glm/gtx/spline.hpp> need to be included to use these functionalities.
#pragma once
// Dependency:
#include "../glm.hpp"
#include "../gtx/optimum_pow.hpp"
#ifndef GLM_ENABLE_EXPERIMENTAL
# error "GLM: GLM_GTX_spline is an experimental extension and may change in the future. Use #define GLM_ENABLE_EXPERIMENTAL before including it, if you really want to use it."
#endif
#if GLM_MESSAGES == GLM_MESSAGES_ENABLED && !defined(GLM_EXT_INCLUDED)
# pragma message("GLM: GLM_GTX_spline extension included")
#endif
namespace glm
{
/// @addtogroup gtx_spline
/// @{
/// Return a point from a catmull rom curve.
/// @see gtx_spline extension.
template<typename genType>
GLM_FUNC_DECL genType catmullRom(
genType const & v1,
genType const & v2,
genType const & v3,
genType const & v4,
typename genType::value_type const & s);
/// Return a point from a hermite curve.
/// @see gtx_spline extension.
template<typename genType>
GLM_FUNC_DECL genType hermite(
genType const & v1,
genType const & t1,
genType const & v2,
genType const & t2,
typename genType::value_type const & s);
/// Return a point from a cubic curve.
/// @see gtx_spline extension.
template<typename genType>
GLM_FUNC_DECL genType cubic(
genType const & v1,
genType const & v2,
genType const & v3,
genType const & v4,
typename genType::value_type const & s);
/// @}
}//namespace glm
#include "spline.inl"

63
glm/gtx/spline.inl Normal file
View file

@ -0,0 +1,63 @@
/// @ref gtx_spline
/// @file glm/gtx/spline.inl
namespace glm
{
template<typename genType>
GLM_FUNC_QUALIFIER genType catmullRom
(
genType const & v1,
genType const & v2,
genType const & v3,
genType const & v4,
typename genType::value_type const & s
)
{
typename genType::value_type s1 = s;
typename genType::value_type s2 = pow2(s);
typename genType::value_type s3 = pow3(s);
typename genType::value_type f1 = -s3 + typename genType::value_type(2) * s2 - s;
typename genType::value_type f2 = typename genType::value_type(3) * s3 - typename genType::value_type(5) * s2 + typename genType::value_type(2);
typename genType::value_type f3 = typename genType::value_type(-3) * s3 + typename genType::value_type(4) * s2 + s;
typename genType::value_type f4 = s3 - s2;
return (f1 * v1 + f2 * v2 + f3 * v3 + f4 * v4) / typename genType::value_type(2);
}
template<typename genType>
GLM_FUNC_QUALIFIER genType hermite
(
genType const & v1,
genType const & t1,
genType const & v2,
genType const & t2,
typename genType::value_type const & s
)
{
typename genType::value_type s1 = s;
typename genType::value_type s2 = pow2(s);
typename genType::value_type s3 = pow3(s);
typename genType::value_type f1 = typename genType::value_type(2) * s3 - typename genType::value_type(3) * s2 + typename genType::value_type(1);
typename genType::value_type f2 = typename genType::value_type(-2) * s3 + typename genType::value_type(3) * s2;
typename genType::value_type f3 = s3 - typename genType::value_type(2) * s2 + s;
typename genType::value_type f4 = s3 - s2;
return f1 * v1 + f2 * v2 + f3 * t1 + f4 * t2;
}
template<typename genType>
GLM_FUNC_QUALIFIER genType cubic
(
genType const & v1,
genType const & v2,
genType const & v3,
genType const & v4,
typename genType::value_type const & s
)
{
return ((v1 * s + v2) * s + v3) * s + v4;
}
}//namespace glm

View file

@ -0,0 +1,67 @@
/// @ref gtx_std_based_type
/// @file glm/gtx/std_based_type.hpp
///
/// @see core (dependence)
/// @see gtx_extented_min_max (dependence)
///
/// @defgroup gtx_std_based_type GLM_GTX_std_based_type
/// @ingroup gtx
///
/// @brief Adds vector types based on STL value types.
/// <glm/gtx/std_based_type.hpp> need to be included to use these functionalities.
#pragma once
// Dependency:
#include "../glm.hpp"
#include <cstdlib>
#ifndef GLM_ENABLE_EXPERIMENTAL
# error "GLM: GLM_GTX_std_based_type is an experimental extension and may change in the future. Use #define GLM_ENABLE_EXPERIMENTAL before including it, if you really want to use it."
#endif
#if GLM_MESSAGES == GLM_MESSAGES_ENABLED && !defined(GLM_EXT_INCLUDED)
# pragma message("GLM: GLM_GTX_std_based_type extension included")
#endif
namespace glm
{
/// @addtogroup gtx_std_based_type
/// @{
/// Vector type based of one std::size_t component.
/// @see GLM_GTX_std_based_type
typedef vec<1, std::size_t, defaultp> size1;
/// Vector type based of two std::size_t components.
/// @see GLM_GTX_std_based_type
typedef vec<2, std::size_t, defaultp> size2;
/// Vector type based of three std::size_t components.
/// @see GLM_GTX_std_based_type
typedef vec<3, std::size_t, defaultp> size3;
/// Vector type based of four std::size_t components.
/// @see GLM_GTX_std_based_type
typedef vec<4, std::size_t, defaultp> size4;
/// Vector type based of one std::size_t component.
/// @see GLM_GTX_std_based_type
typedef vec<1, std::size_t, defaultp> size1_t;
/// Vector type based of two std::size_t components.
/// @see GLM_GTX_std_based_type
typedef vec<2, std::size_t, defaultp> size2_t;
/// Vector type based of three std::size_t components.
/// @see GLM_GTX_std_based_type
typedef vec<3, std::size_t, defaultp> size3_t;
/// Vector type based of four std::size_t components.
/// @see GLM_GTX_std_based_type
typedef vec<4, std::size_t, defaultp> size4_t;
/// @}
}//namespace glm
#include "std_based_type.inl"

View file

@ -0,0 +1,7 @@
/// @ref gtx_std_based_type
/// @file glm/gtx/std_based_type.inl
namespace glm
{
}

51
glm/gtx/string_cast.hpp Normal file
View file

@ -0,0 +1,51 @@
/// @ref gtx_string_cast
/// @file glm/gtx/string_cast.hpp
///
/// @see core (dependence)
/// @see gtx_integer (dependence)
/// @see gtx_quaternion (dependence)
///
/// @defgroup gtx_string_cast GLM_GTX_string_cast
/// @ingroup gtx
///
/// @brief Setup strings for GLM type values
///
/// <glm/gtx/string_cast.hpp> need to be included to use these functionalities.
/// This extension is not supported with CUDA
#pragma once
// Dependency:
#include "../glm.hpp"
#include "../gtc/type_precision.hpp"
#include "../gtc/quaternion.hpp"
#include "../gtx/dual_quaternion.hpp"
#include <string>
#include <cmath>
#ifndef GLM_ENABLE_EXPERIMENTAL
# error "GLM: GLM_GTX_string_cast is an experimental extension and may change in the future. Use #define GLM_ENABLE_EXPERIMENTAL before including it, if you really want to use it."
#endif
#if(GLM_COMPILER & GLM_COMPILER_CUDA)
# error "GLM_GTX_string_cast is not supported on CUDA compiler"
#endif
#if GLM_MESSAGES == GLM_MESSAGES_ENABLED && !defined(GLM_EXT_INCLUDED)
# pragma message("GLM: GLM_GTX_string_cast extension included")
#endif
namespace glm
{
/// @addtogroup gtx_string_cast
/// @{
/// Create a string from a GLM vector or matrix typed variable.
/// @see gtx_string_cast extension.
template<typename genType>
GLM_FUNC_DECL std::string to_string(genType const& x);
/// @}
}//namespace glm
#include "string_cast.inl"

458
glm/gtx/string_cast.inl Normal file
View file

@ -0,0 +1,458 @@
/// @ref gtx_string_cast
/// @file glm/gtx/string_cast.inl
#include <cstdarg>
#include <cstdio>
namespace glm{
namespace detail
{
GLM_FUNC_QUALIFIER std::string format(const char* msg, ...)
{
std::size_t const STRING_BUFFER(4096);
char text[STRING_BUFFER];
va_list list;
if(msg == 0)
return std::string();
va_start(list, msg);
# if(GLM_COMPILER & GLM_COMPILER_VC)
vsprintf_s(text, STRING_BUFFER, msg, list);
# else//
vsprintf(text, msg, list);
# endif//
va_end(list);
return std::string(text);
}
static const char* LabelTrue = "true";
static const char* LabelFalse = "false";
template<typename T, bool isFloat = false>
struct literal
{
GLM_FUNC_QUALIFIER static char const * value() {return "%d";};
};
template<typename T>
struct literal<T, true>
{
GLM_FUNC_QUALIFIER static char const * value() {return "%f";};
};
# if GLM_MODEL == GLM_MODEL_32 && GLM_COMPILER && GLM_COMPILER_VC
template<>
struct literal<uint64_t, false>
{
GLM_FUNC_QUALIFIER static char const * value() {return "%lld";};
};
template<>
struct literal<int64_t, false>
{
GLM_FUNC_QUALIFIER static char const * value() {return "%lld";};
};
# endif//GLM_MODEL == GLM_MODEL_32 && GLM_COMPILER && GLM_COMPILER_VC
template<typename T>
struct prefix{};
template<>
struct prefix<float>
{
GLM_FUNC_QUALIFIER static char const * value() {return "";};
};
template<>
struct prefix<double>
{
GLM_FUNC_QUALIFIER static char const * value() {return "d";};
};
template<>
struct prefix<bool>
{
GLM_FUNC_QUALIFIER static char const * value() {return "b";};
};
template<>
struct prefix<uint8_t>
{
GLM_FUNC_QUALIFIER static char const * value() {return "u8";};
};
template<>
struct prefix<int8_t>
{
GLM_FUNC_QUALIFIER static char const * value() {return "i8";};
};
template<>
struct prefix<uint16_t>
{
GLM_FUNC_QUALIFIER static char const * value() {return "u16";};
};
template<>
struct prefix<int16_t>
{
GLM_FUNC_QUALIFIER static char const * value() {return "i16";};
};
template<>
struct prefix<uint32_t>
{
GLM_FUNC_QUALIFIER static char const * value() {return "u";};
};
template<>
struct prefix<int32_t>
{
GLM_FUNC_QUALIFIER static char const * value() {return "i";};
};
template<>
struct prefix<uint64_t>
{
GLM_FUNC_QUALIFIER static char const * value() {return "u64";};
};
template<>
struct prefix<int64_t>
{
GLM_FUNC_QUALIFIER static char const * value() {return "i64";};
};
template<typename matType>
struct compute_to_string
{};
template<precision P>
struct compute_to_string<vec<1, bool, P> >
{
GLM_FUNC_QUALIFIER static std::string call(vec<1, bool, P> const & x)
{
return detail::format("bvec1(%s)",
x[0] ? detail::LabelTrue : detail::LabelFalse);
}
};
template<precision P>
struct compute_to_string<vec<2, bool, P> >
{
GLM_FUNC_QUALIFIER static std::string call(vec<2, bool, P> const & x)
{
return detail::format("bvec2(%s, %s)",
x[0] ? detail::LabelTrue : detail::LabelFalse,
x[1] ? detail::LabelTrue : detail::LabelFalse);
}
};
template<precision P>
struct compute_to_string<vec<3, bool, P> >
{
GLM_FUNC_QUALIFIER static std::string call(vec<3, bool, P> const & x)
{
return detail::format("bvec3(%s, %s, %s)",
x[0] ? detail::LabelTrue : detail::LabelFalse,
x[1] ? detail::LabelTrue : detail::LabelFalse,
x[2] ? detail::LabelTrue : detail::LabelFalse);
}
};
template<precision P>
struct compute_to_string<vec<4, bool, P> >
{
GLM_FUNC_QUALIFIER static std::string call(vec<4, bool, P> const & x)
{
return detail::format("bvec4(%s, %s, %s, %s)",
x[0] ? detail::LabelTrue : detail::LabelFalse,
x[1] ? detail::LabelTrue : detail::LabelFalse,
x[2] ? detail::LabelTrue : detail::LabelFalse,
x[3] ? detail::LabelTrue : detail::LabelFalse);
}
};
template<typename T, precision P>
struct compute_to_string<vec<1, T, P> >
{
GLM_FUNC_QUALIFIER static std::string call(vec<1, T, P> const & x)
{
char const * PrefixStr = prefix<T>::value();
char const * LiteralStr = literal<T, std::numeric_limits<T>::is_iec559>::value();
std::string FormatStr(detail::format("%svec1(%s)",
PrefixStr,
LiteralStr));
return detail::format(FormatStr.c_str(), x[0]);
}
};
template<typename T, precision P>
struct compute_to_string<vec<2, T, P> >
{
GLM_FUNC_QUALIFIER static std::string call(vec<2, T, P> const & x)
{
char const * PrefixStr = prefix<T>::value();
char const * LiteralStr = literal<T, std::numeric_limits<T>::is_iec559>::value();
std::string FormatStr(detail::format("%svec2(%s, %s)",
PrefixStr,
LiteralStr, LiteralStr));
return detail::format(FormatStr.c_str(), x[0], x[1]);
}
};
template<typename T, precision P>
struct compute_to_string<vec<3, T, P> >
{
GLM_FUNC_QUALIFIER static std::string call(vec<3, T, P> const & x)
{
char const * PrefixStr = prefix<T>::value();
char const * LiteralStr = literal<T, std::numeric_limits<T>::is_iec559>::value();
std::string FormatStr(detail::format("%svec3(%s, %s, %s)",
PrefixStr,
LiteralStr, LiteralStr, LiteralStr));
return detail::format(FormatStr.c_str(), x[0], x[1], x[2]);
}
};
template<typename T, precision P>
struct compute_to_string<vec<4, T, P> >
{
GLM_FUNC_QUALIFIER static std::string call(vec<4, T, P> const & x)
{
char const * PrefixStr = prefix<T>::value();
char const * LiteralStr = literal<T, std::numeric_limits<T>::is_iec559>::value();
std::string FormatStr(detail::format("%svec4(%s, %s, %s, %s)",
PrefixStr,
LiteralStr, LiteralStr, LiteralStr, LiteralStr));
return detail::format(FormatStr.c_str(), x[0], x[1], x[2], x[3]);
}
};
template<typename T, precision P>
struct compute_to_string<mat<2, 2, T, P> >
{
GLM_FUNC_QUALIFIER static std::string call(mat<2, 2, T, P> const & x)
{
char const * PrefixStr = prefix<T>::value();
char const * LiteralStr = literal<T, std::numeric_limits<T>::is_iec559>::value();
std::string FormatStr(detail::format("%smat2x2((%s, %s), (%s, %s))",
PrefixStr,
LiteralStr, LiteralStr,
LiteralStr, LiteralStr));
return detail::format(FormatStr.c_str(),
x[0][0], x[0][1],
x[1][0], x[1][1]);
}
};
template<typename T, precision P>
struct compute_to_string<mat<2, 3, T, P> >
{
GLM_FUNC_QUALIFIER static std::string call(mat<2, 3, T, P> const & x)
{
char const * PrefixStr = prefix<T>::value();
char const * LiteralStr = literal<T, std::numeric_limits<T>::is_iec559>::value();
std::string FormatStr(detail::format("%smat2x3((%s, %s, %s), (%s, %s, %s))",
PrefixStr,
LiteralStr, LiteralStr, LiteralStr,
LiteralStr, LiteralStr, LiteralStr));
return detail::format(FormatStr.c_str(),
x[0][0], x[0][1], x[0][2],
x[1][0], x[1][1], x[1][2]);
}
};
template<typename T, precision P>
struct compute_to_string<mat<2, 4, T, P> >
{
GLM_FUNC_QUALIFIER static std::string call(mat<2, 4, T, P> const & x)
{
char const * PrefixStr = prefix<T>::value();
char const * LiteralStr = literal<T, std::numeric_limits<T>::is_iec559>::value();
std::string FormatStr(detail::format("%smat2x4((%s, %s, %s, %s), (%s, %s, %s, %s))",
PrefixStr,
LiteralStr, LiteralStr, LiteralStr, LiteralStr,
LiteralStr, LiteralStr, LiteralStr, LiteralStr));
return detail::format(FormatStr.c_str(),
x[0][0], x[0][1], x[0][2], x[0][3],
x[1][0], x[1][1], x[1][2], x[1][3]);
}
};
template<typename T, precision P>
struct compute_to_string<mat<3, 2, T, P> >
{
GLM_FUNC_QUALIFIER static std::string call(mat<3, 2, T, P> const & x)
{
char const * PrefixStr = prefix<T>::value();
char const * LiteralStr = literal<T, std::numeric_limits<T>::is_iec559>::value();
std::string FormatStr(detail::format("%smat3x2((%s, %s), (%s, %s), (%s, %s))",
PrefixStr,
LiteralStr, LiteralStr,
LiteralStr, LiteralStr,
LiteralStr, LiteralStr));
return detail::format(FormatStr.c_str(),
x[0][0], x[0][1],
x[1][0], x[1][1],
x[2][0], x[2][1]);
}
};
template<typename T, precision P>
struct compute_to_string<mat<3, 3, T, P> >
{
GLM_FUNC_QUALIFIER static std::string call(mat<3, 3, T, P> const & x)
{
char const * PrefixStr = prefix<T>::value();
char const * LiteralStr = literal<T, std::numeric_limits<T>::is_iec559>::value();
std::string FormatStr(detail::format("%smat3x3((%s, %s, %s), (%s, %s, %s), (%s, %s, %s))",
PrefixStr,
LiteralStr, LiteralStr, LiteralStr,
LiteralStr, LiteralStr, LiteralStr,
LiteralStr, LiteralStr, LiteralStr));
return detail::format(FormatStr.c_str(),
x[0][0], x[0][1], x[0][2],
x[1][0], x[1][1], x[1][2],
x[2][0], x[2][1], x[2][2]);
}
};
template<typename T, precision P>
struct compute_to_string<mat<3, 4, T, P> >
{
GLM_FUNC_QUALIFIER static std::string call(mat<3, 4, T, P> const & x)
{
char const * PrefixStr = prefix<T>::value();
char const * LiteralStr = literal<T, std::numeric_limits<T>::is_iec559>::value();
std::string FormatStr(detail::format("%smat3x4((%s, %s, %s, %s), (%s, %s, %s, %s), (%s, %s, %s, %s))",
PrefixStr,
LiteralStr, LiteralStr, LiteralStr, LiteralStr,
LiteralStr, LiteralStr, LiteralStr, LiteralStr,
LiteralStr, LiteralStr, LiteralStr, LiteralStr));
return detail::format(FormatStr.c_str(),
x[0][0], x[0][1], x[0][2], x[0][3],
x[1][0], x[1][1], x[1][2], x[1][3],
x[2][0], x[2][1], x[2][2], x[2][3]);
}
};
template<typename T, precision P>
struct compute_to_string<mat<4, 2, T, P> >
{
GLM_FUNC_QUALIFIER static std::string call(mat<4, 2, T, P> const & x)
{
char const * PrefixStr = prefix<T>::value();
char const * LiteralStr = literal<T, std::numeric_limits<T>::is_iec559>::value();
std::string FormatStr(detail::format("%smat4x2((%s, %s), (%s, %s), (%s, %s), (%s, %s))",
PrefixStr,
LiteralStr, LiteralStr,
LiteralStr, LiteralStr,
LiteralStr, LiteralStr,
LiteralStr, LiteralStr));
return detail::format(FormatStr.c_str(),
x[0][0], x[0][1],
x[1][0], x[1][1],
x[2][0], x[2][1],
x[3][0], x[3][1]);
}
};
template<typename T, precision P>
struct compute_to_string<mat<4, 3, T, P> >
{
GLM_FUNC_QUALIFIER static std::string call(mat<4, 3, T, P> const & x)
{
char const * PrefixStr = prefix<T>::value();
char const * LiteralStr = literal<T, std::numeric_limits<T>::is_iec559>::value();
std::string FormatStr(detail::format("%smat4x3((%s, %s, %s), (%s, %s, %s), (%s, %s, %s), (%s, %s, %s))",
PrefixStr,
LiteralStr, LiteralStr, LiteralStr,
LiteralStr, LiteralStr, LiteralStr,
LiteralStr, LiteralStr, LiteralStr,
LiteralStr, LiteralStr, LiteralStr));
return detail::format(FormatStr.c_str(),
x[0][0], x[0][1], x[0][2],
x[1][0], x[1][1], x[1][2],
x[2][0], x[2][1], x[2][2],
x[3][0], x[3][1], x[3][2]);
}
};
template<typename T, precision P>
struct compute_to_string<mat<4, 4, T, P> >
{
GLM_FUNC_QUALIFIER static std::string call(mat<4, 4, T, P> const & x)
{
char const * PrefixStr = prefix<T>::value();
char const * LiteralStr = literal<T, std::numeric_limits<T>::is_iec559>::value();
std::string FormatStr(detail::format("%smat4x4((%s, %s, %s, %s), (%s, %s, %s, %s), (%s, %s, %s, %s), (%s, %s, %s, %s))",
PrefixStr,
LiteralStr, LiteralStr, LiteralStr, LiteralStr,
LiteralStr, LiteralStr, LiteralStr, LiteralStr,
LiteralStr, LiteralStr, LiteralStr, LiteralStr,
LiteralStr, LiteralStr, LiteralStr, LiteralStr));
return detail::format(FormatStr.c_str(),
x[0][0], x[0][1], x[0][2], x[0][3],
x[1][0], x[1][1], x[1][2], x[1][3],
x[2][0], x[2][1], x[2][2], x[2][3],
x[3][0], x[3][1], x[3][2], x[3][3]);
}
};
template<typename T, precision P>
struct compute_to_string<tquat<T, P> >
{
GLM_FUNC_QUALIFIER static std::string call(tquat<T, P> const & x)
{
char const * PrefixStr = prefix<T>::value();
char const * LiteralStr = literal<T, std::numeric_limits<T>::is_iec559>::value();
std::string FormatStr(detail::format("%squat(%s, %s, %s, %s)",
PrefixStr,
LiteralStr, LiteralStr, LiteralStr, LiteralStr));
return detail::format(FormatStr.c_str(), x[0], x[1], x[2], x[3]);
}
};
template<typename T, precision P>
struct compute_to_string<tdualquat<T, P> >
{
GLM_FUNC_QUALIFIER static std::string call(tdualquat<T, P> const & x)
{
char const * PrefixStr = prefix<T>::value();
char const * LiteralStr = literal<T, std::numeric_limits<T>::is_iec559>::value();
std::string FormatStr(detail::format("%sdualquat((%s, %s, %s, %s), (%s, %s, %s, %s))",
PrefixStr,
LiteralStr, LiteralStr, LiteralStr, LiteralStr));
return detail::format(FormatStr.c_str(), x.real[0], x.real[1], x.real[2], x.real[3], x.dual[0], x.dual[1], x.dual[2], x.dual[3]);
}
};
}//namespace detail
template<class matType>
GLM_FUNC_QUALIFIER std::string to_string(matType const& x)
{
return detail::compute_to_string<matType>::call(x);
}
}//namespace glm

60
glm/gtx/transform.hpp Normal file
View file

@ -0,0 +1,60 @@
/// @ref gtx_transform
/// @file glm/gtx/transform.hpp
///
/// @see core (dependence)
/// @see gtc_matrix_transform (dependence)
/// @see gtx_transform
/// @see gtx_transform2
///
/// @defgroup gtx_transform GLM_GTX_transform
/// @ingroup gtx
///
/// @brief Add transformation matrices
///
/// <glm/gtx/transform.hpp> need to be included to use these functionalities.
#pragma once
// Dependency:
#include "../glm.hpp"
#include "../gtc/matrix_transform.hpp"
#ifndef GLM_ENABLE_EXPERIMENTAL
# error "GLM: GLM_GTX_transform is an experimental extension and may change in the future. Use #define GLM_ENABLE_EXPERIMENTAL before including it, if you really want to use it."
#endif
#if GLM_MESSAGES == GLM_MESSAGES_ENABLED && !defined(GLM_EXT_INCLUDED)
# pragma message("GLM: GLM_GTX_transform extension included")
#endif
namespace glm
{
/// @addtogroup gtx_transform
/// @{
/// Transforms a matrix with a translation 4 * 4 matrix created from 3 scalars.
/// @see gtc_matrix_transform
/// @see gtx_transform
template<typename T, precision P>
GLM_FUNC_DECL mat<4, 4, T, P> translate(
vec<3, T, P> const & v);
/// Builds a rotation 4 * 4 matrix created from an axis of 3 scalars and an angle expressed in radians.
/// @see gtc_matrix_transform
/// @see gtx_transform
template<typename T, precision P>
GLM_FUNC_DECL mat<4, 4, T, P> rotate(
T angle,
vec<3, T, P> const & v);
/// Transforms a matrix with a scale 4 * 4 matrix created from a vector of 3 components.
/// @see gtc_matrix_transform
/// @see gtx_transform
template<typename T, precision P>
GLM_FUNC_DECL mat<4, 4, T, P> scale(
vec<3, T, P> const & v);
/// @}
}// namespace glm
#include "transform.inl"

Some files were not shown because too many files have changed in this diff Show more