Panda3D
physxRaycastReport.cxx
1 // Filename: physxRaycastReport.cxx
2 // Created by: enn0x (21Oct09)
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 "physxRaycastReport.h"
16 #include "physxRaycastHit.h"
17 
18 ////////////////////////////////////////////////////////////////////
19 // Function: PhysxRaycastReport::onRaycast
20 // Access: Public
21 // Description:
22 ////////////////////////////////////////////////////////////////////
23 bool PhysxRaycastReport::
24 onHit(const NxRaycastHit& hit) {
25 
26  _hits.push_back(PhysxRaycastHit(hit));
27  return true;
28 }
29 
30 ////////////////////////////////////////////////////////////////////
31 // Function: PhysxRaycastReport::get_num_hits
32 // Access: Published
33 // Description:
34 ////////////////////////////////////////////////////////////////////
35 unsigned int PhysxRaycastReport::
36 get_num_hits() const {
37 
38  return _hits.size();
39 }
40 
41 ////////////////////////////////////////////////////////////////////
42 // Function: PhysxRaycastReport::get_first_hit
43 // Access: Published
44 // Description:
45 ////////////////////////////////////////////////////////////////////
46 PhysxRaycastHit PhysxRaycastReport::
47 get_first_hit() {
48 
49  _iterator = _hits.begin();
50  return get_next_hit();
51 }
52 
53 ////////////////////////////////////////////////////////////////////
54 // Function: PhysxRaycastReport::get_next_hit
55 // Access: Published
56 // Description:
57 ////////////////////////////////////////////////////////////////////
58 PhysxRaycastHit PhysxRaycastReport::
59 get_next_hit() {
60 
61  if (_iterator != _hits.end()) {
62  return *_iterator++;
63  }
64 
65  // No more items. Return an empty hit.
66  NxRaycastHit hit;
67  hit.shape = NULL;
68  return PhysxRaycastHit(hit);
69 }
70 
71 ////////////////////////////////////////////////////////////////////
72 // Function: PhysxRaycastReport::get_hit
73 // Access: Published
74 // Description:
75 ////////////////////////////////////////////////////////////////////
76 PhysxRaycastHit PhysxRaycastReport::
77 get_hit(unsigned int idx) {
78 
79  if (!(idx < _hits.size()))
80  {
81  // Index out of bounds. Return an empty hit.
82  NxRaycastHit hit;
83  hit.shape = NULL;
84  return PhysxRaycastHit(hit);
85  }
86 
87  return _hits[idx];
88 }
89 
This structure captures results for a single raycast query.