a/math: Move m_matrix_2x2 functions into their own header

This commit is contained in:
Moses Turner 2023-01-26 17:23:29 -06:00
parent 2c73485ecd
commit da16e64982
5 changed files with 54 additions and 50 deletions

View file

@ -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
*

View file

@ -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)

View file

@ -0,0 +1,52 @@
// Copyright 2023, Collabora, Ltd.
// SPDX-License-Identifier: BSL-1.0
/*!
* @file
* @brief C matrix_2x2 math library.
* @author Moses Turner <moses@collabora.com>
*
* @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

View file

@ -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"

View file

@ -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"