From da16e64982dffed04bee9ef5b3317219336a1fa5 Mon Sep 17 00:00:00 2001 From: Moses Turner Date: Thu, 26 Jan 2023 17:23:29 -0600 Subject: [PATCH] a/math: Move m_matrix_2x2 functions into their own header --- src/xrt/auxiliary/math/m_api.h | 22 --------- src/xrt/auxiliary/math/m_base.cpp | 28 ----------- src/xrt/auxiliary/math/m_matrix_2x2.h | 52 ++++++++++++++++++++ src/xrt/compositor/main/comp_renderer.c | 1 + src/xrt/compositor/render/render_resources.c | 1 + 5 files changed, 54 insertions(+), 50 deletions(-) create mode 100644 src/xrt/auxiliary/math/m_matrix_2x2.h diff --git a/src/xrt/auxiliary/math/m_api.h b/src/xrt/auxiliary/math/m_api.h index 829f0a116..a3ddd6936 100644 --- a/src/xrt/auxiliary/math/m_api.h +++ b/src/xrt/auxiliary/math/m_api.h @@ -428,28 +428,6 @@ math_quat_to_swing_twist(const struct xrt_quat *in, struct xrt_vec2 *out_swing, * */ -/*! - * Multiply Matrix2x2. - * - * @relates xrt_matrix_2x2 - * @ingroup aux_math - */ -void -math_matrix_2x2_multiply(const struct xrt_matrix_2x2 *left, - const struct xrt_matrix_2x2 *right, - struct xrt_matrix_2x2 *result_out); - -/*! - * Transform a vec2 by a 2x2 matrix - * - * @see xrt_matrix_2x2 - * @ingroup aux_math - */ -void -math_matrix_2x2_transform_vec2(const struct xrt_matrix_2x2 *left, - const struct xrt_vec2 *right, - struct xrt_vec2 *result_out); - /*! * Initialize a 3x3 matrix to the identity matrix * diff --git a/src/xrt/auxiliary/math/m_base.cpp b/src/xrt/auxiliary/math/m_base.cpp index 4677f0598..73eb89aa0 100644 --- a/src/xrt/auxiliary/math/m_base.cpp +++ b/src/xrt/auxiliary/math/m_base.cpp @@ -518,35 +518,7 @@ math_quat_to_swing_twist(const struct xrt_quat *in, struct xrt_vec2 *out_swing, * */ -extern "C" void -math_matrix_2x2_multiply(const struct xrt_matrix_2x2 *left, - const struct xrt_matrix_2x2 *right, - struct xrt_matrix_2x2 *result_out) -{ - const struct xrt_matrix_2x2 l = *left; - const struct xrt_matrix_2x2 r = *right; - // Initialisers: struct, union, v[4] - struct xrt_matrix_2x2 result = {{{ - l.v[0] * r.v[0] + l.v[1] * r.v[2], - l.v[0] * r.v[1] + l.v[1] * r.v[3], - l.v[2] * r.v[0] + l.v[3] * r.v[2], - l.v[2] * r.v[1] + l.v[3] * r.v[3], - }}}; - - *result_out = result; -} - -extern "C" void -math_matrix_2x2_transform_vec2(const struct xrt_matrix_2x2 *left, - const struct xrt_vec2 *right, - struct xrt_vec2 *result_out) -{ - const struct xrt_matrix_2x2 l = *left; - const struct xrt_vec2 r = *right; - struct xrt_vec2 result = {l.v[0] * r.x + l.v[1] * r.y, l.v[2] * r.x + l.v[3] * r.y}; - *result_out = result; -} extern "C" void math_matrix_3x3_identity(struct xrt_matrix_3x3 *mat) diff --git a/src/xrt/auxiliary/math/m_matrix_2x2.h b/src/xrt/auxiliary/math/m_matrix_2x2.h new file mode 100644 index 000000000..a8f0931c3 --- /dev/null +++ b/src/xrt/auxiliary/math/m_matrix_2x2.h @@ -0,0 +1,52 @@ +// Copyright 2023, Collabora, Ltd. +// SPDX-License-Identifier: BSL-1.0 +/*! + * @file + * @brief C matrix_2x2 math library. + * @author Moses Turner + * + * @see xrt_matrix_2x2 + * @ingroup aux_math + */ + +#pragma once + +#include "xrt/xrt_defines.h" + +#ifdef __cplusplus +extern "C" { +#endif + +static inline void +math_matrix_2x2_multiply(const struct xrt_matrix_2x2 *left, + const struct xrt_matrix_2x2 *right, + struct xrt_matrix_2x2 *result_out) +{ + const struct xrt_matrix_2x2 l = *left; + const struct xrt_matrix_2x2 r = *right; + + // Initialisers: struct, union, v[4] + struct xrt_matrix_2x2 result = {{{ + l.v[0] * r.v[0] + l.v[1] * r.v[2], + l.v[0] * r.v[1] + l.v[1] * r.v[3], + l.v[2] * r.v[0] + l.v[3] * r.v[2], + l.v[2] * r.v[1] + l.v[3] * r.v[3], + }}}; + + *result_out = result; +} + +static inline void +math_matrix_2x2_transform_vec2(const struct xrt_matrix_2x2 *left, + const struct xrt_vec2 *right, + struct xrt_vec2 *result_out) +{ + const struct xrt_matrix_2x2 l = *left; + const struct xrt_vec2 r = *right; + struct xrt_vec2 result = {l.v[0] * r.x + l.v[1] * r.y, l.v[2] * r.x + l.v[3] * r.y}; + *result_out = result; +} + +#ifdef __cplusplus +} +#endif diff --git a/src/xrt/compositor/main/comp_renderer.c b/src/xrt/compositor/main/comp_renderer.c index e5f48c386..43335bbee 100644 --- a/src/xrt/compositor/main/comp_renderer.c +++ b/src/xrt/compositor/main/comp_renderer.c @@ -20,6 +20,7 @@ #include "math/m_api.h" #include "math/m_vec3.h" #include "math/m_matrix_4x4_f64.h" +#include "math/m_matrix_2x2.h" #include "math/m_space.h" #include "util/u_misc.h" diff --git a/src/xrt/compositor/render/render_resources.c b/src/xrt/compositor/render/render_resources.c index 2ddaf0313..380705e3b 100644 --- a/src/xrt/compositor/render/render_resources.c +++ b/src/xrt/compositor/render/render_resources.c @@ -10,6 +10,7 @@ #include "xrt/xrt_device.h" #include "math/m_api.h" +#include "math/m_matrix_2x2.h" #include "math/m_vec2.h" #include "render/render_interface.h"