Comp 613 Lab Assignments Spring 2012

Comp613 Computer Graphics Laboratories

Submitting labs

Each lab is submitted as a single word document. Lab submissions contain the following:

  1. A statement of the problem
  2. Program design artifacts such as structure charts, UML class and interaction diagrams, pseudocode, flowcharts, etc. (if used)
  3. The code you wrote. (Not generated files)
  4. Some screen captures. These must be compressed. You can use a tool such as MWSnap.

Lab 1 Getting started with Android OpenGL development

1)  Install Android SDK and eclipse plug-in

2)  Follow the tutorial at http://developer.android.com/resources/tutorials/opengl/opengl-es10.html as far as getting a triangle to appear.

3)  Modify your program to draw your initials. You can use GL_LINES

Lab 2 Polygons

1)  Enter the polygon program done in class.

2)  Modify the program to show the interior triangulation.

3)  Add rotation to the polygon.

4)  (optional) Modify the program so that dragging your finger in a southeast direction speeds the rotation, in the northwest direction slows it.

Lab 2a Drawing Simple 2D Figures (taken from David Breen). Extra Credit (5 Points) due Sep 22

Create the following picture:


Use the glColor3f, glBegin(GL_POLYGON), and glVertex functions to create each of the shapes.

The Circle: use the parametric equation of a circle to create multiple vertexes in a polygon. The parametric equations is:
y=sin( angle )
x=cos( angle )
You will need to step the angle between 0 and 2*pi to draw the circle. You can scale and move the circle by multiplying the coordinates and adding offsets to them. Vary the red color by the step of pi to get the shading effect.

The Ellipse: For the ellipse, use the same equation but scale the y down to 60% .

The Square: For the square, draw multiple squares on top of each other, varying the color from black to white. Its a good idea to base the square off of an angle, making the first point at pi/4, and then every pi/2 after that (this will help in the next assignment).

The Triangle: Its a good idea to use angle to draw the points here too.

The window should be 500x500 pixels.

Lab 3 Tessellating triangles

1)  Enter the Sierpinski gasket program

2)  Devise a way for the user to enter the depth of the recursive calls. One way would be adding a menu (settings?) option to bring up a dialog view. You could add a slider to the view which stopped only at integer values.

1)  Add modifications to draw the small triangles filled with color. Vary the color in interesting ways so as to create a quilt-like image.

2)  Add some twisting action. Let the user specify the amount of twist using a second command argument. Twisting of a point is relative to its distance from the origin. Here is some code to twist vertex v0 by an angle in radian measure of twist*d where twist is specified by the user..

d = sqrt(v0[0]*v0[0] + v0[1]*v0[1]);//@mw

v0[0] = cos(twist*d)*v0[0] - sin(twist*d)*v0[1];//@mw

v0[1] = sin(twist*d)*v0[0] + cos(twist*d)*v0[1];//@mw

It uses the 2D distance formula and the trigonometry formulas for rotating a point (x,y) by angle θ.

x’ = x cos θ – y sin θ

y’ = x sin θ + y cos θ

Lab 4 Snowflake Fractals

Write a function to draw a 2D fractal snowflake (Koch curve). See Wikipedia. Start off by writing a recursive function to draw a side.

void side(int n, float x0, float y0, float x1, float y1);

When n is 0, it simply draws the line from P0(x0,y0) to P1(x1,y1).

When n > 1, it calculates the coordinates of 3 new vertices, P2 and P4 are 1/3 and 2/3 of the way down the line from P0 to P1. P3 is found by calculating the midpoint of P0,P1 and offsetting it by a perpendicular distance of Ö3/6. The side function calls itself recursively, decrementing n to draw 4 sides.

After you have tested the side function, create a triangle function. It takes an int n, and the coordinates of 3 points as parameters, and calls the side function 3 times, passing n and 2 points.

Here is a sample output with n = 3:

Once you have your Koch snowflake debugged you may wish to try animating it by progressively increasing the n from say 1 to 5.

Lab 5 3-D Modeling

1)  Draw a cube using different colors for the sides and view it from a perspective projection.

2)  Add a tetrahedron

3)  Add a sphere

4)  Tapping the screen should change shapes

Lab 6 Model transformations

1)  Write a program to draw a solid arrow in 3-D.

2)  Allow the user to initiate model rotations by swiping and elongations by pinching or extending the fingers.

Lab 7 Lights and Materials

1)  Improve the solid shapes created in Lab 5 by adding lights and coating the surfaces with materials.

2)  (optional) Allow the user to move the camera around. (I’m not sure how to do this)

Lab 8Textures

Make a walk-through photo gallery. Take some digital pictures including one of yourself. Using photo software, crop them to a square size and save as a bitmap file. The sides must be a power of 2, such as 256 by 256. Build the gallery using a couple of rooms and doorways. Hang the pictures on the walls using texture mapping. Set up adequate lighting. Walk the camera through the gallery as in Lab 7. Nehe Lesson 10 for guidance on how to do all this on a computer.

Lab 9 Hierarchical Model

Study the Robot program at http://www.gamedev.net/reference/articles/article1267.asp.

Then adapt the program to work on the android platform.

Lab 10 Bezier Curves

Write a 2-D program that allows the user to tap 4 times creating 4 points. A Bezier curve is then drawn through the first and last points with the middle points acting as controls. Once the points are up the user can drag them pulling and pushing the curve in various directions. There should be a key to clear the points.

Lab 11 Molecular Visualization

This lab will involve VMD , a system for visual molecular dynamics using OpenGL.

1) Download and install VMD.

2) Locate the tutorial VMD Molecular Graphics by Jordi Cohen, Marcos Sotomayor and Elizabeth Villa.

3) Follow the Basics of VMD part of the tutorial. You will need to download the ubiquitin 1UBQ.pdb molecule. It may be found at http://www.ks.uiuc.edu/Training/Tutorials/vmd/vmd-tutorial-files/

or at The Protein Data Bank.

4) Alternatively, simply type 1UBQ.pdb into the file name box of the loader and press load.

5) Submit evidence of having done the lab. Include a screen shot of ubiquitin with one amino acid highlighted using the Analysis | Sequence Viewer. Select the amino acid matching your first initial, i.e. if your initial is “J”, the 10th letter in the alphabet, highlight the 10th amino acid. Also submit a 1-page summary of you experience using VMD.

Revised last on 1/11/2012 1 Prof M Werner