summaryrefslogtreecommitdiffstats
path: root/external/include/glm/gtx/matrix_interpolation.inl
diff options
context:
space:
mode:
authorLaG1924 <12997935+LaG1924@users.noreply.github.com>2018-08-21 17:40:38 +0200
committerLaG1924 <12997935+LaG1924@users.noreply.github.com>2018-08-21 17:40:38 +0200
commit2877f4eda3d1b0c7431039e3142ecf1a282a34b1 (patch)
tree58ad35e27ab2a3b8955f5adbf28f296670681ffc /external/include/glm/gtx/matrix_interpolation.inl
parentSmooth sun movement (diff)
downloadAltCraft-2877f4eda3d1b0c7431039e3142ecf1a282a34b1.tar
AltCraft-2877f4eda3d1b0c7431039e3142ecf1a282a34b1.tar.gz
AltCraft-2877f4eda3d1b0c7431039e3142ecf1a282a34b1.tar.bz2
AltCraft-2877f4eda3d1b0c7431039e3142ecf1a282a34b1.tar.lz
AltCraft-2877f4eda3d1b0c7431039e3142ecf1a282a34b1.tar.xz
AltCraft-2877f4eda3d1b0c7431039e3142ecf1a282a34b1.tar.zst
AltCraft-2877f4eda3d1b0c7431039e3142ecf1a282a34b1.zip
Diffstat (limited to 'external/include/glm/gtx/matrix_interpolation.inl')
-rw-r--r--external/include/glm/gtx/matrix_interpolation.inl140
1 files changed, 68 insertions, 72 deletions
diff --git a/external/include/glm/gtx/matrix_interpolation.inl b/external/include/glm/gtx/matrix_interpolation.inl
index 8645f96..1f2915a 100644
--- a/external/include/glm/gtx/matrix_interpolation.inl
+++ b/external/include/glm/gtx/matrix_interpolation.inl
@@ -1,43 +1,43 @@
/// @ref gtx_matrix_interpolation
/// @file glm/gtx/matrix_interpolation.hpp
+#include "../gtc/constants.hpp"
+
namespace glm
{
- template <typename T, precision P>
- GLM_FUNC_QUALIFIER void axisAngle
- (
- tmat4x4<T, P> const & mat,
- tvec3<T, P> & axis,
- T & angle
- )
+ template<typename T, qualifier Q>
+ GLM_FUNC_QUALIFIER void axisAngle(mat<4, 4, T, Q> const& mat, vec<3, T, Q> & axis, T & angle)
{
- T epsilon = (T)0.01;
- T epsilon2 = (T)0.1;
+ T epsilon = static_cast<T>(0.01);
+ T epsilon2 = static_cast<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))
+ 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] - static_cast<T>(3.0)) < epsilon2))
{
- angle = (T)0.0;
- axis.x = (T)1.0;
- axis.y = (T)0.0;
- axis.z = (T)0.0;
+ angle = static_cast<T>(0.0);
+ axis.x = static_cast<T>(1.0);
+ axis.y = static_cast<T>(0.0);
+ axis.z = static_cast<T>(0.0);
return;
}
angle = static_cast<T>(3.1415926535897932384626433832795);
- T xx = (mat[0][0] + (T)1.0) / (T)2.0;
- T yy = (mat[1][1] + (T)1.0) / (T)2.0;
- T zz = (mat[2][2] + (T)1.0) / (T)2.0;
- T xy = (mat[1][0] + mat[0][1]) / (T)4.0;
- T xz = (mat[2][0] + mat[0][2]) / (T)4.0;
- T yz = (mat[2][1] + mat[1][2]) / (T)4.0;
+ T xx = (mat[0][0] + static_cast<T>(1.0)) * static_cast<T>(0.5);
+ T yy = (mat[1][1] + static_cast<T>(1.0)) * static_cast<T>(0.5);
+ T zz = (mat[2][2] + static_cast<T>(1.0)) * static_cast<T>(0.5);
+ T xy = (mat[1][0] + mat[0][1]) * static_cast<T>(0.25);
+ T xz = (mat[2][0] + mat[0][2]) * static_cast<T>(0.25);
+ T yz = (mat[2][1] + mat[1][2]) * static_cast<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 {
+ if(xx < epsilon)
+ {
+ axis.x = static_cast<T>(0.0);
+ axis.y = static_cast<T>(0.7071);
+ axis.z = static_cast<T>(0.7071);
+ }
+ else
+ {
axis.x = sqrt(xx);
axis.y = xy / axis.x;
axis.z = xz / axis.x;
@@ -45,11 +45,14 @@ namespace glm
}
else if (yy > zz)
{
- if (yy < epsilon) {
- axis.x = (T)0.7071;
- axis.y = (T)0.0;
- axis.z = (T)0.7071;
- } else {
+ if(yy < epsilon)
+ {
+ axis.x = static_cast<T>(0.7071);
+ axis.y = static_cast<T>(0.0);
+ axis.z = static_cast<T>(0.7071);
+ }
+ else
+ {
axis.y = sqrt(yy);
axis.x = xy / axis.y;
axis.z = yz / axis.y;
@@ -57,11 +60,14 @@ namespace glm
}
else
{
- if (zz < epsilon) {
- axis.x = (T)0.7071;
- axis.y = (T)0.7071;
- axis.z = (T)0.0;
- } else {
+ if (zz < epsilon)
+ {
+ axis.x = static_cast<T>(0.7071);
+ axis.y = static_cast<T>(0.7071);
+ axis.z = static_cast<T>(0.0);
+ }
+ else
+ {
axis.z = sqrt(zz);
axis.x = xz / axis.z;
axis.y = yz / axis.z;
@@ -71,61 +77,51 @@ namespace glm
}
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)2.0);
+ s = static_cast<T>(1);
+ T const angleCos = (mat[0][0] + mat[1][1] + mat[2][2] - static_cast<T>(1)) * static_cast<T>(0.5);
+ if(angleCos - static_cast<T>(1) < epsilon)
+ angle = pi<T>() * static_cast<T>(0.25);
+ else
+ angle = acos(angleCos);
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 tmat4x4<T, P> axisAngleMatrix
- (
- tvec3<T, P> const & axis,
- T const angle
- )
+ template<typename T, qualifier Q>
+ GLM_FUNC_QUALIFIER mat<4, 4, T, Q> axisAngleMatrix(vec<3, T, Q> const& axis, T const angle)
{
T c = cos(angle);
T s = sin(angle);
T t = static_cast<T>(1) - c;
- tvec3<T, P> n = normalize(axis);
+ vec<3, T, Q> n = normalize(axis);
- return tmat4x4<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)
- );
+ return mat<4, 4, T, Q>(
+ t * n.x * n.x + c, t * n.x * n.y + n.z * s, t * n.x * n.z - n.y * s, static_cast<T>(0.0),
+ t * n.x * n.y - n.z * s, t * n.y * n.y + c, t * n.y * n.z + n.x * s, static_cast<T>(0.0),
+ t * n.x * n.z + n.y * s, t * n.y * n.z - n.x * s, t * n.z * n.z + c, static_cast<T>(0.0),
+ static_cast<T>(0.0), static_cast<T>(0.0), static_cast<T>(0.0), static_cast<T>(1.0));
}
- template <typename T, precision P>
- GLM_FUNC_QUALIFIER tmat4x4<T, P> extractMatrixRotation
- (
- tmat4x4<T, P> const & mat
- )
+ template<typename T, qualifier Q>
+ GLM_FUNC_QUALIFIER mat<4, 4, T, Q> extractMatrixRotation(mat<4, 4, T, Q> const& m)
{
- return tmat4x4<T, P>(
- mat[0][0], mat[0][1], mat[0][2], 0.0,
- mat[1][0], mat[1][1], mat[1][2], 0.0,
- mat[2][0], mat[2][1], mat[2][2], 0.0,
- 0.0, 0.0, 0.0, 1.0
- );
+ return mat<4, 4, T, Q>(
+ m[0][0], m[0][1], m[0][2], static_cast<T>(0.0),
+ m[1][0], m[1][1], m[1][2], static_cast<T>(0.0),
+ m[2][0], m[2][1], m[2][2], static_cast<T>(0.0),
+ static_cast<T>(0.0), static_cast<T>(0.0), static_cast<T>(0.0), static_cast<T>(1.0));
}
- template <typename T, precision P>
- GLM_FUNC_QUALIFIER tmat4x4<T, P> interpolate
- (
- tmat4x4<T, P> const & m1,
- tmat4x4<T, P> const & m2,
- T const delta
- )
+ template<typename T, qualifier Q>
+ GLM_FUNC_QUALIFIER mat<4, 4, T, Q> interpolate(mat<4, 4, T, Q> const& m1, mat<4, 4, T, Q> const& m2, T const delta)
{
- tmat4x4<T, P> m1rot = extractMatrixRotation(m1);
- tmat4x4<T, P> dltRotation = m2 * transpose(m1rot);
- tvec3<T, P> dltAxis;
+ mat<4, 4, T, Q> m1rot = extractMatrixRotation(m1);
+ mat<4, 4, T, Q> dltRotation = m2 * transpose(m1rot);
+ vec<3, T, Q> dltAxis;
T dltAngle;
axisAngle(dltRotation, dltAxis, dltAngle);
- tmat4x4<T, P> out = axisAngleMatrix(dltAxis, dltAngle * delta) * m1rot;
+ mat<4, 4, T, Q> 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]);