Boids

7543b5c50738e23b200e69fe697ea85a
0
NomadRock 101 Oct 07, 2004 at 20:43

04-10-07.thm.jpg

Description
This pair of screenshots is shows off a graphics project I did for school. It was an intro class, and I am no artist, so the graphics aren’t anything to scream about among fellow graphics programmers, but they fit the purpose, and that is the whole idea. I wrote code on and off for about two months to get this project written from scratch.

I first wrote a 3d math library to make my life easier. Then I got a font renderer functioning, and finally wrote up a GUI system for it, that is pretty cool if I do say so myself. It is increadibly non intrusive, and it uses seperate layout files to specify the GUI itself that do not require recompiling. It also has a fun logging class that outputs to an html log with timestamps, and is color coded for importance of entries. I also got a smartpointer class going to take care of objects with reference counting.

The point of this app is to show off the boids algorithm, and there are 3 flocks of boids that will fly around the scene following random waypoints. They start scattered randomly, so they require a little bit of time to regroup before they start flying about as a group.

Also of interest, is a procedurally generated terrain that allows for infinite repetition. The trees are all randomly placed, and repeat along with the terrain. There are only 20 unique trees, to give you an idea of scale.

Everything implemented here is rediculously simple, but it all comes together rather nicely, and could be polished into a nice product very easily if I was so inclined.

The definition of the assignment required me to use Windows, but the code uses SDL, OpenGL, and DevIL, and entirely cross platform compatable to wherever those are supported.

It is mostly unoptomized debug code, and I think it still generates a gprof file for profiling, but it is fast enough as is, so I havn’t bothered with optomizing it any further.

Download Windows Binary

3 Replies

Please log in or register to post a reply.

760a6f5fe0bf771163e05e808716020b
0
NeZbiE 101 Oct 08, 2004 at 04:58

Hey, the “flocks” look pretty neat. It would be nice if you provided some information on how the algorithm you used works =)
Just to make sure I have things right, a “Boid” is one of the individual artificial objects in a simulated flock, right?

94cb346a3db618053acb616c005d1a12
0
LuciferX 101 Oct 08, 2004 at 14:59

No Nez,

It the formula that Woody Boid from Cheers would take while walking from place to place. Needless to say the bird algorithm would be much more intellegent. :tongue:

7543b5c50738e23b200e69fe697ea85a
0
NomadRock 101 Oct 08, 2004 at 18:00

Yes a boid is one simulated bird, but could just as easily be a fish, or if limited to a 2d plane it could be a member of a herd. Anything that flocks.

Each time step, each boid:
tends toward the next waypoint
tends toward the flock’s center or the average position of the boids
tends away from any boid close enough that it might collide with
tends away from the ground if it might collide with it.

The ammounts are then tweaked endlessly to get the behavior you want.

Web search for boid algorithm, it is as known in behavioral AI as A* is known in pathfinding.

http://en.wikipedia.org/wiki/Boids has some nice history.