mirror of
https://github.com/g-truc/glm.git
synced 2024-11-27 02:34:35 +00:00
Promoted angle axis interaction with quaternion
This commit is contained in:
parent
631240eefa
commit
cb017c5bca
@ -241,6 +241,43 @@ namespace detail
|
||||
detail::tquat<T> quat_cast(
|
||||
detail::tmat4x4<T> const & x);
|
||||
|
||||
/// Returns the quaternion rotation angle.
|
||||
///
|
||||
/// @see gtc_quaternion
|
||||
template <typename valType>
|
||||
valType angle(
|
||||
detail::tquat<valType> const & x);
|
||||
|
||||
/// Returns the q rotation axis.
|
||||
///
|
||||
/// @see gtc_quaternion
|
||||
template <typename valType>
|
||||
detail::tvec3<valType> axis(
|
||||
detail::tquat<valType> const & x);
|
||||
|
||||
/// Build a quaternion from an angle and a normalized axis.
|
||||
///
|
||||
/// @param angle Angle expressed in radians if GLM_FORCE_RADIANS is define or degrees otherwise.
|
||||
///
|
||||
/// @see gtc_quaternion
|
||||
template <typename valType>
|
||||
detail::tquat<valType> angleAxis(
|
||||
valType const & angle,
|
||||
valType const & x,
|
||||
valType const & y,
|
||||
valType const & z);
|
||||
|
||||
/// Build a quaternion from an angle and a normalized axis.
|
||||
///
|
||||
/// @param angle Angle expressed in radians if GLM_FORCE_RADIANS is define or degrees otherwise.
|
||||
/// @param axis Axis of the quaternion, must be normalized.
|
||||
///
|
||||
/// @see gtc_quaternion
|
||||
template <typename valType>
|
||||
detail::tquat<valType> angleAxis(
|
||||
valType const & angle,
|
||||
detail::tvec3<valType> const & axis);
|
||||
|
||||
/// Quaternion of floating-point numbers.
|
||||
///
|
||||
/// @see gtc_quaternion
|
||||
|
@ -615,4 +615,65 @@ namespace detail
|
||||
return quat_cast(detail::tmat3x3<T>(m4));
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
GLM_FUNC_QUALIFIER T angle
|
||||
(
|
||||
detail::tquat<T> const & x
|
||||
)
|
||||
{
|
||||
#ifdef GLM_FORCE_RADIANS
|
||||
return acos(x.w) * T(2);
|
||||
#else
|
||||
return glm::degrees(acos(x.w) * T(2));
|
||||
#endif
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
GLM_FUNC_QUALIFIER detail::tvec3<T> axis
|
||||
(
|
||||
detail::tquat<T> const & x
|
||||
)
|
||||
{
|
||||
T tmp1 = T(1) - x.w * x.w;
|
||||
if(tmp1 <= T(0))
|
||||
return detail::tvec3<T>(0, 0, 1);
|
||||
T tmp2 = T(1) / sqrt(tmp1);
|
||||
return detail::tvec3<T>(x.x * tmp2, x.y * tmp2, x.z * tmp2);
|
||||
}
|
||||
|
||||
template <typename valType>
|
||||
GLM_FUNC_QUALIFIER detail::tquat<valType> angleAxis
|
||||
(
|
||||
valType const & angle,
|
||||
valType const & x,
|
||||
valType const & y,
|
||||
valType const & z
|
||||
)
|
||||
{
|
||||
return angleAxis(angle, detail::tvec3<valType>(x, y, z));
|
||||
}
|
||||
|
||||
template <typename valType>
|
||||
GLM_FUNC_QUALIFIER detail::tquat<valType> angleAxis
|
||||
(
|
||||
valType const & angle,
|
||||
detail::tvec3<valType> const & v
|
||||
)
|
||||
{
|
||||
detail::tquat<valType> result;
|
||||
|
||||
#ifdef GLM_FORCE_RADIANS
|
||||
valType a(angle);
|
||||
#else
|
||||
valType a(glm::radians(angle));
|
||||
#endif
|
||||
valType s = glm::sin(a * valType(0.5));
|
||||
|
||||
result.w = glm::cos(a * valType(0.5));
|
||||
result.x = v.x * s;
|
||||
result.y = v.y * s;
|
||||
result.z = v.z * s;
|
||||
return result;
|
||||
}
|
||||
|
||||
}//namespace glm
|
||||
|
@ -135,43 +135,6 @@ namespace glm
|
||||
detail::tquat<valType> const & q,
|
||||
detail::tvec4<valType> const & v);
|
||||
|
||||
/// Returns the quaternion rotation angle.
|
||||
///
|
||||
/// @see gtx_quaternion
|
||||
template <typename valType>
|
||||
valType angle(
|
||||
detail::tquat<valType> const & x);
|
||||
|
||||
/// Returns the q rotation axis.
|
||||
///
|
||||
/// @see gtx_quaternion
|
||||
template <typename valType>
|
||||
detail::tvec3<valType> axis(
|
||||
detail::tquat<valType> const & x);
|
||||
|
||||
/// Build a quaternion from an angle and a normalized axis.
|
||||
///
|
||||
/// @param angle Angle expressed in radians if GLM_FORCE_RADIANS is define or degrees otherwise.
|
||||
///
|
||||
/// @see gtx_quaternion
|
||||
template <typename valType>
|
||||
detail::tquat<valType> angleAxis(
|
||||
valType const & angle,
|
||||
valType const & x,
|
||||
valType const & y,
|
||||
valType const & z);
|
||||
|
||||
/// Build a quaternion from an angle and a normalized axis.
|
||||
///
|
||||
/// @param angle Angle expressed in radians if GLM_FORCE_RADIANS is define or degrees otherwise.
|
||||
/// @param axis Axis of the quaternion, must be normalized.
|
||||
///
|
||||
/// @see gtx_quaternion
|
||||
template <typename valType>
|
||||
detail::tquat<valType> angleAxis(
|
||||
valType const & angle,
|
||||
detail::tvec3<valType> const & axis);
|
||||
|
||||
/// Extract the real component of a quaternion.
|
||||
///
|
||||
/// @see gtx_quaternion
|
||||
|
@ -141,67 +141,6 @@ namespace glm
|
||||
return q * v;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
GLM_FUNC_QUALIFIER T angle
|
||||
(
|
||||
detail::tquat<T> const & x
|
||||
)
|
||||
{
|
||||
#ifdef GLM_FORCE_RADIANS
|
||||
return acos(x.w) * T(2);
|
||||
#else
|
||||
return glm::degrees(acos(x.w) * T(2));
|
||||
#endif
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
GLM_FUNC_QUALIFIER detail::tvec3<T> axis
|
||||
(
|
||||
detail::tquat<T> const & x
|
||||
)
|
||||
{
|
||||
T tmp1 = T(1) - x.w * x.w;
|
||||
if(tmp1 <= T(0))
|
||||
return detail::tvec3<T>(0, 0, 1);
|
||||
T tmp2 = T(1) / sqrt(tmp1);
|
||||
return detail::tvec3<T>(x.x * tmp2, x.y * tmp2, x.z * tmp2);
|
||||
}
|
||||
|
||||
template <typename valType>
|
||||
GLM_FUNC_QUALIFIER detail::tquat<valType> angleAxis
|
||||
(
|
||||
valType const & angle,
|
||||
valType const & x,
|
||||
valType const & y,
|
||||
valType const & z
|
||||
)
|
||||
{
|
||||
return angleAxis(angle, detail::tvec3<valType>(x, y, z));
|
||||
}
|
||||
|
||||
template <typename valType>
|
||||
GLM_FUNC_QUALIFIER detail::tquat<valType> angleAxis
|
||||
(
|
||||
valType const & angle,
|
||||
detail::tvec3<valType> const & v
|
||||
)
|
||||
{
|
||||
detail::tquat<valType> result;
|
||||
|
||||
#ifdef GLM_FORCE_RADIANS
|
||||
valType a(angle);
|
||||
#else
|
||||
valType a(glm::radians(angle));
|
||||
#endif
|
||||
valType s = glm::sin(a * valType(0.5));
|
||||
|
||||
result.w = glm::cos(a * valType(0.5));
|
||||
result.x = v.x * s;
|
||||
result.y = v.y * s;
|
||||
result.z = v.z * s;
|
||||
return result;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
GLM_FUNC_QUALIFIER T extractRealComponent
|
||||
(
|
||||
|
Loading…
Reference in New Issue
Block a user