' ------------------------------------------------------------
'   n3xt-D exemples
'
'   Sample  040   as   first terrain sample.
'   Historique   as 
'     29/03/09  19 as 16    TMyke
'
' ------------------------------------------------------------

' Includes libraries
#include "N3xtD.bi"

' dimes
Dim app As any Ptr
Dim Quit As Integer


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

 
 
 '------------------------------------------------------------------------------------
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_M2)

'_DebugModeNode(terrain, True)
'------------------------------------------------------------------------------------


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


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

' ---------------------------------------
'           Main loop
' ---------------------------------------
While Quit=0
 

' If Escape Key, Exit	
  If _GetKeyDown(KEY_ESCAPE) then
    Quit=1
  EndIf
  
  '--------------------------------------------------------
  ' terrain picking zone test
  If _GetMouseEvent(MOUSE_BUTTON_RIGHT) then
     Dim res as Integer = _PickTerrain(terrain)
      If res  Then
        dim pPos(4) as Single
        _TerrainPickedPosition(terrain, Varptr(ppos(0))) 
        _HeightTerrain(terrain, 16.0, ppos(0), ppos(2),  1.0, TH_UP)
      EndIf
  EndIf
  




  	' ---------------
  	'      Render
  	' ---------------
  _BeginScene(1,128,128)
      _DrawScene()   
     _DrawText(font, "Right click mouse to change height of terrain" ,  10,5,0,0, &hffffffff)
     _DrawText(font, "FPS  as  "+ str(_FPS()),  10,25,0,0, &hffffffff)
     _DrawText(font, "Primitives as  "+ str(_PrimitiveCountDrawn())  ,  10,45,0,0, &hffffffff)
  _EndScene()

Wend 
' end
_FreeEngine()
