diff --git a/CMakeLists.txt b/CMakeLists.txt
index 3f4eaac..028b36c 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -85,6 +85,7 @@ add_library(${PROJECT_NAME}
src/mat3x2.c
src/mat3x4.c
src/mat4.c
+ src/mat4x2.c
src/plane.c
src/frustum.c
src/box.c
diff --git a/Makefile.am b/Makefile.am
index 789cefa..5ac1945 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -42,6 +42,7 @@ cglm_HEADERS = include/cglm/version.h \
include/cglm/cam.h \
include/cglm/io.h \
include/cglm/mat4.h \
+ include/cglm/mat4x2.h \
include/cglm/mat3.h \
include/cglm/mat3x2.h \
include/cglm/mat3x4.h \
@@ -98,6 +99,7 @@ cglm_clipspace_HEADERS = include/cglm/clipspace/persp.h \
cglm_calldir=$(includedir)/cglm/call
cglm_call_HEADERS = include/cglm/call/mat4.h \
+ include/cglm/call/mat4x2.h \
include/cglm/call/mat3.h \
include/cglm/call/mat3x2.h \
include/cglm/call/mat3x4.h \
@@ -166,6 +168,7 @@ cglm_simd_neon_HEADERS = include/cglm/simd/neon/affine.h \
cglm_structdir=$(includedir)/cglm/struct
cglm_struct_HEADERS = include/cglm/struct/mat4.h \
+ include/cglm/struct/mat4x2.h \
include/cglm/struct/mat3.h \
include/cglm/struct/mat3x2.h \
include/cglm/struct/mat3x4.h \
@@ -230,6 +233,7 @@ libcglm_la_SOURCES=\
src/mat3x2.c \
src/mat3x4.c \
src/mat4.c \
+ src/mat4x2.c \
src/plane.c \
src/frustum.c \
src/box.c \
diff --git a/docs/source/api_inline_array.rst b/docs/source/api_inline_array.rst
index 3d08b32..a7bcaf6 100644
--- a/docs/source/api_inline_array.rst
+++ b/docs/source/api_inline_array.rst
@@ -52,6 +52,7 @@ Follow the :doc:`build` documentation for this
mat3x2
mat3x4
mat4
+ mat4x2
vec2
vec2-ext
vec3
diff --git a/docs/source/mat4x2.rst b/docs/source/mat4x2.rst
new file mode 100644
index 0000000..99f03ba
--- /dev/null
+++ b/docs/source/mat4x2.rst
@@ -0,0 +1,30 @@
+.. default-domain:: C
+
+mat4x2
+======
+
+Header: cglm/mat4x2.h
+
+Table of contents (click to go):
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+Macros:
+
+1. GLM_MAT4X2_ZERO_INIT
+#. GLM_MAT4X2_ZERO
+
+Functions:
+
+1. :c:func:`glm_mat4x2_make`
+
+Functions documentation
+~~~~~~~~~~~~~~~~~~~~~~~
+
+.. c:function:: void glm_mat4x2_make(float * __restrict src, mat4x2 dest)
+
+ Create mat4x2 matrix from pointer
+
+ | NOTE: **@src** must contain at least 8 elements.
+ Parameters:
+ | *[in]* **src** pointer to an array of floats
+ | *[out]* **dest** destination matrix4x2
diff --git a/include/cglm/call.h b/include/cglm/call.h
index db522c4..9976852 100644
--- a/include/cglm/call.h
+++ b/include/cglm/call.h
@@ -25,6 +25,7 @@ extern "C" {
#include "call/mat3x2.h"
#include "call/mat3x4.h"
#include "call/mat4.h"
+#include "call/mat4x2.h"
#include "call/affine.h"
#include "call/cam.h"
#include "call/quat.h"
diff --git a/include/cglm/call/mat4x2.h b/include/cglm/call/mat4x2.h
new file mode 100644
index 0000000..f36c731
--- /dev/null
+++ b/include/cglm/call/mat4x2.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_mat4x2_h
+#define cglmc_mat4x2_h
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#include "../cglm.h"
+
+CGLM_EXPORT
+void
+glmc_mat4x2_make(float * __restrict src, mat4x2 dest);
+
+#ifdef __cplusplus
+}
+#endif
+#endif /* cglmc_mat4x2_h */
diff --git a/include/cglm/cglm.h b/include/cglm/cglm.h
index 10b44a6..457d032 100644
--- a/include/cglm/cglm.h
+++ b/include/cglm/cglm.h
@@ -16,6 +16,7 @@
#include "ivec3.h"
#include "ivec4.h"
#include "mat4.h"
+#include "mat4x2.h"
#include "mat3.h"
#include "mat3x2.h"
#include "mat3x4.h"
diff --git a/include/cglm/mat4x2.h b/include/cglm/mat4x2.h
new file mode 100644
index 0000000..1320763
--- /dev/null
+++ b/include/cglm/mat4x2.h
@@ -0,0 +1,49 @@
+/*
+ * Copyright (c), Recep Aslantas.
+ *
+ * MIT License (MIT), http://opensource.org/licenses/MIT
+ * Full license can be found in the LICENSE file
+ */
+
+/*
+ Macros:
+ GLM_MAT4X2_ZERO_INIT
+ GLM_MAT4X2_ZERO
+
+ Functions:
+ CGLM_INLINE void glm_mat4x2_make(float * restrict src, mat4x2 dest)
+ */
+
+#ifndef cglm_mat4x2_h
+#define cglm_mat4x2_h
+
+#include "common.h"
+
+#define GLM_MAT4X2_ZERO_INIT {{0.0f, 0.0f}, {0.0f, 0.0f}, {0.0f, 0.0f}, {0.0f, 0.0f}}
+
+/* for C only */
+#define GLM_MAT4X2_ZERO GLM_MAT4X2_ZERO_INIT
+
+/*!
+ * @brief Create mat4x2 matrix from pointer
+ *
+ * @param[in] src pointer to an array of floats
+ * @param[out] dest matrix
+ */
+CGLM_INLINE
+void
+glm_mat4x2_make(float * __restrict src, mat4x2 dest) {
+ dest[0][0] = src[0];
+ dest[0][1] = src[1];
+
+ dest[1][0] = src[2];
+ dest[1][1] = src[3];
+
+ dest[2][0] = src[4];
+ dest[2][1] = src[5];
+
+ dest[3][0] = src[6];
+ dest[3][1] = src[7];
+}
+
+#endif
diff --git a/include/cglm/struct.h b/include/cglm/struct.h
index 69af12a..46abae3 100644
--- a/include/cglm/struct.h
+++ b/include/cglm/struct.h
@@ -23,6 +23,7 @@ extern "C" {
#include "struct/mat3x2.h"
#include "struct/mat3x4.h"
#include "struct/mat4.h"
+#include "struct/mat4x2.h"
#include "struct/affine.h"
#include "struct/frustum.h"
#include "struct/plane.h"
diff --git a/include/cglm/struct/mat4x2.h b/include/cglm/struct/mat4x2.h
new file mode 100644
index 0000000..a367afb
--- /dev/null
+++ b/include/cglm/struct/mat4x2.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_MAT4X2_ZERO_INIT
+ GLMS_MAT4X2_ZERO
+
+ Functions:
+ CGLM_INLINE mat4x2s glms_mat4x2_make(float * __restrict src);
+ */
+
+#ifndef cglms_mat4x2_h
+#define cglms_mat4x2_h
+
+#include "../common.h"
+#include "../types-struct.h"
+#include "../mat4x2.h"
+
+/* api definition */
+#define glms_mat4x2_(NAME) CGLM_STRUCTAPI(mat4x2, NAME)
+
+#define GLMS_MAT4X2_ZERO_INIT {GLM_MAT4X2_ZERO_INIT}
+
+/* for C only */
+#define GLMS_MAT4X2_ZERO ((mat4x2s)GLMS_MAT4X2_ZERO_INIT)
+
+/*!
+ * @brief Create mat4x2 matrix from pointer
+ *
+ * @param[in] src pointer to an array of floats
+ * @return constructed matrix from raw pointer
+ */
+CGLM_INLINE
+mat4x2s
+glms_mat4x2_(make)(float * __restrict src) {
+ mat4x2s r;
+ glm_mat4x2_make(src, r.raw);
+ return r;
+}
+
+#endif /* cglms_mat4x2_h */
diff --git a/include/cglm/types-struct.h b/include/cglm/types-struct.h
index ea24b19..8aa7982 100644
--- a/include/cglm/types-struct.h
+++ b/include/cglm/types-struct.h
@@ -268,4 +268,17 @@ typedef union CGLM_ALIGN_MAT mat4s {
#endif
} mat4s;
+typedef union mat4x2s {
+ mat4x2 raw;
+ vec2s col[4]; /* [col (4), row (2)] */
+#if CGLM_USE_ANONYMOUS_STRUCT
+ struct {
+ float m00, m01;
+ float m10, m11;
+ float m21, m22;
+ float m31, m32;
+ };
+#endif
+} mat4x2s;
+
#endif /* cglm_types_struct_h */
diff --git a/include/cglm/types.h b/include/cglm/types.h
index 8562816..8712546 100644
--- a/include/cglm/types.h
+++ b/include/cglm/types.h
@@ -61,6 +61,7 @@ typedef CGLM_ALIGN_IF(16) vec2 mat2[2];
typedef vec3 mat2x3[2]; /* [col (2), row (3)] */
typedef vec4 mat2x4[2]; /* [col (2), row (4)] */
typedef CGLM_ALIGN_MAT vec4 mat4[4];
+typedef vec2 mat4x2[4]; /* [col (4), row (2)] */
/*
Important: cglm stores quaternion as [x, y, z, w] in memory since v0.4.0
diff --git a/meson.build b/meson.build
index 856c73c..5f3ab94 100644
--- a/meson.build
+++ b/meson.build
@@ -45,6 +45,7 @@ cglm_src = files(
'src/mat3x2.c',
'src/mat3x4.c',
'src/mat4.c',
+ 'src/mat4x2.c',
'src/plane.c',
'src/frustum.c',
'src/box.c',
diff --git a/src/mat4x2.c b/src/mat4x2.c
new file mode 100644
index 0000000..4e137c6
--- /dev/null
+++ b/src/mat4x2.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_mat4x2_make(float * __restrict src, mat4x2 dest) {
+ glm_mat4x2_make(src, dest);
+}
diff --git a/test/src/test_common.c b/test/src/test_common.c
index 26606c8..46337e4 100644
--- a/test/src/test_common.c
+++ b/test/src/test_common.c
@@ -312,6 +312,19 @@ test_assert_mat4_eq_zero(mat4 m4) {
TEST_SUCCESS
}
+test_status_t
+test_assert_mat4x2_eq_zero(mat4x2 m4x2) {
+ int i, j;
+
+ for (i = 0; i < 4; i++) {
+ for (j = 0; j < 2; j++) {
+ ASSERT(test_eq(m4x2[i][j], 0.0f))
+ }
+ }
+
+ TEST_SUCCESS
+}
+
test_status_t
test_assert_eqf(float a, float b) {
ASSERT(fabsf(a - b) <= 0.000009); /* rounding errors */
diff --git a/test/src/test_common.h b/test/src/test_common.h
index 80a1ae6..d7c6bc3 100644
--- a/test/src/test_common.h
+++ b/test/src/test_common.h
@@ -41,6 +41,9 @@ test_assert_mat4_eq_identity(mat4 m4);
test_status_t
test_assert_mat4_eq_zero(mat4 m4);
+test_status_t
+test_assert_mat4x2_eq_zero(mat4x2 m4x2);
+
test_status_t
test_assert_mat2_eqt(mat2 m1, mat2 m2);
diff --git a/test/src/test_mat4x2.h b/test/src/test_mat4x2.h
new file mode 100644
index 0000000..ea74507
--- /dev/null
+++ b/test/src/test_mat4x2.h
@@ -0,0 +1,56 @@
+/*
+ * 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_MAT4X2_ONCE
+#define CGLM_TEST_MAT4X2_ONCE
+
+TEST_IMPL(MACRO_GLM_MAT4X2_ZERO_INIT) {
+ mat4x2 mat4x2_zero = GLM_MAT4X2_ZERO_INIT;
+ test_assert_mat4x2_eq_zero(mat4x2_zero);
+ TEST_SUCCESS
+}
+
+TEST_IMPL(MACRO_GLM_MAT4X2_ZERO) {
+ mat4x2 mat4x2_zero = GLM_MAT4X2_ZERO;
+ test_assert_mat4x2_eq_zero(mat4x2_zero);
+ TEST_SUCCESS
+}
+
+#endif /* CGLM_TEST_MAT4X2_ONCE */
+
+TEST_IMPL(GLM_PREFIX, mat4x2_make) {
+ float src[24] = {
+ 0.5f, 1.7f, 10.3f, 4.2f, 8.9f, 1.1f, 2.3f, 4.2f,
+ 2.3f, 4.2f, 66.5f, 23.7f, 6.6f, 8.9f, 0.5f, 1.7f,
+ 5.3f, 4.8f, 96.3f, 13.7f, 4.7f, 5.5f, 2.3f, 4.2f
+ };
+
+ mat4x2 dest[3];
+
+ float *srcp = src;
+ unsigned int i, j, k;
+
+ for (i = 0, j = 0, k = 0; i < sizeof(src) / sizeof(float); i+=8,j++) {
+ GLM(mat4x2_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+1][0]));
+ ASSERT(test_eq(src[i+3], dest[j][k+1][1]));
+
+ ASSERT(test_eq(src[i+4], dest[j][k+2][0]));
+ ASSERT(test_eq(src[i+5], dest[j][k+2][1]));
+
+ ASSERT(test_eq(src[i+6], dest[j][k+3][0]));
+ ASSERT(test_eq(src[i+7], dest[j][k+3][1]));
+ }
+
+ TEST_SUCCESS
+}
diff --git a/test/src/test_struct.c b/test/src/test_struct.c
index d5e95c0..5c10780 100644
--- a/test/src/test_struct.c
+++ b/test/src/test_struct.c
@@ -83,6 +83,18 @@ TEST_IMPL(mat4s_zero_init) {
TEST_SUCCESS
}
+TEST_IMPL(mat4x2s_zero_init) {
+ mat4x2s mat4x2_zero = GLMS_MAT4X2_ZERO_INIT;
+ test_assert_mat4x2_eq_zero(mat4x2_zero.raw);
+ TEST_SUCCESS
+}
+
+TEST_IMPL(mat4x2s_zero) {
+ mat4x2s mat4x2_zero = GLMS_MAT4X2_ZERO;
+ test_assert_mat4x2_eq_zero(mat4x2_zero.raw);
+ TEST_SUCCESS
+}
+
TEST_IMPL(quats_zero_init) {
versors quat_zero = GLMS_QUAT_IDENTITY_INIT;
versor quat_zero_a = GLM_QUAT_IDENTITY_INIT;
diff --git a/test/src/tests.c b/test/src/tests.c
index 718b7a3..b874dd5 100644
--- a/test/src/tests.c
+++ b/test/src/tests.c
@@ -25,6 +25,7 @@
#include "test_mat3x2.h"
#include "test_mat3x4.h"
#include "test_mat4.h"
+#include "test_mat4x2.h"
#include "test_quat.h"
#include "test_project.h"
#include "test_plane.h"
@@ -60,6 +61,7 @@
#include "test_mat3x2.h"
#include "test_mat3x4.h"
#include "test_mat4.h"
+#include "test_mat4x2.h"
#include "test_quat.h"
#include "test_project.h"
#include "test_plane.h"
diff --git a/test/tests.h b/test/tests.h
index 86c34c3..7edf436 100644
--- a/test/tests.h
+++ b/test/tests.h
@@ -153,6 +153,12 @@ TEST_DECLARE(glmc_mat4_swap_row)
TEST_DECLARE(glmc_mat4_rmc)
TEST_DECLARE(glmc_mat4_make)
+TEST_DECLARE(MACRO_GLM_MAT4X2_ZERO_INIT)
+TEST_DECLARE(MACRO_GLM_MAT4X2_ZERO)
+TEST_DECLARE(glm_mat4x2_make)
+
+TEST_DECLARE(glmc_mat4x2_make)
+
/* mat3 */
TEST_DECLARE(glm_mat3_copy)
TEST_DECLARE(glm_mat3_identity)
@@ -893,6 +899,8 @@ TEST_DECLARE(mat3x4s_zero_init)
TEST_DECLARE(mat3x4s_zero)
TEST_DECLARE(mat4s_identity_init)
TEST_DECLARE(mat4s_zero_init)
+TEST_DECLARE(mat4x2s_zero_init)
+TEST_DECLARE(mat4x2s_zero)
TEST_DECLARE(quats_zero_init)
TEST_DECLARE(vec3s_one_init)
TEST_DECLARE(vec3s_zero_init)
@@ -1039,7 +1047,13 @@ TEST_LIST {
TEST_ENTRY(glmc_mat4_swap_row)
TEST_ENTRY(glmc_mat4_rmc)
TEST_ENTRY(glmc_mat4_make)
-
+
+ TEST_ENTRY(MACRO_GLM_MAT4X2_ZERO_INIT)
+ TEST_ENTRY(MACRO_GLM_MAT4X2_ZERO)
+ TEST_ENTRY(glm_mat4x2_make)
+
+ TEST_ENTRY(glmc_mat4x2_make)
+
/* mat3 */
TEST_ENTRY(glm_mat3_copy)
TEST_ENTRY(glm_mat3_identity)
@@ -1777,6 +1791,8 @@ TEST_LIST {
TEST_ENTRY(mat3x4s_zero)
TEST_ENTRY(mat4s_identity_init)
TEST_ENTRY(mat4s_zero_init)
+ TEST_ENTRY(mat4x2s_zero_init)
+ TEST_ENTRY(mat4x2s_zero)
TEST_ENTRY(quats_zero_init)
TEST_ENTRY(vec3s_one_init)
TEST_ENTRY(vec3s_zero_init)
diff --git a/win/cglm-test.vcxproj b/win/cglm-test.vcxproj
index 6215331..61df3f4 100644
--- a/win/cglm-test.vcxproj
+++ b/win/cglm-test.vcxproj
@@ -72,6 +72,7 @@
+
diff --git a/win/cglm-test.vcxproj.filters b/win/cglm-test.vcxproj.filters
index 73151ab..7cc7b90 100644
--- a/win/cglm-test.vcxproj.filters
+++ b/win/cglm-test.vcxproj.filters
@@ -97,6 +97,9 @@
src
+
+ src
+
src
diff --git a/win/cglm.vcxproj b/win/cglm.vcxproj
index 0b90050..736ceb0 100644
--- a/win/cglm.vcxproj
+++ b/win/cglm.vcxproj
@@ -77,6 +77,7 @@
+
@@ -130,6 +131,7 @@
+
@@ -174,6 +176,7 @@
+
@@ -227,6 +230,7 @@
+
diff --git a/win/cglm.vcxproj.filters b/win/cglm.vcxproj.filters
index 362fc5c..6f087da 100644
--- a/win/cglm.vcxproj.filters
+++ b/win/cglm.vcxproj.filters
@@ -67,6 +67,9 @@
src
+
+ src
+
src
@@ -198,6 +201,9 @@
include\cglm\call
+
+ include\cglm\call
+
include\cglm\call
@@ -270,6 +276,9 @@
include\cglm
+
+ include\cglm
+
include\cglm
@@ -393,6 +402,9 @@
include\cglm\struct
+
+ include\cglm\struct
+
include\cglm\struct