axisAngle refactoring

Signed-off-by: Sergey Krivohatskiy <s.krivohatskiy@gmail.com>
This commit is contained in:
Sergey Krivohatskiy 2021-03-23 14:27:00 +03:00
parent 57c3be0b9f
commit c9c656ce31

View File

@ -1,6 +1,6 @@
/// @ref gtx_matrix_interpolation /// @ref gtx_matrix_interpolation
#include "../gtc/constants.hpp" #include "../ext/scalar_constants.hpp"
namespace glm namespace glm
{ {
@ -15,12 +15,11 @@ namespace glm
if ((abs(m[1][0] + m[0][1]) < epsilon2) && (abs(m[2][0] + m[0][2]) < epsilon2) && (abs(m[2][1] + m[1][2]) < epsilon2) && (abs(m[0][0] + m[1][1] + m[2][2] - static_cast<T>(3.0)) < epsilon2)) if ((abs(m[1][0] + m[0][1]) < epsilon2) && (abs(m[2][0] + m[0][2]) < epsilon2) && (abs(m[2][1] + m[1][2]) < epsilon2) && (abs(m[0][0] + m[1][1] + m[2][2] - static_cast<T>(3.0)) < epsilon2))
{ {
angle = static_cast<T>(0.0); angle = static_cast<T>(0.0);
axis.x = static_cast<T>(1.0); axis = vec<3, T, Q>(
axis.y = static_cast<T>(0.0); static_cast<T>(1.0), static_cast<T>(0.0), static_cast<T>(0.0));
axis.z = static_cast<T>(0.0);
return; return;
} }
angle = static_cast<T>(3.1415926535897932384626433832795); angle = pi<T>();
T xx = (m[0][0] + static_cast<T>(1.0)) * static_cast<T>(0.5); T xx = (m[0][0] + static_cast<T>(1.0)) * static_cast<T>(0.5);
T yy = (m[1][1] + static_cast<T>(1.0)) * static_cast<T>(0.5); T yy = (m[1][1] + static_cast<T>(1.0)) * static_cast<T>(0.5);
T zz = (m[2][2] + static_cast<T>(1.0)) * static_cast<T>(0.5); T zz = (m[2][2] + static_cast<T>(1.0)) * static_cast<T>(0.5);
@ -74,9 +73,7 @@ namespace glm
} }
return; return;
} }
T s = sqrt((m[2][1] - m[1][2]) * (m[2][1] - m[1][2]) + (m[2][0] - m[0][2]) * (m[2][0] - m[0][2]) + (m[1][0] - m[0][1]) * (m[1][0] - m[0][1]));
if (glm::abs(s) < T(0.001))
s = static_cast<T>(1);
T const angleCos = (m[0][0] + m[1][1] + m[2][2] - static_cast<T>(1)) * static_cast<T>(0.5); T const angleCos = (m[0][0] + m[1][1] + m[2][2] - static_cast<T>(1)) * static_cast<T>(0.5);
if(angleCos >= static_cast<T>(1.0)) if(angleCos >= static_cast<T>(1.0))
{ {
@ -90,9 +87,9 @@ namespace glm
{ {
angle = acos(angleCos); angle = acos(angleCos);
} }
axis.x = (m[1][2] - m[2][1]) / s;
axis.y = (m[2][0] - m[0][2]) / s; axis = glm::normalize(glm::vec<3, T, Q>(
axis.z = (m[0][1] - m[1][0]) / s; m[1][2] - m[2][1], m[2][0] - m[0][2], m[0][1] - m[1][0]));
} }
template<typename T, qualifier Q> template<typename T, qualifier Q>