Home|Projects|About

Verlet Integrator, C++, 5.21.2022

After watching this video, I was inspired to ... completely copy it.
I mean thats how you learn things, right?

For the record: It took an INSANELY small amount of time to get this to work. One slight issue, though: SDL *cannot* draw circles by default. Lack of good primitive drawing functions is actually my only real gripe with SDL, and was the main thing that made raylib attractive.

There really isn't that much to say about this, it really is a simple algorithm. I am somewhat suspicious of his claims of total ball numbers, though it is also possible that I simply structured my code in a dumb way. (one thing was that circles were very computationally expensive, since I was using an algorithm to essentially software-render them)
I ended up getting it to handle around 3000 balls without fps drops
Coulda done way more with some sorta spatial partitioning scheme, threading, etc, but for what I wanted this was fine (I also would have needed to rewrite my entire code, and I didn't feel like doing that...)

This was the reason I wanted to try this, I thought the fact it was deterministic was super cool, and I just wanted to do cool stuff like this with it. Though, you may notice my cicles aren't filled in. I could have used a circle texture or something, but I decided that I could just draw rectangles. Due to the computational overhead of drawing circles pixel-by-pixel, this ended up being considerably faster, too!


I made so many of these. You can see scooby is a little jittery, I fixed that by making the 'balls' only change their velocity out of the way of collisions instead of actually moving out of the way (I believe, it was something like that at least)
It ended up making it look more like a fluid simulation, which honestly I think is a little better. Techincally not true verlet integration anymore, though.
If you wanna try it out for whatever reason, you can download it here. Keep in mind that, at the time, I refused to use any sort of actual image loading libraries, so the source image MUST be a 24 bit uncompressed bitmap.