Search:

This is an old course web from 2008

W1 W2 W3 W4

# Old 2008 Course Web: Assignments / WrittenTransforms

## Transformations Written

Due Tuesday, October 14th.

You can turn in the hard copy by handing it to Blayne in class, or by leaving it in his mailbox on the 5th floor of CS. (Note: you need to have an access key to get to the 5th floor after hours).

If you type your answers, you can email them to Blayne (before the deadline) and he'll print it.

## Question 1

OpenGL provides a "rectangle" command that draws a rectangle in the XY plane (e.g. Z=0):

```    glRectf(float x1, float y1, float x2, float y2);
```

Give a function that draws a rectangle on the XZ plane (Y=0). It should use glRectf and some of the OpenGL transformation functions. You should not use glLoadMatrix (that is, you should build the transformations using the translation, rotation, etc. commands)

## Question 2

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 3

Similar to the previous question, but this time we want a coordinate system that places (0,0,0) at the upper left corner, and (640,480,0) in the lower right. We still want the positive Z axis to point forward (out of the screen) - this is no longer a right handed coordinate system.

Part A Write a sequence of OpenGL transformations (rotate, translate, scale) that achieves this.

Part B Give the 4x4 matrix from this transformation. Hint: its probably easier to figure out the matrix than to multiply the transforms from part A.

Part C: For this matrix to do the right thing, the initial transform on the matrix stack had to be the identity. If the matrix were the identity and we used the transformations from parts A and B, the following would draw a square in the center of the screen:

```    glRectf(310,230,330,250)
```

Suppose we "applied" this transformation twice (either we repeated the lines of code from part A or we multiplied the matrix from part B on top of the stack twice). Where would the rectangle command draw?

(you might notice that this is the bug in the sample code for the practice assignment)

## Question 4

Consider a 3D transformation M (a 4x4 homogeneous coordinate matrix) that is created by composing a rotation and a uniform scale. M maps the unit X vector to (0,1,1), and the unit Y vector to (0,1,-1).

Part A: Where does M map the unit Z vector to?

Part B: What is the amount of the scale used to make M?

Hint: You don't want to figure out what the angles of the rotation are. In fact, you might not need to figure out what the transformation is.

## Question 5

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.

History - Print - Recent Changes - Search