' ------------------------------------------------------------
'   n3xt-D exemples
'
'   Sample  104   as   terrain physic test
'   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

 
 
 
' set the curent folder
_ChangeWorkingDirectory("media")
  
  
'------------------------------------------------------------------------------------
 ' resize physic world space 
  _SetWorldSize(-1000,-1000,-1000,1000,1000,1000)
  
  
'------------------------------------------------------------------------------------
  dim terrain As TerrainNode = _CreateTerrain("height113.bmp", TQ_MEDIUM, 2.0, 0.3, 2.0, 32)
_TextureTerrain(terrain, 0 , "Sol113.jpg")
_TextureTerrain(terrain, 1 , "detailmap3.jpg")
_MaterialTypeNode(terrain, EMT_LIGHTMAP_LIGHTING_M2)
' Create terrain body
' first Method, less accurate, but lighter And faster.
_CreateTerrainBody(terrain, HEIGHTFIELD_METHOD)
' << Or >>
' second Method, accurate, but heavier
'_CreateTerrainBody(terrain, VERTICES_METHOD)
'------------------------------------------------------------------------------------


'-----------------------------------------
' Create a static base
Dim cubemesh as Mesh = _CreateCubeMesh(4.0)
'-----------------------------------------
' Create a cube 
dim i as Integer
  For i = 0 To 25
    Dim cube As EntityNode = _CreateEntityNode(cubemesh)
    _PositionNode(cube, -25+Rnd()*50+50,100,-25+Rnd()*50+50)
    _LoadTextureNode(cube, "body.bmp") 
    ' Create body, dynamique
    _CreateBody(cube, BOX_PRIMITIVE)
  Next




  
'----------------------------------------
  ' Create a camera
Dim cam as CameraNode = _CreateCameraFPS( )
_PositionNode(cam, 0,120,-70)

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

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

' If Escape Key, Exit	
  If _GetKeyDown(KEY_ESCAPE) then
    Quit=1
  EndIf




  	' ---------------
  	'      Render
  	' ---------------
  _BeginScene(1,128,128)
      _DrawScene()   
     _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()
