' ------------------------------------------------------------
'   n3xt-D exemples
'
'   Sample  035   as   Picking 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

Declare Sub DrawTriangle()

'----------------------------------------------------------
' open n3xt-D screen
app = _CreateGraphics3D(800,600)
If app=NULL Then
  End
End If
 

'-----------------------------------------
' Create single sphere
Dim mesh as Mesh =  _CreateSphereMesh(5,16)
Dim sphere as EntityNode = _CreateEntityNode(mesh)


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


'-----------------------------------
' 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 _GetMouseEvent(MOUSE_BUTTON_RIGHT) Then
      Dim node as EntityNode = _PickCamera(cam, _GetMouseX(), _GetMouseY(), ENT_PICKFACE)
  EndIf



  	' ---------------
  	'      Render
  	' ---------------
  _BeginScene()
    _DrawScene()
     DrawTriangle()
    _DrawText(font, "FPS  as  "+ str(_FPS())  ,  10,10,0,0, &hff00ffff)
    _DrawText(font, "use click mouse for pick mesh as "  ,  10,25,0,0, &hff00ffff)
  _EndScene()


Wend 
' end
_FreeEngine()


Sub DrawTriangle()
  Dim tri(8) As Single
  _Pickedtriangle (Varptr(tri(0)) )
  _DrawTriangle3D(Varptr(tri(0)),  &hffffff00)
End sub
