'' ----------------------------------------------------------------------------
'' Irrlicht Wrapper For Imperative Languages - Freebasic Examples
'' Frank Dodd (2006-2010)
'' ----------------------------------------------------------------------------
'' Blitz-Irrlicht 1.8.3 Interface by Ed Musolino (AquaLung 2015)
'' ----------------------------------------------------------------------------
'' Example 51 : Clouds
'' This example demonstrates the billboard cloud objects that are particularly
'' useful For simulating aircraft flying through cloud cover And also For
'' creating a light cloud embelishment For a skydome
'' ----------------------------------------------------------------------------

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

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

' irrlicht objects
Global Terrain:Int
Global TerrainNode:Int
Global TerrainTexture0:Int
Global TerrainTexture1:Int
Global Camera:Int
Global CameraNode:Int
Global CloudTexture:Int
Global CloudNode:Int
Global X:Float
Global Y:Float
Global Z:Float
Global TerrainHeight:Float


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

' send the window caption
iAppTitle( "Example 51: Billboard Clouds by G Davidson" )

' Load the cloud image in as a video texture
CloudTexture = iLoadTexture( "./media/cloud4.png" )

' add the clouds To the scene
' the first parameter is the level of detail, higher values add more structure
' To the cloud when it is closer To the camera
' the second parameter sets the number of child clouds created higher values
' Create more structure
' the third parameter defines how many clouds are created
CloudNode = iCreateClouds( CloudTexture, 3, 1, 500 )

' switch the fog on the clouds To prevent the clouds popping up in the distance
iNodeMaterialFlag( CloudNode, IRR_EMF_FOG_ENABLE, True )

' raise the clouds into the sky
iPositionNode( CloudNode, 0,2700,0 )

' slowly rotate the clouds To simulate drift across the sky
iRotationAnimator( CloudNode, 0, 0.01, 0 )

' we add a terrain To the scene For demonstration purposes, For a detailed
' explaination of the process please refer To example 10
Terrain = iLoadTerrain( "./media/iheight.jpg",0,0,0,0,0,0,1,1,1,255,255,255,255,0,5,ETPS_17 )
TerrainNode = Terrain
iScaleNode( TerrainNode, 40.0, 4.4, 40.0 )
TerrainTexture0 = iLoadTexture( "./media/island.jpg" )
TerrainTexture1 = iLoadTexture( "./media/detailmap3.jpg" )
iNodeTexture( TerrainNode, TerrainTexture0, 0 )
iNodeTexture( TerrainNode, TerrainTexture1, 1 )
iScaleTerrainTexture( Terrain, 1.0, 40.0 )
iNodeMaterialFlag( TerrainNode, IRR_EMF_LIGHTING, False )
iNodeMaterialType ( TerrainNode, IRR_EMT_DETAIL_MAP )
iNodeMaterialFlag( TerrainNode, IRR_EMF_FOG_ENABLE, True )

' add a fog To the scene To gently fade the clouds out in the distance
iCameraFog ( 128,128,255, IRR_EXPONENTIAL_FOG, 0.0,4000.0, 0.5 )

' 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, 3942.8, 1102.7, 5113.9 )
iRotateNode( CameraNode, 19, -185.5, 0 )

' the clipping distance of a camera is a distance beyond which no triangles are
' rendered, this speeds the scene up by Not showing geometry that is in the
' distance And too small To see however our terrain is so huge we need To
' extend this distance out
iCameraRange( Camera, 12000, 1.0 )

iCreateCube( 8, False )

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

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

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

    ' begin the scene
    iBeginScene()

	X = iNodeX( CameraNode, False )
	Z = iNodeZ( CameraNode, False )

    TerrainHeight = iTerrainHeight( TerrainNode, X, Z )
    iPositionNode( CameraNode, X, TerrainHeight + 50, Z )

    ' draw the scene
    iDrawScene()

    ' End drawing the scene And render it
    iEndScene()

Wend

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


End


