How it works...

We randomly distribute the x coordinate of the initial positions between -2.0 and 2.0 for all of the particles, and set the initial velocities to have a y coordinate between 0.1 and 0.5. Since the acceleration has only a y component, the particles will move only along a straight, vertical line in the y direction. The x or z component of the position should always remain at zero. This way, when recycling the particles, we can simply just reset the y coordinate to zero, to restart the particle at its initial position.

Get OpenGL 4 Shading Language Cookbook - Third Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.