;; ----------------------------------------------------------------------------
;; Blitz-Irrlicht 1.8.3 Interface by Ed Musolino (AquaLung 2015)
;; ----------------------------------------------------------------------------
;; SOUND Example : IRRKLANG 3D EXAMPLE
;; This example creates a moving sphere that emits 3D music
;; ----------------------------------------------------------------------------


; Include
Include "../_libs/bIrrlicht.bb"


; Variables

Global Music%
Global SoundSphere%
Global Camera%
Global AnimateSphere%
Global Terrain%
Global Terrain_Collision%
Global CameraX#
Global CameraY#
Global CameraZ#
Global CameraTargetX#
Global CameraTargetY#
Global CameraTargetZ#

; start the irrlicht interface
iIrr3D( 800,600, 32, False )
iAppTitle("IrrKlang 3D Test")

SoundSphere = iCreateSphere( 16, False )
iScaleNode( SoundSphere, 10, 10, 10 )
iNodeColor( SoundSphere, 255, 0, 0, 255 )
AnimateSphere = iFlyCircleAnimator( SoundSphere, 1000, 50, 1000, 100, 0.001 )

Camera = iCreateFPSCamera( 0,100.0,0.5,-1,0,0,0,0.0 )
iPositionNode( Camera, 1000, 500, 1000 )

Terrain = iLoadTerrain("./Media/iheight.jpg",0,0,0,0,0,0,1,1,1,255,255,255,255,0,5,ETPS_17 )
iNodeMaterialFlag( Terrain, IRR_EMF_LIGHTING, False )
iNodeTexture( Terrain, iLoadTexture( "./Media/detailmap-dim.jpg" ), 0 )
iScaleNode( Terrain, 10.0, 0.0, 10.0 )
Terrain_Collision = iGetCollisionGroupFromTerrain ( Terrain, 0 )
iCollisionAnimator( Terrain_Collision, Camera, 20, 20, 20, 0.0, -3.0, 0.0, 0.0, 20, 0.0 )

; start the irrklang interface
iKlangInit()

Music = iPlay3DSound( "./Media/getout.ogg", 0, 0, 0, True, False, True, ESM_AUTO_DETECT, False )
iSoundDistance( Music, 100 )

iCameraCLSColor( 158, 204, 226 )
iHideMouse()

While iRun() And (Not iKeyHit( KEY_ESCAPE ))

	iBeginScene()
	
	iDrawScene()

	iPositionSound( Music, iNodeX( SoundSphere, True ),iNodeY( SoundSphere, True ), iNodeZ( SoundSphere, True ) )

	CameraX = iNodeX( Camera, True )
	CameraY = iNodeY( Camera, True )
	CameraZ = iNodeZ( Camera, True )
	CameraTargetX = iCameraTargetX( Camera )
	CameraTargetY = iCameraTargetY( Camera )
	CameraTargetZ = iCameraTargetZ( Camera )
	iListenerPosition( CameraX, CameraY, CameraZ, CameraTargetX, CameraTargetY, CameraTargetZ, 0, 0, 0, 0,1,0 )
	
	iEndScene()
	
Wend 

iKlangEnd()
iEndIrr3D()

End