CS320      Project 2  Part I - Pool

You will implement the first phase of a pool simulation using the Lab4 files as a starting point.  You have a pool table and pool balls, whose attributes will be read from a file whose name is given as a command line argument. 

The file format is as follows where the data items are separated by whitespace characters:

ll.x ll.y ur.x ur.y  // area of play boundary
color of area of play  // in rgb components on [0.0, 1.0]
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

The coefficient of rolling friction (Crf) has the following property:
    V' = (1 - Crf Ti) V
where V' is the future velocity, Ti is the time elapsed for the current simulation step, and V is the current velocity. 
 

Your simulation should have the following characteristics:

  1. I expect your program to be readable and literate. Use meaningful identifier names, adequate whitespace, and appropriate comments. Split long statements into several lines, preserving readability. Indent carefully.
     
  2. As already mentioned, data will be read from a file. The name of the file to be read should be given on the command line. The simulation should exit if there is not a single command line argument, or if the data file can't be opened.

    The classes BufferedReader and StreamTokenizer are useful for reading the input.  For example to read in the first value you could have code that looks like:

    BufferedReader in = new BufferedReader(new InputStreamReader(new FileInputStream(file)));
    StreamTokenizer st = new StreamTokenizer(in);
    st.nextToken();
    ll.x = st.nval;

     
  3. It is acceptable to use constant values to define the window size rather than compute values. I used a window of size 900 by 450. You may assume that the window will not be resized.
     
  4. Your simulation should be physically accurate. This means you will need to record the time between simulation steps and account for it in your simulation. This also applies to the coefficient of rolling friction. These will ensure the simulation looks the same regardless of the capabilities of the machine on which it runs.

    You may use the method System.currentTimeMillis() to get the current time in milliseconds and use this to calculate the elapsed time since the last step.
     

  5. The ball array should be sized at run time.
     
  6. If designed and written properly, very few modifications need to be made to
    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().


The following will be taken into consideration in evaluating your work:

  1. The design and generality of your solution.
  2. Completeness of testing. (Of course, you need to provide evidence of testing --- you will lose points for not documenting this.)
  3. The readability of your code.
     

Submit your project in a single ZIP archive.