Note: clarifications added. -- 19:01 Jan 13.
Note: discussion and additional details on WebCT. -- 18:00 Jan 17.
Since this is the first assignment, you'll need to spend a little
bit of time to get set up. If you are not already using Java then
download and install the latest
Java SE
JDK (careful not to select the JRE). I also recommend using
Eclipse as a development environment.
Download the
provided code and dump it into a
new java project. The code has two parts. The first part is the
comp599.a1 package which contains the template code for this
assignment. The second part is the comp599.tools package, which is
a set of tools for quickly getting started with 2D and 3D graphics.
There are three parts to the tools package:
- parameters contains boolean and double parameter
classes for quickly setting values with swing interface
controls.
- swing contains layout helpers and panels for
quickly throwing together a Java swing interface.
- viewer contains some simple classes for 2D and
3D viewing, including a 3D trackball and camera controls.
(note that for simplicity, this assignment is set up to be all
2D graphics).
You do not need to change anything in the tools package to
complete this assignment. The source for the tools is provided only
for your convenience, and you should focus your attention on the a1 package.
The code uses two other libraries: JOGL for
OpenGL bindings, and vecmath for classes useful for math with 2D
vectors. JOGL is available at
https://jogl.dev.java.net/.
Click on current release build (JSR-231 1.1.1) and download the
appropriate files for your platform. If on windows, download
- jogl-1.1.1-windows-i586.zip
- jogl-1.1.1-src.zip (to have access to javadoc in Eclipse)
- jogl-1.1.1-docs.zip (if you prefer reading javadoc in your browser)
To make your life more pleasant in Eclipse, you want to attach
the source code to the jar for the javadoc. First add the jar to
your build path, then open up Reference Libraries in your project,
right click on the jar to set properties, go to source code
attachment, and tell it where to find the zip file. Note that the .dll
(or .so) that comes with the jar must be in your path. You
can do this by opening the reference libraries in your project,
right clicking to select properties, choose Native Library and
enter the location of the .dll or .so file.
If you need either a quick introduction to or to brush up on
OpenGL, check out these links:
The OpenGL Programming Guide
(The Red Book) online version
(or
at
Amazon),
Jumping into
JOGL, JOGL:
A Beginner's Guide and Tutorial. Another popular resource
is nehe.gamedev.net (see the
NeHeGL JOGL link on the bottom right).
The vecmath package is available as part
of Java3D.
Instead of installing the full Java3D, you can download just
the vecmath.jar locally. The source code
(i.e., the javadoc) is in the jar, so if it isn't automatically
attached, you'll want to repeat the process above and attach the jar
as source. You might also want to browse the
vecmath
javadoc online.
Below you are asked to assemble a sequence of recorded frames
that demonstrate the required features of your program. You can do
this under Windows using virtualdub and an MPEG-4 /
H.264 codec (I suggest xvid). If you are using
Linux and do not have access to a Windows machine then please let me
know. Once you have both the codec and virtualdub installed, you
can create an avi file from a sequence of png still frames using the
following steps (you'll probably want to complete at least part of
the assignment and then come back to these steps later).
- In virtualdub, select "Open video file..." from the File menu
and choose the first image in the sequence (i.e., img00000.png).
This will automatically load the entire sequence
- The loaded images probably do not have a width and height which
are multiple of 16, so you'll need to add a filter. Under the Video
menu, select "Filters...", click Add, select Resize and click
OK.
- In the window that opens, there should be an option for
Codec-friendly sizing in the bottom right. Select "Multiples of 16"
and click OK. Now back at the Filters, click OK to close it.
- Now you need to set the codec. Choose
"Compression..." under the video menu and choose the codec you
installed (e.g., Xvid MPEG-4 Codec).
- The default configuration of the codec should be fine, but if
the files you are creating are too large, you can return to this
step and press the configure button to change the quantization
settings.
- Now you can save the image sequence to an avi file. Select
"Save as avi..." under the file menu and specify the file name,
then wait for virtualdub to finish encoding the file (it might need
a minute depending on the length of your video and the speed of your
computer).
The provided source code should help you get started quickly. It
has an interface for creating points and dragging them around. The
controls window lets to create a few different procedurally created
test systems and lets you adjust parameters stuff as stiffness,
damping, and step size. The main method lives in the A1App class, so this
is the one you'll want to start when running your program.
Note also the keyboard commands attached to
the drawing canvas that let you start and stop the simulation,
reset, and clear. There are also controls to help you save
sequences of png files. The important parts of the program,
however, are missing.
- Finish implementing the code that computes spring deformation
and viscous spring damping forces. See the Spring.java file
and the comment the starts with "TODO".
- Create getState and setState methods to get and set phase
space state of the system in a flat array. Use these methods
to write a forward Euler numerical integration method using
the Integrator and Function interfaces provided. See the
"TODO" comments in ParticleSystem.java in the updateParticles
and derivs methods. Also see the "TODO" comment in
the ForwardEuler class in the numerical package.
- Note that in some of the example systems, some points have
their pinned property set to true. Add a method to filter the
state (and forces) so that these simple constraints work
nicely with your numerical integration methods (both forward
Euler, and those in step 5).
- Modify the method you made in the previous step to also keep
particles inside the window by projecting them to the closest
boundary. For a particle in contact with a wall, a velocity
away from the wall is OK, but a velocity toward the wall
should not be allowed (the same for forces).
- Create classes that implement the Integrator interface for the
midpoint method, and the 2/3 point method (i.e., add classes to
the numerical package and use them in your particle system.
While you're at it, you
may optionally want to implement the fourth-order Runge-Kutta
method.
- Add keyboard controls so that you can switch between integrators
by pressing 1 through 3 (have a look at the "TODO" comment at
the bottom of the A1App class which adds the KeyAdapter to the
canvas). Automatically adjust the number of
sub-steps so that each step involves the same amount of work (i.e.,
number of calls to compute derivatives).
- Record a sequence of examples that demonstrate how these
different numerical methods perform. With the damping set to
zero find a step size which demonstrates which method performs
best. Also demonstrate which is best when the damping is not zero.
Encode the video as described above. Please keep your video
short (half a minute should be plenty) so that the size
of your compressed video to at most a few MB.
- Finally record a sequence of something interesting or amusing.
This could be something within the existing functionality of
the specification and provided code, or some additional
feature you add to your code. Encode the video as described
above. Keep your video short and to the point (i.e., at most
a few MB).
Complete the following written questions and submit a hard copy
in class on Tuesday January 27. Alternatively you can prepare a pdf
file with your answers (scanned hand written document, or generated
with latex, openoffice, or otherwise) and submit it with your
assignment via webCT (note the earlier deadline).
- Consider a one dimensional system consisting of a single
particle with mass 1 kg attached to a rigid wall with a
spring (100 N/m) and damper (10 N/m/s). If the particle
starts with zero velocity 0.01 m from rest (x=0), what is the
exact trajectory? What is the maximum step size that you
should use to numerically integrate this system with forward
Euler? How would you characterize (in words) the difference
between the exact and numerical solutions? Show your work,
and check your answer with your assignment code.
-
Great! Submit your source code and two xvid encoded videos as a
zip file via webCT. Include a readme.txt file with any specific
comments. Bring your answers to the written questions to the
class on the 27th, or submit them as a pdf via webCT. For both
parts, provide a list of people with which you discussed the
assignment.