1 graphics csci 343, fall 2015 lecture 18 viewing iii--more projection
Post on 06-Jan-2018
219 Views
Preview:
DESCRIPTION
TRANSCRIPT
1
Graphics
CSCI 343, Fall 2015Lecture 18
Viewing III--More Projection
2
Orthographic and Oblique projections
Orthographic Projection:1) Translate clipping volume to origin2) Scale sides of clipping volume to be 2x2x2
M = MORTHOST
Oblique Projection:1) Shear clipping volume to be rectangular box.2) Translate to origin3) Scale sides to 2x2x2
M = MORTHOSTH
3
Perspective NormalizationConsider a perspective projection where the viewing angle is 90 deg and the focal distance is 1.
-1
x
z
x = z
x = -z
Clipping Volume enclosed by:x = +/- z, y = +/- z, zmin < z < zmax
4
Splitting the projection matrixTo 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:
5
Fitting the canonical volumeAt x = -z, x'' = (-(-z/z)) = 1At x = z, x'' = (-z/z) = -1
Sides of canonical volume
The same is true for y.
For zmax and zmin:zmin'' = -( + /zmin) = -1zmax'' = -( + /zmax) = +1
Solve for and :
6
Scaling the X and Y edgesIf 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(xmin, zmax)
(xmax, zmax)
PPROJ = MORTHNS
S = ?
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(xmin, zmax)
(xmax, zmax)
Shear along x:
Shear along y:
x
8
The Shear Matrix
Note that this matrix transforms the center point:
to
Full Perspective Projection:P = MORTHONSH
9
Projections and ShadowsIn simple situations we can generate shadows with a projection trick.
Suppose we have a light source at (xa, ya, za)The "shadow" of a polygon is its projection onto the x,z plane.
(xa, ya, za)
z
x
y
10
Projecting a shadow1. Translate the image so that the light source is at the origin.
T(-xa, -ya, -za)1. Compute the projection along the Y axis, with the focal
distance equal to -ya.2. Translate back to the original position: T(xa, ya, za)
Step 2: Projection Matrix:
z
x
y
-ya
Shadow projection in OpenGLSetting 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);
Drawing the shadow// rotate light source light[0] = Math.sin(theta);light[2] = Math.cos(theta); // model-view matrix for shadow then rendermodelViewMatrix = 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);
top related