Glass Ball Interface
ECS175: Computer Graphics
Due 10:00pm, Mon. May 21


You may do this project with a partner.

This project will help you familiarize yourself with three-dimensional modeling and viewing, animation and user input, and shading. Focus first on the mechanics of viewing and interaction, and then add shading, and finally try it with an interesting model. A program which allows the user to correctly rotate a simple model, with correct normal vectors, is worth a B+. A few extensions worthy of an A are described at the bottom of this page.

Starting off

Here is a program that creates and displays an icosahedron, to start you off. It includes a perspective projection. The vertex colors are determined by the vertex positions.

The glass ball

Now allow the user to move the icosahedron around using the "glass-ball" (aka "arc-ball") user interface. This applet uses the "glass-ball" interface, so you can see how it works. The idea is that we imagine the object to be embedded in a clear glass trackball. When you hold down any mouse button and move the mouse, it spins the glass trackball, and the object along with it. Notice that the object rotates around an axis perpendicular to the direction that the mouse is moving. Moving the mouse with the buttons released does nothing.

You'll need to specify the callback routine for mouse motion. The way you tell the glut you have such a routine is using glutMotionFunc(). Look this up in the on-line glut documentation. This function will get called many times as you move the mouse in the window with the button down. Each time, you'll want to rotate the icosahedron by a little bit.

Now write the callback routine to implement the glass-ball interface. You'll have to figure out what axis to rotate around, and how to use the difference between the new and old x-y positions of the mouse to determine how much to rotate. Try and refine the feel of the interface so it really seems like you're moving the icosahedron with the mouse. Usually you see a "jump" at the beginning when you start moving. To fix this, you'll also need to specify a callback using "glutMouseFunc()".

Add normals to the vertices and implement lighting

In this section you'll be editing the vertex program. Start by making all the vertices white. The picture should be a lot less interesting after that. To make it look 3D, we'll specify a normal vector for every vertex, and use lighting based on the normals to pick the vertex colors. A great thing about the icosahedron is that its vertex positions can also be used as its normals! So go ahead and do that.

Use a directional light coming from direction (1,1,2). This would be roughly behind the viewer's left shoulder, which is traditional.

Read the example "Lighting in a Vertex Shader" in Chapter 8 of the OpenGL ES book, pages 160-163, for an example of coloring the vertices based on their relationship to the light source. Just calculate a diffuse and ambient color for every vertex. More on the theory of diffuse and ambient lighting is in Sections 10.1.1 and 10.1.2 in the textbook (9.1.1 and 9.1.2 in the second edition).

Load in a more interesting model

Here is some code which reads in data from a file in the the 3D .obj format (taken from tutorial 6 in the Wikibook). NOTE: changed on 5/16 so it can read big models like the lion, below. And here are some models that can be read properly by that code. The function load_obj(const char*, Mesh*) reads in a file, specified in the first argument, and loads it into an object specified by the Mesh class. It also computes normals for all the vertices, by averaging the triangle normals of the triangles which share the vertex.

You should check the min and max x,y, and z positions of a new model, to figure out how to scale and translate it so that it lies in a cube centered at the origin, and extending from (-1, -1, -1) to (+1, +1, +1), which is where the icosahedron is.

Optional improvments

Here are some ideas for improving the basic assignment.

Documentation and handin

Write a README file including a) your name, b) how to compile and run your program, and c) a few short paragraphs on what you did. If you use any code you found on the web, please note that in your documentation, and also the source of the model you used.

Turn in the source file of your program, the Makefile, the model you used, and the documentation, but NOT the executable. You do not need to to hand in glm, or shader_utils. Handin to cs175t hw3.

Programs that do not compile and run in Kemper 71 will get a zero!!!