From bb3067ebfbe17eaa819d21b836d7410836e19c86 Mon Sep 17 00:00:00 2001 From: Recep Aslantas Date: Sun, 16 Oct 2016 20:44:13 +0300 Subject: [PATCH] mat4 swap rows/columns --- include/cglm-mat.h | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/include/cglm-mat.h b/include/cglm-mat.h index 1f32c06..565d701 100644 --- a/include/cglm-mat.h +++ b/include/cglm-mat.h @@ -443,5 +443,48 @@ glm_mat4_inv_precise(mat4 mat, mat4 dest) { #endif } +/*! + * @brief swap two matrix columns + * + * @param[in,out] mat matrix + * @param[in] col1 col1 + * @param[in] col2 col2 + */ +CGLM_INLINE +void +glm_mat4_swap_col(mat4 mat, int col1, int col2) { + vec4 tmp; + glm_vec4_dup(mat[col1], tmp); + glm_vec4_dup(mat[col2], mat[col1]); + glm_vec4_dup(tmp, mat[col2]); +} + +/*! + * @brief swap two matrix rows + * + * @param[in,out] mat matrix + * @param[in] col1 col1 + * @param[in] col2 col2 + */ +CGLM_INLINE +void +glm_mat4_swap_row(mat4 mat, int row1, int row2) { + vec4 tmp; + tmp[0] = mat[0][row1]; + tmp[1] = mat[1][row1]; + tmp[2] = mat[2][row1]; + tmp[3] = mat[3][row1]; + + mat[0][row1] = mat[0][row2]; + mat[1][row1] = mat[1][row2]; + mat[2][row1] = mat[2][row2]; + mat[3][row1] = mat[3][row2]; + + mat[0][row2] = tmp[0]; + mat[1][row2] = tmp[1]; + mat[2][row2] = tmp[2];; + mat[3][row2] = tmp[3]; +} + #else #endif /* cglm_mat_h */