'' ----------------------------------------------------------------------------
'' Irrlicht Wrapper For Imperative Languages - Freebasic Examples
'' Frank Dodd (2006)
'' ----------------------------------------------------------------------------
'' Blitz-Irrlicht 1.8.3 Interface by Ed Musolino (AquaLung 2015)
'' ----------------------------------------------------------------------------
'' Example 75: Push Particle Explosion
'' This example demonstrates the use of the push particle affector To Create a
'' flash explosion like effect.
'' ----------------------------------------------------------------------------

'' ////////////////////////////////////////////////////////////////////////////
'' Includes For extension libraries
Framework usr.birrlicht


'' ////////////////////////////////////////////////////////////////////////////
'' Global variables

' irrlicht objects
Global ParticleTexture:Int
Global SmokeParticles:Int
Global SmokeEmitter:Int
Global ParticlesNode:Int
Global TestNode:Int
Global Camera:Int
Global FadeOut:Int
Global fade:Float

'' ////////////////////////////////////////////////////////////////////////////
' start the irrlicht interface
iVSync( True )
iIrr3D( 800, 600, 32, False )

' send the window caption
iAppTitle( "Example 75: Push Particle Explosion" )

' this adds a small test node To the scene, a test node is a simple cube, that
' you can move And texture like any other Object however there is another
' reason For adding this node. the particle system needs another node rendered
' onto the display To allow it To display material effects. this may be an issue
' with the wrapper that needs investigation
TestNode = iCreateCube( 8, False )

' set up a particle system that generates a stream of smoke please see example
' Seven For detailed information
SmokeParticles = iCreateParticleSystem( False,0,-1,0,0,0,0,0,0,1,1,1 )

' finally we add this particle emitting Object To the particle system along
' with a series of affectors
SmokeEmitter = iCreateParticleEmitter( SmokeParticles, -7, 0, -7, 7, 7, 7, 0, 0, 0, 2000, 2000, 255, 255, 255, 255, 255, 255, 300, 300, 15.0, 15.0, 15.0, 15.0, 15 )

iFadeOutAffector( SmokeParticles, 2000, 16,8,0 )

' push the particles upward For 100 units above the affector
iPushAffector ( SmokeParticles, 0, 0, 0, 300, 300, 300, 50, 0.0, 0.0, True )

' Load a grey smoke like image For the particle
ParticleTexture = iLoadTexture( "./media/ParticleGrey.bmp" )

SmokeParticlesNode = SmokeParticles

' apply the texture To the particles system, this texture will now be drawn
' across each particles surface
iNodeTexture( SmokeParticlesNode, ParticleTexture, 0 )

' out particle system is Not affected by lighting so we make it Self
' illuminating
iNodeMaterialFlag( SmokeParticlesNode, IRR_EMF_LIGHTING, False )

' as the particle texture has black borders, each overlapping particle would
' draw this blackness ontop of one another as a sharp egde they would look like
' a lot of solid squares instead of the transparent gas effect we are trying
' To created. so here we change the material Type of the node - instead of
' drawing the node solidly onto the screen it is added onto the colour
' underneath itself so black doesnt change the color And white would build up
' top of the existing color Until it completly saturates the pixel
iNodeMaterialType ( SmokeParticlesNode, IRR_EMT_TRANSPARENT_ADD_COLOR )

' 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 = iCreateCamera( False )
iPositionNode( Camera, 100, 40, 0 )
iCameraTarget( Camera, 0, 40, 0 )
iCameraCLSColor( 128, 128, 128 )

' -----------------------------------------------------------------------------
' While the irrlicht environment is still running
StartTime% = iTime()
While iRun() And (Not iKeyHit( KEY_ESCAPE ))
    ' clear the canvas To black To show the particles up better
    iBeginScene()

    ' draw the scene
    iDrawScene()

    ' End drawing the scene And display it
    iEndScene()

    ' Only Create particles For the first second
    If iTime() > StartTime + 500 Then 
        iEmitterMinParticlesPerSecond( SmokeEmitter, 0 )
        iEmitterMaxParticlesPerSecond( SmokeEmitter, 0 )
    End If 

Wend 

' -----------------------------------------------------------------------------
' Stop the irrlicht engine And Release resources
iEndIrr3D()

End