//
// Irrlicht Wrapper for Imperative Languages
// Frank Dodd (2006)
//
// Additional Work
// Michael Taupitz (2006)
//
// This wrapper DLL encapsulates a sub-set of the features of the powerful
// Irrlicht 3D Graphics Engine exposing the Object Oriented architecture and
// providing a functional 3D SDK for languages that are not object oriented.
//
// This source was created with the help of the great examples in the Irrlicht
// SDK and the excellent Irrlicht documentation. This software was developed
// using the GCC compiler and Code::Blocks IDE
//

/* ////////////////////////////////////////////////////////////////////////////
includes
*/
#include "irrlichtwrapper.h"


/* ///////////////////////****f* 2D/IrrGetTexture
* NAME
*    IrrGetTexture - Load a Texture
* SYNOPSIS
*    IrrGetTexture( TextureFilename.s )
* FUNCTION
*    Loads the Texturefile 'TextureFilename.s'
*    You can all image-formats that Irrlicht know.
* INPUTS
*    TextureFilename.s - Name of the Texturefile
* RESULT
*    A Pointer to the loaded Texture. If the Pointer is 0 then Irrlicht was not able to load the Texture.
* EXAMPLE
*    *mytexture.l = IrrGetTexture( "./media/texture.jpg" )
* NOTES
*    If you have problems with loading Textures, you should compile as
*    Console-Application to see the Irrlicht-Output. Maybe this helps.
****

//////////////////////////////////////////////////////
global variables
*/

/* ////////////////////////////////////////////////////////////////////////////
external variables
*/
extern IrrlichtDevice *device;
extern IVideoDriver* driver;
extern ISceneManager* smgr;
extern IGUIEnvironment* guienv;


/* ////////////////////////////////////////////////////////////////////////////
Global Function Declarations

all of the below functions are declared as C functions and are exposed without
any mangled names so that they can be easily imported into imperative
languages like FreeBasic
*/
extern "C"
{

/* ////////////////////////////////////////////////////////////////////////////
LIGHTING FUNCTIONS
*/
/****f* Light/IrrAddLight
* NAME
*    IrrAddLight - Adds a dynamic light scene node to the scene graph.
* SYNOPSIS
*    IrrAddLight(x.f,y.f,z.f, red.f, green.f, blue.f, size.f)
* INPUTS
*   x.f,y.f,z.f          - position of the light
*   red.f,green.f,blue.f - color of that light
*   size.f               - size of the light (radius)
* FUNCTION
*   The light will cast dynamic light on all other scene nodes in the scene,
*   which have the material flag #IRR_EMF_LIGHTING turned on. (This is the default setting in most scene nodes).
* RESULT
*    Returns pointer to a light scene node
****
* This is for creating the PB-Importfile, and avoiding to make everything manual
#PBIMPORT:IrrAddLight(x.f,y.f,z.f, red.f, green.f, blue.f, size.f)
*/

STATIC_EXPORT void * DLL_EXPORT IrrAddLight( float X, float Y, float Z, float R, float G, float B, float size )
{
	return smgr->addLightSceneNode( 0, core::vector3df(X,Y,Z),
		video::SColorf(1.0f, R, G, B), size );

}

/****f* Light/IrrSetAmbientLight
* NAME
*    IrrSetAmbientLight - Sets the dynamic ambient light color.
* SYNOPSIS
*    IrrSetAmbientLight(red.f,green.f,blue.f [,alpha.f])
* INPUTS
*   red.f,green.f,blue.f - color of that light
*   alpha.f               - optional alpha value. default is 1.0
* FUNCTION
*   Sets the dynamic ambient light color.
*   The default color is (0,0,0,0) which means it is dark.
* RESULT
*    nothing
****
* This is for creating the PB-Importfile, and avoiding to make everything manual
#PBIMPORT:IrrSetAmbientLight(red.f,green.f,blue.f ,alpha.f=1.0)
*/

STATIC_EXPORT void DLL_EXPORT IrrSetAmbientLight( float R, float G, float B )
{
    driver->setAmbientLight( SColorf( R, G, B, 0.0f ));
}


/* ----------------------------------------------------------------------------
Changes the Ambient-Color of a Light (LightSceneNode)
*/
/****f* Light/IrrSetLightAmbientColor
* NAME
*    IrrSetLightAmbientColor - Sets the ambient light color.
* SYNOPSIS
*    IrrSetLightAmbientColor(*node.l, alpha.l, red.l, green.l, blue.l)
* INPUTS
*   *node.l                      - pointer to a light scene node
*   alpha.l,red.l,green.l,blue.l - new ambient color of that light
* FUNCTION
*   Changes the Ambient-Color of a Light (LightSceneNode)
* RESULT
*    nothing
****
* This is for creating the PB-Importfile, and avoiding to make everything manual
#PBIMPORT:IrrSetLightAmbientColor(*node.l, alpha.l, red.l, green.l, blue.l)
*/
STATIC_EXPORT void DLL_EXPORT IrrSetLightAmbientColor( ILightSceneNode* node, int alpha, int red, int green, int blue )
{
    if (node)
        node->getLightData().AmbientColor = SColor(alpha,red,green,blue);
}

/****f* Light/IrrSetLightSpecularColor
* NAME
*    IrrSetLightSpecularColor - Sets the specular light color.
* SYNOPSIS
*    IrrSetLightSpecularColor(*node.l, alpha.l, red.l, green.l, blue.l)
* INPUTS
*   *node.l                      - pointer to a light scene node
*   alpha.l,red.l,green.l,blue.l - new ambient color of that light
* FUNCTION
*   Changes the Specular-Color of a Light (LightSceneNode)
* RESULT
*    nothing
****
* This is for creating the PB-Importfile, and avoiding to make everything manual
#PBIMPORT:IrrSetLightSpecularColor(*node.l, alpha.l, red.l, green.l, blue.l)
*/
STATIC_EXPORT void DLL_EXPORT IrrSetLightSpecularColor( ILightSceneNode* node, int alpha, int red, int green, int blue )
{
    if (node)
        node->getLightData().SpecularColor = SColor(alpha,red,green,blue);
}

/****f* Light/IrrSetLightDiffuseColor
* NAME
*    IrrSetLightDiffuseColor - Sets the diffuse light color.
* SYNOPSIS
*    IrrSetLightDiffuseColor(*node.l, alpha.l, red.l, green.l, blue.l)
* INPUTS
*   *node.l                      - pointer to a light scene node
*   alpha.l,red.l,green.l,blue.l - new diffuse color of that light
* FUNCTION
*   Changes the Diffuse-Color of a Light (LightSceneNode)
* RESULT
*    nothing
****
* This is for creating the PB-Importfile, and avoiding to make everything manual
#PBIMPORT:IrrSetLightDiffuseColor(*node.l, alpha.l, red.l, green.l, blue.l)
*/
STATIC_EXPORT void DLL_EXPORT IrrSetLightDiffuseColor( ILightSceneNode* node, int alpha, int red, int green, int blue )
{
    if (node)
        node->getLightData().DiffuseColor = SColor(alpha,red,green,blue);
}

/****f* Light/IrrSetLightPosition
* NAME
*    IrrSetLightPosition - Sets the position of the light
* SYNOPSIS
*    IrrSetLightPosition(*node.l, x.f,y.f,z.f)
* INPUTS
*   *node.l                     - pointer to a light scene node
*   x.f,y.f,z.f                 - position
* FUNCTION
*   Position of the light. If Type is #IRR_ELT_DIRECTIONAL, this is
*   the direction vector the light is coming from
* RESULT
*    nothing
****
* This is for creating the PB-Importfile, and avoiding to make everything manual
#PBIMPORT:IrrSetLightPosition(*node.l, x.f,y.f,z.f)
*/
STATIC_EXPORT void DLL_EXPORT IrrSetLightPosition( ILightSceneNode* node, float x, float y, float z )
{
    if (node)
        node->getLightData().Position = vector3df(x,y,z);
}


/****f* Light/IrrSetLightRadius
* NAME
*    IrrSetLightRadius - set the radius of the light.
* SYNOPSIS
*    IrrSetLightRadius(*node.l, radius.f)
* INPUTS
*   *node.l       - pointer to a light scene node
*   radius.f      - new radius of the Light
* FUNCTION
*   Radius of light. Everything within this radius be be lighted.
* RESULT
*    nothing
****
* This is for creating the PB-Importfile, and avoiding to make everything manual
#PBIMPORT:IrrSetLightRadius(*node.l, radius.f)
*/
STATIC_EXPORT void DLL_EXPORT IrrSetLightRadius( ILightSceneNode* node, f32 radius )
{
    if (node)
        node->getLightData().Radius = radius;
}

/****f* Light/IrrGetLightRadius
* NAME
*    IrrGetLightRadius - get the radius of the light.
* SYNOPSIS
*    IrrGetLightRadius(*node.l, *radius.f)
* INPUTS
*   *node.l       - pointer to a light scene node
*   *radius.f     - returns radius of the Light
* FUNCTION
*   returns the radius of the light in the radius-paramter
* RESULT
*    nothing
****
* This is for creating the PB-Importfile, and avoiding to make everything manual
#PBIMPORT:IrrGetLightRadius(*node.l, *radius.f)
*/
STATIC_EXPORT void DLL_EXPORT IrrGetLightRadius( ILightSceneNode* node, f32& radius)
{
    if (node)
        radius= node->getLightData().Radius;
}


/****f* Light/IrrSetLightType
* NAME
*    IrrSetLightType - Sets the light type
* SYNOPSIS
*    IrrSetLightType(*node.l, lightType.l)
* INPUTS
*   *node.l       - pointer to a light scene node
*   lightType.l   - type of light (#IRR_ELT_)
* FUNCTION
*   set or change the type of the light
* RESULT
*    nothing
****
* This is for creating the PB-Importfile, and avoiding to make everything manual
#PBIMPORT:IrrSetLightType(*node.l, lightType.l)
*/

STATIC_EXPORT void DLL_EXPORT IrrSetLightType( ILightSceneNode* node, E_LIGHT_TYPE type )
{
    if (node)
        node->getLightData().Type = type;
}


/****
* This is for creating the PB-Importfile, and avoiding to make everything manual
#PBIMPORT:IrrSetLightAttenuation(*node.l, x.f,y.f,z.f)
*/
STATIC_EXPORT void DLL_EXPORT IrrSetLightAttenuation( ILightSceneNode* node, float x, float y, float z )
{
    if (node)
        node->getLightData().Attenuation = vector3df(x,y,z);
}

/****
* This is for creating the PB-Importfile, and avoiding to make everything manual
#PBIMPORT:IrrSetLightDirection(*node.l, x.f,y.f,z.f)
*/
STATIC_EXPORT void DLL_EXPORT IrrSetLightDirection( ILightSceneNode* node, float x, float y, float z )
{
    if (node)
        node->getLightData().Direction = vector3df(x,y,z);
}

/****
* This is for creating the PB-Importfile, and avoiding to make everything manual
#PBIMPORT:IrrSetLightCone(*node.l, innercone.f, outercone.f)
*/
STATIC_EXPORT void DLL_EXPORT IrrSetLightCone( ILightSceneNode* node, f32 innercone, f32 outercone)
{
    if (node) {
        node->getLightData().InnerCone = innercone;
        node->getLightData().OuterCone = outercone;
    }
}

/****
* This is for creating the PB-Importfile, and avoiding to make everything manual
#PBIMPORT:IrrSetLightFalloff(*node.l, falloff.f)
*/
STATIC_EXPORT void DLL_EXPORT IrrSetLightFalloff( ILightSceneNode* node, f32 falloff)
{
    if (node)
        node->getLightData().Falloff = falloff;
}

/****
* This is for creating the PB-Importfile, and avoiding to make everything manual
#PBIMPORT:IrrSetLightCastShadows(*node.l, cast.l)
*/
STATIC_EXPORT void DLL_EXPORT IrrSetLightCastShadows( ILightSceneNode* node, bool cast)
{
    if (node)
        node->getLightData().CastShadows = cast;
}


/* ////////////////////////////////////////////////////////////////////////////
all of the above functions are declared as C functions and are exposed without
any mangled names
*/
}
