From fabf01ff393a87ea9dea6498b1617f17261e2261 Mon Sep 17 00:00:00 2001 From: Dan Weatherford Date: Fri, 11 Jun 2021 01:20:57 -0500 Subject: [PATCH] aux/math: Add math_quat_slerp() --- src/xrt/auxiliary/math/m_api.h | 9 +++++++++ src/xrt/auxiliary/math/m_base.cpp | 12 ++++++++++++ 2 files changed, 21 insertions(+) diff --git a/src/xrt/auxiliary/math/m_api.h b/src/xrt/auxiliary/math/m_api.h index 0e32c02f1..0e23ab42c 100644 --- a/src/xrt/auxiliary/math/m_api.h +++ b/src/xrt/auxiliary/math/m_api.h @@ -290,6 +290,15 @@ void math_quat_rotate_derivative(const struct xrt_quat *rot, const struct xrt_vec3 *deriv, struct xrt_vec3 *result); +/*! + * Slerp (spherical linear interpolation) between two quaternions + * + * @relates xrt_quat + * @ingroup aux_math + */ +void +math_quat_slerp(const struct xrt_quat *left, const struct xrt_quat *right, float t, struct xrt_quat *result); + /* * * Matrix functions diff --git a/src/xrt/auxiliary/math/m_base.cpp b/src/xrt/auxiliary/math/m_base.cpp index c31da1eb4..c7a827e06 100644 --- a/src/xrt/auxiliary/math/m_base.cpp +++ b/src/xrt/auxiliary/math/m_base.cpp @@ -299,6 +299,18 @@ math_quat_rotate_derivative(const struct xrt_quat *quat, const struct xrt_vec3 * *result = ret; } +extern "C" void +math_quat_slerp(const struct xrt_quat *left, const struct xrt_quat *right, float t, struct xrt_quat *result) +{ + assert(left != NULL); + assert(right != NULL); + assert(result != NULL); + + auto l = copy(left); + auto r = copy(right); + + map_quat(*result) = l.slerp(t, r); +} /* *