CS 770870 CLASS 6 PERSPECTIVE Orthographic projections Isometric

  • Slides: 17
Download presentation
CS 770/870 CLASS 6 PERSPECTIVE

CS 770/870 CLASS 6 PERSPECTIVE

Orthographic projections Isometric Oblique In isometric all distances along the major axes are the

Orthographic projections Isometric Oblique In isometric all distances along the major axes are the same

Orthographic Oblique using a shear �Move x and y proportional to the depth

Orthographic Oblique using a shear �Move x and y proportional to the depth

To generate Oblique perspective Cot(q) = dx/dz Cot(f) = dy/dz

To generate Oblique perspective Cot(q) = dx/dz Cot(f) = dy/dz

Orthographic projection matrix The effect is to scale in to a [-1, +1] cube.

Orthographic projection matrix The effect is to scale in to a [-1, +1] cube. Note – the mapping into a viewport is actually done in two stages First we map into a cube. Then we map into the viewport. Reason: Clipping

The Z buffer algorithm �Problem, how do we make sure that nearer objects hide

The Z buffer algorithm �Problem, how do we make sure that nearer objects hide further objects? �A reason why we need to preserve depth after projection. �The z-buffer contains depth information about an image for every pixel that is rendered between the near and the far clipping plane. �For each pixel, about to be rendered. If closer than z-buffer depth draw rgb and z value. Else, discard. It works because the image has already been transformed

Perspective. How to get the scaling

Perspective. How to get the scaling

Brunelleschi’s window

Brunelleschi’s window

Perspective transformation - simplified w=z/d �Final step, divide x and y by w Where

Perspective transformation - simplified w=z/d �Final step, divide x and y by w Where P is the projective transformation matrix (above) M = PS S is the Scene to Viewport mapping

Two specifications Why? gl. Frustum (Left, Right, Bottom, Top, Near, Far); glu. Perspective(fov, aspect,

Two specifications Why? gl. Frustum (Left, Right, Bottom, Top, Near, Far); glu. Perspective(fov, aspect, near far);

View control �The Lookat function from a viewpoint (vp) to a scene point (sp)

View control �The Lookat function from a viewpoint (vp) to a scene point (sp) �glu. Lookat(vp. X, vp. Y, vp. Z, sp. X, sp. Y, sp. Z, up. X, up. Y, up. Z); �Three ways of doing it. Using glu. Lookat, or using translate and rotate, or Using change in basis.

Change in basis �Express one set of axes in the coordinates of another. �In

Change in basis �Express one set of axes in the coordinates of another. �In a simple form this is a rotation. V Y U (x, y) Coordinates of U, V axis As unit vectors Expressed in X, Y system X Convert point (x, y) to point (u, v)

�How to get a rotation to view vector �Use basis method 1) Take difference

�How to get a rotation to view vector �Use basis method 1) Take difference 2) Normalize 3) Put into matrix form (e. Y, e. Y) n v (at. X, at. Y)

To deal with the Up Vector in 3 D �Purpose, Rotate view so that

To deal with the Up Vector in 3 D �Purpose, Rotate view so that some defined up in the scene is aligned with the vertical direction on the screen. �Calculate view vector v (difference + normalize) �Given up vector u use cross products �Side ways vector of view coords s= uxv �New up vector n = uxs sx sy sz nx ny nz vx vy vz Useful fact: the Transpose of a rotation matrix is its inverse.

How to fly �Keep moving the viewpoint in the direction of travel �Rotate according

How to fly �Keep moving the viewpoint in the direction of travel �Rotate according to the view direction. gl. Clear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); gl. Push. Matrix(); gl. Rotatef(view. Angle*180. 0/3. 141592, 0, 1, 0); gl. Translatef(-eye. X, -eye. Y, -eye. Z); // to origin scene(); gl. Pop. Matrix(); glut. Swap. Buffers(); df = my*0. 01; // the speed in the forward direction (my from mouse) view. Angle += mx*0. 0001; // Azimuth in radians dz = cos(view. Angle)*df; dx = sin(view. Angle)*df; eye. X += dx; eye. Z -= dz;

Clipping Cohen Sutherland �The outcode function returns an outcode as follows Ymax Ymin bbbb

Clipping Cohen Sutherland �The outcode function returns an outcode as follows Ymax Ymin bbbb Xmin Xmax >Ymax < Ymin < Xmin >Xmax

Cohen Sutherland Cases C p 2 C A C p 1 B different regions,

Cohen Sutherland Cases C p 2 C A C p 1 B different regions, may need clipping Let o 1 be the outcode of p 1 Case A: o 1 = o 2 = 0; Both inside, no clipping needed Case B: (o 1 & 02) |= 0; all bits same region discard Case C: (o 1 XOR 01) > 0 ; some bits different regions, may need clipping