This assignment makes use of the files contained in this zip file. This assignment is due Thursday, December 7.
This assignment has two parts. The first part is based on renderer_7.zip and specifically on the sub-folder "clients_r7\aspect_ratio_examples
". The second part is based on renderer_9.zip and specifically on the sub-folder "basic_transformation_examples
".
For the first part of this assignment you will write code that uses the Camera
API introduced in renderer_7 to handle changes in the program window's size and aspect ratio. For the second part of this assignment you will use the linear transformations from renderer_9 to create an animation of the letter models from hw2.
In the zip file there is an executable jar file, hw4_demo.jar
, that you can run. Also in the zip file is a program file, Hw4.java
, that you need to complete so that it runs the same way as the demo program.
Play around with the demo program quite a bit to get a sense of what your code should implement.
For the first part of this assignment you need to write code that reacts to the user changing the size and aspect ratio of the program's window. As the user changes the program's window, the program should keep the origin of the scene centered in the program's window and the scene's image should always remain undistorted (the circle should always appear circular and not elliptical). When the user makes the program's window smaller than its initial size, the program should crop the scene's image. When the user makes either of the program window's dimensions larger than their initial size, the program should scale the scene's image larger. Notice that your program never needs to do letterboxing; the framebuffer's viewport will always be the whole framebuffer.
When the program starts up, the dimensions of the window are 800 pixels wide and 400 pixels high. We will refer to those as the window's reference dimensions. When the program starts up, the view-rectangle in the camera's image plane has the boundaries left = -2
, right = 2
, bottom = -1
, and top = 1
. If the user makes the program window's dimensions both less than the reference dimensions, then your program should crop the image in the view-plane by adjusting the camera's view-rectangle. If the user makes either window dimension larger than its reference dimension, then your program needs to combine scaling and cropping to make the image fill the viewport (without any distortion).
For the second part of this assignment you need to use model-to-world transformation matrices on the P, N, and W letter models to create an animation.
In the renderer_9.zip zip file there is a sub folder "basic transformation examples
" containing several examples using translations and rotations to create animations. Build the Javadoc for that folder and open the html
sub-folder's index.html
file using a web browser. The Javadocs combine each example's explanation with it animated gif file.
Also look at RotationExample.java
from the clients_r9
sub-folder of renderer_9.zip.
Here is the most important thing to remember from those examples. If you want to rotate a model around the point (a, b, c)
in the model's coordinate system, and you want this rotation to happen at the point (u, v, w)
in the world coordinate system, then you would do that with the following three transformations (where position
is the Position
object holding the Model
object).
position.transform( Matrix.translate(u, v, w) .times( Matrix.rotate_(theta) ) // choose any axis .times( Matrix.translate(-a, -b, -c) ) );
The two parts of this assignment are completely independent of each other. You can solve them in ether order. For the first part, I think you should first get it working for windows that are strictly smaller than the reference window; that only involves cropping. When the program window is larger (in either dimension) than the reference dimensions, you need to consider two cases, when the window's aspect ratio is more, or less, than 2.0 (the aspect ratio of the reference dimensions).
For the second part, the rotations of the three letters are completely independent of each other. So work on one letter at a time.
Turn in a zip file called CS455Hw4Surname.zip
(where Surname
is your last name) containing Hw4.java
, P.java
, N.java
, and W.java
.
This assignment is due Thursday, December 7.
Here are references to some relevant classes in the Java API.