Kalyan
Kalyan

Reputation: 507

Particles in C++ using OpenGL

I want to start a basic particle system in C++ using OpenGL. I wrote an algorithm for that but I don't understand how to start it.

The problem I am facing is I can print the positions and velocity updates but I don't know how to show it visually using OpenGL.

Upvotes: 1

Views: 2234

Answers (1)

UltraInstinct
UltraInstinct

Reputation: 44444

I hope you are trying out something on the lines of what is below:

  • Have a structure(C++ struct or a class) to denote a Particle. The structure contains:

    • Particle location (x,y,z)
    • Particle velocity (Vx, Vy, Vz)
    • Particle acceleration (Ax, Ay,Az) //something you might need too..
    • paint function to do the painting of the particle.
  • Have an array of this structure. Initialise velocity, position, and acceleration as needed.

  • In a separate thread (or in the repaint event, for starting up) do the following:

    • For every particle (element in the array) do:

      • particle[index].velocityX += particle[index].accelerationX
      • particle[index].velocityY += particle[index].accelerationY
      • particle[index].velocityZ += particle[index].accelerationZ

      • particle[index].locationX += particle[index].velocityX

      • particle[index].locationY += particle[index].velocityY
      • particle[index].locationZ += particle[index].velocityZ

      //translate to the location and paint..

      • Use glTranslated(particle[index].locationX, particle[index].locationY, particle[index].locationZ)

Upvotes: 4

Related Questions