diff --git a/src/xrt/auxiliary/math/m_api.h b/src/xrt/auxiliary/math/m_api.h index cf0f47b23..fea003ecc 100644 --- a/src/xrt/auxiliary/math/m_api.h +++ b/src/xrt/auxiliary/math/m_api.h @@ -113,6 +113,18 @@ math_vec3_cross(const struct xrt_vec3 *l, * */ +/*! + * Create a rotation from a angle in radians and a vector. + * + * @relates xrt_quat + * @relates xrt_vec3 + * @ingroup aux_math + */ +void +math_quat_from_angle_vector(float angle_rads, + const struct xrt_vec3 *vector, + struct xrt_quat *result); + /*! * Create a rotation from a 3x3 rotation matrix. * diff --git a/src/xrt/auxiliary/math/m_base.cpp b/src/xrt/auxiliary/math/m_base.cpp index a98c8c61e..0d8878450 100644 --- a/src/xrt/auxiliary/math/m_base.cpp +++ b/src/xrt/auxiliary/math/m_base.cpp @@ -89,6 +89,14 @@ math_vec3_cross(const struct xrt_vec3 *l, * */ +extern "C" void +math_quat_from_angle_vector(float angle_rads, + const struct xrt_vec3 *vector, + struct xrt_quat *result) +{ + map_quat(*result) = Eigen::AngleAxisf(angle_rads, copy(vector)); +} + extern "C" void math_quat_from_matrix_3x3(const struct xrt_matrix_3x3 *mat, struct xrt_quat *result)