' ------------------------------------------------------------
'   n3xt-D exemples
'
'   Sample 105   as   scene 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  
 
   
' set the curent folder
_ChangeWorkingDirectory("media")



'----------------------------------- 
' add in memory management system a zip file 
 _AddZipFileArchive( "chiropteradm.pk3" )

'-----------------------------------
' Load Quake3 scene Object
  dim obj as Mesh = _LoadMesh("chiropteradm.bsp")
  _ScaleMesh(obj, 0.2,0.2,0.2)
  
  

' Create a mesh with one of the 3D Object loaded
  dim quake as EntityNode =   _CreatePopNodes(obj)
  
 ' resize world box dimension 
 _SetWorldSize(-1000,-1000,-1000,1000,1000,1000)
 ' Create static body scene
  _CreateBody(quake, COMPLEX_PRIMITIVE_SURFACE, False) 
  
  
  

'-----------------------------------------
' Create a static base
dim cubemesh as Mesh = _CreateCubeMesh(2.0)
'-----------------------------------------
' Create a cube 
  For i as Integer = 0 To 25
    dim cube as EntityNode = _CreateEntityNode(cubemesh)
    _PositionNode(cube, -20+Rnd()*40,10+Rnd()*10,-10+Rnd()*12)
    _LoadTextureNode(cube, "wcrate.bmp") 
    ' Create body, dynamique   
    _CreateBody(cube, BOX_PRIMITIVE)
  Next


 



'----------------------------------------- 
' Load an 3D Object 
 obj = _LoadMesh("teapot.b3d")
' Create a mesh with one of the 3D Object loaded
  dim teapot as EntityNode = _CreateEntityNode(obj)
  _PositionNode(teapot, 5,6,0)
  ' Create And  set collide Type
  _CreateBody(teapot, HULL_PRIMITIVE)
  
  
  
  
  
  
'-----------------------------------------
' Create first  camera
dim cam as CameraNode = _CreateCameraFPS( )
_PositionNode(cam, 0,20,-40)



'-----------------------------------
' Load font png
_LoadFont("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 _GetKeyUp(KEY_SPACE) then
    For i as Integer  = 0 To 7
      dim cube as EntityNode = _CreateEntityNode(cubemesh)
      _PositionNode(cube, -20+Rnd()*40,10+Rnd()*10,-10+Rnd()*20)
      _Scalenode(cube, 1.5,1.5,1.5)
      _LoadTextureNode(cube, "object.jpg") 
      ' Create body, no dynamique
      _CreateBody(cube, BOX_PRIMITIVE)
    Next
  EndIf
  

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


Wend 
' end
_FreeEngine()
