Collision with bitmaps

Topics: User Forum
Aug 12, 2008 at 1:01 PM
Hi. I'm working on a project where I have a number of bodies with polygonal geometries that need to be able to interact with bitmap scenery. Normally I'd go ahead with making a collision mesh for the scenery, but in this case it will not suffice as the scenery is effectively a large, deformable bitmap. Auto-generating a collision mesh on the fly seems intensely processor hungry, so my plan is to collision check body geometry directly against the pixels.

Now this is the awkward part. The bodies clearly need to behave as though they are colliding with a fixed point body in the Farseer model, but as actually modelling each pixel is every bit as unrealistic as making a damage mesh, I think I'm going to have to emulate it. Checking pixel collisions against the geometry should be relatively simple and I can presumably calculate the angle of incidence by taking a local sample of the bitmap and averaging out the edge somehow, but feeding this back into the body via force/impulse could prove a little trickier. Has anyone tried anything like this?

An alternative might be to predictively create temporary pixel bodies where a body is about to hit, but again I suspect this will hog processor time.
Aug 12, 2008 at 10:50 PM
Do you have a concept drawing of your game? It would make it easier to help you and come up with a solution.
Aug 15, 2008 at 10:19 AM
I thought I was close to a solution for this but there are still enough pitfalls left in my approach that I'd love to hear other views. I don't have any material to hand, unfortunately, as I am at work, but I could upload a screen of my test demo.

Level scenery is generally a series of large caves, so there are lots of concave surfaces. In addition to this, I am blasting circular holes in the scenery using a stencil map, as in Worms. So far I am attempting to hybridize the Farseer model with my own bitmap collision detection routine, but the system I have is unsatisfactory as a simulation of rigid body physics - I need geometric bodies to twist on contact and collide full on before rebounding, for circular objects to roll and so on. The maths for this stuff seem pretty complex - if it could all be done in Farseer it would make my job a lot easier, but the complex and concave nature of the deformable scenery makes this seem unlikely.

Could I do something like making a collision grid for the walls with intervals of five pixels or so, and somehow recalculate the edges when I cut chunks of scenery out?
Dec 22, 2008 at 7:09 PM
It seems like creating temporary pixel geometries might be the way to go.  But instead of creating new pixel geometries , keep a pool of pre-generated geometries ready, and move them to the appropriate positions when your agent body gets close (within an enlarged bounding rectangle).  This might save you the cost of allocating memory.

Also, if you don't need pixel-perfect collisions, you could maybe use geometry that's 5 pixels per side (for instance), or use tesselating triangles or hexes.