Browse Source

a node shouldn't collide with itself or with any descendants of itself

David Rose 18 years ago
parent
commit
a75e578539
2 changed files with 28 additions and 16 deletions
  1. 26 14
      panda/src/collide/collisionLevelState.I
  2. 2 2
      panda/src/collide/collisionTraverser.cxx

+ 26 - 14
panda/src/collide/collisionLevelState.I

@@ -149,25 +149,37 @@ any_in_bounds() {
         // node.
         CollideMask from_mask = cnode->get_from_collide_mask() & _include_mask;
         if (!(from_mask & node()->get_net_collide_mask()).is_zero()) {
-          // There are bits in common, so go ahead and try the
-          // bounding volume.
-          const GeometricBoundingVolume *col_gbv =
-            get_local_bound(c);
-
-          is_in = true;  // If there's no bounding volume, we're implicitly in.
-
-          if (col_gbv != (GeometricBoundingVolume *)NULL) {
-            is_in = (node_gbv->contains(col_gbv) != 0);
-            _node_volume_pcollector.add_level(1);
-
+          // Also don't test a node with itself, or with any of its
+          // descendants.
+          if (node() == cnode) {
 #ifndef NDEBUG
             if (collide_cat.is_spam()) {
-              collide_cat.spam();
               indent(collide_cat.spam(false), indent_level)
-                << "Comparing " << c << ": " << *col_gbv
-                << " to " << *node_gbv << ", is_in = " << is_in << "\n";
+                << "Not comparing " << c << " to " << _node_path
+                << " (same node)\n";
             }
 #endif  // NDEBUG
+
+          } else {
+            // There are bits in common, and it's not the same
+            // instance, so go ahead and try the bounding volume.
+            const GeometricBoundingVolume *col_gbv =
+              get_local_bound(c);
+
+            is_in = true;  // If there's no bounding volume, we're implicitly in.
+          
+            if (col_gbv != (GeometricBoundingVolume *)NULL) {
+              is_in = (node_gbv->contains(col_gbv) != 0);
+              _node_volume_pcollector.add_level(1);
+              
+#ifndef NDEBUG
+              if (collide_cat.is_spam()) {
+                indent(collide_cat.spam(false), indent_level)
+                  << "Comparing " << c << ": " << *col_gbv
+                  << " to " << *node_gbv << ", is_in = " << is_in << "\n";
+              }
+#endif  // NDEBUG
+            }
           }
         }
 

+ 2 - 2
panda/src/collide/collisionTraverser.cxx

@@ -1177,8 +1177,8 @@ compare_collider_to_node(CollisionEntry &entry,
     DCAST_INTO_V(cnode, entry._into_node);
     int num_solids = cnode->get_num_solids();
     collide_cat.spam()
-      << "Colliding against CollisionNode " << entry._into_node << " which has " << num_solids
-      << " collision solids.\n";
+      << "Colliding against CollisionNode " << entry._into_node
+      << " which has " << num_solids << " collision solids.\n";
     for (int s = 0; s < num_solids; ++s) {
       entry._into = cnode->get_solid(s);
       if (entry._from != entry._into) {