' ------------------------------------------------------------
'   n3xt-D exemples
'
'   Sample  027   as   Poursuite 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 ambient light
' _AmbientLight( &hffaaaaaa)
'----------------------------------------
' Create light And set position
 Dim light As LightNode = _CreateLight(&hffffffff, 180)
 _PositionNode(light, 0,30,10)



' turn off MipMap
_TextureCreation( ETCF_CREATE_MIP_MAPS, False )

'----------------------------------------
' Load 3D objects 
  Dim obj1 as Mesh = _LoadMesh("media/plane.3ds")
  Dim obj2 as Mesh = _LoadMesh("media/earth.x")


'-----------------------------------------
' Create plane
Dim plane as EntityNode =  _CreateEntityNode(obj1)

'-----------------------------------------
' Create sphere
Dim sphere as EntityNode =  _CreateEntityNode(obj2)
_PositionNode(sphere, 0,0.5,5)
_ScaleNode(sphere, 1.5,1.5,1.5)


'-----------------------------------------
' Create arrow mesh
Dim obj3 as Mesh = _CreateArrowMesh()
_ScaleMesh(obj3, 3,4,3)
_RotateMesh(obj3, 90,0,0)
' And the node associed
Dim cc as EntityNode =  _CreateEntityNode(obj3)
_PositionNode(cc, 0,5,0)


_PointNode(cc, sphere)



'-----------------------------------------
' Create first  camera
Dim cam as CameraNode = _CreateCamera( )
_PositionNode(cam, 0,10,-15)
_TurnNode(cam, 15,0,0)

'-----------------------------------
' 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
    
 	' control earth
  If _GetKeyDown(KEY_ARROW_UP) Then
    _TranslateNode(sphere, 0,0,0.5)
    _PointNode(cc, sphere)
  EndIf
  If _GetKeyDown(KEY_ARROW_DOWN) Then
    _TranslateNode(sphere, 0,0,-0.5)
    _PointNode(cc, sphere)
  EndIf
  If _GetKeyDown(KEY_ARROW_RIGHT) Then
    _TranslateNode(sphere, 0.5,0,0)
    _PointNode(cc, sphere)
  EndIf
  If _GetKeyDown(KEY_ARROW_LEFT) Then
    _TranslateNode(sphere, -0.5,0,0)
    _PointNode(cc, sphere)
  EndIf
  If _GetKeyDown(KEY_KEY_R) Then
    _TranslateNode(sphere, 0,0.5,0)
    _PointNode(cc, sphere)
  EndIf
  If _GetKeyDown(KEY_KEY_F) Then
    _TranslateNode(sphere, 0,-0.5,0)
    _PointNode(cc, sphere)
  EndIf


  If _GetMouseEvent(MOUSE_BUTTON_LEFT) Then
    Dim angley as single =  _GetDeltaMouseX() / 4.0
    dim anglex As single =  _GetDeltaMouseY() / 4.0
    _TurnNode(cam, anglex, angley,0)
  EndIf



  	' ---------------
  	'      Render
  	' ---------------
  _BeginScene()
    _DrawScene()
    _DrawText(font, "DirKey and R/F for move earth",  10,10,0,0, &hff00ffff)
  _EndScene()

Wend 
' end
_FreeEngine()
