'' ----------------------------------------------------------------------------
'' Irrlicht Wrapper For Imperative Languages - Freebasic Examples
'' Frank Dodd (2006-2010)
'' ----------------------------------------------------------------------------
'' Blitz-Irrlicht 1.8.3 Interface by Ed Musolino (AquaLung 2015)
'' ----------------------------------------------------------------------------
'' Example 05: BSP Map
'' This example loads a BSP map from a pk3 archive And creates a first person
'' perspective camera so you can move around And view the map with the mouse And
'' the arrow keys
'' ----------------------------------------------------------------------------

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

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

' irrlicht objects
Global BSPMesh:Int
Global BSPNode:Int
Global Camera:Int
Global CameraNode:Int

'' ////////////////////////////////////////////////////////////////////////////
' start the irrlicht interface
iIrr3D( 1280, 720, 32, False )

' send the window caption
iAppTitle( "Example 05: BSP Map" )

' first we add the pk3 archive To our filing system. once we have done this
' we can open any of the files in the archive as If they were in the Current
' working directory
iAddZipFile( "./media/map-20kdm2.pk3", IRR_IGNORE_CASE, IRR_IGNORE_PATHS, "" )

' Load the BSP map from the archive as a mesh Object. any polygons in the mesh
' that do Not have textures will be removed from the scene!
BSPMesh = iLoadOctreeMesh( "20kdm2.bsp" )

' add the map To the scene as a node. when adding the mesh this call uses a 
' mechanism called an octtree that If very efficient at rendering large amounts
' of complext geometry most of which cant be seen, using this call For maps
' will greatly improve your framerates
BSPNode = iAddOctreeMeshNode( BSPMesh )

' add a first person perspective camera into the scene that is controlled with
' the mouse And the cursor keys. If however you capture events when starting
' irrlicht this will become a normal camera that can only be moved by code
Camera = iCreateFPSCamera(0,100.0,0.5,-1,0,0,0,0.0)

' reposition And rotate the camera To look at a nice part of the map
iPositionNode( Camera, 1750, 149, 1369 )
iRotateNode( Camera, 4, -461.63, 0 )

' hide the mouse pointer
iHideMouse()

' erase the canvas with sky-blue Before rendering
iCameraCLSColor( 128, 255, 255 )

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