Download presentation
Presentation is loading. Please wait.
Published byAlberta Banks Modified over 8 years ago
1
1 Graphics CSCI 343, Fall 2015 Lecture 18 Viewing III--More Projection
2
2 Orthographic and Oblique projections Orthographic Projection: 1)Translate clipping volume to origin 2)Scale sides of clipping volume to be 2x2x2 M = M ORTHO ST Oblique Projection: 1)Shear clipping volume to be rectangular box. 2)Translate to origin 3)Scale sides to 2x2x2 M = M ORTHO STH
3
3 Perspective Normalization Consider a perspective projection where the viewing angle is 90 deg and the focal distance is 1. x z x = z x = -z Clipping Volume enclosed by: x = +/- z, y = +/- z, z min < z < z max
4
4 Splitting the projection matrix To fit this in the canonical volume, we want to find a matrix, N, such that: P PROJ = M ORTH N We know that we will have to translate along the Z axis and scale the Z components. Try the following:
5
5 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 z max and z min : z min '' = -( + /z min ) = -1 z max '' = -( + /z max ) = +1 Solve for and :
6
6 Scaling the X and Y edges If the perspective projection does not have a 90 deg viewing angle: We must first scale x and y so the sides are at x = +/-z, y=+/-z x z (x min, z max ) (x max, z max ) P PROJ = M ORTH NS S = ?
7
7 Dealing with a non-centered clipping volume If the frustum that defines the clipping volume is not a right frustum (i.e. the near and far planes are not centered on the Z axis), we must first Shear the clipping volume to center these. z (x min, z max ) (x max, z max ) Shear along x: Shear along y: x
8
8 The Shear Matrix Note that this matrix transforms the center point: to Full Perspective Projection: P = M ORTHO NSH
9
9 Projections and Shadows In simple situations we can generate shadows with a projection trick. Suppose we have a light source at (x a, y a, z a ) The "shadow" of a polygon is its projection onto the x,z plane. (x a, y a, z a ) z x y
10
10 Projecting a shadow 1.Translate the image so that the light source is at the origin. T(-x a, -y a, -z a ) 2.Compute the projection along the Y axis, with the focal distance equal to -y a. 3.Translate back to the original position: T(x a, y a, z a ) Step 2: Projection Matrix: z x y -y a
11
Shadow projection in OpenGL Setting up the matrix, M: light = vec3(0.0, 2.0, 0.0); m = mat4(); m[3][3] = 0; m[3][1] = -1/light[1]; Rendering a square: // model-view matrix for square modelViewMatrix = mat4( ); modelViewMatrix = mult(modelViewMatrix, rotate(30.0, 1.0, 0.0, 0.0)); // send color and matrix for square then render gl.uniformMatrix4fv( modelViewMatrixLoc, false, flatten(modelViewMatrix) ); gl.uniform4fv(fColor, flatten(red)); gl.drawArrays(gl.TRIANGLE_FAN, 0, 4);
12
Drawing the shadow // rotate light source light[0] = Math.sin(theta); light[2] = Math.cos(theta); // model-view matrix for shadow then render modelViewMatrix = mult(modelViewMatrix, translate(light[0], light[1], light[2])); modelViewMatrix = mult(modelViewMatrix, m); modelViewMatrix = mult(modelViewMatrix, translate(-light[0], -light[1], -light[2])); // send color and matrix for shadow gl.uniformMatrix4fv( modelViewMatrixLoc, false, flatten(modelViewMatrix) ); gl.uniform4fv(fColor, flatten(black)); gl.drawArrays(gl.TRIANGLE_FAN, 0, 4);
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.