' ------------------------------------------------------------
'   n3xt-D exemples
'
'   Sample  103   as   first test with 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 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, 20,1,20)
  ' Create body, no dynamique
  _CreateBody(cube, BOX_PRIMITIVE, FALSE)



'-----------------------------------------
' Create a cube 
Dim i as Integer 
  For i = 0 To 25
    Dim cube As EntityNode = _CreateEntityNode(cubemesh)
    _PositionNode(cube, -10+Rnd()*20,10,-10+Rnd()*20)
    _LoadTextureNode(cube, "media/body.bmp") 
    ' Create body, dynamique
    _CreateBody(cube,BOX_PRIMITIVE)
  Next





'-----------------------------------------
' Create a sphere
Dim spheremesh as Mesh = _CreateSphereMesh(1.0)
Dim sphere as EntityNode = _CreateEntityNode(spheremesh)
  _PositionNode(sphere, -2,4,0) 
  _LoadTextureNode(sphere, "media/stones.jpg") 
  ' Create body, no dynamique
  _CreateBody(sphere,SPHERE_PRIMITIVE)

  
'-----------------------------------------
' Create a cylinder 
Dim cylindermesh as Mesh= _CreateCylinderMesh(1.0, 5.0)
Dim cylinder as EntityNode = _CreateEntityNode(cylindermesh)
 _PositionNode(cylinder, -1,4,5)
 _LoadTextureNode(cylinder, "media/water.jpg") 
 '_ScaleNode(cylinder, 2,2,2)

 ' Create body, no dynamique
 _CreateBody(cylinder, CYLINDER_PRIMITIVE)
  _RotateNode(cylinder, 0,0,90) 



'-----------------------------------------
' Create a capsule 
cylindermesh = _CreateCylinderMesh(1.0, 5.0)
cylinder = _CreateEntityNode(cylindermesh)
 _PositionNode(cylinder, -1,4,-2)
 _LoadTextureNode(cylinder, "media/water.jpg") 
 ' Create body, no dynamique
 _CreateBody(cylinder, CAPSULE_PRIMITIVE)
 
 

  
'-----------------------------------------
' Create a hull Object
' 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,12,0)

  ' Create And  set collide Type
  _CreateBody(teapot, HULL_PRIMITIVE)
  
  
  
  
  
  
'-----------------------------------------
' Create first  camera
Dim cam as CameraNode = _CreateCameraFPS( )
_PositionNode(cam, 0,7,-20)



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

' If Escape Key, Exit	
  If _GetKeyDown(KEY_ESCAPE) then
    Quit=1
  EndIf
  
  If _GetKeyUp(KEY_SPACE) then 
    For i  = 0 To 7
      Dim cube as EntityNode = _CreateEntityNode(cubemesh)
      _PositionNode(cube, -8+Rnd()*16,10, -8+Rnd()*16)
      _LoadTextureNode(cube, "media/five.bmp") 
      ' Create body, no dynamique
      _CreateBody(cube, BOX_PRIMITIVE)
    Next
  EndIf
  



  	' ---------------
  	'      Render
  	' ---------------
  _BeginScene()
     _DrawScene()
  _EndScene()
  
  
Wend 
' end
_FreeEngine()

