I have a particle system that as usually creates new particles, updates them and destroys...
In the emitter module there is for loop that resets particles:
foreach p in particles
p.position = rand()
p.velocity = rand()
usually when using C's rand() function we get uniform distibution, but what when I would like to use some other distribution (gaussian for instance) ?
how to change that code so that it will handle several (or at least two) different ways of generating new particles' parameters?
Of course you can create some object: like RandomGenerator, and use some virtual function calls and handle those different behaviours. But this piece of code should be very fast (when updating thousands of particles), so using virtual functions is not good I think.
or maybe I should not care and simply write:
foreach p in particles
p.position = useGaussian ? gausRand() : UniRand()
p.velocity = useGaussian ? gausRand() : UniRand()
we can narrow number of different distribution and use only two or three of them...
please notice that my example is very simple, but in real code you have several particle parametrs configurations.
I would like to get some general advice on that subject.