Homework #4 - Flocking

The goal of this assignment is to develop a deeper understanding of how flocking works, and to improve your ability to write well-modularized C++ code.

You must use the C++ language and the SFML library for this homework assignment.

Resources

The following resources will be helpful for this assignment:

Chapter 6 - Autonomous Agents, in The Nature of Code by Daniel Shiffman. Provides well organized explanations and source code (in Processing) for implementing flocking.

Adding and Subtracting Vectors and Normalizing Vectors

Assignment

In this assignment you will create a simulation consisting of many vehicles (boids) that demonstrate flocking behavior.

To pass the assignment with a B+ grade requires completing #1-6 below. Submission involves sharing a GitHub repository, and making a simple video demonstrating: (a) running simulation demonstrating flocking, (b) adding vehicles to the simulation, (c) demonstration of turning on/off separation, then alignment, then cohesion.

The flocking simulation must meet the following criteria:

1. Vehicle class. There must be a separate C++ class representing individual vehicles, with its own .h and .cpp files (i.e., this vehicle class should not be embedded in some huge "allThingsFlocking.cpp" file).

2. Vehicle system class. There must be a separate C++ class representing the set of all vehicles in the simulation, with its own .h and .cpp files. This must be separate and distinct from the file holding the vehicle class (#1 above). In addition to driving the flocking simulation, this class must also have functions for adding and removing vehicles, and for turning on/off different steering forces. This class must also have functions for setting the weights (scaling factors) on the separation, alignment, and cohesion forces (see slide "Combining Forces" in the lecture notes).

3. Separation, alignment, cohesion. The simulation must include the traditional elements that make up flocking: separation, alignment, and cohesion.

4. Toggle forces. It must be possible, via a keypress, to turn on/off separation, alignment, and cohesion. This will allow you to see the impact of the separation force, alignment force, and cohesion force on the overall simulation.

5. Represent as triangles. Vehicles must be represented by triangles, with two equal long sides and one shorter side. The triangle needs to point in the direction of its velocity vector (that is, it should point towards its heading).

6. Add/remove vehicles. It must be possible to add and remove vehicles from the simulation either via keypress or mouse click.

To get an A grade for the assignment, perform one of the following:

7. Pathing. Implement path following across multiple path segments. Demonstrate by creating a closed path comprised of multiple segments , and showing that vehicles follow the path. The final example should look similar to Exercise 6.13 in Chapter 6 of Nature of Code.

8. Space partitioning. Implement a space partitioning approach (bin-lattice, quadtree, or other) so as to improve the computational efficiency of the force computation.

9. Noise and view blocking. Add some noise to each of the vehicles (velocity or force) so as to create a more naturalistic looking simulation. Then, implement a new force that has the vehicle move away from any other vehicle that is blocking its forward view (see Exercise 6.17 in Chapter 6 of Nature of Code for more details).

For submission, demonstrate this additional functionality in your video submission.