#ifndef __PARTICLE_SYSTEM_CPP__
#define __PARTICLE_SYSTEM_CPP__

#ifdef __HOME__
#include "d:\job\include\TextureManager.h"
#include "d:\job\include\D3DVertexBuffer.h"
#include "d:\job\include\Array.h"
#include "d:\job\include\Vector.h"
#else
#include "include\TextureManager.h"
#include "include\D3DVertexBuffer.h"
#include "include\Array.h"
#include "include\Vector.h"
#endif

#define						EFF_GRAVITY				1
#define						EFF_AGING				2
float						CNST_GRAVITY	=		-0.0003;

#define						EMM_SPRAY				1

#define						FVF_D3DPARTICLE_VERTEX	D3DFVF_XYZB3 | D3DFVF_DIFFUSE | D3DFVF_NORMAL | D3DFVF_TEX1 

class		cD3DParticleVertex:public cVector3{
public:
	float				c1;
	float				c2;
	float				c3;

	cVector3			Norm;

	DWORD				Color;

	float				u1;
	float				v1;

	cD3DParticleVertex( void ){
		Color = 0xffffffff;
	}
	cD3DParticleVertex( float _x , float _y , float _z , float _u1 , float _v1 ):cVector3( _x , _y , _z ){
		u1 = _u1;
		v1 = _v1;
		Norm = cVector3( 0 , 0 , -1 );
		Color = 0xffffff;
		c1 = c2 = c3 = 0;
	}
};

class		cEmitter{
public:
	DWORD				EMITTER_TYPE;
	//position
	float				fOP1;
	//size
	cVector3			OP1;

	//velosity deviation
	float				fOP2;
	//velosity
	cVector3			OP2;

	//life time
	float				fOP3;
	//life time deviation
	float				fOP4;
	cEmitter( void ){EMITTER_TYPE = EMM_SPRAY;OP1 = NULL;OP2=cVector3(0,1,0);}
	void				Create( DWORD , cVector3 );

	cD3DParticleVertex	GetVertex( int , cD3DParticleVertex& );
	cVector3			GetVelosity( void );
	float				GetLifeTime( void );
};

cEmitter					stdEmitter;

class		cParticleSystem{
public:
	int										Shader;

	int										TextureCursor;

	cArray<float>							*LifeTime;
	cArray<cVector3>						*VelosityArray;
	cD3DVertexBuffer<cD3DParticleVertex>	*VertexBuffer;
	cEmitter								Emitter;

	int										_EFFECTS;

	void									Create( cVector3 , cVector3 , float , int , float , int );
	void									CreateMathPart( float , float );
	void									CreateVisualPart( char * );
	void									Release( void );
	void									Render( LPDIRECT3DDEVICE8 );
	void									RunSystem( float );
	cParticleSystem( void ){
		Shader = FVF_D3DPARTICLE_VERTEX;
		VelosityArray = NULL;
		LifeTime = NULL;
		VertexBuffer = NULL;
		Emitter = stdEmitter;
	}
	~cParticleSystem(){}
};

#endif