// ----------------------------------------------------------------------------
// Blitz-Irrlicht 1.8.3 Wrapper by Ed Musolino 2015
// Based off of Frank Dodd's Irrlicht 1.7 Freebasic Wrapper (2006-2010)
// ----------------------------------------------------------------------------

//  This software is provided 'as-is', without any express Or implied
//  warranty.  In no event will the authors be held liable For any damages
//  arising from the use of this software.

//  Permission is granted To anyone To use this software For any purpose,
//  including commercial applications, And To alter it And redistribute it
//  freely, subject To the following restrictions:

//  1. The Origin of this software must Not be misrepresented; you must not
//     claim that you wrote the original software. If you use this software
//     in a product, an acknowledgement in the product documentation would be
//     appreciated but is Not required.
//  2. Altered source versions must be clearly marked as such, And must Not be
//     misrepresented as being the original software.
//  3. This notice may Not be removed Or altered from any source distribution.
//
// /////////////////////////////////////////////////////////////////////////////

#include "bIrrlicht.h"
#include "CLODSceneNode.h"
#include "CZoneSceneNode.h"


extern IrrlichtDevice*		device;
extern IVideoDriver*		driver;
extern ISceneManager*		smgr;
extern IGUIEnvironment*		guienv;


extern "C"
{
/* ----------------------------------------------------------------------------
adds a LOD management node to the scene
*/
DLL_EXPORT int * BBCALL iCreateLODMgr( u32 fadeScale, bool useAlpha, void (*callback)(u32, ISceneNode *))	//CLODSceneNode *
{
	CLODSceneNode* node = new CLODSceneNode( smgr->getRootSceneNode(), -1 );
	if (fadeScale > 0 ) node->fadeScale = fadeScale;
	node->useAlpha = useAlpha;
	node->callback = callback;
	return (int *)node;
}

/* ----------------------------------------------------------------------------
adds a level of detail to a LOD management node
*/
DLL_EXPORT void BBCALL iLODMesh(CLODSceneNode* node, f32 distance, IAnimatedMesh * mesh )
{
	node->AddLODMesh( distance, mesh );
}

/* ----------------------------------------------------------------------------
sets material mapping for fading LOD nodes
*/
DLL_EXPORT void BBCALL iLODMaterialMap(CLODSceneNode* node, E_MATERIAL_TYPE source, E_MATERIAL_TYPE target )
{
	node->SetMaterialMapping( source, target );
}

/* ----------------------------------------------------------------------------
adds a zone/distance management node to the scene
*/
DLL_EXPORT int * BBCALL iCreateZoneMgr( f32 initialNearDistance, f32 initialFarDistance )	//CZoneSceneNode *
{
	CZoneSceneNode* node = new CZoneSceneNode( initialNearDistance, initialFarDistance,
                                                smgr->getRootSceneNode(), smgr, -1 );
//	node->drop();
	return (int *)node;
}

/* ----------------------------------------------------------------------------
sets the draw distances of nodes in the zone/distance management node
*/
DLL_EXPORT void BBCALL iZoneMgrProperties( CZoneSceneNode* node,
                                            f32 newNearDistance,
                                            f32 newFarDistance,
                                            bool accumulateChildBoxes )
{
	node->SetDrawProperties( newNearDistance, newFarDistance, accumulateChildBoxes );
}

/* ----------------------------------------------------------------------------
sets the draw distances of nodes in the zone/distance management node
*/
DLL_EXPORT void BBCALL iZoneMgrBndBox(
                                            CZoneSceneNode* node,
                                            f32 x, f32 y, f32 z,
                                            f32 w, f32 h, f32 d )
{
	node->SetBoundingBox( x, y, z, w, h, d );
}


/* ----------------------------------------------------------------------------
sets the draw distances of nodes in the zone/distance management node
*/
DLL_EXPORT void BBCALL iZoneMgrAttachTerrain(
                                            CZoneSceneNode* node,
											CTerrainTileSceneNode * terrainSource,
											char * structureMap,
											char * colorMap,
											char * detailMap,
											s32 x, s32 y,
											s32 sliceSize )
{
	core::position2d<s32> dataPositionSource( x, y );
	node->attachTerrain ( terrainSource, structureMap, colorMap, detailMap, dataPositionSource, sliceSize );
}











}