#include "EPSG/LightSource.h"

/* EPSG Includes */
#include "EPSG/LightManager.h"

/* System Includes */
#ifdef WIN32
	#include <Windows.h>
#endif

/* OpenGL Includes */
#include <GL/GL.h>
#include <GL/GLU.h>

EPSG::LightSource::LightSource()
{
	_id = EPSG::LightManager::nextID();
	if( _id == 0 )
		glEnable( GL_LIGHTING );
}

int EPSG::LightSource::setupLights()
{
	float pos[4] = {_pos.x, _pos.y, _pos.z, 1};
	float amb[4] = {_amb[0], _amb[1], _amb[2], _amb[3]};
	glLightfv( GL_LIGHT0 + _id, GL_POSITION, pos );
	glLightfv( GL_LIGHT0 + _id, GL_AMBIENT, amb );
	glEnable( GL_LIGHT0 + _id );
	return 1;
}

void EPSG::LightSource::setPosition( float x, float y, float z )
{
	_pos.x = x;
	_pos.y = y;
	_pos.z = z;
}

void EPSG::LightSource::setPosition( Vec3<float> pos )
{
	_pos = pos;
}

void EPSG::LightSource::setDirectional( bool val )
{
	if( val )
		_pos.w = 0;
	else
		_pos.w = 1;
}

void EPSG::LightSource::setAmbient( float r, float g, float b, float a )
{
	_amb[0] = r;
	_amb[1] = g;
	_amb[2] = b;
	_amb[3] = a;
}

void EPSG::LightSource::setDiffuse( float r, float g, float b, float a )
{
	_dif[0] = r;
	_dif[1] = g;
	_dif[2] = b;
	_dif[3] = a;
}

void EPSG::LightSource::setSpecular( float r, float g, float b, float a )
{
	_spc[0] = r;
	_spc[1] = g;
	_spc[2] = b;
	_spc[3] = a;
}