Saturday, January 10, 2009

An example of what I like to do

On my last post I talked a bit about how important it is to find things that you like to do in order to drive learning. I have recently been sort of swept up in this thing, and when it happens to me, you can be sure that I'm going to be absorbed for days.

First let's talk a little about some of the kinds of things that I've seen from people when they get swept up in a learning rapture. The one that comes most prominently to mind was a kid I met on my recent trip to Guatemala, a favorite recent topic of conversation to be sure.

This youngster was an undergraduate who wanted to show me the project he was working on. I could tell that whatever it was would be cool, given his enthusiasm. I was not denied. And I think I even had a few surprises in store for him. I might have been the first person he'd ever met that he didn't have to describe what a Theremin was. This fellows project was to build his very own. I think that's bloody awesome! When I was a youngster myself I was quite interested in early electronic musical instruments. In high school I was fortunate enough to be able to save up to buy myself a decent digital keyboard. It sort of what a let down, because what I really wanted was a Moog or even better an Oberheim, I mean when I dared to dream. It's pretty clear to me, however, this kid is a better musician than me, and certainly a better electronics engineer. It was really cool talking to him. We got talking about early electronic music, like Robert Moog (who went to my high school - if I may name drop) and Wendy Carlos.
What needs to be underscored as that this fellows passion for music was driving an enormous amount of learning on his part. Even if he never ends up working in music, he will have developed enough knowledge to propel him in to a wide variety of useful, interesting and rewarding fields.

The fellow I used to work for when I was doing Human Rights work is another good example of someone who allows his interests to drive his learning. He's a Sociologist by education and degree, but at some point he began to become intensely interested in this computer stuff. He was particularly able to combine his unrelenting passion for social issues with technology which drove him in to the loving clutches of the Free Software movement. This is sort of double dipping of learning potential. For fellows like Patrick, the niftiness of technology is enough motivation by itself, in some ways, even more so for him than myself. But if you combine this with the Free Software movement, you now have a motivated person exposed to an unprecedentedly large body of technical knowledge. Arguments over the merits of free software vs. proprietary software (I am mainly an advocate of Free Software, but my latest exploits have awed me with what is under the hood of some proprietary stuff), there is some very high quality and professionally robust projects out there. Anything you want to learn about is essentially out there.


This sort of brings me to my latest obsession. As I mentioned before my original primary motivator for pursuing technology are video games. It's really kind of sad, but there you have it. When I was a kid I was pretty in to them, and of course in those days, there were no video games of note worth playing in the home. They were all in the "arcades". When thinking back, there was some pretty nutty stuff out there, but what holds my attention were the old cathode ray vector games where instead of rendering pictures using familiar TV scan lines, the shapes were drawn on the screen directly using the electron gun. The result was something that resembled an analog game more than the earlier clunky jaggy raster games. This more analog look and feel lent itself to interesting games that were closer to modeling physics than some of the others. One strange one that always caught my attention but was never very popular was one called Gravitar. It's a successor to the popular Lunar Lander game, except that it throws in a few more elements than just landing on the surface of a planet to make it more interesting. Someone recently came up with a retro take on the game which naturally I had to check out.

Well, when I was a kid I always had the delusional thought I could do even better than those games, and even though I am unlikely to succeed, I decided now was the time to try to do something simple. When I was at University one of my roomates started experimenting with
SDL and wrote a simple 2-D particle simulator. Well, it turns out SDL is still around, and since my language d'jour is Python, I went in for SDL based PyGame. Did I mention that this decision making process happened at 5am (this is prime mind activity time, I'm telling you)? Laptops, especially Macs, make it very easy to start writing projects in bed at this kind of our. By sunrise, I had a rudimentary 2-D particle system where you could introduce object oriented elements which would encapsulate their own behavior and each phase have the opportunity to interact with other particles (like inter-planet gravity vs. single directional gravity).

This was a lot of fun, even though I had not yet written a video game. But it got crazier. Ok, so I wrote my own particle system, but after browsing some of the projects on the PyGame web page I had discovered that there were (of course) already existing open source 2D physics simulation libraries including Python bindings. But these were not just simple silly particle systems like what I wrote... These are full fledged physics systems complete with shape collision detection! Here's a game written using Box2D. Is that not the coolest thing you've ever seen!? It's even better than Falling Sands!

And here is where the real insanity begins. See, if I am going to make a game, I need to make an editor. And if I am going to make an editor, I am going to need a GUI. My GUI of choice is wxWidgets, for a number of reasons. That means I now have to integrate wxPython with PyGame, which is possible... But I also want to do some neat rendering, like automatic scaling/zooming and even rotating the whole screen. I actually prepared to do that stuff in the particle system I wrote myself, but I knew that I could not have as well or efficiently than something like OpenGL. So that meant I had to use OpenGL. Besides, wxWidget/PyGame integration doesn't work on the Mac, so I needed another way to draw polygons in to a window. But I still need PyGame to handle the time scaling, so computers with different speeds and drawing abilities can run the simulation accurately, and sound in case I wanted to ever add that.

This ends up being a lot to learn, but fortunately, all three things I needed to work with are relatively easy to install and even repackage in case I want to distribute this monstrosity.

Working with OpenGL automatically ran in to problems because I discovered a bug where PyOpenGL won't run properly on a Mac with a case insensitive file system. That meant I had to go figure out the problem and even submit a patch to PyOpenGL. After I got all that fixed it turned out to be easy enough for me to translate between the shapes being modeled in the 2D physics system and GL. I'm quite familiar with the kinds of matrix mathematics required to do 2D and 3D graphics and physics, so none of that stuff that is introduced by using GL is a problem. In fact, I know that using matrix transformation this way is flexible and powerful!

I don't know if you followed any of that, but it illustrates how many different things that you get pulled in to an how easy it is when it's something that you think is fun.

No comments: