CS 3 (Spring 2024) Project 04: 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 such that you link the provided forces to your scene and bodies.

We have provided you with new versions of the relevant interfaces (body and scene) to finish implementing. Note that function signatures may have updated and make sure you fix your functions such that they adhere to the updated header files. Please note that you will have to add to the functionality of body and scene. Please refer to the body.h and scene.h files and the structs in body.c and scene.c. The functions that you will need to implement or modify are:

Hints

Below is a demo of “damping” which you can run to test your spring and drag forces in action. This will use you physics engine code, so the goal is to get your implementation of force abstractions to get the damping demo to have the following behavior:

To run the above demo, run the following commands in order: make bin/damping.html and make server

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.