diff --git a/src/xrt/auxiliary/math/m_api.h b/src/xrt/auxiliary/math/m_api.h index b6379b237..5416cf004 100644 --- a/src/xrt/auxiliary/math/m_api.h +++ b/src/xrt/auxiliary/math/m_api.h @@ -477,6 +477,17 @@ math_matrix_3x3_transform_vec3(const struct xrt_matrix_3x3 *left, const struct xrt_vec3 *right, struct xrt_vec3 *result_out); +/*! + * Transform a vec3 by a 4x4 matrix, extending the vector with w = 1.0 + * + * @see xrt_matrix_4x4 + * @ingroup aux_math + */ +void +math_matrix_4x4_transform_vec3(const struct xrt_matrix_4x4 *left, + const struct xrt_vec3 *right, + struct xrt_vec3 *result_out); + /*! * Transform a double vec3 by a 3x3 double matrix * diff --git a/src/xrt/auxiliary/math/m_base.cpp b/src/xrt/auxiliary/math/m_base.cpp index 6a315b0fd..00183ef7a 100644 --- a/src/xrt/auxiliary/math/m_base.cpp +++ b/src/xrt/auxiliary/math/m_base.cpp @@ -551,6 +551,24 @@ math_matrix_3x3_transform_vec3(const struct xrt_matrix_3x3 *left, map_vec3(*result_out) = m * copy(right); } +extern "C" void +math_matrix_4x4_transform_vec3(const struct xrt_matrix_4x4 *left, + const struct xrt_vec3 *right, + struct xrt_vec3 *result_out) +{ + Eigen::Matrix4f m = copy(left); + + Eigen::Vector4f v; + v << right->x, right->y, right->z, 1.0; + + Eigen::Vector4f res; + res = m * v; + + result_out->x = res.x(); + result_out->y = res.y(); + result_out->z = res.z(); +} + extern "C" void math_matrix_3x3_multiply(const struct xrt_matrix_3x3 *left, const struct xrt_matrix_3x3 *right,