1

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.

2

1 Answer 1

4

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)
Sign up to request clarification or add additional context in comments.

2 Comments

Hi guys, Can anyone give me example of basic particle system using openGL, or any link...
Umm, the bullets I have put down above, is pretty much sufficient to implement a basic particle system, IMO. Show us what you have tried, may be we can help. In case you need a code to start you up, google for it; I am sure you will end up with 1000s of it. :)

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.