Panda3D
 All Classes Functions Variables Enumerations
bulletAllHitsRayResult.cxx
1 // Filename: bulletAllHitsRayResult.cxx
2 // Created by: enn0x (21Feb10)
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 "bulletAllHitsRayResult.h"
16 
17 ////////////////////////////////////////////////////////////////////
18 // Function: BulletAllHitsRayResult::Constructor
19 // Access: Protected
20 // Description:
21 ////////////////////////////////////////////////////////////////////
22 BulletAllHitsRayResult::
23 BulletAllHitsRayResult(const btVector3 &from_pos, const btVector3 &to_pos, const CollideMask &mask)
24  : btCollisionWorld::AllHitsRayResultCallback(from_pos, to_pos), _mask(mask) {
25 
26 }
27 
28 ////////////////////////////////////////////////////////////////////
29 // Function: BulletAllHitsRayResult::needsCollision
30 // Access: Protected
31 // Description: Override default implementation.
32 ////////////////////////////////////////////////////////////////////
34 needsCollision(btBroadphaseProxy* proxy0) const {
35 
36  btCollisionObject *obj0 = (btCollisionObject *) proxy0->m_clientObject;
37  PandaNode *node0 = (PandaNode *) obj0->getUserPointer();
38  CollideMask mask0 = node0->get_into_collide_mask();
39 
40  return (_mask & mask0) != 0;
41 }
42 
43 ////////////////////////////////////////////////////////////////////
44 // Function: BulletAllHitsRayResult::addSingleResult
45 // Access: Protected
46 // Description: Override default implementation.
47 ////////////////////////////////////////////////////////////////////
49 addSingleResult(btCollisionWorld::LocalRayResult& rayResult, bool normalInWorldSpace) {
50 
51  // Store part/index information
52  if (rayResult.m_localShapeInfo) {
53  _shapePart.push_back(rayResult.m_localShapeInfo->m_shapePart);
54  _triangleIndex.push_back(rayResult.m_localShapeInfo->m_triangleIndex);
55  }
56  else {
57  _shapePart.push_back(-1);
58  _triangleIndex.push_back(-1);
59  }
60 
61  // Call the default implementation
62  return btCollisionWorld::AllHitsRayResultCallback::addSingleResult(rayResult, normalInWorldSpace);
63 };
64 
65 ////////////////////////////////////////////////////////////////////
66 // Function: BulletAllHitsRayResult::get_from_pos
67 // Access: Published
68 // Description:
69 ////////////////////////////////////////////////////////////////////
70 LPoint3 BulletAllHitsRayResult::
71 get_from_pos() const {
72 
73  return btVector3_to_LPoint3(m_rayFromWorld);
74 }
75 
76 ////////////////////////////////////////////////////////////////////
77 // Function: BulletAllHitsRayResult::get_to_pos
78 // Access: Published
79 // Description:
80 ////////////////////////////////////////////////////////////////////
81 LPoint3 BulletAllHitsRayResult::
82 get_to_pos() const {
83 
84  return btVector3_to_LPoint3(m_rayToWorld);
85 }
86 
87 ////////////////////////////////////////////////////////////////////
88 // Function: BulletAllHitsRayResult::has_hits
89 // Access: Published
90 // Description:
91 ////////////////////////////////////////////////////////////////////
92 bool BulletAllHitsRayResult::
93 has_hits() const {
94 
95  return hasHit();
96 }
97 
98 ////////////////////////////////////////////////////////////////////
99 // Function: BulletAllHitsRayResult::get_closest_hit_fraction
100 // Access: Published
101 // Description:
102 ////////////////////////////////////////////////////////////////////
103 PN_stdfloat BulletAllHitsRayResult::
104 get_closest_hit_fraction() const {
105 
106  return (PN_stdfloat)m_closestHitFraction;
107 }
108 
109 ////////////////////////////////////////////////////////////////////
110 // Function: BulletAllHitsRayResult::get_num_hits
111 // Access: Published
112 // Description:
113 ////////////////////////////////////////////////////////////////////
114 int BulletAllHitsRayResult::
115 get_num_hits() const {
116 
117  return m_collisionObjects.size();
118 }
119 
120 ////////////////////////////////////////////////////////////////////
121 // Function: BulletAllHitsRayResult::get_hit
122 // Access: Published
123 // Description:
124 ////////////////////////////////////////////////////////////////////
125 const BulletRayHit BulletAllHitsRayResult::
126 get_hit(int idx) const {
127 
128  nassertr(idx >= 0 && idx < get_num_hits(), BulletRayHit::empty());
129 
130  BulletRayHit hit;
131 
132  hit._object = m_collisionObjects[idx];
133  hit._normal = m_hitNormalWorld[idx];
134  hit._pos = m_hitPointWorld[idx];
135  hit._fraction = m_hitFractions[idx];
136 
137  hit._shapePart = _shapePart[idx];
138  hit._triangleIndex = _triangleIndex[idx];
139 
140  return hit;
141 }
142 
143 ////////////////////////////////////////////////////////////////////
144 // Function: BulletRayHit::get_hit_fraction
145 // Access: Published
146 // Description:
147 ////////////////////////////////////////////////////////////////////
148 PN_stdfloat BulletRayHit::
149 get_hit_fraction() const {
150 
151  return (PN_stdfloat)_fraction;
152 }
153 
154 ////////////////////////////////////////////////////////////////////
155 // Function: BulletRayHit::get_node
156 // Access: Published
157 // Description:
158 ////////////////////////////////////////////////////////////////////
159 const PandaNode *BulletRayHit::
160 get_node() const {
161 
162  return (_object) ? (PandaNode *)_object->getUserPointer() : NULL;
163 }
164 
165 ////////////////////////////////////////////////////////////////////
166 // Function: BulletRayHit::get_hit_pos
167 // Access: Published
168 // Description:
169 ////////////////////////////////////////////////////////////////////
170 LPoint3 BulletRayHit::
171 get_hit_pos() const {
172 
173  return btVector3_to_LPoint3(_pos);
174 }
175 
176 ////////////////////////////////////////////////////////////////////
177 // Function: BulletRayHit::get_hit_normal
178 // Access: Published
179 // Description:
180 ////////////////////////////////////////////////////////////////////
181 LVector3 BulletRayHit::
182 get_hit_normal() const {
183 
184  return btVector3_to_LVector3(_normal);
185 }
186 
187 ////////////////////////////////////////////////////////////////////
188 // Function: BulletRayHit::get_shape_part
189 // Access: Published
190 // Description:
191 ////////////////////////////////////////////////////////////////////
192 int BulletRayHit::
193 get_shape_part() const {
194 
195  return _shapePart;
196 }
197 
198 ////////////////////////////////////////////////////////////////////
199 // Function: BulletRayHit::get_triangle_index
200 // Access: Published
201 // Description:
202 ////////////////////////////////////////////////////////////////////
203 int BulletRayHit::
204 get_triangle_index() const {
205 
206  return _triangleIndex;
207 }
208 
A basic node of the scene graph or data graph.
Definition: pandaNode.h:72
This is a three-component vector distance (as opposed to a three-component point, which represents a ...
Definition: lvector3.h:100
This is a three-component point in space (as opposed to a three-component vector, which represents a ...
Definition: lpoint3.h:99
virtual btScalar addSingleResult(btCollisionWorld::LocalRayResult &rayResult, bool normalInWorldSpace)
Override default implementation.
virtual bool needsCollision(btBroadphaseProxy *proxy0) const
Override default implementation.
static BulletRayHit empty()
Named constructor intended to be used for asserts with have to return a concrete value.
A general bitmask class.
Definition: bitMask.h:35