From e9aa249a737d1daec9eab63fa2b2c984bbd4a18b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Wladislav=20=E3=83=B4=E3=83=A9=E3=83=89=20Artsimovich?= Date: Thu, 15 Jun 2023 17:42:06 +0900 Subject: [PATCH 1/4] Add forgotten function listing in comment --- include/cglm/affine-mat.h | 1 + 1 file changed, 1 insertion(+) diff --git a/include/cglm/affine-mat.h b/include/cglm/affine-mat.h index 1cd4973..c22c0e0 100644 --- a/include/cglm/affine-mat.h +++ b/include/cglm/affine-mat.h @@ -8,6 +8,7 @@ /* Functions: CGLM_INLINE void glm_mul(mat4 m1, mat4 m2, mat4 dest); + CGLM_INLINE void glm_mul_rot(mat4 m1, mat4 m2, mat4 dest); CGLM_INLINE void glm_inv_tr(mat4 mat); */ From 702bed817365a83051e4856a363fabcd16c8207d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Wladislav=20=E3=83=B4=E3=83=A9=E3=83=89=20Artsimovich?= Date: Thu, 15 Jun 2023 18:18:52 +0900 Subject: [PATCH 2/4] Implement missing Struct API 3D Affine Transforms --- include/cglm/struct/affine-mat.h | 90 ++++++++++++++++++++++++++++++++ include/cglm/struct/affine.h | 1 + 2 files changed, 91 insertions(+) create mode 100644 include/cglm/struct/affine-mat.h diff --git a/include/cglm/struct/affine-mat.h b/include/cglm/struct/affine-mat.h new file mode 100644 index 0000000..78a6a40 --- /dev/null +++ b/include/cglm/struct/affine-mat.h @@ -0,0 +1,90 @@ +/* + * Copyright (c), Recep Aslantas. + * + * MIT License (MIT), http://opensource.org/licenses/MIT + * Full license can be found in the LICENSE file + */ + +/* + Functions: + CGLM_INLINE mat4s glms_mul(mat4 m1, mat4 m2); + CGLM_INLINE mat4s glms_mul_rot(mat4 m1, mat4 m2); + CGLM_INLINE mat4s glms_inv_tr(); + */ + +#ifndef cglms_affine_mat_h +#define cglms_affine_mat_h + +#include "../common.h" +#include "../types-struct.h" +#include "../affine-mat.h" +#include "vec3.h" +#include "vec4.h" +#include "mat4.h" + +/*! + * @brief this is similar to glms_mat4_mul but specialized to affine transform + * + * Matrix format should be: + * R R R X + * R R R Y + * R R R Z + * 0 0 0 W + * + * this reduces some multiplications. It should be faster than mat4_mul. + * if you are not sure about matrix format then DON'T use this! use mat4_mul + * + * @param[in] m1 affine matrix 1 + * @param[in] m2 affine matrix 2 + * @returns destination matrix + */ +CGLM_INLINE +mat4s +glms_mul(mat4s m1, mat4s m2){ + mat4s r; + glm_mul(m1.raw, m2.raw, r.raw); + return r; +} + +/*! + * @brief this is similar to glm_mat4_mul but specialized to affine transform + * + * Right Matrix format should be: + * R R R 0 + * R R R 0 + * R R R 0 + * 0 0 0 1 + * + * this reduces some multiplications. It should be faster than mat4_mul. + * if you are not sure about matrix format then DON'T use this! use mat4_mul + * + * @param[in] m1 affine matrix 1 + * @param[in] m2 affine matrix 2 + * @returns destination matrix + */ +CGLM_INLINE +mat4s +glms_mul_rot(mat4s m1, mat4s m2){ + mat4s r; + glm_mul_rot(m1.raw, m2.raw, r.raw); + return r; +} + +/*! + * @brief inverse orthonormal rotation + translation matrix (ridig-body) + * + * @code + * X = | R T | X' = | R' -R'T | + * | 0 1 | | 0 1 | + * @endcode + * + * @param[in] mat matrix + * @returns destination matrix + */ +CGLM_INLINE +mat4s +glms_inv_tr(mat4s m){ + glm_inv_tr(m.raw); + return m; +} +#endif /* cglms_affine_mat_h */ diff --git a/include/cglm/struct/affine.h b/include/cglm/struct/affine.h index 64e56d0..bc62846 100644 --- a/include/cglm/struct/affine.h +++ b/include/cglm/struct/affine.h @@ -39,6 +39,7 @@ #include "vec3.h" #include "vec4.h" #include "mat4.h" +#include "affine-mat.h" /*! * @brief creates NEW translate transform matrix by v vector From c4d4c4851822996ad147db7ce2354c78e3cad0e9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Wladislav=20=E3=83=B4=E3=83=A9=E3=83=89=20Artsimovich?= Date: Thu, 15 Jun 2023 21:54:54 +0900 Subject: [PATCH 3/4] Add affine-mat.h to the Makefile --- Makefile.am | 1 + 1 file changed, 1 insertion(+) diff --git a/Makefile.am b/Makefile.am index 91f4eee..1eeb988 100644 --- a/Makefile.am +++ b/Makefile.am @@ -163,6 +163,7 @@ cglm_struct_HEADERS = include/cglm/struct/mat4.h \ include/cglm/struct/mat2.h \ include/cglm/struct/affine-pre.h \ include/cglm/struct/affine-post.h \ + include/cglm/struct/affine-mat.h \ include/cglm/struct/affine.h \ include/cglm/struct/affine2d.h \ include/cglm/struct/vec2.h \ From a7cda7f9690452ebeba26d475e0d051f1a970765 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Wladislav=20=E3=83=B4=E3=83=A9=E3=83=89=20Artsimovich?= Date: Thu, 15 Jun 2023 22:02:21 +0900 Subject: [PATCH 4/4] Add new header to Visual Studio as well --- win/cglm.vcxproj | 1 + win/cglm.vcxproj.filters | 3 +++ 2 files changed, 4 insertions(+) diff --git a/win/cglm.vcxproj b/win/cglm.vcxproj index a0a9282..fb35069 100644 --- a/win/cglm.vcxproj +++ b/win/cglm.vcxproj @@ -184,6 +184,7 @@ + diff --git a/win/cglm.vcxproj.filters b/win/cglm.vcxproj.filters index 7b9b6a3..7a32d79 100644 --- a/win/cglm.vcxproj.filters +++ b/win/cglm.vcxproj.filters @@ -603,5 +603,8 @@ include\cglm\struct + + include\cglm\struct + \ No newline at end of file