Reformatting

master
Christophe Riccio ago%!(EXTRA string=14 years)
parent 6f6d161afb
commit bc15b98730
  1. 904
      glm/gtc/half_float.inl
  2. 54
      glm/gtc/matrix_access.inl
  3. 71
      glm/gtc/matrix_inverse.inl
  4. 209
      glm/gtc/matrix_transform.inl
  5. 157
      glm/gtc/noise.inl
  6. 4
      glm/gtc/quaternion.inl
  7. 174
      glm/gtc/swizzle.inl

File diff suppressed because it is too large Load Diff

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

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

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

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

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

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

Loading…
Cancel
Save