mirror of
https://github.com/recp/cglm.git
synced 2026-02-17 03:39:05 +00:00
quat_from_vecs: incorporate PR comments
* C89-style comments * Move all variable declarations to function start * Remove constant variables * Remove newline for ‘else’
This commit is contained in:
@@ -197,22 +197,23 @@ glm_quat_copy(versor q, versor dest) {
|
|||||||
CGLM_INLINE
|
CGLM_INLINE
|
||||||
void
|
void
|
||||||
glm_quat_from_vecs(vec3 a, vec3 b, versor dest) {
|
glm_quat_from_vecs(vec3 a, vec3 b, versor dest) {
|
||||||
float cos_theta = glm_vec3_dot(a, b);
|
CGLM_ALIGN(8) vec3 axis;
|
||||||
if (cos_theta >= 1.f - GLM_FLT_EPSILON) { // a ∥ b
|
float cos_theta;
|
||||||
|
float cos_half_theta;
|
||||||
|
|
||||||
|
cos_theta = glm_vec3_dot(a, b);
|
||||||
|
if (cos_theta >= 1.f - GLM_FLT_EPSILON) { /* a ∥ b */
|
||||||
glm_quat_identity(dest);
|
glm_quat_identity(dest);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
CGLM_ALIGN(8) vec3 axis;
|
if (cos_theta < -1.f + GLM_FLT_EPSILON) { /* angle(a, b) = π */
|
||||||
float cos_half_theta;
|
|
||||||
if (cos_theta < -1.f + GLM_FLT_EPSILON) { // angle(a, b) = 180°
|
|
||||||
glm_vec3_ortho(a, axis);
|
glm_vec3_ortho(a, axis);
|
||||||
cos_half_theta = 0.f;
|
cos_half_theta = 0.f; /* cos π/2 */
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
glm_vec3_cross(a, b, axis);
|
glm_vec3_cross(a, b, axis);
|
||||||
const float cos_zero = 1.0f;
|
cos_half_theta = 1.0f + cos_theta; /* cos 0 + cos θ */
|
||||||
cos_half_theta = cos_zero + cos_theta;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
glm_quat_init(dest, axis[0], axis[1], axis[2], cos_half_theta);
|
glm_quat_init(dest, axis[0], axis[1], axis[2], cos_half_theta);
|
||||||
glm_quat_normalize(dest);
|
glm_quat_normalize(dest);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user