Hey, what about OpenGL?
Programming exercise 3
Learn OpenGL :-)
Implement an interactive 3D viewer similar to the one in your previous
assignment, but with hidden surface removal and shading, using the OpenGL
API. Here are the specifications:
- The program is invoked with two file names. The first file contains
the 3D object to be viewed. The second file contains the viewing and screen
parameters.
The format of these files is as follows (the // indicate explanatory comments
not in the file; words in boldface appear as they are):
object file (ending with .msh):
Object name // the name of the object, one word
Diffuse r g b // this is the diffuse material color for the object.
r,g,b are in [0,255]
Specular r g b n // the color of the specular highlights and the
specular exponent
n // n is the number of vertices (integer)
V0x V0y V0z N0x N0y N0z // vertex coordinates + vertex normal (real numbers)
...
V(n-1)x V(n-1)y V(n-1)z N(n-1)x N(n-1)y N(n-1)z
m // m is the number of triangular faces (integer)
t00 t01 t03 // vertex numbers (integers)
...
t(m-1)0 t(m-1)1 t(m-1)2
k // k is the number of quadrilateral faces (integer)
q00 q01 q03 q04// vertex numbers (integers)
...
q(m-1)0 q(m-1)1 q(m-1)2 q(m-1)4
view file (ending with .viw):
Camera cx cy cz // world coordinates of the camera position (real
numbers)
LookAt lx ly lz // world coordinates of the center of interest (real
numbers)
Up ux uy uz // the "up vector" (real numbers)
Fov a // horizontal field-of-view angle in degrees (real number)
Resolution w h // width and height of screen window in pixels (integers)
Arcrad r // The radius of the arcball in pixels (integer)
Lights n // The number of light sources to be used
L0x L0y L0z L0w // light source position (or direction, if 4th coordinate
is 0)
...
L(n-1)x L(n-1)y L(n-1)z L(n-1)w
Exercises which will not handle the formats correctly will not be graded.
Note the changes from the previous assignment: the incorporation of object
color, a normal for each object, and the light sources. When the coordinates
of the normals of all vertices of a face are all zero, it means you should
compute a normal to the whole face.
- The program opens a screen window of size (w,h) and displays the 3D
object in this window.
The object should be displayed with shading and hidden surface removal.
- If no view file name is given, the program automatically computes an
appropriate view and uses it. The view is such that the object is fully
seen from its widest side and occupies about 3/4 of the screen window.
Hint: use the mesh's bounding box.
- The program should also find a pair of good clipping planes for the
view.
- The program enables the user to:
- interactively rotate the object by manipuationg the arcball with the
left mouse button.
- interactively zoom in/out using the middle mouse button (dragging the
mouse up zooms in).
- interactively pan the camera using the right mouse button (both Camera
and LookAt are translated by a vector parallel to the viewing plane).
- Double buffering should be used for smooth object motion.
- Clicking the `r' key resets the view to its initial state.
- Clicking the `q' key terminates the program.
- Clicking the `x', `y', and `z' keys constrains the arcball motion to
be around the screen's x, y and z axes, respectively. These clicks operate
as toggles (i.e., the next click on any of them gets out of constrained
mode).
- You should create interesting object files and submit them with your
program.
- Use a clear, well modularized programming style. There is no need for
code documentation, only in special cases. Provide a short documentation
for each module.
The exercise should be submitted by the beginning of the targil on January
7. All the files should be in a directory ~you/graphics/ex3. The directory
should also contain a README file saying who are the people submitting
the exercise, which files are there, and document any modifications you
have made to the specification.
We are aware of the fact that this specification may be incomplete.
If you have any questions or problems, e-mail them to cg, and stay tuned
to future modifications and corrections.