From 4052943a0d655716c9bdde0d173ca60d79409ffd Mon Sep 17 00:00:00 2001 From: Recep Aslantas Date: Sun, 17 Dec 2017 15:49:00 +0300 Subject: [PATCH] matrix: make accurate inv version default * now the glm_mat4_inv_precise is deault, because I don't think all people are aware of this func * the old behavior (fast) replaced with new func: glm_mat4_inv_fast if fast version is desired then glm_mat4_inv_fast must be used. --- include/cglm/mat4.h | 24 ++++++++++++------------ include/cglm/simd/sse2/mat4.h | 6 ++++-- include/cglm/vec3.h | 2 +- include/cglm/vec4.h | 2 +- test/src/test_mat4.c | 4 ++-- 5 files changed, 20 insertions(+), 18 deletions(-) diff --git a/include/cglm/mat4.h b/include/cglm/mat4.h index d758cdd..4da3fc7 100644 --- a/include/cglm/mat4.h +++ b/include/cglm/mat4.h @@ -36,7 +36,7 @@ CGLM_INLINE void glm_mat4_scale(mat4 m, float s); CGLM_INLINE float glm_mat4_det(mat4 mat); CGLM_INLINE void glm_mat4_inv(mat4 mat, mat4 dest); - CGLM_INLINE void glm_mat4_inv_precise(mat4 mat, mat4 dest); + 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); */ @@ -78,6 +78,9 @@ #define glm_mat4_udup(mat, dest) glm_mat4_ucopy(mat, dest) #define glm_mat4_dup(mat, dest) glm_mat4_copy(mat, dest) +/* DEPRECATED! default is precise now. */ +#define glm_mat4_inv_precise(mat, dest) glm_mat4_inv(mat, dest) + /*! * @brief copy all members of [mat] to [dest] * @@ -448,10 +451,6 @@ glm_mat4_det(mat4 mat) { /*! * @brief inverse mat4 and store in dest * - * this func uses reciprocal approximation without extra corrections - * e.g Newton-Raphson. this should work faster than _precise, - * to get precise value use _precise version - * * @param[in] mat matrix * @param[out] dest inverse matrix */ @@ -504,22 +503,23 @@ glm_mat4_inv(mat4 mat, mat4 dest) { #endif } - /*! - * @brief inverse mat4 precisely and store in dest + * @brief inverse mat4 and store in dest * - * this do same thing as glm_mat4_inv did. the only diff is this func uses - * division instead of reciprocal approximation. Due to division this might - * work slower than glm_mat4_inv + * this func uses reciprocal approximation without extra corrections + * e.g Newton-Raphson. this should work faster than normal, + * to get more precise use glm_mat4_inv version. + * + * NOTE: You will lose precision, glm_mat4_inv is more accurate * * @param[in] mat matrix * @param[out] dest inverse matrix */ CGLM_INLINE void -glm_mat4_inv_precise(mat4 mat, mat4 dest) { +glm_mat4_inv_fast(mat4 mat, mat4 dest) { #if defined( __SSE__ ) || defined( __SSE2__ ) - glm_mat4_inv_precise_sse2(mat, dest); + glm_mat4_inv_fast_sse2(mat, dest); #else glm_mat4_inv(mat, dest); #endif diff --git a/include/cglm/simd/sse2/mat4.h b/include/cglm/simd/sse2/mat4.h index c070af9..77874a8 100644 --- a/include/cglm/simd/sse2/mat4.h +++ b/include/cglm/simd/sse2/mat4.h @@ -12,6 +12,8 @@ #include "../../common.h" #include "../intrin.h" +#define glm_mat4_inv_precise_sse2(mat, dest) glm_mat4_inv_sse2(mat, dest) + CGLM_INLINE void glm_mat4_scale_sse2(mat4 m, float s){ @@ -157,7 +159,7 @@ glm_mat4_det_sse2(mat4 mat) { CGLM_INLINE void -glm_mat4_inv_sse2(mat4 mat, mat4 dest) { +glm_mat4_inv_fast_sse2(mat4 mat, mat4 dest) { __m128 r0, r1, r2, r3, v0, v1, v2, v3, t0, t1, t2, t3, t4, t5, @@ -281,7 +283,7 @@ glm_mat4_inv_sse2(mat4 mat, mat4 dest) { CGLM_INLINE void -glm_mat4_inv_precise_sse2(mat4 mat, mat4 dest) { +glm_mat4_inv_sse2(mat4 mat, mat4 dest) { __m128 r0, r1, r2, r3, v0, v1, v2, v3, t0, t1, t2, t3, t4, t5, diff --git a/include/cglm/vec3.h b/include/cglm/vec3.h index 5ae1674..64a0aaa 100644 --- a/include/cglm/vec3.h +++ b/include/cglm/vec3.h @@ -226,7 +226,7 @@ glm_vec_inv(vec3 v) { /*! * @brief inverse/opposite vector * - * @param[in] vec source + * @param[in] v source * @param[out] dest destination */ CGLM_INLINE diff --git a/include/cglm/vec4.h b/include/cglm/vec4.h index 7c4cc2b..5a01a95 100644 --- a/include/cglm/vec4.h +++ b/include/cglm/vec4.h @@ -251,7 +251,7 @@ glm_vec4_inv(vec4 v) { /*! * @brief inverse/opposite vector * - * @param[in] vec source + * @param[in] v source * @param[out] dest destination */ CGLM_INLINE diff --git a/test/src/test_mat4.c b/test/src/test_mat4.c index ac977cd..7e4c488 100644 --- a/test/src/test_mat4.c +++ b/test/src/test_mat4.c @@ -70,8 +70,8 @@ test_mat4(void **state) { test_rand_mat4(m3); test_rand_mat4(m4); - glm_mat4_inv(m3, m4); - glm_mat4_inv(m4, m5); + glm_mat4_inv_fast(m3, m4); + glm_mat4_inv_fast(m4, m5); test_assert_mat4_eq2(m3, m5, 0.0009f); test_rand_mat4(m3);