Sparks


Class : Sparks.h

Made By : Steve

Uses : GL_LINES

Complexity : MEDIUM

This effect simulates sparks being emitted from a point source.

Like the electric field, this class was meant to be the first one coded. It has a higher complexity due to the gravity, fading, and lifetime.

The sparks are utilized with the Sparks class. It is initialized with :

Sparks s = new Sparks (int MAX_SPARKS, vector3f coords, vector3f radius, float rand);

The constructor asks the user to specify the maximum number of sparks, emitter coordinates, and its radius. The sparks class does not use radius as other classes do. The radius defines the speed of the sparks. A larger radius will generate faster sparks. It is drawn with :

r -> drawSparks();

As with any of the line-based effects, GL_LIGHTING must be disabled before making the call to the drawing method. The input values for editing are somewhat sensitive :

  • Random : This value lies between 0 and 1. Higher values result in sparks coming out in batches, and lower gives more distributed sparks.
  • Lifetime : This value is measured in frames. The higher the value, the longer the sparks will live.
  • Trail : Like lifetime, this value is measured in frames. It defines the amount of time before the tail begins to follow.
  • Gravity : This value should be less than 0, or sparks will tend to flow upwards.
  • Fade : This value defines the how much the spark will fade per frame. Smaller values will make the fade-time longer. This should be between 0 and 1.

Thoughts : This class yeilded acceptable results. If the trail is short enough, the use of straight lines isn't made too apparent, and the effect is nice. In order to make more of a curve, more lines would need to be drawn, and this leads to difficulty with real-time rendering. I wanted users to be able to use large numbers of sparks, and this would be made difficult with more accurate curves.