|
COS 426 - Computer Graphics
|
Spring 2011
|
Assignment 4: Particle Systems
Due Tuesday, Apr. 26, 11:59 PM
Overview
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, or even flocks of birds or schools of fish.
Getting Started
You should use the following skeleton code (cos426_assignment4.zip) as a starting point for
your assignment. We provide you with several files, but you
should mainly change particle.cpp
.
particleview.cpp
: Interactive program for viewing scenes
particle.[h,cpp]
: Implements the particle system -- this is the main file you should edit.
R3Scene.cpp
: code to support reading and representing scenes.
R2
: code to support operations on 2D points, vectors, lines, segments, and images
R3
: code to support operations on 3D points, vectors, lines, segments, planes, and meshes.
jpeg
: code to read/write JPEG files
particleview.[vcproj/sln]
: Project file for Visual Studio.
Makefile.[mac/cygwin/linux]
: Make file for Mac OS X, cygwin, and linux.
Makefile
: Copy of make file for Mac OS X.
After you have renamed the cos426_assignment4 directory to
[your NetID]_cos426_assignment4, the
first thing to do is compile the program.
This will create
particleview
(or particleview.exe
).
particleview
is like rayview
, but also calls functions
from particle.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, and particle_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.
How the Program Works
When particleview
is executed, it reads a scene file and
spawns a window.
% particleview in.scn
As in meshview
and rayview
,
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),
psrticle springs (R), particle source and sinks (S),
faces (F), edges (E), node bounding boxes (B), lights (L), and the
camera (C), respectively. 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 them with your writeup.
In the provided version of the source code, the scene is drawn
(with particles shown as white points), 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 in
particleview.cpp
, the DrawParticles
function
is called. It reads the current time (in seconds since the start of
the program) and calls three functions that you must implement (in
particle.cpp
): UpdateParticles
,
GenerateParticles
, and RenderParticles
.
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 in particle.cpp
, but you must
fill in the details.
What You Have to Do
The assignment is worth 10 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:
- (1) 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:
- (1) 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.
- (2) Mesh particle sources. Augment the GenerateParticles function
to create particles emanating from the
surface of mesh particle sources.
- (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:
- (1) 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.
- (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.
- 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:
- (2) 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). To get full credit, you must ensure that the
particles never pass through a solid shape.
- (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).
- (3) 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:
- (1) 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.
- (1) Animated obstacles: Make a scene with a hierarchy of
transformations (using begin and end 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.
- (1) 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.
- (2) 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.
- (2) 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, you simulation must be
stable for rapid user motions.
By implementing all the required features, you get 7 points.
There are many ways to get more points:
- implementing the optional features listed above;
- (1) submitting one or more movies for the art contest,
- (1) winning the art contest.
Full credit is 10 points, and scores past 10 will incur diminishing
returns.
You should provide a working program with scripts to run it, along
with short movies to demonstrate that your program works. For each
movie that you submit, you also have to submit the sequence of
commands used to created it.
What to Submit
Please submit a single .zip file named [your NetID]_cos426_assignment4.zip
containing:
[your NetID]_cos426_assignment4/
writeup.html
Makefile or NMakefile
input/
(All the input data for the examples in your writeup and runme script)
output/
(All the output images and movies)
art/
(All images and movies submitted for the art contest)
src/
(the complete, but cleaned modified source code)
We remind you 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. We will test your code by running make in your src/
subdirectory, followed by make in the main assignment directory to create
the output images. Please ensure that your code builds/runs in this way.
Please see the
general notes on submitting your assignments,
or the same notes explained in slides,
as well as the late policy and the
collaboration policy.
The Dropbox link to submit the assignment is
here.
FAQ
Last update
17-Apr-2011 09:05:40
smr at princeton edu