Collision detection with a complex mesh
Members - Reputation: 106
Posted 28 November 2012 - 03:56 PM
I'm currently struggling with the implementation for collision detection for the rooms in my game. The problem is that the rooms are a single mesh loaded from an .x file, and come in different shapes and sizes, so creating a single bounding box over the entire room isn't sufficient. Ideally I would like to create a bounding box on each wall in the room, but I'm not sure if that is possible. Is there a way to somehow read each wall into a separate mesh? Or is there a better way to implement the collision detection with a single room mesh? Thanks for any help.
Members - Reputation: 936
Posted 29 November 2012 - 12:33 AM
Rather than bounding box for each wall, I would choose a polygonal surface, or a planar surface if the walls are not complex / convex, that would be a faster computation wouldn't it. But you might prefer a slightly slower but more general function, such as bounding box, especially if all your walls are orthogonal. Im assuming your problem is trying to differentiate each wall in the mesh in order to fit the bounding box.
It may very much depend on what your geometry is like. And is this your own physics engine ?
Just some thoughts anyway. I have mostly worked on 2d physics, so I can't really offer much more than suggestions and discussion about how to tackle 3d physics.
Crossbones+ - Reputation: 4948
Posted 29 November 2012 - 04:45 AM
Don't even think about taking your graphics assets and dumping them to collision routines. They'll often fail in at least one of two cases
- Performance wise, they contain way more triangles than enough for CD. This results in worse performance and often decreased simulation quality.
But hey, I bet your game is simple enough and perhaps you're running this on i7 so you could do that anyway.
- Gameplay wise, not all meshes are solid.
If you're tempted to add the appropriate switches, you'll end up messing up your mesh representation with physics data. It will only end up in tears.
So, decoupling graphics from physics appears the way to go.
I can tell my code improved a lot since I did so and I strongly suggest to do the same.
As a side note, don't even try doing CD for an arbitrary mesh. Use a library such as Gimpact if you want to be "low level" or even better, use Bullet, which packs it in for you with plenty of other features.