Wednesday, December 17, 2008

Overall project update. Final blog of fall semester

I started this project by writing a very simple python version of a verlet system, modeled after a paper I read on the subject. I had been wanting to write my own physics and collision code for a while, and while I do want to use it for a game, it's my primary focus for senior project.

Jacobsons paper, Advanced Character Physics, was a great introduction paper to using verlet integrationg for physics. The concepts of Particles and Constraints was really easy to grasp, and turned out being very easy to model more complex shapes from; Like soft and rigid bodies.

The first "wave" of code came along pretty nicely. I had some trouble understanding a few things involving the math behind verlet particle integration, but they were worked out pretty quickly. Constraints math wasn't too much more difficult. The goal is merely to push the two the particles apart from one another by half of the distance they need to move to be exactly the rest length apart.

Once it was time to start testing, I had to decide what I want to use for my graphical back end. I really wanted to use something different than pygame, so I went with pyglet, an opengl module for python. Pyglet was decent when I first started, definitely easy to get started with. All I needed was to set up a window, get the fps, and draw a crate powered by my simple physics. Much to my dismay, once I got it working, I realized it couldn't handle much, even as simple as it was in comparison to everything that goes into a dynamics engine. There was a lot coming still(collision, friction, restitution, so I knew I needed to optimize.

Before optimizing, I wanted to clean up an refine some of the code I had. So I started a second version of my code, making a few minor changes while rebuilding everything. Next, I tried getting rid of the Vector2 class, just to get rid of that overhead. With most of the code being vector math, this turned out to be a bit of pain, and somehow, I managed to mess up the math at some point. Soon after, I just decided that it probably wouldn't be worth it to optimize a physics engine in python no matter how many optimizations I used, anyway. So, I rewrote the physics in C++, with the intentions of making it a module for python, though I never did. After finishing the first version and confirming the numbers, I decided that I should try to squeeze in a bit more optimization using simd instructions. I looked into simd for a while, had some trouble getting it to work because I'm an idiot who never set the proper compiler flags. I found out, after writing a simd Vector2 class with overloaded +,-,*,/ operators, that there wasn't much of performance improvement through overloading those particular operations when only dealing with two numbers. Instead, I would need to use simd only during the parts where a lot of that vector math is happening at once, like when solving constraints. Also, I could pack two 2D particles into a Vector4, and do two at a time. But that would only work during the integration step, not when solving the constraints.

Soon, I decided not to bother with most of the optimizations for a while, move on with writing the collision code. The collision code didn't go well at first, but is under way and should be roughly done soon into next semester. Afterward, I'll hopefully have my mind made up about what tools I'll be using to develop the game with, whether it be Ogre or OpenGL. Most likely Ogre, for it's animation utilities, but we'll see.

The future of this project relies on my getting my dynamics engine done. First and foremost, that is my goal, and after that, it's game time.