mirror of
https://github.com/recp/cglm.git
synced 2026-02-17 03:39:05 +00:00
quat: quaternion to mat3
This commit is contained in:
@@ -51,6 +51,10 @@ CGLM_EXPORT
|
|||||||
void
|
void
|
||||||
glmc_quat_mat4(versor q, mat4 dest);
|
glmc_quat_mat4(versor q, mat4 dest);
|
||||||
|
|
||||||
|
CGLM_EXPORT
|
||||||
|
void
|
||||||
|
glmc_quat_mat3(versor q, mat3 dest);
|
||||||
|
|
||||||
CGLM_EXPORT
|
CGLM_EXPORT
|
||||||
void
|
void
|
||||||
glmc_quat_slerp(versor q,
|
glmc_quat_slerp(versor q,
|
||||||
|
|||||||
@@ -216,6 +216,42 @@ glm_quat_mat4(versor q, mat4 dest) {
|
|||||||
dest[3][3] = 1.0f;
|
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
|
* @brief interpolates between two quaternions
|
||||||
* using spherical linear interpolation (SLERP)
|
* using spherical linear interpolation (SLERP)
|
||||||
|
|||||||
@@ -62,6 +62,12 @@ glmc_quat_mat4(versor q, mat4 dest) {
|
|||||||
glm_quat_mat4(q, dest);
|
glm_quat_mat4(q, dest);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
CGLM_EXPORT
|
||||||
|
void
|
||||||
|
glmc_quat_mat3(versor q, mat3 dest) {
|
||||||
|
glm_quat_mat3(q, dest);
|
||||||
|
}
|
||||||
|
|
||||||
CGLM_EXPORT
|
CGLM_EXPORT
|
||||||
void
|
void
|
||||||
glmc_quat_slerp(versor q,
|
glmc_quat_slerp(versor q,
|
||||||
|
|||||||
Reference in New Issue
Block a user