'' ----------------------------------------------------------------------------
'' Irrlicht Wrapper For Imperative Languages - Freebasic Examples
'' Frank Dodd (2006)
'' ----------------------------------------------------------------------------
'' Blitz-Irrlicht 1.8.3 Interface by Ed Musolino (AquaLung 2015)
'' ----------------------------------------------------------------------------
'' Example 67: Push Particle Effect
'' This example creates a particle system To demonstrate particle system effects
'' ----------------------------------------------------------------------------

'' ////////////////////////////////////////////////////////////////////////////
'' 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 67: Push Particle Effect" )

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


' add a particle system To the irrlicht scene manager, a Default emitter is Not
' created as we will define our own. the particle system is blank at the moment
'SmokeParticles.IRR_PARTICLE_EMITTER = New IRR_PARTICLE_EMITTER
SmokeParticles = iCreateParticleSystem( IRR_NO_EMITTER,0,-1,0,0,0,0,0,0,1,1,1 )

' here we define the particle emitter, a particle emitter is a mechanism that
' creates the particles over time And destroys them when their lifetime runs
' out. The parameters Include: a box that defines the volume in which particles
' are created - the larger the box the more diffuse the particle cloud, a
' direction that determines where the particles drift off too, a range that
' defines hoe many particles will be generated each second, a colour range that
' determines a random tint that is applied To the particles, a range that
' determines the lifespan of the particles - the large the values the longer
' And larger (And slower) your particle cloud will be And finally an angle that 
' defines a cone around your direction that is the maximum deviation from the
' direction the particles can take - values here make your particles billow
' outward

' finally we add this particle emitting Object To the particle system
SmokeEmitter = iCreateParticleEmitter( SmokeParticles, -7, 0, -7, 7, 1, 7, 0, 0.04, 0, 80, 100, 255, 255, 255, 255, 255, 255, 800, 2000, 15.0, 15.0, 15.0, 15.0, 15 )

' an affector is a mechanism that alters the particles over time, the fade out
' affector gradually fades the particles out so they are invisible when they
' are deleted this lets them smoothly vanish instead of poping out of existence
iFadeOutAffector( SmokeParticles, 2000, 16,8,0 )

' another affector is the gravity affector, this adds a small amount of velocity
' To the particles each frame, although its called a gravity affector it can
' be used To push the particles in any direction so you can have drifting smoke
' bubbling fountains, etc ...
iGravityAffector ( SmokeParticles, 0.05, 0.05, 0.0, 1.0 )

' another affector is the attractor that can be used To attract Or repel
' particles To a particular point
iAttractionAffector ( SmokeParticles, 10.0, 0.0, 0.0, 20.0, IRR_REPEL, 1, 1, 1 )

iRotationAffector ( SmokeParticles, 0.0, -120.0, 0.0, 0.0,0.0,0.0 )

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

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

ParticlesNode = SmokeParticles

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

' out particle system is Not affected by lighting so we make it Self
' illuminating
iNodeMaterialFlag( ParticlesNode, 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 ( ParticlesNode, 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 )

' clear the canvas To black To show the particles up better
iCameraCLSColor( 128, 128, 128 )

' -----------------------------------------------------------------------------
' While the irrlicht environment is still running
While iRun() And (Not iKeyHit( KEY_ESCAPE ))
    ' begin the scene
    iBeginScene()

    ' draw the scene
    iDrawScene()

    ' End drawing the scene And display it
    iEndScene()
Wend

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

End
