From 1e077fd125d890d968624425593a2ccb3a0c2650 Mon Sep 17 00:00:00 2001 From: Recep Aslantas Date: Sat, 22 Jul 2023 01:21:14 +0300 Subject: [PATCH] add some missing non-square matrix funcs --- include/cglm/call/mat2x3.h | 8 ++++++++ include/cglm/call/mat2x4.h | 8 ++++++++ include/cglm/call/mat3x2.h | 8 ++++++++ include/cglm/call/mat3x4.h | 8 ++++++++ include/cglm/call/mat4x2.h | 8 ++++++++ include/cglm/call/mat4x3.h | 8 ++++++++ include/cglm/mat2x3.h | 30 ++++++++++++++++++++++++++++++ include/cglm/mat2x4.h | 26 ++++++++++++++++++++++++++ include/cglm/mat3x2.h | 31 +++++++++++++++++++++++++++++++ include/cglm/mat3x4.h | 26 ++++++++++++++++++++++++++ include/cglm/mat4x2.h | 34 ++++++++++++++++++++++++++++++++++ include/cglm/mat4x3.h | 34 ++++++++++++++++++++++++++++++++++ include/cglm/types.h | 6 +++--- src/mat2x3.c | 12 ++++++++++++ src/mat2x4.c | 12 ++++++++++++ src/mat3x2.c | 12 ++++++++++++ src/mat3x4.c | 12 ++++++++++++ src/mat4x2.c | 12 ++++++++++++ src/mat4x3.c | 12 ++++++++++++ 19 files changed, 304 insertions(+), 3 deletions(-) diff --git a/include/cglm/call/mat2x3.h b/include/cglm/call/mat2x3.h index 3ca44af..c7f0946 100644 --- a/include/cglm/call/mat2x3.h +++ b/include/cglm/call/mat2x3.h @@ -13,6 +13,14 @@ extern "C" { #include "../cglm.h" +CGLM_EXPORT +void +glmc_mat2x3_copy(mat2x3 mat, mat2x3 dest); + +CGLM_EXPORT +void +glmc_mat2x3_zero(mat2x3 mat); + CGLM_EXPORT void glmc_mat2x3_make(float * __restrict src, mat2x3 dest); diff --git a/include/cglm/call/mat2x4.h b/include/cglm/call/mat2x4.h index 63c5cbe..c2b6495 100644 --- a/include/cglm/call/mat2x4.h +++ b/include/cglm/call/mat2x4.h @@ -13,6 +13,14 @@ extern "C" { #include "../cglm.h" +CGLM_EXPORT +void +glmc_mat2x4_copy(mat2x4 mat, mat2x4 dest); + +CGLM_EXPORT +void +glmc_mat2x4_zero(mat2x4 mat); + CGLM_EXPORT void glmc_mat2x4_make(float * __restrict src, mat2x4 dest); diff --git a/include/cglm/call/mat3x2.h b/include/cglm/call/mat3x2.h index f2d0440..491151b 100644 --- a/include/cglm/call/mat3x2.h +++ b/include/cglm/call/mat3x2.h @@ -13,6 +13,14 @@ extern "C" { #include "../cglm.h" +CGLM_EXPORT +void +glmc_mat3x2_copy(mat3x2 mat, mat3x2 dest); + +CGLM_EXPORT +void +glmc_mat3x2_zero(mat3x2 mat); + CGLM_EXPORT void glmc_mat3x2_make(float * __restrict src, mat3x2 dest); diff --git a/include/cglm/call/mat3x4.h b/include/cglm/call/mat3x4.h index 9f7b3c2..714d744 100644 --- a/include/cglm/call/mat3x4.h +++ b/include/cglm/call/mat3x4.h @@ -13,6 +13,14 @@ extern "C" { #include "../cglm.h" +CGLM_EXPORT +void +glmc_mat3x4_copy(mat3x4 mat, mat3x4 dest); + +CGLM_EXPORT +void +glmc_mat3x4_zero(mat3x4 mat); + CGLM_EXPORT void glmc_mat3x4_make(float * __restrict src, mat3x4 dest); diff --git a/include/cglm/call/mat4x2.h b/include/cglm/call/mat4x2.h index f36c731..3710745 100644 --- a/include/cglm/call/mat4x2.h +++ b/include/cglm/call/mat4x2.h @@ -13,6 +13,14 @@ extern "C" { #include "../cglm.h" +CGLM_EXPORT +void +glmc_mat4x2_copy(mat4x2 mat, mat4x2 dest); + +CGLM_EXPORT +void +glmc_mat4x2_zero(mat4x2 mat); + CGLM_EXPORT void glmc_mat4x2_make(float * __restrict src, mat4x2 dest); diff --git a/include/cglm/call/mat4x3.h b/include/cglm/call/mat4x3.h index a6b1cd3..7790aa8 100644 --- a/include/cglm/call/mat4x3.h +++ b/include/cglm/call/mat4x3.h @@ -13,6 +13,14 @@ extern "C" { #include "../cglm.h" +CGLM_EXPORT +void +glmc_mat4x3_copy(mat4x3 mat, mat4x3 dest); + +CGLM_EXPORT +void +glmc_mat4x3_zero(mat4x3 mat); + CGLM_EXPORT void glmc_mat4x3_make(float * __restrict src, mat4x3 dest); diff --git a/include/cglm/mat2x3.h b/include/cglm/mat2x3.h index 81d682d..8ae65ea 100644 --- a/include/cglm/mat2x3.h +++ b/include/cglm/mat2x3.h @@ -24,6 +24,36 @@ /* for C only */ #define GLM_MAT2X3_ZERO GLM_MAT2X3_ZERO_INIT +/*! + * @brief copy all members of [mat] to [dest] + * + * @param[in] mat source + * @param[out] dest destination + */ +CGLM_INLINE +void +glm_mat2x3_copy(mat2x3 mat, mat2x3 dest) { + dest[0][0] = mat[0][0]; + dest[0][1] = mat[0][1]; + dest[0][2] = mat[0][2]; + + dest[1][0] = mat[1][0]; + dest[1][1] = mat[1][1]; + dest[1][2] = mat[1][2]; +} + +/*! + * @brief make given matrix zero. + * + * @param[in, out] mat matrix + */ +CGLM_INLINE +void +glm_mat2x3_zero(mat2x3 mat) { + CGLM_ALIGN_MAT mat2x3 t = GLM_MAT2X3_ZERO_INIT; + glm_mat2x3_copy(t, mat); +} + /*! * @brief Create mat2x3 matrix from pointer * diff --git a/include/cglm/mat2x4.h b/include/cglm/mat2x4.h index a77976b..4b6faa1 100644 --- a/include/cglm/mat2x4.h +++ b/include/cglm/mat2x4.h @@ -18,12 +18,38 @@ #define cglm_mat2x4_h #include "common.h" +#include "vec4.h" #define GLM_MAT2X4_ZERO_INIT {{0.0f, 0.0f, 0.0f, 0.0f}, {0.0f, 0.0f, 0.0f, 0.0f}} /* for C only */ #define GLM_MAT2X4_ZERO GLM_MAT2X4_ZERO_INIT +/*! + * @brief copy all members of [mat] to [dest] + * + * @param[in] mat source + * @param[out] dest destination + */ +CGLM_INLINE +void +glm_mat2x4_copy(mat2x4 mat, mat2x4 dest) { + glm_vec4_ucopy(mat[0], dest[0]); + glm_vec4_ucopy(mat[1], dest[1]); +} + +/*! + * @brief make given matrix zero. + * + * @param[in, out] mat matrix + */ +CGLM_INLINE +void +glm_mat2x4_zero(mat2x4 mat) { + CGLM_ALIGN_MAT mat2x4 t = GLM_MAT2X4_ZERO_INIT; + glm_mat2x4_copy(t, mat); +} + /*! * @brief Create mat2x4 matrix from pointer * diff --git a/include/cglm/mat3x2.h b/include/cglm/mat3x2.h index 52f330c..0b10286 100644 --- a/include/cglm/mat3x2.h +++ b/include/cglm/mat3x2.h @@ -24,6 +24,37 @@ /* for C only */ #define GLM_MAT3X2_ZERO GLM_MAT3X2_ZERO_INIT +/*! + * @brief copy all members of [mat] to [dest] + * + * @param[in] mat source + * @param[out] dest destination + */ +CGLM_INLINE +void +glm_mat3x2_copy(mat3x2 mat, mat3x2 dest) { + dest[0][0] = mat[0][0]; + dest[0][1] = mat[0][1]; + + dest[1][0] = mat[1][0]; + dest[1][1] = mat[1][1]; + + dest[2][0] = mat[2][0]; + dest[2][1] = mat[2][1]; +} + +/*! + * @brief make given matrix zero. + * + * @param[in, out] mat matrix + */ +CGLM_INLINE +void +glm_mat3x2_zero(mat3x2 mat) { + CGLM_ALIGN_MAT mat3x2 t = GLM_MAT3X2_ZERO_INIT; + glm_mat3x2_copy(t, mat); +} + /*! * @brief Create mat3x2 matrix from pointer * diff --git a/include/cglm/mat3x4.h b/include/cglm/mat3x4.h index a2cbdfd..a22ca4c 100644 --- a/include/cglm/mat3x4.h +++ b/include/cglm/mat3x4.h @@ -26,6 +26,32 @@ /* for C only */ #define GLM_MAT3X4_ZERO GLM_MAT3X4_ZERO_INIT +/*! + * @brief copy all members of [mat] to [dest] + * + * @param[in] mat source + * @param[out] dest destination + */ +CGLM_INLINE +void +glm_mat3x4_copy(mat3x4 mat, mat3x4 dest) { + glm_vec4_ucopy(mat[0], dest[0]); + glm_vec4_ucopy(mat[1], dest[1]); + glm_vec4_ucopy(mat[2], dest[2]); +} + +/*! + * @brief make given matrix zero. + * + * @param[in, out] mat matrix + */ +CGLM_INLINE +void +glm_mat3x4_zero(mat3x4 mat) { + CGLM_ALIGN_MAT mat3x4 t = GLM_MAT3X4_ZERO_INIT; + glm_mat3x4_copy(t, mat); +} + /*! * @brief Create mat3x4 matrix from pointer * diff --git a/include/cglm/mat4x2.h b/include/cglm/mat4x2.h index 1320763..b5074d3 100644 --- a/include/cglm/mat4x2.h +++ b/include/cglm/mat4x2.h @@ -24,6 +24,40 @@ /* for C only */ #define GLM_MAT4X2_ZERO GLM_MAT4X2_ZERO_INIT +/*! + * @brief copy all members of [mat] to [dest] + * + * @param[in] mat source + * @param[out] dest destination + */ +CGLM_INLINE +void +glm_mat4x2_copy(mat4x2 mat, mat4x2 dest) { + dest[0][0] = mat[0][0]; + dest[0][1] = mat[0][1]; + + dest[1][0] = mat[1][0]; + dest[1][1] = mat[1][1]; + + dest[2][0] = mat[2][0]; + dest[2][1] = mat[2][1]; + + dest[3][0] = mat[3][0]; + dest[3][1] = mat[3][1]; +} + +/*! + * @brief make given matrix zero. + * + * @param[in, out] mat matrix + */ +CGLM_INLINE +void +glm_mat4x2_zero(mat4x2 mat) { + CGLM_ALIGN_MAT mat4x2 t = GLM_MAT4X2_ZERO_INIT; + glm_mat4x2_copy(t, mat); +} + /*! * @brief Create mat4x2 matrix from pointer * diff --git a/include/cglm/mat4x3.h b/include/cglm/mat4x3.h index bc69430..b185d75 100644 --- a/include/cglm/mat4x3.h +++ b/include/cglm/mat4x3.h @@ -25,6 +25,40 @@ /* for C only */ #define GLM_MAT4X3_ZERO GLM_MAT4X3_ZERO_INIT +/*! + * @brief copy all members of [mat] to [dest] + * + * @param[in] mat source + * @param[out] dest destination + */ +CGLM_INLINE +void +glm_mat4x3_copy(mat4x3 mat, mat4x3 dest) { + dest[0][0] = mat[0][0]; + dest[0][1] = mat[0][1]; + + dest[1][0] = mat[1][0]; + dest[1][1] = mat[1][1]; + + dest[2][0] = mat[2][0]; + dest[2][1] = mat[2][1]; + + dest[3][0] = mat[3][0]; + dest[3][1] = mat[3][1]; +} + +/*! + * @brief make given matrix zero. + * + * @param[in, out] mat matrix + */ +CGLM_INLINE +void +glm_mat4x3_zero(mat4x3 mat) { + CGLM_ALIGN_MAT mat4x3 t = GLM_MAT4X3_ZERO_INIT; + glm_mat4x3_copy(t, mat); +} + /*! * @brief Create mat4x3 matrix from pointer * diff --git a/include/cglm/types.h b/include/cglm/types.h index 67d41a1..02b30ce 100644 --- a/include/cglm/types.h +++ b/include/cglm/types.h @@ -46,9 +46,9 @@ #define CGLM_CASTPTR_ASSUME_ALIGNED(expr, type) \ ((type*)CGLM_ASSUME_ALIGNED((expr), __alignof__(type))) -typedef int ivec2[2]; -typedef int ivec3[3]; -typedef int ivec4[4]; +typedef int ivec2[2]; +typedef int ivec3[3]; +typedef int ivec4[4]; typedef float vec2[2]; typedef float vec3[3]; diff --git a/src/mat2x3.c b/src/mat2x3.c index b3645b5..ab32870 100644 --- a/src/mat2x3.c +++ b/src/mat2x3.c @@ -8,6 +8,18 @@ #include "../include/cglm/cglm.h" #include "../include/cglm/call.h" +CGLM_EXPORT +void +glmc_mat2x3_copy(mat2x3 mat, mat2x3 dest) { + glm_mat2x3_copy(mat, dest); +} + +CGLM_EXPORT +void +glmc_mat2x3_zero(mat2x3 mat) { + glm_mat2x3_zero(mat); +} + CGLM_EXPORT void glmc_mat2x3_make(float * __restrict src, mat2x3 dest) { diff --git a/src/mat2x4.c b/src/mat2x4.c index 5fb2d53..ad3ec0d 100644 --- a/src/mat2x4.c +++ b/src/mat2x4.c @@ -8,6 +8,18 @@ #include "../include/cglm/cglm.h" #include "../include/cglm/call.h" +CGLM_EXPORT +void +glmc_mat2x4_copy(mat2x4 mat, mat2x4 dest) { + glm_mat2x4_copy(mat, dest); +} + +CGLM_EXPORT +void +glmc_mat2x4_zero(mat2x4 mat) { + glm_mat2x4_zero(mat); +} + CGLM_EXPORT void glmc_mat2x4_make(float * __restrict src, mat2x4 dest) { diff --git a/src/mat3x2.c b/src/mat3x2.c index fd6546c..ac59ebf 100644 --- a/src/mat3x2.c +++ b/src/mat3x2.c @@ -8,6 +8,18 @@ #include "../include/cglm/cglm.h" #include "../include/cglm/call.h" +CGLM_EXPORT +void +glmc_mat3x2_copy(mat3x2 mat, mat3x2 dest) { + glm_mat3x2_copy(mat, dest); +} + +CGLM_EXPORT +void +glmc_mat3x2_zero(mat3x2 mat) { + glm_mat3x2_zero(mat); +} + CGLM_EXPORT void glmc_mat3x2_make(float * __restrict src, mat3x2 dest) { diff --git a/src/mat3x4.c b/src/mat3x4.c index 2f90a7f..64be161 100644 --- a/src/mat3x4.c +++ b/src/mat3x4.c @@ -8,6 +8,18 @@ #include "../include/cglm/cglm.h" #include "../include/cglm/call.h" +CGLM_EXPORT +void +glmc_mat3x4_copy(mat3x4 mat, mat3x4 dest) { + glm_mat3x4_copy(mat, dest); +} + +CGLM_EXPORT +void +glmc_mat3x4_zero(mat3x4 mat) { + glm_mat3x4_zero(mat); +} + CGLM_EXPORT void glmc_mat3x4_make(float * __restrict src, mat3x4 dest) { diff --git a/src/mat4x2.c b/src/mat4x2.c index 4e137c6..622d1e2 100644 --- a/src/mat4x2.c +++ b/src/mat4x2.c @@ -8,6 +8,18 @@ #include "../include/cglm/cglm.h" #include "../include/cglm/call.h" +CGLM_EXPORT +void +glmc_mat4x2_copy(mat4x2 mat, mat4x2 dest) { + glm_mat4x2_copy(mat, dest); +} + +CGLM_EXPORT +void +glmc_mat4x2_zero(mat4x2 mat) { + glm_mat4x2_zero(mat); +} + CGLM_EXPORT void glmc_mat4x2_make(float * __restrict src, mat4x2 dest) { diff --git a/src/mat4x3.c b/src/mat4x3.c index 6617b47..60a14fe 100644 --- a/src/mat4x3.c +++ b/src/mat4x3.c @@ -8,6 +8,18 @@ #include "../include/cglm/cglm.h" #include "../include/cglm/call.h" +CGLM_EXPORT +void +glmc_mat4x3_copy(mat4x3 mat, mat4x3 dest) { + glm_mat4x3_copy(mat, dest); +} + +CGLM_EXPORT +void +glmc_mat4x3_zero(mat4x3 mat) { + glm_mat4x3_zero(mat); +} + CGLM_EXPORT void glmc_mat4x3_make(float * __restrict src, mat4x3 dest) {