Panda3D
bulletClosestHitRayResult.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 bulletClosestHitRayResult.cxx
10  * @author enn0x
11  * @date 2010-02-21
12  */
13 
15 
16 /**
17  *
18  */
19 BulletClosestHitRayResult::
20 BulletClosestHitRayResult(const btVector3 &from_pos, const btVector3 &to_pos, const CollideMask &mask)
21  : btCollisionWorld::ClosestRayResultCallback(from_pos, to_pos), _mask(mask) {
22 
23  _shapePart = -1;
24  _triangleIndex = -1;
25 }
26 
27 /**
28  * Override default implementation.
29  */
31 needsCollision(btBroadphaseProxy* proxy0) const {
32 
33  btCollisionObject *obj0 = (btCollisionObject *) proxy0->m_clientObject;
34  PandaNode *node0 = (PandaNode *) obj0->getUserPointer();
35  CollideMask mask0 = node0->get_into_collide_mask();
36 
37  return (_mask & mask0) != 0;
38 }
39 
40 /**
41  * Override default implementation.
42  */
44 addSingleResult(btCollisionWorld::LocalRayResult& rayResult, bool normalInWorldSpace) {
45 
46  // Store partindex information
47  if (rayResult.m_localShapeInfo) {
48  _shapePart = rayResult.m_localShapeInfo->m_shapePart;
49  _triangleIndex = rayResult.m_localShapeInfo->m_triangleIndex;
50  }
51 
52  // Call the default implementation
53  return btCollisionWorld::ClosestRayResultCallback::addSingleResult(rayResult, normalInWorldSpace);
54 };
55 
56 /**
57  *
58  */
59 bool BulletClosestHitRayResult::
60 has_hit() const {
61 
62  return hasHit();
63 }
64 
65 /**
66  *
67  */
68 PN_stdfloat BulletClosestHitRayResult::
69 get_hit_fraction() const {
70 
71  return (PN_stdfloat)m_closestHitFraction;
72 }
73 
74 /**
75  *
76  */
77 PandaNode *BulletClosestHitRayResult::
78 get_node() const {
79 
80  const btCollisionObject *objectPtr = m_collisionObject;
81  return (objectPtr) ? (PandaNode *)objectPtr->getUserPointer() : nullptr;
82 }
83 
84 /**
85  *
86  */
87 LPoint3 BulletClosestHitRayResult::
88 get_hit_pos() const {
89 
90  return btVector3_to_LPoint3(m_hitPointWorld);
91 }
92 
93 /**
94  *
95  */
96 LVector3 BulletClosestHitRayResult::
97 get_hit_normal() const {
98 
99  return btVector3_to_LVector3(m_hitNormalWorld);
100 }
101 
102 /**
103  *
104  */
105 LPoint3 BulletClosestHitRayResult::
106 get_from_pos() const {
107 
108  return btVector3_to_LPoint3(m_rayFromWorld);
109 }
110 
111 /**
112  *
113  */
114 LPoint3 BulletClosestHitRayResult::
115 get_to_pos() const {
116 
117  return btVector3_to_LPoint3(m_rayToWorld);
118 }
119 
120 /**
121  *
122  */
123 int BulletClosestHitRayResult::
124 get_shape_part() const {
125 
126  return _shapePart;
127 }
128 
129 /**
130  *
131  */
132 int BulletClosestHitRayResult::
133 get_triangle_index() const {
134 
135  return _triangleIndex;
136 }
A basic node of the scene graph or data graph.
Definition: pandaNode.h:64
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
virtual bool needsCollision(btBroadphaseProxy *proxy0) const
Override default implementation.
virtual btScalar addSingleResult(btCollisionWorld::LocalRayResult &rayResult, bool normalInWorldSpace)
Override default implementation.
A general bitmask class.
Definition: bitMask.h:32