Programming Assignment 4
CS 45500
Computer Graphics
Fall, 2021

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

This assignment is based on renderer_6.zip and specifically on the sub-folder "aspect ratio examples" (which is also copied into the zip file).

In the demos sub-folder of the zip file there are two executable jar files, Hw4_Part_1_Demo.jar and Hw4_Part_2_Demo.jar, that you can run. Also in the zip file are two program files Hw4_Part_1.java and Hw4_Part_2.java. that you need to complete so that they run the same way as the two demo programs.

The two demo programs demonstrate two ways that a graphics program can react to a user changing the shape of the program's window. Each demo program, like the programs in the "aspect ratio examples" folder, is displaying a rotating wheel. The rotating wheel image has an aspect ratio of 1 and it starts out with dimensions 512 pixels by 512 pixels. When the user changes the dimension of the program's window (which is the same thing as changing the dimensions of the program's framebuffer) the issue is how the program should display the 512-by-512 wheel image in the new window. The new window might be larger or smaller than the original 512 pixels by 512 pixels. Should the wheel be magnified, or maybe letterboxed, into a larger window? Should the original image be scaled down, or maybe cropped, into a smaller window? If you crop the original image, which part of it is cropped off? If the image is letterboxed, where in the framebuffer is the letterboxing viewport placed (that is, where should the "empty" spaces go)?

To see some important answers to the last few questions, look at the source code to the examples Circle_v2_Letterbox.java and Circle_v3_Crop.java from the "aspect ratio examples" folder. In particular, notice that when we crop a source image, the part that we keep can be placed at nine different locations within the source image (think of a tic-tack-toe grid placed of the source image). Similarly, if we letterbox the viewport within the framebuffer, there are nine locations in the framebuffer where we can place the viewport (think of the same tic-tac-toe grid but placed this time on the framebuffer). If we are both cropping and letterboxing, then we could even choose different grid locations for the cropping of the source image and the letterboxing of the viewport, (though all of the given example programs use the same grid location for both cropping the source image and letterboxing the viewport).

The first demo program chooses to both magnify and crop the source image into the (whole) framebuffer. The program scales (either larger or smaller) the source image onto the larger dimension of the framebuffer, and the program crops the source image in the direction of the shorter edge of the framebuffer. This has the effect of using all of the framebuffer (no letterboxing) and preserving the aspect ratio of the source image (no distortion).

The second demo program crops the source image when the framebuffer is too small and the program letterboxes the viewport when the framebuffer is too large. The cropping or letterboxing is done in each of the two dimensions (horizontal and vertical) independently of each other. The cropping and the letterboxing use the same "grid location" (you can get a nice effect by having the letterboxing and the cropping use the "opposite" grid location from each other; try programming that).

In general, cropping of the source image is implemented using the projOrtho(double left, double right, double bottom, double top) method in the renderer's Camera class.

Letterboxing of a viewport is implemented using the setViewport(int x, int y, int wVP, int hVP) method of the renderer's FrameBuffer class.

There are two illustrations in the zip file that try to visualize the relationship between cropping, letterboxing, and the parameters to the projOrtho() and setViewport() methods.

Turn in a zip file called CS455Hw4Surname.zip (where Surname is your last name) containing your versions of Hw4_Part_1.java and Hw4_Part_2.java.

This assignment is due Tuesday, November 23.