;; ----------------------------------------------------------------------------
;; 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 11 : Animators
;; This example demonstrates animators, these are mechanisms applied To nodes
;; in the scene that animate the object in some manner over time. this wrapper
;; exposes six animators five of which are shown here
;; ----------------------------------------------------------------------------

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

; irrlicht objects
*BoxTexture.irr_texture
*FloorBox.irr_node
Dim *AnimatedBox.irr_node(5) 
*DeletedBox.irr_node
*CircleBox.irr_node
*FlyBox.irr_node
*RotateBox.irr_node
*SplineBox.irr_node
*ret.irr_animator
*camera.irr_camera
Dim sx.f(4)
Dim sy.f(4)
Dim sz.f(4)


;; ////////////////////////////////////////////////////////////////////////////
;; GDB debugger main() function

; -----------------------------------------------------------------------------
; 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()
  
  ; send the window caption
  IrrSetWindowCaption( "Example 11: Animators" )
  
  ; add a bright ambient light to the scene to brighten everything up
  IrrSetAmbientLight( 1,1,1 )
  
  ; first lets load a texture that we can use on the test boxes in the scene
  *BoxTexture = IrrGetTexture( "media\purebasiclogo.bmp" )
  
  ; loop around and set up 5 boxes so we can show each of the animators
  For box_index = 1 To 5
      ; create the box
      *AnimatedBox(box_index) = IrrAddCubeSceneNode(10)
      ; texture the box
      IrrSetNodeMaterialTexture( *AnimatedBox(box_index), *BoxTexture, 0 )
      ;
      ;No Lights, so we avoid to see black boxes. Therfore we set Lighting off.
      IrrSetNodeMaterialFlag( *AnimatedBox(box_index),#IRR_EMF_LIGHTING,#False)
            
      ; scale the box up to a visible size
      IrrSetNodeScale( *AnimatedBox(box_index), 2.5,2.5,5 )
  Next
  
  
  ; this animator will delete the box after a specified number of milliseconds
  ; have passed, in this case 5 seconds
  *ret = IrrAddDeleteAnimator( *AnimatedBox(1), 5000 )
  
  
  ; this animator will fly the box around in a circle, the first 3 parameters
  ; specify the center of the circle, the next specifies the radius of the circle
  ; and finally a speed parameter to specify how far the box is moved each frame
  *ret = IrrAddFlyCircleAnimator( *AnimatedBox(2), 0,50,0, 50, 0.001 )
  
  
  ; this animator will fly the box in a straight line, the first three parameters
  ; specify the start position, the next three the end position, the next number
  ; is the number of milliseconds it takes to fly the path (in this case 3
  ; seconds) and finally you can specify if it is to fly the path once or to loop
  ; around flying it endlessly
  *ret = IrrAddFlyStraightAnimator( *AnimatedBox(3), 0,50,-300, 0,50,300, 3000, IRR_LOOP )
  
  
  ; this animator will spin the box around its centre, its very easy to set up
  ; and simply consists of the speed its to be rotated each frame
  *ret = IrrAddRotationAnimator( *AnimatedBox(4), 0, 0.1, 0 )
  
  ; we move this box out of the way also so it doesnt obscure the deleted box
  IrrSetNodePosition( *AnimatedBox(4), 0,100,0 )
  
  
  ; the last animator is the Spline Animator, its more difficult to set up but
  ; is very natural looking and powerful. A spline is a curved line that passed
  ; through or close to a list of co-ordinates, creating a smooth flight.
  
  ; this animator needs a list of coordinates stored in three arrays, one array
  ; each for the X, Y and Z locations of all the points. The arrays defined here
  ; create a 4 point circle that wobbles up and down a bit. another good way to
  ; get co-ordinates is to load in the camera position example and move your
  ; camera to a point and write down its co-ordinates, this is particularly good
  ; for getting points on a map
  sx(1) = -100
  sy(1) = 50
  sz(1) = 0
  
  sx(2) = 0
  sy(2) = 100
  sz(2) = -100
  
  sx(3) = 100
  sy(3) = 50
  sz(3) = 0
  
  sx(4) = 0
  sy(4) = 100
  sz(4) = 100
  
  ; once the points are defined we can create the animator first we tell it how
  ; many points are in the list (in this case 4) then we pass the first element
  ; of the array of points for each of the x, y and z arrays, the next parameter
  ; defines the starting point on the curve, the next the speed the node travels
  ; along the curve and the final number specifies how tightly the curve is tied
  ; to the points (0 is angular and 1 is loose)
  *ret = IrrAddSplineAnimator( *AnimatedBox(5), 4, @sx(1), @sy(1), @sz(1), 0, 0.5, 1)
  
  
  ; add a static camera to the scene to observe the animation
  *camera = IrrAddCamera( 150,50,0, 0,50,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()
  
      ; 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 2 (Windows - x86)
; CursorPosition = 52
; FirstLine = 50
; Folding = -