'' ----------------------------------------------------------------------------
'' Irrlicht Wrapper For Imperative Languages - Freebasic Examples
'' Frank Dodd (2006-2010)
'' ----------------------------------------------------------------------------
'' Blitz-Irrlicht 1.8.3 Interface by Ed Musolino (AquaLung 2015)
'' ----------------------------------------------------------------------------
'' Example 49 : Collision in a Loaded IrrEdit Scene
'' This example demonstrates collision in a scene that was created in IrrEdit
'' the nodes in the scene are found And Then collision selection objects are
'' created For them in the same way as you would with a custom created scene
'' ----------------------------------------------------------------------------

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

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

' irrlicht objects
Global Camera:Int
Global CameraNode:Int
Global NodeGround:Int
Global NodeBox:Int
Global SelectorGround:Int
Global SelectorBox:Int
Global CombinedCollision:Int
Global CollisionAnimator:Int


'' ////////////////////////////////////////////////////////////////////////////
' start the irrlicht interface
iIrr3D( 1024, 768, 32, False )

' send the window caption
iAppTitle( "Example 49: Collision in a Loaded Scene" )

' Load an example scene created in irrEdit
iLoadScene( "./media/CollisionScene.irr" )

' we add a first person perspective camera To the scene so you can look about
' And move it into the center of the map
Camera = iCreateFPSCamera(0,100.0,0.5,-1,null,0,0,0.0)
CameraNode = Camera
iPositionNode( CameraNode, 200, 100, 0 )
iRotateNode( CameraNode, 0, -90, 0 )

' first we need To get references To the objects in the scene that the viewer
' can collide with
NodeGround = iGetNodeByName( "Ground" )
NodeBox = iGetNodeByName( "Pillar" )

' Next we need To Create collision objects from the nodes 
SelectorGround = iGetCollisionGroupFromBox( NodeGround )
SelectorBox = iGetCollisionGroupFromBox( NodeBox )

' now that we have collision objects For each of the nodes we need To combine
' them into a collision group
CombinedCollision = iCreateCombinedCollisionGroup ()

' creates a meta-selector that is a group of selector objects
iAddCollisionGroupToCombination ( CombinedCollision, SelectorGround )
iAddCollisionGroupToCombination ( CombinedCollision, SelectorBox )

' finally we add a collision animator To the camera, this constrains the camera
' so that its movement is restricted by collision with the collision groups we
' just created. the parameters we supply are as follows: -
'       The collision objects, the node To be effected by collision,
'       x, y And z radius of the collision area,
'       x, y And z force of gravity To apply To the node affected by collision,
'       x, y And z offset of the node
CollisionAnimator = iCollisionAnimator(CombinedCollision, CameraNode,30.0,30.0,30.0,0.0,-3.0,0.0,0.0,50.0,0.0 )

' we also hide the mouse pointer To see the view better
iHideMouse()

' erase the canvas with sky-blue before rendering
iCameraCLSColor( 200, 200, 255 )

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

    ' begin the scene
    iBeginScene()

    ' draw the scene
    iDrawScene()

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

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


End