Viewing Chapter 5.

Slides:



Advertisements
Similar presentations
Computer Graphics - Viewing -
Advertisements

1 View Shandong University Software College Instructor: Zhou Yuanfeng
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,
CS 352: Computer Graphics Chapter 5: Viewing. Interactive Computer GraphicsChapter Overview Specifying the viewpoint Specifying the projection Types.
Classical Viewing CS4395: Computer Graphics 1 Mohan Sridharan Based on slides created by Edward Angel.
CS 4731: Computer Graphics Lecture 11: 3D Viewing Emmanuel Agu.
1 Chapter 5 Viewing. 2 Perspective Projection 3 Parallel Projection.
Introduction to 3D viewing 3D is just like taking a photograph!
Computer Graphics (fall 2009)
Advanced Computer Graphics Three Dimensional Viewing
Computer Graphics I, Fall 2010 Classical Viewing.
CS559: Computer Graphics Lecture 9: Projection Li Zhang Spring 2008.
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.
Chapter 5 Viewing.
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.:
Homogeneous Form, Introduction to 3-D Graphics Glenn G. Chappell U. of Alaska Fairbanks CS 381 Lecture Notes Monday, October 20,
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 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.
Chapters 5 2 March Classical & Computer Viewing Same elements –objects –viewer –projectors –projection plane.
©2005, Lee Iverson Lee Iverson UBC Dept. of ECE EECE 478 Viewing and Projection.
Viewing Chapter 5. CS 480/680Chapter 5 -- Viewing2 n Introduction: -We have completed our discussion of the first half of the synthetic camera model specifying.
Graphics CSCI 343, Fall 2015 Lecture 16 Viewing I
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.
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.
CS 490: Computer Graphics Chapter 5: Viewing. Interactive Computer GraphicsChapter Overview Specifying the viewpoint Specifying the projection Types.
Viewing 고려대학교 컴퓨터 그래픽스 연구실 kucg.korea.ac.kr.
Viewing.
Computer Graphics - Chapter 5 Viewing
Computer Viewing.
Isaac Gang University of Mary Hardin-Baylor
CSCE 441 Computer Graphics 3-D Viewing
CSC461: Lecture 18 Classical Viewing
CSC461: Lecture 20 Parallel Projections in OpenGL
Modeling 101 For the moment assume that all geometry consists of points, lines and faces Line: A segment between two endpoints Face: A planar area bounded.
Unit 4 3D Viewing Pipeline Part - 2
Projections and Normalization
CSC461: Lecture 19 Computer Viewing
Classical Viewing Ed Angel
Isaac Gang University of Mary Hardin-Baylor
Fundamentals of Computer Graphics Part 5 Viewing
Introduction to Computer Graphics with WebGL
Three Dimensional Viewing
CSC4820/6820 Computer Graphics Algorithms Ying Zhu Georgia State University View & Projection.
Projections and Hidden Surface Removal
Chap 3 Viewing Pipeline Reading:
Viewing (Projections)
University of New Mexico
Viewing (Projections)
Interactive Computer Graphics Viewing
Computer Graphics Computer Viewing
THREE-DIMENSIONAL VIEWING II
Computer Viewing Ed Angel Professor Emeritus of Computer Science
University of New Mexico
Isaac Gang University of Mary Hardin-Baylor
CS 352: Computer Graphics Chapter 5: Viewing.
Presentation transcript:

Viewing Chapter 5

Introduction: We have completed our discussion of the first half of the synthetic camera model specifying objects in three dimensions We now investigate the multitude of ways in which we can describe our virtual camera. First, we look at the types of views we can create, and why we need more than one type of view. Then we examine how an application viewer can create a particular view in within OpenGL. CS 480/680 Chapter 5 -- Viewing

1. Classical and Computer Viewing Before looking at the interface between computer-graphics systems and application programmers for 3D viewing, we take a slight diversion to consider classical viewing. There are two reasons to do this First, many jobs that were formerly done by hand drawing - such as animation in movies, architectural rendering, .. Are now done routinely with the aid of compute graphics. Practitioners of these fields need to produce classical views. CS 480/680 Chapter 5 -- Viewing

Second, the relationship between classical and computer viewing shows many advantages of, and a few difficulties with, the approach used by most APIs. When we introduced the synthetic camera model in Chapter 1, we covered some elements: objects, viewers, projectors, and a projection plane The projectors meet at the center of projection (COP) this corresponds to the center of the lens in the camera, or in the eye CS 480/680 Chapter 5 -- Viewing

Both classical and computer graphics allow the viewer to be an infinite distance from the objects Note, as we move the COP to infinity, the projectors become parallel and the COP can be replaced with a direction of projection (DOP) CS 480/680 Chapter 5 -- Viewing

This seeming discrepancy arises because Although computer graphics systems have two fundamental types of viewing (parallel and perspective), classical graphics appears to permit a host of different views ranging from: multiview orthographic projections, one- two- and three-point perspectives This seeming discrepancy arises because in classical graphics due to the desire to show a specific relationship among an object, the viewer, and the projection plane as opposed to the computer graphics approach of complete independence of all specifications CS 480/680 Chapter 5 -- Viewing

1.1 Classical Viewing When an architect draws an image of a building, they know which sides they wish to display, and thus where they should place the viewer Each classical view is determined by a specific relationship between the objects and the viewer. CS 480/680 Chapter 5 -- Viewing

1.2 Orthographic Projections The classical Orthographic projection Multiview Orthographic projections CS 480/680 Chapter 5 -- Viewing

1.3 Axonometric Projections If we allow the projection plane to be at any angle (not just parallel with a face of the object) we end up with an axonometric view. Some special cases: CS 480/680 Chapter 5 -- Viewing

1.4 Oblique Projections These are the most general parallel views projectors can make an arbitrary angle with the projection plane. CS 480/680 Chapter 5 -- Viewing

1.5 Perspective Viewing All perspective views are characterized by diminution of size. (the farther away, the smaller they are) CS 480/680 Chapter 5 -- Viewing

2. Viewing with a Computer We can now return to 3D graphics from a computer perspective We have the choice in OpenGL of a perspective camera or an orthogonal one. In terms of the pipeline architecture, viewing consists of two fundamental operations: First we must position the camera The second is the application of the projection transformation But let’s review the default camera CS 480/680 Chapter 5 -- Viewing

OpenGL starts with the camera at the origin, pointing in the negative z direction. set up for orthogonal vies a viewing volume that is a cube centered at the origin, with sides length 2 clipped out z=0 CS 480/680 Chapter 5 -- Viewing

3. Positioning of the Camera We now examine the API that OpenGL provides for three-dimensional graphics, and show how other APIs differ In this section we deal with positioning the camera. In Section 5.4 we discuss how we specify the desired projection. CS 480/680 Chapter 5 -- Viewing

In OpenGL, the model-view and projection matrices are concatenated together to form the matrix that applies to geometric entities such as vertices. We have seen how to use the model-view matrix to position objects in space. The other is to convert from the reference frame used for modeling to the frame of the camera CS 480/680 Chapter 5 -- Viewing

3.1 Positioning of 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);) With d > 0 CS 480/680 Chapter 5 -- Viewing

Default Frames: initially the camera is at the origin Frames after translation of -d (d>0) CS 480/680 Chapter 5 -- Viewing

At any given time, the state of the model-view matrix encapsulates the relation between the camera frame and the world frame. Although combining the modeling and viewing transformations into a single matrix may initially cause confusion, on closer examination this approach is a good one. The obvious next problems are how we specify the desired position of the camera and how we implement camera positioning in OpenGL CS 480/680 Chapter 5 -- Viewing

We will outline three approaches to this. Here, we find it convenient to think in terms of moving the default camera relative to the world frame. We will outline three approaches to this. One is given in this section, and two others in 5.3.2 (two more are exercises at the end of the chapter) The First Approach: Specify the position indirectly by applying a sequence of rotations and translations to the model-view matrix This is a direct application of the instance transformations we presented in Chapter 4 CS 480/680 Chapter 5 -- Viewing

We must be careful for two reasons: First, we usually want to define the camera before we position the objects in the scene. Second, transformations on the camera may appear to be backward from what we might expect. CS 480/680 Chapter 5 -- Viewing

Here is how to do a side view, Rotate the camera Move it away from origin Model-view matrix C = TR CS 480/680 Chapter 5 -- Viewing

Remember that last transformation specified is first to be applied 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) CS 480/680 Chapter 5 -- Viewing

3.2 Two Viewing APIs We can take a different approach to positioning the camera an approach used by PHIGS, and GKS-3D (two of the original standards in 3D) We describe the camera’s position and orientation in the world frame It’s desired location is centered at the view-reference point (VRP) It’s orientation is specified with the view-plane normal (VPN) and the view-up vector (VUP) CS 480/680 Chapter 5 -- Viewing

2.3 The Look-At Function The use of the VRP, VPN, and VUP is but one way to provide an API for specifying the position of a camera. In many situations, a more direct method is appropriate. gluLookAt(eyex, eyey, eyez, atx, aty, atz, upx, upy, upz); CS 480/680 Chapter 5 -- Viewing

2.4 Other Viewing APIs In many applications, neither of the viewing interfaces that we have presented is appropriate. Consider a flight simulator: The pilot worries about roll, pitch, and yaw CS 480/680 Chapter 5 -- Viewing

Viewing in many applications is most naturally specified in polar coordinates -- rather than rectilinear coordinates. Applications involving objects that rotate about other objects fit this category. CS 480/680 Chapter 5 -- Viewing

4. Simple Projections With a real camera, once we position it, we still must select a lens. In computer graphics we select the type of lens and the size of the film by selecting the type of projection and the viewing parameters. Most APIs distinguish between parallel and perspective views by providing different functions for the two cases. In OpenGL we can set the projection matrix with a glLoadMatrix function, or we can other functions for the most common viewing conditions CS 480/680 Chapter 5 -- Viewing

4.1 Perspective Projections Suppose that we are in the camera frame with the camera located at the origin pointed in the negative z direction. CS 480/680 Chapter 5 -- Viewing

As we saw in Chapter 2, we can place the projection plane in front of the center of projection. Center of projection at the origin Projection plane z = d, d < 0 CS 480/680 Chapter 5 -- Viewing

Consider top and side views xp = x/(z/d) yp = y/(z/d) zp = d CS 480/680 Chapter 5 -- Viewing

Although the perspective transformation preserves lines, it is not Affine It is also irreversible (because all points along a projector project to the same point) We can, however, modify slightly our use of homogenous coordinates to handle projections. CS 480/680 Chapter 5 -- Viewing

4.2 Orthogonal Projections Orthogonal or orthographic projections are a special case of parallel projections, in which the projectors are perpendicular to the view of the plane. CS 480/680 Chapter 5 -- Viewing

4. Projections in OpenGL The projections we just developed did not take into account the properties of the camera: the focal length of its lens, the size of the film plane View Volume CS 480/680 Chapter 5 -- Viewing

Most graphics APIs define clipping parameters through the specification of a projection. The resulting view volume is a frustum -- which is a truncated pyramid. CS 480/680 Chapter 5 -- Viewing

4.1 Perspectives in OpenGL In OpenGL we have two functions for specifying perspective views and one for specifying parallel views. We can specify our camera view by: glFrustrum(xmin, xmax, ymin, ymax, near, far) CS 480/680 Chapter 5 -- Viewing

Because the projection matrix determined by these specifications multiplies the present matrix, we must first select the matrix mode. A typical sequence is glMatrixMode(GL_PROJECTION); glLoadIdentity( ); glFrustrum(xmin, xmax, ymin, ymax, near, far); CS 480/680 Chapter 5 -- Viewing

gluPerspective(fovy, aspect, near, far); In many applications, it is natural to specify the angle or field of view gluPerspective(fovy, aspect, near, far); front plane aspect = w/h CS 480/680 Chapter 5 -- Viewing

4.2 Parallel Viewing in OpenGL The only parallel-viewing function provided by OpenGL is the orthographic viewing function glOrtho(xmin, xmax, ymin, ymax, near, far) near and far measured from camera CS 480/680 Chapter 5 -- Viewing

5. Hidden-Surface Removal Hidden surface removal algorithms can be divided into two broad classes: Object-space algorithms attempt to order the surfaces of the objects in the scene such that drawing surfaces in a particular order provides the correct image. Image-space algorithms work as part of the projection process and seek to determine the relationship among object points on each projector z-buffer fits into this category. CS 480/680 Chapter 5 -- Viewing

The major advantage of z-buffer is that its worst case complexity is proportional to the number of polygons. It can be implemented with a small number of additional calculations over what we have to do anyway. Typically you use these functions: glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH); glEnable(GL_DEPTH_TEST); glClear(GL_DEPTH_BUFFER_BIT); CS 480/680 Chapter 5 -- Viewing

6.1 Culling For a convex object, such as the cube, we could simply remove all the faces pointing away from the viewer, and render only the ones facing the viewer. (we will look at this mroe in Chapter 8) In OpenGL we turn on culling by simply enabling it glEnable(GL_CULL); However, culling works only if we have a convex object. Often we can use culling in addition to the z-buffer algoritm CS 480/680 Chapter 5 -- Viewing

7. Walking Through a Scene Let us modify the version of our color-cube program from Chapter 4 Old Version: the cube rotated about the origin. Orthographic projection In this version perspective projection allow the camera to move. CS 480/680 Chapter 5 -- Viewing

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; } CS 480/680 Chapter 5 -- Viewing

glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glLoadIdentity( ); 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, 0.0); glRotatef(theta[1], 0.0, 1.0, 0.0); glRotatef(theta[2], 0.0, 0.0, 1.0); colorcube( ); glFlush( ); glutSwapBuffers( ); } CS 480/680 Chapter 5 -- Viewing

void myReshape(int w, int h) { glViewport(0,0,w,h); glLoadMatrix(GL_PROJECTION); glLoadIdentity( ); if(w<=h) glFrustrum(-2.0, 2.0, -2.0 * (Glfloat)h/(Glfloat)w, 2.0*(Glfloat(h)/(Glfloat)w, 2.0, 20.0); else glFrustrum(-2.0, 2.0, -2.0 * (Glfloat)w/(Glfloat)h, 2.0*(Glfloat)w/(Glfloat)h, 2.0, 20.0); glMatrixMode(GL_MODELVIEW); } CS 480/680 Chapter 5 -- Viewing

8. Parallel-Projection Matrices CS 480/680 Chapter 5 -- Viewing

9. Perspective-Projection Matrices CS 480/680 Chapter 5 -- Viewing

10. Projections and Shadows The creation of simple shadows is an interesting application of projection matrices. This section covers how to re-project the polygon casting the shadow onto the ground this re-projection is called a shadow polygon. CS 480/680 Chapter 5 -- Viewing

For a simple environment, this technique works well, however, when objects cast shadows on other objects, this method becomes impractical. In Chapter 9 we address a more general shadow-creation method that requires more work. CS 480/680 Chapter 5 -- Viewing

11. Summary We have come a long way. We can now write complete, nontrivial, three dimensional applications. Probably the most instructive activity that you can do now is to write such an application. In Chapter 6 we consider the interaction of light with the materials that characterize our objects. CS 480/680 Chapter 5 -- Viewing

11. Suggested Readings Foley (90), Watt (93) and Hern&Baker (94) derive canonical projection transformations All follow the PHIGS orientation, so the API is slightly different from the one used here. Most differ in whether they use column or row matrices, in where the COP is located, and in whether the projection is in the positive or negative z direction. See the OpenGL Programmer’s Guide (97) for further discussion of the use of the model-view and projection matrices CS 480/680 Chapter 5 -- Viewing

Exercises -- Due next class CS 480/680 Chapter 5 -- Viewing