Docstoc

Viewing Pipeline An Overview

Document Sample
Viewing Pipeline An Overview Powered By Docstoc
					                         OpenGL
                 The Viewing Pipeline:

• Definition: a series of operations that are applied to the
OpenGL matrices, in order to create a 2D representation
from 3D geometry.

• Processes can be broken up into four main areas:

1.The movement of the object is called a modeling transformation.
2.The movement of the camera is called a viewing transformation.
3.The conversion from 3D to 2D is called a projection transformation.
4.The 2D picture plane, which is mapped to the screen viewport, called a
viewport transformation.
      The Camera Analogy
            Camera     OpenGL

Modeling:   position   position
            model      model

Viewing:    position   position
            camera     viewing
                       volume
Projection: choose     choose
            lens       vv shape

Viewport:   choose     choose
            photo      portion
            size       of screen
  Viewing Pipeline & OpenGL
• Can also be thought of as a production line.
• Matrix operations are foundation of pipeline.
• Pipeline transforms vertices (coordinates).
Viewing Pipeline & Coordinates
 Pipeline transforms vertices (coordinates)



 object     eye          clip        ndc         window



   modelview   projection   perspective
                                           viewport
    matrix       matrix       division


   Coordinate systems are key to computer graphics!
      The Model Coordinates and
           Transformations
• The coordinates we specify using the glVertex* commands are the
  model coordinates.

• The glRotate, glTranslate and glScale commands are used to
  transform the model into the desired orientation and size.

• These operations are applied to the modelview matrix.

• We did these matrix transformations as an exercise and in test 1.

• OpenGL does them for us using one-liners (thank goodness).

• After applying the modeling transformations to the model coordinates
  what we get are world coordinates.
     The Model Coordinates and
          Transformations
To begin transformation of this matrix, we need to specify it in the
matrix mode function, then initialize the matrix to the Identity matrix,
and perform your transformations thereafter:
Overview
    The Camera Coordinates and
      Viewing Transformation
•   The next step is to convert the world coordinates into camera coordinates.

•   For this we use: gluLookAt(eyeX, eyeY, eyeZ, referX, referY, referZ, upX, upY, upZ);

•   This performs translations and rotations to transform a point from world coordinates to
    camera coordinates. So the matrix generated is a combination of translation and rotation
    matrices.

•   The default OpenGL viewpoint is located at the origin, looking down the negative Z axis.

•   Two options: The geometry that we wish to view must either be moved to a position from
    which it can be seen from the default viewpoint, or the viewpoint must be moved so that
    it can see the geometry.

•   eyeX, eyeY, eyeZ represents the viewpoint.
•   referX, referY, referZ represents a point along the desired line of sight.
•   upX, upY, upZ represents the view up vector.
The Camera Coordinates and
  Viewing Transformation
                                                       Note that although the
                                                       modeling and viewing
                                                       transformations can
                                                       be considered
                                                       logically separate
                                                       operations, OpenGL
                                                       concatenates all of
                                                       the modeling and
                                                       viewing
                                                       transformations into a
                                                       single matrix
                                                       (i.e. the ModelView
                                                       Matrix)



• Panning or Tilting: move reference point horizontally or vertically.
Overview
         Projection Transformation
•   After applying the modelview matrix OpenGL must now take the camera coordinates
    to the image space. This is done using the projection transformation.

•   Two types of projection: Orthographic and Perspective

•   Each of these transformations defines a volume of space called a frustum.

•   Only geometry that is inside of the frustum is displayed on the screen. Any portion of
    geometry that is outside of the frustum is clipped.
          Projection Transformation
Orthographic:

•   Maps objects directly onto the screen without
    affecting their relative size.


•   Given by: glOrtho(left, right, bottom, top, near, far);

•   Defines a rectangular parallelepiped frustum (a box).

•   Creates a matrix for an orthographic parallel viewing volume and multiplies the
    current matrix by it. (left, bottom, -near) and (right, top, -near) are points on the near
    plane that are mapped to the lower-left and upper-right corners of the viewport
    window, respectively. (left, bottom, -far) and (right, top, -far) are points on the far
    plane that are mapped to the same respective corners of the viewport. Both near and
    far can be positive or negative. The direction of projection is parallel to the z-axis, and
    the viewpoint faces toward the negative z-axis.
         Projection Transformation
Perspective:




•   Makes objects that are farther away appear smaller.


•   Given by: gluPerspective(fov, aspect, near, 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 are the distances between the viewpoint and the clipping
    planes, along the negative z-axis.
Overview
    Clipping and Perspective
             Divison
• Steven’s section
           Viewport Transformation
•   Determines the size of the rendered image.

•   By default the viewport is set to the entire pixel rectangle of the window.

•   The glViewport(GLint x, GLint y, GLsizei width, GLsizei height); command can be
    used to choose a smaller drawing region.

•   The viewport aspect ratio should be the same as that of the view frustum or the
    image appears distorted.

•   The 2D picture plane from the previous transformation forms the world coordinate
    window, which can be mapped to the screen viewport, which ends up on our screen.
        Code Execution Order
Since the order of the transformations is significant, we want to invoke the
OpenGL functions in the proper order, i.e. in the reverse order in which they
will be applied:

				
DOCUMENT INFO