Presentation is loading. Please wait.

Presentation is loading. Please wait.

CSC461: Lecture 20 Parallel Projections in OpenGL

Similar presentations


Presentation on theme: "CSC461: Lecture 20 Parallel Projections in OpenGL"— 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) near and far measured 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 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 aspect = w/h front plane

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 Pipeline View model-view transformation projection perspective
division clipping nonsingular 4D  3D against default cube 3D  2D

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 Orthogonal Matrix Scale to have sides of length 2 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)) P = ST =

10 Final Projection Project on the projection plane Set z =0
Equivalent to the homogeneous coordinate transformation Hence, general orthogonal projection in 4D is Morth = 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 General Shear top view side view

13 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 H(q,f) = P = Morth H(q,f) P = Morth STH(q,f)

14 Equivalency

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

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


Download ppt "CSC461: Lecture 20 Parallel Projections in OpenGL"

Similar presentations


Ads by Google