/** SGX

The   sss    gggg x   x   
     s      g      x x    Engine
      sss   g  gg   x
         s  g   g  x x          Copyright 1995-2008.
     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: include/domains/graphics/primitives/polygon.hpp

*/

#ifndef SGX_DOMAIN_GRAPHICS_PRIMITIVES_POLYGON_HPP
#define SGX_DOMAIN_GRAPHICS_PRIMITIVES_POLYGON_HPP	1

// TODO: RENAME TO sgxPolygonVertex or similar
// TODO: create as template with PolyVtx type because u,v,color are all hacks
class sgxPolyVtx
{
public:
	sgxVector3		vect;
	sgxVector3		norm;
	tREAL32			u, v;
	sgxColorRGBA	color;

	sgxPolyVtx()	{ vect=sgxVector3::Null; u=v=0; color=sgxColorRGBA::White; }
	sgxPolyVtx(const sgxVector3 &pvtx) { vect=pvtx; u=v=0;  color=sgxColorRGBA::White; }
	sgxPolyVtx(const sgxVector3 &pvtx, const tREAL32 &pu, const tREAL32 &pv) { vect=pvtx; u=pu; v=pv;  color=sgxColorRGBA::White; }
};

class sgxPrimitivePolygon : public sgxPrimitiveBase
{
public:
	sgxVector<sgxPolyVtx>	vtx;

	sgxPrimitivePolygon() {  }
	sgxPrimitivePolygon(const sgxVector3 &pv1, const sgxVector3 &pv2, const sgxVector3 &pv3) { vtx.push_back(sgxPolyVtx(pv1)); vtx.push_back(sgxPolyVtx(pv2)); vtx.push_back(sgxPolyVtx(pv3)); }
	sgxPrimitivePolygon(const sgxPolyVtx &pv1, const sgxPolyVtx &pv2, const sgxPolyVtx &pv3) { vtx.push_back(pv1); vtx.push_back(pv2); vtx.push_back(pv3); }
	~sgxPrimitivePolygon() { }

	virtual void	getBoundingSphere(sgxVector3 &pos, tREAL32 &radius) const;
	virtual void	getBoundingBox(sgxVector3 &minpos, sgxVector3 &maxpos) const;

	void	UnityPlaneXY(const tREAL32 &z)
	{
		vtx.clear();
		vtx.push_back(sgxPolyVtx(sgxVector3(0,0,z), 0, 0));
		vtx.push_back(sgxPolyVtx(sgxVector3(1,0,z), 1, 0));
		vtx.push_back(sgxPolyVtx(sgxVector3(1,1,z), 1, 1));
		vtx.push_back(sgxPolyVtx(sgxVector3(0,1,z), 0, 1));
	}
};

#endif /* SGX_DOMAIN_GRAPHICS_PRIMITIVES_POLYGON_HPP */
