Добавил:
Upload Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
SFML Game Development.pdf
Скачиваний:
209
Добавлен:
28.03.2016
Размер:
4.19 Mб
Скачать

Chapter 8

void EmitterNode::emitParticles(sf::Time dt)

{

const float emissionRate = 30.f;

const sf::Time interval = sf::seconds(1.f) / emissionRate;

mAccumulatedTime += dt;

while (mAccumulatedTime > interval)

{

mAccumulatedTime -= interval; mParticleSystem->addParticle(getWorldPosition());

}

}

Why do we separate EmitterNode and ParticleNode? Emitters can be considered purely logical scene nodes that emit particles into particle systems. They are not directly related to rendering. A particle system, however, manages the update and rendering of particles. With our current design, we can have multiple emitters that emit into a single particle system. We only need one ParticleNode instance per effect, even with dozens of emitters. Furthermore, both scene nodes can have

different transforms. An EmitterNode is attached to a missile, emitting particles that take the missile's transform into account. As soon as particles have been emitted, they are managed by the ParticleNode, which uses the global coordinate system. It is reasonable that particles, once created, are no longer influenced by the orientation of the object that created them.

Affectors

As a counterpart to emitters, we also mentioned affectors that affect particles during their lifetime. Affectors can be modeled as functions that are applied to each particle every frame—a meaningful abstraction might therefore be:

std::function<void(Particle&, sf::Time)>

This function takes the particle to affect and the frame time as parameters. The ParticleNode would store a list of affectors and apply them to the particles during its update. We have not implemented affectors in our code since we don't need their functionality at the moment, but you are free to extend the system however you like!

[ 199 ]

www.it-ebooks.info

Соседние файлы в предмете [НЕСОРТИРОВАННОЕ]