#ifndef _CPARTICLESYS_H_
#define _CPARTICLESYS_H_
/*
#include "../../SDK/WCode/App/EngineH.h"
#include "../../SDK/WCode/Math/Math.h"
#include "../../SDK/WCode/GLDef.h"
*/

#include "../App/EngineH.h"
#include "../Math/Math.h"
#include "../GLDef.h"


class CParticle
{
public :
	bool show;
	CVector3 pos, smer;
	float width;
	float height;
	float live;
	float max_live;
	float speed;
};

class CParticleEmitor
{
private :
	bool					_blend, _alpha;
	GLenum					_blendSFactor, _blendDFactor;
	bool					_stop;
	std::vector<CParticle>	_vParticle;
	CVector3				_emPos;
	CVector3				_startPos;
	CVector3				_gravity;
	CVector3				_smer;
	float					_speed;
	float					_live;
	TRGBf					_startColor, _endColor;
	float					_rozptil;  // uhel 0-360
	float					_pocUhel;
	uint					_textureID;
	TVel					_startVel, _startEnd;

	void _RenderParticle(CParticle &p, float uhelx, float uhely );
	void _UpdateParticle( CParticle &p, float time);
	void _NewParticle(CParticle &p);
	
public :
	CParticleEmitor();
public :
	void SetBlendGreen()
	{
		_blendSFactor = GL_ONE_MINUS_SRC_COLOR;
		_blendDFactor = GL_ONE_MINUS_SRC_COLOR;
	}
	void SetBlendBlack()
	{
		_blendSFactor = GL_ONE_MINUS_SRC_ALPHA;
		_blendDFactor = GL_ONE_MINUS_SRC_COLOR;
	}
	void SetBlend(GLenum sf, GLenum df)
	{
		_blendSFactor = sf;
		_blendDFactor = df;
	}
	bool IsShowParticle()
	{
		// Jsou videt castice?? True - jsou, False - nejsou videt
		std::vector<CParticle>::iterator iter = _vParticle.begin();
		for(; iter != _vParticle.end(); iter++)
		{
			if( iter->show == 1 ) { return TRUE; }
		}
		return FALSE;
	}
	inline void SetEmitorPos(CVector3 pos) { _emPos = pos; }
	inline void SetStartVel(TVel v) {_startVel = v;}
	inline void SetStartVel(float vel) { _startVel = W_GetVel( vel, vel ); }
	inline void SetTexture( uint texture )  { _textureID = texture; }
	inline void SetColor(TRGBf start, TRGBf end)
	{
		_startColor = start;
		_endColor = end;
	}
	void SetAtribut(CVector3 pos, float pocUhel, float rozptil, float speed, float live)
	{
		_startPos = pos;
		//_smer = smer;
		_pocUhel = pocUhel;
		_rozptil = rozptil;
		_speed = speed; 
		_live = live;
	}
	void Create( uint quantity );
	
	void Render( float uhelx, float uhely );
	void Update( float timeFrame );
	void Stop() { _stop = 1; }
	void Play() { _stop = 0; }
	CVector3 GetStartPos() const { return _startPos; }
	void DeleteParticle();
	void SetBlend(bool b) { _blend = b; }
	void SetAlpha(bool b) { _alpha = b; }
};

struct TParticleKruh
{
	bool show;
	CVector3 pos;
	float vel;
	float speed_vel;
	float live;
	float max_live;
	float speed;
	uint texture_id;
};

class CPartKruh
{
private:
	std::list<TParticleKruh>	_vParticle;
public:
	CPartKruh();
public:
	void Add( uint texID, CVector3 pos, float vel, float speed_vel, float speed  );
	void Draw();
	void Move( float time );
};

/*
class CPartFlare
{
private:
	std::list<TParticleKruh>	_vParticle;
public:
public:
};*/

#endif //_CPARTICLESYS_H_