COMP 557 - Fall 2009 - Assignment 1
Getting Started with OpenGL

Due 23:39 pm Monday 21 September

Getting Started

Since this is the first assignment, you'll need to spend a little bit of time to get set up. If you are not already using Java then download and install the latest Java SE JDK (careful not to select the JRE). I also recommend using Eclipse as a development environment. If you do use Eclipse as a development environment, make sure that the compiler compliance level is set to 1.6 (Project->Properties->Java Compiler).

Download the provided code and dump it into a new java project. Note that the code lives in the comp557a1 package, so when you create your project you'll want to create the comp557a1 package in your src folder before copying the file. Please do not change the package name, and likewise, add all your code to this one file (this assignment is small, so it should not be too messy living all in one file). The code uses JOGL for OpenGL bindings JOGL is available at https://jogl.dev.java.net/. Click on current release build (JSR-231 1.1.1a) and download the appropriate files for your platform. If on windows, download
  • jogl-1.1.1a-windows-i586.zip
  • jogl-1.1.1a-src.zip (to have access to javadoc in Eclipse)
  • jogl-1.1.1a-docs.zip (if you prefer reading javadoc in your browser)

To make your life more pleasant in Eclipse, you want to attach the source code to the jar for the javadoc. First add the jar to your build path, then open up Reference Libraries in your project, right click on the jar to set properties, go to source code attachment, and tell it where to find the zip file. Note that the .dll (or .so) that comes with the jar must be in your path. You can do this by opening the reference libraries in your project, right clicking to select properties, choose Native Library and enter the location of the .dll or .so file.

To complete this assignment you will likely want to use the vecmath jar for working with matrices, points, and vectors. The vecmath package is available as part of JAVA3D, but instead of installing the full Java3D, you can download just the vecmath.jar locally. The source code (i.e., the javadoc) is in the jar, so if it isn't automatically attached, you'll want to repeat the process above and attach the jar as source. You might also want to browse the vecmath javadoc online.

You may find the following links useful for documentation on OpenGL: The OpenGL Programming Guide (The Red Book) online version (or at Amazon), Jumping into JOGL, JOGL: A Beginner's Guide and Tutorial. Another popular resource is nehe.gamedev.net (see the NeHeGL JOGL link on the bottom right).

Objectives

The purpose of this assignment is to explore object space and world space rotations. The completed assignment will let you apply small incremental x, y, and z rotations to a wire frame cube. The provided source code should help you get started quickly. The file A1App.java contains the necessary source code to create an OpenGL renderer in a windowed frame. The a reasonable camera position and projection matrix is set up for you (see the display method). The code also contains TODO comments in the places where you will need to add code to complete the assignment objectives that are given below.

  1. Write code to draw the world axis using three unit length lines starting at origin along the X Y and Z axis directions. The color of the X axis should be red, the Y axis should be green and the Z axis should be blue.
  2. Write code to draw a cube with edge length 2 using the function glut.glutWireCube(1).
  3. Create a transformation matrix (i.e., vecmath Matrix4d), to map points in your cube object coordinates to world coordinates. Be sure to initially set your matrix to the identity, then use it when you draw your cube by changing the modelview matrix before drawing. Note that you'll need to repackage the contents of the vecmath Matrix4d into a double[] or DoubleBuffer before passing it to OpenGL, so be careful of the order in which you specify matrix entries.
  4. Draw a second axis in the cube's coordinates. Note that they will intitailly be aligned.
  5. The private variables "axisRotate", and "leftMultiplicationMode" are provided to let you control how to rotate the cube. These variables need to be updated given the following keyboard input:
    • Arrow Up: apply a small positive rotation about the current axis.
    • Arrow Down: apply a negative rotation about the current axis.
    • X: Set the default rotation axis to the 'X' axis
    • Y: Set the default rotation axis to the 'Y' axis
    • Z: Set the default rotation axis to the 'Z' axis
    • Space: toggle the left/right matrix multiplication mode.
    • R: Reset the accumulated transformation to the identity.
    Choose a small reasonable value for the angle update, for instance something between 1 and 5 degrees. The rotation should be accumulated. Note that M.mul(M,Rx) is generally safe with vecmath as it checks to see if you're passing the object itself as one of the arguments. Be sure to use the repaint method to request a redraw of the canvas after each keypress.
  6. Optional step: implement code to select between translation, scale, and rotation modes using they keyboard. Use 1 to select rotation, 2 to select scale, and 3 to select translation. Be sure to choose reasonable values for each type of transformation. Change the glutBitmapString call to also provide status of the current transformation mode. Explore how different combinations change the shape of the cube and the object coordinate frame.
  7. Written questions: Your written answers should be submitted as ASCII, pdf, or high quality jpg file (i.e., a scan or a photo of legible written work). Be sure to include your name and student number with your written questions.
    1. Which 3D transformations commute with themselves and with each other, that is, given two transformations A and B, when is AB = BA? Consider the following transformations: identity, translation, nonzero uniform scale, nonzero non-uniform scale, rotation, shear. Build a table or grid to show your answer, filling in only the lower triangle and diagonal.
    2. Show that a 90 degree 2D rotation can be created by composing a sequence of shears.

Finished?

Great! Be sure your name and student number is in the window title, and in the comments of the code. Submit your source code and written answers as a zip file via webCT. Include a readme.txt file with your comments. DOUBLE CHECK your submitted files by downloading them from WebCT. You can not recieve any marks for assignments with missing or corrupt files!

Note that you are encouraged to discuss assignments with your classmates, but not to the point of sharing code and answers. All code and written answers must be your own.