1
Physx Hadinitialoverlap
source link: http://pkxpp.github.io/2020/11/11/PhysX-hadInitialOverlap/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
[TOC]
在做碰撞检测的时候,返回结果一般用hasBlock就可以知道是否碰撞了,但是发现还有一个hadInitialOverlap的时候有点疑惑。这个是啥意思?干什么用的?
hasBlock和hadInitialOverlap
- hasBlock
在HitBuffer的PxHitCallback中
template<typename HitType>
struct PxHitCallback
{
HitType block; //!< Holds the closest blocking hit result for the query. Invalid if hasBlock is false.
bool hasBlock; //!< Set to true if there was a blocking hit during query.
HitType* touches; //!< User specified buffer for touching hits.
- hadInitialOverlap
在PxLocationHit结构体中
struct PxLocationHit : public PxQueryHit
{
PX_INLINE PxLocationHit() : flags(0), position(PxVec3(0)), normal(PxVec3(0)), distance(PX_MAX_REAL) {}
/**
\note For raycast hits: true for shapes overlapping with raycast origin.
\note For sweep hits: true for shapes overlapping at zero sweep distance.
@see PxRaycastHit PxSweepHit
*/
PX_INLINE bool hadInitialOverlap() const { return (distance <= 0.0f); }
拿Sweep测试,测试代码如下
PxSweepBuffer hitSweep;
PxSphereGeometry sweepShape = PxSphereGeometry(30);
PxHitFlags hitFlags = PxHitFlags(PxHitFlag::eDEFAULT);
PxQueryFilterData filterData = PxQueryFilterData(PxQueryFlag::eSTATIC);
status = gScene->sweep(sweepShape, t, unitDir, PxReal(0.0f), hitSweep, hitFlags, filterData);
bool bInitOverlap = hitSweep.block.hadInitialOverlap();
通过修改半径和Sweep距离来看其中情况
情况1:初始的时候没有发生碰撞,Sweep过程中也没有发生碰撞
半径 = 30 距离 = 0
hitSweep.hasBlock = false
hitSweep.block.hadInitialOverlap() = false
情况2:初始的时候没有发生碰撞,Sweep过程中发生碰撞
半径 = 30 距离 = 100
hitSweep.hasBlock = true
hitSweep.block.hadInitialOverlap() = false
情况3:初始的时候发生碰撞,Sweep距离为0
半径 = 100 距离 = 0
hitSweep.hasBlock = true
hitSweep.block.hadInitialOverlap() = true
-
1.是否碰撞用hasBlock就可以了
-
2.有些需求如果想知道一开始就发生碰撞了的话,就用hadInitialOverlap。而且hasBlock也是生效的
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK