Game Development Reference
This allows us to put a hard limit on the number of fireworks being processed,
which can avoid having the physics slow down when things get busy. Many developers
use a different strategy in their engines: they give priority to newly spawned particles
and remove old particles to make way. This gives a slightly less pleasing effect in the
fireworks demo, so I've avoided it.
The code that actually creates new fireworks looks like this:
Excerpt from src/demos/fireworks/fireworks.cpp
* Firework rules control the length of a firework's fuse and the
* particles it should evolve into.
* Creates a new firework of this type and writes it into the given
* instance. The optional parent firework is used to base position
* and velocity on.
void create(Firework *firework, const Firework *parent = NULL) const
firework->type = type;
firework->age = r.randomReal(minAge, maxAge);
if (parent) firework->setPosition(parent->getPosition());
// The velocity is the particle's velocity.
cyclone::Vector3 vel = parent->getVelocity();
vel += r.randomVector(minVelocity, maxVelocity);
// We use a mass of 1 in all cases (no point having fireworks
// with different masses, since they are only under the influence
// of gravity).