a/math: Add math_quat_from_vec_a_to_vec_b()

Part-of: <https://gitlab.freedesktop.org/monado/monado/-/merge_requests/2188>
This commit is contained in:
Jan Schmidt 2023-08-07 02:31:30 +10:00 committed by Marge Bot
parent 4555f5e7f9
commit 36eaad6419
2 changed files with 17 additions and 0 deletions

View file

@ -245,6 +245,17 @@ math_quat_from_matrix_3x3(const struct xrt_matrix_3x3 *mat, struct xrt_quat *res
void
math_quat_from_plus_x_z(const struct xrt_vec3 *plus_x, const struct xrt_vec3 *plus_z, struct xrt_quat *result);
/*!
* Create a rotation from two vectors vec_a and vec_b that would
* rotate vec_a into vec_b
*
* @relates xrt_quat
* @see xrt_vec3
* @ingroup aux_math
*/
void
math_quat_from_vec_a_to_vec_b(const struct xrt_vec3 *vec_a, const struct xrt_vec3 *vec_b, struct xrt_quat *result);
/*!
* Check if this quat can be used in transformation operations.
*

View file

@ -253,6 +253,12 @@ math_quat_from_plus_x_z(const struct xrt_vec3 *plus_x, const struct xrt_vec3 *pl
math_quat_from_matrix_3x3(&m, result);
}
extern "C" void
math_quat_from_vec_a_to_vec_b(const struct xrt_vec3 *vec_a, const struct xrt_vec3 *vec_b, struct xrt_quat *result)
{
map_quat(*result) = Eigen::Quaternionf::FromTwoVectors(copy(vec_a), copy(vec_b));
}
static bool
quat_validate(const float precision, const struct xrt_quat *quat)
{