Browse Source

assert matrices are nonsingular

David Rose 24 years ago
parent
commit
a31c8dd8ee

+ 7 - 0
panda/src/sgmanip/config_sgmanip.cxx

@@ -26,6 +26,13 @@
 Configure(config_sgmanip);
 NotifyCategoryDef(sgmanip, "");
 
+// Set this to true to generate an assertion failure whenever you
+// first attempt to apply a singular transform matrix to the scene
+// graph, or false to ignore this.  The default is true, which makes
+// it much easier to track down singular matrix errors.  In NDEBUG
+// mode, this is ignored and is effectively always false.
+const bool check_singular_transform = config_sgmanip.GetBool("check-singular-transform", true);
+
 ConfigureFn(config_sgmanip) {
   NodePath::init_type();
   PosLerpFunctor::init_type();

+ 3 - 0
panda/src/sgmanip/config_sgmanip.h

@@ -25,4 +25,7 @@
 
 NotifyCategoryDecl(sgmanip, EXPCL_PANDA, EXPTP_PANDA);
 
+// Configure variables for sgmanip package.
+extern const bool EXPCL_PANDA check_singular_transform;
+
 #endif

+ 25 - 1
panda/src/sgmanip/nodePath.cxx

@@ -1410,7 +1410,19 @@ set_mat(const LMatrix4f &mat) {
       << "Setting transform on data graph arc.\n"
       << "(This is probably meaningless.  Did you mean to do this to the bottom node?)\n";
   }
-#endif
+#endif  // NDEBUG
+
+#ifndef NDEBUG
+  if (check_singular_transform) {
+    LMatrix4f inv_mat;
+    bool ok = inv_mat.invert_from(mat);
+    if (!ok) {
+      sgmanip_cat.error()
+        << "Attempt to set a singular transform on " << *this << "\n";
+      nassertv(false);
+    }
+  }
+#endif  // NDEBUG
 
   arc()->set_transition(new TransformTransition(mat));
 }
@@ -1859,6 +1871,18 @@ set_mat(const NodePath &other, const LMatrix4f &mat) {
     new_mat_ptr = &new_mat;
   }
 
+#ifndef NDEBUG
+  if (check_singular_transform) {
+    LMatrix4f inv_mat;
+    bool ok = inv_mat.invert_from(*new_mat_ptr);
+    if (!ok) {
+      sgmanip_cat.error()
+        << "Attempt to set a singular transform on " << *this << "\n";
+      nassertv(false);
+    }
+  }
+#endif  // NDEBUG
+
   darc->set_transition(new TransformTransition(*new_mat_ptr));
 }