'' ----------------------------------------------------------------------------
'' Irrlicht Wrapper For Imperative Languages - Freebasic Examples
'' Frank Dodd (2006-2010)
'' ----------------------------------------------------------------------------
'' Blitz-Irrlicht 1.8.3 Interface by Ed Musolino (AquaLung 2015)
'' ----------------------------------------------------------------------------
'' Example 13: Camera Position
'' This example creates a map For you To move around And displays the Current
'' position of the camera And its rotation on the screen
'' ----------------------------------------------------------------------------

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

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

' irrlicht objects
Global BSPMesh:Int
Global BSPNode:Int
Global Camera:Int
Global BitmapFont:Int
Global X:Float
Global Y:Float
Global Z:Float
Global metrics:String

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

' send the window caption
iAppTitle( "Example 13: Camera Position and Rotation" )

' Create a frist person perspective camera that can be controlled with mouse
' And cursor keys
Camera = iCreateFPSCamera(0,100.0,0.5,-1,0,0,0,0.0)

' reposition And rotate the camera To look at a nice part of the map
iPositionNode( Camera, 1750, 149, 1369 )
iRotateNode( Camera, 4, -461.63, 0 )

' Load a Quake 3 BSP Map from a zip archive
iAddZipFile( "./media/map-20kdm2.pk3", IRR_IGNORE_CASE, IRR_IGNORE_PATHS, "" )
BSPMesh = iLoadOctreeMesh( "20kdm2.bsp" )
BSPNode = iAddOctreeMeshNode( BSPMesh )

' Load the bitmap font as a texture
BitmapFont = iLoadFont ( "./media/bitmapfont.bmp" )

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

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

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

    ' begin the scene
    iBeginScene()

    ' draw the scene
    iDrawScene()

    ' get the position of the camera into the three supplied variables
	px# = iNodeX( Camera, False )
	py# = iNodeY( Camera, False )
	pz# = iNodeZ( Camera, False )
	
    ' Create a wide String with a list of the positions in
    metrics = "POSITION "+ String(px) + " " + String(py) + " " + String(pz)
    
    ' draw this position information To the screen
    iText ( BitmapFont, metrics, 4, 4, 250, 24 )

    ' get the rotation of the camera into the three supplied variables
    'IrrGetNodeRotation( CameraNode, X, Y, Z )
	rx% = iNodePitch( Camera, False )
	ry% = iNodeYaw( Camera, False )
	rz% = iNodeRoll( Camera, False )
	    
    ' Create a wide String with a list of the rotations in
    metrics = "ROTATION "+ String(rx) + " " + String(ry) + " " + String(rz)
    
    ' draw this position information To the screen
    iText ( BitmapFont, metrics, 4, 32, 250, 52 )

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

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


End