'' ----------------------------------------------------------------------------
'' Irrlicht Wrapper For Imperative Languages - Freebasic Examples
'' Frank Dodd (2006-2010)
'' ----------------------------------------------------------------------------
'' Blitz-Irrlicht 1.8.3 Interface by Ed Musolino (AquaLung 2015)
'' ----------------------------------------------------------------------------
'' Example 12 : Collision
'' This example demonstrates the Final animator the collision animator And how
'' To make one node collide against another. In this example we collide the
'' camera node against a BSP map allowing us To walk around the map naturally
'' there are a couple of holes in this map as the textures are Not available
'' To Load the polygons. see If you can escape through the bottom of the screen
'' ----------------------------------------------------------------------------

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

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

' irrlicht objects
Global BSPMesh:Int
Global BSPNode:Int
Global Camera:Int
Global CameraNode:Int
Global MapCollision:Int

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

' send the window caption
iAppTitle( "Example 12: Collision" )

' first we Load the example map into the scene For details on this please
' read example 5
iAddZipFile( "./media/map-20kdm2.pk3", IRR_IGNORE_CASE, IRR_IGNORE_PATHS, "" )
BSPMesh = iLoadOctreeMesh( "20kdm2.bsp" )
BSPNode = iAddOctreeMeshNode( BSPMesh )

' Next we add a first person perspective camera To the scene
Camera = iCreateFPSCamera(0,100.0,0.5,-1,0,0,0,0.0)

' And move it into the middle of the map
iPositionNode( Camera, 1750, 149, 1369 )
iRotateNode( Camera, 4, -461.63, 0 )


' the first thing we need To do with collision is To Create an Object called a
' selector that contains a selection of triangle To be used in the collision
' calculations there are a number of different ways of doing this depending on
' the Type of mesh you are working with. in this example we are using the
' complex BSP map And therefore should use the following command
MapCollision = iGetCollisionGroupFromComplexMesh( BSPMesh, BSPNode,0 )


' now we can add the sixth And Final animator To our camera Object the collision
' animator. This takes a Long list of parameters that define the following :-
' 1) the collision Object created from the map
' 2) the node that is going To be collided against the map
' 3) 3 vaues defining the radius of the node (the camera in this Case). If you
'    make this value too small you wont be able To climb steps, If its too big
'    you might get stuck in a doorway Or be able To jump over a wall. the best
'    thing To do is To have some fun experimenting
' 4) 3 values defining the pull of gravity, in this Case a weak downward force
' 5) finally 3 values defining the offset of the node from the collision point
'    this will enable you To bring an Object To the surface
iCollisionAnimator( MapCollision,Camera,30.0,30.0,30.0,0.0,-9.8,0.0,0.0,50.0,0.0 )

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

', erasing the canvas with sky-blue before rendering
iCameraCLSColor( 128, 255, 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