mirror of
https://github.com/g-truc/glm.git
synced 2024-11-22 17:04:35 +00:00
axisAngle refactoring
Signed-off-by: Sergey Krivohatskiy <s.krivohatskiy@gmail.com>
This commit is contained in:
parent
57c3be0b9f
commit
c9c656ce31
@ -1,11 +1,11 @@
|
|||||||
/// @ref gtx_matrix_interpolation
|
/// @ref gtx_matrix_interpolation
|
||||||
|
|
||||||
#include "../gtc/constants.hpp"
|
#include "../ext/scalar_constants.hpp"
|
||||||
|
|
||||||
namespace glm
|
namespace glm
|
||||||
{
|
{
|
||||||
template<typename T, qualifier Q>
|
template<typename T, qualifier Q>
|
||||||
GLM_FUNC_QUALIFIER void axisAngle(mat<4, 4, T, Q> const& m, vec<3, T, Q> & axis, T& angle)
|
GLM_FUNC_QUALIFIER void axisAngle(mat<4, 4, T, Q> const& m, vec<3, T, Q>& axis, T& angle)
|
||||||
{
|
{
|
||||||
T epsilon = static_cast<T>(0.01);
|
T epsilon = static_cast<T>(0.01);
|
||||||
T epsilon2 = static_cast<T>(0.1);
|
T epsilon2 = static_cast<T>(0.1);
|
||||||
@ -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>
|
||||||
|
Loading…
Reference in New Issue
Block a user