Skip to content

Commit

Permalink
Merge pull request #311 from jzrake/master
Browse files Browse the repository at this point in the history
Add functions eulerAngleXYZ and extractEulerAngleXYZ #311
  • Loading branch information
Groovounet committed Mar 15, 2015
2 parents 4176765 + d331342 commit 14c3673
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 2 deletions.
18 changes: 17 additions & 1 deletion glm/gtx/euler_angles.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -114,14 +114,22 @@ namespace glm
T const & angleZ,
T const & angleY);

/// Creates a 3D 4 * 4 homogeneous rotation matrix from euler angles (X * Y * Z).
/// @see gtx_euler_angles
template <typename T>
GLM_FUNC_DECL tmat4x4<T, defaultp> eulerAngleXYZ(
T const & t1,
T const & t2,
T const & t3);

/// Creates a 3D 4 * 4 homogeneous rotation matrix from euler angles (Y * X * Z).
/// @see gtx_euler_angles
template <typename T>
GLM_FUNC_DECL tmat4x4<T, defaultp> eulerAngleYXZ(
T const & yaw,
T const & pitch,
T const & roll);

/// Creates a 3D 4 * 4 homogeneous rotation matrix from euler angles (Y * X * Z).
/// @see gtx_euler_angles
template <typename T>
Expand Down Expand Up @@ -150,6 +158,14 @@ namespace glm
template <typename T, precision P>
GLM_FUNC_DECL tmat4x4<T, P> orientate4(tvec3<T, P> const & angles);

/// Extracts the (X * Y * Z) Euler angles from the rotation matrix M
/// @see gtx_euler_angles
template <typename T>
GLM_FUNC_DECL void extractEulerAngleXYZ(tmat4x4<T, defaultp> & M,
T & t1,
T & t2,
T & t3);

/// @}
}//namespace glm

Expand Down
56 changes: 55 additions & 1 deletion glm/gtx/euler_angles.inl
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@
/// @author Christophe Riccio
///////////////////////////////////////////////////////////////////////////////////////////////////

#include "compatibility.hpp" // glm::atan2

namespace glm
{
template <typename T>
Expand Down Expand Up @@ -157,7 +159,42 @@ namespace glm
{
return eulerAngleZ(angleZ) * eulerAngleY(angleY);
}


template <typename T>
GLM_FUNC_QUALIFIER tmat4x4<T, defaultp> eulerAngleXYZ
(
T const & t1,
T const & t2,
T const & t3
)
{
T c1 = glm::cos(-t1);
T c2 = glm::cos(-t2);
T c3 = glm::cos(-t3);
T s1 = glm::sin(-t1);
T s2 = glm::sin(-t2);
T s3 = glm::sin(-t3);

tmat4x4<T, defaultp> Result;
Result[0][0] = c2 * c3;
Result[0][1] =-c1 * s3 + s1 * s2 * c3;
Result[0][2] = s1 * s3 + c1 * s2 * c3;
Result[0][3] = static_cast<T>(0);
Result[1][0] = c2 * s3;
Result[1][1] = c1 * c3 + s1 * s2 * s3;
Result[1][2] =-s1 * c3 + c1 * s2 * s3;
Result[1][3] = static_cast<T>(0);
Result[2][0] =-s2;
Result[2][1] = s1 * c2;
Result[2][2] = c1 * c2;
Result[2][3] = static_cast<T>(0);
Result[3][0] = static_cast<T>(0);
Result[3][1] = static_cast<T>(0);
Result[3][2] = static_cast<T>(0);
Result[3][3] = static_cast<T>(1);
return Result;
}

template <typename T>
GLM_FUNC_QUALIFIER tmat4x4<T, defaultp> eulerAngleYXZ
(
Expand Down Expand Up @@ -284,4 +321,21 @@ namespace glm
{
return yawPitchRoll(angles.z, angles.x, angles.y);
}

template <typename T>
GLM_FUNC_DECL void extractEulerAngleXYZ(tmat4x4<T, defaultp> & M,
T & t1,
T & t2,
T & t3)
{
float T1 = glm::atan2<T, defaultp>(M[2][1], M[2][2]);
float C2 = glm::sqrt(M[0][0]*M[0][0] + M[1][0]*M[1][0]);
float T2 = glm::atan2<T, defaultp>(-M[2][0], C2);
float S1 = glm::sin(T1);
float C1 = glm::cos(T1);
float T3 = glm::atan2<T, defaultp>(S1*M[0][2] - C1*M[0][1], C1*M[1][1] - S1*M[1][2 ]);
t1 = -T1;
t2 = -T2;
t3 = -T3;
}
}//namespace glm

0 comments on commit 14c3673

Please sign in to comment.