Explosions on a larger scale

Topics: Developer Forum, User Forum
May 27, 2009 at 1:02 AM

(Ok the subject is a bit misleading - by larger scale, I mean the environments in which they explode, not the explosions themselves)

There are several effects (including explosions) I'd like to implement in an xbox 360 project I'm working on which apply forces to all dynamic objects in a particular range or area (and other types of "locality tests"). The closest thing I've found in the examples is demo7 in the advanced examples (the hair dryer and the grenades). The method used in those examples basically loops through every body in the simulator and does an AABB check against the area around the grenade. While this works ok for a single screen of objects where the locality test is as simple as an AABB check, it becomes noticeably slower when I apply the same technique to the larger scale environments I'm trying to work with, especially since some of the "locality" tests are non-trivial (for example, explosions don't apply forces to objects completely obscured from the source by static objects). And, it's really slow if more than a small number of such effects are being applied at one time.

Does anyone have any suggestions for improving the performance of such a check? I'd be willing to settle for a way to find all objects within an AABB that performs better than brute force. I can then apply the narrower locality checks with less of a performance hit. My backup plan is just to maintain my own partitioning scheme, but I'd like to avoid that if possible.

Coordinator
May 27, 2009 at 1:11 AM
Edited May 27, 2009 at 1:16 AM

The broad phase collision detection in Farseer Physics is a lot faster than simple brute force. As you may well know, the broad phase finds geometries in close range (by comparing their AABBs) and create an Arbiter (containing the two geometries) if they are close.

You could create a sensor (it's still a geometry, but does not have any dynamics applied to it). This sensor should be as big as the explosion area you need. When you add it to the physics simulator, it will be included in the broad phase collision detection, and thus, you will have a much faster check against other geometries close by.
I included an event some time ago into all the broad phase colliders. It's called OnBroadPhaseCollision (If I remember correctly). This event fires whenever an arbiter is created containing the geometry. (Basically when the geometry's AABB intersects another AABB).

This should get the stone rolling.

By the way. I do the bruteforce (O(n^2)) method in the simple samples, simply because they should be simple ;)