Panda3D
 All Classes Functions Variables Enumerations
collisionRecorder.cxx
1 // Filename: collisionRecorder.cxx
2 // Created by: drose (16Apr03)
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 #include "collisionRecorder.h"
16 #include "collisionTraverser.h"
17 
18 #ifdef DO_COLLISION_RECORDING
19 
20 TypeHandle CollisionRecorder::_type_handle;
21 
22 ////////////////////////////////////////////////////////////////////
23 // Function: CollisionRecorder::Constructor
24 // Access: Protected
25 // Description:
26 ////////////////////////////////////////////////////////////////////
27 CollisionRecorder::
28 CollisionRecorder() {
29  _num_missed = 0;
30  _num_detected = 0;
31  _trav = (CollisionTraverser *)NULL;
32 }
33 
34 ////////////////////////////////////////////////////////////////////
35 // Function: CollisionRecorder::Destructor
36 // Access: Public, Virtual
37 // Description:
38 ////////////////////////////////////////////////////////////////////
39 CollisionRecorder::
40 ~CollisionRecorder() {
41  if (_trav != (CollisionTraverser *)NULL) {
42  _trav->clear_recorder();
43  }
44 }
45 
46 ////////////////////////////////////////////////////////////////////
47 // Function: CollisionRecorder::output
48 // Access: Public
49 // Description:
50 ////////////////////////////////////////////////////////////////////
51 void CollisionRecorder::
52 output(ostream &out) const {
53  out << "tested " << _num_missed + _num_detected << ", detected "
54  << _num_detected << "\n";
55 }
56 
57 ////////////////////////////////////////////////////////////////////
58 // Function: CollisionRecorder::begin_traversal
59 // Access: Public, Virtual
60 // Description: This method is called at the beginning of a
61 // CollisionTraverser::traverse() call. It is provided
62 // as a hook for the derived class to reset its state as
63 // appropriate.
64 ////////////////////////////////////////////////////////////////////
65 void CollisionRecorder::
66 begin_traversal() {
67  _num_missed = 0;
68  _num_detected = 0;
69 }
70 
71 ////////////////////////////////////////////////////////////////////
72 // Function: CollisionRecorder::collision_tested
73 // Access: Public, Virtual
74 // Description: This method is called when a pair of collision solids
75 // have passed all bounding-volume tests and have been
76 // tested for a collision. The detected value is set
77 // true if a collision was detected, false otherwise.
78 ////////////////////////////////////////////////////////////////////
79 void CollisionRecorder::
80 collision_tested(const CollisionEntry &entry, bool detected) {
81  if (detected) {
82  _num_detected++;
83  } else {
84  _num_missed++;
85  }
86 }
87 
88 ////////////////////////////////////////////////////////////////////
89 // Function: CollisionRecorder::end_traversal
90 // Access: Public, Virtual
91 // Description: This method is called at the end of a
92 // CollisionTraverser::traverse() call. It is provided
93 // as a hook for the derived class to finalize its state
94 // as appropriate.
95 ////////////////////////////////////////////////////////////////////
96 void CollisionRecorder::
97 end_traversal() {
98 }
99 
100 #endif // DO_COLLISION_RECORDING
Defines a single collision event.
This class manages the traversal through the scene graph to detect collisions.
TypeHandle is the identifier used to differentiate C++ class types.
Definition: typeHandle.h:85