TGC Codebase Backup



Smoke Effect (DBC and DBPro) by Hamish McHaggis

17th Oct 2003 14:27
Summary

A rising, fading 3D smoke effect using particles.



Description

Just uncomment the right parts of the code if you are using DBC (there are 2 section in capitals). It uses a method of creating ghosted, textured planes and moving, scaling and fading them to create a relatively realistic smoke effect in 3D.



Code
                                    ` This code was downloaded from The Game Creators
                                    ` It is reproduced here with full permission
                                    ` http://www.thegamecreators.com
                                    
                                    `Smoke particle effect
`By Joseph Thomson
`17/10/03

`Setup
sync on
sync rate 40
hide mouse

`Number of smoke particles
numSmokeParticles=50

`Particle value arrays
dim smokeParticlesPos#(numSmokeParticles,3)
dim smokeParticlesVel#(numSmokeParticles,3)
dim smokeParticlesSize#(numSmokeParticles,3)
dim smokeParticlesFade#(numSmokeParticles,2)

`Create smoke image
create bitmap 1,50,50
`REMARK FOR DBC!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
ink rgb(130,130,130),0
`UNREMARK FOR DBC!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
`ink rgb(200,200,200),0
`Draw random dots in a circle shape
for x=1 to 1000
   ang=rnd(360)
   rad=rnd(20)
   dot 25+sin(ang)*rad,25+cos(ang)*rad
next x
`Blur smoke image
blur bitmap 1,8
get image 1,0,0,50,50
delete bitmap 1

backdrop on
color backdrop rgb(0,0,0)

`Make particles
for x=1 to numSmokeParticles
   make object plain x,10,10
   texture object x,1
   hide object x
   `Deactivate ambient light
   `REMARK FOR DBC!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
   set object ambient x,0
   `Make black areas see through
   `REMARK FOR DBC!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
   set object transparency x,1
   `UNREMARK FOR DBC!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
   `set object x,1,0,1,1,1,1,0
   `Ghost particle
   ghost object on x
next x

position camera 0,20,-50

do
   `Position new particle at origin every nth time
   inc count
   if count=2 then count=0
   if count=0
      `Increase number of particle to reset
      inc currentParticle
      `Loop round if you reach the end of the particles
      if currentParticle>numSmokeParticles then currentParticle=1
      `Reset particle values
      `Position
      smokeParticlesPos#(currentParticle,1)=0
      smokeParticlesPos#(currentParticle,2)=0
      smokeParticlesPos#(currentParticle,3)=0
      `Scale
      smokeParticlesSize#(currentParticle,1)=50
      smokeParticlesSize#(currentParticle,2)=50
      `Velocity (randomize)
      smokeParticlesVel#(currentParticle,1)=rnd(200)/1000.0-0.1
      smokeParticlesVel#(currentParticle,2)=rnd(100)/1000.0+0.1
      smokeParticlesVel#(currentParticle,3)=rnd(200)/1000.0-0.1
      smokeParticlesFade#(currentParticle,1)=200
      `Show the particle
      show object currentParticle
   endif

   `Loop through particles
   for x=1 to numSmokeParticles
      `Re-position and scale particle values
      for y=1 to 3
         smokeParticlesSize#(x,y)=smokeParticlesSize#(x,y)+0.5
         smokeParticlesPos#(x,y)=smokeParticlesPos#(x,y)+smokeParticlesVel#(x,y)
      next y
      `Fade particle value
      smokeParticlesFade#(x,1)=smokeParticlesFade#(x,1)-1.5
      `Position, scale and fade particle object
      position object x,smokeParticlesPos#(x,1),smokeParticlesPos#(x,2),smokeParticlesPos#(x,3)
      scale object x,smokeParticlesSize#(x,1),smokeParticlesSize#(x,2),100
      fade object x,smokeParticlesFade#(x,1)
      `Point at camera
      set object to camera orientation x
   next x
   sync
loop