⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 testparticlesystem.cpp

📁 这是一款游戏中的粒子系统
💻 CPP
字号:
// TestParticleSystem.cpp : 实现文件
//

#include "stdafx.h"
#include "PerfectParticle.h"
#include "TestParticleSystem.h"
#include ".\testparticlesystem.h"


// CTestParticleSystem 对话框

IMPLEMENT_DYNAMIC(CTestParticleSystem, CDialog)
CTestParticleSystem::CTestParticleSystem(CWnd* pParent /*=NULL*/)
: CDialog(CTestParticleSystem::IDD, pParent)
{
}

CTestParticleSystem::~CTestParticleSystem()
{
}

void CTestParticleSystem::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
}


BEGIN_MESSAGE_MAP(CTestParticleSystem, CDialog)
	ON_WM_PAINT()
	ON_WM_TIMER()
END_MESSAGE_MAP()


// CTestParticleSystem 消息处理程序

INT_PTR CTestParticleSystem::DoModal(char *filename)
{
	m_particleFile=new char[100];
	strcpy(m_particleFile,filename);
	return CDialog::DoModal();
}

BOOL CTestParticleSystem::OnInitDialog()
{
	CDialog::OnInitDialog();
	HICON icon=::LoadIcon(theApp.m_hInstance,MAKEINTRESOURCE(IDR_MAINFRAME));
	SetIcon(icon,TRUE);
	SetIcon(icon,FALSE);
	m_canRender=true;
	m_device=new CInitEnviroment(m_hWnd,800,600,true);
	m_camera=new CCamera(CCamera::Land);
	D3DXVECTOR3 *pos=m_camera->GetEyePos();
	pos->z =-50.0f; 
	m_camera->SetEyePos(pos);

	m_sys=new CParticleSystem(m_device->p_D3dDevice);
	m_sys->InportConfigFile(m_particleFile);
	SetTimer(1001,10,NULL);
	return TRUE; 
}

void CTestParticleSystem::OnPaint()
{
	Render();
	CPaintDC dc(this);
}

void CTestParticleSystem::OnTimer(UINT nIDEvent)
{
	Render();
	CDialog::OnTimer(nIDEvent);
}

void CTestParticleSystem::Render(){
	if(m_canRender==false)
		return;
	m_canRender=false;
	////////////////////////////////////
	//设置渲染区域
	GetClientRect(&m_renderRect);
	static DWORD currenttime=0;
	static DWORD lasttime=0;
	currenttime = ::timeGetTime();
	float fCurrentFrameTime = ((float)( currenttime - lasttime )) * 0.001f;
	lasttime = currenttime;

	m_device->p_D3dDevice->BeginScene();
	m_device->p_D3dDevice->Clear(0,NULL,D3DCLEAR_TARGET|D3DCLEAR_ZBUFFER ,
		D3DCOLOR_XRGB(0,0,0) ,1.0f,0);
	m_camera->Set3DCamera(m_device->p_D3dDevice,
		(float)(m_renderRect.right-m_renderRect.left),
		(float)(m_renderRect.bottom-m_renderRect.top),1,1000,1000);
	m_sys->Update( fCurrentFrameTime );
	m_sys->Render(m_camera);
	m_device->p_D3dDevice->EndScene();
	m_device->p_D3dDevice->Present(NULL,&m_renderRect,NULL,NULL) ;
	m_canRender=true;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -