Game Development Reference
In-Depth Information
// 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
}
The update method updates the position of each particle and kills par-
ticles that have aged past their specified lifetime. Notice that the
system doesn't remove dead particles. We do this because when we
want to create a new firework, we can simply reset an existing dead
firework system. This saves us from having to create and destroy parti-
cles frequently.
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;
}
}
}
The Firework system uses different blend factors when rendering. Fur-
ther, it disables writes to the depth buffer. We can easily change the
blend factors and depth write from the default by overriding the
PSystem::preRender and PSystem::postRender methods. The
overridden implementations:
void Firework::preRender()
{
PSystem::preRender();
_device->SetRenderState(D3DRS_SRCBLEND, D3DBLEND_ONE);
_device->SetRenderState(D3DRS_DESTBLEND, D3DBLEND_ONE);
Search WWH ::




Custom Search