quat: quaternion to mat3

This commit is contained in:
Recep Aslantas
2018-04-07 13:27:40 +03:00
parent ae06c51746
commit 9b8748acc4
3 changed files with 46 additions and 0 deletions

View File

@@ -51,6 +51,10 @@ CGLM_EXPORT
void
glmc_quat_mat4(versor q, mat4 dest);
CGLM_EXPORT
void
glmc_quat_mat3(versor q, mat3 dest);
CGLM_EXPORT
void
glmc_quat_slerp(versor q,

View File

@@ -216,6 +216,42 @@ glm_quat_mat4(versor q, mat4 dest) {
dest[3][3] = 1.0f;
}
/*!
* @brief convert quaternion to mat3
*
* @param[in] q quaternion
* @param[out] dest result matrix
*/
CGLM_INLINE
void
glm_quat_mat3(versor q, mat3 dest) {
float w, x, y, z;
float xx, yy, zz;
float xy, yz, xz;
float wx, wy, wz;
w = q[0];
x = q[1];
y = q[2];
z = q[3];
xx = 2.0f * x * x; xy = 2.0f * x * y; wx = 2.0f * w * x;
yy = 2.0f * y * y; yz = 2.0f * y * z; wy = 2.0f * w * y;
zz = 2.0f * z * z; xz = 2.0f * x * z; wz = 2.0f * w * z;
dest[0][0] = 1.0f - yy - zz;
dest[1][1] = 1.0f - xx - zz;
dest[2][2] = 1.0f - xx - yy;
dest[0][1] = xy + wz;
dest[1][2] = yz + wx;
dest[2][0] = xz + wy;
dest[1][0] = xy - wz;
dest[2][1] = yz - wx;
dest[0][2] = xz - wy;
}
/*!
* @brief interpolates between two quaternions
* using spherical linear interpolation (SLERP)

View File

@@ -62,6 +62,12 @@ glmc_quat_mat4(versor q, mat4 dest) {
glm_quat_mat4(q, dest);
}
CGLM_EXPORT
void
glmc_quat_mat3(versor q, mat3 dest) {
glm_quat_mat3(q, dest);
}
CGLM_EXPORT
void
glmc_quat_slerp(versor q,