'' ----------------------------------------------------------------------------
'' Irrlicht Wrapper For Imperative Languages - Freebasic Examples
'' Frank Dodd (2006-2010)
'' ----------------------------------------------------------------------------
'' Blitz-Irrlicht 1.8.3 Interface by Ed Musolino (AquaLung 2015)
'' ----------------------------------------------------------------------------
'' Example 21 : Carrying Objects
'' This example demonstrates how you can attach a child model To an animated
'' Direct X model containing joints
'' ----------------------------------------------------------------------------

'' ////////////////////////////////////////////////////////////////////////////
'' Includes For extension libraries
Framework usr.birrlicht

'' ////////////////////////////////////////////////////////////////////////////
'' Global variables

' irrlicht objects
Global BoxTexture:Int
Global SceneNode:Int
Global OurCamera:Int
Global JointNode:Int
Global TestNode:Int

'' ////////////////////////////////////////////////////////////////////////////
' start the irrlicht interface
iIrr3D( 1280, 720, 32, False )

' send the window caption
iAppTitle( "Example 21: Carrying Objects" )

' Load a mesh, when loading a .x file the textures will be automatically loaded
' And applied To the model
SceneNode = iLoadAnimMesh( "./Media/dwarf.x", False )

' switch off lighting effects on this model
iNodeMaterialFlag( SceneNode, IRR_EMF_LIGHTING, False )

' set the speed of playback For the animated Direct X model
iAnimationSpeed( SceneNode, 2000 )

' add a camera into the scene pointing at the model
OurCamera = iCreateCamera( IRR_NO_OBJECT )
iPositionNode( OurCamera, 75, 40, -150 )
iCameraTarget( OurCamera, 0, 40, 0 )

' Create a test node To represent the Object that is being carried
TestNode = iCreateCube( 16, IRR_NO_OBJECT )

' Load texture resources For texturing the box
BoxTexture = iLoadTexture( "./Media/texture.jpg" )

' assign a texture To the carried Object
iNodeTexture( TestNode, BoxTexture, 0 )

' switch off lighting effects on the test box
iNodeMaterialFlag( TestNode, IRR_EMF_LIGHTING, False )

' offset the position of the node so that it appears To be attached To the
' characters hand
iPositionNode( TestNode, 20,-15,-10 )

' get an invisible node that is attached To the specified joint on the animated
' node
JointNode = iGetNodeJoint( SceneNode, "Joint16" )

' attach the carried test node To this invisible joint node from now on the
' carried Object will move along with the joint without any more intervention
' from us
iNodeParent( TestNode, JointNode )

iCameraCLSColor( 140, 255, 255 )

' -----------------------------------------------------------------------------
' While the irrlicht environment is still running
While iRun() And (Not iKeyHit( KEY_ESCAPE ))

    ' begin the scene, erasing the canvas with sky-blue before rendering
    iBeginScene()

    ' draw the scene
    iDrawScene()
    
    ' End drawing the scene And render it
    iEndScene()
Wend 

' -----------------------------------------------------------------------------
' Stop the irrlicht engine And Release resources
iEndIrr3D()

End