Graphics CSCI 343 Fall 2019 Lecture 17 Viewing

  • Slides: 12
Download presentation
Graphics CSCI 343, Fall 2019 Lecture 17 Viewing II--Projection 1

Graphics CSCI 343, Fall 2019 Lecture 17 Viewing II--Projection 1

A Note on 3 D Surfaces When we create 3 D surfaces, we need

A Note on 3 D Surfaces When we create 3 D surfaces, we need a way to specify the front and back of the surface, so that we only display what’s necessary. This will be important for shading and texture mapping. In Open. GL, the order of vertices determines the front face of the surface using the right-hand rule. p 0 -p 1 -p 2 -p 3 correctly specifies the outer face as the front. p 3 -p 2 -p 1 -p 0 specifies the inner face as front. Make sure the triangles conform to this order as well. p 3 p 2 p 0 p 1 2

Hidden Surface Removal Z-Buffer Algorithms: _When we render surfaces on a screen, we only

Hidden Surface Removal Z-Buffer Algorithms: _When we render surfaces on a screen, we only want to render the surface that is closest to the camera at each pixel. _Z-Buffer algorithms use a buffer of the Z values associated with each rasterized point. _As successive polygons are converted to raster coordinates, the algorithm checks the Z value of the new polygon against the current content of the Z buffer. _Only polygons with the lowest Z values are rendered. 3

Specifying the clipping volume for Parallel projection gl. Ortho(xmin, xmax, ymin, ymax, near, far)

Specifying the clipping volume for Parallel projection gl. Ortho(xmin, xmax, ymin, ymax, near, far) y (xmin, ymin, -near) (xmax, ymaxn, -far) x z 4

Specifying the clipping volume for Perspective projection gl. Frustum(xmin, xmax, ymin, ymax, near, far)

Specifying the clipping volume for Perspective projection gl. Frustum(xmin, xmax, ymin, ymax, near, far) where the x and y positions are defined on the near plane. y y far near fovy -z z x glu. Perspective gl. Frustum Alternatively, you can specify the field of view in the vertical direction, fovy, and the aspect ratio (width/height): glu. Perspective(fovy, aspect, near, far) 5

Projection Normalization Open. GL accomplishes projections by the following steps: 1. Transform clipping volume

Projection Normalization Open. GL accomplishes projections by the following steps: 1. Transform clipping volume to the canonical volume. 2. Use orthographic projection to project to the image plane. Orthographic Projection: (1, 1, -1) (xmax, ymax, zmin) (xmin, ymin, zmax) Clipping Volume (-1, 1) 2 Canonical Volume 6

Transforming the clipping volume To transform the clipping volume for orthographic projection we must:

Transforming the clipping volume To transform the clipping volume for orthographic projection we must: 1. Translate it so it is centered on the origin. 2. Scale it so the length of each side is 2. Translation: Scaling: 7

Parallel Oblique Projection x q (xp, 0) xp = x - z cotq (x,

Parallel Oblique Projection x q (xp, 0) xp = x - z cotq (x, z) z y (y, z) f (yp, 0) yp = y - z cotf z P=? 8

Matrices for Oblique Projection Shear Matrix To transform to canonical volume, use scale and

Matrices for Oblique Projection Shear Matrix To transform to canonical volume, use scale and translation after shear: P = MORTHSTH(q, f) 9

Perspective Normalization Consider a perspective projection where the viewing angle is 90 deg and

Perspective Normalization Consider a perspective projection where the viewing angle is 90 deg and the focal distance is 1. x x = -z -1 x=z z Clipping Volume enclosed by: x = +/- z, y = +/- z, zmin < zmax 10

Splitting the projection matrix To fit this in the canonical volume, we want to

Splitting the projection matrix To fit this in the canonical volume, we want to find a matrix, N, such that: PPROJ = MORTHN We know that we will have to translate along the Z axis and scale the Z components. Try the following: 11

Fitting the canonical volume At x = -z, x'' = (-(-z/z)) = 1 At

Fitting the canonical volume At x = -z, x'' = (-(-z/z)) = 1 At x = z, x'' = (-z/z) = -1 Sides of canonical volume The same is true for y. For zmax and zmin: zmin'' = -(a + b/zmin) = -1 zmax'' = -(a + b/zmax) = +1 Solve for a and b: 12