From f8bd200d400260f89b60468ca48e45a4f5d09638 Mon Sep 17 00:00:00 2001 From: Recep Aslantas Date: Mon, 24 Oct 2016 14:00:04 +0300 Subject: [PATCH] euler angles zyx --- include/cglm-euler.h | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/include/cglm-euler.h b/include/cglm-euler.h index bd6fb2b..ddbe783 100644 --- a/include/cglm-euler.h +++ b/include/cglm-euler.h @@ -44,6 +44,40 @@ glm_euler(float yaw, dest[3][3] = 1.0f; } +/*! + * @brief build rotation matrix from euler angles (zyx) + */ +CGLM_INLINE +void +glm_euler_zyx(float yaw, + float pitch, + float roll, + mat4 dest) { + float cx, cy, cz, + sx, sy, sz; + + sx = sinf(pitch); cx = cosf(pitch); + sy = sinf(yaw); cy = cosf(yaw); + sz = sinf(roll); cz = cosf(roll); + + dest[0][0] = cy * cz; + dest[0][1] = cy * sz; + dest[0][2] =-sy; + dest[1][0] = cz * sx * sy - cx * sz; + dest[1][1] = cx * cz + sx * sy * sz; + dest[1][2] = cy * sx; + dest[2][0] = cx * cz * sy + sx * sz; + dest[2][1] =-cz * sx + cx * sy * sz; + dest[2][2] = cx * cy; + dest[0][3] = 0.0f; + dest[1][3] = 0.0f; + dest[2][3] = 0.0f; + dest[3][0] = 0.0f; + dest[3][1] = 0.0f; + dest[3][2] = 0.0f; + dest[3][3] = 1.0f; +} + /*! * @brief build rotation matrix from euler angles (zxy) */