Chapter 5 Viewing.

Slides:



Advertisements
Similar presentations
Computer Graphics - Viewing -
Advertisements

1 View Shandong University Software College Instructor: Zhou Yuanfeng
1 Angel: Interactive Computer Graphics 4E © Addison-Wesley 2005 Projection Matrices modified by Ray Wisman Ed Angel Professor of Computer.
Projection Matrices CS4395: Computer Graphics 1 Mohan Sridharan Based on slides created by Edward Angel.
Based on slides created by Edward Angel
1 Angel: Interactive Computer Graphics 4E © Addison-Wesley 2005 Computer Viewing Ed Angel Professor of Computer Science, Electrical and Computer Engineering,
Projection Matrices Ed Angel
Objectives Derive the perspective projection matrices used for standard OpenGL projections Derive the perspective projection matrices used for standard.
Classical Viewing CS4395: Computer Graphics 1 Mohan Sridharan Based on slides created by Edward Angel.
1 Chapter 5 Viewing. 2 Perspective Projection 3 Parallel Projection.
Computer Graphics (fall 2009)
Transformation & Projection Feng Yu Proseminar Computer Graphics :
1 Projection Matrices. 2 Objectives Derive the projection matrices used for standard OpenGL projections Introduce oblique projections Introduce projection.
Computer Graphics I, Fall 2010 Classical Viewing.
1 Introduction to Computer Graphics with WebGL Ed Angel Professor Emeritus of Computer Science Founding Director, Arts, Research, Technology and Science.
Viewing Angel Angel: Interactive Computer Graphics5E © Addison-Wesley
1 E. Angel and D. Shreiner : Interactive Computer Graphics 6E © Addison-Wesley 2012 Classical Viewing Sai-Keung Wong ( 黃世強 ) Computer Science National.
1 Classical Viewing. 2 Objectives Introduce the classical views Compare and contrast image formation by computer with how images have been formed by architects,
C O M P U T E R G R A P H I C S Guoying Zhao 1 / 67 C O M P U T E R G R A P H I C S Guoying Zhao 1 / 67 Computer Graphics Three-Dimensional Graphics III.
Computer Graphics Bing-Yu Chen National Taiwan University.
Fundamentals of Computer Graphics Part 5 Viewing prof.ing.Václav Skala, CSc. University of West Bohemia Plzeň, Czech Republic ©2002 Prepared with Angel,E.:
1 Introduction to Computer Graphics with WebGL Ed Angel Professor Emeritus of Computer Science Founding Director, Arts, Research, Technology and Science.
CAP 4703 Computer Graphic Methods Prof. Roy Levow Chapter 5.
Demetriou/Loizidou – ACSC330 – Chapter 5 Viewing Dr. Giorgos A. Demetriou Computer Science Frederick Institute of Technology.
Computer Graphics I, Fall 2010 Computer Viewing.
Viewing and Projection. 2 3 Angel: Interactive Computer Graphics 5E © Addison-Wesley 2009  Introduce the classical views  Compare and contrast image.
CS5500 Computer Graphics March 12, 2007.
Viewing Chapter 5. CS 480/680 2Chapter 5 -- Viewing Introduction: Introduction: We have completed our discussion of the first half of the synthetic camera.
Graphics Graphics Korea University kucg.korea.ac.kr Viewing 고려대학교 컴퓨터 그래픽스 연구실.
Review on Graphics Basics. Outline Polygon rendering pipeline Affine transformations Projective transformations Lighting and shading From vertices to.
1 Angel: Interactive Computer Graphics 4E © Addison-Wesley 2005 Classical Viewing Ed Angel Professor of Computer Science, Electrical and Computer Engineering,
Classical Viewing Ed Angel Professor of Computer Science, Electrical and Computer Engineering, and Media Arts University of New Mexico.
Viewing and Projection
Classical Viewing Ed Angel Professor of Computer Science, Electrical and Computer Engineering, and Media Arts University of New Mexico.
Viewing Angel Angel: Interactive Computer Graphics5E © Addison-Wesley
CS5500 Computer Graphics March 20, Computer Viewing Ed Angel Professor of Computer Science, Electrical and Computer Engineering, and Media Arts.
1 E. Angel and D. Shreiner: Interactive Computer Graphics 6E © Addison-Wesley 2012 Computer Viewing Isaac Gang University of Mary Hardin-Baylor.
Viewing. Classical Viewing Viewing requires three basic elements - One or more objects - A viewer with a projection surface - Projectors that go from.
Viewing 고려대학교 컴퓨터 그래픽스 연구실 kucg.korea.ac.kr.
Viewing.
Computer Graphics - Chapter 5 Viewing
Computer Viewing.
Projection Our 3-D scenes are all specified in 3-D world coordinates
Isaac Gang University of Mary Hardin-Baylor
CSC461: Lecture 18 Classical Viewing
CSC461: Lecture 20 Parallel Projections in OpenGL
Projections and Normalization
CSC461: Lecture 19 Computer Viewing
Classical Viewing Ed Angel
Introduction to Computer Graphics with WebGL
Introduction to Computer Graphics with WebGL
Viewing Chapter 5.
Isaac Gang University of Mary Hardin-Baylor
Introduction to Computer Graphics with WebGL
Isaac Gang University of Mary Hardin-Baylor
Projections and Hidden Surface Removal
Introduction to Computer Graphics with WebGL
Introduction to Computer Graphics with WebGL
Viewing (Projections)
University of New Mexico
Viewing (Projections)
Computer Graphics Computer Viewing
Computer Viewing Ed Angel Professor Emeritus of Computer Science
PROJECTIONS KOYEL DATTA GUPTA.
University of New Mexico
Isaac Gang University of Mary Hardin-Baylor
Viewing and Projection
Viewing and Projection
Presentation transcript:

Chapter 5 Viewing

OpenGL Perspective Matrix planar geometric projections parallel perspective 1 point 2 point 3 point multiview orthographic axonometric oblique isometric dimetric trimetric

Perspective Projection

Parallel Projection

Classical Viewing Viewing requires three basic elements One or more objects A viewer with a projection surface Projectors that go from the object(s) to the projection surface Classical views are based on the relationship among these elements The viewer picks up the object and orients it how she would like to see it Each object is assumed to constructed from flat principal faces Buildings, polyhedra, manufactured objects

Planar Geometric Projections Standard projections project onto a plane Projectors are lines that either converge at a center of projection are parallel Such projections preserve lines but not necessarily angles

Classical Projections

Orthographic Projection Projectors are orthogonal to projection surface

Multiview Orthographic Projection Projection plane parallel to principal face Usually form front, top, side views isometric (not multiview orthographic view) front in CAD and architecture, we often display three multiviews plus isometric side top

Advantages and Disadvantages Preserves both distances and angles Shapes preserved Can be used for measurements Building plans Manuals Cannot see what object really looks like because many surfaces hidden from view Often we add the isometric

Axonometric Projections Allow projection plane to move relative to object classify by how many angles of a corner of a projected cube are the same none: trimetric two: dimetric three: isometric q 1 q 2 q 3

Types of Axonometric Projections

Construction of Axonometric Projections Projectors are still orthogonal to the projection plane, but Projection plane can have any orientation w.r.t. the object

Advantages and Disadvantages Lines are scaled (foreshortened) but can find scaling factors Lines preserved but angles are not Projection of a circle in a plane not parallel to the projection plane is an ellipse Can see three principal faces of a box-like object Some optical illusions possible Parallel lines appear to diverge Does not look real because far objects are scaled the same as near objects Used in CAD applications

Oblique Projection Arbitrary relationship between projectors and projection plane

Advantages and Disadvantages Can pick the angles to emphasize a particular face In physical world, cannot create with simple camera; possible with bellows camera or special lens (architectural)

Perspective Projection Projectors coverge at center of projection

Vanishing Points Parallel lines (not parallel to the projection plan) on the object converge at a single point in the projection (the vanishing point) Drawing simple perspectives by hand uses these vanishing point(s) vanishing point

Three-Point Perspective No principal face parallel to projection plane Three vanishing points for cube

Two-Point Perspective On principal direction parallel to projection plane Two vanishing points for cube

One-Point Perspective One principal face parallel to projection plane One vanishing point for cube

Advantages and Disadvantes Objects further from viewer are projected smaller than the same sized objects closer to the viewer (diminuition) Looks realistic Equal distances along a line are not projected into equal distances (nonuniform foreshortening) Angles preserved only in planes parallel to the projection plane More difficult to construct by hand than parallel projections (but not more difficult by computer)

Computer Viewing There are three aspects of the viewing process, all of which are implemented in the pipeline, Positioning the camera Setting the model-view matrix Selecting a lens Setting the projection matrix Clipping Setting the view volume

The OpenGL Camera In OpenGL, initially the world and camera frames are the same Default model-view matrix is an identity The camera is located at origin and points in the negative z direction OpenGL also specifies a default view volume that is a cube with sides of length 2 centered at the origin Default projection matrix is an identity

Default Projection Default projection is orthogonal clipped out z=0

Moving the Camera Frame If we want to visualize object with both positive and negative z values we can either Move the camera in the positive z direction Translate the camera frame Move the objects in the negative z direction Translate the world frame Both of these views are equivalent and are determined by the model-view matrix Want a translation (glTranslatef(0.0,0.0,-d);) d > 0

Moving Camera Back from Origin frames after translation by –d d > 0 default frames

Moving the Camera (Object) We can move the camera to any desired position by a sequence of rotations and translations Example: positive x (side view of an object) Rotate the camera Move it away from origin Model-view matrix C = TR

OpenGL Code Remember that last transformation specified is first to be applied glMatrixMode(GL_MODELVIEW) glLoadIdentity(); glTranslatef(0.0, 0.0, -d); glRotatef(90.0, 0.0, 1.0, 0.0); We are changing the modelview matrix C. A vertex specified at q through glVertex, after the change is still at q in the world frame, but is at Cq in the camera frame known internally to OpenGL.

Manually Generating an Isometric View – 1/3 Rotating about the y axis by 45o Rotating about the x axis by 35.26o Translating along the z direction by d y y 2 2  z z

Manually Generating an Isometric View – 2/3

Manually Generating an Isometric View – 3/3 glMatrixMode(GL_MODELVIEW); glLoadIdentity(); glTranslatef(0.0, 0.0, -d); glRotatef(35.26, 1.0, 0.0, 0.0); glRotate(45.0, 0.0, 1.0, 0.0);

The LookAt Function – 1/2 The GLU library contains the function glLookAt to from the required modelview matrix through a simple interface Note the need for setting an up direction Still need to initialize Can concatenate with modeling transformations Example: isometric view of cube aligned with axes glMatrixMode(GL_MODELVIEW): glLoadIdentity(); gluLookAt(-1.0, 1.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0);

The LookAt Function – 2/2 glLookAt(eyex, eyey, eyez, atx, aty, atz, upx, upy, upz)

Other Viewing APIs – 1/2 The LookAt function is only one possible API for positioning the camera Others include View reference point, view plane normal, view up (PHIGS, GKS-3D) Yaw, pitch, roll Elevation, azimuth, twist Direction angles

Other Viewing APIs – 2/2

Simple Perspective Center of projection at the origin Projection plane z = d, d < 0

Perspective Equations Consider top and side views xp = yp = zp = d

Homogeneous Coordinate Form consider q = Mp where M = q =  p =

Perspective Division However w  1, so we must divide by w to return from homogeneous coordinates This perspective division yields the desired perspective equations We will consider the corresponding clipping volume with the OpenGL functions xp = yp = zp = d

Orthogonal Projections The default projection in the eye (camera) frame is orthogonal For points within the default view volume Most graphics systems use view normalization All other views are converted to the default view by transformations that determine the projection matrix Allows use of the same pipeline for all views xp = x yp = y zp = 0

Homogeneous Coordinate Representation xp = x yp = y zp = 0 wp = 1 pp = Mp M = In practice, we can let M = I and set the z term to zero later

Projections in OpenGL

OpenGL Perspective glFrustum(xmin,xmax,ymin,ymax,near,far)

Using Field of View With glFrustum it is often difficult to get the desired view gluPerpective(fovy, aspect, near, far) often provides a better interface front plane aspect = w/h

OpenGL Orthogonal Viewing glOrtho(xmin,xmax,ymin,ymax,near,far) glOrtho(left,right,bottom,top,near,far) near and far measured from camera

Hidden-Surface Removal

Z-Buffer Algorithm Keep track of the smallest depth or z value for each pixel Z value is initialized to the farthest distance Worst-case time complexity is O(n), where n is the number of polygons glutInitDisplayMode(GLUT_DEPTH); glEnable(GL_DEPTH_TEST); glClear(GL_DEPTH_BUFFER_BIT);

Culling Removing all the faces pointing away from the viewer. For example, rendering n cubes with culling can filter 3n polygons glEnable(GL_CULL);

Walking Through a Scene – 1/3 void keys(unsigned char key, int x, int y) { if(key==‘x’) viewer[0]-=1.0; if(key==‘X’) viewer[0]+=1.0; if(key==‘y’) viewer[1]-=1.0; if(key==‘Y’) viewer[1]+=1.0; if(key==‘z’) viewer[2]-=1.0; if(key==‘Z’) viewer[2]+=1.0; glutPostRedisplay(); }

Walking Through a Scene – 2/3 void display(void) { glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glLoadIdentity(); gluLookAt(viewer[0],viewer[1],viewer[2],0.0,0.0,0.0,0.0,1.0,0.0); glRotatef(theta[0],1.0,0.0,1.0); glRotatef(theta[1],0.0,1.0,0.0); glRotatef(theta[2],0.0,0.0,1.0); colorcube(); glFlush(); glutSwapBuffers(); }

Walking Through a Scene – 3/3 void myReshape(int w, int h) { glViewport(0, 0, w, h); glMatrixMode(GL_PROJECTION); glLoadIdentity(); if(w<=h) glFrustum(-2.0, 2.0, -2.0*(GLfloat)h/(GLfloat)w, 2.0*(GLfloat)h/(GLfloat)w, 2.0, 20.0); else glFrustum(-2.0, 2.0, -2.0*(GLfloat)w/(GLfloat)h, 2.0*(GLfloat)w/(GLfloat)h, 2.0, 20.0); glMatrixMode(GL_MODELVIEW); }

Parallel-Projection Matrices Orthographic projection of distorted object Perspective View

Normalization Rather than derive a different projection matrix for each type of projection, we can convert all projections to orthogonal projections with the default view volume This strategy allows us to use standard transformations in the pipeline and makes for efficient clipping

Pipeline View modelview transformation projection transformation perspective division 4D  3D nonsingular clipping projection 3D  2D against default cube

Notes We stay in four-dimensional homogeneous coordinates through both the modelview and projection transformations Both these transformations are nonsingular Default to identity matrices (orthogonal view) Normalization lets us clip against simple cube regardless of type of projection Delay final projection until end Important for hidden-surface removal to retain depth information as long as possible

Orthogonal Normalization glOrtho(left,right,bottom,top,near,far) -1 1 -1 1 -1 1 normalization  find transformation to convert specified clipping volume to default Canonical view volume

Orthogonal Matrix Scale to have sides of length 2 Two steps Move center to origin T(-(left+right)/2, -(bottom+top)/2,(near+far)/2)) Scale to have sides of length 2 S(2/(left-right),2/(top-bottom),2/(near-far)) P = ST =

Final Projection Set z =0 Equivalent to the homogeneous coordinate transformation Hence, general orthogonal projection in 4D is Morth = P = MorthST

Oblique Projections The OpenGL projection functions cannot produce general parallel projections such as However if we look at the example of the cube it appears that the cube has been sheared Oblique Projection = Shear + Orthogonal Projection

General Shear top view side view

Shear Matrix xy shear (z values unchanged) Projection matrix General case: H(q,f) = P = Morth H(q,f) P = Morth STH(q,f)

Equivalency

Effect on Clipping The projection matrix P = STH transforms the original clipping volume to the default clipping volume object top view z = 1 DOP DOP x = -1 x = 1 far plane z = -1 clipping volume near plane distorted object (projects correctly)

Simple Perspective Consider a simple perspective with the COP at the origin, the near clipping plane at z = -1, and a 90 degree field of view determined by the planes x = z, y = z

Perspective Matrices Simple projection matrix in homogeneous coordinates (z=-1, and the center of projection is at the origin) Note that this matrix is independent of the far clipping plane M =

Generalization after persepective divison, the point (x, y, z, 1) goes to Let N = x’’ = -x/z y’’ = -y/z z’’ = -(a+b/z) If we apply an orthographic projection along the z-axis to N, we get: MorthN= And the projection of an arbitrary point p is, p’=MorthNp = , after perspective division: xp = -x/z yp = -y/z We get the same result regardless of a and b!

Picking a and b If we pick the zmin plane is mapped to z = -1 the zmax plane is mapped to z =1 and the sides are mapped to x =  1, y =  1 Hence the new clipping volume is the default clipping volume

Normalization Transformation distorted object projects correctly original clipping volume original object new clipping volume

Normalization and Hidden-Surface Removal Although our selection of the form of the perspective matrices may appear somewhat arbitrary, it was chosen so that if z1 > z2 in the original clipping volume then the for the transformed points z1’ > z2’ Thus we hidden surface removal works if we first apply the normalization transformation However, the formula z’’ = -(a+b/z) implies that the distances are distorted by the normalization which can cause numerical problems especially if the near distance is small

OpenGL Perspective glFrustum allows for an unsymmetric viewing frustum (although gluPerspective does not)

OpenGL Perspective Matrix The normalization in glFrustum requires an initial shear to form a right viewing pyramid, followed by a scaling to get the normalized perspective volume. Finally, the perspective matrix results in needing only a final orthogonal transformation P = NSH our previously defined perspective matrix shear and scale

Normalization Details Shear the point of ((xmin+xmax)/2,(ymin+ymax)/2, zmax) to (0, 0, zmax) z z=zmax So the resulting frustum is described by the planes: z=zmin  x Next, scale the volume so that x=z, y= z, so the scaling matrix is: S(2zmax/(xmax-xmin),2zmax/(ymax-ymin),1) Finally, we make use of the previous N.

Why do we do it this way? Normalization allows for a single pipeline for both perspective and orthogonal viewing We keep in four dimensional homogeneous coordinates as long as possible to retain three-dimensional information needed for hidden-surface removal and shading We simplify clipping

Projections and Shadows Idea: put the projection plane behind the object! For example, in this figure, assume (xl, yl, zl) is a light source, then we can set the projection plane on the plane of y=0

Implementing Shadows – 1/2 Move the light source to the origin by a translation:T(-xl, -yl, -zl), then we could use a simple perspective projection through the origin, the projection matrix is Finally we translate everything back.

Implementing Shadows – 2/2 GLfloat m[16]; /* shadow projection matrix */ For(i=0;i<15;i++) m[i]=0.0; m[0]=m[5]=m[10]=1.0; m[7]=-1.0/yl; glColor3fv(polygon_color); glBegin(GL_POLYGON); . /* draw polygon normally */ . glEnd(); glMatrixMode(GL_MODELVIEW); glPushMatrix(); glTranslatef(xl, yl, zl); glMultMatrixf(m); glTranslate(-xl, -yl, -zl); glColor3fv(shadow_color); glBegin(GL_POLYGON); . /* draw the polygon again */ . glEnd(); glPopMatrix(); /* restore state */ This works if objects cannot cast shadows on other objects!

Summary and Notes Classical Viewing Parallel Projection versus Perspective Projection OpenGL Projections Projection Normalization Shadows