Added creating a rotation matrix from Euler angles

Creating a rotation matrix for 10 sequences of rotation axes:
z-x-z, x-y-x, y-z-y, z-y-z, x-z-x, y-x-y, y-z-x, z-x-y, x-z-y, z-y-x.
This commit is contained in:
Vitali Parkhomenko 2018-03-19 18:43:01 +03:00
parent 5fe5f32edd
commit 5361f5e4ec
2 changed files with 430 additions and 0 deletions

View File

@ -122,6 +122,86 @@ namespace glm
T const& pitch,
T const& roll);
/// Creates a 3D 4 * 4 homogeneous rotation matrix from euler angles (X * Z * X).
/// @see gtx_euler_angles
template <typename T>
GLM_FUNC_DECL mat<4, 4, T, defaultp> eulerAngleXZX(
T const & t1,
T const & t2,
T const & t3);
/// Creates a 3D 4 * 4 homogeneous rotation matrix from euler angles (X * Y * X).
/// @see gtx_euler_angles
template <typename T>
GLM_FUNC_DECL mat<4, 4, T, defaultp> eulerAngleXYX(
T const & t1,
T const & t2,
T const & t3);
/// Creates a 3D 4 * 4 homogeneous rotation matrix from euler angles (Y * X * Y).
/// @see gtx_euler_angles
template <typename T>
GLM_FUNC_DECL mat<4, 4, T, defaultp> eulerAngleYXY(
T const & t1,
T const & t2,
T const & t3);
/// Creates a 3D 4 * 4 homogeneous rotation matrix from euler angles (Y * Z * Y).
/// @see gtx_euler_angles
template <typename T>
GLM_FUNC_DECL mat<4, 4, T, defaultp> eulerAngleYZY(
T const & t1,
T const & t2,
T const & t3);
/// Creates a 3D 4 * 4 homogeneous rotation matrix from euler angles (Z * Y * Z).
/// @see gtx_euler_angles
template <typename T>
GLM_FUNC_DECL mat<4, 4, T, defaultp> eulerAngleZYZ(
T const & t1,
T const & t2,
T const & t3);
/// Creates a 3D 4 * 4 homogeneous rotation matrix from euler angles (Z * X * Z).
/// @see gtx_euler_angles
template <typename T>
GLM_FUNC_DECL mat<4, 4, T, defaultp> eulerAngleZXZ(
T const & t1,
T const & t2,
T const & t3);
/// Creates a 3D 4 * 4 homogeneous rotation matrix from euler angles (X * Z * Y).
/// @see gtx_euler_angles
template <typename T>
GLM_FUNC_DECL mat<4, 4, T, defaultp> eulerAngleXZY(
T const & t1,
T const & t2,
T const & t3);
/// Creates a 3D 4 * 4 homogeneous rotation matrix from euler angles (Y * Z * X).
/// @see gtx_euler_angles
template <typename T>
GLM_FUNC_DECL mat<4, 4, T, defaultp> eulerAngleYZX(
T const & t1,
T const & t2,
T const & t3);
/// Creates a 3D 4 * 4 homogeneous rotation matrix from euler angles (Z * Y * X).
/// @see gtx_euler_angles
template <typename T>
GLM_FUNC_DECL mat<4, 4, T, defaultp> eulerAngleZYX(
T const & t1,
T const & t2,
T const & t3);
/// Creates a 3D 4 * 4 homogeneous rotation matrix from euler angles (Z * X * Y).
/// @see gtx_euler_angles
template <typename T>
GLM_FUNC_DECL mat<4, 4, T, defaultp> eulerAngleZXY(
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>

View File

@ -252,6 +252,356 @@ namespace glm
return Result;
}
template <typename T>
GLM_FUNC_QUALIFIER mat<4, 4, T, defaultp> eulerAngleXZX
(
T const & t1,
T const & t2,
T const & t3
)
{
T c1 = glm::cos(t1);
T s1 = glm::sin(t1);
T c2 = glm::cos(t2);
T s2 = glm::sin(t2);
T c3 = glm::cos(t3);
T s3 = glm::sin(t3);
mat<4, 4, T, defaultp> Result;
Result[0][0] = c2;
Result[0][1] = c1 * s2;
Result[0][2] = s1 * s2;
Result[0][3] = static_cast<T>(0);
Result[1][0] =-c3 * s2;
Result[1][1] = c1 * c2 * c3 - s1 * s3;
Result[1][2] = c1 * s3 + c2 * c3 * s1;
Result[1][3] = static_cast<T>(0);
Result[2][0] = s2 * s3;
Result[2][1] =-c3 * s1 - c1 * c2 * s3;
Result[2][2] = c1 * c3 - c2 * s1 * s3;
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 mat<4, 4, T, defaultp> eulerAngleXYX
(
T const & t1,
T const & t2,
T const & t3
)
{
T c1 = glm::cos(t1);
T s1 = glm::sin(t1);
T c2 = glm::cos(t2);
T s2 = glm::sin(t2);
T c3 = glm::cos(t3);
T s3 = glm::sin(t3);
mat<4, 4, T, defaultp> Result;
Result[0][0] = c2;
Result[0][1] = s1 * s2;
Result[0][2] =-c1 * s2;
Result[0][3] = static_cast<T>(0);
Result[1][0] = s2 * s3;
Result[1][1] = c1 * c3 - c2 * s1 * s3;
Result[1][2] = c3 * s1 + c1 * c2 * s3;
Result[1][3] = static_cast<T>(0);
Result[2][0] = c3 * s2;
Result[2][1] =-c1 * s3 - c2 * c3 * s1;
Result[2][2] = c1 * c2 * c3 - s1 * s3;
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 mat<4, 4, T, defaultp> eulerAngleYXY
(
T const & t1,
T const & t2,
T const & t3
)
{
T c1 = glm::cos(t1);
T s1 = glm::sin(t1);
T c2 = glm::cos(t2);
T s2 = glm::sin(t2);
T c3 = glm::cos(t3);
T s3 = glm::sin(t3);
mat<4, 4, T, defaultp> Result;
Result[0][0] = c1 * c3 - c2 * s1 * s3;
Result[0][1] = s2* s3;
Result[0][2] =-c3 * s1 - c1 * c2 * s3;
Result[0][3] = static_cast<T>(0);
Result[1][0] = s1 * s2;
Result[1][1] = c2;
Result[1][2] = c1 * s2;
Result[1][3] = static_cast<T>(0);
Result[2][0] = c1 * s3 + c2 * c3 * s1;
Result[2][1] =-c3 * s2;
Result[2][2] = c1 * c2 * c3 - s1 * s3;
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 mat<4, 4, T, defaultp> eulerAngleYZY
(
T const & t1,
T const & t2,
T const & t3
)
{
T c1 = glm::cos(t1);
T s1 = glm::sin(t1);
T c2 = glm::cos(t2);
T s2 = glm::sin(t2);
T c3 = glm::cos(t3);
T s3 = glm::sin(t3);
mat<4, 4, T, defaultp> Result;
Result[0][0] = c1 * c2 * c3 - s1 * s3;
Result[0][1] = c3 * s2;
Result[0][2] =-c1 * s3 - c2 * c3 * s1;
Result[0][3] = static_cast<T>(0);
Result[1][0] =-c1 * s2;
Result[1][1] = c2;
Result[1][2] = s1 * s2;
Result[1][3] = static_cast<T>(0);
Result[2][0] = c3 * s1 + c1 * c2 * s3;
Result[2][1] = s2 * s3;
Result[2][2] = c1 * c3 - c2 * s1 * s3;
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 mat<4, 4, T, defaultp> eulerAngleZYZ
(
T const & t1,
T const & t2,
T const & t3
)
{
T c1 = glm::cos(t1);
T s1 = glm::sin(t1);
T c2 = glm::cos(t2);
T s2 = glm::sin(t2);
T c3 = glm::cos(t3);
T s3 = glm::sin(t3);
mat<4, 4, T, defaultp> Result;
Result[0][0] = c1 * c2 * c3 - s1 * s3;
Result[0][1] = c1 * s3 + c2 * c3 * s1;
Result[0][2] =-c3 * s2;
Result[0][3] = static_cast<T>(0);
Result[1][0] =-c3 * s1 - c1 * c2 * s3;
Result[1][1] = c1 * c3 - c2 * s1 * s3;
Result[1][2] = s2 * s3;
Result[1][3] = static_cast<T>(0);
Result[2][0] = c1 * s2;
Result[2][1] = s1 * s2;
Result[2][2] = 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 mat<4, 4, T, defaultp> eulerAngleZXZ
(
T const & t1,
T const & t2,
T const & t3
)
{
T c1 = glm::cos(t1);
T s1 = glm::sin(t1);
T c2 = glm::cos(t2);
T s2 = glm::sin(t2);
T c3 = glm::cos(t3);
T s3 = glm::sin(t3);
mat<4, 4, T, defaultp> Result;
Result[0][0] = c1 * c3 - c2 * s1 * s3;
Result[0][1] = c3 * s1 + c1 * c2 * s3;
Result[0][2] = s2 *s3;
Result[0][3] = static_cast<T>(0);
Result[1][0] =-c1 * s3 - c2 * c3 * s1;
Result[1][1] = c1 * c2 * c3 - s1 * s3;
Result[1][2] = c3 * s2;
Result[1][3] = static_cast<T>(0);
Result[2][0] = s1 * s2;
Result[2][1] =-c1 * s2;
Result[2][2] = 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 mat<4, 4, T, defaultp> eulerAngleXZY
(
T const & t1,
T const & t2,
T const & t3
)
{
T c1 = glm::cos(t1);
T s1 = glm::sin(t1);
T c2 = glm::cos(t2);
T s2 = glm::sin(t2);
T c3 = glm::cos(t3);
T s3 = glm::sin(t3);
mat<4, 4, T, defaultp> Result;
Result[0][0] = c2 * c3;
Result[0][1] = s1 * s3 + c1 * c3 * s2;
Result[0][2] = c3 * s1 * s2 - c1 * s3;
Result[0][3] = static_cast<T>(0);
Result[1][0] =-s2;
Result[1][1] = c1 * c2;
Result[1][2] = c2 * s1;
Result[1][3] = static_cast<T>(0);
Result[2][0] = c2 * s3;
Result[2][1] = c1 * s2 * s3 - c3 * s1;
Result[2][2] = c1 * c3 + s1 * s2 *s3;
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 mat<4, 4, T, defaultp> eulerAngleYZX
(
T const & t1,
T const & t2,
T const & t3
)
{
T c1 = glm::cos(t1);
T s1 = glm::sin(t1);
T c2 = glm::cos(t2);
T s2 = glm::sin(t2);
T c3 = glm::cos(t3);
T s3 = glm::sin(t3);
mat<4, 4, T, defaultp> Result;
Result[0][0] = c1 * c2;
Result[0][1] = s2;
Result[0][2] =-c2 * s1;
Result[0][3] = static_cast<T>(0);
Result[1][0] = s1 * s3 - c1 * c3 * s2;
Result[1][1] = c2 * c3;
Result[1][2] = c1 * s3 + c3 * s1 * s2;
Result[1][3] = static_cast<T>(0);
Result[2][0] = c3 * s1 + c1 * s2 * s3;
Result[2][1] =-c2 * s3;
Result[2][2] = c1 * c3 - s1 * s2 * s3;
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 mat<4, 4, T, defaultp> eulerAngleZYX
(
T const & t1,
T const & t2,
T const & t3
)
{
T c1 = glm::cos(t1);
T s1 = glm::sin(t1);
T c2 = glm::cos(t2);
T s2 = glm::sin(t2);
T c3 = glm::cos(t3);
T s3 = glm::sin(t3);
mat<4, 4, T, defaultp> Result;
Result[0][0] = c1 * c2;
Result[0][1] = c2 * s1;
Result[0][2] =-s2;
Result[0][3] = static_cast<T>(0);
Result[1][0] = c1 * s2 * s3 - c3 * s1;
Result[1][1] = c1 * c3 + s1 * s2 * s3;
Result[1][2] = c2 * s3;
Result[1][3] = static_cast<T>(0);
Result[2][0] = s1 * s3 + c1 * c3 * s2;
Result[2][1] = c3 * s1 * s2 - c1 * s3;
Result[2][2] = c2 * c3;
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 mat<4, 4, T, defaultp> eulerAngleZXY
(
T const & t1,
T const & t2,
T const & t3
)
{
T c1 = glm::cos(t1);
T s1 = glm::sin(t1);
T c2 = glm::cos(t2);
T s2 = glm::sin(t2);
T c3 = glm::cos(t3);
T s3 = glm::sin(t3);
mat<4, 4, T, defaultp> Result;
Result[0][0] = c1 * c3 - s1 * s2 * s3;
Result[0][1] = c3 * s1 + c1 * s2 * s3;
Result[0][2] =-c2 * s3;
Result[0][3] = static_cast<T>(0);
Result[1][0] =-c2 * s1;
Result[1][1] = c1 * c2;
Result[1][2] = s2;
Result[1][3] = static_cast<T>(0);
Result[2][0] = c1 * s3 + c3 * s1 * s2;
Result[2][1] = s1 * s3 - c1 * c3 * s2;
Result[2][2] = c2 * c3;
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 mat<4, 4, T, defaultp> yawPitchRoll
(