Code Correctness
As always, this assignment has a particular set of design features that we expect you to focus on. Here’s the list of the other design features we’ve already highlighted:
- encapsulation
- code duplication
- good variable and function names
- procedural decomposition
- “overcommenting” (e.g., the comments do not explain things that are already clear from the code itself)
- usage of whitespace
- overmodularization (e.g., modularizing into functions that actually make the code less clear)
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:
- In
scene
:scene_add_force_creator
scene_tick
scene_init
scene_free
- In
body
:body_add_force
body_add_impulse
body_tick
body_init
body_remove
body_is_removed
Hints
- A force creator is a function that takes in an aux struct which contains a list of bodies and a force constant. It applies a force, such as Newtonian gravity, spring, and drag force, to the bodies in the aux provided to it when the function is called.
- Examples of this can be seen in forces.c
- You should create a struct and any additionally functions (init, free) to support this struct in forces to store the information of the force creator and its associated aux when a force is added between/on bodies in the
scene_add_force_creator
, so that you can call the force_creator function on its aux to apply forces on the bodies everyscene_tick
.- Note: You are allowed to add functionality to forces.c and forces.h, but not remove any.
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
If your team has rotated roles correctly, you should have done the demo last week. However, the engine component is much more different from the game and demo components. Thus, before you get started, we highly encourage you to talk with your teammates to learn about what they implemented in the engine in previous weeks!
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
.
Task 0. When you are done, your group should meet and complete the questions here.