Programming Assignment 2
CS 45500 / CS 51580
Computer Graphics
Fall, 2024

This assignment makes use of the files contained in this zip file. This assignment is due Tuesday, October 22.

This assignment and your previous assignment are about the data structures used at the two ends of the 3D graphics rendering pipeline; what goes into the beginning of the pipeline and what comes out of the end of the pipeline. Roughly, what goes into the pipeline is the Scene data structure which describes the geometry of what the renderer should draw. What comes out of the pipeline is the FrameBuffer data structure which holds the pixel image of the scene drawn by the renderer. The previous assignment was about just the FrameBuffer data structure. This assignment is about what goes into the rendering pipeline, the Scene data structure.

For this assignment, you will define three Model data structures that can be used to build scenes. Then you will use your models to build a sequence of Scene data structures that can be given to the renderer to create a sequence of FrameBuffer data structures. You will then use the sequence of framebuffers to create a movie.

As we have said in class, a Scene is mainly a collection of models positioned in camera space. A Model is a list of vertices in 3-dimensional space (which we call "model space") and a list of line segments. Each Vertex contains three doubles (for the x, y, and z coordinates of a point in the model). Each LineSegment contains the (integer) index for two Vertex objects from the Model's vertex list. The vertices and line segments combine to form a wire-frame shape that we see as a geometric object in the scene. Each Model is combined with a Vector in a Position object. The vector is used by the renderer to translate every vertex in the model from "model space" to "camera space". This positions the model where we want it in front of the camera.

In this assignment you will be using renderer_4 which adds colors to the models. Read the Readme_r4_color.txt file from renderer_4.zip for an explanation of how colored line segments are added to a model. The main idea is that a Model object contains a List of Color objects (in addition to the List of Vertex objects). Each LineSegment object contains four integer indices. Two indices into the Model's Vertex list determine the endpoints of the LineSegment (as before), and two integer indices into the Model's Color list determine the color at each endpoint of the LineSegment.

Here is a sketch of what a Scene data structure looks like in renderer_4. Notice how a LineSegment object refers to two List objects. The first list holds two indices into the Model's Vertex list, and the second list holds two indices into the Model's Color list.

            Scene
           /     \
          /       \
    Camera        List<Position>
                          |
                          |
                          |
                       Position
                      /        \
                     /          \
                    /            \
               Vector             Model
               /  |  \       /---/  |  \---\
              /   |   \     /       |       \
             x    y   z    /        |        \
                          /         |         \
                List<Vertex>   List<Color>     List<Primitive>
                       |             |                  |
                       |             |                  |
                       |             |                  |
                    Vertex         Color             LineSegment
                    /  |  \        / | \            /           \
                   /   |   \      /  |  \          /             \
                  x    y    z    r   g   b    List<Integer>   List<Integer>

When you instantiate a LineSegment object, you give the LineSegment constructor four integer values.

   Primitive ls = new LineSegment(2, 3, 1, 0);

The first two integer parameters are indices into the Model's Vertex list. The last two integer parameters are indices into the Model's Color list.

In the zip file there are three java source files, P.java, N.java, and W.java. Each of these files defines a sub-class of the Model class (from the scene package). The file P.java is partly done for you. You need to complete it and the other two files so that each one defines a model that represents the letter of the alphabet the file is named after. You need to determine how many Vertex, Color, and LineSegment objects each model needs and then write the code that instantiates those objects and puts them into the model. Make each letter one unit tall (in the y-direction), one unit wide (in the x-direction), and a quarter unit deep (in the z-direction). Each letter should have its base line on the x-axis. The y-axis should touch the left side of each letter. The front face of each letter should be in the plane z = 0. The back face of each letter should be in the plane z = -0.25. Look at the supplied animation to see how each model's line segments should be colored.

If you want to see examples of Model classes, look at the files in the models_L package in renderer_1.zip. In particular, look at the files Square.java, Circle.java, Cube.java, and Tetrahedron.java, because those are the simplest models.

To see some examples of creating a Model with colored line segments, look at the files InteractiveTriangle_R4.java, InteractiveCube_R4.java, or ThreeLines_R4.java in the clinets_r4 package in renderer_4.zip

After you have defined your letter models, complete the program Hw2.java that uses your letter models to create an animation that looks like the file Hw2_animation.gif from the zip file. Your letters do not have to be shaped exactly like my letters, but they should be colored the same way.

After you have defined your letter models, and before you actually start to work on the animation, write code in Hw2.java that just creates the initial frame of the animation. The three letters should initially have their front faces in the plane z = -1.5. The plane z = -1.5 intersects the camera's view volume in a square that is 3 units wide and 3 units tall (the view volume, in the z = -1.5 plane, extends from -1.5 to 1.5 along the x-axis, and from -1.5 to 1.5 along the y-axis.). This square is just wide enough to place the three letters next to each other. First place the three letters next to each other with the x-axis running through the middle of each letter. After you get this image, translate the P up so that it just touches the top of the view volume and translate the W down so that it just touches the bottom of the view volume. That should give you the correct initial positions for the three models. (See the first frame from the sub-folder hw2\animation-frames.)

Your code should move the models by modifying the Vector object associated with each Model object. If we look at the letter P in the animation, it moves 2 units right, then 2 units down, then 2 units left, and finally 2 units up. This brings the P back to where it started, so the animation can cycle through the frames to create a continuous loop. The letter W in the animation moves 2 units left, then 2 units up, then 2 units right, and finally 2 units down. This brings the W back to where it started. You should write the code that moves just the P and W letters and get them both correct. After P and W are correct, you can work on the N letter.

If you want to see examples of how to move models in an animation, look at the files OfflineCube.java, OfflineCubes.java, and OfflineMovie.java in the clients_r1 package in renderer_1.zip.

The letter N moves just backwards and forwards. It moves backwards for 100 frames and then moves forwards for 100 frames. To make your letter N move like the one in the animation, move your letter by 0.02 in each frame.

You should not change the package structure of the folder hw2. The files Hw2.java, P.java, N.java, and W.java are in the default package of the folder hw2. All the renderer classes are in the renderer_4.jar jar file. The included build script sets the classpath appropriately.

After you have Hw2.java working, convert the image frames that your program produces into a real "animation" file. To do this you need to download the following zip file and unzip it to your C:\ directory as the folder C:\ImageMagick-7.1.1-39-portable-Q8-x64.

ImageMagick-7.1.1-39-portable-Q8-x64.zip

After you have ImageMagick on your computer, and after you run your program to produce all the animation frames, just double click on the command file ImageMagick-7.1.1-39-portable-Q8-x64.cmd and it should use your frames to create an animation file called animation.gif. Double click on your animation file to see your movie.

Turn in a zip file called CS455Hw2Surname.zip (where Surname is your last name) containing your versions of P.java, N.java, W.java, Hw2.java, and animation.gif. Please do NOT submit the frames for your animation.

This assignment is due Tuesday, October 22.