' ------------------------------------------------------------
'   n3xt-D exemples
'
'   Sample  041  :  terrain with light.
'   Historique  :
'     29/03/09  19:16    TMyke
'
' ------------------------------------------------------------

' Includes libraries
#include "N3xtD.bi"

' Globales
Dim app As any Ptr
Dim Quit As Integer


'----------------------------------------------------------
' open n3xt-D screen
app = _CreateGraphics3D(800,600)
If app=NULL Then
  End
End If

 
'------------------------------------------------------------------------------------
 ' Create light And set position
 Dim  light as LightNode = _CreateLight(&hffffffff, 256.0) 
  _PositionNode(light, 50,100,50)


'------------------------------------------------------------------------------------
Dim terrain as TerrainNode = _CreateTerrain("media/height113.bmp", 1, 2.0, 0.45,2.0, 32)
_TextureTerrain(terrain, 0 , "media/Sol113.jpg")
_TextureTerrain(terrain, 1 , "media/detailmap3.jpg")
_MaterialTypeNode(terrain,  EMT_LIGHTMAP_LIGHTING_M2)

'_DebugModeNode(terrain, TRUE)
'------------------------------------------------------------------------------------


  
  ' Create a camera
Dim cam as CameraNode = _CreateCameraFPS()
_PositionNode(cam, 100,80,100)


  
'-----------------------------------
' Load font png
_LoadFont("media/courriernew.png")
Dim font as IGUIFont = _GetFont()

' ---------------------------------------
'           Main loop
' ---------------------------------------
Dim hh as Single=0
While Quit=0
 

' If Escape Key, Exit	
  If _GetKeyDown(KEY_ESCAPE) then
    Quit=1
  EndIf
  
 
   
  ' move camera with dir key And mouse (Left click)
  If _GetKeyDown(KEY_ARROW_LEFT) then
    hh= _TerrainHeight(terrain,  _NodeX(cam),  _NodeZ(cam))+10.0
    _PositionNode(cam, _NodeX(cam), hh, _NodeZ(cam))
  EndIf
  If _GetKeyDown(KEY_ARROW_RIGHT) Then
    hh= _TerrainHeight(terrain,  _NodeX(cam),  _NodeZ(cam))+10.0
    _PositionNode(cam, _NodeX(cam), hh, _NodeZ(cam))
  EndIf 
  If _GetKeyDown(KEY_ARROW_UP) then
    hh= _TerrainHeight(terrain,  _NodeX(cam),  _NodeZ(cam))+10.0
    _PositionNode(cam, _NodeX(cam), hh, _NodeZ(cam))
  EndIf
  If _GetKeyDown(KEY_ARROW_DOWN) Then
    hh= _TerrainHeight(terrain,  _NodeX(cam),  _NodeZ(cam))+10.0
    _PositionNode(cam, _NodeX(cam), hh, _NodeZ(cam))
  EndIf




  	' ---------------
  	'      Render
  	' ---------------
  _BeginScene(1,128,128)
      _DrawScene()   
     _DrawText(font, "FPS : "+ str(_FPS()),  10,25,0,0, &hffffffff)
     _DrawText(font, "Primitives: "+ str(_PrimitiveCountDrawn())  ,  10,45,0,0, &hffffffff)
  _EndScene()


Wend 
' end
_FreeEngine()

