Merge pull request #334 from EasyIP2023/feature/mat3x4

add new matrix mat3x4
This commit is contained in:
Recep Aslantas
2023-07-16 23:32:05 +03:00
committed by GitHub
24 changed files with 316 additions and 0 deletions

View File

@@ -83,6 +83,7 @@ add_library(${PROJECT_NAME}
src/mat2x4.c
src/mat3.c
src/mat3x2.c
src/mat3x4.c
src/mat4.c
src/plane.c
src/frustum.c

View File

@@ -44,6 +44,7 @@ cglm_HEADERS = include/cglm/version.h \
include/cglm/mat4.h \
include/cglm/mat3.h \
include/cglm/mat3x2.h \
include/cglm/mat3x4.h \
include/cglm/mat2.h \
include/cglm/mat2x3.h \
include/cglm/mat2x4.h \
@@ -99,6 +100,7 @@ cglm_calldir=$(includedir)/cglm/call
cglm_call_HEADERS = include/cglm/call/mat4.h \
include/cglm/call/mat3.h \
include/cglm/call/mat3x2.h \
include/cglm/call/mat3x4.h \
include/cglm/call/mat2.h \
include/cglm/call/mat2x3.h \
include/cglm/call/mat2x4.h \
@@ -166,6 +168,7 @@ cglm_structdir=$(includedir)/cglm/struct
cglm_struct_HEADERS = include/cglm/struct/mat4.h \
include/cglm/struct/mat3.h \
include/cglm/struct/mat3x2.h \
include/cglm/struct/mat3x4.h \
include/cglm/struct/mat2.h \
include/cglm/struct/mat2x3.h \
include/cglm/struct/mat2x4.h \
@@ -225,6 +228,7 @@ libcglm_la_SOURCES=\
src/mat2x4.c \
src/mat3.c \
src/mat3x2.c \
src/mat3x4.c \
src/mat4.c \
src/plane.c \
src/frustum.c \

View File

@@ -50,6 +50,7 @@ Follow the :doc:`build` documentation for this
mat2x4
mat3
mat3x2
mat3x4
mat4
vec2
vec2-ext

30
docs/source/mat3x4.rst Normal file
View File

@@ -0,0 +1,30 @@
.. default-domain:: C
mat3x4
======
Header: cglm/mat3x4.h
Table of contents (click to go):
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Macros:
1. GLM_MAT3X4_ZERO_INIT
#. GLM_MAT3X4_ZERO
Functions:
1. :c:func:`glm_mat3x4_make`
Functions documentation
~~~~~~~~~~~~~~~~~~~~~~~
.. c:function:: void glm_mat3x4_make(float * __restrict src, mat3x4 dest)
Create mat3x4 matrix from pointer
| NOTE: **@src** must contain at least 12 elements.
Parameters:
| *[in]* **src** pointer to an array of floats
| *[out]* **dest** destination matrix3x4

View File

@@ -23,6 +23,7 @@ extern "C" {
#include "call/mat2x4.h"
#include "call/mat3.h"
#include "call/mat3x2.h"
#include "call/mat3x4.h"
#include "call/mat4.h"
#include "call/affine.h"
#include "call/cam.h"

View File

@@ -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_mat3x4_h
#define cglmc_mat3x4_h
#ifdef __cplusplus
extern "C" {
#endif
#include "../cglm.h"
CGLM_EXPORT
void
glmc_mat3x4_make(float * __restrict src, mat3x4 dest);
#ifdef __cplusplus
}
#endif
#endif /* cglmc_mat3x4_h */

View File

@@ -18,6 +18,7 @@
#include "mat4.h"
#include "mat3.h"
#include "mat3x2.h"
#include "mat3x4.h"
#include "mat2.h"
#include "mat2x3.h"
#include "mat2x4.h"

54
include/cglm/mat3x4.h Normal file
View File

@@ -0,0 +1,54 @@
/*
* Copyright (c), Recep Aslantas.
*
* MIT License (MIT), http://opensource.org/licenses/MIT
* Full license can be found in the LICENSE file
*/
/*
Macros:
GLM_MAT3X4_ZERO_INIT
GLM_MAT3X4_ZERO
Functions:
CGLM_INLINE void glm_mat3x4_make(float * restrict src, mat3x4 dest)
*/
#ifndef cglm_mat3x4_h
#define cglm_mat3x4_h
#include "common.h"
#define GLM_MAT3X4_ZERO_INIT {{0.0f, 0.0f, 0.0f, 0.0f}, \
{0.0f, 0.0f, 0.0f, 0.0f}, \
{0.0f, 0.0f, 0.0f, 0.0f}}
/* for C only */
#define GLM_MAT3X4_ZERO GLM_MAT3X4_ZERO_INIT
/*!
* @brief Create mat3x4 matrix from pointer
*
* @param[in] src pointer to an array of floats
* @param[out] dest matrix
*/
CGLM_INLINE
void
glm_mat3x4_make(float * __restrict src, mat3x4 dest) {
dest[0][0] = src[0];
dest[0][1] = src[1];
dest[0][2] = src[2];
dest[0][3] = src[3];
dest[1][0] = src[4];
dest[1][1] = src[5];
dest[1][2] = src[6];
dest[1][3] = src[7];
dest[2][0] = src[8];
dest[2][1] = src[9];
dest[2][2] = src[10];
dest[2][3] = src[11];
}
#endif

View File

@@ -21,6 +21,7 @@ extern "C" {
#include "struct/mat2x4.h"
#include "struct/mat3.h"
#include "struct/mat3x2.h"
#include "struct/mat3x4.h"
#include "struct/mat4.h"
#include "struct/affine.h"
#include "struct/frustum.h"

View File

@@ -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_MAT3X4_ZERO_INIT
GLMS_MAT3X4_ZERO
Functions:
CGLM_INLINE mat3x4s glms_mat3x4_make(float * __restrict src);
*/
#ifndef cglms_mat3x4_h
#define cglms_mat3x4_h
#include "../common.h"
#include "../types-struct.h"
#include "../mat3x4.h"
/* api definition */
#define glms_mat3x4_(NAME) CGLM_STRUCTAPI(mat3x4, NAME)
#define GLMS_MAT3X4_ZERO_INIT {GLM_MAT3X4_ZERO_INIT}
/* for C only */
#define GLMS_MAT3X4_ZERO ((mat3x4s)GLMS_MAT3X4_ZERO_INIT)
/*!
* @brief Create mat3x4 matrix from pointer
*
* @param[in] src pointer to an array of floats
* @return constructed matrix from raw pointer
*/
CGLM_INLINE
mat3x4s
glms_mat3x4_(make)(float * __restrict src) {
mat3x4s r;
glm_mat3x4_make(src, r.raw);
return r;
}
#endif /* cglms_mat3x4_h */

View File

@@ -243,6 +243,18 @@ typedef union mat3x2s {
#endif
} mat3x2s;
typedef union mat3x4s {
mat3x4 raw;
vec4s col[3]; /* [col (3), row (4)] */
#if CGLM_USE_ANONYMOUS_STRUCT
struct {
float m00, m01, m02, m03;
float m10, m11, m12, m13;
float m20, m21, m22, m23;
};
#endif
} mat3x4s;
typedef union CGLM_ALIGN_MAT mat4s {
mat4 raw;
vec4s col[4];

View File

@@ -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 vec2 mat3x2[3]; /* [col (3), row (2)] */
typedef vec4 mat3x4[3]; /* [col (3), row (4)] */
typedef CGLM_ALIGN_IF(16) vec2 mat2[2];
typedef vec3 mat2x3[2]; /* [col (2), row (3)] */
typedef vec4 mat2x4[2]; /* [col (2), row (4)] */

View File

@@ -43,6 +43,7 @@ cglm_src = files(
'src/mat2x4.c',
'src/mat3.c',
'src/mat3x2.c',
'src/mat3x4.c',
'src/mat4.c',
'src/plane.c',
'src/frustum.c',

15
src/mat3x4.c Normal file
View File

@@ -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_mat3x4_make(float * __restrict src, mat3x4 dest) {
glm_mat3x4_make(src, dest);
}

View File

@@ -269,6 +269,19 @@ test_assert_mat3x2_eq_zero(mat3x2 m3x2) {
TEST_SUCCESS
}
test_status_t
test_assert_mat3x4_eq_zero(mat3x4 m3x4) {
int i, j;
for (i = 0; i < 3; i++) {
for (j = 0; j < 4; j++) {
ASSERT(test_eq(m3x4[i][j], 0.0f))
}
}
TEST_SUCCESS
}
test_status_t
test_assert_mat4_eq_identity(mat4 m4) {
int i, j;

View File

@@ -77,6 +77,9 @@ test_assert_mat3_eq_zero(mat3 m3);
test_status_t
test_assert_mat3x2_eq_zero(mat3x2 m3x2);
test_status_t
test_assert_mat3x4_eq_zero(mat3x4 m3x4);
test_status_t
test_assert_vec3_eq(vec3 v1, vec3 v2);

59
test/src/test_mat3x4.h Normal file
View File

@@ -0,0 +1,59 @@
/*
* 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_MAT3X4_ONCE
#define CGLM_TEST_MAT3X4_ONCE
TEST_IMPL(MACRO_GLM_MAT3X4_ZERO_INIT) {
mat3x4 mat3x4_zero = GLM_MAT3X4_ZERO_INIT;
test_assert_mat3x4_eq_zero(mat3x4_zero);
TEST_SUCCESS
}
TEST_IMPL(MACRO_GLM_MAT3X4_ZERO) {
mat3x4 mat3x4_zero = GLM_MAT3X4_ZERO;
test_assert_mat3x4_eq_zero(mat3x4_zero);
TEST_SUCCESS
}
#endif /* CGLM_TEST_MAT3X4_ONCE */
TEST_IMPL(GLM_PREFIX, mat3x4_make) {
float src[36] = {
0.5f, 1.7f, 10.3f, 4.2f, 8.9f, 1.1f, 2.3f, 4.2f, 66.5f, 23.7f, 6.6f, 8.9f,
2.3f, 4.2f, 66.5f, 23.7f, 6.6f, 8.9f, 0.5f, 1.7f, 10.3f, 4.2f, 8.9f, 1.1f,
5.3f, 4.8f, 96.3f, 13.7f, 4.7f, 5.5f, 2.3f, 4.2f, 66.5f, 23.7f, 6.6f, 8.9f
};
mat3x4 dest[3];
float *srcp = src;
unsigned int i, j, k;
for (i = 0, j = 0, k = 0; i < sizeof(src) / sizeof(float); i+=12,j++) {
GLM(mat3x4_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][3]));
ASSERT(test_eq(src[i+4], dest[j][k+1][0]));
ASSERT(test_eq(src[i+5], dest[j][k+1][1]));
ASSERT(test_eq(src[i+6], dest[j][k+1][2]));
ASSERT(test_eq(src[i+7], dest[j][k+1][3]));
ASSERT(test_eq(src[i+8], dest[j][k+2][0]));
ASSERT(test_eq(src[i+9], dest[j][k+2][1]));
ASSERT(test_eq(src[i+10], dest[j][k+2][2]));
ASSERT(test_eq(src[i+11], dest[j][k+2][3]));
}
TEST_SUCCESS
}

View File

@@ -57,6 +57,18 @@ TEST_IMPL(mat3x2s_zero) {
TEST_SUCCESS
}
TEST_IMPL(mat3x4s_zero_init) {
mat3x4s mat3x4_zero = GLMS_MAT3X4_ZERO_INIT;
test_assert_mat3x4_eq_zero(mat3x4_zero.raw);
TEST_SUCCESS
}
TEST_IMPL(mat3x4s_zero) {
mat3x4s mat3x4_zero = GLMS_MAT3X4_ZERO;
test_assert_mat3x4_eq_zero(mat3x4_zero.raw);
TEST_SUCCESS
}
TEST_IMPL(mat4s_identity_init) {
mat4s mat4_identity = GLMS_MAT4_IDENTITY_INIT;
mat4 mat4_identity_a = GLM_MAT4_IDENTITY_INIT;

View File

@@ -23,6 +23,7 @@
#include "test_mat2x4.h"
#include "test_mat3.h"
#include "test_mat3x2.h"
#include "test_mat3x4.h"
#include "test_mat4.h"
#include "test_quat.h"
#include "test_project.h"
@@ -57,6 +58,7 @@
#include "test_mat2x4.h"
#include "test_mat3.h"
#include "test_mat3x2.h"
#include "test_mat3x4.h"
#include "test_mat4.h"
#include "test_quat.h"
#include "test_project.h"

View File

@@ -196,6 +196,12 @@ TEST_DECLARE(glm_mat3x2_make)
TEST_DECLARE(glmc_mat3x2_make)
TEST_DECLARE(MACRO_GLM_MAT3X4_ZERO_INIT)
TEST_DECLARE(MACRO_GLM_MAT3X4_ZERO)
TEST_DECLARE(glm_mat3x4_make)
TEST_DECLARE(glmc_mat3x4_make)
TEST_DECLARE(MACRO_GLM_MAT2_IDENTITY_INIT)
TEST_DECLARE(MACRO_GLM_MAT2_ZERO_INIT)
TEST_DECLARE(MACRO_GLM_MAT2_IDENTITY)
@@ -883,6 +889,8 @@ TEST_DECLARE(mat3s_identity_init)
TEST_DECLARE(mat3s_zero_init)
TEST_DECLARE(mat3x2s_zero_init)
TEST_DECLARE(mat3x2s_zero)
TEST_DECLARE(mat3x4s_zero_init)
TEST_DECLARE(mat3x4s_zero)
TEST_DECLARE(mat4s_identity_init)
TEST_DECLARE(mat4s_zero_init)
TEST_DECLARE(quats_zero_init)
@@ -1075,6 +1083,12 @@ TEST_LIST {
TEST_ENTRY(glmc_mat3x2_make)
TEST_ENTRY(MACRO_GLM_MAT3X4_ZERO_INIT)
TEST_ENTRY(MACRO_GLM_MAT3X4_ZERO)
TEST_ENTRY(glm_mat3x4_make)
TEST_ENTRY(glmc_mat3x4_make)
TEST_ENTRY(MACRO_GLM_MAT2_IDENTITY_INIT)
TEST_ENTRY(MACRO_GLM_MAT2_ZERO_INIT)
TEST_ENTRY(MACRO_GLM_MAT2_IDENTITY)
@@ -1759,6 +1773,8 @@ TEST_LIST {
TEST_ENTRY(mat3s_zero_init)
TEST_ENTRY(mat3x2s_zero_init)
TEST_ENTRY(mat3x2s_zero)
TEST_ENTRY(mat3x4s_zero_init)
TEST_ENTRY(mat3x4s_zero)
TEST_ENTRY(mat4s_identity_init)
TEST_ENTRY(mat4s_zero_init)
TEST_ENTRY(quats_zero_init)

View File

@@ -70,6 +70,7 @@
<ClInclude Include="..\test\src\test_mat2x4.h" />
<ClInclude Include="..\test\src\test_mat3.h" />
<ClInclude Include="..\test\src\test_mat3x2.h" />
<ClInclude Include="..\test\src\test_mat3x4.h" />
<ClInclude Include="..\test\src\test_mat4.h" />
<ClInclude Include="..\test\src\test_plane.h" />
<ClInclude Include="..\test\src\test_project.h" />

View File

@@ -91,6 +91,9 @@
<ClInclude Include="..\test\src\test_mat3x2.h">
<Filter>src</Filter>
</ClInclude>
<ClInclude Include="..\test\src\test_mat3x4.h">
<Filter>src</Filter>
</ClInclude>
<ClInclude Include="..\test\src\test_mat4.h">
<Filter>src</Filter>
</ClInclude>

View File

@@ -75,6 +75,7 @@
<ClCompile Include="..\src\mat2x4.c" />
<ClCompile Include="..\src\mat3.c" />
<ClCompile Include="..\src\mat3x2.c" />
<ClCompile Include="..\src\mat3x4.c" />
<ClCompile Include="..\src\mat4.c" />
<ClCompile Include="..\src\plane.c" />
<ClCompile Include="..\src\project.c" />
@@ -127,6 +128,7 @@
<ClInclude Include="..\include\cglm\call\mat2x4.h" />
<ClInclude Include="..\include\cglm\call\mat3.h" />
<ClInclude Include="..\include\cglm\call\mat3x2.h" />
<ClInclude Include="..\include\cglm\call\mat3x4.h" />
<ClInclude Include="..\include\cglm\call\mat4.h" />
<ClInclude Include="..\include\cglm\call\plane.h" />
<ClInclude Include="..\include\cglm\call\project.h" />
@@ -170,6 +172,7 @@
<ClInclude Include="..\include\cglm\mat2x4.h" />
<ClInclude Include="..\include\cglm\mat3.h" />
<ClInclude Include="..\include\cglm\mat3x2.h" />
<ClInclude Include="..\include\cglm\mat3x4.h" />
<ClInclude Include="..\include\cglm\mat4.h" />
<ClInclude Include="..\include\cglm\plane.h" />
<ClInclude Include="..\include\cglm\project.h" />
@@ -222,6 +225,7 @@
<ClInclude Include="..\include\cglm\struct\mat2x4.h" />
<ClInclude Include="..\include\cglm\struct\mat3.h" />
<ClInclude Include="..\include\cglm\struct\mat3x2.h" />
<ClInclude Include="..\include\cglm\struct\mat3x4.h" />
<ClInclude Include="..\include\cglm\struct\mat4.h" />
<ClInclude Include="..\include\cglm\struct\plane.h" />
<ClInclude Include="..\include\cglm\struct\project.h" />

View File

@@ -61,6 +61,9 @@
<ClCompile Include="..\src\mat3x2.c">
<Filter>src</Filter>
</ClCompile>
<ClCompile Include="..\src\mat3x4.c">
<Filter>src</Filter>
</ClCompile>
<ClCompile Include="..\src\mat4.c">
<Filter>src</Filter>
</ClCompile>
@@ -189,6 +192,9 @@
<ClInclude Include="..\include\cglm\call\mat3x2.h">
<Filter>include\cglm\call</Filter>
</ClInclude>
<ClInclude Include="..\include\cglm\call\mat3x4.h">
<Filter>include\cglm\call</Filter>
</ClInclude>
<ClInclude Include="..\include\cglm\call\mat4.h">
<Filter>include\cglm\call</Filter>
</ClInclude>
@@ -258,6 +264,9 @@
<ClInclude Include="..\include\cglm\mat3x2.h">
<Filter>include\cglm</Filter>
</ClInclude>
<ClInclude Include="..\include\cglm\mat3x4.h">
<Filter>include\cglm</Filter>
</ClInclude>
<ClInclude Include="..\include\cglm\mat4.h">
<Filter>include\cglm</Filter>
</ClInclude>
@@ -378,6 +387,9 @@
<ClInclude Include="..\include\cglm\struct\mat3x2.h">
<Filter>include\cglm\struct</Filter>
</ClInclude>
<ClInclude Include="..\include\cglm\struct\mat3x4.h">
<Filter>include\cglm\struct</Filter>
</ClInclude>
<ClInclude Include="..\include\cglm\struct\mat4.h">
<Filter>include\cglm\struct</Filter>
</ClInclude>