
; XIncludeFile #PB_Compiler_Home + "Includes\IrrlichtWrapper_main.pbi"
XIncludeFile #PB_Compiler_Home + "Includes\IrrlichtWrapper_Include.pbi"

#MAX_DYNODES = 3 
Dim dynodes.l(#MAX_DYNODES)
Define *g_cubeTexture.l
*KeyEvent.IRR_KEY_EVENT


;Place the 3 Node over the one and lat fall the nice thingie....
Procedure setDyNodes()  
  Shared dynodes()
  Shared *g_cubeTexture.l
  RandomSeed(ElapsedMilliseconds())
  starty.f = 30
  For i = 0 To #MAX_DYNODES-1
    IrrPhysicsSetEntityPos(dynodes(i),(7-Random(7)), starty, 100.0) 
    starty+25.0
  Next
EndProcedure

Procedure createDyNodes() 
  Shared dynodes()
  Shared *g_cubeTexture.l  
  For i = 0 To #MAX_DYNODES-1
    *dynamicCubeNode.l = IrrAddCubeSceneNode(10.0)
    IrrSetNodeMaterialTexture( *dynamicCubeNode, *g_cubeTexture, 0 )
     IrrSetNodeMaterialFlag(*dynamicCubeNode,#IRR_EMF_LIGHTING,#False)
    dynodes(i) = IrrPhysicsAddDynamicCube(*dynamicCubeNode,10.0,10.0,10.0,40.0)
  Next 
EndProcedure

If InitSprite() = 0 Or InitKeyboard() = 0 Or InitMouse() = 0  
  MessageRequester("Error","Can't open DirectX",0)  
  End  
EndIf  

 ;InitIrrlichtWrapperDll()
 IrrStart( #IRR_EDT_DIRECT3D9, 400, 200, #IRR_WINDOWED, #IRR_NO_SHADOWS, #IRR_CAPTURE_EVENTS )
 IrrPhysicsInit() 
 IrrSetWindowCaption( "Example 01: Hello World - The GUI" )
 Debug("1")
 IrrGuiAddStaticText( "Hello World", 4,0,200,16, #IRR_GUI_NO_BORDER, #IRR_GUI_NO_WRAP )

*g_cubeTexture   = IrrGetTexture("../media/wall.bmp")

*camera = IrrAddCamera(0,0,60,0,0,100.0)
 
*light = IrrAddLight(-15,5,-105,255,255,255,100)
; 

; At first wi pu a static cube in the Scene (to drop the other over them.....
*staticCubeNode.l = IrrAddCubeSceneNode(10.0)
IrrSetNodeMaterialTexture( *staticCubeNode, *g_cubeTexture, 0 )
IrrSetNodeMaterialFlag(*staticCubeNode,#IRR_EMF_LIGHTING,#False)

Debug("2")
*staticCube.l = IrrPhysicsAddStaticCube(*staticCubeNode,10.0,10.0,10.0,10.0)
IrrPhysicsSetEntityPos(*staticCube,0, 0.0, 100.0)
Debug("3")

createDyNodes() 
setDyNodes()
  
Quit.l = #False
While IrrRunning() And Quit = #False
  IrrBeginScene( 0,0,0 )   
  IrrDrawScene()
  IrrDrawGUI() 
  IrrEndScene()
  IrrPhysicsUpdate() 
  
  While IrrKeyEventAvailable() 
    *KeyEvent = IrrReadKeyEvent()
    Select *KeyEvent\key
      Case #IRR_KEY_SPACE
        setDyNodes() 
      Case  #IRR_KEY_ESCAPE
        Quit=#True 
    EndSelect
  Wend
        
Wend

 
  IrrPhysicsClose()
  IrrStop()
 
 
; jaPBe Version=3.7.2.629
; Build=1
; Language=0x0000 Language Neutral
; FirstLine=40
; CursorPosition=86
; ExecutableFormat=Console
; Executable=T:\projects\pb4\fun\ipvk\ipvk.exe
; DontSaveDeclare
; EOF