Devember Day 07
Well I actually managed to get an hour of development done in class today. Maybe it helped that I have programming classes on Mondays. But usually the teacher spends a lot more time talking than allowing us to actually code.
Today's lesson was about classes in C++. They are starting at the absolute basics, which is understandable because some kids haven't ever seen programming before. However, I've had four semesters of computer science classes prior to this school so I guess I could say that I won't be worried about passing any programming tests any time soon.
The example program we made in class was a virtual ball pit type thing. We created a Circle
class to store position, velocity, colour, and radius. Then just updated and rendered a vector of them. I spent a while trying to implement collision detection, which I got to work somewhat well. I'm interested in learning a more advanced way of doing it than simply checking if two circles intersect every frame and changing their velocities and moving them slightly if they do. I imagine one better way would be to cast some kind of ray somehow, although that seems like it could be quite a difficult thing to implement.
50 circles:
And 2000 circles:
I tried enabling collision detection for the 2000 circle example, I got one frame rendered, then nothing for the next ~15s. The algorithm definitely needs some improvement. I don't think it helps that the game engine I'm using (my school's) is more of a didactic engine than a professional one.
A few more interesting color variations (2500 circles each):
After increasing the number of circles past ~3000 the lag becomes apparent.
Although the saying "a picture is worth a thousand words" is true, a gif is truly worth a thousand pictures.
Unfortunately I don't know of a good way to embed gifs in this format, but if you want to see (a very compressed version of) what I'm seeing, click here, it looks quite different from just the still pictures. Too bad the movement doesn't really show in that gif. Ah well.
I'll attach a code snippet along with this log you can skim over if you're interested in how I'm drawing these. It's basically pseudo-code, because the game engine does so much of the internal work for you. If you're reading this on draft.sx then you won't be able to see the .cpp file, you can just click on the id at the top of the screen (#c72b7c8e856af3b19fb0) to be taken to the gist page. (Or just on that link for the extremely lazy).
That's it for today! See you tomorrow.