' ------------------------------------------------------------
'   n3xt-D exemples
'
'   Sample 004  :  load a simple 3D object ad set mesh
'   Historique  :
'     29/03/09  19:16    TMyke
'
' ------------------------------------------------------------

' Includes libraries
#INCLUDE "N3xtD.bi"

FUNCTION PBMAIN()
' Globales
DIM app AS DWORD 'ANY PTR
DIM Quit AS INTEGER


'----------------------------------------------------------
' open n3xt-D screen
app = CreateGraphics3D(800,600, 32, 0, %TRUE, %DEVICE_TYPES.EDT_DIRECT3D9, %TRUE)
IF app = %NULL THEN
  END
END IF

AmbientLight(&hffffff00)

' load an 3D object
  DIM obj AS Mesh
  obj = LoadMesh("media/earth.x", %HARDMAPPING.EHM_STATIC)
' create a mesh with one of the 3D object loaded
  DIM sphere AS EntityNode
  sphere = CreateEntityNode(obj, 0,  0,  0, %NULL)
' set debug information
  DebugModeNode(sphere, %DEBUG_BBOX )




' create a camera
DIM cam AS CameraNode
cam  = CreateCamera(%NULL)
PositionNode(cam, 0,0,-5)




' ---------------------------------------
'           main loop
' ---------------------------------------
WHILE Quit=0


' just turn our sphere
 TurnNode(sphere, 0,0.5,0, 0)

' If Escape Key, Exit
  IF GetKeyDown(%KEY_CODE.KEY_ESCAPE) THEN
    Quit=1
  END IF


    ' ---------------
    '      Render
    ' ---------------
  BeginScene(20,20,50, 255, 1,  1)
  DrawScene()
  EndScene()


WEND
' end
FreeEngine()

END FUNCTION
