mirror of
https://github.com/panda3d/panda3d.git
synced 2025-10-02 09:52:27 -04:00
Added part info to Bullet raycast results.
This commit is contained in:
parent
cc79e24c6c
commit
bfac6fa6be
@ -33,11 +33,6 @@ BulletAllHitsRayResult(const btVector3 &from_pos, const btVector3 &to_pos, const
|
||||
bool BulletAllHitsRayResult::
|
||||
needsCollision(btBroadphaseProxy* proxy0) const {
|
||||
|
||||
// Original implementation:
|
||||
//bool collides = (proxy0->m_collisionFilterGroup & m_collisionFilterMask) != 0;
|
||||
//collides = collides && (m_collisionFilterGroup & proxy0->m_collisionFilterMask);
|
||||
//return collides;
|
||||
|
||||
btCollisionObject *obj0 = (btCollisionObject *) proxy0->m_clientObject;
|
||||
PandaNode *node0 = (PandaNode *) obj0->getUserPointer();
|
||||
CollideMask mask0 = node0->get_into_collide_mask();
|
||||
@ -45,6 +40,28 @@ needsCollision(btBroadphaseProxy* proxy0) const {
|
||||
return (_mask & mask0) != 0;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: BulletAllHitsRayResult::addSingleResult
|
||||
// Access: Protected
|
||||
// Description: Override default implementation.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
btScalar BulletAllHitsRayResult::
|
||||
addSingleResult(btCollisionWorld::LocalRayResult& rayResult, bool normalInWorldSpace) {
|
||||
|
||||
// Store part/index information
|
||||
if (rayResult.m_localShapeInfo) {
|
||||
_shapePart.push_back(rayResult.m_localShapeInfo->m_shapePart);
|
||||
_triangleIndex.push_back(rayResult.m_localShapeInfo->m_triangleIndex);
|
||||
}
|
||||
else {
|
||||
_shapePart.push_back(-1);
|
||||
_triangleIndex.push_back(-1);
|
||||
}
|
||||
|
||||
// Call the default implementation
|
||||
return btCollisionWorld::AllHitsRayResultCallback::addSingleResult(rayResult, normalInWorldSpace);
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: BulletAllHitsRayResult::get_from_pos
|
||||
// Access: Published
|
||||
@ -117,6 +134,9 @@ get_hit(int idx) const {
|
||||
hit._pos = m_hitPointWorld[idx];
|
||||
hit._fraction = m_hitFractions[idx];
|
||||
|
||||
hit._shapePart = _shapePart[idx];
|
||||
hit._triangleIndex = _triangleIndex[idx];
|
||||
|
||||
return hit;
|
||||
}
|
||||
|
||||
@ -164,3 +184,25 @@ get_hit_normal() const {
|
||||
return btVector3_to_LVector3(_normal);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: BulletRayHit::get_shape_part
|
||||
// Access: Published
|
||||
// Description:
|
||||
////////////////////////////////////////////////////////////////////
|
||||
int BulletRayHit::
|
||||
get_shape_part() const {
|
||||
|
||||
return _shapePart;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: BulletRayHit::get_triangle_index
|
||||
// Access: Published
|
||||
// Description:
|
||||
////////////////////////////////////////////////////////////////////
|
||||
int BulletRayHit::
|
||||
get_triangle_index() const {
|
||||
|
||||
return _triangleIndex;
|
||||
}
|
||||
|
||||
|
@ -38,12 +38,18 @@ PUBLISHED:
|
||||
LVector3 get_hit_normal() const;
|
||||
PN_stdfloat get_hit_fraction() const;
|
||||
|
||||
int get_shape_part() const;
|
||||
int get_triangle_index() const;
|
||||
|
||||
private:
|
||||
const btCollisionObject *_object;
|
||||
btVector3 _normal;
|
||||
btVector3 _pos;
|
||||
btScalar _fraction;
|
||||
|
||||
int _shapePart;
|
||||
int _triangleIndex;
|
||||
|
||||
friend struct BulletAllHitsRayResult;
|
||||
};
|
||||
|
||||
@ -68,12 +74,16 @@ PUBLISHED:
|
||||
|
||||
public:
|
||||
virtual bool needsCollision(btBroadphaseProxy* proxy0) const;
|
||||
virtual btScalar addSingleResult(btCollisionWorld::LocalRayResult& rayResult, bool normalInWorldSpace);
|
||||
|
||||
private:
|
||||
BulletAllHitsRayResult(const btVector3 &from_pos, const btVector3 &to_pos, const CollideMask &mask);
|
||||
|
||||
CollideMask _mask;
|
||||
|
||||
btAlignedObjectArray<int> _shapePart;
|
||||
btAlignedObjectArray<int> _triangleIndex;
|
||||
|
||||
friend class BulletWorld;
|
||||
};
|
||||
|
||||
|
@ -23,6 +23,8 @@ BulletClosestHitRayResult::
|
||||
BulletClosestHitRayResult(const btVector3 &from_pos, const btVector3 &to_pos, const CollideMask &mask)
|
||||
: btCollisionWorld::ClosestRayResultCallback(from_pos, to_pos), _mask(mask) {
|
||||
|
||||
_shapePart = -1;
|
||||
_triangleIndex = -1;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
@ -33,11 +35,6 @@ BulletClosestHitRayResult(const btVector3 &from_pos, const btVector3 &to_pos, co
|
||||
bool BulletClosestHitRayResult::
|
||||
needsCollision(btBroadphaseProxy* proxy0) const {
|
||||
|
||||
// Original implementation:
|
||||
//bool collides = (proxy0->m_collisionFilterGroup & m_collisionFilterMask) != 0;
|
||||
//collides = collides && (m_collisionFilterGroup & proxy0->m_collisionFilterMask);
|
||||
//return collides;
|
||||
|
||||
btCollisionObject *obj0 = (btCollisionObject *) proxy0->m_clientObject;
|
||||
PandaNode *node0 = (PandaNode *) obj0->getUserPointer();
|
||||
CollideMask mask0 = node0->get_into_collide_mask();
|
||||
@ -45,6 +42,24 @@ needsCollision(btBroadphaseProxy* proxy0) const {
|
||||
return (_mask & mask0) != 0;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: BulletAllHitsRayResult::addSingleResult
|
||||
// Access: Protected
|
||||
// Description: Override default implementation.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
btScalar BulletClosestHitRayResult::
|
||||
addSingleResult(btCollisionWorld::LocalRayResult& rayResult, bool normalInWorldSpace) {
|
||||
|
||||
// Store part/index information
|
||||
if (rayResult.m_localShapeInfo) {
|
||||
_shapePart = rayResult.m_localShapeInfo->m_shapePart;
|
||||
_triangleIndex = rayResult.m_localShapeInfo->m_triangleIndex;
|
||||
}
|
||||
|
||||
// Call the default implementation
|
||||
return btCollisionWorld::ClosestRayResultCallback::addSingleResult(rayResult, normalInWorldSpace);
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: BulletClosestHitRayResult::has_hit
|
||||
// Access: Published
|
||||
@ -123,3 +138,25 @@ get_to_pos() const {
|
||||
return btVector3_to_LPoint3(m_rayToWorld);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: BulletClosestHitRayResult::get_shape_part
|
||||
// Access: Published
|
||||
// Description:
|
||||
////////////////////////////////////////////////////////////////////
|
||||
int BulletClosestHitRayResult::
|
||||
get_shape_part() const {
|
||||
|
||||
return _shapePart;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: BulletClosestHitRayResult::get_triangle_index
|
||||
// Access: Published
|
||||
// Description:
|
||||
////////////////////////////////////////////////////////////////////
|
||||
int BulletClosestHitRayResult::
|
||||
get_triangle_index() const {
|
||||
|
||||
return _triangleIndex;
|
||||
}
|
||||
|
||||
|
@ -43,14 +43,21 @@ PUBLISHED:
|
||||
LVector3 get_hit_normal() const;
|
||||
PN_stdfloat get_hit_fraction() const;
|
||||
|
||||
int get_shape_part() const;
|
||||
int get_triangle_index() const;
|
||||
|
||||
public:
|
||||
virtual bool needsCollision(btBroadphaseProxy* proxy0) const;
|
||||
virtual btScalar addSingleResult(btCollisionWorld::LocalRayResult& rayResult, bool normalInWorldSpace);
|
||||
|
||||
private:
|
||||
BulletClosestHitRayResult(const btVector3 &from_pos, const btVector3 &to_pos, const CollideMask &mask);
|
||||
|
||||
CollideMask _mask;
|
||||
|
||||
int _shapePart;
|
||||
int _triangleIndex;
|
||||
|
||||
friend class BulletWorld;
|
||||
};
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user