The open source OpenXR runtime

a/math: Add math_quat_to_euler_angles

Part-of: <https://gitlab.freedesktop.org/monado/monado/-/merge_requests/2312>

authored by

Christoph Haag and committed by
Marge Bot
71b5d37e 7150279e

+19
+8
src/xrt/auxiliary/math/m_api.h
··· 223 223 math_quat_from_euler_angles(const struct xrt_vec3 *angles, struct xrt_quat *result); 224 224 225 225 /*! 226 + * Create a rotation from a quaternion to euler angles 227 + * @relates xrt_quat 228 + * @ingroup aux_math 229 + */ 230 + void 231 + math_quat_to_euler_angles(const struct xrt_quat *quat, struct xrt_vec3 *euler_angles); 232 + 233 + /*! 226 234 * Create a rotation from a 3x3 rotation (row major) matrix. 227 235 * 228 236 * @relates xrt_quat
+11
src/xrt/auxiliary/math/m_base.cpp
··· 223 223 } 224 224 225 225 extern "C" void 226 + math_quat_to_euler_angles(const struct xrt_quat *quat, struct xrt_vec3 *euler_angles) 227 + { 228 + Eigen::Quaternionf eigen_quat(quat->w, quat->x, quat->y, quat->z); 229 + Eigen::Vector3f eigen_euler = eigen_quat.toRotationMatrix().eulerAngles(2, 1, 0); 230 + 231 + euler_angles->x = eigen_euler.x(); 232 + euler_angles->y = eigen_euler.y(); 233 + euler_angles->z = eigen_euler.z(); 234 + } 235 + 236 + extern "C" void 226 237 math_quat_from_matrix_3x3(const struct xrt_matrix_3x3 *mat, struct xrt_quat *result) 227 238 { 228 239 Eigen::Matrix3f m;