


Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!



This project is meant to familiarize you with OpenGL, and see the rendering pipeline concepts and algorithms ‘in action’. First, you will need to read in a 3D triangle model. Its format is going to be the following. The first two entries will be integers, the triangle count and the vertex count. Then, there will follow a triangle table: a number of lines, each listing three integers (ID’s ov vertices bounding a triangle). Finally, there will be the vertex table: coordinates of all the vertices. For example, here is an input file that represents a tetrahedron:
4 4 0 1 2 2 1 3 2 3 0 0 3 1 0.000000 0.000000 1. 1.000000 0.000000 0. 0.000000 1.000000 0. 0.000000 0.000000 0.
The first two numbers say that you have 4 vertices and 4 triangles (mind the order!), the coordinates of the vertices are listed in the final 4 lines and the other lines tell you which triples of vertices bound a triangle. You will need to draw the model you have read in. We are not setting very strict requirements as to how to set the lighting conditions or viewing parameters (see below though); do whatever pleases your eyes, just make sure the image looks clean and you don’t do anything crazy like putting the light source inside the model or such. Also, make sure that in the initial image you draw the model shows up and it roughly fits inside the window. The center of the window should roughly overlap with the center of the object. One way to ensure this is to apply a transformation (translate and scale ) to the model so that the center of the bounding box of the model projects to the center of the screen and the entire bounding box is visible. The bounding box is the smallest axis-oriented paralleliped enclosing the model. To compute the coordinates of its center you can, for example, calculate the maximum and minimum x-, y- and z-coordinates of a vertex and then compute the average of the minimum and maximum x, minimum and maximum y and minimum and maximum z. After the program is started, a still image should be displayed. Here are the the first two specific things you have to do (see the Interface section for more) to get full credit:
The main part of the user interface will be a virtual trackball. Basically, the idea is to give the user the ability to grab (by pressing the left mouse button) an imaginary (invisible) ball centered at the middle of the displayed model and let her rotate it by moving the mouse with the left button down. Of course, the displayed model should rotate together with the ball. This requires proper handling of mouse events (see glutMouseFunc, glutMotionFunc).
You should be able to select the following items from a menu (just as in the enclosed code, the menu should be attached to the right mouse button):
lines Line mode: draw only the edges of the triangles
points Point mode: draw only the vertices
triangles Triangle mode: draw ‘filled’ triangles
toggle Gouraud/flat Toggle between Gouraud shading (smooth shading in OpenGL nomenclature) and Flat shading [see ‘normals’ section]
zoom in Zoom in a little (we want to be able to iterate this until we see just this little triangle in the middle!)
zoom out Zoom out a little (also here, we need to be able to iterate this)
W/M-fixed light - Toggle between light having a fixed location in the world and having a fixed location relative to the model
toggle orientation Switch from back-face culling to front-face culling and back; note that this is equivalent to reorienting all triangles [that’s meant to show the effect of wrong oriantation of triangles on the back face culling algorithm] For zooming in and out, I suggest changing the field of view in gluPerspective call. Although scaling the model may also be an option, it may be less conve- nient: you need to be careful about the model growing so big that it contains the origin or the front of it being clipped away by the front clipping plane. The current modelview matrix is applied to the light source location at the moment you specify it. This is the key to implementing the light behavior correctly.
in this ‘toy’ project, but if you were to sell your code to someone... I would advise doing this in software – see the writeup on trackball).
Late penalty: 3n−^1 , where n is the number of days late. Send your code (as a tarfile or gzipped tarfile) to the class email address. All files should extract to the current directory and compile by simply typing ‘make’. The name of the executable should be ’proj2’, and should read the input file from the standard input and provide a way of specifying the window size exactly like the provided piece of code. We’ll be running your programs like this: % proj2 < input file name We’ll use linux. Make sure your code compiles and runs on the lab machines. Programs that do not won’t get credit. We’ll run your code for the posted examples. Breakdown of the grade:
Most of the grading will be done by just running your code and trying things out. Make sure that the time between the code is started and the model shows up in your window is only about a few seconds and there are no delays when switching between modes etc. As always, we need to be able to see that something works to give credit for it. By ‘works’ we mean ‘works in general’, i.e. for all input models rather than just one or two. When grading the trackball, we’ll check if it gives reasonable immediate feedback (meaning reasonable refreshing of the view in response to the mouse- moving-with-button-down events) and if it is reasonably intuitive to use. Most importantly, the rotation direction/axis/angle should be naturally linked to the mouse cursor movement. You are welcome to discuss high-level implementation details or compare the output/interface of your code. However, you have to write the code yourself.