' ------------------------------------------------------------
'   n3xt-D exemples
'
'   Sample 108   as    test material physic engine
'   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,25,3)
 _AmbientLight(&hff222222)


  ' -----------------------------------------
  '          Create And init some physicmaterial
  ' -----------------------------------------
  Dim mat(6) as Integer
  mat(1)= _CreatePhysicMaterial()
  mat(2)= _CreatePhysicMaterial()
  mat(3)= _CreatePhysicMaterial()
  mat(4)= _CreatePhysicMaterial()
  mat(5)= _CreatePhysicMaterial()
  
  Dim pair1 as NMaterialPair = _CreatePhysicMaterialPair( mat(1),  mat(1), 0.1, 0.3, 0.25, 0)
  Dim pair2 as NMaterialPair = _CreatePhysicMaterialPair( mat(1),  mat(2), 0.3, 1.1, 0.82, 0)
  Dim pair3 as NMaterialPair = _CreatePhysicMaterialPair( mat(1),  mat(3), 0.5, 0.025, 0.01, 0)
  Dim pair4 as NMaterialPair = _CreatePhysicMaterialPair( mat(1),  mat(4), 0.7, 1.0, 1.0, 0)
  Dim pair5 as NMaterialPair = _CreatePhysicMaterialPair( mat(1),  mat(5), 0.9, 0.1, 0.5, 0)



'-----------------------------------------
' Create a static base
Dim cubemesh as Mesh = _CreateCubeMesh(1.0)
Dim cube as Entitynode = _CreateEntityNode(cubemesh)
  _PositionNode(cube, 0,-2,0) 
  _LoadTextureNode(cube, "media/grille1.bmp") 
  _ScaleNode( cube, 30,1,30)
  _RotateNode(cube, 0,0,25)
  ' Create body, no dynamique
  _CreateBody(cube, BOX_PRIMITIVE, False)
  _GroupPhysicMaterialBody(cube,  mat(1))


'-----------------------------------------
  ' Create 5 random cubes
  For i as Integer =0 To 4
    dim mesh As Entitynode = _CreateEntityNode(cubemesh)
    _ScaleNode( mesh, 2,2,2)
    _PositionNode(mesh, 10, 10 ,-4+4*i)
    _MaterialColorNode(mesh)
    _DiffuseColorNode(mesh, &hff000000+Rnd()*&hffffff)
    _LoadTextureNode(mesh, "media/body.bmp") 
    _CreateBody(mesh, BOX_PRIMITIVE)
    _GroupPhysicMaterialBody(mesh,  mat(i+1))
  Next



'-----------------------------------------
' Create first  camera
dim cam as CameraNode = _CreateCameraFPS( )
_PositionNode(cam, -5,7,-20)



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

' If Escape Key, Exit	
  If _GetKeyDown(KEY_ESCAPE) then
    Quit=1
  EndIf
  
   
  	' ---------------
  	'      Render
  	' ---------------
  _BeginScene(128,128,128)
     _DrawScene()
  _EndScene()


Wend 
' end
_FreeEngine()
