;; ----------------------------------------------------------------------------
;; 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"


;; ////////////////////////////////////////////////////////////////////////////
;; Include the Irr3D-Requester
XIncludeFile "Irr3DRequester.pb"


;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 *SparkTexture.irr_texture = #Null



Define *em.l  ; pointer to the Emitter


Declare LoadTextures()

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)
If Irr3DRequester()

   width.l  = irr3DRequesterSetting\videomode\dimension\width
   height.l = irr3DRequesterSetting\videomode\dimension\height

Debug("height="+Str(height))
  ; send the window caption
  IrrSetWindowCaption( "Example : Particle System Demo" )

;  *camera = IrrAddFPSCamera()


  LoadTextures()

  ; 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-8 to see Particle-Effects"+Chr(13)+"Escape to quit", 4,0,width,160, #IRR_GUI_NO_BORDER, #True )
  IrrGuiStaticSetOverrideColor(*stat, 255,255,255)

  *fps = IrrGuiAddStaticText( "FPS", 0,height-30,400,height, #IRR_GUI_NO_BORDER, #True )
  IrrGuiStaticSetOverrideColor(*fps, 255,255,255)

  effect.s = "none"

  ; -----------------------------------------------------------------------------
  ; while the irrlicht environment is still running
  While IrrRunning()
      IrrGuiSetText(*fps, "FPS="+Str(IrrGetFPS()) + " - Effect="+effect)

      ; 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_IS_DOWN
          Select *KeyEvent\key
            Case #IRR_KEY_KEY_1 : effect="Fountain" : Tausend()
            Case #IRR_KEY_KEY_2 : effect="Smoke" : Smoke()
            Case #IRR_KEY_KEY_3 : effect="Psyco" : Sparks()
            Case #IRR_KEY_KEY_4 : effect="Fire" : Fire()
            Case #IRR_KEY_KEY_5 : effect="Crash" : Crash()
            Case #IRR_KEY_KEY_6 : effect="Explosion" : explosion()
            Case #IRR_KEY_KEY_7 : effect="Attract" : Attract()
            Case #IRR_KEY_KEY_8 : effect="Align to Fall" : Aligned()
            Case #IRR_KEY_ESCAPE : IrrStop() : End
          EndSelect
        EndIf
      EndIf


  Wend

  ; -----------------------------------------------------------------------------
  ; Stop the irrlicht engine and release resources
;s  IrrStop()

EndIf

End

Procedure LoadTextures()
  Shared *SparkTexture
  Shared *BallTexture
  Shared *FireTexture
  Shared *SmokeTexture
  Shared *Smoke2Texture
  Shared *FireballTexture
  Shared *StoneTexture
  Shared *BeamTexture
  Shared *Font

  mediadir.s = "media"

  *SparkTexture    = IrrGetTexture( mediadir+"\Spark.png"         )
  *BallTexture     = IrrGetTexture( mediadir+"\Spark.jpg"         )
  *FireTexture     = IrrGetTexture( mediadir+"\fire.jpg"          )
  *FireballTexture = IrrGetTexture( mediadir+"\Fire.bmp"          )
  *SmokeTexture    = IrrGetTexture( mediadir+"\Smoke_2.bmp"         ) ;Smoke.png
  *Smoke2Texture    = IrrGetTexture( mediadir+"\Smoke.png"         ) ;Smoke.png
  *StoneTexture    = IrrGetTexture( mediadir+"\Particle-011x.png" )
  *BeamTexture     = IrrGetTexture( mediadir+"\trail_beam.tga" )

  ; load a bitmap font as a texture
  *Font = IrrGetFont ( mediadir+"\font_arial_18.tga" )

  IrrGuiSetSkinFont(*Font);

EndProcedure
;Effect 1 -
Procedure Tausend()
  Shared *camera
  Shared *FireballTexture

  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)
    IrrSetNodeMaterialTexture( *ParticlesNode, *FireballTexture, 0 )
    IrrSetNodeMaterialType ( *ParticlesNode, #IRR_EMT_TRANSPARENT_VERTEX_ALPHA  ) ; uncomment me... ;)


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

EndProcedure

;Effect 2 -
Procedure Smoke()
  Shared *camera
  Shared *SmokeTexture

  IrrSetNodePosition(*camera,400,0,400)

  *ParticlesNode = IrrAddParticleSystemExtToScene( #IRR_NO_EMITTER )

  IrrSetNodeScale(*ParticlesNode, 1,1,1)

  IrrSetParticleSize(*ParticlesNode,100,100)

  Define SmokeEmitter.IRR_PARTICLE_EMITTER

  With SmokeEmitter
    \min_box_x = -2
    \min_box_y = -1
    \min_box_z = -2
    \max_box_x = 2;    IrrSetParticleEmitter(*ParticlesNode,  *em2)

    \max_box_y = 1
    \max_box_z = 2

    \direction_x = 0.0
    \direction_y = 0.0
    \direction_z = 0.0
    \min_paritlcles_per_second = 30
    \max_paritlcles_per_second = 40
    \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 = 180
   EndWith


    *em = IrrCreateParticleEmitter(*ParticlesNode, @SmokeEmitter)

;    *ps2 = IrrCreateParticleSystemExt(*em, 10,40, -200.0, 200.0, 0.5, 3.0, 1.0, 4.0, 0, -200.0,200.0)

    IrrPSExtSetInitalDelay(*ParticlesNode,0)
    IrrPSExtSetScaleRange(*ParticlesNode,2,3.0)
    IrrPSExtSetRotationRange(*ParticlesNode,-20,20)
    IrrPSExtSetRotationSpeedRange(*ParticlesNode,-200.0, 200.0)
    IrrPSExtSetWeightRange(*ParticlesNode,1.0,4.0)
    IrrPSExtSetEmitterDelayTimes(*ParticlesNode,10,12)
    IrrSetParticleEmitter(*ParticlesNode,  *em)


    IrrAddGravityParticleAffector(*ParticlesNode, 0,0.4,0,1000)
    IrrAddFadeOutParticleAffector(*ParticlesNode )
    IrrAddSpinParticleAffector(*ParticlesNode, 8000)

    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... ;)
    IrrSetNodeMaterialTexture( *ParticlesNode, *SmokeTexture, 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
  Shared *BallTexture
  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... ;)
    IrrSetNodeMaterialTexture( *ParticlesNode, *BallTexture, 0 )
    IrrSetNodeMaterialType ( *ParticlesNode, #IRR_EMT_TRANSPARENT_VERTEX_ALPHA  ) ; uncomment me... ;)


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

EndProcedure

Procedure Fire()
  Shared *camera
  Shared *FireTexture

  IrrSetNodePosition(*camera,400,0,400)

 *ParticlesNode = IrrAddParticleSystemExtToScene( #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 = IrrCreateParticleEmitter(*ParticlesNode, @FireEmitter)
;    *ps2 = IrrCreateParticleSystemExt(*em, 10,100, -200.0, 200.0, 0.5, 1.0, 1.0, 4.0,0, -20, 20)


    IrrPSExtSetInitalDelay(*ParticlesNode,20)
    IrrPSExtSetScaleRange(*ParticlesNode,1.0,1.0)
    IrrPSExtSetRotationRange(*ParticlesNode,0,360)
    IrrPSExtSetRotationSpeedRange(*ParticlesNode,-20.0, 20.0)
    IrrPSExtSetWeightRange(*ParticlesNode,1.0,4.0)
    IrrPSExtSetEmitterDelayTimes(*ParticlesNode,10,100)


    IrrSetParticleEmitter(*ParticlesNode,  *em)


    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... ;)
    IrrSetNodeMaterialTexture( *ParticlesNode, *FireTexture, 0 )
    IrrSetNodeMaterialType ( *ParticlesNode, #IRR_EMT_TRANSPARENT_VERTEX_ALPHA  ) ; uncomment me... ;)


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

EndProcedure

Procedure Crash()
  Shared *camera
  Shared *StoneTexture
  Shared *SmokeTexture

  IrrSetNodePosition(*camera,400,600,400)

 *ParticlesNode = IrrAddParticleSystemExtToScene( #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 = 01.0
    \direction_z = 0.0
    \min_paritlcles_per_second = 20
    \max_paritlcles_per_second = 25
    \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 = 800
    \max_lifetime = 1000
    \max_angle_degrees = 80
   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)


    IrrPSExtSetInitalDelay(*ParticlesNode,20)
    IrrPSExtSetScaleRange(*ParticlesNode,0.5,5.0)
    IrrPSExtSetRotationRange(*ParticlesNode,-359,359)
    IrrPSExtSetRotationSpeedRange(*ParticlesNode,-200.0, 200.0)
    IrrPSExtSetWeightRange(*ParticlesNode,1.0,4.0)
    IrrPSExtSetEmitterDelayTimes(*ParticlesNode,1,2)

    IrrSetParticleEmitter(*ParticlesNode,  *em)



    IrrSetNodeMaterialFlag( *ParticlesNode, #IRR_EMF_LIGHTING, #IRR_OFF )
    IrrSetNodeMaterialFlag( *ParticlesNode, #IRR_EMF_ZBUFFER, #False)
    IrrSetNodeMaterialType ( *ParticlesNode, #IRR_EMT_TRANSPARENT_ALPHA_CHANNEL  ) ; uncomment me... ;)
    IrrSetNodeMaterialTexture( *ParticlesNode, *StoneTexture, 0 )


    IrrAddGravityParticleAffector(*ParticlesNode, 0,-0.7,0,1000)

    ;IrrAddBounceParticleAffector(*ParticlesNode, 0,-5.0,0, 0,1,0, 3.0)

    IrrAddCollisionParticleAffector(*ParticlesNode, 0,-5.0,0, 0,1,0)


    IrrAddSPinParticleAffector(*ParticlesNode, 2)

    IrrAddStopParticleAffector(*ParticlesNode, 500)
    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... ;)
    IrrSetNodeMaterialTexture( *ParticlesNode, *SmokeTexture, 0 )
    IrrSetNodeMaterialType ( *ParticlesNode, #IRR_EMT_TRANSPARENT_VERTEX_ALPHA  ) ; uncomment me... ;)


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


EndProcedure


Procedure explosion()
  Shared *camera
  Shared *FireTexture
  Shared *Smoke2Texture

  IrrSetNodePosition(*camera,400,000,400)



    ; now a little smoky...
 *ParticlesNode = IrrAddParticleSystemExtToScene( #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 = -10
    \min_box_z = -13
    \max_box_x = 13
    \max_box_y = 10
    \max_box_z = 14

    \direction_x = 0.0
    \direction_y = 0.0
    \direction_z = 0.0
    \min_paritlcles_per_second = 40
    \max_paritlcles_per_second = 40
    \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 = 180
   EndWith

    *em = IrrCreateParticleEmitter(*ParticlesNode, @SmokeEmitter)

;    *em2 = IrrCreateEmitterManager(*em, 1,2, -200.0, 200.0, 1.5, 2.0, 1.0, 4.0,200, -20, 20)

    IrrPSExtSetInitalDelay(*ParticlesNode,200)
    IrrPSExtSetScaleRange(*ParticlesNode,0.5,2.0)
    IrrPSExtSetRotationRange(*ParticlesNode,0,360)
    IrrPSExtSetRotationSpeedRange(*ParticlesNode,-200.0, 200.0)
    IrrPSExtSetWeightRange(*ParticlesNode,1.0,4.0)
    IrrPSExtSetEmitterDelayTimes(*ParticlesNode,1,2)

    IrrSetParticleEmitter(*ParticlesNode,  *em)




    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... ;)
    IrrSetNodeMaterialTexture( *ParticlesNode, *Smoke2Texture, 0 )
    IrrSetNodeMaterialType ( *ParticlesNode, #IRR_EMT_TRANSPARENT_VERTEX_ALPHA  ) ; uncomment me... ;)

    IrrAddAttractionParticleAffector(*ParticlesNode , 0,0,0, 200.0, #False, #True, #True, #True)

    IrrAddSpinParticleAffector(*ParticlesNode, 2)
    IrrAddStopParticleAffector(*ParticlesNode, 50+300)
    IrrAddDeleteAnimator(*ParticlesNode, 5000)



 *ParticlesNode = IrrAddParticleSystemExtToScene( #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 = IrrCreateParticleEmitter(*ParticlesNode, @ExplosionEmitter)

;    *em2 = IrrCreateEmitterManager(*em3, 1,10, -200.0, 200.0, 1.5, 2.0, 1.0, 4.0,0, -20, 20)

    IrrPSExtSetInitalDelay(*ParticlesNode,0)
    IrrPSExtSetScaleRange(*ParticlesNode,1.5,2.0)
    IrrPSExtSetRotationRange(*ParticlesNode,0,360)
    IrrPSExtSetRotationSpeedRange(*ParticlesNode,-20.0, 20.0)
    IrrPSExtSetWeightRange(*ParticlesNode,1.0,4.0)
    IrrPSExtSetEmitterDelayTimes(*ParticlesNode,1,2)

    IrrSetParticleEmitter(*ParticlesNode,  *em)



    IrrAddGravityParticleAffector(*ParticlesNode, 0,0,0,1000)
    IrrAddSpinParticleAffector(*ParticlesNode, 800)
    IrrAddFadeOutParticleAffector(*ParticlesNode )
    IrrAddAttractionParticleAffector(*ParticlesNode , 0,0,0, 200.0, #False, #True, #True, #True)

    IrrSetNodeMaterialFlag( *ParticlesNode, #IRR_EMF_LIGHTING, #IRR_OFF )
    IrrSetNodeMaterialType ( *ParticlesNode, #IRR_EMT_TRANSPARENT_ADD_COLOR  ) ; uncomment me... ;)
    IrrSetNodeMaterialFlag( *ParticlesNode, #IRR_EMF_ZBUFFER, #False)
    IrrSetNodeMaterialTexture( *ParticlesNode, *FireTexture, 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
  Shared *BallTexture

  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 = 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)

    IrrSetNodeMaterialFlag( *ParticlesNode, #IRR_EMF_ZBUFFER, #False)
    IrrSetNodeMaterialFlag( *ParticlesNode, #IRR_EMF_LIGHTING, #IRR_OFF )
    IrrSetNodeMaterialType ( *ParticlesNode, #IRR_EMT_TRANSPARENT_ADD_COLOR  ) ; uncomment me... ;)
    IrrSetNodeMaterialTexture( *ParticlesNode, *BallTexture, 0 )
    IrrSetNodeMaterialType ( *ParticlesNode, #IRR_EMT_TRANSPARENT_VERTEX_ALPHA  ) ; uncomment me... ;)


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



EndProcedure



Procedure Aligned()
  Shared *camera
  Shared *SparkTexture
  Shared *BeamTexture

  IrrSetNodePosition(*camera,400,000,400)

 *ParticlesNode = IrrAddParticleSystemExtToScene( #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.5
    \direction_z = 0.5
    \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 = 255
    \max_start_color_green = 0
    \max_start_color_blue = 64
    \min_lifetime = 1200
    \max_lifetime = 1500
    \max_angle_degrees = 180
   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)

    IrrPSExtSetInitalDelay(*ParticlesNode,0)
    IrrPSExtSetScaleRange(*ParticlesNode,1.5,2.0)
    IrrPSExtSetRotationRange(*ParticlesNode,0,0)
    IrrPSExtSetRotationSpeedRange(*ParticlesNode,0.0, 0.0)
    IrrPSExtSetWeightRange(*ParticlesNode,1.0,4.0)
    IrrPSExtSetEmitterDelayTimes(*ParticlesNode,1,2)

    IrrSetParticleEmitter(*ParticlesNode,  *em)

    IrrAddGravityParticleAffector(*ParticlesNode, 0,-3,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... ;)
    IrrSetNodeMaterialTexture( *ParticlesNode, *BeamTexture, 0 )
    IrrSetNodeMaterialType ( *ParticlesNode, #IRR_EMT_TRANSPARENT_VERTEX_ALPHA  ) ; uncomment me... ;)
;    IrrSetNodeMaterialType ( *ParticlesNode, #IRR_EMT_TRANSPARENT_ALPHA_CHANNEL  ) ; uncomment me... ;)


    IrrAddStopParticleAffector(*ParticlesNode, 100)
    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 = 160
; FirstLine = 160
; Folding = 2-
; Executable = K:\_mt\Temp\ParticleDemo\ParticleDemo.exe
; jaPBe Version=3.7.10.668
; Build=1
; FirstLine=170
; CursorPosition=172
; ExecutableFormat=Windows
; DontSaveDeclare
; EOF