Top Banner
CLASS 6 PERSPECTIVE CS770/870
17

CLASS 6 PERSPECTIVE CS770/870. Orthographic projections Isometric ObliqueIn isometric all distances along the major axes are the same.

Dec 17, 2015

Download

Documents

Cathleen Oliver
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: CLASS 6 PERSPECTIVE CS770/870. Orthographic projections Isometric ObliqueIn isometric all distances along the major axes are the same.

CLASS 6

PERSPECTIVE

CS770/870

Page 2: CLASS 6 PERSPECTIVE CS770/870. Orthographic projections Isometric ObliqueIn isometric all distances along the major axes are the same.

Orthographic projections

Isometric

Oblique In isometric all distances along the major axes are the same

Page 3: CLASS 6 PERSPECTIVE CS770/870. Orthographic projections Isometric ObliqueIn isometric all distances along the major axes are the same.

Orthographic Oblique using a shear

Move x and y proportional to the depth

Page 4: CLASS 6 PERSPECTIVE CS770/870. Orthographic projections Isometric ObliqueIn isometric all distances along the major axes are the same.

To generate Oblique perspective

Cot(q) = dx/dz

Cot(f) = dy/dz

Page 5: CLASS 6 PERSPECTIVE CS770/870. Orthographic projections Isometric ObliqueIn isometric all distances along the major axes are the same.

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

Page 6: CLASS 6 PERSPECTIVE CS770/870. Orthographic projections Isometric ObliqueIn isometric all distances along the major axes are the same.

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

Page 7: CLASS 6 PERSPECTIVE CS770/870. Orthographic projections Isometric ObliqueIn isometric all distances along the major axes are the same.

Perspective. How to get the scaling

Page 8: CLASS 6 PERSPECTIVE CS770/870. Orthographic projections Isometric ObliqueIn isometric all distances along the major axes are the same.

Brunelleschi’s window

Page 9: CLASS 6 PERSPECTIVE CS770/870. Orthographic projections Isometric ObliqueIn isometric all distances along the major axes are the same.

Perspective transformation - simplified

Final step, divide x and y by ww=z/d

M = PS

Where P is the projective transformation matrix (above)

S is the Scene to Viewport mapping

Page 10: CLASS 6 PERSPECTIVE CS770/870. Orthographic projections Isometric ObliqueIn isometric all distances along the major axes are the same.

Two specifications

glFrustum (Left,Right, Bottom, Top, Near, Far);

gluPerspective(fov, aspect, near far);

Why?

Page 11: CLASS 6 PERSPECTIVE CS770/870. Orthographic projections Isometric ObliqueIn isometric all distances along the major axes are the same.

View control

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

gluLookat(vpX,vpY, vpZ, spX,spY,spZ, upX, upY, upZ);

Three ways of doing it.

Using gluLookat, or using translate and rotate, or

Using change in basis.

Page 12: CLASS 6 PERSPECTIVE CS770/870. Orthographic projections Isometric ObliqueIn isometric all distances along the major axes are the same.

Change in basis

Express one set of axes in the coordinates of another.In a simple form this is a rotation.

X

YUV

Coordinates of U,V axis As unit vectorsExpressed in X,Y system

(x,y)

Convert point (x,y) to point (u,v)

Page 13: CLASS 6 PERSPECTIVE CS770/870. Orthographic projections Isometric ObliqueIn isometric all distances along the major axes are the same.

How to get a rotation to view vectorUse basis method

(atX, atY)

(eY,eY)1) Take difference2) Normalize3) Put into matrix form v

n

Page 14: CLASS 6 PERSPECTIVE CS770/870. Orthographic projections Isometric ObliqueIn isometric all distances along the major axes are the same.

To deal with the Up Vector in 3D

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 productsSide ways vector of view coords s= uxvNew up vector n = uxs

sx sy sz

nx ny nz

vx vy vz

Useful fact: the Transpose of a rotation matrix is its inverse.

Page 15: CLASS 6 PERSPECTIVE CS770/870. Orthographic projections Isometric ObliqueIn isometric all distances along the major axes are the same.

How to fly

Keep moving the viewpoint in the direction of travel

Rotate according to the view direction.glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);glPushMatrix();

glRotatef(viewAngle*180.0/3.141592, 0,1,0);glTranslatef(-eyeX,-eyeY, -eyeZ); // to originscene();

glPopMatrix();glutSwapBuffers();

df = my*0.01; // the speed in the forward direction (my from mouse)viewAngle += mx*0.0001; // Azimuth in radiansdz = cos(viewAngle)*df; dx = sin(viewAngle)*df;eyeX += dx; eyeZ -= dz;

Page 16: CLASS 6 PERSPECTIVE CS770/870. Orthographic projections Isometric ObliqueIn isometric all distances along the major axes are the same.

Clipping Cohen Sutherland

The outcode function returns an outcode as follows

Xmin Xmax

Ymin

Ymax

bbbb

>Ymax

>Xmax< Ymin< Xmin

Page 17: CLASS 6 PERSPECTIVE CS770/870. Orthographic projections Isometric ObliqueIn isometric all distances along the major axes are the same.

Cohen Sutherland Cases

p1

p2

Let o1 be the outcode of p1

Case A: o1 = o2 = 0; Both inside, no clipping neededCase B: (o1 & 02) |= 0; all bits same same region discard

Case C: (o1 XOR 01) > 0 ; some bits different different regions, may need clipping

AB

CC

different regions, may need clipping

C