亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關于我們
? 蟲蟲下載站

?? psystem.cpp

?? Direct 9.0 游戲編程 包括PDF書籍和源代碼
?? CPP
字號:
//////////////////////////////////////////////////////////////////////////////////////////////////
// 
// File: pSystem.cpp
// 
// Author: Frank Luna (C) All Rights Reserved
//
// System: AMD Athlon 1800+ XP, 512 DDR, Geforce 3, Windows XP, MSVC++ 7.0 
//
// Desc: Represents a geneal particle system.
//          
//////////////////////////////////////////////////////////////////////////////////////////////////

#include <cstdlib>
#include "pSystem.h"

using namespace psys;

const DWORD Particle::FVF = D3DFVF_XYZ | D3DFVF_DIFFUSE;

PSystem::PSystem()
{
	_device = 0;
	_vb     = 0;
	_tex    = 0;
}

PSystem::~PSystem()
{
	d3d::Release<IDirect3DVertexBuffer9*>(_vb);
	d3d::Release<IDirect3DTexture9*>(_tex);
}

bool PSystem::init(IDirect3DDevice9* device, char* texFileName)
{
	// vertex buffer's size does not equal the number of particles in our system.  We
	// use the vertex buffer to draw a portion of our particles at a time.  The arbitrary
	// size we choose for the vertex buffer is specified by the _vbSize variable.

	_device = device; // save a ptr to the device

	HRESULT hr = 0;

	hr = device->CreateVertexBuffer(
		_vbSize * sizeof(Particle),
		D3DUSAGE_DYNAMIC | D3DUSAGE_POINTS | D3DUSAGE_WRITEONLY,
		Particle::FVF,
		D3DPOOL_DEFAULT, // D3DPOOL_MANAGED can't be used with D3DUSAGE_DYNAMIC 
		&_vb,
		0);
	
	if(FAILED(hr))
	{
		::MessageBox(0, "CreateVertexBuffer() - FAILED", "PSystem", 0);
		return false;
	}

	hr = D3DXCreateTextureFromFile(
		device,
		texFileName,
		&_tex);

	if(FAILED(hr))
	{
		::MessageBox(0, "D3DXCreateTextureFromFile() - FAILED", "PSystem", 0);
		return false;
	}

	return true;
}

void PSystem::reset()
{
	std::list<Attribute>::iterator i;
	for(i = _particles.begin(); i != _particles.end(); i++)
	{
		resetParticle( &(*i) );
	}
}

void PSystem::addParticle()
{
	Attribute attribute;

	resetParticle(&attribute);

	_particles.push_back(attribute);
}

void PSystem::preRender()
{
	_device->SetRenderState(D3DRS_LIGHTING, false);
	_device->SetRenderState(D3DRS_POINTSPRITEENABLE, true);
	_device->SetRenderState(D3DRS_POINTSCALEENABLE, true); 
	_device->SetRenderState(D3DRS_POINTSIZE, d3d::FtoDw(_size));
	_device->SetRenderState(D3DRS_POINTSIZE_MIN, d3d::FtoDw(0.0f));

	// control the size of the particle relative to distance
	_device->SetRenderState(D3DRS_POINTSCALE_A, d3d::FtoDw(0.0f));
	_device->SetRenderState(D3DRS_POINTSCALE_B, d3d::FtoDw(0.0f));
	_device->SetRenderState(D3DRS_POINTSCALE_C, d3d::FtoDw(1.0f));
		
	// use alpha from texture
	_device->SetTextureStageState(0, D3DTSS_ALPHAARG1, D3DTA_TEXTURE);
	_device->SetTextureStageState(0, D3DTSS_ALPHAOP, D3DTOP_SELECTARG1);

	_device->SetRenderState(D3DRS_ALPHABLENDENABLE, true);
	_device->SetRenderState(D3DRS_SRCBLEND, D3DBLEND_SRCALPHA);
    _device->SetRenderState(D3DRS_DESTBLEND, D3DBLEND_INVSRCALPHA);
}

void PSystem::postRender()
{
	_device->SetRenderState(D3DRS_LIGHTING,          true);
	_device->SetRenderState(D3DRS_POINTSPRITEENABLE, false);
	_device->SetRenderState(D3DRS_POINTSCALEENABLE,  false);
	_device->SetRenderState(D3DRS_ALPHABLENDENABLE,  false);
}

void PSystem::render()
{
	//
	// Remarks:  The render method works by filling a section of the vertex buffer with data,
	//           then we render that section.  While that section is rendering we lock a new
	//           section and begin to fill that section.  Once that sections filled we render it.
	//           This process continues until all the particles have been drawn.  The benifit
	//           of this method is that we keep the video card and the CPU busy.  

	if( !_particles.empty() )
	{
		//
		// set render states
		//

		preRender();
		
		_device->SetTexture(0, _tex);
		_device->SetFVF(Particle::FVF);
		_device->SetStreamSource(0, _vb, 0, sizeof(Particle));

		//
		// render batches one by one
		//

		// start at beginning if we're at the end of the vb
		if(_vbOffset >= _vbSize)
			_vbOffset = 0;

		Particle* v = 0;

		_vb->Lock(
			_vbOffset    * sizeof( Particle ),
			_vbBatchSize * sizeof( Particle ),
			(void**)&v,
			_vbOffset ? D3DLOCK_NOOVERWRITE : D3DLOCK_DISCARD);

		DWORD numParticlesInBatch = 0;

		//
		// Until all particles have been rendered.
		//
		std::list<Attribute>::iterator i;
		for(i = _particles.begin(); i != _particles.end(); i++)
		{
			if( i->_isAlive )
			{
				//
				// Copy a batch of the living particles to the
				// next vertex buffer segment
				//
				v->_position = i->_position;
				v->_color    = (D3DCOLOR)i->_color;
				v++; // next element;

				numParticlesInBatch++; //increase batch counter

				// if this batch full?
				if(numParticlesInBatch == _vbBatchSize) 
				{
					//
					// Draw the last batch of particles that was
					// copied to the vertex buffer. 
					//
					_vb->Unlock();

					_device->DrawPrimitive(
						D3DPT_POINTLIST,
						_vbOffset,
						_vbBatchSize);

					//
					// While that batch is drawing, start filling the
					// next batch with particles.
					//

					// move the offset to the start of the next batch
					_vbOffset += _vbBatchSize; 

					// don't offset into memory thats outside the vb's range.
					// If we're at the end, start at the beginning.
					if(_vbOffset >= _vbSize) 
						_vbOffset = 0;       

					_vb->Lock(
						_vbOffset    * sizeof( Particle ),
						_vbBatchSize * sizeof( Particle ),
						(void**)&v,
						_vbOffset ? D3DLOCK_NOOVERWRITE : D3DLOCK_DISCARD);

					numParticlesInBatch = 0; // reset for new batch
				}	
			}
		}

		_vb->Unlock();

		// its possible that the LAST batch being filled never 
		// got rendered because the condition 
		// (numParticlesInBatch == _vbBatchSize) would not have
		// been satisfied.  We draw the last partially filled batch now.
		
		if( numParticlesInBatch )
		{
			_device->DrawPrimitive(
				D3DPT_POINTLIST,
				_vbOffset,
				numParticlesInBatch);
		}

		// next block
		_vbOffset += _vbBatchSize; 

		//
		// reset render states
		//

		postRender();
	}
}

bool PSystem::isEmpty()
{
	return _particles.empty();
}

bool PSystem::isDead()
{
	std::list<Attribute>::iterator i;
	for(i = _particles.begin(); i != _particles.end(); i++)
	{
		// is there at least one living particle?  If yes,
		// the system is not dead.
		if( i->_isAlive )
			return false;
	}
	// no living particles found, the system must be dead.
	return true;
}

void PSystem::removeDeadParticles()
{
	std::list<Attribute>::iterator i;

	i = _particles.begin();

	while( i != _particles.end() )
	{
		if( i->_isAlive == false )
		{
			// erase returns the next iterator, so no need to
		    // incrememnt to the next one ourselves.
			i = _particles.erase(i); 
		}
		else
		{
			i++; // next in list
		}
	}
}

//*****************************************************************************
// Snow System
//***************

Snow::Snow(d3d::BoundingBox* boundingBox, int numParticles)
{
	_boundingBox   = *boundingBox;
	_size          = 0.25f;
	_vbSize        = 2048;
	_vbOffset      = 0; 
	_vbBatchSize   = 512; 
	
	for(int i = 0; i < numParticles; i++)
		addParticle();
}

void Snow::resetParticle(Attribute* attribute)
{
	attribute->_isAlive  = true;

	// get random x, z coordinate for the position of the snow flake.
	d3d::GetRandomVector(
		&attribute->_position,
		&_boundingBox._min,
		&_boundingBox._max);

	// no randomness for height (y-coordinate).  Snow flake
	// always starts at the top of bounding box.
	attribute->_position.y = _boundingBox._max.y; 

	// snow flakes fall downwards and slightly to the left
	attribute->_velocity.x = d3d::GetRandomFloat(0.0f, 1.0f) * -3.0f;
	attribute->_velocity.y = d3d::GetRandomFloat(0.0f, 1.0f) * -10.0f;
	attribute->_velocity.z = 0.0f;

	// white snow flake
	attribute->_color = d3d::WHITE;
}

void Snow::update(float timeDelta)
{
	std::list<Attribute>::iterator i;
	for(i = _particles.begin(); i != _particles.end(); i++)
	{
		i->_position += i->_velocity * timeDelta;

		// is the point outside bounds?
		if( _boundingBox.isPointInside( i->_position ) == false ) 
		{
			// nope so kill it, but we want to recycle dead 
			// particles, so respawn it instead.
			resetParticle( &(*i) );
		}
	}
}

//*****************************************************************************
// Explosion System
//********************

Firework::Firework(D3DXVECTOR3* origin, int numParticles)
{
	_origin        = *origin;
	_size          = 0.9f;
	_vbSize        = 2048;
	_vbOffset      = 0;   
	_vbBatchSize   = 512; 

	for(int i = 0; i < numParticles; i++)
		addParticle();
}

void Firework::resetParticle(Attribute* attribute)
{
	attribute->_isAlive  = true;
	attribute->_position = _origin;

	D3DXVECTOR3 min = D3DXVECTOR3(-1.0f, -1.0f, -1.0f);
	D3DXVECTOR3 max = D3DXVECTOR3( 1.0f,  1.0f,  1.0f);

	d3d::GetRandomVector(
		&attribute->_velocity,
		&min,
		&max);

	// normalize to make spherical
	D3DXVec3Normalize(
		&attribute->_velocity,
		&attribute->_velocity);

	attribute->_velocity *= 100.0f;

	attribute->_color = D3DXCOLOR(
		d3d::GetRandomFloat(0.0f, 1.0f),
		d3d::GetRandomFloat(0.0f, 1.0f),
		d3d::GetRandomFloat(0.0f, 1.0f),
		1.0f);

	attribute->_age      = 0.0f;
	attribute->_lifeTime = 2.0f; // lives for 2 seconds
}

void Firework::update(float timeDelta)
{
	std::list<Attribute>::iterator i;

	for(i = _particles.begin(); i != _particles.end(); i++)
	{
		// only update living particles
		if( i->_isAlive )
		{
			i->_position += i->_velocity * timeDelta;

			i->_age += timeDelta;

			if(i->_age > i->_lifeTime) // kill 
				i->_isAlive = false;
		}
	}
}

void Firework::preRender()
{
	PSystem::preRender();

	_device->SetRenderState(D3DRS_SRCBLEND, D3DBLEND_ONE);
    _device->SetRenderState(D3DRS_DESTBLEND, D3DBLEND_ONE);

	// read, but don't write particles to z-buffer
	_device->SetRenderState(D3DRS_ZWRITEENABLE, false);
}

void Firework::postRender()
{
	PSystem::postRender();

	_device->SetRenderState(D3DRS_ZWRITEENABLE, true);
}

//*****************************************************************************
// Laser System
//****************

ParticleGun::ParticleGun(Camera* camera)
{
	_camera          = camera;
	_size            = 0.8f;
	_vbSize          = 2048;
	_vbOffset        = 0;  
	_vbBatchSize     = 512; 
}

void ParticleGun::resetParticle(Attribute* attribute)
{
	attribute->_isAlive  = true;

	D3DXVECTOR3 cameraPos;
	_camera->getPosition(&cameraPos);

	D3DXVECTOR3 cameraDir;
	_camera->getLook(&cameraDir);

	// change to camera position
	attribute->_position = cameraPos;
	attribute->_position.y -= 1.0f; // slightly below camera
	                         // so its like we're carrying a gun

	// travels in the direction the camera is looking
	attribute->_velocity = cameraDir * 100.0f;

	// green
	attribute->_color = D3DXCOLOR(0.0f, 1.0f, 0.0f, 1.0f);

	attribute->_age      = 0.0f; 
	attribute->_lifeTime = 1.0f; // lives for 1 seconds
}

void ParticleGun::update(float timeDelta)
{
	std::list<Attribute>::iterator i;

	for(i = _particles.begin(); i != _particles.end(); i++)
	{
		i->_position += i->_velocity * timeDelta;

		i->_age += timeDelta;

		if(i->_age > i->_lifeTime) // kill 
			i->_isAlive = false;
	}
	removeDeadParticles();
}

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
欧美高清在线精品一区| 欧美一级片在线看| 在线观看国产一区二区| 欧美性受xxxx| 欧美一级欧美三级在线观看| 久久精品欧美日韩| 一区二区三区不卡视频| 一区二区三区在线不卡| 激情偷乱视频一区二区三区| 99精品黄色片免费大全| 欧美一级日韩不卡播放免费| 亚洲欧美另类小说视频| 五月婷婷综合激情| 国产亚洲综合在线| 天天av天天翘天天综合网| 日本道色综合久久| 国产亚洲精品免费| 日韩伦理av电影| 亚洲国产视频在线| 国产一区二区毛片| 99精品在线免费| 欧美日韩综合在线免费观看| 88在线观看91蜜桃国自产| 日韩视频免费观看高清在线视频| 国产午夜精品一区二区| 成人网页在线观看| 欧美精品一区二区三区四区| 五月天激情综合网| 欧美日韩久久一区| 亚洲综合男人的天堂| 99国产麻豆精品| 亚洲精品第1页| 99re这里都是精品| 欧美国产1区2区| 成人动漫在线一区| 中文字幕不卡的av| 成人av在线播放网站| 久久精品夜色噜噜亚洲a∨| 激情av综合网| 国产午夜精品福利| 日韩欧美精品三级| 欧美调教femdomvk| 国产一区二区中文字幕| 五月开心婷婷久久| 亚洲精品中文在线影院| 7777女厕盗摄久久久| 国产一区二区中文字幕| 亚洲天堂av一区| 精品国产凹凸成av人网站| 国产一区二区三区四区五区入口 | 色伊人久久综合中文字幕| 亚洲国产aⅴ成人精品无吗| 精品久久久久一区二区国产| 久久91精品久久久久久秒播| 欧美成人一区二区三区片免费| 国产福利一区二区三区视频| 一区二区三区中文字幕电影| 久久香蕉国产线看观看99| 99国产精品久久久久久久久久久| 亚洲一区二区欧美激情| 亚洲精品一区二区三区在线观看 | 精品嫩草影院久久| 99re6这里只有精品视频在线观看| 夜夜嗨av一区二区三区中文字幕 | 中文在线资源观看网站视频免费不卡 | 精品卡一卡二卡三卡四在线| 日本韩国欧美一区| 91国偷自产一区二区三区观看 | 色香色香欲天天天影视综合网| 狠狠网亚洲精品| 美女一区二区视频| 日本欧美一区二区| 亚洲一区二区三区四区五区中文| 国产欧美日韩精品在线| 日韩三级视频在线观看| 欧美一区二区在线观看| 91精品中文字幕一区二区三区| 欧美在线播放高清精品| 欧美丝袜丝交足nylons图片| 国产成人精品综合在线观看| 欧美aaaaa成人免费观看视频| 日韩久久一区二区| 亚洲国产精品精华液ab| 精品国精品自拍自在线| 日韩女同互慰一区二区| 欧美一区二区日韩| 日韩欧美美女一区二区三区| 欧美一级一级性生活免费录像| 日韩欧美一区在线| 精品免费国产二区三区| 日韩一区二区三区免费看| 欧美成人精品3d动漫h| 国产人成亚洲第一网站在线播放| 欧美激情一区在线| 亚洲免费观看高清完整版在线| 日韩精品久久久久久| 国产专区综合网| 色婷婷国产精品久久包臀| 欧美成人欧美edvon| 亚洲欧洲三级电影| 久热成人在线视频| 91极品美女在线| 欧美成人猛片aaaaaaa| 一区二区三区四区在线免费观看| 久久国产精品色婷婷| 91成人在线精品| 国产精品理论在线观看| 精品一区二区三区蜜桃| 欧美在线免费播放| 久久精品视频免费| 久久国产精品99久久人人澡| 色呦呦网站一区| √…a在线天堂一区| 国产美女视频一区| 欧美疯狂做受xxxx富婆| 久久久久久久综合色一本| 午夜精品在线视频一区| 日本韩国一区二区三区视频| 亚洲欧美综合网| 成人久久久精品乱码一区二区三区 | 在线日韩av片| 国产精品五月天| 成人av免费网站| 欧美激情一区二区三区不卡| 国内外成人在线| 久久久久久久久久久电影| 老汉av免费一区二区三区| 精品久久久久久久久久久久包黑料 | 欧美一区二区大片| 国产一区二区三区蝌蚪| 国产视频911| 色呦呦一区二区三区| 国产91丝袜在线播放0| 日本一区二区三级电影在线观看 | 日韩电影在线看| 久久新电视剧免费观看| 97精品视频在线观看自产线路二| 一区二区三区产品免费精品久久75| 欧美伊人久久久久久久久影院| 婷婷国产在线综合| 久久精品亚洲乱码伦伦中文| 91网页版在线| 日本亚洲欧美天堂免费| 国产精品久久久久婷婷二区次| 成人99免费视频| 日本aⅴ亚洲精品中文乱码| 久久久久久久久免费| 日本韩国欧美一区| 精一区二区三区| 亚洲一区成人在线| 久久只精品国产| 欧美日韩一级黄| 不卡一区二区三区四区| 成人精品视频.| 狠狠v欧美v日韩v亚洲ⅴ| 一区二区三区四区在线| 国产亚洲va综合人人澡精品| 911国产精品| 欧美日韩一区二区在线视频| 波多野结衣中文一区| 久久99深爱久久99精品| 天天综合色天天| 亚洲国产视频在线| 一个色在线综合| 一级中文字幕一区二区| 亚洲日本va在线观看| 国产精品久久久久久久久图文区| 久久这里只有精品6| 日韩欧美一级精品久久| 欧美一级国产精品| 欧美日本视频在线| 欧美日韩一区高清| 9191成人精品久久| 日韩久久免费av| 26uuu久久天堂性欧美| www成人在线观看| 欧美高清在线一区二区| 国产精品国产三级国产专播品爱网 | 麻豆91免费看| 高清国产一区二区| 99精品欧美一区二区蜜桃免费 | 视频一区国产视频| 成人综合婷婷国产精品久久 | 亚洲一区国产视频| 九色porny丨国产精品| 成人手机电影网| 欧美乱妇15p| 久久亚洲综合色一区二区三区| 国产精品网站导航| 亚洲第一av色| 国产成人日日夜夜| 欧美性猛交一区二区三区精品| 欧美一区二区精美| 亚洲人妖av一区二区| 老司机精品视频一区二区三区| 91免费看视频| 国产精品色噜噜| 国产麻豆精品在线| 51精品国自产在线| 一区二区三区在线免费|