math: Make it possible to get a rotation from a rotation matrix

This commit is contained in:
Jakob Bornecrantz 2019-12-25 14:13:34 +00:00
parent 35fcd2ae3d
commit 7618f4c5a4
2 changed files with 24 additions and 0 deletions

View file

@ -102,6 +102,17 @@ math_vec3_accum(const struct xrt_vec3 *additional, struct xrt_vec3 *inAndOut);
*
*/
/*!
* Create a rotation from a 3x3 rotation matrix.
*
* @relates xrt_quat
* @relates xrt_matrix_3x3
* @ingroup aux_math
*/
void
math_quat_from_matrix_3x3(const struct xrt_matrix_3x3 *mat,
struct xrt_quat *result);
/*!
* Check if this quat can be used in transformation operations.
*

View file

@ -81,6 +81,19 @@ math_vec3_accum(const struct xrt_vec3 *additional, struct xrt_vec3 *inAndOut)
*
*/
extern "C" void
math_quat_from_matrix_3x3(const struct xrt_matrix_3x3 *mat,
struct xrt_quat *result)
{
Eigen::Matrix3f m;
m << mat->v[0], mat->v[1], mat->v[2], mat->v[3], mat->v[4], mat->v[5],
mat->v[6], mat->v[7], mat->v[8];
Eigen::Quaternionf q(m);
map_quat(*result) = q;
}
extern "C" bool
math_quat_validate(const struct xrt_quat *quat)
{