CPSC 424, Computer Graphics, Spring 2010
Lab 1: Geometric Transforms


For the first lab of the semester, you will write two programs in Java. The first program is more of a warm-up exercise in which you will apply geometric transforms to achieve certain specified effects. Hopefully, you will finish the first program during the lab period. The second assignment asks you to use hierarchical modeling to create an animation simliar to the one in Subsection 1.3.2 of the notes.

The programs from this lab will be due in two weeks, before the start of lab on Thursday, February 9. (Note that Lab 2 will not be a programming lab and will probably be due at the same time.) You should copy your programs into your homework directory in /classes/s10/cs424/homework. I will also expect you to have an applet version of the second program on your CS424 web site. (The next lab will have more information about creating this web site.)

For this lab, you can use any Java development environment that you like, whether it's Netbeans, Eclipse, or even the command line. You will need copies of all the files in /classes/s10/cs424/lab1-files: Transforms.java, Lab1Animation.java, Lab1Applet.java, and iss.jpg. You should add copies of all these files to the project or directory where you are working.


Part 1: Transforming a Picture

For the first programming assignment in this lab, you will work on Transforms.java. This program loads the image iss.jpg and uses it in a basic picture that looks like this:

The program has a method

private void basicDraw(Graphics2D g2)

that draws this picture. This method draws the picture with its upper left corner at (0,0). The picture is 200-by-150 pixels, and its lower right corner is at (200,150). Of course, if a transform has been applied to the graphics context g2, then the shape, size, and orientation of the picture that actually appears on the screen will be different.

The program that you have been given draws one copy of the basic picture on the screen. Your assignment is draw eight more copies, with certain transformations. When you have finished, the program's window should look like this, or at least as close as you can make it:

(The full size image is twice as large as the version shown here.)

The program's window is 900 pixels wide and 750 pixels high. It is divided into nine 300-by-250 pixel rectangles. Each rectangle holds a copy of the basic picture, subject to different transformations. The starter program draws the version in the upper left rectangle. This version is already subject to a transformation, since it has been moved over 50 pixels and down 50 pixels from its natural position. In the program, this version is drawn with the commands

                g2.translate(50,50);
                basicDraw(g2);
                g2.setTransform(originalTransform);

The last line restores the transform in g2 to whatever it was before the translation was applied, presumably the identity transform. You need to do this after each picture that you draw, so that the transforms that you apply to one picture don't affect the following pictures.

You should make sure that you understand the various types of transform covered in Subsection 1.3.1. You should remember that transformations are applied to a picture in the reverse of the order in which they are specified in the code. And, to make things easier on yourself, you should remember this hint: It is usually easier to understand the effect of a rotate, scaling, or shear transformation if (0,0) is at the center of the object that is being transformed. Since the center of this picture is (100,75), not (0,0), you might want to move the center to (0,0) first, then apply a transform or two, then move the center back to its original position or to the point where you want it to be in the end.


Part 2: Animation through Hierarchical Modeling

This lab's second programming assignment is open-ended. You should create an animation using hierarchical modeling. The requirement that the modeling be hierarchical means that you must have objects that have moving parts, and those objects must then be subject to further transformation. Using several levels of hierarchy would be nice, but is not required. A picture that looks like something is preferred, but a well-done, complex abstract animation could also be acceptable. You should spend time on the animation. Try to produce something that is reasonably complex, looks nice, and is original.

You can use Lab1Animation.java as a start. This program shows a very simple animation of a triangle and a rectangle (which you should remove). There is nothing hierarchical about it. The program uses a real-number coordinate system with (0,0) at the lower left corner and (7,5) at the upper right, but you are not required to use the same coordinate system.

You can also look at the example from Subsection 1.3.2 to get ideas. A reduced-size copy of the applet from that section is shown below, and the source code can be found in HierarchicalModeling2D.java. You will want to write subroutines that draw individual objects in their natural coordinate systems, as is done in this example.

The file Lab1Applet.java can be used to put an applet version of your program on a web page. You won't have to make any changes to it, and you won't need it until you start work on your web site.

Some ideas for things that you might add to your animation: A sun with rotating or pulsing rays that moves across the sky. Something like a ferris wheel (which is s a little tricky, since you have to make the seats not rotate as the wheel goes around). A cart (or parade float) that carries a TV that is showing a simple animation. A double pinwheel that has a rotating rod with a rotating pinwheel on either end. An airplane with a stick-figure waving pilot. Anything else that you can think of.


David Eck for CPSC 424