Fixed bug #15, added missing roll, pitch and yaw functions; Fixed half implicit conversions

This commit is contained in:
Christophe Riccio
2012-12-13 22:48:20 +01:00
parent 931b7bcdd6
commit 841f91e830
11 changed files with 244 additions and 171 deletions

View File

@@ -212,6 +212,27 @@ namespace detail
detail::tvec3<T> eulerAngles(
detail::tquat<T> const & x);
/// Returns roll value of euler angles expressed in radians if GLM_FORCE_RADIANS is define or degrees otherwise.
///
/// @see gtx_quaternion
template <typename valType>
valType roll(
detail::tquat<valType> const & x);
/// Returns pitch value of euler angles expressed in radians if GLM_FORCE_RADIANS is define or degrees otherwise.
///
/// @see gtx_quaternion
template <typename valType>
valType pitch(
detail::tquat<valType> const & x);
/// Returns yaw value of euler angles expressed in radians if GLM_FORCE_RADIANS is define or degrees otherwise.
///
/// @see gtx_quaternion
template <typename valType>
valType yaw(
detail::tquat<valType> const & x);
/// Converts a quaternion to a 3 * 3 matrix.
///
/// @see gtc_quaternion

View File

@@ -512,7 +512,46 @@ namespace detail
{
return detail::tvec3<T>(pitch(x), yaw(x), roll(x));
}
template <typename valType>
GLM_FUNC_QUALIFIER valType roll
(
detail::tquat<valType> const & q
)
{
#ifdef GLM_FORCE_RADIANS
return valType(atan2(valType(2) * (q.x * q.y + q.w * q.z), q.w * q.w + q.x * q.x - q.y * q.y - q.z * q.z));
#else
return glm::degrees(atan(valType(2) * (q.x * q.y + q.w * q.z), q.w * q.w + q.x * q.x - q.y * q.y - q.z * q.z));
#endif
}
template <typename valType>
GLM_FUNC_QUALIFIER valType pitch
(
detail::tquat<valType> const & q
)
{
#ifdef GLM_FORCE_RADIANS
return valType(atan2(valType(2) * (q.y * q.z + q.w * q.x), q.w * q.w - q.x * q.x - q.y * q.y + q.z * q.z));
#else
return glm::degrees(atan(valType(2) * (q.y * q.z + q.w * q.x), q.w * q.w - q.x * q.x - q.y * q.y + q.z * q.z));
#endif
}
template <typename valType>
GLM_FUNC_QUALIFIER valType yaw
(
detail::tquat<valType> const & q
)
{
#ifdef GLM_FORCE_RADIANS
return asin(valType(-2) * (q.x * q.z - q.w * q.y));
#else
return glm::degrees(asin(valType(-2) * (q.x * q.z - q.w * q.y)));
#endif
}
template <typename T>
GLM_FUNC_QUALIFIER detail::tmat3x3<T> mat3_cast
(