mirror of
https://github.com/recp/cglm.git
synced 2025-10-04 09:08:53 +00:00
implement euler angles zxy, zyx (yaw-pitch-roll)
This commit is contained in:
75
include/cglm-euler.h
Normal file
75
include/cglm-euler.h
Normal file
@@ -0,0 +1,75 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c), Recep Aslantas.
|
||||||
|
*
|
||||||
|
* MIT License (MIT), http://opensource.org/licenses/MIT
|
||||||
|
* Full license can be found in the LICENSE file
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef cglm_euler_h
|
||||||
|
#define cglm_euler_h
|
||||||
|
|
||||||
|
#include "cglm.h"
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* @brief build rotation matrix from euler angles (zxy)
|
||||||
|
*/
|
||||||
|
CGLM_INLINE
|
||||||
|
void
|
||||||
|
glm_euler_angle(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 - sx * sy * sz;
|
||||||
|
dest[0][1] = cy * sz + cz * sx * sy;
|
||||||
|
dest[0][2] =-cx * sy;
|
||||||
|
dest[1][0] =-cx * sz;
|
||||||
|
dest[1][1] = cx * cz;
|
||||||
|
dest[1][2] = sx;
|
||||||
|
dest[2][0] = cz * sy + cy * sx * sz;
|
||||||
|
dest[2][1] = sy * sz - cy * cz * sx;
|
||||||
|
dest[2][2] = cx * cy;
|
||||||
|
dest[0][3] = 0.0f;
|
||||||
|
dest[1][3] = 0.0f;
|
||||||
|
dest[2][3] = 0.0f;
|
||||||
|
dest[3][3] = 1.0f;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* @brief build rotation matrix from euler angles/yaw-pitch-roll (zyx)
|
||||||
|
*/
|
||||||
|
CGLM_INLINE
|
||||||
|
void
|
||||||
|
glm_yaw_pitch_roll(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][3] = 1.0f;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif /* cglm_euler_h */
|
@@ -25,5 +25,6 @@ typedef vec4 versor;
|
|||||||
#include "cglm-affine.h"
|
#include "cglm-affine.h"
|
||||||
#include "cglm-cam.h"
|
#include "cglm-cam.h"
|
||||||
#include "cglm-quat.h"
|
#include "cglm-quat.h"
|
||||||
|
#include "cglm-euler.h"
|
||||||
|
|
||||||
#endif /* glm_h */
|
#endif /* glm_h */
|
||||||
|
Reference in New Issue
Block a user