Boids Flocking Simulation
This project consists of independent bodies, boids, acting on certain characteristics to simulate the nature of a flying flock of birds. A world is created and boids are given three desires to fly based on Craig W. Reynolds paper, “Flocks, Herds, and Schools: A Distributed Behavior Model.”
- Collision Avoidance: The desire to avoid collisions with nearby boids
- Velocity Matching: The desire to fly at the same speed as nearby boids
- Flock Centering: The desire to stay towards the center of the flock
The desires are accomplished with object oriented programming, creating objects for boids, flocks, and behaviors. Each boid belongs to a flock that knows every boid within the flock and computes a distance matrix between the boids of the flock. Although boids could do this on their own, it is more efficient for the flock to calculate this each tick. Boids are also given a behavior that uses algorithms to tell the boid where to move based on its three desires. A point class is used for 3-D coordinates to hold locations and vectors. The point class overrides operators so point objects can be added, scaled, etc. and contains functions to calculate distance, magnitude and to normalize vectors. Each tick, the flock is told to update, telling every boid to move, which asks its behavior where to move and moves the boid, and then flock updates the distance between all the boids.
Realistic Animation:
Parameters are used to weigh the importance of all three desires of the boids. After trial and error, parameters were found to create a decent flying simulation of a flock of birds.
Unrealistic Animation:
The following is an example of an animation where the parameter on the flock centering is too high. Notice that the boids lose their sense of direction and all repeatedly fly towards the center.
Other
While this was part of a group project, I was not involved in the development on the world, graphics, or GUI anymore than to make sure flock objects were being initialized and called correctly. The goal for this project was to create object avoidance and multiple behavior algorithms before running out of time.
Check out the GitHub repository
