Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

I have a terrain that can not be represented as height map. Say a mountain with caves. I have it in one large .obj file. How do I load such a terrain into bullet-phisics engine?

Or I shall generate height map, load it as a terrain and then load my caves as a seprate obj file somehow cutting it out from generated terrain?

share|improve this question
add comment

2 Answers

See my answer to a similar question I asked. Basically one option (that worked well for me) is to implement your own collision listener into Bullet Physics. All you really need to start is a function of your own that tells you whether a specific point in your world is solid. Then as you can see in my answer, you'll just need to override a few objects, and you're done. Most of the code can be copied from the original terrain collision listener, then slightly modified for your game. This is a fairly powerful way to get collision handling working, but it might not be the simplest.

share|improve this answer
    
Wount I loose in speed and performance If I woul use my terrain Impl instead of Bullets one? –  myWallJSON Jun 8 '12 at 11:31
    
That's possible, but you have to realize that you're attempting to do something more complex than what bullet offers. With increased complexity comes decreased performance. I still get excellent performance with collision detection in my game. You won't know until you try. –  Byte56 Jun 8 '12 at 14:23
add comment

Bullet does support arbitrary meshes; I'm sure Byte56's answer will work but you'll definitely be doing more work than you need to and it'll perform worse than Bullet's built-in solution.

Have a look at the btBvhTriangleMeshShape and btTriangleIndexVertexArray classes; you'll need to load in your obj file to get its vertices and indices, create a btTriangleIndexVertexArray containing those, then create a btBvhTriangleMeshShape from this. That'll give you the collision shape, then it's just a case of attaching that to a rigid body.

Here are Bullet's reference pages for the two classes; there should be enough google fuel in there for you!

http://bulletphysics.com/Bullet/BulletFull/classbtBvhTriangleMeshShape.html

http://bulletphysics.com/Bullet/BulletFull/classbtTriangleIndexVertexArray.html

Bear in mind that Bullet makes it hard to figure out who owns what memory; in this case it expects you to manage both the btTriangleIndexVertexArray you pass into the shape, and the vertex and index arrays you pass to that; it won't take a copy or take ownership of those pointers. So either keep them around as values on the stack or as class members, or make sure to keep hold of the pointers and delete them in the correct order.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.