Stanford University, Spring 2021, CS 448Z: Physically Based Animation and Sound

Assignment #0: Audiovisual code warm-up 

Prof. Doug James

Due
: Thursday, April 8, 2021

Goal: In this preliminary assignment, you will implement an interactive audiovisual simulation of a simple particle system. The goal of this assignment is to ensure that everyone has a basic audiovisual coding framework setup before we start a nontrivial animation-sound assignment.

Platform: You may implement your audiovisual simulation in any suitable real-time graphics environment that will support custom sound generation--not just loading & playing sound clips, or using fixed-function oscillator models. You may have your own preference, but some suggestions are:
Instructions: In the following steps, you will implement a simple particle system of N balls (or other objects) bouncing in a box. You can use 2D or 3D depending on your graphics preferences. For example, here is an OpenProcessing implementation of 2D and 3D examples (without sound).
  1. Implement the basic graphics framework to draw N balls on the screen (e.g., as circles or spheres), and maintain the position/velocity state of each spherical object.
  2. Making the particles move: Implement a symplectic Euler integrator which (as discussed in class) first updates the particle velocity using applied forces, and then updates the particle position. You can use random initial velocities (of a suitably bounded magnitude) to get started. Include a downward gravitational force.
  3. Wall-particle collision detection and response: The particles are currently not constrained to stay inside the box. Implement a scheme to detect collisions with the four walls, and modify the velocity to provide simple collision response, using a (particle-specific) restitution coefficient to attenuate normal velocity. Be careful how you update your particle velocity/position or you might find your particles sinking into the floor.
  4. Adding sound: Every time a ball hits a wall, you should play a suitable "click" (or other) custom sound or your devising to indicate that an impact was made, with amplitude proportional to the collision impulse magnitude, m |dv|.  Next, to avoid all collisions during a time-step producing "clicks" at the same time-step-size dependent instant, you can estimate the time of ball-wall collision more accurately, and shift the "click" sound in the sound buffer.  As an implementation detail, you can use a circular sound buffer to composite sounds into, then regularly extract the next output sound clip (of suitable "buffer size"). See the documentation on how to stream sounds from a real-time application. Your sound should play clearly and without noticeable audio artifacts.
  5. Make it interactive: You can pull particles around by applying forces to particles near your mouse position. You can also change, e.g., rotate, the direction of gravity using keyboard controls to make all the particles move.
For this starter assignment, feel free to help each other and ask questions on Piazza.

Submission: Please upload your implementation and a very brief note about your findings as a zip file to your HW0 entry in Canvas.