PDA

View Full Version : Draw 2d shock-wave using OpenGL?



paul_nicholls
14-07-2009, 04:22 AM
Hi all,
I am drawing some 2d explosions using OpenGL triangle strips.

http://2.bp.blogspot.com/_vMC6A9wL7B8/SlwFHHanVLI/AAAAAAAAAAU/XUTTnSJH_O8/s1600-h/Screenshot.png

I would like to make the explosions look more like this (with shock-wave ring, ignore rest of explosion):

http://www.espressosoft.com/images/blog/gamepic9.png

Here is the code I currently use:

Procedure TExplosion.Draw;
Const
cSegments = 20;

Var
p : Integer;
t : Single;
a : Single;
r2 : Single;
r1 : Single;
ex : Single;
ey : Single;
Begin
If Time < 0 Then Exit;
t := Time / TTL;
r2 := MinRadius + MaxRadius * (1 - t);
r1 := r2 - 25;
If r1 < 0 Then r1 := 0;

glPushMatrix;
glTranslatef(x,y,0);
glBegin(GL_TRIANGLE_STRIP);
For p := 0 To cSegments Do
Begin
a := p * 2 * PI / cSegments;
ex := Cos(a);
ey := Sin(a);
// outer ring edge
glColor4f(1,0.2,0,t);
glVertex3f(r2 * ex,r2 * ey,0);
// inner ring edge
glColor4f(1,1,0,t / 2);
glVertex3f(r1 * ex,r1 * ey,0);
End;
glEnd;
glPopMatrix;
End;


Any ideas?

I'm sure I could make a nice texture, but I am not sure what U,V coordinates I would use inside the code when doing the triangle strip...

cheers,
Paul

Andreaz
14-07-2009, 04:38 AM
Well, i've done that using a single, alpha blended quad in my particle demo here:

http://www.pascalgamedevelopment.com/forum/index.php?topic=5781.0 (press the LMB)

There i just use a quad with the texture coordinates {0,0} and {1,1} where i move the corner verticies outward over time, its a easy "hack" to achive the same effect.

paul_nicholls
14-07-2009, 08:35 AM
Well, i've done that using a single, alpha blended quad in my particle demo here:

http://www.pascalgamedevelopment.com/forum/index.php?topic=5781.0 (press the LMB)

There i just use a quad with the texture coordinates {0,0} and {1,1} where i move the corner verticies outward over time, its a easy "hack" to achive the same effect.





Thanks Andreaz, I will take a look :)
Thanks all for your replies :)
cheers,
Paul

paul_nicholls
14-07-2009, 11:23 AM
Andreaz,
would it be ok if I maybe tried using the shockwave.bmp (slightly edited), and maybe 1 or more of the bullet 'sprites' (bullets.png) from your particles demo in my competition entry?

I would understand if you said no :)

cheers,
Paul

noeska
23-08-2009, 08:33 PM
Thank You! :)

Your ring render is the missing link in my glvg unit on making radial fill possible with more then 2 colors.

It is not entirely wat i want because with larger radiuses the lines become visible. e.g. if an inner ring has 40 segment and another ring has 80 holes will apear.
Is is solveable with just using lots of segment always, but that probeably is not efficient.

Is it possibel to make the inner part of the ring use less segement than the outer part?
How would one triangulate such going from 2 points on the inside to many more on the outsie. Btw sorry for breaking on your thread.