Ver código fonte

throw on-floor events only for topmost object

David Rose 22 anos atrás
pai
commit
7086723c67

+ 1 - 1
panda/src/collide/collisionHandlerEvent.h

@@ -67,7 +67,7 @@ PUBLISHED:
 
   void clear();
 
-private:
+protected:
   void throw_event_for(const vector_string &patterns, CollisionEntry *entry);
   void throw_event_pattern(const string &pattern, CollisionEntry *entry);
 

+ 12 - 1
panda/src/collide/collisionHandlerFloor.cxx

@@ -60,6 +60,11 @@ bool CollisionHandlerFloor::
 handle_entries() {
   bool okflag = true;
 
+  // Reset the set of things our parent class CollisionHandlerEvent
+  // recorded a collision with.  We'll only consider ourselves
+  // collided with the topmost object for each from_entry.
+  _current_colliding.clear();
+
   FromEntries::const_iterator fi;
   for (fi = _from_entries.begin(); fi != _from_entries.end(); ++fi) {
     const NodePath &from_node_path = (*fi).first;
@@ -81,6 +86,7 @@ handle_entries() {
         // Get the maximum height for all collisions with this node.
         bool got_max = false;
         float max_height = 0.0f;
+        CollisionEntry *max_entry = NULL;
         
         Entries::const_iterator ei;
         for (ei = entries.begin(); ei != entries.end(); ++ei) {
@@ -99,10 +105,15 @@ handle_entries() {
             if (!got_max || height > max_height) {
               got_max = true;
               max_height = height;
+              max_entry = entry;
             }
           }
         }
-        
+
+        // Record a collision with the topmost element for the
+        // CollisionHandlerEvent base class.
+        _current_colliding.insert(max_entry);
+
         // Now set our height accordingly.
         float adjust = max_height + _offset;
         if (!IS_THRESHOLD_ZERO(adjust, 0.001)) {

+ 2 - 1
panda/src/collide/collisionHandlerPhysical.cxx

@@ -83,9 +83,10 @@ add_entry(CollisionEntry *entry) {
 ////////////////////////////////////////////////////////////////////
 bool CollisionHandlerPhysical::
 end_group() {
+  bool result = handle_entries();
   CollisionHandlerEvent::end_group();
 
-  return handle_entries();
+  return result;
 }
 
 ////////////////////////////////////////////////////////////////////