' ------------------------------------------------------------
'   n3xt-D exemples
'
'   Sample  044   as   LOD Entity system
'   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
  

' Load the different mesh To construct LOD dim mesh  
Dim earthMesh1 As Mesh = _LoadMesh("media/sphereLOD1.3ds")  
Dim earthMesh2 as Mesh = _LoadMesh("media/sphereLOD2.3ds")  
Dim earthMesh3 as Mesh = _LoadMesh("media/sphereLOD3.3ds")  
Dim earthMesh4 as Mesh = _LoadMesh("media/sphereLOD4.3ds")  
Dim earthMesh5 as Mesh = _LoadMesh("media/sphereLOD5.3ds")  
Dim earthMesh6 as Mesh = _LoadMesh("media/sphereLOD6.3ds")  




'----------------------------------------
Dim hillmesh as Mesh = _CreateHillPlaneMesh()
' quick ground 
Dim hillplane as EntityNode = _CreateEntityNode(hillmesh)
_LoadTextureNode(hillplane, "media/wall.jpg") 




_DistanceLOD(  80.0,  150.0,  210.0,  250.0,  280.0,  320.0)


'----------------------------------------
' one entitynode LOD setting
Dim entitylod as EntityNode = _CreateLODEntityNode(earthMesh1)
_AddMeshLODEntityNode(entitylod, earthMesh2, 1 )
_AddMeshLODEntityNode(entitylod, earthMesh3, 2 )
_AddMeshLODEntityNode(entitylod, earthMesh4, 3 )
_AddMeshLODEntityNode(entitylod, earthMesh5, 4 )
_AddMeshLODEntityNode(entitylod, earthMesh6, 5 )
_PositionNode(entitylod, 80,80,0)



'----------------------------------------
' set static zone with entitynode LOD setting
Dim lod as EntityNode = _CreateStaticZone(earthMesh1)
_SetLODStaticZoneEntityNode(lod, earthMesh2, 1 )
_SetLODStaticZoneEntityNode(lod, earthMesh3, 2 )
_SetLODStaticZoneEntityNode(lod, earthMesh4, 3 )
_SetLODStaticZoneEntityNode(lod, earthMesh5, 4 )
_SetLODStaticZoneEntityNode(lod, earthMesh6, 5 )

Dim cube as EntityNode
For i as Integer =0 To 60
  Dim sac As single = Rnd()*10+5
  sac=sac/10.0
   _AddElementStaticZone(lod, Rnd()*150.0-75 ,0, Rnd()*150.0-75, 0,0,0, sac,sac,sac)
Next
_DebugModeNode(lod, DEBUG_BBOX )


 

 
' Create a camera
dim cam as CameraNode = _CreateCameraFPS( )
_PositionNode(cam, 0,50,-40)



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

  

  	' ---------------
  	'      Render
  	' ---------------
  _BeginScene()
     _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()

