Panda3D
collisionHandlerHighestEvent.cxx
Go to the documentation of this file.
1 /**
2  * PANDA 3D SOFTWARE
3  * Copyright (c) Carnegie Mellon University. All rights reserved.
4  *
5  * All use of this software is subject to the terms of the revised BSD
6  * license. You should have received a copy of this license along
7  * with this source code in a file named "LICENSE."
8  *
9  * @file collisionHandlerHighestEvent.cxx
10  * @author drose
11  * @date 2002-03-16
12  */
13 
15 #include "config_collide.h"
16 
17 #include "eventParameter.h"
18 #include "throw_event.h"
19 
20 
21 TypeHandle CollisionHandlerHighestEvent::_type_handle;
22 
23 /**
24  * The default CollisionHandlerEvent will throw no events. Its pattern
25  * strings must first be set via a call to add_in_pattern() and/or
26  * add_out_pattern().
27  */
30 }
31 
32 /**
33  * Will be called by the CollisionTraverser before a new traversal is begun.
34  * It instructs the handler to reset itself in preparation for a number of
35  * CollisionEntries to be sent.
36  */
39  if (collide_cat.is_spam()) {
40  collide_cat.spam()
41  << "begin_group.\n";
42  }
43  _last_colliding.clear();
44  if (_closest_collider) {
45  _last_colliding.insert(_closest_collider);
46  }
47  _current_colliding.clear();
48  _collider_distance = 0;
49  _closest_collider = nullptr;
50 }
51 
52 /**
53  * Called between a begin_group() .. end_group() sequence for each collision
54  * that is detected.
55  */
58  nassertv(entry != nullptr);
59  LVector3 vec =
60  entry->get_surface_point(entry->get_from_node_path()) -
61  entry->get_from()->get_collision_origin();
62  double dist = vec.length_squared();
63  if (_closest_collider == nullptr || dist < _collider_distance) {
64  _collider_distance = dist;
65  _closest_collider = entry;
66  }
67 }
68 
69 /**
70  * Called by the CollisionTraverser at the completion of all collision
71  * detections for this traversal. It should do whatever finalization is
72  * required for the handler.
73  */
76  if (_closest_collider) {
77  _current_colliding.insert(_closest_collider);
78  }
80 }
virtual bool end_group()
Called by the CollisionTraverser at the completion of all collision detections for this traversal.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
get_from_node_path
Returns the NodePath that represents the CollisionNode that contains the CollisionSolid that triggere...
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.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
Defines a single collision event.
virtual void begin_group()
Will be called by the CollisionTraverser before a new traversal is begun.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
virtual void add_entry(CollisionEntry *entry)
Called between a begin_group() .
CollisionHandlerHighestEvent()
The default CollisionHandlerEvent will throw no events.
get_from
Returns the CollisionSolid pointer for the particular solid that triggered this collision.
TypeHandle is the identifier used to differentiate C++ class types.
Definition: typeHandle.h:81
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.