/** SGX

The   sss    gggg x   x   
     s      g      x x    Engine
      sss   g  gg   x
         s  g   g  x x          Copyright 1995-2009.
     ssss    gggg x   x         Steven Goodwin. All Rights Reserved.
    
This version has been released under the GNU Public License v2.0.

Please see the license files for details.

File: sgx/include/sgx/graphics/sgxprimitives.hpp

*/

#ifndef SGX_GRAPHICS_PRIMITIVES_HPP
#define SGX_GRAPHICS_PRIMITIVES_HPP		1

class sgxGfxPolygon : public sgxPrimitivePolygon
{
public:
	const CSGXTexture		*pTexture;
	CPlatformData			*m_pPlatformData;

// TODO: CALL BASE CLASS
	sgxGfxPolygon() : sgxPrimitivePolygon() { m_pPlatformData = NULL; pTexture = NULL; }
	sgxGfxPolygon(const sgxVector3 &pv1, const sgxVector3 &pv2, const sgxVector3 &pv3) :sgxPrimitivePolygon(pv1,pv2,pv3) { pTexture = NULL; m_pPlatformData = NULL; }
	sgxGfxPolygon(const sgxPolyVtx &pv1, const sgxPolyVtx &pv2, const sgxPolyVtx &pv3) :sgxPrimitivePolygon(pv1,pv2,pv3) { pTexture = NULL; m_pPlatformData = NULL; }
	~sgxGfxPolygon() { delete m_pPlatformData; /* We do not take ownership of the pTexture ptr */ }

	void	draw(const sgxMatrix43 &transform) const;

};

class sgxGfxSphere : public sgxPrimitiveSphere
{
public:
	sgxGfxSphere() : sgxPrimitiveSphere(1) {}
	sgxGfxSphere(tREAL32 r) : sgxPrimitiveSphere(r) {}

};

class CStaticMesh : public sgxPrimitiveBase
{
public:
	sgxVector<sgxGfxPolygon>	m_Polygons;
	CPlatformData			*m_pPlatformData;

	CStaticMesh();
	~CStaticMesh();
	void	Clear();
	void	draw(const sgxMatrix43 &transform) const;
	void	addPolygon(const sgxGfxPolygon &poly);
	void	addPolygon(const sgxVector3 &v1, const sgxVector3 &v2, const sgxVector3 &v3);
	void	addPolygon(const sgxPolyVtx &v1, const sgxPolyVtx &v2, const sgxPolyVtx &v3);
	void	addPolygon(const CSGXTexture &texture, const sgxVector3 &v1, const sgxVector3 &v2, const sgxVector3 &v3);
};

class sgxCuboidFace
{
public:
	const CSGXTexture	*pTexture;
	sgxUV				uv;
	sgxColorRGBA		color[4];
};

class sgxGfxCuboid : public sgxPrimitiveCuboid
{
public:
	sgxCuboidFace	face[6];

	void	setCuboidColor(const sgxColorRGB &col);
	void	setCuboidColor(const sgxColorRGBA &col);
	void	setCuboidAlpha(const tREAL32 &alpha);
	void	setCuboidTexture(const CSGXTexture *pTexture);
};

class sgxAnimationKeyframes
{
public:
	tUINT32	m_ID;
};

class CAnimatedMesh : public sgxPrimitiveBase
{
public:
	static CAnimatedMesh *		load(const sgxString &md2);
	
	CAnimatedMesh();
	virtual ~CAnimatedMesh();

	virtual void				update(const tREAL32 telaps);
	virtual void				draw(const sgxMatrix43 &transform) const;

	
	virtual void				startAnimation(const tUINT32 animIndex);
	virtual void				startTransitionAnimation(const tUINT32 animIndex);
	virtual void				setAnimationFrameRate(const tREAL32 rateFPS);
	virtual tBOOL				isAnimationPlaying();
	virtual tUINT32				getCurrentAnimation();
	virtual void				pauseAnimation();
	virtual void				resumeAnimation();

protected:
	tBOOL						m_bPlaying;
	tBOOL						m_bTransition;
	tUINT32						m_iTransitionAnim;
	sgxAnimationKeyframes *		m_pCurrentAnimation;
	tUINT32						m_iCurrentAnim;
	tREAL32						m_fFrameRate;

	sgxVector<sgxAnimationKeyframes *>		m_AnimationData;

//protected:
	CPlatformData *				m_pPlatformAnim;

};

#endif /* SGX_GRAPHICS_PRIMITIVES_HPP */
