- Forward


Transformation in OpenGL
with Examples


Prof. David Bernstein
James Madison University

Computer Science Department
bernstdh@jmu.edu

Print

A Review of Viewing
Back SMYC Forward
  1. ModelView Matrix:
    • From object coordinates to eye coordinates
    • glMatrixMode(GL_MODELVIEW);
  2. Projection Matrix
    • From eye coordinates to clip coordinates
    • glMatrixMode(GL_PROJECTION);
ModelView Matrix
Back SMYC Forward
  • The Viewing Transform:
    • Positions the viewing volume in the world
    • Usually set using gluLookAt()
  • The Modeling Transform
    • "Positions" the model in the world
    • Usually set using glTranslate*(), glScale*(), glRotate*()
The Projection
Back SMYC Forward
  • Orthographic:
    • glOrtho(left, right, bottom, top, near, far)
  • Perspective:
    • glFrustum(fovy, aspect, zNear, zFar)
    • where fovy is the field of view (in degrees) in the \(y\) direction, aspect is the aspect ration that determines the FOV in the \(x\) direction, zNear is the positive distance from the viewer to the near clipping plane, and zFar is the positive distance from the viewer to the far clipping plane
The Composition of Different Transformations
Back SMYC Forward
  • Two Observations:
    • Thus far we have only worked with one object at a time
    • Working with multiple objects requires multiple transformations
  • A Warning:
    • The order of the transformations is important and requires careful thought
    • Management of the stack of transformations (using glPushMatrix() and glPopMatrix()) is important and requires careful thought
An Example
Back SMYC Forward

The Sun, Earth and Moon

openglexamples/transforms/solarsystem.c (Fragment: display)
 
Another Example
Back SMYC Forward

Hinged Blocks

openglexamples/transforms/hinges.c (Fragment: display)
 
A Third Example
Back SMYC Forward

First-Person Viewing

openglexamples/transforms/firstperson.c
 
There's Always More to Learn
Back -