'' ----------------------------------------------------------------------------
'' Irrlicht Wrapper For Imperative Languages - Freebasic Examples
'' Frank Dodd (2006-2010)
'' ----------------------------------------------------------------------------
'' Blitz-Irrlicht 1.8.3 Interface by Ed Musolino (AquaLung 2015)
'' ----------------------------------------------------------------------------
'' Example 55: Zone Management
'' This example demonstrates zone management objects, these are parent objects
'' that manage the visibility of their child objects And can be used To remove
'' numbers of objects out of the visible scene when the camera moves out of
'' visible range
'' ----------------------------------------------------------------------------

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

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

' irrlicht objects
Global Billboard:Int
Global BillboardTexture:Int
Global Camera:Int
Global zone:Int
Global x:Int
Global z:Int
Global n:Int


'' ////////////////////////////////////////////////////////////////////////////
' -----------------------------------------------------------------------------
' start the irrlicht interface
iIrr3D( 1024, 768, 32, False )

' send the window caption
iAppTitle( "Example 55: Zone Management" )

' Load the texture resource For the billboard
BillboardTexture = iLoadTexture( "./media/BlitzLogo_Big.jpg" )

' here we Create 900 zones
For x = -15 To 15
    For z = -15 To 15
        
        ' we add in a zone management Object And set the near distance To 100
        ' And the far distance To 300. the zone management Object will only
        ' be visible If the zone is more than 100 units from the active camera
        ' And less than 300 units away, any child objects of this zone will be
        ' completely unprocessed.
        ' If you set your zone up in conjunction with fog you can have lots of
        ' complex objects in the scene And when the zone they were in was out of
        ' camera range the objects would be completely disabled And have no
        ' impact on the processing of the scene
        ' you could also place a large number of zone managers into another zone
        ' If your environment was sufficiently complex
        ' the near value also allows you To implement a simple level of detail
        ' LOD effect by having a low And high resoloution zones overlapping one
        ' another the high resoloution zone might display from 0 To 100 While
        ' the low resoloution zone displays from 100 To 500
        zone = iCreateZoneMgr(10,300)

        ' here we Create 6 billboards For each zone, this would make nearly 4600
        ' billboards but as only a small set are displayed there is minimal
        ' effect on the speed of the display
        For n = 0 To 5
            Billboard = iCreateBillBoard( 5.0, 5.0, 0, 0, 0 )
            iNodeTexture( Billboard, BillboardTexture, 0 )
            iNodeMaterialFlag( Billboard, IRR_EMF_LIGHTING, IRR_OFF )
            iPositionNode( Billboard, Rnd(50), Rnd(50), Rnd(50) )
            
            ' finally we attach the billboard To the zone as a child And the
            ' billboard is thereafter automatically managed by the zone manager
            iNodeParent( Billboard, zone )
        Next

        iPositionNode( zone, x*100, 0, z*100 )
    Next
Next

' add a first person perspective camera into the scene so we can move around
' the billboard And see how it reacts
Camera = iCreateFPSCamera(0,100,1.0,0,0,0,0,0)


' hide the mouse pointer
iHideMouse()

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 render it
    iEndScene()

Wend

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


End