a/math: Add math_quat_{len, unrotate}

This commit is contained in:
Mateo de Mayo 2021-12-30 17:31:46 -03:00
parent cf5574a4e9
commit 06597a0655
2 changed files with 38 additions and 0 deletions

View file

@ -204,6 +204,15 @@ math_quat_validate_within_1_percent(const struct xrt_quat *quat);
void
math_quat_invert(const struct xrt_quat *quat, struct xrt_quat *out_quat);
/*!
* The euclidean norm or length of a quaternion. Same as if it were a vec4.
*
* @relates xrt_quat
* @ingroup aux_math
*/
float
math_quat_len(const struct xrt_quat *quat);
/*!
* Normalize a quaternion.
*
@ -244,6 +253,14 @@ math_quat_rotate_vec3(const struct xrt_quat *left, const struct xrt_vec3 *right,
void
math_quat_rotate(const struct xrt_quat *left, const struct xrt_quat *right, struct xrt_quat *result);
/*!
* Inverse of @ref math_quat_rotate. Removes @p left rotation from @p right.
*
* @relates xrt_quat
* @ingroup aux_math
*/
void
math_quat_unrotate(const struct xrt_quat *left, const struct xrt_quat *right, struct xrt_quat *result);
/*!
* Integrate a local angular velocity vector (exponential map) and apply to a

View file

@ -251,6 +251,12 @@ math_quat_invert(const struct xrt_quat *quat, struct xrt_quat *out_quat)
map_quat(*out_quat) = map_quat(*quat).conjugate();
}
extern "C" float
math_quat_len(const struct xrt_quat *quat)
{
return map_quat(*quat).norm();
}
extern "C" void
math_quat_normalize(struct xrt_quat *inout)
{
@ -295,6 +301,21 @@ math_quat_rotate(const struct xrt_quat *left, const struct xrt_quat *right, stru
map_quat(*result) = q;
}
extern "C" void
math_quat_unrotate(const struct xrt_quat *left, const struct xrt_quat *right, struct xrt_quat *result)
{
assert(left != NULL);
assert(right != NULL);
assert(result != NULL);
auto l = copy(left);
auto r = copy(right);
auto q = l.inverse() * r;
map_quat(*result) = q;
}
extern "C" void
math_quat_rotate_vec3(const struct xrt_quat *left, const struct xrt_vec3 *right, struct xrt_vec3 *result)
{