Wednesday, May 6, 2009

Project 3: Boids, flocking, and colorful boxes!

So, for Project 3, I chose to implement Boids. Basically, the program implements the three rules of flocking behavior in 3-dimensional space. If one boid is near another, it will start to follow it, kind of like a herd. This program is based off of the algorithm developed by Craig Reynolds, .

Before I go into detail about how I undertook this project, here is the end result:
click me!


Now that you have all been thoroughly "wowed" by the flying boxes...
I first started by reading up everything that I could find about boids on Wikipedia. After putting together a rough setup of the program based off of Conrad Parker's psuedocode, I also read up on how to implement 3D in Processing. While the math seemed right, I still had issues actually getting it to display anything in the environment... So I referenced a Processing-based example that showed how to implement boids in 2D which helped me iron-out many of the issues I was left with. Bull-headed persistance and experimentation helped me develope the environment-wrap. After seeing what some of the other students had done for their projects, I decided mine was in dire need of spicing up... So, I added the color changing feature, just to make it stand out from the sea of other uncolored boids. While designing it, I implemented OpenGL graphics processing to display the boxes, and, unfortunately, that does not export as a clean, self-contained application. So instead of using OpenGL to provide you with what you see when you launch my boids application, I used Processing's 3D graphics generator, P3D; which for some reason, does some strange stuff to the boids as they fly off of the screen in the Z-axis.