' ------------------------------------------------------------
'   n3xt-D exemples
'
'   Sample  043  :  10.000 grass element with wind simulation
'   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

 
 
 
' set the curent folder
_ChangeWorkingDirectory("media")
  
  
'----------------------------------------
' Load 3D objects 
  dim obj1 as Mesh = _LoadMesh("plane.3ds")
'-----------------------------------------
' Create plane
dim plane as EntityNode =  _CreateEntityNode(obj1)
_ScaleNode(plane, 6,5,6)
'----------------------------------------
  



'----------------------------------------
' grass zone
Dim spritemesh as Mesh = _LoadMesh("grass1.3ds")
_ScaleMesh(spritemesh, 0.15, 0.1, 0.15)

   
  Dim staticArea as EntityNode
 
     
  staticArea = _CreateBatchNode(spritemesh, EMT_TRANSPARENT_ALPHA_CHANNEL_REF, TRUE)
  _WindValueBatchZone(staticArea, 0.10, 30)

dim k as integer
dim x as single, z as Single, sac as Single
  For k = 0 To 10000
     x = -140+Rnd()*280
     z = -140+Rnd()*280   
     sac = 0.65 + Rnd()*0.55
    _AddBatchElement(staticArea, x, 6.5 ,z, 0,0,0, sac,1,sac)
  Next
  '_DebugModeNode(staticArea, DEBUG_BBOX )



'----------------------------------------
' def camera
Dim cam as CameraNode =_CreateCameraFPS(80, 0.1)
  _PositionNode(cam, 0, 20, -0)
  
  
'-----------------------------------
' 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(128,128,128)
      _DrawScene()   
      _DrawText(font, "FPS : " + str(_FPS())  ,  10,25,0,0, &hffffffff)
      _DrawText(font, "Primitives: "+ str(_PrimitiveCountDrawn())  ,  10,45,0,0, &hffffffff)
      _DrawText(font, "10.000 grass element with wind simulation",  10,65,0,0, &hffffffff)
  _EndScene()
  

Wend 
' end
_FreeEngine()
