main-written2

This written homework is due Wednesday, October 14.

10/13/2009 - we have not fully covered viewing in class, so we have not discussed all that you need for question 3. so you can skip it. it is covered well in the books.

If you write out the assignment by hand, you can either give the paper to the TA in class, or place it in her mailbox on the 5th floor (remember, the elevators are locked after 5pm).

If you type your answer, you can email them to the TA.

The goal of this assignment is to make sure you understand the concepts from class that you will need for the programming assignment (coming soon). If you can’t do these simple examples, you may have a hard time writing code to do the operations on images.

Question 1

The standard OpenGL coordinate system (called “Normalized Device Coordinates”) put 0,0 at the center of the screen. Has X going to the right, Y going up, and Z coming out of the screen (its right-handed). The range along each axis is from -1 to 1 (so -1,-1,0 is the lower left corner of the screen). You get this coordinate system when you have the identity matrix atop the matrix stack (using glLoadIdentity).

Suppose we want a transformation that makes the lower left corner of the screen (0,0,0) and the upper right corner of the screen (640,480,0). (the Z values should not be changed). There is an OpenGL function called glOrtho for doing this, but we won’t use it in the this question.

Part A Provide a sequence of openGL commands that set up this coordinate system (it should be a sequence of translations, rotations, and scales).

Part B Reverse the order of the transformations in your answer to 2A. This program would give a different result. Change the parameters to the functions so that it gives the same transformation as in 2A.

Question 2

Here’s a little open GL function that draws a “house shaped” object that is articulated:

    void glHouseArm(float angle1, float angle2) {
        glPushMatrix();
        glRectf(0,0,1,1);
        glTranslatef(0,1,0);
        glRotatef(angle1,0,0,1);
        glRectf(0,0,1,1);
        glTranslatef(0,1,0);
        glRotatef(angle2,0,0,1);
        glBegin(GL_TRIANGLES);
        glVertex2f(0,0);
        glVertex2f(1,0);
        glVertex2f(.5,.5);
        glEnd();
        glPopMatrix();
    }

Part A: Sketch what this would look like if angle1 = angle2 = 0. What would the position of the tip of the triangle be?

Part B: Sketch what this would look like if angle1 = 90, and angle2 = 45. What would the position of the tip of the triangle be?

Part C: Write an equation that computes the position of the tip of the triangle given the two angles.

Question 3

Parts of this question were not covered in class before the assignment, so you do not need to do it for the assignment. Also, note that the original version of this assignment has an error in the camera matrix.

A vertex is drawn at the origin. It is viewed through a camera that is positioned with the viewing matrix:

1/2-1/20-2
1/21/20-2
0012
0001

The object that the vertex is drawn with transformation matrix:

0-102
1004
0016
0001

This simple projective transform matrix is used:

1000
0100
0001
00-10

Where does the point appear in screen coordinates? (give the x,y position)

Question 4

Consider a simple OpenGL like language/graphics system where there is a single drawing command DrawSquare that draws a unit (1x1) square with its lower left corner at the origin, Translate and Scale commands that concatenate the appropriate transform on the top of the matrix stack, and PushMatrix and PopMatrix commands that behave like OpenGL (or like we used on the board in class. A sample is given below.

Question 4A: Write a program that produces the picture here without using the push/pop commands:

Question 4B: Write a program that produces the same picture with push and pop commands. Write your program in a way that if you needed to change it to reposition one of the squares (without effecting the other two, or the sizes of any of them), you would only need to change one line of the program.

Page last modified on October 27, 2009, at 09:04 AM