' ------------------------------------------------------------
'   n3xt-D exemples
'
'   Sample  054   as   single sprite2D 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


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

'-----------------------------------------
' Create earth
Dim sphere as EntityNode =  _CreateEntityNode(obj2)
_ScaleNode(sphere, 1.5,1.5,1.5)


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




'----------------------------------------
'// PARTIE 2D
'----------------------------------------
'-----------------------------------------
' Create sprite 1
Dim sp1 as Sprite2D = _CreateSprite2D("media/grass.bmp", 0.2)
_PositionNode(sp1, 0,0,1)


'-----------------------------------------
' Create sprite 2
Dim sp2 as Sprite2D = _CreateSprite2D("media/five.bmp", 0.75, &hffffffff)
_PositionNode(sp2, 200,50,1.5)
'_CenterSprite3D(sp2,  50,  50) 

Dim texturelist as NArray = _CreateListTexture("media/ball2.png", 64,64) 
dim anim as NNodeAnimator = _CreateTextureAnimator( texturelist,  100)
_AddAnimatorTexture(sp2, anim)



'-----------------------------------
' 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
   
  
  If _GetKeyDown(KEY_KEY_R) Then
      _TurnNode(sp2, 0,0,1)
  EndIf
  If _GetKeyDown(KEY_KEY_Y) Then
      _TurnNode(sp2, 0,0,-1)
  EndIf
  If _GetKeyDown(KEY_KEY_T) Then
      _MoveNode(sp2,1,0,0)
  EndIf
  If _GetKeyDown(KEY_KEY_V) Then
      _MoveNode(sp2,-1,0,0)
  EndIf
  



  Dim xx as Integer = _ProjectedX(sphere)
  dim yy As Integer = _ProjectedY(sphere)
  _PositionNode(sp1, xx-400+10, 300-yy+10, 1)

  	' ---------------
  	'      Render
  	' ---------------
  _BeginScene(100,100,100)
      _DrawScene()

      _Begin2D(800,600)
        _RenderSprite2D(sp1)
        _RenderSprite2D(sp2)
      _End2D()
      
      _DrawText(font, "Key R/Y/T/V to move sprite2",  10,10,0,0)
      _DrawText(font, "move earth with mouse and sprite1 follow...",  10,25,0,0)

  _EndScene()

Wend 
' end
_FreeEngine()

