0
\$\begingroup\$

I am creating a game using PhysX as the physics engine and I have a function which checks the overlapped bodies based on a sphere geometry. When there are overlapping bodies I just set a force on them. The problem is that the overlap function always return false. No matter what I feed it with. Here is my code:

void PhysxManager::ExplosionSphere(const glm::vec3& pos, float radius, float _force) { PxOverlapBuffer hit; // [out] Overlap results PxSphereGeometry overlapShape = PxSphereGeometry(radius); // [in] shape to test for overlaps PxTransform shapePose = PxTransform(PxVec3(pos.x, pos.y, pos.z)); // [in] initial shape pose (at distance=0) if (mScene->overlap(overlapShape, shapePose, hit, PxSceneQueryFilterData(PxQueryFlag::eNO_BLOCK))) { for (int i = 0; i < hit.nbTouches; ++i) { auto actor = dynamic_cast<physx::PxRigidDynamic*>(hit.touches[i].actor); if (actor) { PxVec3 force = (actor->getGlobalPose().p - PxVec3(pos.x, pos.y, pos.z)); actor->addForce(force * _force); } } } } 

Any ideas what might be the problem or maybe an alternative to overlap?

\$\endgroup\$

1 Answer 1

1
\$\begingroup\$

I couldn't get it to work as mentioned above. Instead I made it to work as I wanted using

PxSceneQueryExt::overlapMultiple

This was suggested by NVidia on their forums as an alternative. Note that I wanted to work with multiple objects in the query.

I used it like this :

PxSphereGeometry overlapShape = PxSphereGeometry(radius); // [in] shape to test for overlaps PxTransform shapePose = PxTransform(PxVec3(pos.x, pos.y, pos.z), PxQuat(physx::PxHalfPi, physx::PxVec3(0.0f, 0.0f, 1.0f))); // [in] initial shape pose (at distance=0) std::unique_ptr<PxOverlapHit[]> hitOv = std::make_unique<PxOverlapHit[]>(4096); int howMany = PxSceneQueryExt::overlapMultiple(*mScene, overlapShape, shapePose, hitOv.get(), 4096, PxQueryFilterData(PxQueryFlag::eSTATIC | PxQueryFlag::eDYNAMIC | PxQueryFlag::eNO_BLOCK)); 
\$\endgroup\$
0

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.