Week 3 Tutorial Solutions

This week's tutorial will be in the normal classrooms rather than the lab.

Question 1:

Go around the class and talk about why you're interested in graphics. What's the coolest graphics application you have seen? What would you like to be able to make?

Question 2:

Suppose we perform the following sequence of 2d transformations in jogl.Draw the successive coordinate frames:

Draw a house in the resulting coordinate frame, assuming that the house was located in the following starting position.

Final House Translated,Rotated,Scaled

How does the result change if you change the order of the transformations (try all 6 possiblities).

Here the order TRS, TSR on the first row, RTS, RST on the second row and STR, SRT on the last row.

Things to note:

Question 3:

Given a function

//This function draws a pole of width 0.1, height 2
//With the bottom, middle of the pole at the origin 
//of its local coordinate system as shown in the following picture.
private void drawPole(GL2 gl);

And another function

//This function draws a windmill vane with the left most point at the 
//origin of its local coordinate frame as shown in the following picture
private void drawVane(GL2 gl);
  1. Write a function called

    public void drawWindmill(GL2 gl);
    
    that can draw a windmill as shown in the following picture

    public void drawWindmill(GL2 gl){
        gl.glPushMatrix();
            drawPole(gl2);
        
            gl.glTranslated(0,2,0);
            for(int i=0; i < 3; i++){
                gl.glRotated(120,0,0,1); //These rotations accumulate
                gl.drawVane(gl); 
            }
            
        gl.glPopMatrix();
    }
    
  2. Write a function named

    public void drawWindmills(GL2 gl);
    

    that draws windwills as shown in the following picture. Note: This picture shows the world coordinate frame.

    public void drawWindmills(GL2 gl){
        gl.glPushMatrix();
           gl.glTranslated(-1,-1,0);
           drawWindmill(gl);        
        gl.glPopMatrix();
    
        gl.glPushMatrix();
           gl.glTranslated(1,0,0);
           gl.glScaled(0.5,0.5,1);
           drawWindmill(gl);
        gl.glPopMatrix();
    }
    
  3. Draw a scene graph that could model this simple scene.

      Scene Root
         | |
       Windmill
          |
        Pole
        | | |
        Vane   
    
  4. How could we make our vanes rotate?

    Have some kind of variable such as theta, that gets updated each time display gets called by the animator. Then use it to perform a rotation before the vanes are drawn. For example:

    public void drawWindmill(GL2 gl){
        gl.glPushMatrix();
            drawPole(gl2);
           
            gl.glTranslated(0,2,0);
            gl.glRotated(theta,0,0,1);
            for(int i=0; i < 3; i++){
                gl.glRotated(120,0,0,1); //These rotations accumulate
                gl.drawVane(gl); 
            }
            
        gl.glPopMatrix();
    }
    

Question 4:

Consider building a model of the solar system. What would the scene graph look like? What is the local coordinate frame for each object? How would they evolve over time? Careful, this is not as obvious at it might look.

There are many possible answers. A naive graph might look like:

Sun --- Mercury
    \-- Venus
    \-- Earth -- Moon
    \-- Mars
     ... etc

The problem with this model is that the Moon is directly attached to the Earth's coordinate frame. So when the Earth rotates, the Moon will move with it.

A better graph would be

Sun --- Mercury
    \-- Venus
    \-- EarthPivot --- Earth
    |              \-- Moon
    \-- Mars
     ... etc

The EarthPivot is an empty object, just a place holder for a coordinate frame. The EarthPivot orbits the sun. The Earth sits at the EarthPivot and rotates. The Moon orbits around the EarthPivot. Now the Moon's orbit is decoupled from the Earth's rotation.

A well designed scene graph only couples together parts of the scene that move in the same way. Pivot objects are a good way to connect elements which have a common component to their movement but don't have a direct parent-child relationship.

Question 5:

Consider the world shown below, in world coordinates.

  1. An orthographic camera with bounds (left = -1, right = 1, bottom = -1, top = 1) is placed at (2, 3).

  2. What if you placed it at (2,3),rotated the camera by 90 degrees then scale it by (2, 2).

  3. Suppose the viewport is an 800x600 screen.