mirror of
https://github.com/recp/cglm.git
synced 2026-02-17 03:39:05 +00:00
quat: use vector functions for available operations
* provide quat_copy function
This commit is contained in:
@@ -133,6 +133,18 @@ glm_quatv(versor q, float angle, vec3 axis) {
|
|||||||
q[3] = c;
|
q[3] = c;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* @brief copy quaternion to another one
|
||||||
|
*
|
||||||
|
* @param[in] q quaternion
|
||||||
|
* @param[out] dest destination
|
||||||
|
*/
|
||||||
|
CGLM_INLINE
|
||||||
|
void
|
||||||
|
glm_quat_copy(versor q, versor dest) {
|
||||||
|
glm_vec4_copy(q, dest);
|
||||||
|
}
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
* @brief returns norm (magnitude) of quaternion
|
* @brief returns norm (magnitude) of quaternion
|
||||||
*
|
*
|
||||||
@@ -185,8 +197,7 @@ glm_quat_dot(versor q1, versor q2) {
|
|||||||
CGLM_INLINE
|
CGLM_INLINE
|
||||||
void
|
void
|
||||||
glm_quat_conjugate(versor q, versor dest) {
|
glm_quat_conjugate(versor q, versor dest) {
|
||||||
glm_vec4_copy(q, dest);
|
glm_vec4_flipsign_to(q, dest);
|
||||||
glm_vec4_flipsign(dest);
|
|
||||||
dest[3] = -dest[3];
|
dest[3] = -dest[3];
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -442,23 +453,16 @@ glm_quat_slerp(versor q, versor r, float t, versor dest) {
|
|||||||
|
|
||||||
cosTheta = glm_quat_dot(q, r);
|
cosTheta = glm_quat_dot(q, r);
|
||||||
if (cosTheta < 0.0f) {
|
if (cosTheta < 0.0f) {
|
||||||
q[0] *= -1.0f;
|
glm_vec4_flipsign(q);
|
||||||
q[1] *= -1.0f;
|
|
||||||
q[2] *= -1.0f;
|
|
||||||
q[3] *= -1.0f;
|
|
||||||
|
|
||||||
cosTheta = -cosTheta;
|
cosTheta = -cosTheta;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (fabs(cosTheta) >= 1.0f) {
|
if (fabs(cosTheta) >= 1.0f) {
|
||||||
dest[0] = q[0];
|
glm_quat_copy(q, dest);
|
||||||
dest[1] = q[1];
|
|
||||||
dest[2] = q[2];
|
|
||||||
dest[3] = q[3];
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
sinTheta = sqrt(1.0f - cosTheta * cosTheta);
|
sinTheta = sqrtf(1.0f - cosTheta * cosTheta);
|
||||||
|
|
||||||
c = 1.0f - t;
|
c = 1.0f - t;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user