0
\$\begingroup\$

enter image description here

I'm trying the collision detection example in SampleSubmarine and I'm having a problem.

As shown in the picture, when Plane and Sphere collide, the break is made at int a = 10 of the onContact function, but the break is applied here even though there has not been a collision yet.

The size of the shape and the size of the drawn sphere are the same, but I do not know why it was before the collision.

If you don't know, I'll attach the code as well.

this is for filtershader

 PxFilterFlags SampleSubmarineFilterShader( PxFilterObjectAttributes attributes0, PxFilterData filterData0, PxFilterObjectAttributes attributes1, PxFilterData filterData1, PxPairFlags& pairFlags, const void* constantBlock, PxU32 constantBlockSize) { // let triggers through if (PxFilterObjectIsTrigger(attributes0) || PxFilterObjectIsTrigger(attributes1)) { pairFlags = PxPairFlag::eTRIGGER_DEFAULT; return PxFilterFlag::eDEFAULT; } // generate contacts for all that were not filtered above pairFlags = PxPairFlag::eCONTACT_DEFAULT; // trigger the contact callback for pairs (A,B) where // the filtermask of A contains the ID of B and vice versa. if ((filterData0.word0 & filterData1.word1) && (filterData1.word0 & filterData0.word1)) pairFlags |= PxPairFlag::eNOTIFY_TOUCH_FOUND; return PxFilterFlag::eDEFAULT; } 

this is for PxSimulationEventCallback

 class ContactCallBack : public PxSimulationEventCallback { // PxSimulationEventCallback을(를) 통해 상속됨 virtual void onConstraintBreak(PxConstraintInfo * constraints, PxU32 count) override; virtual void onWake(PxActor ** actors, PxU32 count) override; virtual void onSleep(PxActor ** actors, PxU32 count) override; virtual void onContact(const PxContactPairHeader & pairHeader, const PxContactPair * pairs, PxU32 nbPairs) override; virtual void onTrigger(PxTriggerPair * pairs, PxU32 count) override; virtual void onAdvance(const PxRigidBody * const * bodyBuffer, const PxTransform * poseBuffer, const PxU32 count) override; }; 

this is for plane

 HRESULT PhysXManager::CreateSimulation() { material = physics->createMaterial(0.5f, 0.5f, 0.1f); auto groundPlane = PxCreatePlane(*physics, PxPlane(0, 1, 0, 1), *material); SetupFiltering(groundPlane, FilterGroup::eHEIGHTFIELD, FilterGroup::eSUBMARINE); scene->addActor(*groundPlane); return S_OK; } 

this is for sphere

 HRESULT ColliderRenderer::CreateBuffer(PxGeometryType::Enum _geoType) { switch (_geoType) { case physx::PxGeometryType::eSPHERE: GeometricPrimitive::CreateSphere(vertices, indices, 10, 8, false); // 3rd parameter is diameter break; .... } ..... } 

this is for shape

 PxShape* Collider::AddCollider() { ColliderDesc desc; desc.scale = Vector3(5.f, 5.f, 5.f); desc.radius = 5.f; desc.halfHeight = 10.f; return PhysXManager::GetInstance()->AddCollider(geoType, desc); } PxShape* PhysXManager::AddCollider(PxGeometryType::Enum _type, ColliderDesc _desc) { PxShape* shape = nullptr; switch (_type) { case physx::PxGeometryType::eSPHERE: shape = physics->createShape(PxSphereGeometry(PxReal(_desc.radius)), *material, true); break; ... } return shape; } 

Spheres and spheres, as well as collisions with spheres and planes, break before shapes collide. Does anyone know about this?

loop code

while (TRUE) { if (PeekMessage(&msg, nullptr, 0, 0, PM_REMOVE)) { TranslateMessage(&msg); DispatchMessage(&msg); } FrameTimeDefault += TimeMgr->ComputeTimer(L"Timer_Default"); if (1.f / 60.f <= FrameTimeDefault) { physxManager->RunSimulate(); mainApp->Update(TimeMgr->ComputeTimer(L"Timer_60")); mainApp->Render(); FrameTimeDefault = 0.f; } } 

this is for simulation code

void PhysXManager::RunSimulate() { scene->simulate(1.f / 60.f); scene->fetchResults(true); } 
\$\endgroup\$
6
  • \$\begingroup\$ Are you sure that you're not drawing the frame before the collision is detected? I.e. in the game loop, you'd first do the collision detection/resolution/step, only then you would draw the result of the step. \$\endgroup\$ Commented Dec 11, 2021 at 2:06
  • \$\begingroup\$ Do you mean it is because the difference between physics simulation and drawing because of the frame? i edited my loop code \$\endgroup\$ Commented Dec 11, 2021 at 2:29
  • \$\begingroup\$ Yes, the simulation occurs before it is rendered. When you get to the first breakpoint, then add another breakpoint at FrameTimeDefault = 0.f;; if you're lucky, you'll see the two surfaces touch (otherwise, the ball will have bounced off of the plane already). \$\endgroup\$ Commented Dec 11, 2021 at 3:15
  • \$\begingroup\$ Mainapp->update() and mainapp->render() are executed every 60 frames, and simulation is also executed every 60 frames. Why are they different? \$\endgroup\$ Commented Dec 11, 2021 at 3:59
  • \$\begingroup\$ There was no collision in the view in the physx visual debugger. \$\endgroup\$ Commented Dec 11, 2021 at 5:42

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.