diff --git a/docs/source/mat3.rst b/docs/source/mat3.rst index 9b0bec4..e577ce4 100644 --- a/docs/source/mat3.rst +++ b/docs/source/mat3.rst @@ -21,6 +21,7 @@ Functions: 1. :c:func:`glm_mat3_copy` #. :c:func:`glm_mat3_identity` #. :c:func:`glm_mat3_identity_array` +#. :c:func:`glm_mat3_zero` #. :c:func:`glm_mat3_mul` #. :c:func:`glm_mat3_transpose_to` #. :c:func:`glm_mat3_transpose` @@ -60,6 +61,13 @@ Functions documentation | *[in,out]* **mat** matrix array (must be aligned (16/32) if alignment is not disabled) | *[in]* **count** count of matrices +.. c:function:: void glm_mat3_zero(mat3 mat) + + make given matrix zero + + Parameters: + | *[in,out]* **mat** matrix to + .. c:function:: void glm_mat3_mul(mat3 m1, mat3 m2, mat3 dest) multiply m1 and m2 to dest diff --git a/docs/source/mat4.rst b/docs/source/mat4.rst index f9a1c18..a74d6e2 100644 --- a/docs/source/mat4.rst +++ b/docs/source/mat4.rst @@ -26,6 +26,7 @@ Functions: #. :c:func:`glm_mat4_copy` #. :c:func:`glm_mat4_identity` #. :c:func:`glm_mat4_identity_array` +#. :c:func:`glm_mat4_zero` #. :c:func:`glm_mat4_pick3` #. :c:func:`glm_mat4_pick3t` #. :c:func:`glm_mat4_ins3` @@ -81,6 +82,13 @@ Functions documentation | *[in,out]* **mat** matrix array (must be aligned (16/32) if alignment is not disabled) | *[in]* **count** count of matrices +.. c:function:: void glm_mat4_zero(mat4 mat) + + make given matrix zero + + Parameters: + | *[in,out]* **mat** matrix to + .. c:function:: void glm_mat4_pick3(mat4 mat, mat3 dest) copy upper-left of mat4 to mat3 diff --git a/include/cglm/cam.h b/include/cglm/cam.h index 314b065..e77b989 100644 --- a/include/cglm/cam.h +++ b/include/cglm/cam.h @@ -84,7 +84,7 @@ glm_frustum(float left, mat4 dest) { float rl, tb, fn, nv; - glm__memzero(float, dest, sizeof(mat4)); + glm_mat4_zero(dest); rl = 1.0f / (right - left); tb = 1.0f / (top - bottom); @@ -122,7 +122,7 @@ glm_ortho(float left, mat4 dest) { float rl, tb, fn; - glm__memzero(float, dest, sizeof(mat4)); + glm_mat4_zero(dest); rl = 1.0f / (right - left); tb = 1.0f / (top - bottom); @@ -259,7 +259,7 @@ glm_perspective(float fovy, mat4 dest) { float f, fn; - glm__memzero(float, dest, sizeof(mat4)); + glm_mat4_zero(dest); f = 1.0f / tanf(fovy * 0.5f); fn = 1.0f / (nearVal - farVal); diff --git a/include/cglm/common.h b/include/cglm/common.h index 199bfda..422716a 100644 --- a/include/cglm/common.h +++ b/include/cglm/common.h @@ -26,34 +26,6 @@ # define CGLM_INLINE static inline __attribute((always_inline)) #endif -#define glm__memcpy(type, dest, src, size) \ - do { \ - type *srci; \ - type *srci_end; \ - type *desti; \ - \ - srci = (type *)src; \ - srci_end = (type *)((char *)srci + size); \ - desti = (type *)dest; \ - \ - while (srci != srci_end) \ - *desti++ = *srci++; \ - } while (0) - -#define glm__memset(type, dest, size, val) \ - do { \ - type *desti; \ - type *desti_end; \ - \ - desti = (type *)dest; \ - desti_end = (type *)((char *)desti + size); \ - \ - while (desti != desti_end) \ - *desti++ = val; \ - } while (0) - -#define glm__memzero(type, dest, size) glm__memset(type, dest, size, 0) - #include "types.h" #include "simd/intrin.h" diff --git a/include/cglm/mat3.h b/include/cglm/mat3.h index 0ecd755..3126064 100644 --- a/include/cglm/mat3.h +++ b/include/cglm/mat3.h @@ -17,6 +17,7 @@ CGLM_INLINE void glm_mat3_copy(mat3 mat, mat3 dest); CGLM_INLINE void glm_mat3_identity(mat3 mat); CGLM_INLINE void glm_mat3_identity_array(mat3 * restrict mat, size_t count); + CGLM_INLINE void glm_mat3_zero(mat3 mat); CGLM_INLINE void glm_mat3_mul(mat3 m1, mat3 m2, mat3 dest); CGLM_INLINE void glm_mat3_transpose_to(mat3 m, mat3 dest); CGLM_INLINE void glm_mat3_transpose(mat3 m); @@ -65,7 +66,17 @@ CGLM_INLINE void glm_mat3_copy(mat3 mat, mat3 dest) { - glm__memcpy(float, dest, mat, sizeof(mat3)); + dest[0][0] = mat[0][0]; + dest[0][1] = mat[0][1]; + dest[0][2] = mat[0][2]; + + dest[1][0] = mat[1][0]; + dest[1][1] = mat[1][1]; + dest[1][2] = mat[1][2]; + + dest[2][0] = mat[2][0]; + dest[2][1] = mat[2][1]; + dest[2][2] = mat[2][2]; } /*! @@ -108,6 +119,18 @@ glm_mat3_identity_array(mat3 * __restrict mat, size_t count) { } } +/*! + * @brief make given matrix zero. + * + * @param[in, out] mat matrix + */ +CGLM_INLINE +void +glm_mat3_zero(mat3 mat) { + CGLM_ALIGN_MAT mat3 t = GLM_MAT3_ZERO_INIT; + glm_mat3_copy(t, mat); +} + /*! * @brief multiply m1 and m2 to dest * diff --git a/include/cglm/mat4.h b/include/cglm/mat4.h index 74e876a..e6b916b 100644 --- a/include/cglm/mat4.h +++ b/include/cglm/mat4.h @@ -22,6 +22,7 @@ CGLM_INLINE void glm_mat4_copy(mat4 mat, mat4 dest); CGLM_INLINE void glm_mat4_identity(mat4 mat); CGLM_INLINE void glm_mat4_identity_array(mat4 * restrict mat, size_t count); + CGLM_INLINE void glm_mat4_zero(mat4 mat); CGLM_INLINE void glm_mat4_pick3(mat4 mat, mat3 dest); CGLM_INLINE void glm_mat4_pick3t(mat4 mat, mat3 dest); CGLM_INLINE void glm_mat4_ins3(mat3 mat, mat4 dest); @@ -31,6 +32,7 @@ CGLM_INLINE void glm_mat4_mulv3(mat4 m, vec3 v, vec3 dest); CGLM_INLINE float glm_mat4_trace(mat4 m); CGLM_INLINE float glm_mat4_trace3(mat4 m); + CGLM_INLINE void glm_mat4_quat(mat4 m, versor dest) ; CGLM_INLINE void glm_mat4_transpose_to(mat4 m, mat4 dest); CGLM_INLINE void glm_mat4_transpose(mat4 m); CGLM_INLINE void glm_mat4_scale_p(mat4 m, float s); @@ -40,6 +42,7 @@ CGLM_INLINE void glm_mat4_inv_fast(mat4 mat, mat4 dest); CGLM_INLINE void glm_mat4_swap_col(mat4 mat, int col1, int col2); CGLM_INLINE void glm_mat4_swap_row(mat4 mat, int row1, int row2); + CGLM_INLINE float glm_mat4_rmc(vec4 r, mat4 m, vec4 c); */ #ifndef cglm_mat_h @@ -98,7 +101,15 @@ CGLM_INLINE void glm_mat4_ucopy(mat4 mat, mat4 dest) { - glm__memcpy(float, dest, mat, sizeof(mat4)); + dest[0][0] = mat[0][0]; dest[1][0] = mat[1][0]; + dest[0][1] = mat[0][1]; dest[1][1] = mat[1][1]; + dest[0][2] = mat[0][2]; dest[1][2] = mat[1][2]; + dest[0][3] = mat[0][3]; dest[1][3] = mat[1][3]; + + dest[2][0] = mat[2][0]; dest[3][0] = mat[3][0]; + dest[2][1] = mat[2][1]; dest[3][1] = mat[3][1]; + dest[2][2] = mat[2][2]; dest[3][2] = mat[3][2]; + dest[2][3] = mat[2][3]; dest[3][3] = mat[3][3]; } /*! @@ -168,6 +179,18 @@ glm_mat4_identity_array(mat4 * __restrict mat, size_t count) { } } +/*! + * @brief make given matrix zero. + * + * @param[in, out] mat matrix + */ +CGLM_INLINE +void +glm_mat4_zero(mat4 mat) { + CGLM_ALIGN_MAT mat4 t = GLM_MAT4_ZERO_INIT; + glm_mat4_copy(t, mat); +} + /*! * @brief copy upper-left of mat4 to mat3 * @@ -474,10 +497,8 @@ glm_mat4_transpose(mat4 m) { glm_mat4_transp_sse2(m, m); #else mat4 d; - glm_mat4_transpose_to(m, d); - - glm__memcpy(float, m, d, sizeof(mat4)); + glm_mat4_ucopy(d, m); #endif } @@ -682,7 +703,7 @@ glm_mat4_swap_row(mat4 mat, int row1, int row2) { * * rmc stands for Row * Matrix * Column * - * the result is scalar because S * M = Matrix1x4 (row vector), + * the result is scalar because R * M = Matrix1x4 (row vector), * then Matrix1x4 * Vec4 (column vector) = Matrix1x1 (Scalar) * * @param[in] r row vector or matrix1x4