I have a btBvhTriangleMeshShape that I've created which is a square made up of 18 triangles forming a 3x3 grid centered around the player. The (x,z) values are set to create this grid. The y-values are set to 0.0f.
Each frame, I change the 18 y-values to reflect heights taken from the correct part of the correct heightmap.
Once I change this mesh such that the y-values reference different rows/columns in the heightmap than when the mesh was originally created, the character controller stops colliding with it and falls through the dynamics world.
Each frame I have started called btBvhTriangleMeshShape::buildOptimizedBvh() right before I remove the rigid body from last frame and re-insert the same rigid body as the current frame's rigid body. For certain flat parts of the terrain this works OK, but once the 3x3 grid starts describing a sloped surface, the character controller once again falls through. The debug drawer shows that the "box" around the mesh is just a flat-plane that doesn't take on the height of the mesh.
Can anyone suggest how I should correctly tell Bullet that I have changed some underlying vertex data in the btBvhTriangeMeshShape and that it needs to recompute its internal structures so I can continue colliding against this mesh as a rigid body?
Using btBvhTriangleMeshShape for terrain
-
SteveSegreto
- Posts: 32
- Joined: Sun Sep 12, 2010 10:25 am
-
SteveSegreto
- Posts: 32
- Joined: Sun Sep 12, 2010 10:25 am
Re: Using btBvhTriangleMeshShape for terrain
I was able to achieve the desired results using a btHeightfieldTerrainShape and providing it with a pointer to float heights for the applicable portion of my terrain. The terraindemo didn't generate a Visual Studio project when I first ran the script to generate the demos, so I didn't try the demo until later. After trying the demo out I realized it was suitable for my problem described above.