Avoid ground collision with Bullet

后端 未结 2 368
一生所求
一生所求 2020-12-13 17:14

I\'m trying to use Bullet physic engine to create a 3D world.

I\'ve got my character with a Capsule shape on his body and my ground his made of some static blocs sti

2条回答
  •  余生分开走
    2020-12-13 17:39

    Your problem caller "Internal Edge Collision". I just found the solution few our hour ago. If you are using btHeightfieldTerrainShapefor your world then you must use btBvhTriangleMeshShape to slove this problem.

    Here is the answer.

    Add this callback:

    static bool CustomMaterialCombinerCallback(btManifoldPoint& cp,const btCollisionObject* colObj0,int partId0,int index0,const btCollisionObject* colObj1,int partId1,int index1)
    {
       btAdjustInternalEdgeContacts(cp,colObj1,colObj0, partId1,index1);
       return true;
    }
    
    extern ContactAddedCallback gContactAddedCallback;
    

    Afterwards create the btBvhTriangleMeshShape and add this code where pGround is your btBvhTriangleMeshShape:

    // Enable custom material callback
    pGround->setCollisionFlags(pGround->getCollisionFlags() | btCollisionObject::CF_CUSTOM_MATERIAL_CALLBACK);
    
    btTriangleInfoMap* triangleInfoMap = new btTriangleInfoMap();
    btGenerateInternalEdgeInfo(pGroundShape, triangleInfoMap);
    

    Or you can open the InternalEdgeDemo example in Bullet to see how to implement it in detail.

提交回复
热议问题