From 3fbf590d39ed9bcb1e2fbd63274bc440932c5ad9 Mon Sep 17 00:00:00 2001 From: Recep Aslantas Date: Mon, 29 May 2017 20:52:38 +0300 Subject: [PATCH] func for make matrix identity --- include/call/cglmc-mat.h | 4 ++++ include/call/cglmc-mat3.h | 4 ++++ include/cglm-mat.h | 21 +++++++++++++++++++++ include/cglm-mat3.h | 21 +++++++++++++++++++++ src/cglm-mat.c | 6 ++++++ src/cglm-mat3.c | 6 ++++++ 6 files changed, 62 insertions(+) diff --git a/include/call/cglmc-mat.h b/include/call/cglmc-mat.h index 2877fdc..6ea81e4 100644 --- a/include/call/cglmc-mat.h +++ b/include/call/cglmc-mat.h @@ -25,6 +25,10 @@ CGLM_EXPORT void glmc_mat4_copy(mat4 mat, mat4 dest); +CGLM_EXPORT +void +glmc_mat4_identity(mat4 mat); + CGLM_EXPORT void glmc_mat4_pick3(mat4 mat, mat3 dest); diff --git a/include/call/cglmc-mat3.h b/include/call/cglmc-mat3.h index e6c6c21..ceebc7e 100644 --- a/include/call/cglmc-mat3.h +++ b/include/call/cglmc-mat3.h @@ -20,6 +20,10 @@ CGLM_EXPORT void glmc_mat3_copy(mat3 mat, mat3 dest); +CGLM_EXPORT +void +glmc_mat3_identity(mat3 mat); + CGLM_EXPORT void glmc_mat3_mul(mat3 m1, mat3 m2, mat3 dest); diff --git a/include/cglm-mat.h b/include/cglm-mat.h index 397037a..87644ef 100644 --- a/include/cglm-mat.h +++ b/include/cglm-mat.h @@ -74,6 +74,27 @@ glm_mat4_copy(mat4 mat, mat4 dest) { #endif } +/*! + * @brief make given matrix identity. It is identical with below, + * but it is more easy to do that with this func especially for members + * e.g. glm_mat4_identity(aStruct->aMatrix); + * + * @code + * glm_mat4_copy(GLM_MAT4_IDENTITY, mat); // C only + * + * // or + * mat4 mat = GLM_MAT4_IDENTITY_INIT; + * @endcode + * + * @param[in, out] mat destination + */ +CGLM_INLINE +void +glm_mat4_identity(mat4 mat) { + mat4 t = GLM_MAT4_IDENTITY_INIT; + glm_mat4_copy(t, mat); +} + /*! * @brief copy upper-left of mat4 to mat3 * diff --git a/include/cglm-mat3.h b/include/cglm-mat3.h index e080693..cf8275a 100644 --- a/include/cglm-mat3.h +++ b/include/cglm-mat3.h @@ -38,6 +38,27 @@ glm_mat3_copy(mat3 mat, mat3 dest) { glm__memcpy(float, dest, mat, sizeof(mat3)); } +/*! + * @brief make given matrix identity. It is identical with below, + * but it is more easy to do that with this func especially for members + * e.g. glm_mat3_identity(aStruct->aMatrix); + * + * @code + * glm_mat3_copy(GLM_MAT3_IDENTITY, mat); // C only + * + * // or + * mat3 mat = GLM_MAT3_IDENTITY_INIT; + * @endcode + * + * @param[in, out] mat destination + */ +CGLM_INLINE +void +glm_mat3_identity(mat3 mat) { + mat3 t = GLM_MAT3_IDENTITY_INIT; + glm_mat3_copy(t, mat); +} + /*! * @brief multiply m1 and m2 to dest * diff --git a/src/cglm-mat.c b/src/cglm-mat.c index d2991a0..5677c81 100644 --- a/src/cglm-mat.c +++ b/src/cglm-mat.c @@ -19,6 +19,12 @@ glmc_mat4_copy(mat4 mat, mat4 dest) { glm_mat4_copy(mat, dest); } +CGLM_EXPORT +void +glmc_mat4_identity(mat4 mat) { + glm_mat4_identity(mat); +} + CGLM_EXPORT void glmc_mat4_pick3(mat4 mat, mat3 dest) { diff --git a/src/cglm-mat3.c b/src/cglm-mat3.c index e8b4a70..cc94e7d 100644 --- a/src/cglm-mat3.c +++ b/src/cglm-mat3.c @@ -13,6 +13,12 @@ glmc_mat3_copy(mat3 mat, mat3 dest) { glm_mat3_copy(mat, dest); } +CGLM_EXPORT +void +glmc_mat3_identity(mat3 mat) { + glm_mat3_identity(mat); +} + CGLM_EXPORT void glmc_mat3_mul(mat3 m1, mat3 m2, mat3 dest) {