## 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.

# 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.

• The two most primitive things to represent are two-dimensional vectors and polygons. You will implement the base of both of these this week.
• The main data structure we will need is an ArrayList. This week, you will write a simple wrapper for an array, and you will extend it to be more useful in future weeks.

# 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:

• include: header files go here
• library: source files for your libraries (e.g., vec_list, polygon, etc.)
• demo: source files for the demos go here
• tests: test source files go here
• out: built object files will be generated here
• ref: reference object files for the demo and game are provided here
• bin: built binaries will be generated here

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

• make demo: compile the demo and runs the web server
• make game: compile the game and runs the web server
• make test: compile all libraries and tests and run all the tests
• make NO_ASAN=true demo compiles the demo without asan - this is recommended for running demos
• make server: Run the web server with the current binaries
• make clean: remove all generated binaries

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