Solved

Fire and explosion

Posted on 2001-07-15
6
385 Views
Last Modified: 2013-12-26
Where I can find the good explosion and fire algorithm. I have seen in games that when an object is destroyed. An irregular shape is drawn there. And the color of shape darkens from the border to inside gradually. And this gives the effect of fire. What is the technique behind it. (Is there any supporting thing in dx 8).
0
Comment
Question by:Sana060101
6 Comments
 
LVL 2

Expert Comment

by:smitty1276
Comment Utility
It's a particle system, usually.  Image a whole bunch of small quads moving (exploding) away from the point of the explosion.  They are usually done by texturing the quads with an appropriate texture and alpha blending them.  As they move away from the point of the explosion you will want the alpha value to increase (the transparency) and maybe the color (from red to grey or black).  When you have a lot of them moving outward in every direction, it will look like an explosion.
0
 

Expert Comment

by:GuyJohnston
Comment Utility
You  could  break  your  object down to a triangle list,
then copy the list to another list reversing the normals
so you could draw both sides of the triangles.

Then you could give each triangle a random vector outward, and a random rotation.  For each frame,  you  rotate  and expand.  Do  these calculations from a reference triangle list that you use over again so you can calculate rotation, and offset.

I did something like this on an old 386 computer programming in DOS. It looked pretty cool, but then again you really don't expect alot from a 386.  
0
 
LVL 2

Expert Comment

by:cybermike3d
Comment Utility
Another suggestion ... I have a couple of gif's with fire and explosion fx. These are typicaly 20 frames in duration. What I then did was convert each frame to a .dds texture map (.dds is a 4 channel texture map with alpha, red, green and blue) Then place a simple square polygon at the position in space where I want the explosion to occur and then 'playback' the 20 frames ... and u have a photorealistic explosion effect. In fact, all the pyrotec fx are .dds texture maps 'projected' onto a polygon at the location that I want it to occur. Minimal processing overhead and great fx.
If u want a sample gif to try out, Have a look at http://www.cybermike.co.za/clanibh00.htm  ... you are quite welcome to copy and play around with the artwork. If this is the way u want to go, let me know ... I have some more. You really dont want to tie up your cpu calculating fire and smoke.
0
What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

 

Author Comment

by:Sana060101
Comment Utility
Cybermike
I liked the way you have created fire. But I have never used fx. Can you send me a simple application  that implements the technique.  
0
 
LVL 2

Accepted Solution

by:
cybermike3d earned 50 total points
Comment Utility
The following code snippets do all the work

First, load the polygon with its texture map sequence.
'---------------------------------------
    l1 = 30: i = 0:   meshn$(l1, i) = "poly05.x":   strtexname(l1, i) = "smoke01.dds": loadmeshtex:    meshno(930) = 30
    l1 = 30: i = 1:   meshn$(l1, i) = "poly05.x":   strtexname(l1, i) = "smoke01.dds": loadmeshtex:    meshno(930) = 30
    l1 = 30: i = 2:   meshn$(l1, i) = "poly05.x":   strtexname(l1, i) = "smoke02.dds": loadmeshtex:    meshno(930) = 30
    l1 = 30: i = 3:   meshn$(l1, i) = "poly05.x":   strtexname(l1, i) = "smoke03.dds": loadmeshtex:    meshno(930) = 30
    l1 = 30: i = 4:   meshn$(l1, i) = "poly05.x":   strtexname(l1, i) = "smoke04.dds": loadmeshtex:    meshno(930) = 30
    l1 = 30: i = 5:   meshn$(l1, i) = "poly05.x":   strtexname(l1, i) = "smoke05.dds": loadmeshtex:    meshno(930) = 30
    l1 = 30: i = 6:   meshn$(l1, i) = "poly05.x":   strtexname(l1, i) = "smoke06.dds": loadmeshtex:    meshno(930) = 30
    l1 = 30: i = 7:   meshn$(l1, i) = "poly05.x":   strtexname(l1, i) = "smoke07.dds": loadmeshtex:    meshno(930) = 30
    l1 = 30: i = 8:   meshn$(l1, i) = "poly05.x":   strtexname(l1, i) = "smoke08.dds": loadmeshtex:    meshno(930) = 30
    l1 = 30: i = 9:   meshn$(l1, i) = "poly05.x":   strtexname(l1, i) = "smoke09.dds": loadmeshtex:    meshno(930) = 30
    l1 = 30: i = 10:  meshn$(l1, i) = "poly05.x":   strtexname(l1, i) = "smoke10.dds": loadmeshtex:    meshno(930) = 30
    l1 = 30: i = 11:  meshn$(l1, i) = "poly05.x":   strtexname(l1, i) = "smoke11.dds": loadmeshtex:    meshno(930) = 30
    l1 = 30: i = 12:  meshn$(l1, i) = "poly05.x":   strtexname(l1, i) = "smoke12.dds": loadmeshtex:    meshno(930) = 30
    l1 = 30: i = 13:  meshn$(l1, i) = "poly05.x":   strtexname(l1, i) = "smoke13.dds": loadmeshtex:    meshno(930) = 30
    l1 = 30: i = 14:  meshn$(l1, i) = "poly05.x":   strtexname(l1, i) = "smoke14.dds": loadmeshtex:    meshno(930) = 30
    l1 = 30: i = 15:  meshn$(l1, i) = "poly05.x":   strtexname(l1, i) = "smoke15.dds": loadmeshtex:    meshno(930) = 30
    l1 = 30: i = 16:  meshn$(l1, i) = "poly05.x":   strtexname(l1, i) = "smoke16.dds": loadmeshtex:    meshno(930) = 30
    l1 = 30: i = 17:  meshn$(l1, i) = "poly05.x":   strtexname(l1, i) = "smoke17.dds": loadmeshtex:    meshno(930) = 30
    l1 = 30: i = 18:  meshn$(l1, i) = "poly05.x":   strtexname(l1, i) = "smoke18.dds": loadmeshtex:    meshno(930) = 30
    l1 = 30: i = 19:  meshn$(l1, i) = "poly05.x":   strtexname(l1, i) = "smoke19.dds": loadmeshtex:    meshno(930) = 30
    l1 = 30: i = 20:  meshn$(l1, i) = "poly05.x":   strtexname(l1, i) = "smoke20.dds": loadmeshtex:    meshno(930) = 30
'--------------------------------------
Sub loadmeshtexhi()
    Set g_mesh(l1, i) = g_D3DX.LoadMeshFromX(rootdir$ + "\" + meshn$(l1, i), _
                                    D3DXMESH_MANAGED, _
                                    g_D3DDevice, _
                                    Nothing, _
                                    MtrlBuffer, _
                                    g_NumMaterials)
    g_D3DX.BufferGetMaterial MtrlBuffer, 0, g_meshmaterials(l1, i)
    If strtexname(l1, i) = "" Then strtexname(l1, i) = g_D3DX.BufferGetTextureName(MtrlBuffer, 0)
    If strtexname(l1, i) <> "" Then
        Set g_meshtextures(l1, i) = g_D3DX.CreateTextureFromFile(g_D3DDevice, rootdir$ + "\" + strtexname(l1, i))
    End If
End Sub
'-----------------------------------------------
'then draw the billowing smoke and flame trail behind the craft
'----------------------------------------------
'To save space, I use the same holding variable for the bullets as the smoke ... if craft is going down in flames ... it aint shooting bullets

        '----------------------------------------------------------- draw smoke
    'Draw fire & smoke on friendlies (Reddish tint)
     For l = startoffriend To endoffriend
      If bullets(l, 1) = 1 Then
       ' In order to prevent tiling, one has to draw the smoke from the furthest to the closest.
       ' so u have to determine if the craft is comming towards or going away from u
       ixdif = eye.X - posx(l): iydif = eye.z - posz(l): getcord: angl1 = itnang - heading(l): angl1 = Int(angl1): angl3 = itnang
       If angl1 > 180 Then angl1 = angl1 - 360
       If angl1 < -180 Then angl1 = angl1 + 360
       If itnang > 180 Then itnang = itnang - 360
       If heading(l) > 180 Then heading(l) = heading(l) - 360
       ixdif = eye.X - posx(sel)
       iydif = eye.z - posz(sel)
       getcord
       angl2 = Abs(Int(itnang - angl3))
       If angl2 > 180 Then angl2 = angl2 - 360
       If angl2 < -180 Then angl2 = angl2 + 360
      'if craft is outside the field of vission ... dont draw the smoke
       If angl2 < 35 Then
        If angl1 < 90 And angl1 > -90 Then
         For l2 = 2 To 20
          i = l2
          l1 = meshno(930)
          l5 = meshno(930)
          scalez = 0.02 * l2
          g_meshmaterials(l1, i).emissive.r = 0.6: g_meshmaterials(l1, i).emissive.g = 0: g_meshmaterials(l1, i).emissive.b = 0
          light.Ambient.r = 1: light.Ambient.g = 1: light.Ambient.b = 1
          g_D3DDevice.SetRenderState D3DRS_AMBIENT, &HFFFFFF
          D3DXMatrixRotationYawPitchRoll rotMatrix, rolx(900) / rad, (roly(900) - 90) / rad, Rnd(1) * 360 / rad
          D3DXMatrixMultiply matWorld, matWorld, rotMatrix
          smokeno = Int(Rnd(1) * 16) + 1
          D3DXMatrixTranslation transMatrix, bulletx(l, l2), bullety(l, l2), bulletz(l, l2)
          D3DXMatrixScaling scaleMatrix, scalez, scalez, scalez
          D3DXMatrixMultiply matWorld, scaleMatrix, rotMatrix
          D3DXMatrixMultiply matWorld, matWorld, transMatrix
          g_D3DDevice.SetTransform D3DTS_WORLD, matWorld
          g_D3DDevice.SetMaterial g_meshmaterials(l5, l2)
          g_D3DDevice.SetTexture 0, g_meshtextures(l5, smokeno)
          g_mesh(l5, l2).DrawSubset 0
         Next
        End If
   
        If angl1 > 90 Or angl1 < -90 Then
         For l2 = 20 To 2 Step -1
          i = l2
          l1 = meshno(930)
          l5 = meshno(930)
          scalez = 0.02 * l2
          g_meshmaterials(l1, i).emissive.r = 0.3: g_meshmaterials(l1, i).emissive.g = 0: g_meshmaterials(l1, i).emissive.b = 0
          light.Ambient.r = 1: light.Ambient.g = 1: light.Ambient.b = 1
          g_D3DDevice.SetRenderState D3DRS_AMBIENT, &HFFFFFF
          D3DXMatrixRotationYawPitchRoll rotMatrix, rolx(900) / rad, (roly(900) - 90) / rad, Rnd(1) * 360 / rad
          D3DXMatrixMultiply matWorld, matWorld, rotMatrix
          smokeno = Int(Rnd(1) * 16) + 1
          D3DXMatrixTranslation transMatrix, bulletx(l, l2), bullety(l, l2), bulletz(l, l2)
          D3DXMatrixScaling scaleMatrix, scalez, scalez, scalez
          D3DXMatrixMultiply matWorld, scaleMatrix, rotMatrix
          D3DXMatrixMultiply matWorld, matWorld, transMatrix
          g_D3DDevice.SetTransform D3DTS_WORLD, matWorld
          g_D3DDevice.SetMaterial g_meshmaterials(l5, l2)
          g_D3DDevice.SetTexture 0, g_meshtextures(l5, smokeno)
          g_mesh(l5, l2).DrawSubset 0
        Next
       End If
      End If
     End If
    Next


'-------------------------------------------------------
' getcord is the math behind the 3d angular translation
'-------------------------------------------------------
Sub getcord()
        itargetrange = Sqr(ixdif ^ 2 + iydif ^ 2)
        If iydif <> 0 Then itgan = Atn(ixdif / iydif) * 57.2958
        If iydif = 0 And ixdif = 0 Then itgan = 0: itgang = 0
        If iydif = 0 And ixdif < 0 Then itgan = 270
        If iydif = 0 And ixdif > 0 Then itgan = 90
        itgang = itgan
        If iydif < 0 Then itgang = 180 + itgan
        If ixdif < 0 And iydif > 0 Then itgang = 360 + itgan
        itnang = ina + itgang
        If itnang > 360 Then itnang = itnang - 360
        If itnang < 0 Then itnang = itnang + 360
End Sub

So there you go, make a few bitmaps of flame and sparks and smoke, and play them in quick sucsession on a polygon. Its like having a big alpha blended screen in space and u can playback any movie clip u like. Use the artwork of the gif on the link i gave u above ...

One of these days im gonna figure out how to channel an avi into a texture map ... and then im really gonna have some fun ...

regards
(yberMike ;-D)

0
 
LVL 2

Expert Comment

by:smitty1276
Comment Utility
I've been thinking of doing that myself... converting movies into "sprite" type textures.  You could do some cool stuff... you could even simulate a big "Downtown New York style" screen with ads for stuff running in the scene somewhere.
0

Featured Post

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

What is RenderMan: RenderMan is a not any particular piece of software. RenderMan is an industry standard, defining set of rules that any rendering software should use, to be RenderMan-compliant. Pixar's RenderMan is a flagship implementation of …
As game developers, we quickly learn that Artificial Intelligence (AI) doesn’t need to be so tough.  To reference Space Ghost: “Moltar, I have a giant brain that is able to reduce any complex machine into a simple yes or no answer. (http://www.youtu…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

6 Experts available now in Live!

Get 1:1 Help Now