CS 18 (Spring 2026) Project 02: Forces and Impulses (Physics Engine)

In this project, you will add an abstraction for forces and impulses.

Code Correctness

Force Abstraction

This week, our scene abstraction also needs to support “registering” force and impulses (in a similar way to how sdl_wrapper supports registering key handlers). To do this, you will need to implement some new functionality in body and scene. The idea is, during each tick, the scene runs all attached forces. The forces can be “registered” using the scene_add_force_creator function. We have declared a force_creator_t typedef which takes in a piece of auxillary state to be used by the actual implementation of the force. Additionally, implementation of force creators for gravity between two bodies, a spring force between two bodies, and drag on a single body have been provided. Consider what additional abstractions you can make to link the provided forces to your scene and bodies.

We have provided you with new versions of the relevant interfaces (body.h and scene.h) that you’ll have to implement in body.c and scene.c. Note that documentation for existing functions might have updated, so make sure you to fix your functions such that they adhere to the updated header files (the Compare feature in VSCode is helpful for this).

The list of functions that you will need to implement or modify are:

All the documentation for these functions can be ound in their respective .h files.

Here are a few hints:

Testing

We have provided tests for the physics engine files. All provided tests must pass in order to receive full credit. As a reminder, these can be run with make test.

Below is a demo of “damping” which you can run to test your spring and drag forces in action. We have provided the demo binary, so it only requires a correct implementation of the engine to work. If the engine is implemented correctly, the damping demo should have the following behavior:

To run the above demo, run the following command: make damping.

Once all your group members have finished, work with them to complete the extension (more information in the main project page).