1 / 20

CSC461: Lecture 20 Parallel Projections in OpenGL

CSC461: Lecture 20 Parallel Projections in OpenGL. Objectives Introduce OpenGL viewing functions Derive the projection matrices used for standard OpenGL projections Introduce oblique projections Introduce projection normalization Introduce hidden-surface removal algorithms.

wmonique
Download Presentation

CSC461: Lecture 20 Parallel Projections in OpenGL

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. CSC461: Lecture 20 Parallel Projections in OpenGL Objectives • Introduce OpenGL viewing functions • Derive the projection matrices used for standard OpenGL projections • Introduce oblique projections • Introduce projection normalization • Introduce hidden-surface removal algorithms

  2. OpenGL Orthogonal Viewing glOrtho(xmin,xmax,ymin,ymax,near,far) glOrtho(left,right,bottom,top,near,far) nearandfarmeasured from camera

  3. OpenGL Perspective Viewing • The function:glFrustum(xmin,xmax,ymin,ymax,near,far) • OpenGL figures out the transformation matrix and perspective division • With glFrustum it is often difficult to get the desired view

  4. front plane aspect = w/h Using Field of View (fov) • The function gluPerpective(fovy, aspect, near, far) • The angle fov is the angle between the top and bottom planes of the clipping volume in the y direction • The aspect ratio = width/height • Often provides a better interface

  5. Normalization • Rather than derive a different projection matrix for each type of projection, we can convert all projections to orthogonal projections with the default view volume • This strategy allows us to use standard transformations in the pipeline and makes for efficient clipping

  6. model-view transformation projection transformation perspective division 4D  3D nonsingular clipping projection 3D  2D against default cube Pipeline View

  7. Notes • We stay in four-dimensional homogeneous coordinates through both the model-view and projection transformations • Both these transformations are nonsingular • Default to identity matrices (orthogonal view) • Normalization lets us clip against simple cube regardless of type of projection • Delay final projection until end • Important for hidden-surface removal to retain depth information as long as possible

  8. Orthogonal Normalization • glOrtho(left,right,bottom,top,near,far) • Normalization  find transformation to convert specified clipping volume to default  canonical view volume • Default volume: centered at the origin with the length of 2

  9. P = ST = Orthogonal Matrix • Two steps • Move center to origin -- translation T(-(left+right)/2, -(bottom+top)/2,(near+far)/2)) • Scale to have sides of length 2 S(2/(left-right),2/(top-bottom),2/(near-far))

  10. Morth = Final Projection • Project on the projection plane • Set z =0 • Equivalent to the homogeneous coordinate transformation • Hence, general orthogonal projection in 4D is P = MorthST

  11. Oblique Projections • OpenGL only supports orthogonal projection function, not general parallel projections such as oblique projections • However if we look at the example of the cube it appears that the cube has been sheared • Oblique Projection = Shear + Orthogonal Projection • Concatenate shear and orthographic viewings

  12. top view side view General Shear

  13. H(q,f) = Shear Matrix xp= x – z cotanθ, yp= y – z cotanø, zp= 0 xy shear (z values unchanged) Projection matrix: General case: Where S and T are the same as orthogonal projection P = MorthH(q,f) P = MorthSTH(q,f)

  14. Equivalency

  15. object top view z = 1 DOP DOP x = -1 x = 1 far plane z = -1 clipping volume near plane distorted object (projects correctly) Effect on Clipping • The projection matrix P = STH transforms the original clipping volume to the default clipping volume

  16. Surface Display • All surfaces should be specified • Two approaches to determine which surfaces should be displayed • Remove those surfaces that should not be visible Hidden-surface-removal • Find those surfaces that are visible  Visible-surface • Many algorithms exist • OpenGL uses the z-buffer algorithm (a hidden-surface-removal algorithm)

  17. Hidden-Surface-Removal • Two categories of hidden-surface-removal algorithms • Object-space algorithms: • order the surfaces in the scene such that drawing surfaces in a particular order provides the correct image • Example: back-face first for a cube • Not easy to sort the surfaces • Image-space algorithms • As part of the projection process • Seek to determine the relationship among object points on each projector • The z-buffer algorithm

  18. The z-buffer Algorithm • A projector from the COP passes through two surfaces • The closest object determines the color placed in the color buffer at the corresponding location • For each pixel in the color buffer, keep the depth information in the z-buffer • When a new color is projected to the pixel, check its z-value to determine if the color should be replaced • The depth is the distance from the object to the origin – the viewer

  19. Using The z-buffer • Initialize the z-buffer – to a value that corresponds to the farthest distance from the viewer gluInitDisplayMode(GLUT_RGB|GLUT_DEPTH) • Enable the z-buffer glEnable(GL_DEPTH_TEST) • Clear the z-buffer glClear(GL_DEPTH_BUFFER_BIT)

  20. Culling • Remove all the faces pointing away from the viewer and only render the ones facing the viewer • Enable culling glEnable(GL_CULL) • Only works for convex objects, e.g. cube • Combination of culling and the z-buffer

More Related