Idea for implementing explosions

Great!

To recap:

Code: Select all

   /* Methodology:
    * Force applied at a ray is inversely proportional to the square of distance from source
    * AABB is used to query for shapes that may be affected
    * use AABB that is sufficiently large so that the non circular shape doesn't cause discernible difference
    * For each RIGID BODY (not shape -- this is an optimization) that is matched, loop through its vertices to determine
    *      the extreme points -- if there is structure that contains outlining polygon, use that as an additional optimization
    * Evenly cast a number of rays against the shape - number roughly proportional to the arc coverage
    *      -Something like every 3 degrees should do the trick although this can be altered depending on the distance (if really close don't need such a high density of rays)
    *      -There should be a minimum number of rays (3-5?) applied to each body so that small bodies far away are still accurately modeled
    *      -Be sure to have the forces of each ray be proportional to the average arc length covered by each.
    * For each ray that actually intersects with the shape (non intersections indicate something blocking the path of explosion):
    *      > apply the appropriate force dotted with the negative of the collision normal at the collision point
    *      > optionally apply linear interpolation between aforementioned Normal force and the original explosion force in the direction of ray to simulate "surface friction" of sorts
    */

I'll be referring to that as I write my code; I figured it'd probably be useful for anyone looking to make more realistic explosions.

Also, something we haven't explored is that this also allows us to do a bit more while rendering our explosions. We've got data that shows exactly where the explosion can reach since rays are blocked from continuing after intersecting an object. We've even got normal vectors and collision points for each ray, which can be helpful for drawing sparks and effects that look like they bounce off of shapes, and should be much more efficient than instantiating physics particles to do that for us (though CCD does make it a whole lot more robust than it would have been otherwise). You could definitely use this to make some beautiful dynamics but I'm afraid I wont be able to come up with something that looks all that good. In my program I've only had success making pretty things using various shader effects (bloom + per pixel displacement) and my textures have come out terrible looking so far. Though a nice distorting, expanding shockwave effect which gets reflected by objects, would certainly look very nice, and I think I can do that. Someone needs to show me how to make nice looking fireballs, sparks, and smoke though.
dc443 wrote:No I don't do flash. This is going into my C++/OpenGL project. I could probably make a demo or something at some point showcasing the features... later on...


Cool. I prefer C++/OpenGL anyway 🙂 You are gonna share your source code right? :p

dc443 wrote:Someone needs to show me how to make nice looking fireballs, sparks, and smoke though.


Wish I could help, but I'm afraid I'm no artist.
My project is not open source at the moment, but I'm making a self contained method that will calculate and apply the forces so you could just drop it in and it'll work with few modifications.
If you are weighting the force strength based on angle coverage, keep in mind that such a calculation automatically applies a 1/r falloff (in 2d; in 3d if you use the angular area it's 1/r^2) so the only reason to further weight the force based on distance is if you want the falloff to be as it would be in 3d.

One last thing that hasn't been addressed is the fact that if part of the blast is shielded the rest of it will be felt stronger, and that the blast can actually travel through passageways because of stuff like that. This is a little harder to account for, though, so maybe best to leave it out for a first attempt.
I think the best way (processing speed best way) to do this would just to apply force on the object from world position of the center of the explosion, and in the direction of the objects center of mass.
It wouldn't be perfect, but it would work, and make a mostly-realistic looking explosion.

That's what I'm going to to in my game engine. 😀
Sgt. Sparky wrote:I think the best way (processing speed best way) to do this would just to apply force on the object from world position of the center of the explosion, and in the direction of the objects center of mass.


I mentioned this in the first post on this thread. this method is not realistic but is how it's done most of the time.
Here is a demonstration of the simple method using inverse square:

http://www.fox-x.com/#mapid=kCDSCdROJx

(shoot the red box)
Interesting...
This is really useful!
Progess report:

going pretty well. Just finished the bit that calculates the max and min arc coverage on a per-shape basis (easily extended to per-body)
Image

The debug lines are not color coded according to each shape but the line and the corresponding text do have the same color.

I know our solution didn't require this but I'm really tempted to implement a datastructure that keeps track of the exact segments along the arc that each shape/body is exposed to. This way, something that is mostly blocked will be simulated much more accurately...
Any chance you could post your function in this thread please?
I've hit exactly the same hurdle.

Original thread: https://box2d.org/forum/viewtopic.php?t=1688