From a03cf3ff2c0bdb6a3a160b13e7e218403b125ddf Mon Sep 17 00:00:00 2001 From: David Rose Date: Mon, 17 Sep 2001 23:30:21 +0000 Subject: [PATCH] don't be so fussy about nearly-singular matrices --- panda/src/linmath/lmatrix3_src.I | 6 +++++- panda/src/linmath/lmatrix4_src.cxx | 6 +++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/panda/src/linmath/lmatrix3_src.I b/panda/src/linmath/lmatrix3_src.I index 36fd7f00e2..224132ebd7 100644 --- a/panda/src/linmath/lmatrix3_src.I +++ b/panda/src/linmath/lmatrix3_src.I @@ -818,7 +818,11 @@ invert_from(const FLOATNAME(LMatrix3) &other) { FLOATTYPE other_det = MATRIX3_DETERMINANT(other._m.m); - if (IS_NEARLY_ZERO(other_det)) { + // We throw the value out only if it's smaller than our "small" + // threshold squared. This helps reduce overly-sensitive + // rejections. + if (IS_THRESHOLD_ZERO(other_det, (NEARLY_ZERO(FLOATTYPE) * NEARLY_ZERO(FLOATTYPE)))) { + // if (IS_NEARLY_ZERO(other_det)) { #ifdef NOTIFY_DEBUG linmath_cat.warning() << "Tried to invert singular LMatrix3.\n"; #endif diff --git a/panda/src/linmath/lmatrix4_src.cxx b/panda/src/linmath/lmatrix4_src.cxx index 019548fff1..076997190f 100644 --- a/panda/src/linmath/lmatrix4_src.cxx +++ b/panda/src/linmath/lmatrix4_src.cxx @@ -242,7 +242,11 @@ decompose_mat(int index[4]) { } } - if (IS_NEARLY_ZERO(big)) { + // We throw the value out only if it's smaller than our "small" + // threshold squared. This helps reduce overly-sensitive + // rejections. + if (IS_THRESHOLD_ZERO(big, (NEARLY_ZERO(FLOATTYPE) * NEARLY_ZERO(FLOATTYPE)))) { + // if (IS_NEARLY_ZERO(big)) { return false; } vv[i] = 1.0f / big;