;; ----------------------------------------------------------------------------
;; Irrlicht Wrapper For Imperative Languages - Purebasic Examples
;; IrrlichtWrapper and FreeBasic-Example by Frank Dodd (2006)
;; Improved IrrlichtWrapper - Michael Taupitz (2007)
;; PureBasic-Examples by Michael Taupitz (neotoma) & Marius Eckardt (Thalius) 
;; ----------------------------------------------------------------------------
;; Example 04 : 3D Models - Meshes And Nodes
;; This example loads an MD2 model And adds it As a node To the scene
;; ----------------------------------------------------------------------------

EnableExplicit 

;; Include the Irr3D-Requester
XIncludeFile "Irr3DRequester.pb"


;; ////////////////////////////////////////////////////////////////////////////
;; Global variables

; irrlicht objects
Define *MD2Mesh.irr_mesh          ;Pointer to the Mesh
Define *MeshTexture.irr_texture     ;Pointer to the Texture
Define *SceneNode.irr_node        ;Pointer to the SceneNode
Define *OurCamera.irr_camera      ;Pointer to the Camera

; -----------------------------------------------------------------------------
; To Start the Irrlicht-Device we use the Irr3DRequester, to make it more comfortable
; for the Users, and also easier to test different resolutions and devices.
If Irr3DRequester()

  ; set the window caption
  IrrSetWindowCaption( "Example 04: 3D Models - Meshes and Nodes" )
  
  ; add credits for the model as a static text GUI object on the display
  IrrGuiAddStaticText( "Welcome to Irrlicht", 4,0,200,16, #IRR_GUI_NO_BORDER, #IRR_GUI_NO_WRAP )
  
  ; load a mesh this acts as a blue print for the model
  *MD2Mesh = IrrGetMesh( "media\sydney.md2" )
  
  ; load texture resources for texturing the scene nodes
  *MeshTexture = IrrGetTexture( "media\sydney.bmp" )
  
  ; add the mesh to the scene as a new node, the node is an instance of the
  ; mesh object supplied here
  *SceneNode = IrrAddMeshToScene( *MD2Mesh )
  
  ; apply a material to the node to give its surface color
  IrrSetNodeMaterialTexture( *SceneNode, *MeshTexture, 0 )
  
  ; switch off lighting effects on this model, as there are no lights in this
  ; scene the model would otherwise render pule black
  IrrSetNodeMaterialFlag( *SceneNode, #IRR_EMF_LIGHTING, #IRR_OFF )
  
  ; play an animation sequence embeded in the mesh. MD2 models have a group of
  ; preset animations for various poses and actions. this animation sequence is
  ; the character standing idle
  IrrPlayNodeMD2Animation( *SceneNode, #IRR_EMAT_STAND )
  
  ; add a camera into the scene, the first co-ordinates represents the 3D
  ; location of our view point into the scene the second co-ordinates specify the
  ; target point that the camera is looking at
  *OurCamera = IrrAddCamera( 50,0,0, 0,0,0 )
   
  ; -----------------------------------------------------------------------------
  ; while the irrlicht environment is still running
  While IrrRunning()
      ; begin the scene, erasing the canvas with sky-blue before rendering
      IrrBeginScene( 240, 255, 255 )
  
      ; draw the scene
      IrrDrawScene()
      
      ; draw the GUI
      IrrDrawGUI()
  
      ; end drawing the scene and render it
      IrrEndScene()
  Wend
  
  ; -----------------------------------------------------------------------------
  ; Stop the irrlicht engine and release resources
  IrrStop()
  
EndIf  

End
; IDE Options = PureBasic 4.10 Beta 3 (Windows - x86)
; CursorPosition = 38
; FirstLine = 15
; Folding = -