//********************************************************************
// This source file is part of Ninfa3D Engine
// 
// Copyright (C) 2008-2009 Viz_fuerte.
// All rights reserved.
// 
// LIMITED WARRANTY
// This software is provided "as-is", without any express or implied warranty.
// In no event shall the author be held liable for any damages arising from the use of this software.
// This is a contract. By accepting the Ninfa3D Engine (the SOFTWARE), 
// you (either an individual or a single entity, the LICENSEE) accept the terms and conditions of this licensing agreement.
// 
// If the LICENSEE does not accept the terms and conditions, then LICENSEE must not accept the SOFTWARE.
// If at a later time the LICENSEE decides not to continue licensing the SOFTWARE under these terms and 
// conditions, then the LICENSEE must delete permanently all files constituting the SOFTWARE.
//
// File: Light.cpp
//********************************************************************

/*--------------------------------------------------------------------
Includos*/

	#include "..\..\Header Files\Ninfa3D.h"

/*--------------------------------------------------------------------
Variables externas*/

	extern IrrlichtDevice* device;
	extern IVideoDriver* driver;
	extern ISceneManager* SceneManager;

/*--------------------------------------------------------------------
Declaracion global de funciones*/

extern "C"
{

	/*====================================================================
	Crea una luz*/

	DLL_EXPORT void* DLL_APIENTRY CreateLight(E_LIGHT_TYPE LightType)
	{
		ILightSceneNode* Light = SceneManager->addLightSceneNode(0,vector3df(0,0,0),SColorf(1,1,1),100.0);
		
		float Red   = SceneManager->getAmbientLight().getRed();
		float Green = SceneManager->getAmbientLight().getGreen();
		float Blue  = SceneManager->getAmbientLight().getBlue();

		Light->getLightData().SpecularColor = SColorf(1.0,1.0,1.0,1.0);
		Light->getLightData().AmbientColor  = SColorf(Red,Green,Blue,1.0);

		Light->enableCastShadow(false);

		Light->setLightType(LightType);
		return (void*)Light;
	}

	/*====================================================================
	Cambia el tamaņo del angulo de la luz de tipo cono*/

	DLL_EXPORT void DLL_APIENTRY LightConeAngles(ILightSceneNode* Light,float Inner,float Outer)
	{
		if(!Light)
			device->getLogger()->log( "ERROR in LightConeAngles: The light does not exist.",ELL_ERROR );

		Light->getLightData().InnerCone = Inner;
		Light->getLightData().OuterCone = Outer;
	}

	/*====================================================================
	*/

	DLL_EXPORT void DLL_APIENTRY LightFalloff(ILightSceneNode* Light,float Falloff)
	{
		if(!Light)
			device->getLogger()->log( "ERROR in LightFalloff: The light does not exist.",ELL_ERROR );

		Light->getLightData().Falloff = Falloff;
	}

	/*====================================================================
	Hace que la luz sea una guia para las sombras*/

	DLL_EXPORT void DLL_APIENTRY LightCastShadow(ILightSceneNode* Light)
	{
		if(!Light)
			device->getLogger()->log( "ERROR in LightCastShadow: The light does not exist.",ELL_ERROR );

		Light->enableCastShadow(true);
	}

	/*====================================================================
	*/

	DLL_EXPORT void DLL_APIENTRY LightAttenuation(ILightSceneNode* Light,float Constant,float Linear,float Quadratic)
	{
		if(!Light)
			device->getLogger()->log( "ERROR in LightAttenuation: The light does not exist.",ELL_ERROR );

		Light->getLightData().Attenuation = vector3df(Constant,Linear,Quadratic);
	}

	/*====================================================================
	Cambia el radio de la luz*/

	DLL_EXPORT void DLL_APIENTRY LightRadius(ILightSceneNode* Light,float Radius)
	{
		if(!Light)
			device->getLogger()->log( "ERROR in LightRadius: The light does not exist.",ELL_ERROR );

		Light->setRadius(Radius);
	}

	DLL_EXPORT void DLL_APIENTRY LightDirection(ILightSceneNode* Light,float X,float Y,float Z)
	{
		if(!Light)
			device->getLogger()->log( "ERROR in LightDirection: The light does not exist.",ELL_ERROR );

		Light->getLightData().Direction = vector3df(X,Y,Z);
	}

	/*====================================================================
	Cambia el color de la luz*/

	DLL_EXPORT void DLL_APIENTRY LightColor(ILightSceneNode* Light,unsigned int R,unsigned int G,unsigned int B)
	{
		if(!Light)
			device->getLogger()->log( "ERROR in LightColor: The light does not exist.",ELL_ERROR );

		Light->getLightData().SpecularColor = SColorf((float)R / 255,(float)G / 255,(float)B / 255,1.0);
		Light->getLightData().DiffuseColor = SColorf((float)R / 255,(float)G / 255,(float)B / 255,1.0);
		Light->getLightData().AmbientColor = SColorf((float)R / 255,(float)G / 255,(float)B / 255,1.0);
	}

}