;; ----------------------------------------------------------------------------
;; Irrlicht Wrapper For Imperative Languages - Purebasic Examples
;; IrrlichtWrapper and FreeBasic-Example by Frank Dodd (2006)
;; Improved IrrlichtWrapper - Michael Taupitz (2007)
;; PureBasic-Examples by Michael Taupitz (neotoma) & Marius Eckardt (Thalius) 
;; ----------------------------------------------------------------------------
;; Example 07: Particle System
;; This example creates a couple of simple particle systems To demonstrate
;; particle system effects
;; ----------------------------------------------------------------------------

;; ////////////////////////////////////////////////////////////////////////////
;; Include the Irr3D-Requester
XIncludeFile #PB_Compiler_Home + "Includes\IrrlichtWrapper_Include.pbi"


;EnableExplicit

;; ////////////////////////////////////////////////////////////////////////////
;; Global variables

; irrlicht objects
Define *ParticleTexture.irr_texture
Define *TestNodeTexture.irr_texture
Define SmokeParticles.irr_model
Define SmokeEmitter.IRR_PARTICLE_EMITTER
Define *ParticlesNode.irr_node
Define *TestNode.irr_node
Define *camera.irr_camera
Define *Particle.irr_node
Define *KeyEvent.IRR_KEY_EVENT


Define *em.l  ; pointer to the Emitter


Declare Tausend()
Declare Smoke()
Declare Sparks()
Declare Fire()
Declare Crash()
Declare Explosion()
Declare Attract()
Declare Aligned()

;whow - PB is much slower  !
Procedure.f RndR(f1.f, f2.f)
;  frnd.f = 
	ProcedureReturn  f1 + (f2-f1)*Random(4294967296)/4294967296.0;
EndProcedure 


starttime = ElapsedMilliseconds()
For i = 0 To 100000
  IrrRnd(1000, 2000, @back.f)
  If back < 1000.0 Or back > 2000     
    Debug(StrF(back))
  EndIf  
Next
Debug("Ende=" + Str(ElapsedMilliseconds() - starttime))

starttime = ElapsedMilliseconds()
For i = 0 To 100000
  back.f = RndR(1000, 2000)
  If back < 1000.0 Or back > 2000     
    Debug(StrF(back))
  EndIf  
Next
Debug("Ende=" + Str(ElapsedMilliseconds() - starttime))


; -----------------------------------------------------------------------------
; To Start the Irrlicht-Device we use the Irr3DRequester, to make it more comfortable
; for the Users, and also easier to test different resolutions and devices.
 If  IrrStart( #IRR_EDT_DIRECT3D9, 640, 480, #IRR_WINDOWED, #IRR_NO_SHADOWS, #True)


  ; send the window caption
  IrrSetWindowCaption( "Example : Particle System" )

;  *camera = IrrAddFPSCamera()

  
  ; add a fixed position camera to the scene so we can view the particle system.
  ; the first three parameters are the cameras location, the second three
  ; parameters are where the camera is looking at
  *camera = IrrAddCamera( 100,0,100, 0,0,0 )
  IrrSetNodePosition(*camera,400,0,400)

  *stat = IrrGuiAddStaticText( "Particle Example"+Chr(13)+"Press 1-6 To see Particles", 4,0,400,160, #IRR_GUI_NO_BORDER, #True )
  IrrGuiStaticSetOverrideColor(*stat, 255,255,255)
  
  ; -----------------------------------------------------------------------------
  ; while the irrlicht environment is still running
  While IrrRunning()
      ; clear the canvas to black to show the particles up better
      IrrBeginScene( 0, 0, 0 )
  
      ; draw the scene
      IrrDrawScene()
  
      ; draw the Graphical User Interface
      IrrDrawGUI()
    
      ; end drawing the scene and display it
      IrrEndScene()
                  
      If IrrKeyEventAvailable()
        *KeyEvent = IrrReadKeyEvent()
        If *KeyEvent\direction = #IRR_KEY_DOWN
          Select *KeyEvent\key
            Case #IRR_KEY_KEY_1 : Tausend()
            Case #IRR_KEY_KEY_2 : Smoke()
            Case #IRR_KEY_KEY_3 : Sparks()
            Case #IRR_KEY_KEY_4 : Fire()
            Case #IRR_KEY_KEY_5 : Crash()
            Case #IRR_KEY_KEY_6 : Explosion()
            Case #IRR_KEY_KEY_7 : Attract()
            Case #IRR_KEY_KEY_8 : Aligned()
            Case #IRR_KEY_ESCAPE : IrrStop()
          EndSelect
        EndIf
      EndIf
      
  Wend
  
  ; -----------------------------------------------------------------------------
  ; Stop the irrlicht engine and release resources
;s  IrrStop()
  
EndIf

End


;Effect 1 - 
Procedure Tausend()
  Shared *camera  
  IrrSetNodePosition(*camera,400,0,400)


  *ParticlesNode = IrrAddParticleSystemToScene( #IRR_NO_EMITTER )
  
  IrrSetNodeScale(*ParticlesNode, 1,1,1)
  
  IrrSetParticleSize(*ParticlesNode,5,5)
   
  Define TausendEmitter.IRR_PARTICLE_EMITTER    
  
  With TausendEmitter
    \min_box_x = -2
    \min_box_y = -1
    \min_box_z = -2
    \max_box_x = 2
    \max_box_y = 1
    \max_box_z = 2

    \direction_x = 0.0
    \direction_y = 0.7
    \direction_z = 0.0
    \min_paritlcles_per_second = 2000
    \max_paritlcles_per_second = 2000
    \min_start_color_red = 255
    \min_start_color_green = 255
    \min_start_color_blue = 255
    \max_start_color_red = 255
    \max_start_color_green = 255
    \max_start_color_blue = 255
    \min_lifetime = 1500
    \max_lifetime = 1500
    \max_angle_degrees = 20
   EndWith  
   
    *em = IrrAddParticleEmitter(*ParticlesNode, @TausendEmitter)

    IrrAddGravityParticleAffector(*ParticlesNode, 0,-1.6,0,1000)
    IrrAddFadeOutParticleAffector(*ParticlesNode )

    IrrSetNodeMaterialFlag( *ParticlesNode, #IRR_EMF_LIGHTING, #IRR_OFF )
    IrrSetNodeMaterialType ( *ParticlesNode, #IRR_EMT_TRANSPARENT_ADD_COLOR  ) ; uncomment me... ;)
    IrrSetNodeMaterialFlag( *ParticlesNode, #IRR_EMF_ZBUFFER, #False)
    *ParticleTexture = IrrGetTexture( "..\media\Fire.bmp" )
    IrrSetNodeMaterialTexture( *ParticlesNode, *ParticleTexture, 0 )
    IrrSetNodeMaterialType ( *ParticlesNode, #IRR_EMT_TRANSPARENT_VERTEX_ALPHA  ) ; uncomment me... ;)
  

    IrrAddStopParticleAffector(*ParticlesNode, 1000)
    IrrAddDeleteAnimator(*ParticlesNode, 3000)     

EndProcedure 

;Effect 2 - 
Procedure Smoke()
  Shared *camera  
  IrrSetNodePosition(*camera,400,0,400)

  *ParticlesNode = IrrAddParticleSystemToScene( #IRR_NO_EMITTER )
  
  IrrSetNodeScale(*ParticlesNode, 1,1,1)
  
  IrrSetParticleSize(*ParticlesNode,200,200)
   
  Define SmokeEmitter.IRR_PARTICLE_EMITTER    
  
  With SmokeEmitter
    \min_box_x = -2
    \min_box_y = -1
    \min_box_z = -2
    \max_box_x = 2
    \max_box_y = 1
    \max_box_z = 2

    \direction_x = 0.0
    \direction_y = 0.0
    \direction_z = 0.0
    \min_paritlcles_per_second = 15
    \max_paritlcles_per_second = 30
    \min_start_color_red = 180
    \min_start_color_green = 128
    \min_start_color_blue = 128
    \max_start_color_red = 0
    \max_start_color_green = 0
    \max_start_color_blue = 64
    \min_lifetime = 1500
    \max_lifetime = 1500
    \max_angle_degrees = 20
   EndWith  
   

    *em = IrrCreateParticleEmitter(*ParticlesNode, @SmokeEmitter)    
    *em2 = IrrCreateEmitterManager(*em, 10,40, -200.0, 200.0, 0.5, 3.0, 1.0, 4.0, 0, -200.0,200.0)
    IrrSetParticleEmitter(*ParticlesNode,  *em2)    
    

    IrrAddGravityParticleAffector(*ParticlesNode, 0,0.6,0,100)
    IrrAddFadeOutParticleAffector(*ParticlesNode )
    IrrAddSpinParticleAffector(*ParticlesNode, 800)  

    IrrSetNodeMaterialFlag( *ParticlesNode, #IRR_EMF_LIGHTING, #IRR_OFF )  ; is now important for transparent materials
    IrrSetNodeMaterialFlag( *ParticlesNode, #IRR_EMF_ZBUFFER, #False)
    
    IrrSetNodeMaterialType ( *ParticlesNode, #IRR_EMT_TRANSPARENT_ADD_COLOR  ) ; uncomment me... ;)
    *ParticleTexture = IrrGetTexture( "..\media\Smoke.png" )
    IrrSetNodeMaterialTexture( *ParticlesNode, *ParticleTexture, 0 )
;    IrrSetNodeMaterialType ( *ParticlesNode, #IRR_EMT_TRANSPARENT_VERTEX_ALPHA  ) ; uncomment me... ;)
  
    IrrAddStopParticleAffector(*ParticlesNode, 3000)
    IrrAddDeleteAnimator(*ParticlesNode, 5000)     

EndProcedure 

;Effect Sparks() - 
;while there is no particle-rotation - it won't work
Procedure Sparks()
  Shared *camera  
  IrrSetNodePosition(*camera,400,0,400)

  *ParticlesNode = IrrAddParticleSystemToScene( #IRR_NO_EMITTER )
  
  IrrSetNodeScale(*ParticlesNode, 1,1,1)
  
  IrrSetParticleSize(*ParticlesNode,100,100)
   
  Define SparkEmitter1.IRR_PARTICLE_EMITTER    
  
  With SparkEmitter1
    \min_box_x = -20
    \min_box_y = -1
    \min_box_z = -20
    \max_box_x = 20
    \max_box_y = 10
    \max_box_z = 20

    \direction_x = 0.0
    \direction_y = 0.9
    \direction_z = 0.0
    \min_paritlcles_per_second = 60
    \max_paritlcles_per_second = 100
    \min_start_color_red = 180
    \min_start_color_green = 128
    \min_start_color_blue = 128
    \max_start_color_red = 0
    \max_start_color_green = 0
    \max_start_color_blue = 64
    \min_lifetime = 1200
    \max_lifetime = 1500
    \max_angle_degrees = 180
   EndWith  
   
    *em = IrrAddParticleEmitter(*ParticlesNode, @SparkEmitter1)

    IrrAddGravityParticleAffector(*ParticlesNode, 0,-0.6,0,1000)
    IrrAddFadeOutParticleAffector(*ParticlesNode )

    IrrSetNodeMaterialFlag( *ParticlesNode, #IRR_EMF_LIGHTING, #IRR_OFF )
    IrrSetNodeMaterialFlag( *ParticlesNode, #IRR_EMF_ZBUFFER, #False)
    IrrSetNodeMaterialType ( *ParticlesNode, #IRR_EMT_TRANSPARENT_ADD_COLOR  ) ; uncomment me... ;)
    *ParticleTexture = IrrGetTexture( "..\media\Spark.jpg" )
    IrrSetNodeMaterialTexture( *ParticlesNode, *ParticleTexture, 0 )
    IrrSetNodeMaterialType ( *ParticlesNode, #IRR_EMT_TRANSPARENT_VERTEX_ALPHA  ) ; uncomment me... ;)
  

    IrrAddStopParticleAffector(*ParticlesNode, 3000)
    IrrAddDeleteAnimator(*ParticlesNode, 5000)     

EndProcedure 

Procedure Fire()
  Shared *camera  
  IrrSetNodePosition(*camera,400,0,400)

 *ParticlesNode = IrrAddParticleSystemToScene( #IRR_NO_EMITTER )
  
  IrrSetNodeScale(*ParticlesNode, 1,1,1)
  
  IrrSetParticleSize(*ParticlesNode,100,100)
   
  Define FireEmitter.IRR_PARTICLE_EMITTER    
  
  With FireEmitter
    \min_box_x = -20
    \min_box_y = -1
    \min_box_z = -20
    \max_box_x = 20
    \max_box_y = 10
    \max_box_z = 20

    \direction_x = 0.0
    \direction_y = 0.3
    \direction_z = 0.0
    \min_paritlcles_per_second = 30
    \max_paritlcles_per_second = 35
    \min_start_color_red = 180
    \min_start_color_green = 128
    \min_start_color_blue = 128
    \max_start_color_red = 0
    \max_start_color_green = 0
    \max_start_color_blue = 64
    \min_lifetime = 1200
    \max_lifetime = 1500
    \max_angle_degrees = 10
   EndWith  
   
;    *em = IrrAddParticleEmitter(*ParticlesNode, @FireEmitter)

    *em = IrrCreateParticleEmitter(*ParticlesNode, @FireEmitter)    
    *em2 = IrrCreateEmitterManager(*em, 10,100, -200.0, 200.0, 0.5, 1.0, 1.0, 4.0,0, -20, 20)
    IrrSetParticleEmitter(*ParticlesNode,  *em2)    


    IrrAddGravityParticleAffector(*ParticlesNode, 0,0.06,0,1000)
    IrrAddFadeOutParticleAffector(*ParticlesNode )

    IrrSetNodeMaterialFlag( *ParticlesNode, #IRR_EMF_LIGHTING, #IRR_OFF )
    IrrSetNodeMaterialFlag( *ParticlesNode, #IRR_EMF_ZBUFFER, #False)
    IrrSetNodeMaterialType ( *ParticlesNode, #IRR_EMT_TRANSPARENT_ADD_COLOR  ) ; uncomment me... ;)
    *ParticleTexture = IrrGetTexture( "..\media\Fire.jpg" )
    IrrSetNodeMaterialTexture( *ParticlesNode, *ParticleTexture, 0 )
    IrrSetNodeMaterialType ( *ParticlesNode, #IRR_EMT_TRANSPARENT_VERTEX_ALPHA  ) ; uncomment me... ;)
;    IrrSetNodeMaterialType ( *ParticlesNode, #IRR_EMT_TRANSPARENT_ALPHA_CHANNEL  ) ; uncomment me... ;)
  

    IrrAddStopParticleAffector(*ParticlesNode, 3000)
    IrrAddDeleteAnimator(*ParticlesNode, 5000)     

EndProcedure 

Procedure Crash()
  Shared *camera  
  IrrSetNodePosition(*camera,400,600,400)

 *ParticlesNode = IrrAddParticleSystemToScene( #IRR_NO_EMITTER )
  
  IrrSetNodeScale(*ParticlesNode, 1,1,1)
  
  IrrSetParticleSize(*ParticlesNode,50,50)
   
  Define CrashEmitter.IRR_PARTICLE_EMITTER    
  
  With CrashEmitter
    \min_box_x = -20
    \min_box_y = -1
    \min_box_z = -20
    \max_box_x = 20
    \max_box_y = 10
    \max_box_z = 20

    \direction_x = 0.0
    \direction_y = 1.2
    \direction_z = 0.0
    \min_paritlcles_per_second = 10
    \max_paritlcles_per_second = 70
    \min_start_color_red = 255
    \min_start_color_green = 255
    \min_start_color_blue = 255
    \max_start_color_red = 64
    \max_start_color_green = 64
    \max_start_color_blue = 64
    \min_lifetime = 8000
    \max_lifetime = 10000
    \max_angle_degrees = 60
   EndWith  
   
   
    *em = IrrCreateParticleEmitter(*ParticlesNode, @CrashEmitter)    
    *em2 = IrrCreateEmitterManager(*em, 1,2, -200.0, 200.0, 0.5, 5.0, 1.0, 4.0,0, -20, 20)
    IrrSetParticleEmitter(*ParticlesNode,  *em2)    
   
   
   ; *em = IrrAddParticleEmitter(*ParticlesNode, @CrashEmitter)



    IrrSetNodeMaterialFlag( *ParticlesNode, #IRR_EMF_LIGHTING, #IRR_OFF )
    IrrSetNodeMaterialFlag( *ParticlesNode, #IRR_EMF_ZBUFFER, #False)
;    IrrSetNodeMaterialType ( *ParticlesNode, #IRR_EMT_TRANSPARENT_ADD_COLOR  ) ; uncomment me... ;)
    IrrSetNodeMaterialType ( *ParticlesNode, #IRR_EMT_TRANSPARENT_ALPHA_CHANNEL  ) ; uncomment me... ;)
    *ParticleTexture = IrrGetTexture( "..\media\Particle-011x.png" )
    IrrSetNodeMaterialTexture( *ParticlesNode, *ParticleTexture, 0 )
    ;IrrSetNodeMaterialType ( *ParticlesNode, #IRR_EMT_TRANSPARENT_VERTEX_ALPHA  ) ; uncomment me... ;)
  

    IrrAddGravityParticleAffector(*ParticlesNode, 0,-1.9,0,1000)
    IrrAddCollisionParticleAffector(*ParticlesNode, 0,0.0,0, 0,1,0)
    IrrAddSPinParticleAffector(*ParticlesNode, 2)  

    IrrAddStopParticleAffector(*ParticlesNode, 300)
    IrrAddDeleteAnimator(*ParticlesNode, 3000)     
    
    ;bigger ones
;     *ParticlesNode = IrrAddParticleSystemToScene( #IRR_NO_EMITTER )  
;     IrrSetNodeScale(*ParticlesNode, 1,1,1)  
;     IrrSetParticleSize(*ParticlesNode,120,100)
;     *em = IrrAddParticleEmitter(*ParticlesNode, @CrashEmitter)
; 
;     IrrAddGravityParticleAffector(*ParticlesNode, 0,-1.2,0,1000)
;     IrrSetNodeMaterialFlag( *ParticlesNode, #IRR_EMF_LIGHTING, #IRR_OFF )
;     IrrSetNodeMaterialType ( *ParticlesNode, #IRR_EMT_TRANSPARENT_ALPHA_CHANNEL  ) ; uncomment me... ;)
;     *ParticleTexture = IrrGetTexture( "..\media\Particle-011x.png" )
;     IrrSetNodeMaterialTexture( *ParticlesNode, *ParticleTexture, 0 )
;     
;     IrrAddCollisionParticleAffector(*ParticlesNode, 0,0.0,0, 0,1,0)
;     IrrAddSPinParticleAffector(*ParticlesNode, 2)  
;     IrrAddStopParticleAffector(*ParticlesNode, 300)
;     IrrAddDeleteAnimator(*ParticlesNode, 3000)     

    
    ; now a little smoky...
 *ParticlesNode = IrrAddParticleSystemToScene( #IRR_NO_EMITTER )
  
  IrrSetNodeScale(*ParticlesNode, 1,1,1)
  
  IrrSetParticleSize(*ParticlesNode,200,200)
   
  Define SmokeEmitter.IRR_PARTICLE_EMITTER    
  
  With SmokeEmitter
    \min_box_x = -100
    \min_box_y = -80
    \min_box_z = -100
    \max_box_x = 100
    \max_box_y = 100
    \max_box_z = 100

    \direction_x = 0.0
    \direction_y = 0.0
    \direction_z = 0.0
    \min_paritlcles_per_second = 60
    \max_paritlcles_per_second = 100
    \min_start_color_red = 255
    \min_start_color_green = 255
    \min_start_color_blue = 255
    \max_start_color_red = 255
    \max_start_color_green = 255
    \max_start_color_blue = 255
    \min_lifetime = 500
    \max_lifetime = 500
    \max_angle_degrees = 180
   EndWith  
   
    *em = IrrAddParticleEmitter(*ParticlesNode, @SmokeEmitter)

    IrrAddGravityParticleAffector(*ParticlesNode, 0,0.06,0,1000)
    IrrAddFadeOutParticleAffector(*ParticlesNode )

    IrrSetNodeMaterialFlag( *ParticlesNode, #IRR_EMF_LIGHTING, #IRR_OFF )
    IrrSetNodeMaterialFlag( *ParticlesNode, #IRR_EMF_ZBUFFER, #False)
    IrrSetNodeMaterialType ( *ParticlesNode, #IRR_EMT_TRANSPARENT_ADD_COLOR  ) ; uncomment me... ;)
    *ParticleTexture = IrrGetTexture( "..\media\Smoke.png" )
    IrrSetNodeMaterialTexture( *ParticlesNode, *ParticleTexture, 0 )
    IrrSetNodeMaterialType ( *ParticlesNode, #IRR_EMT_TRANSPARENT_VERTEX_ALPHA  ) ; uncomment me... ;)
  

    IrrAddStopParticleAffector(*ParticlesNode, 300)
    IrrAddDeleteAnimator(*ParticlesNode, 5000)     
    
    
    
    

EndProcedure 


Procedure Explosion()
  Shared *camera  
  IrrSetNodePosition(*camera,400,000,400)


    
    ; now a little smoky...
 *ParticlesNode = IrrAddParticleSystemToScene( #IRR_NO_EMITTER )
  
  IrrSetNodeScale(*ParticlesNode, 1,1,1)
;  IrrSetNodePosition(*ParticlesNode,0,0,60)
;  
  IrrSetParticleSize(*ParticlesNode,160,160)
   
  Define SmokeEmitter.IRR_PARTICLE_EMITTER    
  
  With SmokeEmitter
    \min_box_x = -15
    \min_box_y = -1
    \min_box_z = -13
    \max_box_x = 13
    \max_box_y = 1
    \max_box_z = 14

    \direction_x = 0.1
    \direction_y = 0.1
    \direction_z = 0.1
    \min_paritlcles_per_second = 200
    \max_paritlcles_per_second = 200
    \min_start_color_red = 255
    \min_start_color_green = 255
    \min_start_color_blue = 255
    \max_start_color_red = 255
    \max_start_color_green = 255
    \max_start_color_blue = 255
    \min_lifetime = 800
    \max_lifetime = 1200
    \max_angle_degrees = 0
   EndWith  
   
    *em = IrrAddParticleEmitter(*ParticlesNode, @SmokeEmitter)

    IrrAddGravityParticleAffector(*ParticlesNode, 0,0.05,00.0,10)
    IrrAddFadeOutParticleAffector(*ParticlesNode )

    IrrSetNodeMaterialFlag( *ParticlesNode, #IRR_EMF_ZBUFFER, #False)
    IrrSetNodeMaterialFlag( *ParticlesNode, #IRR_EMF_LIGHTING, #IRR_OFF )
    IrrSetNodeMaterialType ( *ParticlesNode, #IRR_EMT_TRANSPARENT_ADD_COLOR  ) ; uncomment me... ;)
    IrrSetNodeMaterialType ( *ParticlesNode, #IRR_EMT_TRANSPARENT_ALPHA_CHANNEL  ) ; uncomment me... ;)
    *ParticleTexture = IrrGetTexture( "..\media\Smoke.png" )
    IrrSetNodeMaterialTexture( *ParticlesNode, *ParticleTexture, 0 )
    IrrSetNodeMaterialType ( *ParticlesNode, #IRR_EMT_TRANSPARENT_VERTEX_ALPHA  ) ; uncomment me... ;)
  

    IrrAddStopParticleAffector(*ParticlesNode, 30)
    IrrAddDeleteAnimator(*ParticlesNode, 5000)     
    


 *ParticlesNode = IrrAddParticleSystemToScene( #IRR_NO_EMITTER )
  
  IrrSetNodeScale(*ParticlesNode, 1,1,1)
  
  IrrSetParticleSize(*ParticlesNode,200,200)
   
  Define ExplosionEmitter.IRR_PARTICLE_EMITTER    
  
  With ExplosionEmitter
    \min_box_x = -20
    \min_box_y = -20
    \min_box_z = -10
    \max_box_x = 20
    \max_box_y = 20
    \max_box_z = 20

    \direction_x = 0.03
    \direction_y = 0.0
    \direction_z = 0.01
    \min_paritlcles_per_second = 30
    \max_paritlcles_per_second = 43
    \min_start_color_red = 255
    \min_start_color_green = 255
    \min_start_color_blue = 255
    \max_start_color_red = 80
    \max_start_color_green = 4
    \max_start_color_blue = 6
    \min_lifetime = 500
    \max_lifetime = 500
    \max_angle_degrees = 360
   EndWith  
   
    *em = IrrAddParticleEmitter(*ParticlesNode, @ExplosionEmitter)

    IrrAddGravityParticleAffector(*ParticlesNode, 0,0,0,1000)
;    IrrAddFadeOutParticleAffector(*ParticlesNode )

    IrrSetNodeMaterialFlag( *ParticlesNode, #IRR_EMF_LIGHTING, #IRR_OFF )
    IrrSetNodeMaterialType ( *ParticlesNode, #IRR_EMT_TRANSPARENT_ADD_COLOR  ) ; uncomment me... ;)
    IrrSetNodeMaterialFlag( *ParticlesNode, #IRR_EMF_ZBUFFER, #False)
    *ParticleTexture = IrrGetTexture( "..\media\fire.jpg" )
    IrrSetNodeMaterialTexture( *ParticlesNode, *ParticleTexture, 0 )
   ;IrrSetNodeMaterialType ( *ParticlesNode, #IRR_EMT_TRANSPARENT_VERTEX_ALPHA  ) ; uncomment me... ;)
  

    IrrAddStopParticleAffector(*ParticlesNode, 300)
    IrrAddDeleteAnimator(*ParticlesNode, 3000)     
;     
;     ;bigger ones
;     *ParticlesNode = IrrAddParticleSystemToScene( #IRR_NO_EMITTER )  
;     IrrSetNodeScale(*ParticlesNode, 1,1,1)  
;     IrrSetParticleSize(*ParticlesNode,120,100)
;     *em = IrrAddParticleEmitter(*ParticlesNode, @CrashEmitter)
; 
;     IrrAddGravityParticleAffector(*ParticlesNode, 0,-1.2,0,1000)
;     IrrSetNodeMaterialFlag( *ParticlesNode, #IRR_EMF_LIGHTING, #IRR_OFF )
;     IrrSetNodeMaterialType ( *ParticlesNode, #IRR_EMT_TRANSPARENT_ALPHA_CHANNEL  ) ; uncomment me... ;)
;     *ParticleTexture = IrrGetTexture( "..\media\Particle-011x.png" )
;     IrrSetNodeMaterialTexture( *ParticlesNode, *ParticleTexture, 0 )
;     
;     IrrAddCollisionParticleAffector(*ParticlesNode, 0,0.0,0, 0,1,0)
;   
;     IrrAddStopParticleAffector(*ParticlesNode, 300)
;     IrrAddDeleteAnimator(*ParticlesNode, 3000)     
; 
;ProcedureReturn


    
    
    
    

EndProcedure 



Procedure Attract()

  Shared *camera  
  IrrSetNodePosition(*camera,400,600,400)

  *ParticlesNode = IrrAddParticleSystemToScene( #IRR_NO_EMITTER )
  
  IrrSetNodeScale(*ParticlesNode, 1,1,1)
  
  IrrSetParticleSize(*ParticlesNode,100,100)
   
  Define AttractEmitter.IRR_PARTICLE_EMITTER    
  
  With AttractEmitter
    \min_box_x = -20
    \min_box_y = -1
    \min_box_z = -20
    \max_box_x = 20
    \max_box_y = 10
    \max_box_z = 20

    \direction_x = 0.0
    \direction_y = 0.0
    \direction_z = 0.0
    \min_paritlcles_per_second = 600
    \max_paritlcles_per_second = 600
    \min_start_color_red = 255
    \min_start_color_green = 255
    \min_start_color_blue = 255
    \max_start_color_red = 255
    \max_start_color_green = 255
    \max_start_color_blue = 255
    \min_lifetime = 1200
    \max_lifetime = 1500
    \max_angle_degrees = 0
   EndWith  
   
    ;*em = IrrAddParticleEmitter(*ParticlesNode, @AttractEmitter)
    *em = IrrAddParticleRingEmitter(*ParticlesNode, @AttractEmitter, 0,0,0, 200, 1)    

    IrrAddGravityParticleAffector(*ParticlesNode, 0,-0.6,0,1000)
    IrrAddFadeOutParticleAffector(*ParticlesNode )

    IrrAddAttractionParticleAffector(*ParticlesNode , 0,0,0, 700.0, #False, #True, #True, #True)
;;    IrrAddAttractionParticleAffector(*ParticlesNode , 200,300,0, 700.0, #True, #True, #True, #True)

    IrrSetNodeMaterialFlag( *ParticlesNode, #IRR_EMF_ZBUFFER, #False)
    IrrSetNodeMaterialFlag( *ParticlesNode, #IRR_EMF_LIGHTING, #IRR_OFF )
    IrrSetNodeMaterialType ( *ParticlesNode, #IRR_EMT_TRANSPARENT_ADD_COLOR  ) ; uncomment me... ;)
    *ParticleTexture = IrrGetTexture( "..\media\Spark.jpg" )
    IrrSetNodeMaterialTexture( *ParticlesNode, *ParticleTexture, 0 )
    IrrSetNodeMaterialType ( *ParticlesNode, #IRR_EMT_TRANSPARENT_VERTEX_ALPHA  ) ; uncomment me... ;)
  

    IrrAddStopParticleAffector(*ParticlesNode, 1000)
    IrrAddDeleteAnimator(*ParticlesNode, 2000)     



EndProcedure 



Procedure Aligned()
  Shared *camera  
  IrrSetNodePosition(*camera,400,000,400)

 *ParticlesNode = IrrAddParticleSystemToScene( #IRR_NO_EMITTER )
  
  IrrSetNodeScale(*ParticlesNode, 1,1,1)
  
  IrrSetParticleSize(*ParticlesNode,100,100)
   
  Define AlignEmitter.IRR_PARTICLE_EMITTER    
  
  With AlignEmitter
    \min_box_x = -20
    \min_box_y = -10
    \min_box_z = -20
    \max_box_x = 20
    \max_box_y = 10
    \max_box_z = 20

    \direction_x = 0.5
    \direction_y = 0.2
    \direction_z = 0.0
    \min_paritlcles_per_second = 3000
    \max_paritlcles_per_second = 3000
    \min_start_color_red = 180
    \min_start_color_green = 128
    \min_start_color_blue = 128
    \max_start_color_red = 0
    \max_start_color_green = 0
    \max_start_color_blue = 64
    \min_lifetime = 1200
    \max_lifetime = 1500
    \max_angle_degrees = 88
   EndWith  
   
;    *em = IrrAddParticleEmitter(*ParticlesNode, @FireEmitter)

    *em = IrrCreateParticleEmitter(*ParticlesNode, @AlignEmitter)    
    *em2 = IrrCreateEmitterManager(*em, 1,2, 0,0.01, 0.5, 1.0, 1.0, 4.0,0, 0,0)
    IrrSetParticleEmitter(*ParticlesNode,  *em2)    


    IrrAddGravityParticleAffector(*ParticlesNode, 0,-2,0,1000)
    IrrAddAttractionParticleAffector(*ParticlesNode , 0,0,0, 70.0, #False, #True, #True, #True)
    IrrAddAlignParticleAffector(*ParticlesNode ,0.0)
   IrrAddFadeOutParticleAffector(*ParticlesNode )

    IrrSetNodeMaterialFlag( *ParticlesNode, #IRR_EMF_ZBUFFER, #False)
    IrrSetNodeMaterialFlag( *ParticlesNode, #IRR_EMF_LIGHTING, #IRR_OFF )
    IrrSetNodeMaterialType ( *ParticlesNode, #IRR_EMT_TRANSPARENT_ADD_COLOR  ) ; uncomment me... ;)
    *ParticleTexture = IrrGetTexture( "..\media\Spark.png" )
    IrrSetNodeMaterialTexture( *ParticlesNode, *ParticleTexture, 0 )
    IrrSetNodeMaterialType ( *ParticlesNode, #IRR_EMT_TRANSPARENT_VERTEX_ALPHA  ) ; uncomment me... ;)
;    IrrSetNodeMaterialType ( *ParticlesNode, #IRR_EMT_TRANSPARENT_ALPHA_CHANNEL  ) ; uncomment me... ;)
  

    IrrAddStopParticleAffector(*ParticlesNode, 1000)
    IrrAddDeleteAnimator(*ParticlesNode, 3000)     
EndProcedure

; jaPBe Version=3.7.2.629
; Build=0
; FirstLine=23
; CursorPosition=44
; ExecutableFormat=Windows
; DontSaveDeclare
; IDE Options = PureBasic 4.10 Beta 3 (Windows - x86)
; ExecutableFormat = Console
; CursorPosition = 424
; FirstLine = 392
; Folding = --
; Executable = L:\tmp\PartikelDemo\ParticleDemo.exe
; DisableDebugger