// ----------------------------------------------------------------------------
// 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 "CBillboardGroupSceneNode.h"


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




extern "C"
{

/* ----------------------------------------------------------------------------
adds a billboard group to the scene this is a collection of managed flat 3D textured sprites
*/
DLL_EXPORT int * BBCALL iCreateBillBoardGroup( void )//float sizex, float sizey, float x, float y, float z ) * CHECK FOR ERROR
{
    core::vector3df position( 0.0f, 0.0f, 0.0f );
    core::vector3df rotation( 0.0f, 0.0f, 0.0f );
    core::vector3df scale( 1.0f, 1.0f, 1.0f );
	ISceneNode* node = new CBillboardGroupSceneNode( smgr->getRootSceneNode(), smgr, 666, position, rotation, scale );

	node->drop();
	return (int *)node;
}

/* ----------------------------------------------------------------------------
adds a billboard to the scene this is a flat 3D textured sprite
*/
DLL_EXPORT void BBCALL iBillBoardToGroup( CBillboardGroupSceneNode *node, float sizex, float sizey, float x, float y, float z, float roll, u32 A, u32 R, u32 G, u32 B )
{
    core::vector3df position( x, y, z );
    core::dimension2df size( sizex, sizey );
    video::SColor vertexColor( A, R, G, B );

    node->addBillboard( position, size, roll, vertexColor );
}

/* ----------------------------------------------------------------------------
adds a billboard to the scene this is a flat 3D textured sprite
*/
DLL_EXPORT void BBCALL iBillBoardByAxisToGroup( CBillboardGroupSceneNode *node,
                                              float sizex, float sizey,
                                              float x, float y, float z,
                                              float roll, u32 A, u32 R, u32 G, u32 B,
                                              float axis_x, float axis_y, float axis_z )
{
    core::vector3df position( x, y, z );
    core::vector3df axis( axis_x, axis_y, axis_z );
    core::dimension2df size( sizex, sizey );
    video::SColor vertexColor( A, R, G, B );

    axis.normalize();
    node->addBillboardWithAxis( position, size, axis, roll, vertexColor );
}

/* ----------------------------------------------------------------------------
adds a billboard to the scene this is a flat 3D textured sprite
*/
DLL_EXPORT void BBCALL iFreeBillBoardFromGroup( CBillboardGroupSceneNode *node, CBillboardGroupSceneNode::SBillboard * billboard )
{
    node->removeBillboard( billboard );
}

/* ----------------------------------------------------------------------------
adds a billboard to the scene this is a flat 3D textured sprite
*/
DLL_EXPORT void BBCALL iBillBoardGroupShadows( CBillboardGroupSceneNode *node, float x, float y, float z, f32 intensity, f32 ambient )
{
    const core::vector3df lightDir( x, y, z );
    node->applyVertexShadows( lightDir, intensity, ambient);
}

/* ----------------------------------------------------------------------------
get the number of billboards in the billboard group
*/
DLL_EXPORT u32 BBCALL iBillBoardGroupCount( CBillboardGroupSceneNode *node )
{
    return node->getBillboardCount();
}

/* ----------------------------------------------------------------------------
forces an update of the billboard system
*/
DLL_EXPORT void BBCALL iBillBoardForceUpdate( CBillboardGroupSceneNode *node )
{
    node->forceUpdate( );
}



/* ----------------------------------------------------------------------------
adds a billboard to the scene this is a flat 3D textured sprite
*/
DLL_EXPORT int * BBCALL iCreateBillBoard( float sizex, float sizey, float x, float y, float z )
{
    return (int *)smgr->addBillboardSceneNode(
            NULL,
            dimension2d<f32>( sizex, sizey ),
            vector3df(x, y, z )
    );
}

/* ----------------------------------------------------------------------------
Sets the color of a billboard
*/
DLL_EXPORT void BBCALL iBillBoardColor( IBillboardSceneNode * node, unsigned int topColor, unsigned int bottomColor )
{
	node->setColor( video::SColor(topColor), video::SColor( bottomColor));
}

/* ----------------------------------------------------------------------------
Sets the size of a billboard
*/
DLL_EXPORT void BBCALL iBillBoardSize( IBillboardSceneNode * node, float Width, float Height )
{
	node->setSize( core::dimension2d<f32>(Width,Height));
}

/* ----------------------------------------------------------------------------
Adds a text scene node, which uses billboards. The node, and the text on it,
will scale with distance.
*/
DLL_EXPORT int * BBCALL iCreateTextBillBoard(
		IGUIFont * font,
		const char * text,
		float sizex, float sizey,
		float x, float y, float z,
		ISceneNode * parentNode,
		SColor colorTop,
		SColor colorBottom )
{
	//CHECK IF VALID FONT EXISTS
	if (!font && guienv)
		font = guienv->getBuiltInFont();

	return (int *)smgr->addBillboardTextSceneNode (
			font,
			ConvertCharToWChar(text),
			parentNode,		// parent
            dimension2d<f32>( sizex, sizey ),
            vector3df(x, y, z ),
			-1,		// default ID
			colorTop.color,
			colorBottom.color);
}









}


