An Interactive Flocking Simulator in OpenGL

Slides

Video

Milestone

A quick demo of our project

A quick demo of our project

Abstract

Our project simulates a flock of birds using the Boids algorithm. While most implementations of Boids are in 2D, we aim to create a fully 3D, visually appealing experience that models the phenomenon of "murmuring” (flocking) starlings. With the addition of environments, predator-prey interactions, wind physics, and an interactable GUI, we aim to immerse the user in a realistic simulation.

Technical Approach

Overview

We used C++ and OpenGL to code and render our simulation. We initialize each Boid with a random position and velocity, then apply the alignment, cohesion, and separation forces outlined below. Small improvements to the algorithm—along with external forces such as predator-prey interactions and wind—create a more realistic simulation. We also use a simple spatial hashing scheme to improve the efficiency of our simulation. Finally, we implement various visual improvements and update the GUI so the user can influence the simulation.

Getting Started

Our starting point was the skeleton code from Homework 4, Cloth Sim. We studied clothSimulator.cpp to understand the rendering and simulation pipeline, then updated the GUI with our parameters and created classes based on pointMass, cloth, and clothSimulator. The boid class represents each individual agent, the flock class represents a group of Boids, and the flockSimulator class runs the simulation and handles events.

Our Simulation

Our Boids follow the Reynolds model and possess three attributes: position, velocity, and acceleration. We can compute the total force on each Boid with the following equation:

A simple diagram of Boids behaviors.

A simple diagram of Boids behaviors.

First, we have an alignment force that causes Boids to move in the same direction. We set a radius to identify neighbors, then loop through the neighbors to determine their average velocity. We increment the force by the difference in velocities.