Panda3D
|
00001 // Filename: bulletAllHitsRayResult.cxx 00002 // Created by: enn0x (21Feb10) 00003 // 00004 //////////////////////////////////////////////////////////////////// 00005 // 00006 // PANDA 3D SOFTWARE 00007 // Copyright (c) Carnegie Mellon University. All rights reserved. 00008 // 00009 // All use of this software is subject to the terms of the revised BSD 00010 // license. You should have received a copy of this license along 00011 // with this source code in a file named "LICENSE." 00012 // 00013 //////////////////////////////////////////////////////////////////// 00014 00015 #include "bulletAllHitsRayResult.h" 00016 00017 //////////////////////////////////////////////////////////////////// 00018 // Function: BulletAllHitsRayResult::Constructor 00019 // Access: Protected 00020 // Description: 00021 //////////////////////////////////////////////////////////////////// 00022 BulletAllHitsRayResult:: 00023 BulletAllHitsRayResult(const btVector3 &from_pos, const btVector3 &to_pos, const CollideMask &mask) 00024 : btCollisionWorld::AllHitsRayResultCallback(from_pos, to_pos), _mask(mask) { 00025 00026 } 00027 00028 //////////////////////////////////////////////////////////////////// 00029 // Function: BulletAllHitsRayResult::needsCollision 00030 // Access: Protected 00031 // Description: Override default implementation. 00032 //////////////////////////////////////////////////////////////////// 00033 bool BulletAllHitsRayResult:: 00034 needsCollision(btBroadphaseProxy* proxy0) const { 00035 00036 // Original implementation: 00037 //bool collides = (proxy0->m_collisionFilterGroup & m_collisionFilterMask) != 0; 00038 //collides = collides && (m_collisionFilterGroup & proxy0->m_collisionFilterMask); 00039 //return collides; 00040 00041 btCollisionObject *obj0 = (btCollisionObject *) proxy0->m_clientObject; 00042 PandaNode *node0 = (PandaNode *) obj0->getUserPointer(); 00043 CollideMask mask0 = node0->get_into_collide_mask(); 00044 00045 return (_mask & mask0) != 0; 00046 } 00047 00048 //////////////////////////////////////////////////////////////////// 00049 // Function: BulletAllHitsRayResult::get_from_pos 00050 // Access: Published 00051 // Description: 00052 //////////////////////////////////////////////////////////////////// 00053 LPoint3 BulletAllHitsRayResult:: 00054 get_from_pos() const { 00055 00056 return btVector3_to_LPoint3(m_rayFromWorld); 00057 } 00058 00059 //////////////////////////////////////////////////////////////////// 00060 // Function: BulletAllHitsRayResult::get_to_pos 00061 // Access: Published 00062 // Description: 00063 //////////////////////////////////////////////////////////////////// 00064 LPoint3 BulletAllHitsRayResult:: 00065 get_to_pos() const { 00066 00067 return btVector3_to_LPoint3(m_rayToWorld); 00068 } 00069 00070 //////////////////////////////////////////////////////////////////// 00071 // Function: BulletAllHitsRayResult::has_hits 00072 // Access: Published 00073 // Description: 00074 //////////////////////////////////////////////////////////////////// 00075 bool BulletAllHitsRayResult:: 00076 has_hits() const { 00077 00078 return hasHit(); 00079 } 00080 00081 //////////////////////////////////////////////////////////////////// 00082 // Function: BulletAllHitsRayResult::get_closest_hit_fraction 00083 // Access: Published 00084 // Description: 00085 //////////////////////////////////////////////////////////////////// 00086 PN_stdfloat BulletAllHitsRayResult:: 00087 get_closest_hit_fraction() const { 00088 00089 return (PN_stdfloat)m_closestHitFraction; 00090 } 00091 00092 //////////////////////////////////////////////////////////////////// 00093 // Function: BulletAllHitsRayResult::get_num_hits 00094 // Access: Published 00095 // Description: 00096 //////////////////////////////////////////////////////////////////// 00097 int BulletAllHitsRayResult:: 00098 get_num_hits() const { 00099 00100 return m_collisionObjects.size(); 00101 } 00102 00103 //////////////////////////////////////////////////////////////////// 00104 // Function: BulletAllHitsRayResult::get_hit 00105 // Access: Published 00106 // Description: 00107 //////////////////////////////////////////////////////////////////// 00108 const BulletRayHit BulletAllHitsRayResult:: 00109 get_hit(int idx) const { 00110 00111 nassertr(idx >= 0 && idx < get_num_hits(), BulletRayHit::empty()); 00112 00113 BulletRayHit hit; 00114 00115 hit._object = m_collisionObjects[idx]; 00116 hit._normal = m_hitNormalWorld[idx]; 00117 hit._pos = m_hitPointWorld[idx]; 00118 hit._fraction = m_hitFractions[idx]; 00119 00120 return hit; 00121 } 00122 00123 //////////////////////////////////////////////////////////////////// 00124 // Function: BulletRayHit::get_hit_fraction 00125 // Access: Published 00126 // Description: 00127 //////////////////////////////////////////////////////////////////// 00128 PN_stdfloat BulletRayHit:: 00129 get_hit_fraction() const { 00130 00131 return (PN_stdfloat)_fraction; 00132 } 00133 00134 //////////////////////////////////////////////////////////////////// 00135 // Function: BulletRayHit::get_node 00136 // Access: Published 00137 // Description: 00138 //////////////////////////////////////////////////////////////////// 00139 PandaNode *BulletRayHit:: 00140 get_node() const { 00141 00142 return (_object) ? (PandaNode *)_object->getUserPointer() : NULL; 00143 } 00144 00145 //////////////////////////////////////////////////////////////////// 00146 // Function: BulletRayHit::get_hit_pos 00147 // Access: Published 00148 // Description: 00149 //////////////////////////////////////////////////////////////////// 00150 LPoint3 BulletRayHit:: 00151 get_hit_pos() const { 00152 00153 return btVector3_to_LPoint3(_pos); 00154 } 00155 00156 //////////////////////////////////////////////////////////////////// 00157 // Function: BulletRayHit::get_hit_normal 00158 // Access: Published 00159 // Description: 00160 //////////////////////////////////////////////////////////////////// 00161 LVector3 BulletRayHit:: 00162 get_hit_normal() const { 00163 00164 return btVector3_to_LVector3(_normal); 00165 } 00166