' ------------------------------------------------------------
'   n3xt-D exemples
'
'   Sample 050   as   load simples MD2 animation and set
'   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

_ChangeWorkingDirectory("media/animations")

'---------------------------------------------------
' Load an 3D Object 
  Dim obj1 as AnimatedMesh = _LoadAnimatedMesh("sydney.md2")
  Dim obj2 as AnimatedMesh = _LoadAnimatedMesh("sydney.md2")
  Dim obj3 as AnimatedMesh = _LoadAnimatedMesh("vieux.md2")



'---------------------------------------------------
'sidney standby: method one
'---------------------------------------------------
Dim md2 as AnimatedNode = _CreateAnimation(obj1)
_LoadTextureNode( md2, "sydney.bmp" ) 

_AnimationMD2(md2, EMAT_STAND ) 
_SpeedAnimation(md2, 36)
_PositionNode(md2, 0,0,0)

'---------------------------------------------------
'sidney run: alternate method, same result
'---------------------------------------------------
Dim md2_2 as AnimatedNode = _CreateAnimation(obj2)
_LoadTextureNode( md2_2, "sydney.bmp" )

Dim outBegin as Integer,outEnd as Integer, outFPS as Integer   
_MD2FrameLoopType(md2_2, EMAT_STAND , Varptr(outBegin), Varptr(outEnd), Varptr(outFPS))   
_SpeedAnimation(md2_2, outFPS)
_FrameLoopAnimation(md2_2,  outBegin, outEnd)
_PositionNode(md2_2, -50,0,0)

'---------------------------------------------------
' "vieux": all frames
'---------------------------------------------------
Dim md2_3 as AnimatedNode = _CreateAnimation(obj3)
_SpeedAnimation(md2_3, 35)
_FrameLoopAnimation(md2_3,  0, 496)
_LoadTextureNode( md2_3, "vieux.tga" )
_PositionNode(md2_3, 50,0,0)
'---------------------------------------------------



'---------------------------------------------------
' Create a camera
dim cam as CameraNode = _CreateCamera( )
_PositionNode(cam, 20,0,-80)


'-----------------------------------
' Load font png
_LoadFont("../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(50, 50, 50)
     _DrawScene()
     _DrawText(font, "FrameNumber of second 'vieux' as  "+ str(_AnimationFrameNumber(md2_2)),  10,10,0,0, &hff00ffff)
  _EndScene()

Wend 
' end
_FreeEngine()

