Attack of the Boids
By Henry Chen→In the Textbook (Fundamentals of Computer Graphics, 4th Edition), if you keep reading Chapter 16 past the assigned readings (from A8), you will come across section 16.7 which describes animating Groups of Objects. Specifically, we focus the emergent behavior of flocking, where the motion of a group member (called a boid) in relation to just a few of its closest neighbours can be used to exihbit coordinated goal-driven motion (Reynolds, 1987). A copy of the original paper can be found on the DCS website: https://www.cs.toronto.edu/~dt/siggraph97-course/cwr87/
Key features
- General boid class representation (you can change the mesh associated by pressing “m”)
- Each boid is influenced by the target, cohesion, alignment, and separation forces (clamped) - notice that just comparing with a fixed number of neighbours (fixed cost) is sufficient to produce our global behavior.
- Flock animated using OpenGl viewer.
- use 1,2,3,4,5 to toggle the different influences to see the effects. “m” for different boid mesh.
Key files
- src/boid.cpp - Implements the boid class
- include/boid.h - Header file for boid class
- main.cpp - Animation file (you can play with global variables here)
- CMakeList.txt - basically just A8, but with some changes
- Readme.md - You’re reading it right now!
- piece.mp4 - Demo of project (or see this youtube video: https://youtu.be/5OGj3mlQiI4)
Note: Other files are essentially unchanged from A8 starter code so you can see how it fits in.
Acknowledgements
- Textbook - Fundamentals of Computer Graphics, 4th Edition (Steve Marschner, Peter Shirley)
- Original Paper - Reynolds, 1987: https://www.cs.toronto.edu/~dt/siggraph97-course/cwr87/
- Also referenced this helpful guide (By Thomas Rouch) to understand the key concepts, particularly the math for Alignment, Separation, and Cohesion: https://medium.com/better-programming/mastering-flock-simulation-with-boids-c-opengl-and-imgui-5a3ddd9cb958
- I used the same external libraries as A8, particularly OpenGL (libigl).
- I also asked ChatGPT for some help with conceptual questions, particularly when writing the OpenGL viewer.