/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* E.P. Scene Graph
* Developed by:
*       - Eduardo Ribeiro (eribeiro @ tecgraf . puc-rio . br)
*       - Peter Dam (peter @ tecgraf . puc-rio . br)
* File: Mat4.h
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */

#ifndef _EPSG_MAT4_
#define _EPSG_MAT4_

namespace EPSG
{
	template <typename T>
	class Mat4
	{
	public:
		/* [CONSTRUCTOR] */	Mat4();

		T&					operator[]( int index );
		
		T&					get( int i, int j );
		T*					getAsArray();
		void				setIdentity();
		Mat4<T>				invert();

	private:
		T					values[16];
		T					invalid;
	};
}

/* TEMPLATE METHODS */
template <typename T>
EPSG::Mat4<T>::Mat4()
{
	setIdentity();
}

template <typename T>
T& EPSG::Mat4<T>::operator[]( int index )
{
	if( index < 0 || index > 16 )
		return invalid;

	return values[index];
}

template <typename T>
T& EPSG::Mat4<T>::get( int i, int j )
{
	if( i*4 + j < 0 || i*4 + j > 16 )
		return invalid;

	return values[i*4+j];
}

template <typename T>
T* EPSG::Mat4<T>::getAsArray()
{
	return values;
}

template <typename T>
void EPSG::Mat4<T>::setIdentity()
{
	for( int i = 0; i < 16; i++ )
	{
		if( i % 4 == 0 )
			values[i] = (T)1;
		else
			values[i] = (T)0;
	}
}

template <typename T>
EPSG::Mat4<T> EPSG::Mat4<T>::invert()
{
	Mat4<T> ret;

	//TODO: Invert the matrix and save to ret

	return ret;
}

#endif //_EPSG_MAT4_