diff --git a/CMakeLists.txt b/CMakeLists.txt index f91e1dd..bb7bcba 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -79,6 +79,7 @@ add_library(${PROJECT_NAME} src/vec4.c src/ivec4.c src/mat2.c + src/mat2x3.c src/mat3.c src/mat4.c src/plane.c diff --git a/Makefile.am b/Makefile.am index 4fae2b0..dd14edc 100644 --- a/Makefile.am +++ b/Makefile.am @@ -44,6 +44,7 @@ cglm_HEADERS = include/cglm/version.h \ include/cglm/mat4.h \ include/cglm/mat3.h \ include/cglm/mat2.h \ + include/cglm/mat2x3.h \ include/cglm/affine-pre.h \ include/cglm/affine-post.h \ include/cglm/affine.h \ @@ -96,6 +97,7 @@ cglm_calldir=$(includedir)/cglm/call cglm_call_HEADERS = include/cglm/call/mat4.h \ include/cglm/call/mat3.h \ include/cglm/call/mat2.h \ + include/cglm/call/mat2x3.h \ include/cglm/call/vec2.h \ include/cglm/call/vec3.h \ include/cglm/call/vec4.h \ @@ -160,6 +162,7 @@ cglm_structdir=$(includedir)/cglm/struct cglm_struct_HEADERS = include/cglm/struct/mat4.h \ include/cglm/struct/mat3.h \ include/cglm/struct/mat2.h \ + include/cglm/struct/mat2x3.h \ include/cglm/struct/affine-pre.h \ include/cglm/struct/affine-post.h \ include/cglm/struct/affine-mat.h \ @@ -212,6 +215,7 @@ libcglm_la_SOURCES=\ src/vec4.c \ src/ivec4.c \ src/mat2.c \ + src/mat2x3.c \ src/mat3.c \ src/mat4.c \ src/plane.c \ diff --git a/docs/source/api_inline_array.rst b/docs/source/api_inline_array.rst index 56a0dd7..ddb2ec1 100644 --- a/docs/source/api_inline_array.rst +++ b/docs/source/api_inline_array.rst @@ -46,6 +46,7 @@ Follow the :doc:`build` documentation for this quat euler mat2 + mat2x3 mat3 mat4 vec2 diff --git a/docs/source/mat2x3.rst b/docs/source/mat2x3.rst new file mode 100644 index 0000000..e961a8a --- /dev/null +++ b/docs/source/mat2x3.rst @@ -0,0 +1,31 @@ +.. default-domain:: C + +mat2x3 +====== + +Header: cglm/mat2x3.h + +Table of contents (click to go): +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +Macros: + +1. GLM_MAT2X3_ZERO_INIT +#. GLM_MAT2x3_ZERO + +Functions: + +1. :c:func:`glm_mat2x3_make` + +Functions documentation +~~~~~~~~~~~~~~~~~~~~~~~ + +.. c:function:: void glm_mat2x3_make(float * __restrict src, mat2x3 dest) + + Create mat2x3 matrix from pointer + + | NOTE: **@src** must contain at least 6 elements. + + Parameters: + | *[in]* **src** pointer to an array of floats + | *[out]* **dest** destination matrix2x3 diff --git a/include/cglm/call.h b/include/cglm/call.h index 734bd46..e932ac5 100644 --- a/include/cglm/call.h +++ b/include/cglm/call.h @@ -19,6 +19,7 @@ extern "C" { #include "call/ivec3.h" #include "call/ivec4.h" #include "call/mat2.h" +#include "call/mat2x3.h" #include "call/mat3.h" #include "call/mat4.h" #include "call/affine.h" diff --git a/include/cglm/call/mat2x3.h b/include/cglm/call/mat2x3.h new file mode 100644 index 0000000..3ca44af --- /dev/null +++ b/include/cglm/call/mat2x3.h @@ -0,0 +1,23 @@ +/* + * Copyright (c), Recep Aslantas. + * + * MIT License (MIT), http://opensource.org/licenses/MIT + * Full license can be found in the LICENSE file + */ + +#ifndef cglmc_mat2x3_h +#define cglmc_mat2x3_h +#ifdef __cplusplus +extern "C" { +#endif + +#include "../cglm.h" + +CGLM_EXPORT +void +glmc_mat2x3_make(float * __restrict src, mat2x3 dest); + +#ifdef __cplusplus +} +#endif +#endif /* cglmc_mat2x3_h */ diff --git a/include/cglm/cglm.h b/include/cglm/cglm.h index 1828cb4..eb208d7 100644 --- a/include/cglm/cglm.h +++ b/include/cglm/cglm.h @@ -18,6 +18,7 @@ #include "mat4.h" #include "mat3.h" #include "mat2.h" +#include "mat2x3.h" #include "affine.h" #include "cam.h" #include "frustum.h" diff --git a/include/cglm/mat2x3.h b/include/cglm/mat2x3.h new file mode 100644 index 0000000..aca921d --- /dev/null +++ b/include/cglm/mat2x3.h @@ -0,0 +1,45 @@ +/* + * Copyright (c), Recep Aslantas. + * + * MIT License (MIT), http://opensource.org/licenses/MIT + * Full license can be found in the LICENSE file + */ + +/* + Macros: + GLM_MAT2X3_ZERO_INIT + GLM_MAT2X3_ZERO + + Functions: + CGLM_INLINE void glm_mat2x3_make(float * restrict src, mat2x3 dest) + */ + +#ifndef cglm_mat2x3_h +#define cglm_mat2x3_h + +#include "common.h" + +#define GLM_MAT2X3_ZERO_INIT {{0.0f, 0.0f, 0.0f}, {0.0f, 0.0f, 0.0f}} + +/* for C only */ +#define GLM_MAT2X3_ZERO ((mat2x3)GLM_MAT2X3_ZERO_INIT) + +/*! + * @brief Create mat2x3 matrix from pointer + * + * @param[in] src pointer to an array of floats + * @param[out] dest matrix + */ +CGLM_INLINE +void +glm_mat2x3_make(float * __restrict src, mat2x3 dest) { + dest[0][0] = src[0]; + dest[0][1] = src[1]; + dest[0][2] = src[2]; + + dest[1][0] = src[3]; + dest[1][1] = src[4]; + dest[1][2] = src[5]; +} + +#endif diff --git a/include/cglm/struct.h b/include/cglm/struct.h index 871525a..0d88518 100644 --- a/include/cglm/struct.h +++ b/include/cglm/struct.h @@ -17,6 +17,7 @@ extern "C" { #include "struct/vec3.h" #include "struct/vec4.h" #include "struct/mat2.h" +#include "struct/mat2x3.h" #include "struct/mat3.h" #include "struct/mat4.h" #include "struct/affine.h" diff --git a/include/cglm/struct/mat2x3.h b/include/cglm/struct/mat2x3.h new file mode 100644 index 0000000..1d8e79c --- /dev/null +++ b/include/cglm/struct/mat2x3.h @@ -0,0 +1,46 @@ +/* + * Copyright (c), Recep Aslantas. + * + * MIT License (MIT), http://opensource.org/licenses/MIT + * Full license can be found in the LICENSE file + */ + +/* + Macros: + GLMS_MAT2X3_ZERO_INIT + GLMS_MAT2X3_ZERO + + Functions: + CGLM_INLINE float glms_mat2x3_make(float * __restrict src); + */ + +#ifndef cglms_mat2x3_h +#define cglms_mat2x3_h + +#include "../common.h" +#include "../types-struct.h" +#include "../mat2x3.h" + +/* api definition */ +#define glms_mat2x3_(NAME) CGLM_STRUCTAPI(mat2x3, NAME) + +#define GLMS_MAT2X3_ZERO_INIT {GLM_MAT2X3_ZERO_INIT} + +/* for C only */ +#define GLMS_MAT2X3_ZERO ((mat2x3s)GLMS_MAT2X3_ZERO_INIT) + +/*! + * @brief Create mat2x3 matrix from pointer + * + * @param[in] src pointer to an array of floats + * @return constructed matrix from raw pointer + */ +CGLM_INLINE +mat2x3s +glms_mat2x3_(make)(float * __restrict src) { + mat2x3s r; + glm_mat2x3_make(src, r.raw); + return r; +} + +#endif /* cglms_mat2x3_h */ diff --git a/include/cglm/types-struct.h b/include/cglm/types-struct.h index d581fca..6ab34d2 100644 --- a/include/cglm/types-struct.h +++ b/include/cglm/types-struct.h @@ -197,6 +197,17 @@ typedef union mat2s { #endif } mat2s; +typedef union mat2x3s { + mat2x3 raw; + vec3s col[2]; /* col -> row | [row (2), col (3)] */ +#if CGLM_USE_ANONYMOUS_STRUCT + struct { + float m00, m01, m02; + float m10, m11, m12; + }; +#endif +} mat2x3s; + typedef union mat3s { mat3 raw; vec3s col[3]; diff --git a/include/cglm/types.h b/include/cglm/types.h index e6011c3..3d6cb00 100644 --- a/include/cglm/types.h +++ b/include/cglm/types.h @@ -56,6 +56,7 @@ typedef CGLM_ALIGN_IF(16) float vec4[4]; typedef vec4 versor; /* |x, y, z, w| -> w is the last */ typedef vec3 mat3[3]; typedef CGLM_ALIGN_IF(16) vec2 mat2[2]; +typedef vec3 mat2x3[2]; /* [row (2), col (3)] */ typedef CGLM_ALIGN_MAT vec4 mat4[4]; /* diff --git a/meson.build b/meson.build index 8abe71e..b488aa7 100644 --- a/meson.build +++ b/meson.build @@ -39,6 +39,7 @@ cglm_src = files( 'src/vec4.c', 'src/ivec4.c', 'src/mat2.c', + 'src/mat2x3.c', 'src/mat3.c', 'src/mat4.c', 'src/plane.c', diff --git a/src/mat2x3.c b/src/mat2x3.c new file mode 100644 index 0000000..b3645b5 --- /dev/null +++ b/src/mat2x3.c @@ -0,0 +1,15 @@ +/* + * Copyright (c), Recep Aslantas. + * + * MIT License (MIT), http://opensource.org/licenses/MIT + * Full license can be found in the LICENSE file + */ + +#include "../include/cglm/cglm.h" +#include "../include/cglm/call.h" + +CGLM_EXPORT +void +glmc_mat2x3_make(float * __restrict src, mat2x3 dest) { + glm_mat2x3_make(src, dest); +} diff --git a/test/src/test_common.c b/test/src/test_common.c index 46b6e63..2289b24 100644 --- a/test/src/test_common.c +++ b/test/src/test_common.c @@ -174,6 +174,19 @@ test_assert_mat2_eq_zero(mat2 m2) { TEST_SUCCESS } +test_status_t +test_assert_mat2x3_eq_zero(mat2x3 m2x3) { + int i, j; + + for (i = 0; i < 2; i++) { + for (j = 0; j < 3; j++) { + ASSERT(test_eq(m2x3[i][j], 0.0f)) + } + } + + TEST_SUCCESS +} + test_status_t test_assert_mat3_eq(mat3 m1, mat3 m2) { int i, j; diff --git a/test/src/test_common.h b/test/src/test_common.h index 841f77b..4c6dc77 100644 --- a/test/src/test_common.h +++ b/test/src/test_common.h @@ -53,6 +53,9 @@ test_assert_mat2_eq_identity(mat2 m2); test_status_t test_assert_mat2_eq_zero(mat2 m2); +test_status_t +test_assert_mat2x3_eq_zero(mat2x3 m2x3); + test_status_t test_assert_mat3_eq(mat3 m1, mat3 m2); diff --git a/test/src/test_mat2x3.h b/test/src/test_mat2x3.h new file mode 100644 index 0000000..287efc3 --- /dev/null +++ b/test/src/test_mat2x3.h @@ -0,0 +1,53 @@ +/* + * Copyright (c), Recep Aslantas. + * + * MIT License (MIT), http://opensource.org/licenses/MIT + * Full license can be found in the LICENSE file + */ + +#include "test_common.h" + +#ifndef CGLM_TEST_MAT2X3_ONCE +#define CGLM_TEST_MAT2X3_ONCE + +TEST_IMPL(MACRO_GLM_MAT2X3_ZERO_INIT) { + mat2x3 m = GLM_MAT2X3_ZERO_INIT; + + ASSERT(test_eq(m[0][0], 0.0f)) + ASSERT(test_eq(m[0][1], 0.0f)) + ASSERT(test_eq(m[0][2], 0.0f)) + ASSERT(test_eq(m[1][0], 0.0f)) + ASSERT(test_eq(m[1][1], 0.0f)) + ASSERT(test_eq(m[1][2], 0.0f)) + + TEST_SUCCESS +} + +#endif /* CGLM_TEST_MAT2X3_ONCE */ + +TEST_IMPL(GLM_PREFIX, mat2x3_make) { + float src[18] = { + 0.5f, 1.7f, 10.3f, 4.2f, 8.9f, 1.1f, + 2.3f, 4.2f, 66.5f, 23.7f, 6.6f, 8.9f, + 5.3f, 4.8f, 96.3f, 13.7f, 4.7f, 5.5f + }; + + mat2x3 dest[3]; + + float *srcp = src; + unsigned int i, j, k; + + for (i = 0, j = 0, k = 0; i < sizeof(src) / sizeof(float); i+=6,j++) { + GLM(mat2x3_make)(srcp + i, dest[j]); + + ASSERT(test_eq(src[ i ], dest[j][k][0])); + ASSERT(test_eq(src[i+1], dest[j][k][1])); + ASSERT(test_eq(src[i+2], dest[j][k][2])); + + ASSERT(test_eq(src[i+3], dest[j][k+1][0])); + ASSERT(test_eq(src[i+4], dest[j][k+1][1])); + ASSERT(test_eq(src[i+5], dest[j][k+1][2])); + } + + TEST_SUCCESS +} diff --git a/test/src/test_struct.c b/test/src/test_struct.c index ce79356..16ac389 100644 --- a/test/src/test_struct.c +++ b/test/src/test_struct.c @@ -7,6 +7,14 @@ #include "test_common.h" +TEST_IMPL(mat2x3s_zero_init) { + mat2x3s mat2x3_zero = GLMS_MAT2X3_ZERO_INIT; + mat2x3 mat2x3_zero_a = GLM_MAT2X3_ZERO_INIT; + test_assert_mat2x3_eq_zero(mat2x3_zero_a); + test_assert_mat2x3_eq_zero(mat2x3_zero.raw); + TEST_SUCCESS +} + TEST_IMPL(mat3s_identity_init) { mat3s mat3_identity = GLMS_MAT3_IDENTITY_INIT; mat3 mat3_identity_a = GLM_MAT3_IDENTITY_INIT; diff --git a/test/src/tests.c b/test/src/tests.c index 580454e..bec1b62 100644 --- a/test/src/tests.c +++ b/test/src/tests.c @@ -19,6 +19,7 @@ #include "test_ivec3.h" #include "test_ivec4.h" #include "test_mat2.h" +#include "test_mat2x3.h" #include "test_mat3.h" #include "test_mat4.h" #include "test_quat.h" @@ -50,6 +51,7 @@ #include "test_ivec3.h" #include "test_ivec4.h" #include "test_mat2.h" +#include "test_mat2x3.h" #include "test_mat3.h" #include "test_mat4.h" #include "test_quat.h" diff --git a/test/tests.h b/test/tests.h index 996102b..acdfb35 100644 --- a/test/tests.h +++ b/test/tests.h @@ -228,6 +228,10 @@ TEST_DECLARE(glmc_mat2_swap_row) TEST_DECLARE(glmc_mat2_rmc) TEST_DECLARE(glmc_mat2_make) +TEST_DECLARE(glm_mat2x3_make) + +TEST_DECLARE(glmc_mat2x3_make) + /* camera (incl [LR]H cross [NZ]O) */ TEST_DECLARE(glm_perspective_lh_zo) TEST_DECLARE(glm_perspective_rh_zo) @@ -1044,7 +1048,7 @@ TEST_LIST { TEST_ENTRY(glmc_mat3_swap_row) TEST_ENTRY(glmc_mat3_rmc) TEST_ENTRY(glmc_mat3_make) - + TEST_ENTRY(MACRO_GLM_MAT2_IDENTITY_INIT) TEST_ENTRY(MACRO_GLM_MAT2_ZERO_INIT) TEST_ENTRY(MACRO_GLM_MAT2_IDENTITY) @@ -1083,6 +1087,10 @@ TEST_LIST { TEST_ENTRY(glmc_mat2_rmc) TEST_ENTRY(glmc_mat2_make) + TEST_ENTRY(glm_mat2x3_make) + + TEST_ENTRY(glmc_mat2x3_make) + /* camera (incl [LR]H cross [NZ]O) */ TEST_ENTRY(glm_perspective_lh_zo) TEST_ENTRY(glm_perspective_rh_zo) diff --git a/win/cglm-test.vcxproj b/win/cglm-test.vcxproj index 69017a5..c32bac6 100644 --- a/win/cglm-test.vcxproj +++ b/win/cglm-test.vcxproj @@ -66,6 +66,7 @@ + @@ -419,4 +420,4 @@ - \ No newline at end of file + diff --git a/win/cglm-test.vcxproj.filters b/win/cglm-test.vcxproj.filters index ade5d3e..0180b18 100644 --- a/win/cglm-test.vcxproj.filters +++ b/win/cglm-test.vcxproj.filters @@ -79,6 +79,9 @@ src + + src + src @@ -107,4 +110,4 @@ src - \ No newline at end of file + diff --git a/win/cglm.vcxproj b/win/cglm.vcxproj index fb35069..2ab9522 100644 --- a/win/cglm.vcxproj +++ b/win/cglm.vcxproj @@ -71,6 +71,7 @@ + @@ -120,6 +121,7 @@ + @@ -160,6 +162,7 @@ + @@ -209,6 +212,7 @@ + diff --git a/win/cglm.vcxproj.filters b/win/cglm.vcxproj.filters index 7a32d79..1668718 100644 --- a/win/cglm.vcxproj.filters +++ b/win/cglm.vcxproj.filters @@ -97,6 +97,9 @@ src + + src + src @@ -607,4 +610,4 @@ include\cglm\struct - \ No newline at end of file +