Presentation is loading. Please wait.

Presentation is loading. Please wait.

Viewing Chapter 5. CS 480/680 2Chapter 5 -- Viewing Introduction: Introduction: We have completed our discussion of the first half of the synthetic camera.

Similar presentations


Presentation on theme: "Viewing Chapter 5. CS 480/680 2Chapter 5 -- Viewing Introduction: Introduction: We have completed our discussion of the first half of the synthetic camera."— Presentation transcript:

1 Viewing Chapter 5

2 CS 480/680 2Chapter 5 -- Viewing Introduction: Introduction: We have completed our discussion of the first half of the synthetic camera model We have completed our discussion of the first half of the synthetic camera model specifying objects in three dimensions specifying objects in three dimensions We now investigate the multitude of ways in which we can describe our virtual camera. 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. 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. Then we examine how an application viewer can create a particular view in within OpenGL.

3 CS 480/680 3Chapter 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. 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 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. 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. Practitioners of these fields need to produce classical views.

4 CS 480/680 4Chapter 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. 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: When we introduced the synthetic camera model in Chapter 1, we covered some elements: objects, viewers, projectors, and a projection plane objects, viewers, projectors, and a projection plane The projectors meet at the center of projection (COP) The projectors meet at the center of projection (COP) this corresponds to the center of the lens in the camera, or in the eye this corresponds to the center of the lens in the camera, or in the eye

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

6 CS 480/680 6Chapter 5 -- Viewing Although computer graphics systems have two fundamental types of viewing Although computer graphics systems have two fundamental types of viewing (parallel and perspective), (parallel and perspective), classical graphics appears to permit a host of different views ranging from: classical graphics appears to permit a host of different views ranging from: multiview orthographic projections, one- two- and three- point perspectives multiview orthographic projections, one- two- and three- point perspectives This seeming discrepancy arises because 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 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 as opposed to the computer graphics approach of complete independence of all specifications

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

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

9 CS 480/680 9Chapter 5 -- Viewing 1.3 Axonometric Projections 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. 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: Some special cases:

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

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

12 CS 480/680 12Chapter 5 -- Viewing 2. Viewing with a Computer We can now return to 3D graphics from a computer perspective 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. 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: In terms of the pipeline architecture, viewing consists of two fundamental operations: First we must position the camera First we must position the camera The second is the application of the projection transformation The second is the application of the projection transformation But let’s review the default camera But let’s review the default camera

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

14 CS 480/680 14Chapter 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 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 this section we deal with positioning the camera. In Section 5.4 we discuss how we specify the desired projection. In Section 5.4 we discuss how we specify the desired projection.

15 CS 480/680 15Chapter 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. 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 We have seen how to use the model-view matrix to position objects in space. to position objects in space. The other is to convert from the reference frame used for modeling to the frame of the camera The other is to convert from the reference frame used for modeling to the frame of the camera

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

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

18 CS 480/680 18Chapter 5 -- Viewing At any given time, the state of the model-view matrix encapsulates the relation between the camera frame and the world frame. 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. 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 The obvious next problems are how we specify the desired position of the camera and how we implement camera positioning in OpenGL

19 CS 480/680 19Chapter 5 -- Viewing Here, we find it convenient to think in terms of moving the default camera relative to the world frame. 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. 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) 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: The First Approach: Specify the position indirectly by applying a sequence of rotations and translations to the model-view matrix 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 This is a direct application of the instance transformations we presented in Chapter 4

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

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

22 CS 480/680 22Chapter 5 -- Viewing OpenGL Code OpenGL Code Remember that last transformation specified is first to be applied Remember that last transformation specified is first to be applied glMatrixMode(GL_MODELVIEW); glMatrixMode(GL_MODELVIEW); glLoadIdentity( ); glLoadIdentity( ); glTranslatef(0.0, 0.0, -d); glTranslatef(0.0, 0.0, -d); glRotatef(-90.0, 0.0, 1.0, 0.0) glRotatef(-90.0, 0.0, 1.0, 0.0)

23 CS 480/680 23Chapter 5 -- Viewing 3.2 Two Viewing APIs 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 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 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 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) It’s orientation is specified with the view-plane normal (VPN) and the view-up vector (VUP)

24 CS 480/680 24Chapter 5 -- Viewing 2.3 The Look-At Function 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. 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. In many situations, a more direct method is appropriate. gluLookAt(eyex, eyey, eyez, atx, aty, atz, upx, upy, upz); gluLookAt(eyex, eyey, eyez, atx, aty, atz, upx, upy, upz);

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

26 CS 480/680 26Chapter 5 -- Viewing Viewing in many applications is most naturally specified in polar coordinates -- rather than rectilinear coordinates. 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. Applications involving objects that rotate about other objects fit this category.

27 CS 480/680 27Chapter 5 -- Viewing 4. Simple Projections With a real camera, once we position it, we still must select a lens. 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. 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. 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 In OpenGL we can set the projection matrix with a glLoadMatrix function, or we can other functions for the most common viewing conditions

28 CS 480/680 28Chapter 5 -- Viewing 4.1 Perspective Projections 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. Suppose that we are in the camera frame with the camera located at the origin pointed in the negative z direction.

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

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

31 CS 480/680 31Chapter 5 -- Viewing Although the perspective transformation preserves lines, it is not Affine 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) 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. We can, however, modify slightly our use of homogenous coordinates to handle projections.

32 CS 480/680 32Chapter 5 -- Viewing 4.2 Orthogonal Projections 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. Orthogonal or orthographic projections are a special case of parallel projections, in which the projectors are perpendicular to the view of the plane.

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

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

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

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

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

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

39 CS 480/680 39Chapter 5 -- Viewing 5. Hidden-Surface Removal Hidden surface removal algorithms can be divided into two broad classes: Hidden surface removal algorithms can be divided into two broad classes: Object-space algorithms 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. 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 Image-space algorithms work as part of the projection process and seek to determine the relationship among object points on each projector 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. z-buffer fits into this category.

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

41 CS 480/680 41Chapter 5 -- Viewing 6.1 Culling 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) 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 In OpenGL we turn on culling by simply enabling it glEnable(GL_CULL); glEnable(GL_CULL); However, culling works only if we have a convex object. However, culling works only if we have a convex object. Often we can use culling in addition to the z-buffer algoritm Often we can use culling in addition to the z-buffer algoritm

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

43 CS 480/680 43Chapter 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 == ‘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 == ‘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; if(key == ‘Z’) viewer[2] += 1.0; if(key == ‘Z’) viewer[2] += 1.0;}

44 CS 480/680 44Chapter 5 -- Viewing void display(void) { glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glLoadIdentity( ); glLoadIdentity( ); gluLookAt(viewer[0], viewer[1], viewer[2], gluLookAt(viewer[0], viewer[1], viewer[2], 0.0, 0.0, 0.0, 0.0, 1.0, 0.0); 0.0, 0.0, 0.0, 0.0, 1.0, 0.0); glRotatef(theta[0], 1.0, 0.0, 0.0); glRotatef(theta[0], 1.0, 0.0, 0.0); glRotatef(theta[1], 0.0, 1.0, 0.0); glRotatef(theta[1], 0.0, 1.0, 0.0); glRotatef(theta[2], 0.0, 0.0, 1.0); glRotatef(theta[2], 0.0, 0.0, 1.0); colorcube( ); colorcube( ); glFlush( ); glFlush( ); glutSwapBuffers( ); glutSwapBuffers( );}

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

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

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

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

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

50 CS 480/680 50Chapter 5 -- Viewing 11. Summary We have come a long way. We have come a long way. We can now write complete, nontrivial, three dimensional applications. 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. 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. In Chapter 6 we consider the interaction of light with the materials that characterize our objects.

51 CS 480/680 51Chapter 5 -- Viewing 11. Suggested Readings Foley (90), Watt (93) and Hern&Baker (94) derive canonical projection transformations 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. 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. 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 See the OpenGL Programmer’s Guide (97) for further discussion of the use of the model-view and projection matrices

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


Download ppt "Viewing Chapter 5. CS 480/680 2Chapter 5 -- Viewing Introduction: Introduction: We have completed our discussion of the first half of the synthetic camera."

Similar presentations


Ads by Google