aux/math: Implement math_matrix_3x3_multiply.

This commit is contained in:
Moses Turner 2021-03-05 17:13:27 -06:00 committed by Christoph Haag
parent d54b653751
commit c776a19e15
2 changed files with 30 additions and 0 deletions
src/xrt/auxiliary/math

View file

@ -4,6 +4,7 @@
* @file
* @brief C interface to math library.
* @author Jakob Bornecrantz <jakob@collabora.com>
* @author Moses Turner <mosesturner@protonmail.com>
*
* @see xrt_vec3
* @see xrt_quat
@ -311,6 +312,17 @@ math_matrix_3x3_transform_vec3(const struct xrt_matrix_3x3 *left,
const struct xrt_vec3 *right,
struct xrt_vec3 *result);
/*!
* Multiply Matrix3x3.
*
* @relates xrt_matrix_3x3
* @ingroup aux_math
*/
void
math_matrix_3x3_multiply(const struct xrt_matrix_3x3 *left,
const struct xrt_matrix_3x3 *right,
struct xrt_matrix_3x3 *result);
/*!
* Initialize Matrix4x4 with identity.
*

View file

@ -5,6 +5,7 @@
* @brief Base implementations for math library.
* @author Jakob Bornecrantz <jakob@collabora.com>
* @author Ryan Pavlik <ryan.pavlik@collabora.com>
* @author Moses Turner <mosesturner@protonmail.com>
* @ingroup aux_math
*/
@ -314,6 +315,23 @@ math_matrix_3x3_transform_vec3(const struct xrt_matrix_3x3 *left, const struct x
map_vec3(*result) = m * copy(right);
}
extern "C" void
math_matrix_3x3_multiply(const struct xrt_matrix_3x3 *left,
const struct xrt_matrix_3x3 *right,
struct xrt_matrix_3x3 *result)
{
result->v[0] = left->v[0] * right->v[0] + left->v[1] * right->v[3] + left->v[2] * right->v[6];
result->v[1] = left->v[0] * right->v[1] + left->v[1] * right->v[4] + left->v[2] * right->v[7];
result->v[2] = left->v[0] * right->v[2] + left->v[1] * right->v[5] + left->v[2] * right->v[8];
result->v[3] = left->v[3] * right->v[0] + left->v[4] * right->v[3] + left->v[5] * right->v[6];
result->v[4] = left->v[3] * right->v[1] + left->v[4] * right->v[4] + left->v[5] * right->v[7];
result->v[5] = left->v[3] * right->v[2] + left->v[4] * right->v[5] + left->v[5] * right->v[8];
result->v[6] = left->v[6] * right->v[0] + left->v[7] * right->v[3] + left->v[8] * right->v[6];
result->v[7] = left->v[6] * right->v[1] + left->v[7] * right->v[4] + left->v[8] * right->v[7];
result->v[8] = left->v[6] * right->v[2] + left->v[7] * right->v[5] + left->v[8] * right->v[8];
}
void
math_matrix_4x4_identity(struct xrt_matrix_4x4 *result)