Hey everyone.
I played with irrBullet quite a while ago and now it's time to fully integrate it into my project.
Similar to quite some users I'm facing a problem with adding my terrain scene node to the physics simulation. The scene node is correctly added to the sim world but other objects still pass through it.
Here's my approach:
From the terrain scene node's nature, it's not possible to get its standard IMesh but a mesh buffer from an arbitrary LOD. Hence I extended
ITriangleMeshShape's functionality to also accept IMeshBuffers as a parameter as ITMS basically works on the mesh buffers of IMesh.
Code: Select all
void IBvhTriangleMeshShape::createShape(IMeshBuffer *meshBuffer)
{
btBvhTriangleMeshShape* bvhShape = new btBvhTriangleMeshShape(getTriangleMeshFromBuffer(meshBuffer), false, true);
shape = bvhShape;
calculateLocalInertia(getMass(), vector3df(0.0f,0.0f,0.0f));
}
On my side of the action, I use the following code to add terrain to the physics simulation:
Code: Select all
void OFLPhysics::addTerrain(scene::ITerrainSceneNode* terrain)
{
OFLPhysics* inst = getInstance();
scene::CDynamicMeshBuffer buf(irr::video::EVT_STANDARD,irr::video::EIT_16BIT);
terrain->getMeshBufferForLOD(buf, 0);
ICollisionShape* terrShape = new IBvhTriangleMeshShape(terrain, &buf, 0.f);
terrShape->setMargin(.5f);
IRigidBody* terrBody = inst->bWorld->addRigidBody(terrShape);
terrBody->setCollisionFlags(ECF_STATIC_OBJECT);
}
Obviously, it fills a MeshBuffer object with data for a given LOD step which is then used to create bullet's representation of it.
Note that debugging shows the correct (similar) values as for verts- and triangle count.
Hence the questions are:
- Am I doing smth wrong?
- Am I missing smth?
All the other stuff collides as it should so I'm quite sure the sim is correctly set up.
Help greatly appreciated,
![Wink ;)](./images/smilies/icon_wink.gif)
p.