CS 320
75 points, due Apr. 6, 2009
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:
The simulation should exit if there is not a single command line argument, or if the data file can't be opened.
Look online (phoenix) at the documentation for fopen()
,
fscanf()
, and fclose()
. The fscanf()
conversion
formats you will need for reading are %lf
for reading doubles and
%ld
for reading integers. 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. You should account for this overflow.
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 solution 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 6th. My standard late penalty (10%/three days) will apply.