Panda3D

collisionRecorder.cxx

00001 // Filename: collisionRecorder.cxx
00002 // Created by:  drose (16Apr03)
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 #include "collisionRecorder.h"
00016 #include "collisionTraverser.h"
00017 
00018 #ifdef DO_COLLISION_RECORDING
00019 
00020 TypeHandle CollisionRecorder::_type_handle;
00021 
00022 ////////////////////////////////////////////////////////////////////
00023 //     Function: CollisionRecorder::Constructor
00024 //       Access: Protected
00025 //  Description:
00026 ////////////////////////////////////////////////////////////////////
00027 CollisionRecorder::
00028 CollisionRecorder() {
00029   _num_missed = 0;
00030   _num_detected = 0;
00031   _trav = (CollisionTraverser *)NULL;
00032 }
00033 
00034 ////////////////////////////////////////////////////////////////////
00035 //     Function: CollisionRecorder::Destructor
00036 //       Access: Public, Virtual
00037 //  Description:
00038 ////////////////////////////////////////////////////////////////////
00039 CollisionRecorder::
00040 ~CollisionRecorder() {
00041   if (_trav != (CollisionTraverser *)NULL) {
00042     _trav->clear_recorder();
00043   }
00044 }
00045 
00046 ////////////////////////////////////////////////////////////////////
00047 //     Function: CollisionRecorder::output
00048 //       Access: Public
00049 //  Description: 
00050 ////////////////////////////////////////////////////////////////////
00051 void CollisionRecorder::
00052 output(ostream &out) const {
00053   out << "tested " << _num_missed + _num_detected << ", detected "
00054       << _num_detected << "\n";
00055 }
00056 
00057 ////////////////////////////////////////////////////////////////////
00058 //     Function: CollisionRecorder::begin_traversal
00059 //       Access: Public, Virtual
00060 //  Description: This method is called at the beginning of a
00061 //               CollisionTraverser::traverse() call.  It is provided
00062 //               as a hook for the derived class to reset its state as
00063 //               appropriate.
00064 ////////////////////////////////////////////////////////////////////
00065 void CollisionRecorder::
00066 begin_traversal() {
00067   _num_missed = 0;
00068   _num_detected = 0;
00069 }
00070 
00071 ////////////////////////////////////////////////////////////////////
00072 //     Function: CollisionRecorder::collision_tested
00073 //       Access: Public, Virtual
00074 //  Description: This method is called when a pair of collision solids
00075 //               have passed all bounding-volume tests and have been
00076 //               tested for a collision.  The detected value is set
00077 //               true if a collision was detected, false otherwise.
00078 ////////////////////////////////////////////////////////////////////
00079 void CollisionRecorder::
00080 collision_tested(const CollisionEntry &entry, bool detected) {
00081   if (detected) {
00082     _num_detected++;
00083   } else {
00084     _num_missed++;
00085   }
00086 }
00087 
00088 ////////////////////////////////////////////////////////////////////
00089 //     Function: CollisionRecorder::end_traversal
00090 //       Access: Public, Virtual
00091 //  Description: This method is called at the end of a
00092 //               CollisionTraverser::traverse() call.  It is provided
00093 //               as a hook for the derived class to finalize its state
00094 //               as appropriate.
00095 ////////////////////////////////////////////////////////////////////
00096 void CollisionRecorder::
00097 end_traversal() {
00098 }
00099 
00100 #endif  // DO_COLLISION_RECORDING
 All Classes Functions Variables Enumerations