' ------------------------------------------------------------
'   n3xt-D exemples
'
'   Sample  042: terrain splatting
'   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

  

  Dim light as LightNode = _CreateLight(&hffff0000, 256.0)
  _PositionNode(light, 50,100,50)

 
 '------------------------------------------------------------------------------------
Dim terrain as TerrainNode = _CreateTerrain("media/aterrain1.bmp", TQ_MEDIUM, 2.0,0.35,2.0, 4)
_SplattingTerrain(terrain,  -500.0, &hffffffff)

Dim alphamap as NTexture = _TextureTerrain(terrain, 0,"media/alpha1.bmp")
_TextureTerrain(terrain, 1,"media/025.jpg")
_TextureTerrain(terrain, 2,"media/stone.bmp")
_TextureTerrain(terrain, 3,"media/splatting3.png") 
_TextureTerrain(terrain, 4,"media/dirt.bmp")
_TextureTerrain(terrain, 5,"media/detailmap3.jpg")
'_TextureTerrain(terrain, 6,"media/lightmap.jpg")
'------------------------------------------------------------------------------------


  
  ' Create a camera
Dim cam as CameraNode = _CreateCameraFPS( )
_PositionNode(cam, -100,280,-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))) 
        _WriteTextureTerrain(terrain, alphamap, pPos(0), pPos(2), 8, &hffff0000)
      EndIf
  EndIf  
   

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


Wend 
' end
_FreeEngine()
