Aman Desai
← Projects

3D Multi-Species Boid Simulation

C++ · OpenGL · Spatial Audio

title: "3D Multi-Species Boid Simulation" date: "2024-12-01" description: "Real-time flocking with spatialized audio, written in C++." tech: ["C++", "OpenGL", "Spatial Audio"] status: "course-project" links:

  • label: "GitHub" href: "https://github.com/amanpdesai/Desai_Aman-130H"

Motivation

Reynolds' classic boid model produces convincing flocking from three local rules: separation, alignment, and cohesion. I wanted to push past the textbook version — multiple species with distinct rule weights, and spatialized audio so that a flock passing your virtual head sounds like it's passing your virtual head.

Approach

The simulation runs in a tight C++ loop with a uniform-grid spatial hash for neighbor lookups, keeping per-frame work near linear in the number of agents. Audio cues are positioned in 3D using HRTF-style panning so each species has a recognisable signature.

  • Per-species parameter sets (separation radius, max speed, cohesion weight)
  • Spatial hash grid keyed on cell index for O(1) neighbour queries
  • Spatialized audio synchronized to flock centroid

Results

Comfortably interactive at a few thousand agents on commodity hardware. Different species emerge with visibly different behaviours from parameter tuning alone — one of those satisfying moments where local rules add up to something that looks deliberate.

What's next

  • Replace the spatial hash with a BVH for very dense scenes
  • Try learned policies per species (DDPG / PPO) and compare to the hand-tuned rules

References

  • Reynolds, Flocks, herds and schools: A distributed behavioral model, SIGGRAPH 1987