Panda3D
collisionHandlerHighestEvent.cxx
1 // Filename: collisionHandlerEvent.cxx
2 // Created by: drose (16Mar02)
3 //
4 ////////////////////////////////////////////////////////////////////
5 //
6 // PANDA 3D SOFTWARE
7 // Copyright (c) Carnegie Mellon University. All rights reserved.
8 //
9 // All use of this software is subject to the terms of the revised BSD
10 // license. You should have received a copy of this license along
11 // with this source code in a file named "LICENSE."
12 //
13 ////////////////////////////////////////////////////////////////////
14 
15 
16 #include "collisionHandlerHighestEvent.h"
17 #include "config_collide.h"
18 
19 #include "eventParameter.h"
20 #include "throw_event.h"
21 
22 
23 TypeHandle CollisionHandlerHighestEvent::_type_handle;
24 
25 ////////////////////////////////////////////////////////////////////
26 // Function: CollisionHandlerEvent::Constructor
27 // Access: Public
28 // Description: The default CollisionHandlerEvent will throw no
29 // events. Its pattern strings must first be set via a
30 // call to add_in_pattern() and/or add_out_pattern().
31 ////////////////////////////////////////////////////////////////////
34 }
35 
36 ////////////////////////////////////////////////////////////////////
37 // Function: CollisionHandlerEvent::begin_group
38 // Access: Public, Virtual
39 // Description: Will be called by the CollisionTraverser before a new
40 // traversal is begun. It instructs the handler to
41 // reset itself in preparation for a number of
42 // CollisionEntries to be sent.
43 ////////////////////////////////////////////////////////////////////
46  if (collide_cat.is_spam()) {
47  collide_cat.spam()
48  << "begin_group.\n";
49  }
50  _last_colliding.clear();
51  if (_closest_collider) {
52  _last_colliding.insert(_closest_collider);
53  }
54  _current_colliding.clear();
55  _collider_distance = 0;
56  _closest_collider = NULL;
57 }
58 
59 ////////////////////////////////////////////////////////////////////
60 // Function: CollisionHandlerEvent::add_entry
61 // Access: Public, Virtual
62 // Description: Called between a begin_group() .. end_group()
63 // sequence for each collision that is detected.
64 ////////////////////////////////////////////////////////////////////
67  nassertv(entry != (CollisionEntry *)NULL);
68  LVector3 vec =
69  entry->get_surface_point(entry->get_from_node_path()) -
70  entry->get_from()->get_collision_origin();
71  double dist = vec.length_squared();
72  if (_closest_collider == NULL || dist < _collider_distance) {
73  _collider_distance = dist;
74  _closest_collider = entry;
75  }
76 }
77 
78 ////////////////////////////////////////////////////////////////////
79 // Function: CollisionHandlerPhysical::end_group
80 // Access: Public, Virtual
81 // Description: Called by the CollisionTraverser at the completion of
82 // all collision detections for this traversal. It
83 // should do whatever finalization is required for the
84 // handler.
85 ////////////////////////////////////////////////////////////////////
88  if (_closest_collider) {
89  _current_colliding.insert(_closest_collider);
90  }
92 }
float length_squared() const
Returns the square of the vector&#39;s length, cheap and easy.
Definition: lvecBase3.h:749
virtual bool end_group()
Called by the CollisionTraverser at the completion of all collision detections for this traversal...
LPoint3 get_surface_point(const NodePath &space) const
Returns the point, on the surface of the "into" object, at which a collision is detected.
virtual bool end_group()
Called by the CollisionTraverser at the completion of all collision detections for this traversal...
This is a three-component vector distance (as opposed to a three-component point, which represents a ...
Definition: lvector3.h:100
Defines a single collision event.
virtual void begin_group()
Will be called by the CollisionTraverser before a new traversal is begun.
virtual void add_entry(CollisionEntry *entry)
Called between a begin_group() .
CollisionHandlerHighestEvent()
The default CollisionHandlerEvent will throw no events.
NodePath get_from_node_path() const
Returns the NodePath that represents the CollisionNode that contains the CollisionSolid that triggere...
TypeHandle is the identifier used to differentiate C++ class types.
Definition: typeHandle.h:85
const CollisionSolid * get_from() const
Returns the CollisionSolid pointer for the particular solid that triggered this collision.