Boids

In early December 2005, I ported Eric Singer's Max boids objects to jitter. The Max boids objects were improved and rereleased by Jasch and André Sier in Novermber 2005. When they were released, I used them in my Jelly Ocean project to move the jellies around in the world. The main problem I had with the Max-based obejcts was the data output method. For each boid, a message was output on each bang at a minimum, and the way I was using boids3d there were 2 messages for each boid on each bang. Thus, for 25 boids, I had 50 max messages. This slowed down my patch way too much, and it seemed to me that the objects would be ideal as jitter objects. This way, three would only be one message per bang with each boid residing in a cell of the output matrix.

The boids algorithm has quite a large number of parameters, and when I had asked if I could port the objecs to Jitter, I was worried that slogging through the code was going to be a real pain, especially to debug. On the contrary, the port was practically trivial. The boids2d and boids3d code was extremely well organized, commented, and stuctured. The biggest changes I made involved replacing some structs with arrays and collapsing the amount of code between control parameters and their internal use in the object.

Since the structs contained variables of the same type, and Jitter objects can have arrays as attributes, it was a simple move from struct to array for representing points and velocities in 3D as well as a bounding rectangular solid. I simply made a few #defines for x, y, z, and also for the 6 pints of the rectangular bounding box and voilà. The structs had members with the same names, so all that was left to do was change the struct member access notaton in C to array member access notation (e.g '.' to '[ ]').

The collapsing of the parameter messaging structure was also fairly straightforward. The original max objects had messages that called functions which then set the boids struct member variables. Since Jitter objects have the very useful attribute feature, these methods were for the most part extraneous (there were a few exceptions). As a result, I reworked the naming of the boids struct member variables to match the incoming messages/attributes and that was it.

Since the boids objects have so many parameters, they can be used for a wide variety of patterns and uses. What I really love about this algorithm is that it is behavior based and whn you create graphics with it, the images tend to show this. The pixels end up having this complex intelligent force behind them. For what I've experimented with so far, the 2D boids algorithm is great for drawing and the 3D boids algorithm is fantastic for moving creatures around in 3D.

On a final note, I also added a utility rendering object for the jit.boids objects called xray.jit.boidsrender. It facilitates the drawing of boids in OpenGL. Below are the OS X and Windows distributions of the objects with the source code.

Download

Jitter Boids [OS X]

Jitter Boids [Windows]

boids 2d