使用图层进行碰撞过滤(PhysX 3.4)

时间:2018-04-11 08:27:59

标签: c++ sdk collision layer physx

我想用Unity中的层来过滤我的碰撞,但我真的不明白怎么做。我正在学习本教程:http://docs.nvidia.com/gameworks/content/gameworkslibrary/physx/guide/Manual/RigidBodyCollision.html#collision-filtering

我想要做的就是禁用具有图层立方体和平面的对象之间的碰撞...

Graph.cpp:

bool Graph::Init()
{
/*...*/

cubeCollider->SetLayer(Physics::PhysicLayer::Cube);
planeCollider->SetLayer(Physics::PhysicLayer::Plane);
sphereCollider->SetLayer(Physics::PhysicLayer::Sphere);
capsuleCollider->SetLayer(Physics::PhysicLayer::Capsule);

_physX->SetCollisionFiltering(Physics::PhysicLayer::Cube, Physics::PhysicLayer::Plane);

/*...*/
}

以下是我设置滤镜着色器的方法:

PhysX.cpp:

void PhysX::SetCollisionFiltering(PhysicLayer p_one, PhysicLayer p_two)
{
 // I don't really know what to do here...

PxFilterData filterData;

filterData.word0 =  p_one;
filterData.word1 =  p_two;

// no collision between objects with layer ONE and objects with layer TWO ? 
for (unsigned int i = 0; i < _colliders.size(); ++i)
{
    if (_colliders[i]->GetLayer() == p_one || _colliders[i]->GetLayer() == p_two)
        _colliders[i]->GetShape()->setSimulationFilterData(filterData);
}
}

physx::PxFilterFlags CreateFilterShader(PxFilterObjectAttributes p_attributes0, PxFilterData p_filterData0, 
                                    PxFilterObjectAttributes p_attributes1, PxFilterData p_filterData1, 
                                    PxPairFlags& p_pairFlags, const void* p_constantBlock, PxU32 constantBlockSize)

{
    // Trigger
if (PxFilterObjectIsTrigger(p_attributes0) || PxFilterObjectIsTrigger(p_attributes1))
{
    p_pairFlags = PxPairFlag::eDETECT_DISCRETE_CONTACT
        | PxPairFlag::eSOLVE_CONTACT
        | PxPairFlag::eNOTIFY_TOUCH_FOUND
        | PxPairFlag::eNOTIFY_TOUCH_LOST;
}
    // Normal Collision
else
{
            //  Not sure
    if ((p_filterData0.word0 & p_filterData1.word1) && (p_filterData1.word0 & p_filterData0.word1))
    {
        p_pairFlags = PxPairFlag::eDETECT_DISCRETE_CONTACT
            | PxPairFlag::eSOLVE_CONTACT
            | PxPairFlag::eNOTIFY_CONTACT_POINTS
            | PxPairFlag::eNOTIFY_THRESHOLD_FORCE_FOUND
            | PxPairFlag::eNOTIFY_THRESHOLD_FORCE_LOST
            | PxPairFlag::eNOTIFY_THRESHOLD_FORCE_PERSISTS

            | PxPairFlag::eNOTIFY_TOUCH_FOUND
            | PxPairFlag::eNOTIFY_TOUCH_LOST
            | PxPairFlag::eNOTIFY_TOUCH_PERSISTS;
    }
}

return PxFilterFlag::eDEFAULT;
}

使用这段代码,我的对象都没有碰撞......我真的不明白什么是PxFilter.word0,word1 word2和word3 ......

提前致谢!

0 个答案:

没有答案