'' ----------------------------------------------------------------------------
'' Irrlicht Wrapper For Imperative Languages - Freebasic Examples
'' Frank Dodd (2006)
'' ----------------------------------------------------------------------------
'' Blitz-Irrlicht 1.8.3 Interface by Ed Musolino (AquaLung 2015)
'' ----------------------------------------------------------------------------
'' Example 109 : Beam node
'' This example demonstrates the beam node
'' ----------------------------------------------------------------------------

'' ////////////////////////////////////////////////////////////////////////////
'' Includes For extension libraries
Framework usr.birrlicht
Import brl.retro

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

' irrlicht objects
Global MD2Mesh:Int
Global MeshTexture:Int
Global SceneNode:Int
Global OurCamera:Int


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

' set the window caption
iAppTitle( "Example 109: Beam node" )

' Load texture resources For texturing the scene nodes
MeshTexture = iLoadTexture( "./media/beam.png" )

' add a New beam node To the scene
SceneNode = iCreateBeam()

' apply a material To the node To give its surface color
iNodeTexture( SceneNode, MeshTexture, 0 )

' use transparency with this billboard Type node
iNodeMaterialType ( SceneNode, IRR_EMT_TRANSPARENT_ADD_COLOR )

' add a camera into the scene, the first co-ordinates represents the 3D
' location of our view point into the scene the second co-ordinates specify the
' target point that the camera is looking at
OurCamera = iCreateCamera( False )
iPositionNode( OurCamera, 50, 0, 0 )

' generate an initial random position
x# = -400
y# = Rnd(-20,20)
z# = Rnd(-20,20)

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

        ' begin the scene
        iBeginScene()

        ' set the beam position
        x = x + 2
        iPositionBeam( Scenenode, x, y, z,  x + 100, y, z )

        ' If the beam exceeds 600 restart it
        If x > 200 Then
            x = - 400
            y = Rnd(-20,20)
            z = Rnd(-20,20)

        	' set the beam size
			size# = Rnd(.1,2)
        	iBeamSize( Scenenode, size )

        EndIf

        ' draw the scene
        iDrawScene()
        
        ' End drawing the scene And render it
        iEndScene()

Wend

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

End
