'' ----------------------------------------------------------------------------
'' Irrlicht Wrapper For Imperative Languages - Freebasic Examples
'' Frank Dodd (2006)
'' ----------------------------------------------------------------------------
'' Blitz-Irrlicht 1.8.3 Interface by Ed Musolino (AquaLung 2015)
'' ----------------------------------------------------------------------------
'' Example 29 : Skydome
'' This example adds a skydome around the whole scene that makes a backdrop
'' For your scene To be rendered against
'' ----------------------------------------------------------------------------

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

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

' irrlicht objects
Global SkyDome:Int
Global SkyBox:Int
Global Camera:Int
Global tex:Int
Global tex2:Int


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

' send the window caption
iAppTitle( "Example 29: Skydome Day \ Night" )

' the skydome is a simple hollow sphere that surrounds the whole scene. a single
' texture is applied To the entire surface of the sphere.
tex = iLoadTexture("./media/Sky_horiz_6-2048.jpg")
tex2 = iLoadTexture("./media/Copy of stars_.bmp")

' Create a sphere
SkyDome = iCreateSphere( 16, False )

' texture the sphere
iNodeTexture( SkyDome, tex, 0 )
iNodeMaterialType( SkyDome, IRR_EMT_TRANSPARENT_ADD_COLOR )

' turn on lighting on the sphere
iNodeMaterialFlag( SkyDome, IRR_EMF_LIGHTING, True )

' turn on lighting on the sphere
iNodeMaterialFlag( SkyDome, IRR_EMF_LIGHTING, True )

' lets make is big
iScaleNode( SkyDome, 3000, 3000, 3000 )

' Flip the sphere inside out
iFlipNodeMesh( SkyDome )

' add skybox For night sky
SkyBox = iCreateSkybox(tex2,tex2,tex2,tex2,tex2,tex2)
iNodeMaterialType( SkyBox, IRR_EMT_TRANSPARENT_ADD_COLOR )

' we add a first person perspective camera To the scene so you can look about
Camera = iCreateFPSCamera(0,100.0,0.5,-1,0,0,0,0.0)

' hide the mouse pointer
iHideMouse()

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

iAmbientLight(1,1,1)

' -----------------------------------------------------------------------------
' While the irrlicht environment is still running
SunLight# = 1.0
Day = False
While iRun() And (Not iKeyHit( KEY_ESCAPE ))

    ' begin the scene
    iBeginScene()

'	day \ night cycle
	If Day Then	SunLight = SunLight + 0.005
	If Day And SunLight > 1.0 Then Day = False ; SunLight = 1.0
	If (Not Day) Then SunLight = SunLight - 0.005
	If (Not Day) And SunLight < 0.0 Then Day = True ; SunLight = 0.0
	iAmbientLight( SunLight, SunLight, SunLight )
		
    ' draw the scene
	' first lets center the skydome on the camera
	iPositionNode( SkyDome, iNodeX( Camera, True ), iNodeY( Camera, True ), iNodeZ( Camera, True ) )

    iDrawScene()

    ' End drawing the scene And render it
    iEndScene()

Wend 

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


End