;; ----------------------------------------------------------------------------
;; Irrlicht Wrapper For Imperative Languages - Purebasic Examples
;; IrrlichtWrapper and FreeBasic-Example by Frank Dodd (2006)
;; Improved IrrlichtWrapper and PureBasicExample by Michael Taupitz 
;; ----------------------------------------------------------------------------
;; Example 36 : LensFlare
;; This Example is converted from the Acki's Extensions LensFlare-Demo.
;; ----------------------------------------------------------------------------

EnableExplicit 

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

;; ////////////////////////////////////////////////////////////////////////////
;; Global variables
Define *camera.irr_camera
Define *light.irr_node
Define *noda.irr_node
Define *lensflareNode.irr_node
Define *mTexture.irr_texture
Define *dynamicCubeNode.irr_node
Define *dc.irr_node
Define *mesh.irr_mesh, *mc.irr_mesh
Define mx.f,my.f,mz.f

Define fps.l=0, lastFPS.l = 0

; -----------------------------------------------------------------------------
; 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 36 : LensFlare" )
  
  
  IrrPhysicsInit() 
  
  
  ;Creating a light as Parent for the LensFlare
  ;*light = IrrAddLight(0,0,0,0.6,0.7,1.0,600.0)
  
  *mTexture   = IrrGetTexture("media/wall.bmp") 
  *mesh =   IrrGetMesh("media/mikesbox.3ds")
  *noda = IrrAddMeshToScene(*mesh) 
  IrrSetNodeScale( *noda,20,20,20)
  IrrSetNodeMaterialTexture(*noda,*mTexture,0)
  IrrSetNodeMaterialTexture(*noda,*mTexture,1)
  
  IrrSetNodeMaterialType(*noda,#IRR_EMT_SOLID) 
  IrrSetNodeMaterialFlag(*noda,#IRR_EMF_LIGHTING,#False)
  *mc = IrrPhysicsAddStaticMesh(*mesh,*noda,20,20,20,10)
  IrrPhysicsSetEntityMassMatrix(*mc,0.0001,0.0,0.0,0.0)  
  IrrAddRotationAnimator(*noda,0,0,0.1)

  
;IrrPhysicsSetEntityRot(*noda,90,0,90)
  
  
  *dynamicCubeNode = IrrAddCubeSceneNode(100.0)
  IrrSetNodeMaterialTexture( *dynamicCubeNode, *mTexture, 0 )
  IrrSetNodeMaterialFlag(*dynamicCubeNode,#IRR_EMF_LIGHTING,#False)
  *dc = IrrPhysicsAddDynamicCube(*dynamicCubeNode,100.0,100.0,100.0,4.0)
  IrrPhysicsSetEntityPos(*dc,0,0,100)
  
  *dynamicCubeNode = IrrAddCubeSceneNode(100.0)
  IrrSetNodeMaterialTexture( *dynamicCubeNode, *mTexture, 0 )
  IrrSetNodeMaterialFlag(*dynamicCubeNode,#IRR_EMF_LIGHTING,#False)
  *dc = IrrPhysicsAddDynamicCube(*dynamicCubeNode,100.0,100.0,100.0,1.0)
  IrrPhysicsSetEntityPos(*dc,30,150,100)
  
  
  
  ;A simple FPS-Cam is enough for this example.
  ; *camera = IrrAddFPSCamera()
   ; IrrSetNodePosition(*camera,0,0,0)
  *camera = IrrAddCamera( 0,0,-750, 0,0,0 )
  ; disable mouse cursor
  IrrHideMouse() 
  
  ; -----------------------------------------------------------------------------
  ; while the irrlicht environment is still running
  While IrrRunning()
    ; begin the scene, erasing the canvas with sky-blue before rendering
    IrrBeginScene( 0,0,0)
    
    ; draw the scene to the render buffer
    IrrDrawScene()
    
    IrrGetNodeRotation(*noda,@mx.f,@my.f,@mz.f)
    IrrPhysicsSetEntityRot(*mc,mx,my,mz)
    IrrPhysicsUpdate()
    
    ; end drawing the scene and render it
    IrrEndScene()
    
    fps = IrrGetFPS()
    If fps <> lastFPS 
      IrrSetWindowCaption("IrrlichtWrappper - LensFlare example FPS:" + Str(fps) )
      lastFPS = fps;
    EndIf
    
    
  Wend
  
  ; -----------------------------------------------------------------------------
  ; Stop the irrlicht engine and release resources
  IrrStop()
  IrrPhysicsClose()
EndIf


End

; jaPBe Version=3.7.2.629
; Build=0
; Language=0x0000 Language Neutral
; FirstLine=39
; CursorPosition=57
; ExecutableFormat=Console
; DontSaveDeclare
; IDE Options = PureBasic 4.10 Beta 2 (Windows - x86)
; CursorPosition = 52
; FirstLine = 50
; Folding = -