'' ----------------------------------------------------------------------------
'' Irrlicht Wrapper For Imperative Languages - Freebasic Examples
'' Frank Dodd (2006-2010)
'' ----------------------------------------------------------------------------
'' Blitz-Irrlicht 1.8.3 Interface by Ed Musolino (AquaLung 2015)
'' ----------------------------------------------------------------------------
'' Example 28 : Hillplane
'' This example creates a terrain from a hillplane Object that is a generated
'' mesh grid with an irregular surface.
'' ----------------------------------------------------------------------------

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

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

' irrlicht objects
Global Terrain%
Global TerrainNode%
Global TerrainTexture0%
Global TerrainTexture1%
Global Camera%
Global CameraNode%
Global Hillmesh%
Global HillNode%

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

' send the window caption
iAppTitle( "Example 28: Hill Planes" )


' add a hill plane mesh To the mesh pool And scene
HillMesh = iCreateHillPlaneMesh( "HillPlane", 16.0, 16.0, 64, 64, False, 12.0, 4, 3, 1, 1 )

HillNode = iAddMeshToScene( HillMesh )

' we Load two textures in To apply To the hillplane node
TerrainTexture0 = iLoadTexture( "./media/terrain-texture.jpg" )
TerrainTexture1 = iLoadTexture( "./media/detailmap3.jpg" )

' the first texture is a color texture that is applied across the entire
' surface of the map. this needs To be a fairly high resoloution as the map is
' very large now
iNodeTexture( HillNode, TerrainTexture0, 0 )

' the second texture is tiled many times across the map this adds fine detail
' And structure To the first enlarged terain color
iNodeTexture( HillNode, TerrainTexture1, 1 )

' finally we apply some material texuring effects To the node
' the terrain is Self illuminating
iNodeMaterialFlag( HillNode, IRR_EMF_LIGHTING, IRR_OFF )

' the material Type is detail Type. this Type applies the first texture across
' the entire node And Then scales And applies the second texture across the node
' there are many different material types you can set, these can be found in the
' .bi definition file, experiment with them
iNodeMaterialType ( HillNode, IRR_EMT_DETAIL_MAP )

' we add a first person perspective camera To the scene so you can look about
' And move it into the center of the map
Camera = iCreateFPSCamera(0,100.0,0.5,-1,0,0,0,0.0)
CameraNode = Camera
iPositionNode( CameraNode, 0, 25, 0 )

' we also hide the mouse pointer To see the view better
iHideMouse()

' erase the canvas with sky-blue Before rendering
iCameraCLSColor( 140, 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 render it
    iEndScene()
Wend 

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

End