// this function updates the particle void Particles::run_particle(float seconds) { // handle lifespan life += seconds; if(life > lifespan) { reset_particle(); return; } velocity += acceleration * seconds; position += velocity * seconds; if(position.y < 11 && position.z < -14) reset_particle(); if(position.z > -14) { if(!((position.y > ((-11/45)*position.z)) && (position.y < ((-18/45)*position.z + 14)))) reset_particle(); } if((position.y <= min.y || position.y > max.y) || (position.x <= min.x || position.x > max.x)||(position.z <= min.z || position.z > max.z)){ reset_particle(); } return; }
Particles::Particles(D3DXVECTOR3 starting,D3DXVECTOR3 mi, D3DXVECTOR3 ma,D3DXVECTOR3 v, D3DXVECTOR3 a){ start = starting; min = mi; max = ma; startV = v; startA = a; reset_particle(); }
// this function updates the particle void Particles::run_particle(float seconds) { // handle lifespan life += seconds; if(life > lifespan) { reset_particle(); return; } velocity += acceleration * seconds; position += velocity * seconds; if((position.y <= min.y || position.y > max.y) || (position.x <= min.x || position.x > max.x)||(position.z <= min.z || position.z > max.z)){ reset_particle(); } return; }
void SNOW::update(float time) //对所有雪花进行更新,死了的雪花则将其复活 { list<ATTRIBUTE>::iterator i; for(i = _particles.begin();i != _particles.end();i++) { i->_position += i->_velocity * time; //速度乘以时间等于位移 if(_box.IsPointInside(i->_position) == false) reset_particle(&(*i)); } }
HRESULT ParticleSystem::initialise(LPDIRECT3DDEVICE9 device) { // Store the render target for later use... renderTarget_ = device; Particle p; reset_particle(p); particles_.resize(maxParticles_, p); // Create a vector of empty particles - make 'max_particles_' copies of particle 'p'. // Create a vertex buffer for the particles (each particule represented as an individual vertex). int buffer_size = maxParticles_ * sizeof(POINTVERTEX); // The data in the buffer doesn't exist at this point, but the memory space // is allocated and the pointer to it (g_pPointBuffer) also exists. if (FAILED(device -> CreateVertexBuffer(buffer_size, 0, D3DFVF_POINTVERTEX, D3DPOOL_DEFAULT, &points_, NULL))) { return E_FAIL; // Return if the vertex buffer culd not be created. } return S_OK; }