Week 6 Tutorial

Question 1:

Consider the following code for drawing a pyramid.

Which way are the faces pointing? If you drew this in OpenGL with back face culling turned on, what would you see?

        // the base
        gl.glBegin(GL2.GL_POLYGON);
        {
            gl.glVertex3d(1, 1, 0);
            gl.glVertex3d(-1, 1, 0);
            gl.glVertex3d(-1,-1, 0);
            gl.glVertex3d(1, -1, 0);
        }
        gl.glEnd();        

        // the sides
        gl.glBegin(GL2.GL_POLYGON);
        {
            gl.glVertex3d(0, 0, 2);
            gl.glVertex3d(1, 1, 0);
            gl.glVertex3d(-1, 1, 0);
        }
        gl.glEnd();        

        gl.glBegin(GL2.GL_POLYGON);
        {
            gl.glVertex3d(0, 0, 2);
            gl.glVertex3d(-1, -1, 0);
            gl.glVertex3d(-1, 1, 0);
        }
        gl.glEnd();        

        gl.glBegin(GL2.GL_POLYGON);
        {
            gl.glVertex3d(0, 0, 2);
            gl.glVertex3d(-1, -1, 0);
            gl.glVertex3d(1, -1, 0);
        }
        gl.glEnd();        

        gl.glBegin(GL2.GL_POLYGON);
        {
            gl.glVertex3d(0, 0, 2);
            gl.glVertex3d(1, -1, 0);
            gl.glVertex3d(1, 1, 0);
        }
        gl.glEnd();        

Question 2: 3D Modeling

Note: This question is from last week's tutorial. If you completed it then you can skip it now

Question 3:

Use bilinear interpolation to work out the pixel depths for the triangle below, given the coordinates for the vertices as stated. Calculate depth values to one decimal place.

Show the result of copying the triangle into a depth buffer.

Use this depth buffer to add the rectangle below. Draw the resulting image.

Suppose the green rectangle is transparent (with alpha = 0.5). What does the resulting image look like in this case?

Question 4:

Consider the dungeon map below:

Assuming each wall is a single polygon, and assigning normals as you see fit, build a BSP tree for this map. There are many possible trees, depending on the order in which you choose polygons. What is the smallest tree you can find?

If the player is in the position marked, what order should the polygons be drawn so that all hidden surfaces are renderered properly?