Game Development Reference
In-Depth Information
Observe that we use the D3DUSAGE_POINTS flag, which spec-
ifies that the vertex buffer will hold point sprites.
Take note that the vertex buffer size is predefined by _vbSize
and has nothing to do with the number of particles in the sys-
tem. That is, _vbSize will rarely equal the number of particles
in the system. This is because we render the particle system in
batches and not all at once. We explain the rendering process in
section 14.2.1.
We use the default memory pool instead of the usual managed
memory pool because dynamic vertex buffers cannot be placed
in the managed memory pool.
reset —This method resets the attributes of every particle in the
system:
void PSystem::reset()
{
std::list<Attribute>::iterator i;
for(i = _particles.begin(); i != _particles.end(); i++)
{
resetParticle( &(*i) );
}
}
resetParticle —This method resets the attributes of a particle.
How a particle's attributes should be reset is dependent upon the
specifics of a particular particle system. Therefore, we make this
method abstract to force the subclass to implement it.
addParticle —This method adds a particle to the system. It uses
the resetParticle method to initialize the particle before adding
it to the list:
void PSystem::addParticle()
{
Attribute attribute;
resetParticle(&attribute);
_particles.push_back(attribute);
}
update —This method updates all the particles in the system.
Since the implementation of such a method is dependent upon the
specifics of a particular particle system, we declare this method
abstract to force the subclass to implement it.
render —This method displays all the particles in the system. The
implementation is quite involved, and we devote subsection 14.2.1
to a discussion of it.
Search WWH ::




Custom Search