From 4d5653b1f658272c869552c23ff35472cc35f051 Mon Sep 17 00:00:00 2001 From: Recep Aslantas Date: Sat, 22 Jul 2023 14:17:26 +0300 Subject: [PATCH] add some missing non-square matrix funcs in struct api --- include/cglm/struct/mat2x3.h | 83 +++++++++++++++++++++++++++++++++++ include/cglm/struct/mat2x4.h | 83 +++++++++++++++++++++++++++++++++++ include/cglm/struct/mat3x2.h | 83 +++++++++++++++++++++++++++++++++++ include/cglm/struct/mat3x4.h | 83 +++++++++++++++++++++++++++++++++++ include/cglm/struct/mat4x2.h | 84 ++++++++++++++++++++++++++++++++++++ include/cglm/struct/mat4x3.h | 83 +++++++++++++++++++++++++++++++++++ 6 files changed, 499 insertions(+) diff --git a/include/cglm/struct/mat2x3.h b/include/cglm/struct/mat2x3.h index 483aea0..d0aacb0 100644 --- a/include/cglm/struct/mat2x3.h +++ b/include/cglm/struct/mat2x3.h @@ -11,7 +11,12 @@ GLMS_MAT2X3_ZERO Functions: + CGLM_INLINE mat2x3s glms_mat2x3_zero(void); CGLM_INLINE mat2x3s glms_mat2x3_make(float * __restrict src); + CGLM_INLINE mat2s glms_mat2x3_mul(mat2x3s m1, mat3x2s m2); + CGLM_INLINE vec2s glms_mat2x3_mulv(mat2x3s m, vec3s v); + CGLM_INLINE mat3x2s glms_mat2x3_transpose(mat2x3s m); + CGLM_INLINE mat2x3s glms_mat2x3_scale(mat2x3s m, float s); */ #ifndef cglms_mat2x3_h @@ -29,6 +34,19 @@ /* for C only */ #define GLMS_MAT2X3_ZERO ((mat2x3s)GLMS_MAT2X3_ZERO_INIT) +/*! + * @brief make given matrix zero. + * + * @param[in, out] mat matrix + */ +CGLM_INLINE +mat2x3s +glms_mat2x3_(zero)(void) { + mat2x3s r; + glm_mat2x3_zero(r.raw); + return r; +} + /*! * @brief Create mat2x3 matrix from pointer * @@ -43,4 +61,69 @@ glms_mat2x3_(make)(float * __restrict src) { return r; } +/*! + * @brief multiply m1 and m2 to dest + * + * m1, m2 and dest matrices can be same matrix, it is possible to write this: + * + * @code + * glm_mat2x3_mul(m, m, m); + * @endcode + * + * @param[in] m1 left matrix + * @param[in] m2 right matrix + * @param[out] dest destination matrix + */ +CGLM_INLINE +mat2s +glms_mat2x3_(mul)(mat2x3s m1, mat3x2s m2) { + mat2s r; + glm_mat2x3_mul(m1.raw, m2.raw, r.raw); + return r; +} + +/*! + * @brief multiply matrix with column vector and store in dest vector + * + * @param[in] m matrix (left) + * @param[in] v vector (right, column vector) + * @param[out] dest result vector + */ +CGLM_INLINE +vec2s +glms_mat2x3_(mulv)(mat2x3s m, vec3s v) { + vec2s r; + glm_mat2x3_mulv(m.raw, v.raw, r.raw); + return r; +} + +/*! + * @brief transpose matrix and store in dest + * + * @param[in] m matrix + * @param[out] dest result + */ +CGLM_INLINE +mat3x2s +glms_mat2x3_(transpose)(mat2x3s m) { + mat3x2s r; + glm_mat2x3_transpose(m.raw, r.raw); + return r; +} + +/*! + * @brief scale (multiply with scalar) matrix + * + * multiply matrix with scalar + * + * @param[in, out] m matrix + * @param[in] s scalar + */ +CGLM_INLINE +mat2x3s +glms_mat2x3_(scale)(mat2x3s m, float s) { + glm_mat2x3_scale(m.raw, s); + return m; +} + #endif /* cglms_mat2x3_h */ diff --git a/include/cglm/struct/mat2x4.h b/include/cglm/struct/mat2x4.h index be76854..4b31dd2 100644 --- a/include/cglm/struct/mat2x4.h +++ b/include/cglm/struct/mat2x4.h @@ -11,7 +11,12 @@ GLMS_MAT2X4_ZERO Functions: + CGLM_INLINE mat2x4s glms_mat2x4_zero(void); CGLM_INLINE mat2x4s glms_mat2x4_make(float * __restrict src); + CGLM_INLINE mat2s glms_mat2x4_mul(mat2x4s m1, mat4x2s m2); + CGLM_INLINE vec2s glms_mat2x4_mulv(mat2x4s m, vec4s v); + CGLM_INLINE mat4x2s glms_mat2x4_transpose(mat2x4s m); + CGLM_INLINE mat2x4s glms_mat2x4_scale(mat2x4s m, float s); */ #ifndef cglms_mat2x4_h @@ -29,6 +34,19 @@ /* for C only */ #define GLMS_MAT2X4_ZERO ((mat2x4s)GLMS_MAT2X4_ZERO_INIT) +/*! + * @brief make given matrix zero. + * + * @param[in, out] mat matrix + */ +CGLM_INLINE +mat2x4s +glms_mat2x4_(zero)(void) { + mat2x4s r; + glm_mat2x4_zero(r.raw); + return r; +} + /*! * @brief Create mat2x4 matrix from pointer * @@ -43,4 +61,69 @@ glms_mat2x4_(make)(float * __restrict src) { return r; } +/*! + * @brief multiply m1 and m2 to dest + * + * m1, m2 and dest matrices can be same matrix, it is possible to write this: + * + * @code + * glm_mat2x4_mul(m, m, m); + * @endcode + * + * @param[in] m1 left matrix + * @param[in] m2 right matrix + * @param[out] dest destination matrix + */ +CGLM_INLINE +mat2s +glms_mat2x4_(mul)(mat2x4s m1, mat4x2s m2) { + mat2s r; + glm_mat2x4_mul(m1.raw, m2.raw, r.raw); + return r; +} + +/*! + * @brief multiply matrix with column vector and store in dest vector + * + * @param[in] m matrix (left) + * @param[in] v vector (right, column vector) + * @param[out] dest result vector + */ +CGLM_INLINE +vec2s +glms_mat2x4_(mulv)(mat2x4s m, vec4s v) { + vec2s r; + glm_mat2x4_mulv(m.raw, v.raw, r.raw); + return r; +} + +/*! + * @brief transpose matrix and store in dest + * + * @param[in] m matrix + * @param[out] dest result + */ +CGLM_INLINE +mat4x2s +glms_mat2x4_(transpose)(mat2x4s m) { + mat4x2s r; + glm_mat2x4_transpose(m.raw, r.raw); + return r; +} + +/*! + * @brief scale (multiply with scalar) matrix + * + * multiply matrix with scalar + * + * @param[in, out] m matrix + * @param[in] s scalar + */ +CGLM_INLINE +mat2x4s +glms_mat2x4_(scale)(mat2x4s m, float s) { + glm_mat2x4_scale(m.raw, s); + return m; +} + #endif /* cglms_mat2x4_h */ diff --git a/include/cglm/struct/mat3x2.h b/include/cglm/struct/mat3x2.h index 4c35291..7f3c134 100644 --- a/include/cglm/struct/mat3x2.h +++ b/include/cglm/struct/mat3x2.h @@ -11,7 +11,12 @@ GLMS_MAT3X2_ZERO Functions: + CGLM_INLINE mat3x2s glms_mat3x2_zero(void); CGLM_INLINE mat3x2s glms_mat3x2_make(float * __restrict src); + CGLM_INLINE mat3s glms_mat3x2_mul(mat3x2s m1, mat2x3s m2); + CGLM_INLINE vec3s glms_mat3x2_mulv(mat3x2s m, vec2s v); + CGLM_INLINE mat2x3s glms_mat3x2_transpose(mat3x2s m); + CGLM_INLINE mat3x2s glms_mat3x2_scale(mat3x2s m, float s); */ #ifndef cglms_mat3x2_h @@ -29,6 +34,19 @@ /* for C only */ #define GLMS_MAT3X2_ZERO ((mat3x2s)GLMS_MAT3X2_ZERO_INIT) +/*! + * @brief make given matrix zero. + * + * @param[in, out] mat matrix + */ +CGLM_INLINE +mat3x2s +glms_mat3x2_(zero)(void) { + mat3x2s r; + glm_mat3x2_zero(r.raw); + return r; +} + /*! * @brief Create mat3x2 matrix from pointer * @@ -43,4 +61,69 @@ glms_mat3x2_(make)(float * __restrict src) { return r; } +/*! + * @brief multiply m1 and m2 to dest + * + * m1, m2 and dest matrices can be same matrix, it is possible to write this: + * + * @code + * glm_mat3x2_mul(m, m, m); + * @endcode + * + * @param[in] m1 left matrix + * @param[in] m2 right matrix + * @param[out] dest destination matrix + */ +CGLM_INLINE +mat3s +glms_mat3x2_(mul)(mat3x2s m1, mat2x3s m2) { + mat3s r; + glm_mat3x2_mul(m1.raw, m2.raw, r.raw); + return r; +} + +/*! + * @brief multiply matrix with column vector and store in dest vector + * + * @param[in] m matrix (left) + * @param[in] v vector (right, column vector) + * @param[out] dest result vector + */ +CGLM_INLINE +vec3s +glms_mat3x2_(mulv)(mat3x2s m, vec2s v) { + vec3s r; + glm_mat3x2_mulv(m.raw, v.raw, r.raw); + return r; +} + +/*! + * @brief transpose matrix and store in dest + * + * @param[in] m matrix + * @param[out] dest result + */ +CGLM_INLINE +mat2x3s +glms_mat3x2_(transpose)(mat3x2s m) { + mat2x3s r; + glm_mat3x2_transpose(m.raw, r.raw); + return r; +} + +/*! + * @brief scale (multiply with scalar) matrix + * + * multiply matrix with scalar + * + * @param[in, out] m matrix + * @param[in] s scalar + */ +CGLM_INLINE +mat3x2s +glms_mat3x2_(scale)(mat3x2s m, float s) { + glm_mat3x2_scale(m.raw, s); + return m; +} + #endif /* cglms_mat3x2_h */ diff --git a/include/cglm/struct/mat3x4.h b/include/cglm/struct/mat3x4.h index 2bc0241..c273b2d 100644 --- a/include/cglm/struct/mat3x4.h +++ b/include/cglm/struct/mat3x4.h @@ -11,7 +11,12 @@ GLMS_MAT3X4_ZERO Functions: + CGLM_INLINE mat3x4s glms_mat3x4_zero(void); CGLM_INLINE mat3x4s glms_mat3x4_make(float * __restrict src); + CGLM_INLINE mat3s glms_mat3x4_mul(mat3x4s m1, mat4x3s m2); + CGLM_INLINE vec3s glms_mat3x4_mulv(mat3x4s m, vec4s v); + CGLM_INLINE mat4x3s glms_mat3x4_transpose(mat3x4s m); + CGLM_INLINE mat3x4s glms_mat3x4_scale(mat3x4s m, float s); */ #ifndef cglms_mat3x4_h @@ -29,6 +34,19 @@ /* for C only */ #define GLMS_MAT3X4_ZERO ((mat3x4s)GLMS_MAT3X4_ZERO_INIT) +/*! + * @brief make given matrix zero. + * + * @param[in, out] mat matrix + */ +CGLM_INLINE +mat3x4s +glms_mat3x4_(zero)(void) { + mat3x4s r; + glm_mat3x4_zero(r.raw); + return r; +} + /*! * @brief Create mat3x4 matrix from pointer * @@ -43,4 +61,69 @@ glms_mat3x4_(make)(float * __restrict src) { return r; } +/*! + * @brief multiply m1 and m2 to dest + * + * m1, m2 and dest matrices can be same matrix, it is possible to write this: + * + * @code + * glm_mat3x4_mul(m, m, m); + * @endcode + * + * @param[in] m1 left matrix + * @param[in] m2 right matrix + * @param[out] dest destination matrix + */ +CGLM_INLINE +mat3s +glms_mat3x4_(mul)(mat3x4s m1, mat4x3s m2) { + mat3s r; + glm_mat3x4_mul(m1.raw, m2.raw, r.raw); + return r; +} + +/*! + * @brief multiply matrix with column vector and store in dest vector + * + * @param[in] m matrix (left) + * @param[in] v vector (right, column vector) + * @param[out] dest result vector + */ +CGLM_INLINE +vec3s +glms_mat3x4_(mulv)(mat3x4s m, vec4s v) { + vec3s r; + glm_mat3x4_mulv(m.raw, v.raw, r.raw); + return r; +} + +/*! + * @brief transpose matrix and store in dest + * + * @param[in] m matrix + * @param[out] dest result + */ +CGLM_INLINE +mat4x3s +glms_mat3x4_(transpose)(mat3x4s m) { + mat4x3s r; + glm_mat3x4_transpose(m.raw, r.raw); + return r; +} + +/*! + * @brief scale (multiply with scalar) matrix + * + * multiply matrix with scalar + * + * @param[in, out] m matrix + * @param[in] s scalar + */ +CGLM_INLINE +mat3x4s +glms_mat3x4_(scale)(mat3x4s m, float s) { + glm_mat3x4_scale(m.raw, s); + return m; +} + #endif /* cglms_mat3x4_h */ diff --git a/include/cglm/struct/mat4x2.h b/include/cglm/struct/mat4x2.h index a367afb..33449bb 100644 --- a/include/cglm/struct/mat4x2.h +++ b/include/cglm/struct/mat4x2.h @@ -11,7 +11,12 @@ GLMS_MAT4X2_ZERO Functions: + CGLM_INLINE mat4x2s glms_mat4x2_zero(void); CGLM_INLINE mat4x2s glms_mat4x2_make(float * __restrict src); + CGLM_INLINE mat4s glms_mat4x2_mul(mat4x2s m1, mat2x4s m2); + CGLM_INLINE vec4s glms_mat4x2_mulv(mat4x2s m, vec2s v); + CGLM_INLINE mat2x4s glms_mat4x2_transpose(mat4x2s m); + CGLM_INLINE mat4x2s glms_mat4x2_scale(mat4x2s m, float s); */ #ifndef cglms_mat4x2_h @@ -29,6 +34,20 @@ /* for C only */ #define GLMS_MAT4X2_ZERO ((mat4x2s)GLMS_MAT4X2_ZERO_INIT) + +/*! + * @brief make given matrix zero. + * + * @param[in, out] mat matrix + */ +CGLM_INLINE +mat4x2s +glms_mat4x2_(zero)(void) { + mat4x2s r; + glm_mat4x2_zero(r.raw); + return r; +} + /*! * @brief Create mat4x2 matrix from pointer * @@ -43,4 +62,69 @@ glms_mat4x2_(make)(float * __restrict src) { return r; } +/*! + * @brief multiply m1 and m2 to dest + * + * m1, m2 and dest matrices can be same matrix, it is possible to write this: + * + * @code + * glm_mat4x2_mul(m, m, m); + * @endcode + * + * @param[in] m1 left matrix + * @param[in] m2 right matrix + * @param[out] dest destination matrix + */ +CGLM_INLINE +mat4s +glms_mat4x2_(mul)(mat4x2s m1, mat2x4s m2) { + mat4s r; + glm_mat4x2_mul(m1.raw, m2.raw, r.raw); + return r; +} + +/*! + * @brief multiply matrix with column vector and store in dest vector + * + * @param[in] m matrix (left) + * @param[in] v vector (right, column vector) + * @param[out] dest result vector + */ +CGLM_INLINE +vec4s +glms_mat4x2_(mulv)(mat4x2s m, vec2s v) { + vec4s r; + glm_mat4x2_mulv(m.raw, v.raw, r.raw); + return r; +} + +/*! + * @brief transpose matrix and store in dest + * + * @param[in] m matrix + * @param[out] dest result + */ +CGLM_INLINE +mat2x4s +glms_mat4x2_(transpose)(mat4x2s m) { + mat2x4s r; + glm_mat4x2_transpose(m.raw, r.raw); + return r; +} + +/*! + * @brief scale (multiply with scalar) matrix + * + * multiply matrix with scalar + * + * @param[in, out] m matrix + * @param[in] s scalar + */ +CGLM_INLINE +mat4x2s +glms_mat4x2_(scale)(mat4x2s m, float s) { + glm_mat4x2_scale(m.raw, s); + return m; +} + #endif /* cglms_mat4x2_h */ diff --git a/include/cglm/struct/mat4x3.h b/include/cglm/struct/mat4x3.h index 97a7c32..30aea81 100644 --- a/include/cglm/struct/mat4x3.h +++ b/include/cglm/struct/mat4x3.h @@ -11,7 +11,12 @@ GLMS_MAT4X3_ZERO Functions: + CGLM_INLINE mat4x3s glms_mat4x3_zero(void); CGLM_INLINE mat4x3s glms_mat4x3_make(float * __restrict src); + CGLM_INLINE mat4s glms_mat4x3_mul(mat4x3s m1, mat3x4s m2); + CGLM_INLINE vec4s glms_mat4x3_mulv(mat4x3s m, vec3s v); + CGLM_INLINE mat3x4s glms_mat4x3_transpose(mat4x3s m); + CGLM_INLINE mat4x3s glms_mat4x3_scale(mat4x3s m, float s); */ #ifndef cglms_mat4x3_h @@ -29,6 +34,19 @@ /* for C only */ #define GLMS_MAT4X3_ZERO ((mat4x3s)GLMS_MAT4X3_ZERO_INIT) +/*! + * @brief make given matrix zero. + * + * @param[in, out] mat matrix + */ +CGLM_INLINE +mat4x3s +glms_mat4x3_(zero)(void) { + mat4x3s r; + glm_mat4x3_zero(r.raw); + return r; +} + /*! * @brief Create mat4x3 matrix from pointer * @@ -43,4 +61,69 @@ glms_mat4x3_(make)(float * __restrict src) { return r; } +/*! + * @brief multiply m1 and m2 to dest + * + * m1, m2 and dest matrices can be same matrix, it is possible to write this: + * + * @code + * glm_mat4x3_mul(m, m, m); + * @endcode + * + * @param[in] m1 left matrix + * @param[in] m2 right matrix + * @param[out] dest destination matrix + */ +CGLM_INLINE +mat4s +glms_mat4x3_(mul)(mat4x3s m1, mat3x4s m2) { + mat4s r; + glm_mat4x3_mul(m1.raw, m2.raw, r.raw); + return r; +} + +/*! + * @brief multiply matrix with column vector and store in dest vector + * + * @param[in] m matrix (left) + * @param[in] v vector (right, column vector) + * @param[out] dest result vector + */ +CGLM_INLINE +vec4s +glms_mat4x3_(mulv)(mat4x3s m, vec3s v) { + vec4s r; + glm_mat4x3_mulv(m.raw, v.raw, r.raw); + return r; +} + +/*! + * @brief transpose matrix and store in dest + * + * @param[in] m matrix + * @param[out] dest result + */ +CGLM_INLINE +mat3x4s +glms_mat4x3_(transpose)(mat4x3s m) { + mat3x4s r; + glm_mat4x3_transpose(m.raw, r.raw); + return r; +} + +/*! + * @brief scale (multiply with scalar) matrix + * + * multiply matrix with scalar + * + * @param[in, out] m matrix + * @param[in] s scalar + */ +CGLM_INLINE +mat4x3s +glms_mat4x3_(scale)(mat4x3s m, float s) { + glm_mat4x3_scale(m.raw, s); + return m; +} + #endif /* cglms_mat4x3_h */