Skip to content

C++ simulation of flocking behavior using the Boids algorithm and OpenGL

License

Notifications You must be signed in to change notification settings

irisxu02/boids-opengl

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Simulating Flocking Behaviour With Boids Algorithm and OpenGL

See 3d-viz branch for 3D simulation.

Requirements

  • CMake >= 3.2
  • OpenGL
    • GLFW
    • GLEW
    • glm (header-only library for math with vectors/matrices in OpenGL)
sudo apt-get install libglew-dev libglfw3-dev libglm-dev

Compile and Run

make && ./flocksim

Inspiration

Inspired by a recent article published by National Geographic, What are birds doing when they fly in swarms? Scientists may now know.:

The team has learned that no matter how large the flock, each starling interacts with only seven neighbors, which might be as much as their brains can handle. The exact neighbors change from second to second, but the starlings don’t track these shifting alliances. They merely fly in the same direction as whichever seven birds are nearest, while staying close but not too close. Alignment, attraction, and avoidance: By plugging this trio of rules into a computer model, along with some basic aerodynamics, Charlotte Hemelrijk from the University of Groningen in the Netherlands created a virtual murmuration that resembled the real deal—and matched the data from Rome.

This showed that the starlings need no overarching plan, no leader, and no telepathic hive mind. They barely need to communicate at all. Through the simplest of interactions, playing out over distances of a few feet, the breathtaking, sky-spanning complexity of a murmuration emerges.

Implementation

The implementation is based on the Boids algorithm to simulate flocking behavior. Boids are simulated with three core behaviors:

  • Alignment: Each boid aligns its direction with neighbouring boids.
  • Attraction: Each boid moves toward the center of mass of neighbouring boids.
  • Avoidance: Each boid avoids collisions with nearby boids.

Each boid is represented as a triangle with colour given by its velocity. The boids appear to move in unison without any centralized control.

References:

About

C++ simulation of flocking behavior using the Boids algorithm and OpenGL

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published