COS 426:
|
General | Syllabus | Assignments | Final Project
In this assignment, you will implement a basic particle system. The program will read in a scene file with particle commands and then draw particles as they move over time in an interactive viewer.
At its simplest, your program will be able to spawn particles, apply forces such as gravity and drag to them, and bounce them off of scene geometry. Once you have the basic system in place, you have a broad selection of options to improve your system. You can choose to focus on the rendering or the physics of the particles. Improved rendering will allow for more convincing simulation of phenomena such as smoke, fire, and sparks. Improved physics will allow simulation of rope and cloth, solid objects, or even flocks of birds or schools of fish.
Whenparticleview
is executed, it reads a scene file and spawns a window.As in% particleview in.scn
meshview
andrayview
,particleview
allows interactive viewing of the scene with the mouse and keyboard. Dragging with the left, middle, and right mouse buttons down rotates, scales, and translates the scene, respectively. Hitting keyboard keys toggle display of particles (P), particle springs (R), particle source and sinks (S), faces (F), edges (E), node bounding boxes (B), lights (L), and the camera (C). Hitting the SPACE key prints the current camera parameters (in a format that can be included in another .scn file), Q quits, and F1 saves a screenshot in an image (in "imageN.jpg", for N=1,2,etc. increasing each time an image is dumped in the same session). Some of these commands are also available via a menu that pops up when the right mouse button is pressed. Of course, you are welcome to modify the source code in particleview.cpp in any way you want to produce new displays, but please keep the semantics of the existing user interface, and please provide documentation of new features with your writeup.In the skeleton code, the scene is drawn, but the particle system is not implemented. Your job is to fill in the code in
particle.cpp
to generate, update, and render particles at each time step of the simulation. For every refresh of the window inparticleview.cpp
, theDrawParticles
function is called. It reads the current time (in seconds since the start of the program) and calls three functions that you must implement (inparticle.cpp
):UpdateParticles
,GenerateParticles
, andRenderParticles
.UpdateParticles
should update the position (and possibly other parameters) of every particle at the current time.GenerateParticles
should create new particles for every particle source.RenderParticles
should use OpenGL commands to draw every particle on the screen. Shells are provided for these three functions inparticle.cpp
, but you must fill in the details.
The assignment is worth 20 points. The following is a list of features that you may implement (listed roughly from easiest to hardest within each group). The number in front of the feature corresponds to how many points the feature is worth. The features in bold face are required. The other ones are optional.
- First step:
- (2) Euler integration. Augment the UpdateParticles function to update the position of every particle according to its current velocity and vector forces, taking into account gravity and drag, using the simple forward Euler integration technique.
- Particle sources:
- (2) Sphere particle sources. Modify the GenerateParticles function to create particles emanating from the surface of sphere-shaped particle sources. To generate positions on a sphere distributed uniformly with respect to surface area, you can use the strategy outlined here.
- (3) Mesh particle sources. Augment the GenerateParticles function to create particles emanating from the surface of mesh particle sources. To generate positions on the mesh distributed uniformly with respect to surface area, you can iteratively select a triangle with probability proportional to its area and then use the strategy outlined here to select a point on the selected triangle.
- (1) Other particle sources. Modify the GenerateParticles function to create particles emanating from the surface of sources in the shape of circles, boxes, lines, cylinders, cones, etc. One point per source type will be awarded, up to a maximum of 2.
- Particle sinks:
- (2) Sphere particle sinks. Augment the UpdateParticles function to apply a force that attracts all particles towards the surfaces of sphere-shaped particle sinks and deletes them when particles hit the surface.
- (2) Mesh particle sinks. Augment the UpdateParticles function to apply a force that attracts all particles towards the surface of a mesh nd deletes them when particles hit the surface.
- (1) Other particle sinks. Augment the UpdateParticles function to apply a force that attracts all particles towards the closest point on the surface of sinks in the shape of circles, boxes, lines, cylinders, cones, meshes, etc. Particles are deleted when they hit the surface. One point per sink type will be awarded, up to a maximum of 2.
- Particle simulation:
- (1) Particle lifetimes. Augment the UpdateParticles function to delete particles when their lifetimes expire.
- (2) Adaptive step sizes. Improve the accuracy of your simulation by implementing the adaptive step size technique. You should be able to implement this technique without changing the global time step by taking multiple substeps for every particle during each time step. Demonstate the difference in accuracy on at least one scene.
- (1) Midpoint integration. Experiment with the tradeoffs in speed versus accuracy in your simulation by implementing the midpoint integration technique. Demonstate the trade-offs on at least one scene.
- (1) Fourth-order Runge-Kutta integration. Experiment with the tradeoffs in speed versus accuracy in your simulation by implementing the fourth-order Runge-Kutta integration technique. Demonstate the trade-offs on at least one scene.
- Particle interaction:
- (4) Particle-scene collisions. Handle collisions between moving particles and stationary surfaces represented by shapes in the scene file. For each particle, in each time step, you should determine whether the particle traveling along its current trajectory will collide with shapes in the scene within the given time step, and if so where and when. When a particle collides with a surface, the surface exerts a force upon the particle in the direction of the surface normal causing point-shaped particles to bounce off. If the elasticity of the particle equals 1.0, it will go in the specular direction, for smaller values, the vector component of the velocity which is parallel to the normal is scaled by the elasticity, the tangential component is unchanged. You should apply that force to update the particle velocity (ignore the effect of the particle on the scene) and then continue to simulate the particle until the end of the time step (a single particle may collide with a sequence of many scene elements in the same time step). Required shapes are the sphere, box, and mesh. Additional shapes are optional and worth 1 point each.
- (1) Particle attraction. Augment your simulation to allow particles to apply simple attraction forces on one another. The direction of the force should be along the vector between the particles, and the magnitude should following Newton's law of gravity (i.e., F=G(m_1*m_2)/r^2, where r is the distance between particles).
- (2) Springs. Augment your simulation to handle springs between particles -- i.e., particles conected by a spring exert a force on one another according to Hooke's Law. To get credit, you must demonstrate this feature on a string of particles connected by springs. Fix the first particle in space, and determine the position of the remaining particles by their spring connections. To get an additional two points, you can create a 2D mesh of springs representing an elastic cloth and simulate its motion under non-trivial forces (e.g., collisions with shapes in the scene). To get another additional two points, you can create a 3D arrangement of springs connecting all pairs of vertices in a 3D mesh (e.g., an icosahedron) and simulate its motion under non-trivial forces (e.g., collisions as it bounces off obstacles in a scene).
- (4) Flocking. Implement a system similar to Boids. Make sure that your boids try to avoid geometry in the scene; you can accomplish this by allowing them to look a bit ahead of themselves by shooting a ray. Combined with rendering particles as animated geometry, you can make a reasonably convincing simulation of a flock of birds or a school of fish.
- Scene animation:
- (2) Animated camera. Augment
particleview.cpp
to move the camera automatically along the trajectory of the first particle in the scene file. Set the camera towards vector along the particle velocity vector and the up vector to best align with the direction of maximum curvature of the particle's path.- (2) Animated obstacles: Make a scene with a hierarchy of transformations (using
begin
andend
commands or by creating nodes in your program) and then animate the scene by changing transformations as a function of time. You can use this feature to create simple rotating parts like a spinning wheel, flapping wing, ceiling fan, etc. You get an additional point if particles collide correctly with the animated scene elements.- (2) Animated particles: Augment the scene description and parser to create a scene in which the shape associated with a particle is animated (i.e., the shape is changing over time).
- Particle rendering:
- (1) Trails. Modify your particle rendering so that each particle leaves a trail behind it as it moves. You will have to remember previous positions for each particle and use GL_POINTS or GL_LINE_STRIP to achieve this effect. Try storing only the last K positions and fading out the color towards the end of the trail.
- (1) Dynamic materials. Scale the material properties of every particle based on its velocity and/or lifetime.
- (2) Responsive materials. Change the material properties of every particle based on its proximity to static shapes in the scene.
- (2) Animated materials. Augment the scene description and parser to associate multiple materials with every particle and then cycle through them at regular time slices over the lifetime of the particle. Combining this feature with textures, you should be able to get a reasonable approximation of fire.
- (3) Textured sprites. Replace the code in RenderParticles to render a small square polygon centered at every particle position oriented towards the viewer and apply a texture (included as the last field of the material) when rendering the polygon. You should be able to use this feature to generate interesting visual effects like snow flakes and smoke (with partially transparent textures).
- Interactive control:
- (1) Source control. Allow the user to click with the mouse to select a particle source. Then, when a particle source is selected and the simulation is running, keyboard commands should allow the user to increase/decrease the rate of generated particles ("R" increases by 10% and "r" decreases by 10%). You could also support keyboard commands to increase/decrease the speed (e.g., "S" increases by 10% and "s" decreases by 10%), mass ("M" increases by 10% and "m" decreases by 10%), etc. for debugging purposes.
- (1) Sink control. Allow the user to click with the mouse to select a particle sink. Then, when a particle sink is selected and the simulation is running, keyboard commands should allow the user to increase/decrease the force associated with the sink ("I" increases by 10% and "i" decreases by 10%).
- (2) Source and sink dragging. Allow the user to move particle sources and sinks by selecting them and dragging with the mouse.
- (4) Rope or cloth manipulation. If implementing rope or cloth, allow the user to pick a point on the rope or cloth and drag it around. To get credit for this option, your simulation must be stable for rapid user motions.
- Input:
- (1) Make an interesting scene: Submit the .scn file, and include an animated .gif of your scene.
By implementing all the required features, you get 13 points. There are many ways to get more points:
It is possible to get more than 20 points. However, after 20 points, additional points will incur diminishing returns, as on past assignments.
- implementing the optional features listed above;
- (1) Answering a nontrivial question on Piazza (please copy the question and answer into your writeup),
- (1) Submitting one or more gifs for the art contest, and
- (2) Winning the art contest.
You should use the following skeleton code (cos426_assignment4.zip) as a starting point for your assignment. Compiling the skeleton code will createparticleview
(orparticleview.exe
).particleview
is likerayview
, but also calls functions fromparticle.cpp
for simulation and drawing of particle systems.The skeleton code is able to read scene files (like in assignment 3) augmented to support particle systems. Specifically, the scene file format now supports five new commands:
particle
,particle_source
,particle_sink
,particle_spring
, andparticle_gravity
.We provide several scenes with particles in the
input
subdirectory of the zip file that you can use to test your program along with a set of examples. However, you should definitely create your own files for testing, demonstration, and artistic purposes.
You should submit your solution using one zip file named
cos426_assignment4.zip
via CS dropbox at this submission link. The submitted zip file should have the following internal directory structure:cos426_assignment4/
writeup.html
- your writeup (see the description below),src/
- the complete source code, including all the code for libraries, compilation, etc.input/
- all the input data used to produce the results in your writeup.output/
- all the gif movies and images referenced by your writeupart/
- all gif movies submitted for the art contest (optional).The
writeup.html
file should be an HTML document demonstrating the effects of the features you have implemented and would like scored. You can start from thewriteup.html
provided with the distribution as a template -- simply add/delete sections to that HTML file for the features you implement.The
src
directory should have all code required to compile and link your program (including the files provided with the assignment), along with a Visual Studio Solution file and a Makefile to rebuild the code. We will not attempt to grade assignments that neither build in Visual Studio nor with GNU Make under Mac OS X.The
output
directory should contain animated gifs that you have captured to demonstrate the features of your program.Note that you are expected to use good programming style at all times, including meaningful variable names, a comment or three describing what the code is doing, etc. Partial credit may not be assigned for code without comments.
Answers to frequently asked questions:
How can I upload my assignment4.zip file if it is larger than 50MB (CS dropbox's limit)?
CS drop box is only able to handle file uploads of 50MB or less. If your assignment4.zip file is larger than that, then you can split your submission into multiple .zip files and then upload the extra ones via the Additional Files section of CS drop box. Or, much better, you can upload your entire assignment4.zip file via ftp. Specifically, follow these instructions from any shell (on mac or Linux) or cmd (on windows). Note that you have to substitute youremail with your email address:mv assignment4.zip youremail.zip ftp ftp.cs.princeton.edu (login is "anonymous", password is your email address) cd incoming/funk/Assignment4 put youremail.zip quit
Note that the Assignment4 directory is writable, but not readable. So, you will not be able to "ls" in that directory.