mirror of
https://github.com/recp/cglm.git
synced 2025-12-26 02:25:02 +00:00
Add nlerp for quaternions
Normalized linear interpolation for quaterions are a cheaper alternative to slerp. This PR adds nlerp operaiton for quaternions.
This commit is contained in:
@@ -38,6 +38,7 @@
|
||||
CGLM_INLINE void glm_quat_lerp(versor from, versor to, float t, versor dest);
|
||||
CGLM_INLINE void glm_quat_lerpc(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_nlerp(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,
|
||||
@@ -628,6 +629,29 @@ glm_quat_lerpc(versor from, versor to, float t, versor dest) {
|
||||
glm_vec4_lerpc(from, to, t, dest);
|
||||
}
|
||||
|
||||
/*!
|
||||
* @brief interpolates between two quaternions
|
||||
* taking the shortest rotation path using
|
||||
* normalized linear interpolation (NLERP)
|
||||
*
|
||||
* @param[in] from from
|
||||
* @param[in] to to
|
||||
* @param[in] t interpolant (amount)
|
||||
* @param[out] dest result quaternion
|
||||
*/
|
||||
CGLM_INLINE
|
||||
void
|
||||
glm_quat_nlerp(versor from, versor to, float t, versor dest) {
|
||||
float dot = glm_vec4_dot(from, to);
|
||||
versor target;
|
||||
if (dot >= 0)
|
||||
glm_quat_copy(to, target);
|
||||
else
|
||||
glm_vec4_negate_to(to, target);
|
||||
glm_quat_lerp(from, target, t, dest);
|
||||
glm_quat_normalize(dest);
|
||||
}
|
||||
|
||||
/*!
|
||||
* @brief interpolates between two quaternions
|
||||
* using spherical linear interpolation (SLERP)
|
||||
|
||||
Reference in New Issue
Block a user