Skip to content

Commit

Permalink
Fixed axisAngle NaN #638
Browse files Browse the repository at this point in the history
  • Loading branch information
Groovounet committed Jun 24, 2017
1 parent 631fd17 commit 26b3e3e
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 2 deletions.
8 changes: 7 additions & 1 deletion glm/gtx/matrix_interpolation.inl
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
/// @ref gtx_matrix_interpolation
/// @file glm/gtx/matrix_interpolation.hpp

#include "../gtc/constants.hpp"

namespace glm
{
template<typename T, precision P>
Expand Down Expand Up @@ -72,7 +74,11 @@ 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)0.5);
T const angleCos = (mat[0][0] + mat[1][1] + mat[2][2] - (T)1.0) * (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;
Expand Down
1 change: 1 addition & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ glm::mat4 camera(float Translate, glm::vec2 const & Rotate)
- Fixed usused variable warning in GTX_spline #618
- Fixed references to GLM_FORCE_RADIANS which was removed #642
- Fixed glm::fastInverseSqrt to use fast inverse square #640
- Fixed axisAngle NaN #638
#### Deprecation:
- Requires Visual Studio 2013, GCC 4.7, Clang 3.4, Cuda 7, ICC 2013 or a C++11 compiler
Expand Down
38 changes: 37 additions & 1 deletion test/gtx/gtx_matrix_interpolation.cpp
Original file line number Diff line number Diff line change
@@ -1,9 +1,45 @@
#define GLM_ENABLE_EXPERIMENTAL
#include <glm/gtc/quaternion.hpp>
#include <glm/gtx/matrix_interpolation.hpp>

#include <iostream>

int test_axisAngle()
{
int Error = 0;

float p = 0.171654f;
glm::mat4 m1(-0.9946f, 0.0f, -0.104531f, 0.0f,
0.0f, 1.0f, 0.0f, 0.0f,
0.104531f, 0.0f, -0.9946f, 0.0f,
0.0f, 0.0f, 0.0f, 1.0f);
glm::mat4 m2(-0.992624f, 0.0f, -0.121874f, 0.0f,
0.0f, 1.0f, 0.0f, 0.0f,
0.121874f, 0.0f, -0.992624f, 0.0f,
0.0f, 0.0f, 0.0f, 1.0f);

glm::mat4 const m1rot = glm::extractMatrixRotation(m1);
glm::mat4 const dltRotation = m2 * glm::transpose(m1rot);

glm::vec3 dltAxis(0.0f);
float dltAngle = 0.0f;
glm::axisAngle(dltRotation, dltAxis, dltAngle);

std::cout << "dltAngle: (" << dltAxis.x << ", " << dltAxis.y << ", " << dltAxis.z << "), dltAngle: " << dltAngle << std::endl;

glm::fquat q = glm::quat_cast(dltRotation);
std::cout << "q: (" << q.x << ", " << q.y << ", " << q.z << ", " << q.w << ")" << std::endl;
float yaw = glm::yaw(q);
std::cout << "Yaw: " << yaw << std::endl;

return Error;
}

int main()
{
int Error(0);
int Error = 0;

Error += test_axisAngle();

return Error;
}
Expand Down

0 comments on commit 26b3e3e

Please sign in to comment.