Panda3D
|
00001 // Filename: collisionHandlerEvent.cxx 00002 // Created by: drose (16Mar02) 00003 // 00004 //////////////////////////////////////////////////////////////////// 00005 // 00006 // PANDA 3D SOFTWARE 00007 // Copyright (c) Carnegie Mellon University. All rights reserved. 00008 // 00009 // All use of this software is subject to the terms of the revised BSD 00010 // license. You should have received a copy of this license along 00011 // with this source code in a file named "LICENSE." 00012 // 00013 //////////////////////////////////////////////////////////////////// 00014 00015 00016 #include "collisionHandlerHighestEvent.h" 00017 #include "config_collide.h" 00018 00019 #include "eventParameter.h" 00020 #include "throw_event.h" 00021 00022 00023 TypeHandle CollisionHandlerHighestEvent::_type_handle; 00024 00025 //////////////////////////////////////////////////////////////////// 00026 // Function: CollisionHandlerEvent::Constructor 00027 // Access: Public 00028 // Description: The default CollisionHandlerEvent will throw no 00029 // events. Its pattern strings must first be set via a 00030 // call to add_in_pattern() and/or add_out_pattern(). 00031 //////////////////////////////////////////////////////////////////// 00032 CollisionHandlerHighestEvent:: 00033 CollisionHandlerHighestEvent() { 00034 } 00035 00036 //////////////////////////////////////////////////////////////////// 00037 // Function: CollisionHandlerEvent::begin_group 00038 // Access: Public, Virtual 00039 // Description: Will be called by the CollisionTraverser before a new 00040 // traversal is begun. It instructs the handler to 00041 // reset itself in preparation for a number of 00042 // CollisionEntries to be sent. 00043 //////////////////////////////////////////////////////////////////// 00044 void CollisionHandlerHighestEvent:: 00045 begin_group() { 00046 if (collide_cat.is_spam()) { 00047 collide_cat.spam() 00048 << "begin_group.\n"; 00049 } 00050 _last_colliding.clear(); 00051 if (_closest_collider) { 00052 _last_colliding.insert(_closest_collider); 00053 } 00054 _current_colliding.clear(); 00055 _collider_distance = 0; 00056 _closest_collider = NULL; 00057 } 00058 00059 //////////////////////////////////////////////////////////////////// 00060 // Function: CollisionHandlerEvent::add_entry 00061 // Access: Public, Virtual 00062 // Description: Called between a begin_group() .. end_group() 00063 // sequence for each collision that is detected. 00064 //////////////////////////////////////////////////////////////////// 00065 void CollisionHandlerHighestEvent:: 00066 add_entry(CollisionEntry *entry) { 00067 nassertv(entry != (CollisionEntry *)NULL); 00068 LVector3 vec = 00069 entry->get_surface_point(entry->get_from_node_path()) - 00070 entry->get_from()->get_collision_origin(); 00071 double dist = vec.length_squared(); 00072 if (_closest_collider == NULL || dist < _collider_distance) { 00073 _collider_distance = dist; 00074 _closest_collider = entry; 00075 } 00076 } 00077 00078 //////////////////////////////////////////////////////////////////// 00079 // Function: CollisionHandlerPhysical::end_group 00080 // Access: Public, Virtual 00081 // Description: Called by the CollisionTraverser at the completion of 00082 // all collision detections for this traversal. It 00083 // should do whatever finalization is required for the 00084 // handler. 00085 //////////////////////////////////////////////////////////////////// 00086 bool CollisionHandlerHighestEvent:: 00087 end_group() { 00088 if (_closest_collider) { 00089 _current_colliding.insert(_closest_collider); 00090 } 00091 return CollisionHandlerEvent::end_group(); 00092 }