Viewing Transformation - PowerPoint PPT Presentation

1 / 21
About This Presentation
Title:

Viewing Transformation

Description:

gluLookAt(eyex, eyey, eyez, centerx, centery, centerz, upx, upy, upz) ... build_rotmatrix (rotationMatrix, quat); glMultMatrixf (&rotationMatrix[0][0] ... – PowerPoint PPT presentation

Number of Views:130
Avg rating:3.0/5.0
Slides: 22
Provided by: jacky5
Category:

less

Transcript and Presenter's Notes

Title: Viewing Transformation


1
Viewing Transformation
  • Position and aim the camera
  • gluLookAt(eyex, eyey, eyez, centerx, centery,
    centerz, upx, upy, upz)
  • Default location at origin looking down the
    negative z-axis

2
Viewing Transformation (Cont)
gluLookAt(4.0, 2.0, 1.0, 2.0, 4.0, -3.0, 2.0,
2.0, -1.0)
Default location
3
Projection Transformation
  • Define a viewing volume
  • Orthographic projection
  • Perspective projection

4
Projection Transformation (Orthographic)
  • glOrtho(left, right, bottom, top, near, far)

5
Projection Transformation (Orthographic) Cont
  • gluOrtho2D(left, right, bottom, top)
  • A special case of glOrtho() withnear -1 and
    far 1
  • Vertices with z-coordinate smaller than 1 or
    larger than 1 will be clipped away

6
Projection Transformation (Perspective)
  • glFrustum(left, right, bottom, top, near, far)

7
Projection Transformation (Perspective) Cont
  • gluPerspective(fovy, aspect, near, far), a
    special case of glFrustum() with symmetric
    perspective view

8
Projection Transformation
  • Orthographic projections
  • w component is always 1
  • Perspective projections,
  • w component may not be 1
  • Perspective division has to be performed by
    dividing all coordinates values by w to get back
    the normalized device coordinates

9
Viewing Volume Clipping
  • Six clipping planes
  • Clip away the polygons outside the viewing volume

10
Viewport Transformation
  • Map the OpenGL image to the window system
  • glViewport(x, y, width, height)
  • Generally, the aspet ratio of viewport should
    equal the aspect ratio of the image on the
    projection plane to avoid distortion

11
Accumulating Rotations
  • Computer graphics application requires user to
    spin a model with mouse
  • Incremental rotations must be accumulated for
    accurate orientation
  • Two naive ways and quaternion way

12
Accumulating Rotations (Cont)
  • Naïve 1 Perform glRotate() calls for each
    incremental rotation
  • floating-point errors produce non-orthogonal
    matrices
  • model may shrink or grow
  • Requires saving and restoring multiple modelview
    matrices

X
X
X
13
Accumulating Rotations (Cont)
  • Naïve 2 Represent each model orientation as
    three angles, each representing rotation around
    the x, y, z axis
  • incorrect result because rotations are not
    commutative

X
14
Accumulating Rotations (Cont)
  • Quaternion Way quaternion represents rotation as
    four floating-point values

15
Trackball Interface
  • trackball.c implements quaternion math
  • contains routines for
  • converting a rotation matrices to a quaternion
  • accumulating quaternions
  • converting a quaternion representation to a
    rotation matrix

16
Trackball Interface (Cont)
  • Converting rotations to quaternions
  • Call trackball() with the beginning and ending
    window coordinates which are normalized to
    between 1 and 1.
  • Example rotation around x-axis
  • float deltaQuat4
  • trackball(deltaQuat,
  • 0.0, -0.1, / starting x, y /
  • 0.0, 0.3) / ending x, y /

17
Trackball Interface (Cont)
  • Accumulating quarternions
  • Call add_quarts() to accumulate one quaternion
    with another
  • Example accumulate the first two quaternions and
    store in the third one
  • float currentQuat4
  • add_quats(deltaQuat, currentQuat, currentQuat)

18
Trackball Interface (Cont)
  • Converting a quarternion to a rotation matrix
  • Call build_rotmatrix() to convert an accumulated
    quaternion to a rotation matrix for modelview
    matrix multiplication
  • Example
  • GLfloat rotationMatrix44
  • build_rotmatrix(rotationMatrix, currentQuat)
  • glPushMatrix()
  • glMultMatrix(rotationMatrix00)
  • ...
  • glPopMatrix()

19
Trackball UI
  • ui.c implements the trackball rotation, panning,
    zooming effected by mouse buttons movements
  • The modelview stack is updated in the following
    order TRM
  • Translation (panX, panY, zoom)x Rotation about
    center of scenex Original Viewing Transformation

20
Trackball UI (Cont)
  • The original viewing transformation is first
    applied
  • Rotation, panning and zooming are applied with
    respect to the eye coordinate frame
  • First store the original viewing transformation
    matrix
  • GLfloat originalViewMatrix44
  • glGetFloatv (GL_MODELVIEW_MATRIX,
    originalViewMatrix00)

21
Trackball UI (Cont)
  • Current modelview matrix is updated as follow
  • glPushMatrix ()
  • glLoadIdentity()glTranslatef (panX, panY,
    Zoom)
  • glTranslatef (0.0, 0.0, -lengthOfView)
  • build_rotmatrix (rotationMatrix, quat)
  • glMultMatrixf (rotationMatrix00)
  • glTranslatef (0.0, 0.0, lengthOfView)
  • glMultMatrixf (originalViewMatrix00)
  • drawScene()
  • glPopMatrix ()
Write a Comment
User Comments (0)
About PowerShow.com