www.pudn.com > 3D_Tank.rar > Particle.h


#ifndef __PARTICLE_H__ 
#define __PARTICLE_H__ 
 
#include  
#include  
#include "ComPtr.h" 
#include "Arithmetic.h" 
#include "Error.h" 
 
struct Particle			//顶点缓冲中需要的顶点格式 
{ 
    D3DXVECTOR3 m_vPosition;		//粒子位置,世界坐标 
	D3DCOLOR	m_Color;			//粒子的颜色 
	 
	static const DWORD FVF = D3DFVF_XYZ | D3DFVF_DIFFUSE;  //顶点标志 
}; 
 
struct Attribute		//游戏逻辑中需要的顶点信息 
{ 
	D3DXVECTOR3 m_vPosition;	//粒子位置,世界坐标 
    D3DXVECTOR3 m_vVelocity;	//粒子的速度 
    D3DCOLOR	m_Color;		//粒子的颜色 
	BOOL		m_bIsAlive;		//粒子是否还存在 
}; 
 
class CParticleSystem 
{	 
public: 
	CParticleSystem(); 
	~CParticleSystem(); 
	BOOL Init(const CComPtr &device, LPCTSTR pTextureFile);	 
													//初始化纹理和创建顶点缓冲 
	VOID Reset();	 
	VOID ResetParticle(Attribute *attribute); 
	VOID AddPartile(); 
	VOID Update(float fTimeDelta); 
	VOID RemoveDeadParticle(); 
 
	VOID PrepareRenderState(); 
	VOID Render(); 
	VOID ResetRenderState(); 
     
	VOID GetBoundingBox(D3DXVECTOR3 *min, D3DXVECTOR3 *max); 
 
	VOID SetOrigin(const D3DXVECTOR3 &origin); 
	VOID SetVelocity(const D3DXVECTOR3 &velocity); 
	VOID SetInitColor(const D3DCOLOR &color); 
	VOID SetBoundingBox(const D3DXVECTOR3 &min, const D3DXVECTOR3 &max); 
	VOID SetBoundingBox(const Box &box); 
 
	BOOL IsEmpty(); 
	BOOL IsDead(); 
 
private: 
	CComPtr		m_pDevice;		//D3D接口 
	CComPtr		m_pTexture;		//纹理接口 
	CComPtr	m_pVB;			//顶点缓冲接口 
	D3DXVECTOR3						m_vOrigin;		//粒子生成点 
	D3DXVECTOR3						m_vInitVelocity;//粒子初始速度 
	float							m_fSize;		//粒子的大小 
	D3DCOLOR						m_InitColor;	//新生成粒子的颜色 
	Box								m_BoundingBox;	//包裹盒,粒子的活动范围 
	std::list			m_listParticle;	//链表,用以存放粒子的属性 
 
	DWORD	m_dwVBSize;				//顶点缓冲的大小	 
	DWORD	m_dwVBOffset;			//顶点缓冲的偏移量 
	DWORD	m_dwBatchSize;			//处理时的批大小  
 
	//逻辑相关 
	float							m_fFireColdTime; 
}; 
 
#endif			//Particle