CS-511 - Alternate Assignment 2 (5%)

Bouncing balls

Due by: September 23, 2008

Assignment Specifications

This assignment is intended only for students who took cs411. The purpose of this assignment is to write a program that simulates bouncing balls inside a 3D box. The program gets in the command line two arguments: the number of balls and a speed factor. In the beginning of the program the balls should be placed at random locations with random velocity vectors. At each time step a new position for the balls is calculated based on their previous location and the velocity vector. Intersection computations should be used to detect situations in which the balls hit the sides of the box or hit each other. In such cases the velocity vector should be changed. The speed factor provided by the command line argument may be used to increase/decrease the overall motion of the balls. The following are some particular implementation details:

  1. Determining the displacement of the balls at each step: Given the position of ball $i$ at time step $k$: $p_i(k)$ and the velocity vector of it at that time step $v_i(k)$, the position of the ball at time step $(k+1)$ is given by: $p_i(k+1)=p_i(k)+\alpha v_i(k)$ where $\alpha$ is the global speed parameter specified in the command line arguments, and $\vert v_i(k)\vert=1$.

  2. Determining a collision with a face: At each step, after moving the balls to their new positions, collision with box faces are detected in order to determine if changes to the velocity vectors are necessary. A ball is determined to be colliding with a face $f_j$ if the distance between its center $p_i(k)$ and the face is smaller or equal to its radius $r_i$. Specifically, assuming that the face $f_j$ is represented by a normalized normal $n_j$ collision is detected when verifying that: $\vert n_j\cdot (p_i(k)-q_j)\vert\leq r$ where $q_j$ is an arbitrary point on that face. In a case where a collision of ball $i$ is detected with face $j$, the velocity vector of the ball at time step $(k+1)$ should be changed to $v_i(k+1)=v_i(k) - (2 n_j \cdot v_i(k)) n_j$.

  3. Determining a collision with a ball: At each step, after moving the balls to their new positions, collisions with other balls are detected in order to determine if changes to the velocity vectors are necessary. A ball $i$ is determined to be colliding with another ball $j$ if the distance between its center $p_i(k)$ and the center of the other ball $p_j(k)$ is smaller or equal to the sum of their radii $r_i +
r_j$. That is a collision is detected when: $\vert p_i(k)-p_j(k)\vert \leq r_i +
r_j$. In a case where a collision of ball $i$ is detected with ball $j$ we switch their velocity vectors at time step $(k+1)$. That is: $v_i(k+1)=v_j(k)$ and $v_j(k+1)=v_i(k)$.

  4. Rendering attributes: The size of the box should be at least 10 times larger than the radius of the balls. The balls should have identical radii. Different balls should be rendered in different colors. Rendering should be done with lighting enabled. The light source should be positioned where the camera is. The box should be rendered as a wireframe. Moving to the next time step should be done in the idle handler.

  5. Submission instructions: Please follow the instructions of assignment 1.



Gady Agam 2008-09-09