From 93a08fce17155addc14fc526644d9e24320d1a67 Mon Sep 17 00:00:00 2001 From: Recep Aslantas Date: Mon, 9 Apr 2018 23:12:44 +0300 Subject: [PATCH] quat: axis angle of quaternion --- include/cglm/quat.h | 50 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) diff --git a/include/cglm/quat.h b/include/cglm/quat.h index efea541..e73bf8b 100644 --- a/include/cglm/quat.h +++ b/include/cglm/quat.h @@ -260,6 +260,56 @@ glm_quat_imag(versor q, vec3 dest) { dest[2] = q[2]; } +/*! + * @brief returns normalized imaginary part of quaternion + * + * @param[in] q quaternion + */ +CGLM_INLINE +void +glm_quat_imagn(versor q, vec3 dest) { + glm_normalize_to(q, dest); +} + +/*! + * @brief returns length of imaginary part of quaternion + * + * @param[in] q quaternion + */ +CGLM_INLINE +float +glm_quat_imaglen(versor q) { + return glm_vec_norm(q); +} + +/*! + * @brief returns angle of quaternion + * + * @param[in] q quaternion + */ +CGLM_INLINE +float +glm_quat_angle(versor q) { + /* + sin(theta / 2) = length(x*x + y*y + z*z) + cos(theta / 2) = w + theta = 2 * atan(sin(theta / 2) / cos(theta / 2)) + */ + return 2.0f * atan2f(glm_quat_imaglen(q), glm_quat_real(q)); +} + +/*! + * @brief axis of quaternion + * + * @param[in] q quaternion + * @param[out] dest axis of quaternion + */ +CGLM_INLINE +void +glm_quat_axis(versor q, versor dest) { + glm_quat_imagn(q, dest); +} + /*! * @brief convert quaternion to mat4 *