mirror of
https://github.com/recp/cglm.git
synced 2026-02-17 03:39:05 +00:00
replace mat4_mulq with glm_quat_rotate
* glm_quat_rotate is better name to rotate transform matrix using quaternion. * we may use mat4_mulq in the future for another purpose e.g. left multiplication quat with matrix
This commit is contained in:
@@ -53,10 +53,6 @@ CGLM_EXPORT
|
|||||||
void
|
void
|
||||||
glmc_mat4_mulv(mat4 m, vec4 v, vec4 dest);
|
glmc_mat4_mulv(mat4 m, vec4 v, vec4 dest);
|
||||||
|
|
||||||
CGLM_EXPORT
|
|
||||||
void
|
|
||||||
glmc_mat4_mulq(mat4 m, versor q, mat4 dest);
|
|
||||||
|
|
||||||
CGLM_EXPORT
|
CGLM_EXPORT
|
||||||
void
|
void
|
||||||
glmc_mat4_quat(mat4 m, versor dest);
|
glmc_mat4_quat(mat4 m, versor dest);
|
||||||
|
|||||||
@@ -319,21 +319,6 @@ glm_mat4_mulv(mat4 m, vec4 v, vec4 dest) {
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
/*!
|
|
||||||
* @brief multiply mat4 with quaternion and store in dest vector
|
|
||||||
*
|
|
||||||
* @param[in] m left matrix
|
|
||||||
* @param[in] q quaternion as right matrix
|
|
||||||
* @param[out] dest destination matrix
|
|
||||||
*/
|
|
||||||
CGLM_INLINE
|
|
||||||
void
|
|
||||||
glm_mat4_mulq(mat4 m, versor q, mat4 dest) {
|
|
||||||
mat4 rot;
|
|
||||||
glm_quat_mat4(q, rot);
|
|
||||||
glm_mat4_mul(m, rot, dest);
|
|
||||||
}
|
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
* @brief convert mat4's rotation part to quaternion
|
* @brief convert mat4's rotation part to quaternion
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -15,8 +15,10 @@
|
|||||||
CGLM_INLINE void glm_quat_init(versor q, float x, float y, float z, float w);
|
CGLM_INLINE void glm_quat_init(versor q, float x, float y, float z, float w);
|
||||||
CGLM_INLINE void glm_quat(versor q, float angle, float x, float y, float z);
|
CGLM_INLINE void glm_quat(versor q, float angle, float x, float y, float z);
|
||||||
CGLM_INLINE void glm_quatv(versor q, float angle, vec3 axis);
|
CGLM_INLINE void glm_quatv(versor q, float angle, vec3 axis);
|
||||||
|
CGLM_INLINE void glm_quat_copy(versor q, versor dest);
|
||||||
CGLM_INLINE float glm_quat_norm(versor q);
|
CGLM_INLINE float glm_quat_norm(versor q);
|
||||||
CGLM_INLINE void glm_quat_normalize(versor q);
|
CGLM_INLINE void glm_quat_normalize(versor q);
|
||||||
|
CGLM_INLINE void glm_quat_normalize_to(versor q, versor dest);
|
||||||
CGLM_INLINE float glm_quat_dot(versor q1, versor q2);
|
CGLM_INLINE float glm_quat_dot(versor q1, versor q2);
|
||||||
CGLM_INLINE void glm_quat_conjugate(versor q, versor dest);
|
CGLM_INLINE void glm_quat_conjugate(versor q, versor dest);
|
||||||
CGLM_INLINE void glm_quat_inv(versor q, versor dest);
|
CGLM_INLINE void glm_quat_inv(versor q, versor dest);
|
||||||
@@ -30,8 +32,20 @@
|
|||||||
CGLM_INLINE void glm_quat_axis(versor q, versor dest);
|
CGLM_INLINE void glm_quat_axis(versor q, versor dest);
|
||||||
CGLM_INLINE void glm_quat_mul(versor p, versor q, versor dest);
|
CGLM_INLINE void glm_quat_mul(versor p, versor q, versor dest);
|
||||||
CGLM_INLINE void glm_quat_mat4(versor q, mat4 dest);
|
CGLM_INLINE void glm_quat_mat4(versor q, mat4 dest);
|
||||||
CGLM_INLINE void glm_quat_mat3(versor q, mat3 dest)
|
CGLM_INLINE void glm_quat_mat4t(versor q, mat4 dest);
|
||||||
|
CGLM_INLINE void glm_quat_mat3(versor q, mat3 dest);
|
||||||
|
CGLM_INLINE void glm_quat_mat3t(versor q, mat3 dest);
|
||||||
|
CGLM_INLINE void glm_quat_lerp(versor from, versor to, float t, versor dest);
|
||||||
CGLM_INLINE void glm_quat_slerp(versor q, versor r, float t, versor dest);
|
CGLM_INLINE void glm_quat_slerp(versor q, versor r, float t, versor dest);
|
||||||
|
CGLM_INLINE void glm_quat_look(vec3 eye, versor ori, mat4 dest);
|
||||||
|
CGLM_INLINE void glm_quat_for(vec3 dir, vec3 fwd, vec3 up, versor dest);
|
||||||
|
CGLM_INLINE void glm_quat_forp(vec3 from,
|
||||||
|
vec3 to,
|
||||||
|
vec3 fwd,
|
||||||
|
vec3 up,
|
||||||
|
versor dest);
|
||||||
|
CGLM_INLINE void glm_quat_rotatev(versor q, vec3 v, vec3 dest);
|
||||||
|
CGLM_INLINE void glm_quat_rotate(mat4 m, versor q, mat4 dest);
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef cglm_quat_h
|
#ifndef cglm_quat_h
|
||||||
@@ -46,6 +60,14 @@
|
|||||||
# include "simd/sse2/quat.h"
|
# include "simd/sse2/quat.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
CGLM_INLINE
|
||||||
|
void
|
||||||
|
glm_mat4_mulv(mat4 m, vec4 v, vec4 dest);
|
||||||
|
|
||||||
|
CGLM_INLINE
|
||||||
|
void
|
||||||
|
glm_mat4_mul(mat4 m1, mat4 m2, mat4 dest);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* IMPORTANT:
|
* IMPORTANT:
|
||||||
* ----------------------------------------------------------------------------
|
* ----------------------------------------------------------------------------
|
||||||
@@ -603,10 +625,6 @@ glm_quat_slerp(versor from, versor to, float t, versor dest) {
|
|||||||
glm_vec4_scale(q1, 1.0f / sinTheta, dest);
|
glm_vec4_scale(q1, 1.0f / sinTheta, dest);
|
||||||
}
|
}
|
||||||
|
|
||||||
CGLM_INLINE
|
|
||||||
void
|
|
||||||
glm_mat4_mulv(mat4 m, vec4 v, vec4 dest);
|
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
* @brief creates view matrix using quaternion as camera orientation
|
* @brief creates view matrix using quaternion as camera orientation
|
||||||
*
|
*
|
||||||
@@ -677,7 +695,7 @@ glm_quat_forp(vec3 from, vec3 to, vec3 fwd, vec3 up, versor dest) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
* @brief rotate existing transform matrix using quaternion
|
* @brief rotate vector using using quaternion
|
||||||
*
|
*
|
||||||
* @param[in] q quaternion
|
* @param[in] q quaternion
|
||||||
* @param[in] v vector to rotate
|
* @param[in] v vector to rotate
|
||||||
@@ -704,4 +722,19 @@ glm_quat_rotatev(versor q, vec3 v, vec3 dest) {
|
|||||||
glm_vec_add(v1, v2, dest);
|
glm_vec_add(v1, v2, dest);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* @brief rotate existing transform matrix using quaternion
|
||||||
|
*
|
||||||
|
* @param[in] m existing transform matrix
|
||||||
|
* @param[in] q quaternion
|
||||||
|
* @param[out] dest destination matrix
|
||||||
|
*/
|
||||||
|
CGLM_INLINE
|
||||||
|
void
|
||||||
|
glm_quat_rotate(mat4 m, versor q, mat4 dest) {
|
||||||
|
mat4 rot;
|
||||||
|
glm_quat_mat4(q, rot);
|
||||||
|
glm_mat4_mul(m, rot, dest);
|
||||||
|
}
|
||||||
|
|
||||||
#endif /* cglm_quat_h */
|
#endif /* cglm_quat_h */
|
||||||
|
|||||||
@@ -62,12 +62,6 @@ glmc_mat4_mulv(mat4 m, vec4 v, vec4 dest) {
|
|||||||
glm_mat4_mulv(m, v, dest);
|
glm_mat4_mulv(m, v, dest);
|
||||||
}
|
}
|
||||||
|
|
||||||
CGLM_EXPORT
|
|
||||||
void
|
|
||||||
glmc_mat4_mulq(mat4 m, versor q, mat4 dest) {
|
|
||||||
glm_mat4_mulq(m, q, dest);
|
|
||||||
}
|
|
||||||
|
|
||||||
CGLM_EXPORT
|
CGLM_EXPORT
|
||||||
void
|
void
|
||||||
glmc_mat4_quat(mat4 m, versor dest) {
|
glmc_mat4_quat(mat4 m, versor dest) {
|
||||||
|
|||||||
@@ -154,5 +154,35 @@ test_quat(void **state) {
|
|||||||
|
|
||||||
test_assert_vec3_eq(v1, v2);
|
test_assert_vec3_eq(v1, v2);
|
||||||
|
|
||||||
|
/* 11. test rotate transform */
|
||||||
|
glm_translate_make(rot1, (vec3){-10.0, 45.0f, 8.0f});
|
||||||
|
glm_rotate(rot1, glm_rad(-90), GLM_ZUP);
|
||||||
|
|
||||||
|
glm_quatv(q3, glm_rad(-90.0f), GLM_ZUP);
|
||||||
|
glm_translate_make(rot2, (vec3){-10.0, 45.0f, 8.0f});
|
||||||
|
glm_quat_rotate(rot2, q3, rot2);
|
||||||
|
|
||||||
|
/* result must be same (almost) */
|
||||||
|
test_assert_mat4_eq2(rot1, rot2, 0.000009);
|
||||||
|
|
||||||
|
glm_rotate_make(rot1, glm_rad(-90), GLM_ZUP);
|
||||||
|
glm_translate(rot1, (vec3){-10.0, 45.0f, 8.0f});
|
||||||
|
|
||||||
|
glm_quatv(q3, glm_rad(-90.0f), GLM_ZUP);
|
||||||
|
glm_mat4_identity(rot2);
|
||||||
|
glm_quat_rotate(rot2, q3, rot2);
|
||||||
|
glm_translate(rot2, (vec3){-10.0, 45.0f, 8.0f});
|
||||||
|
|
||||||
|
/* result must be same (almost) */
|
||||||
|
test_assert_mat4_eq2(rot1, rot2, 0.000009);
|
||||||
|
|
||||||
|
/* reverse */
|
||||||
|
glm_rotate_make(rot1, glm_rad(-90), GLM_ZUP);
|
||||||
|
glm_quatv(q3, glm_rad(90.0f), GLM_ZUP);
|
||||||
|
glm_quat_rotate(rot1, q3, rot1);
|
||||||
|
|
||||||
|
/* result must be identity */
|
||||||
|
test_assert_mat4_eq2(rot1, GLM_MAT4_IDENTITY, 0.000009);
|
||||||
|
|
||||||
/* TODO: add tests for slerp, lerp */
|
/* TODO: add tests for slerp, lerp */
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user