CS 320
75 points, due Mar. 30, 2011
For this project you will implement the first phase of a pool simulation,
starting from collision.c
. You have a pool table with certain
attributes and pool balls with certain attributes. There is a simulation
attribute or two to handle as well. Sample data is collected into the file
poolData.txt
. Your simulation will take a file name as a command
line argument and use the data in the file to define the simulation. The
data format is as follows.
Notes: Lengths are in inches. Colors are rgb components on [0.0, 1.0].
Velocities are inches per second. Time is seconds. The coefficient of
rolling friction () has units of inches per second per inch.
Mathematically:
number of simulation steps per render step ll.x ll.y ur.x ur.y --- area of play boundary color of area of play width of fringe area surrounding area of play color of fringe area coefficient of restitution coefficient of rolling friction number of balls mass radius color position velocity --- ball data, repeated for each ball
Your simulation should have the following characteristics:
collision.c
is readable and
literate and use it as a model. Be sure that all comments are appropriate
to your program. Do not simply comment-out lines of code that you are no
longer using -- remove such lines from your program.
The simulation should exit if there is not a single command line argument, or if the data file can't be opened.
Look online at the C library documentation for fopen()
,
fscanf()
, and fclose()
. The fscanf()
conversion
formats you will need for reading are %lf
for reading doubles,
%ld
for reading longs, and %d
for reading ints. Do not
forget to pass the addresses of
the variables into which you are reading:
fscanf(data, "%lf", &ll.x); /* FYI, data is a file handle. */
GetTickCount()
will be useful here:
#include <Windows.h> #include <Winbase.h> int GetTickCount(void);This function returns the current number of milliseconds since boot time. It overflows every 49.7 days. It would not be wise to assume that this value won't overflow while your program is running.
collisionResponse()
for handling collisions between a ball
and the boundary. It will be quite useful to have a wrapper function
generate the virtual ball modeling the boundary and then pass the two balls
to collisionResponse()
. You will need to find a way to represent
the infinite mass of the virtual ball and modify collisionResponse()
to recognize this and adjust the computation. This is the only change
needed to collisionResponse()
.
Your project is to be e-mailed to me at kelliher[at]goucher.edu. All project files should be sent as attachments in a single e-mail. You may collect all the files into a single ZIP archive, but be sure to first change the file extension and inform me in the email that the file contains a ZIP archive. You should send all files necessary for me to build your program from source (generally, this is all .h and .c files), as well as any documentation and test files. You should send an ASCII file, named README.txt, describing the rest of the attached files. I will build your program from source and run it for myself. Your project is due at the beginning of class on the 30th.