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.
This commit is contained in:
Recep Aslantas
2017-12-17 15:49:00 +03:00
parent 33fefb9454
commit 4052943a0d
5 changed files with 20 additions and 18 deletions

View File

@@ -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

View File

@@ -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,

View File

@@ -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

View File

@@ -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

View File

@@ -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);