CS488 - Introduction to Computer Graphics - Lecture 14

Mouse Interface



The application logic


Presentation of the model to the user


Provision of interpreted (more or less) input to the user


Usually the view knows where in screen coordinates it put each scene element


For assignment 3 you need to be able to select graphical objects with the mouse

The simple principle

  1. Mouse gives (x, y).
  2. Render pixel at (x, y ) keeping track of the polygon it comes from.
  3. Associate polygon with object

For the assignment let GL do it for you.

See the notes.


For assignment 3 you need to be able to rotate with the mouse

The virtual trackball

You need to modify the sample code.

Hierarchical Models

What we have

How to render any polygon anywhere

  1. Put the polygon where you want it to be in world coordinates
  2. Transform to view coordinates
  3. Perspective transform
  4. Clip in normalized device coordinates.
  5. Scan convert each polygon in any order, using z-buffer to remove occuded pixels

What we want to have

Objects made of polygons that we can feed into the rendering pipeline.

Argument by example

Suppose you are modelling classical temples. How do you do it?

  1. Open up Vitruvius. You will find that all temples are assumbled from a few basic parts, such as
  2. You don't know the words, but there are drawings with dimensions.
  3. There are rules for making them bigger and smaller, so you think of scaling matrices.
  4. There are rules for putting them in different orientations, so you think of rotation matrices.
  5. There are rules for placing them in different locations, so you think of translation matrices.

At this point you can make a temple, but it's a lot of work. To make it easier, divide and conquer

  1. Column = base + shaft + capital. Reuse this as a unit.
  2. Entablature = architrave + frieze + cornice. Reuse this as a unit.

You get the idea. The result is

What does this look like?

Scene -> First temple -> Stylobate
                      -> First column -> Generic column -> Base
                                                        -> Shaft
                                                        -> Capital
                      -> Second column
                      -> ...
                      -> Entablature
      -> Second temple /
                       -> First column /

Make a scene

proc scene
  pushMatrix( )
    temple( )
  popMatrix( )
  pushMatrix( )
    temple( )
  popMatrix( )

Make a temple

proc temple( )
  pushMatrix( )
    stylobate( )
  popMatrix( )
  pushMatrix( )
    column( )
  popMatrix( )
  pushMatrix( )
    column( )
  popMatrix( )
  pushMatrix( )
    entablature( )
  popMatrix( ) 

We don't want always to write a program, so we encapsulate the program as data.

Traverse a DAG

traverse( root )

proc traverse( node ) {
  if ( primitve( node ) ) {
    draw( node )
  } else { for each child {
    traverse( child )

Build a DAG

scene = gr.transform( )

temple1 = gr.transform( )
gr.add_child( temple1, scene )
gr.set_transform( temple1, gr.translation(...)*gr.rotation(...)
gr.set_material( temple1, marble )

stylobate1 = gr.transform( )
floor = gr.cube( )
gr.add_child( stylobate, floor )
gr.add_child( temple1, stylobate )
gr.set_transform( stylobate, gr.scaling(...) )
column1 = gr.transform( )
gr.add_child( temple1, column1 )
gr.set_transform( column1, gr.translation(...)*gr.scaling(...)

Return to: