This assignment makes use of the files contained in this zip file. This assignment is due Monday, November 17.
For this assignment, you will implement a simple event driven GUI program that combines our 3D renderer with the Java GUI framework.
In the zip file there is a program Hw3.java that you need to complete. Also in the zip file is a runnable demo program hw3_demo.jar that you can run (on Windows) by double clicking on hw3_demo.cmd. On Linux or Macs (and also on Windows) you can run the demo program from the command-line with this command.
> java -jar hw3_demo.jar
Play around with the demo program quite a bit to get a sense of what your code should implement.
Carefully read the code in Hw3.java to understand the outline of what you need to write. Think in terms of the Model-View-Controller (MVC) design pattern. Notice how the program's outline specifies code for each of the Model, the View, and the Controller. The Model part of MVC is pretty much complete in Hw3.java. You need to implement about half of the View part (the GUI components) and most of the Controller part (the event handlers).
You need to implement two (broad) steps. First, create all the GUI components needed by the program and add them to the appropriate GUI containers. Second, define event handlers for all of the GUI components.
If you compile and run the Hw3.java program from the zip file, you will see that it produces a window (a JFrame) containing a framebuffer with a GUI panel below it. The framebuffer should display a blue sphere. In the GUI panel below the framebuffer, the model combo box should work and let you change the model displayed in the framebuffer. However, the other GUI components in the bottom panel do not do anything yet (you need to implement their event handlers). Also, the window is missing a GUI panel along its right edge (the east panel). You need to create GUI components and add them to the east panel so that the window looks like the demo program. Then you need to add event handlers for each of the GUI components.
When you implement the east panel, notice that the panel object is already defined for you in Hw3.java as a Box
container. The Box container has the ability to equally space its components vertically in the container. (A standard JPanel with a BoxLayout manager would bunch all the components together at the top of the panel.) To get the Box container to equally space its components, you need to put glue into the container between the components (specifically, vertical glue). Write your code in small steps. Compile and run your program after you create and add each component to the east panel. It is easier to debug one small step rather than debugging seven or eight steps with an unknown number of errors in them.
After the GUI looks correct, start to implement the event handlers. The event handler for the model combo box is implemented for you. You need to implement all the other event handlers. Start with simple event handlers.
scene object to the console window.Camera modes.
Then make the "Screenshot" button save the FrameBuffer as a PPM file. Look in the clients_r2 folder from renderer_2.zip for the file InteractiveModelsAll_R2.java. It implements a "screenshot" feature using the '+' key command.
Write the event handler for the color combo box (use the model combo box handler as a guide). The color combo box event handler should translate the selected name in the combo box into an integer value and store that value in the colorChoice field (which is part of the Model in MVC). Then the updateGUI() method (which is the View in MVC) should use the colorChoice value to select an appropriate (static) method from the utility class renderer.scene.util.ModelShading. That class in the renderer contains static methods for shading models in a number of different ways. Read the Javadocs for renderer_2 for the API to the ModelShading class.
Write the event handlers for moving the model. Moving the model involves both the axis radio button group and the slider. The three radio buttons should share a single ActionListener event handler and the slider needs its own ChangeListener event handler. There are four variables in the MVC's Model to help you manage this, currentAxis, xAxisSliderValue, yAxisSliderValue, and zAxisSliderValue. The radio button group sets the value of the currentAxis variable. Then when the slider gets changed, the slider uses currentAxis to know which axis variable it should assign its current slider value to.
Notice one important detail in the demo program. When the user clicks on an axis radio button, the slider adjusts itself to that axis's last slider value. That is, the slider should remember the last slider value for each axis. The axis button group's event handler needs to update the appearance of the slider component (by using the setValue() method in the JSlider class).
After these event handlers (which are part of the Controller in MVC) update the four slider variables (which are part of the Model in MVC), then the View needs to use the x, y, and z slider values to translate the Scene's Model. (Notice that we have both a Model class in the renderer and a Model in the MVC pattern; they are not the same thing!) The slider values are always integers between 0 and 100. The View (which is the updateGUI() method) needs to convert the x, y, and z slider values into camera coordinates for the position's translation vector. Here is how that translation should be done.
The updateGUI() method should put the converted translation values into the translation Vector of the Position that holds the Model.
Finally, make the "Clipping" checkbox turn on and off the renderer's line clipping. You need to be able to move a model past the left or right edge of the framebuffer to see the effect of clipping.
According to the Model-View-Controller design pattern, the event handlers are part of the Controller and their job is to update variables in the Model. The Model, in this program, is the collection of instance variables in the Hw3 class; in particular, notice that the scene object is part of the Model. After the Controller updates the Model, the View is supposed to take over and update the GUI. In this assignment, the View is the method updateGUI(). So most of the event handlers should update some Hw3 instance variable and then end with a call to updateGUI(). But not all of the event handlers fall into this pattern. For example, the "Information" button does not really have any affect on the Model or the appearance of the GUI. It just prints the scene object to the console window. So the "Information" button can be thought of as not being part of the MVC pattern. What other event handlers are not really part of the MVC pattern?
The event handler for the combo box of model names is written for you in the clients_r2 folder from renderer_2.zip. You can write your event handlers in any of these styles.
Remember, do NOT try to write all the code for this program and then start to debug it. That will not work. First get all the GUI components in the right place (without any event handlers). Then get one event handler at a time working. Writing event handlers is not easy. Debugging multiple event handlers at once is extremely difficult and foolish since you don't have to write your code that way.
You should not change the package structure of the hw3 folder. The files Hw3.java and ModelList.java are in the default package of the folder hw3. Do not give those classes a package statement. All the renderer classes are in the renderer_2.jar jar file. The included build script, build_&_run_client.cmd, sets the classpath appropriately.
Turn in a zip file called CS455Hw3Surname.zip (where Surname is your last name) containing Hw3.java, ModelList.java, and any other files that you created as part of your solution.
This assignment is due Monday, November 17.
Here are references to relevant classes in the Java API.