This is a modifiable smoke and fire particle system developed in C++ with OpenGL.

Smoke & Fire Particle System


The movement of the smoke is calculated by a turbulence factor. The way turbulence was calculated is by implementing a Catmull-Rom spline and changing wind vectors. Turbulence levels are set at different heights and then interpolated based on the spline. The turbulence factor increases as the particle rises. To keep the smoke more dense towards the center, two separate Catmull-Rom splines are used. 1/3rd of the particles only take half of the turbulence factor to accomplish this. The diagram below demonstrates turbulence.

Color and alpha linear interpolators are also used to keep the smoke near the flame a much darker color and then dissipate slowly.

Turbulence Turbulence




The videos below demonstrate two separate types of collision that were implemented with the particle system.

Both simple and complex calculations use this formula to calculate if a particle is within a certain distance of the plane a polygon lies on:

  normal = cross(Poly Point[1] – Poly Point[0], Poly Point[2] – Poly Point[1]);


  d = -dot(Poly Point[0],normal);

  distance = dot(particle point, normal) + d;

  If the distance is less then a small amount then it is near the same plane that polygon is on

For the simple collision X and Y are set in the same direction.

This means you can simply check if it is between the min and max of the polygon's X and Y values.

with Simple Collisions


For a more complex calculation such as a tube, a check was needed to see if the particle was within the polygon.

This check is similar to a ray tracer calculation in which you check each side of the polygon and see if the particle is to the left of each side.

  Calculate a side vector of the polygon P[i+1] – P[i]

  left = cross( normal , side);

  if( dot(left,position-polyC[i][j]) < 0 )

  If this is true for all sides of the polygon then the particle is within the polygon

with Complex Collisions


After finding if a particle collided with a polygon. The particle then needs to be pushed away from it by:

acceleration += -k*( distance - 0.05 ) * normal;

-- This will push the particle away from the polygon in the direction of the polygons normal then:

acceleration -= (dot(vector,normal) * normal);

-- This will push the particle away from the polygon perpendicular to the polygons normal.