From 2b1eece9ac6f061dbb53add79af63758bcfe5aeb Mon Sep 17 00:00:00 2001 From: Recep Aslantas Date: Wed, 13 Feb 2019 10:12:49 +0300 Subject: [PATCH] mat3: add rmc for mat3 --- docs/source/mat3.rst | 18 ++++++++++++++++++ docs/source/mat4.rst | 2 +- include/cglm/call/mat3.h | 4 ++++ include/cglm/mat3.h | 24 ++++++++++++++++++++++++ src/mat3.c | 6 ++++++ 5 files changed, 53 insertions(+), 1 deletion(-) diff --git a/docs/source/mat3.rst b/docs/source/mat3.rst index 8592c4e..9b0bec4 100644 --- a/docs/source/mat3.rst +++ b/docs/source/mat3.rst @@ -32,6 +32,7 @@ Functions: #. :c:func:`glm_mat3_trace` #. :c:func:`glm_mat3_swap_col` #. :c:func:`glm_mat3_swap_row` +#. :c:func:`glm_mat3_rmc` Functions documentation ~~~~~~~~~~~~~~~~~~~~~~~ @@ -161,3 +162,20 @@ Functions documentation | *[in, out]* **mat** matrix | *[in]* **row1** row1 | *[in]* **row2** row2 + +.. c:function:: float glm_mat3_rmc(vec3 r, mat3 m, vec3 c) + + | **rmc** stands for **Row** * **Matrix** * **Column** + + | helper for R (row vector) * M (matrix) * C (column vector) + + | the result is scalar because R * M = Matrix1x3 (row vector), + | then Matrix1x3 * Vec3 (column vector) = Matrix1x1 (Scalar) + + Parameters: + | *[in]* **r** row vector or matrix1x3 + | *[in]* **m** matrix3x3 + | *[in]* **c** column vector or matrix3x1 + + Returns: + scalar value e.g. Matrix1x1 diff --git a/docs/source/mat4.rst b/docs/source/mat4.rst index 294f8f4..f9a1c18 100644 --- a/docs/source/mat4.rst +++ b/docs/source/mat4.rst @@ -278,7 +278,7 @@ Functions documentation | helper for R (row vector) * M (matrix) * C (column vector) - | 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) Parameters: diff --git a/include/cglm/call/mat3.h b/include/cglm/call/mat3.h index f27e187..fbd8270 100644 --- a/include/cglm/call/mat3.h +++ b/include/cglm/call/mat3.h @@ -72,6 +72,10 @@ CGLM_EXPORT void glmc_mat3_swap_row(mat3 mat, int row1, int row2); +CGLM_EXPORT +float +glmc_mat3_rmc(vec3 r, mat3 m, vec3 c); + #ifdef __cplusplus } #endif diff --git a/include/cglm/mat3.h b/include/cglm/mat3.h index 05bcf11..0ecd755 100644 --- a/include/cglm/mat3.h +++ b/include/cglm/mat3.h @@ -22,11 +22,13 @@ CGLM_INLINE void glm_mat3_transpose(mat3 m); CGLM_INLINE void glm_mat3_mulv(mat3 m, vec3 v, vec3 dest); CGLM_INLINE float glm_mat3_trace(mat3 m); + CGLM_INLINE void glm_mat3_quat(mat3 m, versor dest); CGLM_INLINE void glm_mat3_scale(mat3 m, float s); CGLM_INLINE float glm_mat3_det(mat3 mat); CGLM_INLINE void glm_mat3_inv(mat3 mat, mat3 dest); CGLM_INLINE void glm_mat3_swap_col(mat3 mat, int col1, int col2); CGLM_INLINE void glm_mat3_swap_row(mat3 mat, int row1, int row2); + CGLM_INLINE float glm_mat3_rmc(vec3 r, mat3 m, vec3 c); */ #ifndef cglm_mat3_h @@ -372,4 +374,26 @@ glm_mat3_swap_row(mat3 mat, int row1, int row2) { mat[2][row2] = tmp[2]; } +/*! + * @brief helper for R (row vector) * M (matrix) * C (column vector) + * + * rmc stands for Row * Matrix * Column + * + * the result is scalar because R * M = Matrix1x3 (row vector), + * then Matrix1x3 * Vec3 (column vector) = Matrix1x1 (Scalar) + * + * @param[in] r row vector or matrix1x3 + * @param[in] m matrix3x3 + * @param[in] c column vector or matrix3x1 + * + * @return scalar value e.g. Matrix1x1 + */ +CGLM_INLINE +float +glm_mat3_rmc(vec3 r, mat3 m, vec3 c) { + vec3 tmp; + glm_mat3_mulv(m, c, tmp); + return glm_vec3_dot(r, tmp); +} + #endif /* cglm_mat3_h */ diff --git a/src/mat3.c b/src/mat3.c index acb981b..337f1f1 100644 --- a/src/mat3.c +++ b/src/mat3.c @@ -91,3 +91,9 @@ void glmc_mat3_swap_row(mat3 mat, int row1, int row2) { glm_mat3_swap_row(mat, row1, row2); } + +CGLM_EXPORT +float +glmc_mat3_rmc(vec3 r, mat3 m, vec3 c) { + return glm_mat3_rmc(r, m, c); +}