Panda3D
bulletAllHitsRayResult.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 bulletAllHitsRayResult.cxx
10  * @author enn0x
11  * @date 2010-02-21
12  */
13 
14 #include "bulletAllHitsRayResult.h"
15 
16 /**
17  *
18  */
19 BulletAllHitsRayResult::
20 BulletAllHitsRayResult(const btVector3 &from_pos, const btVector3 &to_pos, const CollideMask &mask)
21  : btCollisionWorld::AllHitsRayResultCallback(from_pos, to_pos), _mask(mask) {
22 
23 }
24 
25 /**
26  * Override default implementation.
27  */
29 needsCollision(btBroadphaseProxy* proxy0) const {
30 
31  btCollisionObject *obj0 = (btCollisionObject *) proxy0->m_clientObject;
32  PandaNode *node0 = (PandaNode *) obj0->getUserPointer();
33  CollideMask mask0 = node0->get_into_collide_mask();
34 
35  return (_mask & mask0) != 0;
36 }
37 
38 /**
39  * Override default implementation.
40  */
42 addSingleResult(btCollisionWorld::LocalRayResult& rayResult, bool normalInWorldSpace) {
43 
44  // Store partindex information
45  if (rayResult.m_localShapeInfo) {
46  _shapePart.push_back(rayResult.m_localShapeInfo->m_shapePart);
47  _triangleIndex.push_back(rayResult.m_localShapeInfo->m_triangleIndex);
48  }
49  else {
50  _shapePart.push_back(-1);
51  _triangleIndex.push_back(-1);
52  }
53 
54  // Call the default implementation
55  return btCollisionWorld::AllHitsRayResultCallback::addSingleResult(rayResult, normalInWorldSpace);
56 };
57 
58 /**
59  *
60  */
61 LPoint3 BulletAllHitsRayResult::
62 get_from_pos() const {
63 
64  return btVector3_to_LPoint3(m_rayFromWorld);
65 }
66 
67 /**
68  *
69  */
70 LPoint3 BulletAllHitsRayResult::
71 get_to_pos() const {
72 
73  return btVector3_to_LPoint3(m_rayToWorld);
74 }
75 
76 /**
77  *
78  */
79 bool BulletAllHitsRayResult::
80 has_hits() const {
81 
82  return hasHit();
83 }
84 
85 /**
86  *
87  */
88 PN_stdfloat BulletAllHitsRayResult::
89 get_closest_hit_fraction() const {
90 
91  return (PN_stdfloat)m_closestHitFraction;
92 }
93 
94 /**
95  *
96  */
97 int BulletAllHitsRayResult::
98 get_num_hits() const {
99 
100  return m_collisionObjects.size();
101 }
102 
103 /**
104  *
105  */
106 const BulletRayHit BulletAllHitsRayResult::
107 get_hit(int idx) const {
108 
109  nassertr(idx >= 0 && idx < get_num_hits(), BulletRayHit::empty());
110 
111  BulletRayHit hit;
112 
113  hit._object = m_collisionObjects[idx];
114  hit._normal = m_hitNormalWorld[idx];
115  hit._pos = m_hitPointWorld[idx];
116  hit._fraction = m_hitFractions[idx];
117 
118  hit._shapePart = _shapePart[idx];
119  hit._triangleIndex = _triangleIndex[idx];
120 
121  return hit;
122 }
123 
124 /**
125  *
126  */
127 PN_stdfloat BulletRayHit::
128 get_hit_fraction() const {
129 
130  return (PN_stdfloat)_fraction;
131 }
132 
133 /**
134  *
135  */
136 PandaNode *BulletRayHit::
137 get_node() const {
138 
139  return (_object) ? (PandaNode *)_object->getUserPointer() : nullptr;
140 }
141 
142 /**
143  *
144  */
145 LPoint3 BulletRayHit::
146 get_hit_pos() const {
147 
148  return btVector3_to_LPoint3(_pos);
149 }
150 
151 /**
152  *
153  */
154 LVector3 BulletRayHit::
155 get_hit_normal() const {
156 
157  return btVector3_to_LVector3(_normal);
158 }
159 
160 /**
161  *
162  */
163 int BulletRayHit::
164 get_shape_part() const {
165 
166  return _shapePart;
167 }
168 
169 /**
170  *
171  */
172 int BulletRayHit::
173 get_triangle_index() const {
174 
175  return _triangleIndex;
176 }
A basic node of the scene graph or data graph.
Definition: pandaNode.h:64
virtual bool needsCollision(btBroadphaseProxy *proxy0) const
Override default implementation.
virtual btScalar addSingleResult(btCollisionWorld::LocalRayResult &rayResult, bool normalInWorldSpace)
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:32
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.