For our “Console Development” module in the second year of my university degree, we had to produce a tech-demo for the Sony PlayStation Portable using industry-standard development kits.
I wrote a “flocking” algorithm in C, optimised to use the PSP’s VFPU (Vector Floating Point Unit) for increased performance with inline MIPS Assembly. The boids have a simple 3D wireframe mesh, but their movement is limited to a 2D plane. My coursework was awarded with a “B-” grade.
Read on for the details of this project.
The red boid provides the debug information on the left, in terms of position on screen and behaviour outputs. The behaviours are known as “Separation”, “Cohesion” and “Alignment”, respectively.
Separation makes the each boid maintain a small distance from those surrounding it so that they avoid bumping into each other; Cohesion makes the boids head toward the average position of those nearby, helping them stay clumped together; and Alignment makes each boid head in approximately the same direction as other nearby boids. These three behaviours combine to produce a “desired velocity” for the boid, which is then added to its position to create the algorithmic movement that you see.
More realistic movement can be achieved by limiting the boid’s ability to react to its desired velocity, versus its actual velocity. For example, if the boid were a car, its turning circle would get wider the faster it went, and it would also take longer to accelerate or brake.