' ------------------------------------------------------------
'   n3xt-D exemples
'
'   Sample  014   as  primitives with a light And material.

'   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 light And set position
  Dim light as LightNode = _CreateLight( &hffffffff, 10) 
  _PositionNode(light, 0,5,0)
 
  
' Create mesh
 Dim cubemesh as Mesh = _CreateCubeMesh()
 Dim spheremesh as Mesh = _CreateSphereMesh()
 Dim cylindermesh as Mesh= _CreateCylinderMesh(1.0, 3.0)

 
' Create a cube And set position
 Dim cube as EntityNode = _CreateEntityNode(cubemesh)
_PositionNode(cube, -6,0,0) 
' first Method set
 Dim mat as NMaterial = _NodeMaterial(cube)
_ColorMaterial(mat,  ECM_NONE) 
_DiffuseColorMaterial(mat,  &hffff0000) 



' Create a sphere And set position
 Dim sphere as EntityNode = _CreateEntityNode(spheremesh)
_PositionNode(sphere, -2,0,0) 
' second metohd set
_MaterialColorNode(sphere)
_DiffuseColorNode(sphere, &hff00ff00)



' Create a cylinder And set position
 Dim cylinder as EntityNode = _CreateEntityNode(cylindermesh)
_PositionNode(cylinder, 2,2,0) 
_RotateNode(cylinder, 0,0,90) 
' second metohd set
_MaterialColorNode(cylinder)
_DiffuseColorNode(cylinder, &hff0000ff)



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



Dim lightpos(4) as Single
dim angle As Single = 3.0

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

' If Escape Key, Exit	
  If _GetKeyDown(KEY_ESCAPE) then
    Quit=1
  EndIf 


  angle = angle + 0.02
  lightpos(0) = 10*Cos( angle)
  lightpos(2) = 10*Sin( angle)
  _XNode( light, lightpos(0))
  _ZNode( light, lightpos(2))

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


Wend 
' end
_FreeEngine()

