' ------------------------------------------------------------
'   n3xt-D exemples
'
'   Sample  100   as   first test collision.
'   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 
  
'----------------------------------------
' Create traditional light And set position
  Dim light as LightNode = _CreateLight(&hffdddddd, 200)
  _PositionNode(light, 5,15,-3)



 
'-----------------------------------------
' Create a cube 
  Dim cubemesh as Mesh = _CreateCubeMesh(3.0)
  
  Dim cube as EntityNode = _CreateEntityNode(cubemesh)
  
    _PositionNode(cube, -3,1,0)
    _LoadTextureNode(cube, "media/wcrate.bmp") 
    dim mat as NMaterial = _NodeMaterial(cube)
    _ColorMaterial(mat,  ECM_NONE)     
    ' Create And  set collide Type
    _CreateNodeCollide(cube, BOX_PRIMITIVE, 1)


 ' Load an 3D Object 
  Dim obj as Mesh = _LoadMesh("media/teapot.b3d")
  _ScaleMesh(obj, 0.4,0.4,0.4)

' Create a mesh with one of the 3D Object loaded
  Dim teapot as EntityNode = _CreateEntityNode(obj)
  _PositionNode(teapot, 0.75,0,0)
  ' Create And  set collide Type
  _CreateNodeCollide(teapot, HULL_PRIMITIVE, 1)





'-----------------------------------------
' Create first  camera
dim cam as CameraNode = _CreateCamera( )
_PositionNode(cam, 0,5,-10)
_RotateNode(cam, 15,-5,0)

' ---------------------------------------
'           Main loop
' ---------------------------------------
While Quit=0
 

' If Escape Key, Exit	
  If _GetKeyDown(KEY_ESCAPE) then
    Quit=1
  EndIf
  
  _TurnNode(teapot, 0,1,0)
  
  
    If _NodeCollide(teapot, cube) then
      _DiffuseColorNode(cube, &hff000000)
    Else
      _DiffuseColorNode(cube, &hffffffff)
    EndIf
  

  	' ---------------
  	'      Render
  	' ---------------
  _BeginScene(30,30,30)
     _DrawScene()
  _EndScene()


Wend 
' end
_FreeEngine()

