#ifndef GLCOMPILESMOOTHVISITOR_H
#define GLCOMPILESMOOTHVISITOR_H

#include "GlCompileVisitor.h"


namespace nsSceneGraph {

class GlCompileSmoothVisitor : public GlCompileVisitor
{
	private:
		void calculateSmoothNormals(VertexArray *array);

	public:
		virtual ~GlCompileSmoothVisitor(void);

		virtual void visit(VertexArray *array);
};


typedef struct
{
	int triangle;
	int index;
} VertexTriangleTableEntry;


typedef struct
{
	bool operator() (const Vertex3F &first, const Vertex3F &second) const
	{
		/*
		 * MARK 0:
		 * We are using the magnitude of a vector for the less<T> functor
		 * of the multimap. The problem is, that the magnitude of a vector
		 * isn't really unique. So we can't exactly distinguish between
		 * vectors with different orientations and different directions. For
		 * example the magnitudes of
		 *    Va = { -1, 4, 2 }
		 *    Vb = { 1, -4, 2 }
		 *    Vc = { 2, 1, -4 }
		 * are all the same. Oh!
		 *
		 * Solution:
		 * An entry of a multimap is always containing the key which was
		 * used for adding this entry. So we can check the returned entry
		 * if it is really associated with the given vertex. (See MARK 1
		 * comment in VertexArray.cpp.)
		 */
		return (first.x * first.x + first.y * first.y + first.z * first.z) <
			(second.x * second.x + second.y * second.y + second.z * second.z) ? true : false;
	}
} VertexTriangleTableCompare;


typedef std::multimap<Vertex3F, VertexTriangleTableEntry, VertexTriangleTableCompare> VertexTriangleTable;
typedef std::pair<Vertex3F, VertexTriangleTableEntry> VertexTriangleTablePair;


}

#endif

