'' ----------------------------------------------------------------------------
'' Irrlicht Wrapper For Imperative Languages - Freebasic Examples
'' Frank Dodd (2006-2010)
'' ----------------------------------------------------------------------------
'' Blitz-Irrlicht 1.8.3 Interface by Ed Musolino (AquaLung 2015)
'' ----------------------------------------------------------------------------
'' Example 30 : Animated Water Effect
'' This example creates an animated water effect that is applied To a flat
'' hillplane Object. The effect alters the surface of the mesh in a manner that
'' simulates waves on water
'' ----------------------------------------------------------------------------

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

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

' irrlicht objects
Global Terrain:Int
Global TerrainNode:Int
Global TerrainTexture:Int
Global Camera:Int
Global CameraNode:Int
Global WaterMesh:Int
Global WaterNode:Int

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

' send the window caption
iAppTitle( "Example 30: Animated Water Effect" )


' add a hill plane mesh To the mesh pool
WaterMesh = iCreateHillPlaneMesh( "HillPlane", 16.0, 16.0, 64, 64,  0,  0.0, 4, 3, 8, 8 )

' add a scene node For rendering an animated water surface mesh
WaterNode = iCreateWater( WaterMesh,2.0,300.0,10.0,0,-1,0,0,0,0,0,0,1.0,1.0,1.0)

' we Load two textures in To apply To the terrain node
TerrainTexture = iLoadTexture( "./media/water.png" )

' 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( WaterNode, TerrainTexture, 0 )

' finally we apply some material texuring effects To the node
' the water is Self illuminating
iNodeMaterialFlag( WaterNode, IRR_EMF_LIGHTING, False )

' the sphere map material Type gives a shiny effect appropriate For a
' water surface
iNodeMaterialType ( WaterNode, IRR_EMT_SPHERE_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