Hi all
I couldn't find an 'intros/newbies' area here so figured I'd dive in here with my first post!
I'm a student of physics and recently got into the idea of putting basic (or complex) physics principles into my own simulators.
So to start I've just thrown together a little attempt at simulating particles in a box. It consists of a larger red (player) ball which you can move around to collide with other particles in the box. Manipulable settings include player mass, particle mass, gravity strength, number of particles, 'anti-gravity' player ball, 'freeze' the particles, and - my favourite - turn on electric fields around all the particles so they repel each other.
There's no 'gaming' element to it, but I'm pleased nonetheless as I've seen that it's possible to quite easily put physics into games. My next effort will probably be something relating to quantum mechanics or fluid dynamics. I'm in the process of learning geophysical fluid dynamics now too so in future I hope to do some basic planetary simulations (in 3D?), where the user can do things like set the rotation speed, gravity, density of atmosphere, generate clouds or ocean currents etc. Along the way I might have a go at making some games out of these things too.
Anyway, here's my first little project
-
https://github.com/Stuart88/ParticlesFull executable is available in the RAR archive on GitHub, or alternatively the source code is there along with the necessary font and sprite files
. Many of you will probably notice that I rather amateurishly dumped all the code in one huge source file. I know it should have been broken into separate files but visual studio didn't like the way I was trying to share variables across files. Instead of remedying the issue I decided to take the lazy route out of it. My goal here was simply to prove to myself that I can code a basic physics simulator. Later efforts will have neater code.
Also - for the physics folk - In the simulation, the momentum transfer on collision is accurate but for the electric fields it is not. The electric fields were just an extra thing I tacked onto the end, so instead of coding it with proper physics I just wrote an arbitrary velocity transfer using the inverse square law. For all intents and purposes it 'looks' correct, but for large numbers of particles the problem becomes obvious in that they never stop moving in the box (instead of reaching a stable equilibrium).
Another issue is that the particles sometimes 'jiggle' when at rest on the floor of the box