Panda3D
bulletClosestHitRayResult.cxx
1 // Filename: bulletClosestHitRayResult.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 "bulletClosestHitRayResult.h"
16 
17 ////////////////////////////////////////////////////////////////////
18 // Function: BulletClosestHitRayResult::Constructor
19 // Access: Protected
20 // Description:
21 ////////////////////////////////////////////////////////////////////
22 BulletClosestHitRayResult::
23 BulletClosestHitRayResult(const btVector3 &from_pos, const btVector3 &to_pos, const CollideMask &mask)
24  : btCollisionWorld::ClosestRayResultCallback(from_pos, to_pos), _mask(mask) {
25 
26  _shapePart = -1;
27  _triangleIndex = -1;
28 }
29 
30 ////////////////////////////////////////////////////////////////////
31 // Function: BulletClosestHitRayResult::needsCollision
32 // Access: Protected
33 // Description: Override default implementation.
34 ////////////////////////////////////////////////////////////////////
36 needsCollision(btBroadphaseProxy* proxy0) const {
37 
38  btCollisionObject *obj0 = (btCollisionObject *) proxy0->m_clientObject;
39  PandaNode *node0 = (PandaNode *) obj0->getUserPointer();
40  CollideMask mask0 = node0->get_into_collide_mask();
41 
42  return (_mask & mask0) != 0;
43 }
44 
45 ////////////////////////////////////////////////////////////////////
46 // Function: BulletAllHitsRayResult::addSingleResult
47 // Access: Protected
48 // Description: Override default implementation.
49 ////////////////////////////////////////////////////////////////////
51 addSingleResult(btCollisionWorld::LocalRayResult& rayResult, bool normalInWorldSpace) {
52 
53  // Store part/index information
54  if (rayResult.m_localShapeInfo) {
55  _shapePart = rayResult.m_localShapeInfo->m_shapePart;
56  _triangleIndex = rayResult.m_localShapeInfo->m_triangleIndex;
57  }
58 
59  // Call the default implementation
60  return btCollisionWorld::ClosestRayResultCallback::addSingleResult(rayResult, normalInWorldSpace);
61 };
62 
63 ////////////////////////////////////////////////////////////////////
64 // Function: BulletClosestHitRayResult::has_hit
65 // Access: Published
66 // Description:
67 ////////////////////////////////////////////////////////////////////
68 bool BulletClosestHitRayResult::
69 has_hit() const {
70 
71  return hasHit();
72 }
73 
74 ////////////////////////////////////////////////////////////////////
75 // Function: BulletClosestHitRayResult::get_hit_fraction
76 // Access: Published
77 // Description:
78 ////////////////////////////////////////////////////////////////////
79 PN_stdfloat BulletClosestHitRayResult::
80 get_hit_fraction() const {
81 
82  return (PN_stdfloat)m_closestHitFraction;
83 }
84 
85 ////////////////////////////////////////////////////////////////////
86 // Function: BulletClosestHitRayResult::get_node
87 // Access: Published
88 // Description:
89 ////////////////////////////////////////////////////////////////////
90 const PandaNode *BulletClosestHitRayResult::
91 get_node() const {
92 
93  const btCollisionObject *objectPtr = m_collisionObject;
94  return (objectPtr) ? (const PandaNode *)objectPtr->getUserPointer() : NULL;
95 }
96 
97 ////////////////////////////////////////////////////////////////////
98 // Function: BulletClosestHitRayResult::get_hit_pos
99 // Access: Published
100 // Description:
101 ////////////////////////////////////////////////////////////////////
102 LPoint3 BulletClosestHitRayResult::
103 get_hit_pos() const {
104 
105  return btVector3_to_LPoint3(m_hitPointWorld);
106 }
107 
108 ////////////////////////////////////////////////////////////////////
109 // Function: BulletClosestHitRayResult::get_hit_normal
110 // Access: Published
111 // Description:
112 ////////////////////////////////////////////////////////////////////
113 LVector3 BulletClosestHitRayResult::
114 get_hit_normal() const {
115 
116  return btVector3_to_LVector3(m_hitNormalWorld);
117 }
118 
119 ////////////////////////////////////////////////////////////////////
120 // Function: BulletClosestHitRayResult::get_from_pos
121 // Access: Published
122 // Description:
123 ////////////////////////////////////////////////////////////////////
124 LPoint3 BulletClosestHitRayResult::
125 get_from_pos() const {
126 
127  return btVector3_to_LPoint3(m_rayFromWorld);
128 }
129 
130 ////////////////////////////////////////////////////////////////////
131 // Function: BulletClosestHitRayResult::get_to_pos
132 // Access: Published
133 // Description:
134 ////////////////////////////////////////////////////////////////////
135 LPoint3 BulletClosestHitRayResult::
136 get_to_pos() const {
137 
138  return btVector3_to_LPoint3(m_rayToWorld);
139 }
140 
141 ////////////////////////////////////////////////////////////////////
142 // Function: BulletClosestHitRayResult::get_shape_part
143 // Access: Published
144 // Description:
145 ////////////////////////////////////////////////////////////////////
146 int BulletClosestHitRayResult::
147 get_shape_part() const {
148 
149  return _shapePart;
150 }
151 
152 ////////////////////////////////////////////////////////////////////
153 // Function: BulletClosestHitRayResult::get_triangle_index
154 // Access: Published
155 // Description:
156 ////////////////////////////////////////////////////////////////////
157 int BulletClosestHitRayResult::
158 get_triangle_index() const {
159 
160  return _triangleIndex;
161 }
162 
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 bool needsCollision(btBroadphaseProxy *proxy0) const
Override default implementation.
virtual btScalar addSingleResult(btCollisionWorld::LocalRayResult &rayResult, bool normalInWorldSpace)
Override default implementation.