/*
 * $Id: light.h 4270 2016-11-06 11:02:47Z antonin.misek-skoda-auto.cz $
 *
 * Description  : One line description of file.
 * Author       : Vaclav Kyba <mail/Jabber: vaseo1@gmail.com>  <ICQ: 98576293>
 * 
 * Purpose      :
 *     Long description of what the file is for.
 */


#ifndef __LIGHT__H__
#define __LIGHT__H__

#include <vector>
#include "countable.h"
#include "smartptr.h"
#include "3dmath.h"

namespace VRUT
{
	/// Lights from N900
	struct EnvironmentLight :  public Countable {

		struct EnvironmentLightEntry {
			Vector3 rgb;		//light color
			float luminance;
			Vector3 position;	//light position in "infinity"

			EnvironmentLightEntry() : luminance(0) {}
			EnvironmentLightEntry & operator=(const EnvironmentLightEntry& el) {
				if (this != &el) {
					rgb = el.rgb;
					luminance = el.luminance;
					position = el.position;
				}
				return *this;
			}
		};
		
		std::vector<EnvironmentLightEntry> data;
		std::vector<EnvironmentLightEntry> reducedData;
		int lightReference;
		
		EnvironmentLight() : lightReference(100) {}
	};
	typedef std::vector<EnvironmentLight::EnvironmentLightEntry> envData;
	
	///Light definition
	struct Light
	{
		///Light position is given by transformation matrix of light node
		///Light direction is implicitly (0,0,-1), real direction is given by transformation matrix of light node
		///Light type
		enum LIGHT_TYPE
		{
			OMNI,				///<Omnidirectional
			DIRECTIONAL,		///<Directional light
			SPOTLIGHT,			///<Spotlight
			ENVIRONMENT_LIGHT,	///<EnvironmentLight from N900
			UNKNOWN				///<Unknown type
		} type;
		///Diffuse color
		Vector4 diffuse;
		///Spotlight angle (\c SPOTLIGHT only)
		float angle;
		///Spotlight exponent (\c SPOTLIGHT only)
		float exponent;
		///attenuation by distance (constant, linear, quadratic) coefficients
		Vector3 attenuation;
		///path to IES file
		wxString ies;
		///pointer to EnvironmentLight
		smart_pointer<EnvironmentLight> envLight;
		///Constructor
		Light(LIGHT_TYPE _type=UNKNOWN) : type(_type), diffuse(0.0f,0.0f,0.0f,1.0f), angle(0), exponent(1), attenuation(1,0,0), envLight(NULL)
		{
		}

		///Get string with light properties
		wxString ToString() const
		{
			return wxString::Format(wxT("Light type: %i\nDiffuse: "), type)+diffuse.ToString()+wxString::Format(wxT("\nAngle (spot): %f\nExponent (spot): %f\nAttenuation: ")+
						attenuation.ToString()+wxT("\n"), angle, exponent);
		}

		/// Is same as method
		bool IsSameAs(const Light &l) const 
		{
			if ((type != l.type) || (diffuse != l.diffuse) || (angle != l.angle) || (exponent != l.exponent) || (attenuation!=l.attenuation) || (ies != l.ies))
				return false;
			return true;
		}
	};
}

#endif
