Computer Science 4160 - Computer Graphics
Assignment 1
Spring 2008
Transformations
Due February 14, 11:59pm
Purpose
This assignment was designed with 2 main goals:
- Help you understand how viewing and other transformations are used to render scenes.
- To get you to compile and run an openGL program so you can make sure you have everything set up correctly for later assignments.
This assignment also gives you a chance to play around a little and
explore. In particular, the assignment skeleton is written in OpenGL.
While not absolutely required for this assignment, it would help for
later assignments (which will require extensive use of OpenGL) if you
could at least understand the framework (we'll discuss this briefly in
class) and you may also want to play around with it a little.
However, do note the submission requirements to not submit any
modifications to the main assignment framework.
General Information
This assignment will ask you to fill in the code to allow rotation of the viewpoint around a scene.
Post any questions you have to the newsgroup. Other students will
want to see the answers too. Do not post anything resembling
code.
Getting started
This assignment is only supported for windows. Specifically, it was created with C++ Visual Studio 6.0. Try to get access to a computer with this software. If you plan to use UNIX, start early so you have time to contact the system administrator about problems you encounter (such as setting up glut, or finding the directory where gl.h is located).
- You probably already have openGL set up on your computer. Search for gl.h to see if you have it. If not, go to www.opengl.org and follow the instructions on downloading the appropriate files.
- You probably don't already have Glut set up. If you want, you can
also find the download for that package from www.opengl.org.
Alternatively, you can download the three necessary files from glut.zip. You will have to set up your path to
point to the location of the dll. Note that some people have had
problems compiling the skeleton with the new glut version. The one in
the zip file should work.
- Download the assignment: HW1: Transformations.
- Unzip hw1.zip.
- Run hw1_solution_v2.exe. If you get an error message about glut32.dll, try adjusting your path, or simply copying it into the same directory.
- Compile and run the files as is.
- You should see the same teapot on a blue background, but the arrow keys won't work. Your job will be to make them work.
ONLY MAKE CHANGES TO Transform.cpp. Do not add any #include lines to the code. Do not change Transform.h. If you do make changes to any of the other files, make sure your solution works without those changes. You will only be submitting Transform.cpp.
The files nv_mathdecl.h, nv_algebra.cpp, nv_math.h and nv_algebra.h are provided as helper files. Don't worry about the details of these files. Concentrate on main.cpp. That said, You will probably have a much easier time if you look at set_rot().
Details
You will be implementing a classic crystal ball interface. This simulates a world in which the viewer is glued to the outside of a transparent sphere, looking in. The sphere is centered at the origin, and that is the direction towards which your eye is always pointing. At the origin, there is something interesting to look at -- in this case, a teapot.
You can change the viewpoint by rotating the crystal ball in any direction about the origin. Usually this is done with a mouse, but you will be using the keyboard for this assignment to make things easier. You must think about how the position of the eye and direction of the up vector change with left-right or up-down rotations.
Fill in the parts of Transform.cpp that say "//FILL IN YOUR CODE HERE". First, you should fill in left() and up(). Once these are working, fill in lookAt().
The compiled correct solution has been provided for you. Your solution must behave identically to hw1_solution_v2.exe. All you need to test this is to press the arrow keys a few times and toggle 'g' to make sure your lookAt() works.
You should play around with the solution to try and make the red and blue light line up by updating one and not the other (press 'h' when the solution is running). Also, you will have to answer a question in the submission email (see below).
Submission
You may submit more than once. Only the last submission will be graded.
When you are satisfied with you results, submit via email as described below:
To: cs4160@lists.cs.columbia.edu
From: [you]
Subject: HW1 - [your name]
Attachment: Tranform.cpp (do not include it as text. Make sure it's a separate file attachment.)
Body: Your name and email.
Describe why it is that the red light seems to provide more than just
a point light source, illuminating the entire half of the teapot,
while the blue light leaves most of the teapot dark, only illuminating
as a point source. The answer can be found in the red book (Woo 3rd Ed.), on
page 189 (4th ed, 5th ed, 6th ed = 195).
If you did not use Visual Studio on a Windows platform, please describe what you did to complete this assignment.
Documentation and Hints
We include below some optional documentation and hints that may be of
interest. You are not required to use or refer to any of the material
here, however. This mainly pertains to the material needed in
tranform.cpp Main.cpp is not very well documented; one goal is for
you to try to learn some OpenGL if you want to look at it in more detail.
- Helper Functions: In the course of modifying
Transform.cpp, you may want to make use of the helper classes and
functions from the nv libraries. These include vec3 for 3-vectors,
mat3 and mat4 for 3x3 and 4x4 matrices, normalize to set vectors to
unit norm, and set_rot to specify
rotations. You can consult the sources on these functions. If
you do choose to use these functions, one common gotcha is that
Matrices are assumed column major in the nv libraries
as opposed to the standard math convention of row major.
- Left: The simplest function to fill in is left. The
input is the degrees of rotation, the current eye 3-vector and current
up 3-vector. Note that you may need to convert degrees to radians (in
the standard way) to set up a rotation matrix. Your job is to update
the eye and up vectors appropriately for the user moving left (and
equivalently right). This function should not require more than about
3 lines of code to do the appropriate rotations.
- Up: The up function is slightly more complicated, but
satisfies the same basic requirements as left. You might want to make
use of helper functions like cross (get the syntax correct) and
auxiliary vectors. Again, you need to update the eye and up vectors
correctly.
- lookAt: Finally, you need to code in the
transformation matrix, given the eye and up vectors. You will likely
need to refer to the class notes to do this. It is likely to help to
define an x y z coordinate frame (as 3 vectors), and to build up an
auxiliary 4x4 matrix M which is returned as the result of this
function. Consult class notes and lectures for this part.
FAQ
- Development Environment?
The TA will use Visual C++ 2005 to compile and run your programs.
Please make sure it works with Visual C++ 2005.
- What if I don't have Visual C++ 2005?
You can apply for a CS account. It only costs $50 and after that you will
be able to get Visual Studio 2005 Professional edition for free
(directions).
If you insist on using other compilers, it is up to you to make sure the TA
can compile and run your hand-in "as-is".
- Where can I find resources of OpenGL lessons?
The website Nehe
provides useful lessons.