DEV Community

Cover image for A Simple Particle Simulator in C++ and OpenGL
YJDoc2
YJDoc2

Posted on

A Simple Particle Simulator in C++ and OpenGL

Hey Guys!

Quite some time ago, I had made a very very simple particle simulator in C++ and OpenGL. It is not that much accurate, and sometimes, it is more of a trial and error, but it can create some beautiful things like these :

  • A Simple almost Stable Spiral
    Simple Spiral GIF

  • Another Spiral
    Unstable Spiral

  • A Four Body Simulation
    Four Body Simulation

It is not that much accurate, but it can emulate Universal gravitation, Earth's Gravitation, and Electromagnetic force.
It can simulate Spherical and point like masses, charges or both. It also supports static objects, which can act as fixed objects like Earth's Surface, or fixed surfaces to bounce. And it also has collision emulation, but sometimes the collisions can work out in incorrect directions 😅

Currently it is built and tested in Linux, but it should work on Windows with appropriate Compiler and OpenGL linking changes (If any one can do this and anyone can check it, please open a Pull request!).

It has a simple syntax for describing bodies that should be in simulation.
The GitHub repo :

GitHub logo YJDoc2 / Particle-Simulator

A physics simulator made in C++. This simulates colliding bodies,gravity and electric forces. This uses openGL to display the simulation

Simulator

A simple, not-so-accurate basic physics simulator.


About

This started as an attempt of making an accurate physics simulator which can simulate Univeral Gravitation and Electromagnetic forces on particles, and display of motion of them using OpenGL.
However soon that idea fizzled out, as difficulties were found in making a global time-step and accurate collision detection.
Some of these problems were resolved, and some could not be.
This is a not-so-accurate physics simulator, which can simulate Universal gravitation, Electromagnetic force, and Earth's Gravitation 'g'.

This can simulate motion of spheres, points and add static oblique rectangles and can show their paths. It can do collision detection for all of those bodies, but can give wrong results sometimes.

This started as an attempt to use OpenGL while learning Computer Graphics in SE. Also really wanted to do this as a project related to physics for a long time. Even though it…

So if you check this out, please let me know what do you think about this. Also, if you generate something interesting using this, please post a GIF in comments if possible !

Thank you!

Top comments (0)