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();
    }

Question 2:

Consider the 2D tranformation matrix:

[ 1  -1   1 ]
[ 1   2   2 ] 
[ 0   0   1 ]

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.

Question 4:

Sketch the lines described by these equations:

  1. L(t) = A + (B-A)t, where A = (2,0), B=(0,4)
  2. 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:

Repeat the process using the Cyrus-Beck algorithm instead.