Week 4 Tutorial
Question 1:
Consider the following OpenGL code:
public void display(GLAutoDrawable drawable) {
GL2 gl = drawable.getGL().getGL2();
gl.glClearColor(1.0f, 1.0f, 1.0f, 1.0f);
gl.glClear(GL.GL_COLOR_BUFFER_BIT);
gl.glColor3d(0.0, 0.0, 0.0);
gl.glMatrixMode(GL2.GL_MODELVIEW);
// #1
gl.glLoadIdentity();
// #2
gl.glRotated(30, 0, 0, 1);
// #3
gl.glScaled(-2, 2, 1);
// #4
gl.glTranslated(1, 0, 0);
// #5
gl.glBegin(GL2.GL_POLYGON);
{
gl.glVertex2d(1, 1);
gl.glVertex2d(1, 2);
gl.glVertex2d(2, 1.5);
}
gl.glEnd();
}
- What is the coordinate frame at each of the lines marked #1 to #5?
- What is the value of the model-view matrix at each of these lines?
- What are the global coordinates of the three vertices of the polygon (in homogeneous coordinates)?
Question 2:
Consider the 2D tranformation matrix:
[ 1 -1 1 ]
[ 1 2 2 ]
[ 0 0 1 ]
- Is this matrix affine? Why/why not?
- What are the axes of the coordinate frame it represents? What
is the origin? Sketch it.
- What is the scale of each of the axes?
- What is the angle of each of the axes?
- Does this transformation have a shear component? Why/why not?
Question 3:
Consider the scene graph below:

Note: If this is taking too long and people are already comfortable
with matrix multiplication feel free to use
matrix multiplier
or similar. In an exam you would have to do by hand/normal calculator but
you have already done enough matrix mult in question 1 for one tutorial.
- What is the model-view matrix at each node?
- If Object 3 has its parent changed to Object 2 without changing its local origin, angle or scale, how does its coordinate frame change?
- If we want to preserve Object 3's original coordinate frame, what new values do we need to set for its origin, angle and scale?
- If a camera with a local origin of 0,0, rotation angle of 0
and scale of 2 was attached to Object 2 in the scene graph,
what would the view matrix contain after setting the view for the camera?
Question 4:
Sketch the lines described by these equations:
- L(t) = A + (B-A)t, where A = (2,0), B=(0,4)
- n . (C - L) = 0, where n = (-1,1), C = (0,1)
Where do they intersect?
If Line 1 is a ray starting at A and line 2 is an edge of a polygon (with n pointing outwards), is the ray entering or exiting the polygon?
Question 5:
Given the clipping rectangle with bottom-left corner (1,1) and top-right corner (4,5), apply the Cohen-Sutherland algorithm to clip the following lines:
- A = (0,2), B=(4,0)
- A = (3,4), B=(2,2)
- A = (0,6), B=(5,6)
- A = (3,0), B=(5,2)
Repeat the process using the Cyrus-Beck algorithm instead.