CS 3 (Spring 2024) Project 01: Bouncing Star (Engine)

In this project, you will begin your physics engine by starting to build the underlying data structures.

Code Correctness

Goals and Deliverables

In this project, you will begin writing the codebase you will be working with over the next several weeks; it is entirely possible that you will still be using some of this code in week 10 of the term. This week, you will build a basic data structure.

vector_t

In vector.h, we’ve provided function prototypes which you should implement in vector.c. See the provided documentation in vector.h for what the functionality should be. Your vector.c file should (1) include the vector.h header and (2) define the functions specified in vector.h. You’ll be writing an extensive set of functions that act directly on vector_ts that are not pointers. Your vector_t will eventually represent position, velocity, acceleration, and other vector quantities in your physics engine.

vec_list_t

In CS 2, you may remember that we created an ArrayList in Java from scratch, making it auto-resizable and generic. We will eventually get to the same place in C, but, because C doesn’t provide as nice abstractions as Java, it’s going to take us a few weeks. This week, since we only need to represent a single polygon, all we need is a fixed-size ArrayList of vector_t *s. Notice that we are using pointers, not values here! This will be important later.

Polygons

A polygon can be represented as a fixed-size vec_list_t. We will take the convention that a polygon’s vertices are stored in a counter-clockwise order.

Running and Testing your Code: make and the Makefile

In project 0, you used clang to compile your one-file C programs. Going forward, our project will consist of many C files. It is important to organize projects carefully to help reduce the complexity that comes with larger programs. Your physics library will have the following directory structure:

We have provided you with a Makefile which is set up to build the project. It allows you to run the following commands:

To run all the tests, all you need to type is make test. To run compile and run an individual test suite, run the following commands (replacing vector with the test suite you want to run) :

make bin/test_suite_vector
./bin/test_suite_vector