Viewing Transformations
  • Viewing transformations change the position and orientation of the viewpoint
    • Analogous to "moving the camera"
  •  Ways to implement vieing transformations:
    • Use one or more modeling tranformations
      • Moving objects around a stationary camera
      • Moving the camera around the world (equivalent)
    • Use the Utility Libary routine gluLookAt() to define a line-of-sight
    • Roll your own routine (cosine matrix, HPR, etc)

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

 

  Using GLUlookat()
  • Many times an application will build up a scene around a known origin 
  •  GLUlookat() will "aim the camera" by specifying the modeling transformation
  • Three parameters:
    • Location of the viewpoint
    • Reference point along the view vector

    • A direction vector specifying the "up" direction
void gluLookAt(GLdouble eyex, GLdouble eyey, GLdouble eyez, GLdouble centerx, GLdouble centery, GLdouble centerz, GLdouble upx, GLdouble upy, GLdouble upz);

Defines a viewing matrix and multiplies it to the right of the current matrix. The desired viewpoint is specified by eyex, eyey, and eyez. The centerx, centery, and centerz arguments specify any point along the desired line of sight, but typically they're some point in the center of the scene being looked at. The upx, upy, and upz arguments indicate which direction is up (that is, the direction from the bottom to the top of the viewing volume).

     

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

 

Using GLUlookat() (cont)
  • The default viewing position is as if the following were specified:

  • gluLookat(0.0, 0.0, 0.0, 0.0, 0.0, -1.00.0, 1.0, 0.0);
                               loc                aim                          up
     


     
     
     
     
     
     
     


 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

 

  Example gluLookat()

    gluLookat(4.0, 2.0, 1.0, 2.0, 4.0, -3.0, 2.0, 2.0, -1.0);
     

  • The camera position (eyex, eyey, eyez) is at (4, 2, 1). 
  • Reference point is at (2, 4, -3). 
  • Orientation vector of (2, 2, -1)
  • Remember!  this is a GL Utility (GLU) routine! (encapsulates several OGL calls)

  •  

     
     
     
     
     
     
     
     
     
     
     
     
     


 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

 

  Multiple transformations
    Note: You can have only one active viewing transformation. You cannot try to combine the effects of two viewing transformations, any more than a camera can have two tripods. If you want to change the position of the camera, make sure you call glLoadIdentity() to wipe away the effects of any current viewing transformation.
     
     
     
     

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

 

  Custom Utility Routines

View from aircraft:

    void pilotView(GLdouble planex, GLdouble planey, GLdouble planez, GLdouble roll, GLdouble pitch, GLdouble heading) 

      glRotated(roll, 0.0, 0.0, 1.0); 
      glRotated(pitch, 0.0, 1.0, 0.0); 
      glRotated(heading, 1.0, 0.0, 0.0);
      glTranslated(-planex, -planey, -planez); 
    }
     
"Orbiting view" of object at origin:
    void polarView(GLdouble distance, GLdouble twist, GLdouble elevation, GLdouble azimuth) 

      glTranslated(0.0, 0.0, -distance); 
      glRotated(-twist, 0.0, 0.0, 1.0); 
      glRotated(-elevation, 1.0, 0.0, 0.0); 
      glRotated(azimuth, 0.0, 0.0, 1.0); 
    }
     
     
     

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

 

  Projection Transformations
  • Projection transformations provide:
    • Defines a viewing volume to specified how an object is projected onto the screen
    • Defines the clipping region which specifies which geometry is visible
  •  In order to define Projection transformations specify the folowing

  •  

     

    glMatrixMode(GL_PROJECTION); 
    glLoadIdentity();
     
     
     
     
     
     
     
     


 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

 

  Perspective Transformation
  • "Foreshortens" objects as a function of their distance from the eyepoint
  •  The viewing volume is a frustrum in a perspective view

  •  

     


     
     
     
     

  •  Objects within the pyramid are projected toward the apex of the pyramid
  •  Closer objects will occupy a larger fraction of the viewport
    • They occupy a larger proportion of the viewing volume

     
     
     
     
     

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

 

  Using glFrustrum()
  • Perspective transformations are define with glFrustrum()

void glFrustum(GLdouble left, GLdouble right, GLdouble bottom, GLdouble top, GLdouble near, GLdouble far); 

Creates a matrix for a perspective-view frustum and multiplies the current matrix by it. The frustum's viewing volume is defined by the parameters: (left, bottom, -near) and (right, top, -near) specify the (x, y, z) coordinates of the lower-left and upper-right corners of the near clipping plane; near and far give the distances from the viewpoint to the near and far clipping planes. They should always be positive.

NOTE!  use glLoadIdentity() to completely re-define the perspective transformation

     
     
     
     
     
     

     
     
     
     
     
     
     
     
     
     
     


 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

 

  Using gluPerspective()
  • Equivalent transformations can be accomplished with gluPerspective()


void gluPerspective(GLdouble fovy, GLdouble aspect, GLdouble near, GLdouble far); 

Creates a matrix for a symmetric perspective-view frustum and multiplies the current matrix by it. fovy is the angle of the field of view in the x-z plane; its value must be in the range [0.0,180.0]. aspect is the aspect ratio of the frustum, its width divided by its height. near and far values the distances between the viewpoint and the clipping planes, along the negative z-axis. They should always be positive.