' ------------------------------------------------------------
'   n3xt-D exemples
'
'   Sample 047   as   Test Multi SceneManager.
'   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




'-----------------------------------------
' Create a cube in the base SceneManager
Dim cubemesh as Mesh = _CreateCubeMesh(1)
  For i as Integer = 0 To 15
     Dim cube As EntityNode = _CreateEntityNode(cubemesh)
    _PositionNode(cube, -6+Rnd()*12,0,-6+Rnd()*12)
    _LoadTextureNode(cube, "media/body.bmp") 
  Next
  ' Create a camera
  Dim cam as CameraNode = _CreateCameraFPS( )
  _PositionNode(cam, 0,0,-5)



'-----------------------------------------
' Create New SceneManager
Dim smgr2 as Byte Ptr = _CreateSceneManager()
'-----------------------------------------
' set the N3xtD system with the New SceneManager
Dim smgr1 as Byte Ptr = _CurentSceneManager(smgr2)


'-----------------------------------------
' Create a cube in the second SceneManager
  For i as Integer = 0 To 15
    Dim cube As EntityNode = _CreateEntityNode(cubemesh)
    _PositionNode(cube, -6+Rnd()*12,-4,-6+Rnd()*12)
    _LoadTextureNode(cube, "media/five.bmp") 
  Next
  ' Create a camera in the New SceneManager
  ' (each SceneManager must have a camera)
  dim cam2 as CameraNode = _CreateCamera( )
  _PositionNode(cam2, 0,0,-5)



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


dim flag As Integer=0
' ---------------------------------------
'           Main loop
' ---------------------------------------
While Quit=0
 

' If Escape Key, Exit	
  If _GetKeyDown(KEY_ESCAPE) then
    Quit=1
  EndIf
  
  
  If _GetKeyUp(KEY_F1) then
    _CurentSceneManager(smgr1)
    flag=0
  EndIf    
  If _GetKeyUp(KEY_F2) Then
    _CurentSceneManager(smgr2)
    flag=1
  EndIf    
  If _GetKeyUp(KEY_F3) then
    flag=2
  EndIf     
     




  	' ---------------
  	'      Render
  	' ---------------
  _BeginScene()
     If(flag=2) Then _DrawSceneManager(smgr1)
     _DrawScene()
     _DrawText(font, "F1/F2 to switch between SceneManager",  10,10,0,0)
     _DrawText(font, "F3    Draw to SceneManager",  10,30,0,0)
  _EndScene()



Wend 
' end
_FreeEngine()

