# 3D explosion effect

This topic is 3906 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Hello all, I've been working on a game project for a while and I just finished implementing some basic collision detection. The problem is that I don't have any animation for the projectiles impacting on the shields/hull of their targets. What I'm looking for is a 3D explosion effect of some kind (no shaders, please) and perhaps some sort of shield impact effect. Pretty much anything decent will do, I mostly just need a general idea of some code to get something like that working. Thanks! (test version of app available on request if you want to see the engine style)

##### Share on other sites
Well, explosion sprites are a dime a dozen these days, so grab one (or a few) of those and get them into your desired image format and loaded into your game.

From there, well, it's just a matter of finding the point of impact and producing an explosion effect there. Depending on how your collision detection works you can probably calculate the point of impact, or hopefully at least get close enough to where the player won't notice the effect in the completely wrong place.

As for your "shield impact" question, decades of sci-fi film have taught us that shields are invisible spheroids around spaceships, so you could either render a few faces of an invisible sphere with some kind of translucent sparky texture, or have neat little ripple effects occur wherever something is striking them.

No matter what you do, though, the real onus is on your special effects--the code behind it is just a matter of calculating the point of intersection between two objects, which is hopefully extractable from your collision detector, and then initiating an effect there.

##### Share on other sites
Not entirely what I meant, but thats ok. I came up with an idea that involves drawing "ripples" in the form of circles along the surface of the shield sphere. What I need now is the appropriate formulas for determining the the coords/radius of a circle (basically, I need the formulas defining a circular slice of a sphere with the first slice being the point at which the impact occurs.

KNOWN: the point at which the projectile impacts the shields, orientation information for both the ship being hit and the projectile (in the form up Up, forward, and right vectors).

##### Share on other sites
Quote:
 Original post by medevilenemyNot entirely what I meant, but thats ok. I came up with an idea that involves drawing "ripples" in the form of circles along the surface of the shield sphere. What I need now is the appropriate formulas for determining the the coords/radius of a circle (basically, I need the formulas defining a circular slice of a sphere with the first slice being the point at which the impact occurs.KNOWN: the point at which the projectile impacts the shields, orientation information for both the ship being hit and the projectile (in the form up Up, forward, and right vectors).
A common way of building a sphere mesh is the 'stacks and slices' method (used by e.g. GLUT to render sphere meshes).

This approach uses spherical coordinates to compute a series of 'rings', starting at the top of the sphere, increasing in radius towards the 'equator', and then decreasing in radius towards the bottom ('top' and 'bottom' being relative, of course).

These 'rings' of vertices could also, I think, serve as the vertex information for the 'shield hit' effect you describe. In essence, you would substitute elapsed time in for the 'latitude' variable in the spherical coordinate computation, yielding a series of rings radiating out from the hit point and 'moving' backwards along the sphere.

These computations could all be performed in local space, of course, and then transformed into world space using a coordinate frame built from the hit point and the normal to the shield sphere at that point.

From what you describe, I think this might be the sort of thing you're looking for, so post back if you need more details.

##### Share on other sites
the current design I'm going for (which I may revise later) is to draw a fading, expanding ring effect at the point of impact aligned with the plane perpendicular to the sphere at the impact point. I have modified some earlier code of mine to draw the ring effect, but I am having trouble aligning it properly. regardless of the where the projectile impacts, the effect needs to be tangent to the sphere. I have the position vectors of the ship and of the projectile, as well as the radius of the shield (the projectile is on the bubble and is consequently of distance radius from the ship at the moment of impact) available.

 and thanks again!

##### Share on other sites
Quote:
 Original post by medevilenemythe current design I'm going for (which I may revise later) is to draw a fading, expanding ring effect at the point of impact aligned with the plane perpendicular to the sphere at the impact point. I have modified some earlier code of mine to draw the ring effect, but I am having trouble aligning it properly. regardless of the where the projectile impacts, the effect needs to be tangent to the sphere. I have the position vectors of the ship and of the projectile, as well as the radius of the shield (the projectile is on the bubble and is consequently of distance radius from the ship at the moment of impact) available. and thanks again!
Personally, I think it'd be more effective if the 'ripple' effect moved over the surface of the sphere rather than lying in a plane tangent to it (for one thing, you could then see the effect clearly from any angle). But, maybe you can add that once you get everything else working...

As far as aligning the effect properly goes, that's basically a billboarding problem. Can I ask what math library you're using? Maybe it already has functionality available for building billboard transforms (and if not, it's pretty easy to explain how to do it in a post).

##### Share on other sites
I'm not using any prebuilt math library. I have a modified form of the Vector3 class which I use for vectors and such, and aside from that I mostly use some creative algebra and trig. I agree that running the effect on the surface of the sphere would look better, I was planning on trying to adapt it to that once I had alignment down. (I'm pretty sure there is a relatively simple formula to determine the radius of a "small circle" of a sphere knowing its distance from the center of the parent sphere)

Anyway, the best I can come up with is I can derive a vector between the centers of the ship and of the projectile (which I'm calling the Radius vector). what I then need is to come up with are vectors corresponding to a plane completely perpendicular to that vector. Then I can swap out the Up, right, and view vectors of the projectile for those in such a way that view (forward) lies along the radius vector and so on. I just don't know how to do the math for any of that... I'm kind of overwhelmed by it.

##### Share on other sites
Quote:
 Original post by medevilenemyAnyway, the best I can come up with is I can derive a vector between the centers of the ship and of the projectile (which I'm calling the Radius vector). what I then need is to come up with are vectors corresponding to a plane completely perpendicular to that vector. Then I can swap out the Up, right, and view vectors of the projectile for those in such a way that view (forward) lies along the radius vector and so on. I just don't know how to do the math for any of that... I'm kind of overwhelmed by it.
You can probably find the math for this by searching the forums for 'billboarding' (it also comes up fairly often in relation to rendering various primitives - such as cylinders - in alignment with a particular axis). However, the algorithm is simple enough that I'll just go ahead and post it here:
vector3 z = normalize(impact_point - ship.pos);// This awkwardly named function returns the index of the// component (x, y, or z) with the least absolute value:int i = z.index_of_component_of_least_magnitude();vector3 ref(0,0,0);ref = 1;vector3 x = normalize(cross(ref, z));vector3 y = cross(z, x);
The vectors x, y, and z now represent a coordinate frame, with 'z' normal to the sphere and 'x' and 'y' lying in the plane tangent to it.

##### Share on other sites
wow, thanks a lot jyk, that is pretty much exactly what I was looking for! Just one question:

Quote:
 // This awkwardly named function returns the index of the// component (x, y, or z) with the least absolute value:int i = z.index_of_component_of_least_magnitude();

I'm not quite sure what this means. I understand that it picks out the element of z with the smallest value. In physical terms, though, what does said shortest element represent? (sorry for continually bugging you with my trivialities)

##### Share on other sites
Quote:
Original post by medevilenemy
wow, thanks a lot jyk, that is pretty much exactly what I was looking for! Just one question:

Quote:
 // This awkwardly named function returns the index of the// component (x, y, or z) with the least absolute value:int i = z.index_of_component_of_least_magnitude();

I'm not quite sure what this means. I understand that it picks out the element of z with the smallest value. In physical terms, though, what does said shortest element represent? (sorry for continually bugging you with my trivialities)
Just to be clear, it's the smallest absolute value, not the least value. Some example input and output (indices are zero-based - 0 corresponds to 'x', 1 to 'y', and 2 to 'z'):
[-5 -1 3] returns 1[ 0  1 4] returns 0[-9 -2 1] returns 2
In geometrical terms, the index corresponds to the cardinal axis with which the input vector is 'least aligned' (visualizing a few example cases should make it clear why this is so).

Crossing the initial vector with the cardinal axis with which it's least aligned simply assures that the resulting vector will have sufficient magnitude to be safely normalized, and that it can therefore be used to build a valid orthonormal basis. (Remember that the cross product of two vectors which are aligned or nearly aligned will have a small magnitude, and that normalizing such a vector can introduce numerical errors; as such, we have to be sure to avoid this case when building the basis.)

1. 1
2. 2
3. 3
Rutin
18
4. 4
JoeJ
14
5. 5

• 14
• 10
• 23
• 9
• 43
• ### Forum Statistics

• Total Topics
632635
• Total Posts
3007561
• ### Who's Online (See full list)

There are no registered users currently online

×