CS5500 Computer Graphics March 20, 2006. Computer Viewing Ed Angel Professor of Computer Science, Electrical and Computer Engineering, and Media Arts.

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
1 Angel: Interactive Computer Graphics 4E © Addison-Wesley 2005 Representation Ed Angel Professor of Computer Science, Electrical and Computer Engineering,
Objectives Derive the perspective projection matrices used for standard OpenGL projections Derive the perspective projection matrices used for standard.
OpenGL and Projections
OpenGL (II). How to Draw a 3-D object on Screen?
1 Chapter 5 Viewing. 2 Perspective Projection 3 Parallel Projection.
CS 480/680 Computer Graphics Representation Dr. Frederick C Harris, Jr. Fall 2012.
1 Introduction to Computer Graphics with WebGL Ed Angel Professor Emeritus of Computer Science Founding Director, Arts, Research, Technology and Science.
1 Introduction to Computer Graphics with WebGL Ed Angel Professor Emeritus of Computer Science Founding Director, Arts, Research, Technology and Science.
Computer Graphics (fall 2009)
1 Projection Matrices. 2 Objectives Derive the projection matrices used for standard OpenGL projections Introduce oblique projections Introduce projection.
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.
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.
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.
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.
OpenGL The Viewing Pipeline: Definition: a series of operations that are applied to the OpenGL matrices, in order to create a 2D representation from 3D.
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.
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
1 E. Angel and D. Shreiner: Interactive Computer Graphics 6E © Addison-Wesley 2012 Computer Viewing Isaac Gang University of Mary Hardin-Baylor.
1 Angel: Interactive Computer Graphics 4E © Addison-Wesley 2005 Transformations Ed Angel Professor of Computer Science, Electrical and Computer Engineering,
OpenGL LAB III.
Viewing. Classical Viewing Viewing requires three basic elements - One or more objects - A viewer with a projection surface - Projectors that go from.
1 Introduction to Computer Graphics with WebGL Ed Angel Professor Emeritus of Computer Science Founding Director, Arts, Research, Technology and Science.
Viewing 고려대학교 컴퓨터 그래픽스 연구실 kucg.korea.ac.kr.
Viewing.
Computer Viewing.
Isaac Gang University of Mary Hardin-Baylor
CSC461: Lecture 20 Parallel Projections in OpenGL
Projections and Normalization
Introduction to Computer Graphics with WebGL
CSC461: Lecture 19 Computer Viewing
Introduction to Computer Graphics with WebGL
Introduction to Computer Graphics with WebGL
Fundamentals of Computer Graphics Part 5 Viewing
Isaac Gang University of Mary Hardin-Baylor
Introduction to Computer Graphics with WebGL
Projections and Hidden Surface Removal
Introduction to Computer Graphics with WebGL
Chap 3 Viewing Pipeline Reading:
Introduction to Computer Graphics with WebGL
Introduction to Computer Graphics with WebGL
University of New Mexico
Viewing (Projections)
Computer Graphics Computer Viewing
THREE-DIMENSIONAL VIEWING II
Computer Viewing Ed Angel Professor Emeritus of Computer Science
Viewing and Projection
Viewing and Projection
Presentation transcript:

CS5500 Computer Graphics March 20, 2006

Computer Viewing Ed Angel Professor of Computer Science, Electrical and Computer Engineering, and Media Arts University of New Mexico

3 Angel: Interactive Computer Graphics 3E © Addison-Wesley 2002 Objectives Introduce the mathematics of projection Introduce OpenGL viewing functions Look at alternate viewing APIs

4 Angel: Interactive Computer Graphics 3E © Addison-Wesley 2002 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

5 Angel: Interactive Computer Graphics 3E © Addison-Wesley 2002 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

6 Angel: Interactive Computer Graphics 3E © Addison-Wesley 2002 Default Projection Default projection is orthogonal clipped out z=0 2

7 Angel: Interactive Computer Graphics 3E © Addison-Wesley 2002 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

8 Angel: Interactive Computer Graphics 3E © Addison-Wesley 2002 Moving Camera back from Origin default frames frames after translation by –d d > 0

9 Angel: Interactive Computer Graphics 3E © Addison-Wesley 2002 Moving the Camera We can move the camera to any desired position by a sequence of rotations and translations Example: side view ­Rotate the camera ­Move it away from origin ­Model-view matrix C = TR

10 Angel: Interactive Computer Graphics 3E © Addison-Wesley 2002 OpenGL code Remember that last transformation specified is first to be applied Also, remember that we are transforming the objects, not the camera. glMatrixMode(GL_MODELVIEW) glLoadIdentity(); glTranslatef(0.0, 0.0, -d); glRotatef(90.0, 0.0, 1.0, 0.0);

11 Angel: Interactive Computer Graphics 3E © Addison-Wesley 2002 The LookAt Function The GLU library contains the function glLookAt to form 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., );

12 Angel: Interactive Computer Graphics 3E © Addison-Wesley 2002 glLookAt(eyex, eyey, eyez, atx, aty, atz, upx, upy, upz)

13 Angel: Interactive Computer Graphics 3E © Addison-Wesley 2002 Other Viewing APIs The LookAt function is only one possible API for positioning the camera Others include ­Yaw, pitch, roll ­Elevation, azimuth, twist ­Direction angles

Now, we have determined how the objects are placed relative to the camera. But we haven’t defined how the objects are projected to the image.

15 Angel: Interactive Computer Graphics 3E © Addison-Wesley 2002 (Orthogonal) Projection and Normalization 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 x p = x y p = y z p = 0

16 Angel: Interactive Computer Graphics 3E © Addison-Wesley 2002 Homogeneous Coordinate Representation x p = x y p = y z p = 0 w p = 1 p p = Mp M = In practice, we can let M = I and set the z term to zero later

17 Angel: Interactive Computer Graphics 3E © Addison-Wesley 2002 Simple Perspective Center of projection at the origin Projection plane z = d, d < 0

18 Angel: Interactive Computer Graphics 3E © Addison-Wesley 2002 Perspective Equations Consider top and side views x p =y p = z p = d (or = )

19 Angel: Interactive Computer Graphics 3E © Addison-Wesley 2002 Homogeneous Coordinate Form M = consider q = Mp where p =  q =

20 Angel: Interactive Computer Graphics 3E © Addison-Wesley 2002 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 x p =y p = z p = d =

21 Angel: Interactive Computer Graphics 3E © Addison-Wesley 2002 OpenGL Orthogonal Viewing glOrtho(xmin,xmax,ymin,ymax,near,far) glOrtho(left,right,bottom,top,near,far) near and far measured from camera

22 Angel: Interactive Computer Graphics 3E © Addison-Wesley 2002 OpenGL Perspective glFrustum(xmin,xmax,ymin,ymax,near,far)

23 Angel: Interactive Computer Graphics 3E © Addison-Wesley 2002 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 aspect = w/h front plane

Now, we will look at how the OpenGL projection matrices are computed…

25 Angel: Interactive Computer Graphics 3E © Addison-Wesley 2002 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

26 Angel: Interactive Computer Graphics 3E © Addison-Wesley 2002 Pipeline View modelview transformation projection transformation perspective division clippingprojection nonsingular 4D  3D against default cube 3D  2D

27 Angel: Interactive Computer Graphics 3E © Addison-Wesley 2002 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

28 Angel: Interactive Computer Graphics 3E © Addison-Wesley 2002 Orthogonal Normalization glOrtho(left,right,bottom,top,near,far) normalization  find transformation to convert specified clipping volume to default

29 Angel: Interactive Computer Graphics 3E © Addison-Wesley 2002 Orthogonal Matrix 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 =

30 Angel: Interactive Computer Graphics 3E © Addison-Wesley 2002 Final Projection Set z =0 Equivalent to the homogeneous coordinate transformation Hence, general orthogonal projection in 4D is M orth = P = M orth ST

31 Angel: Interactive Computer Graphics 3E © Addison-Wesley 2002 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

32 Angel: Interactive Computer Graphics 3E © Addison-Wesley 2002 General Shear top view side view

33 Angel: Interactive Computer Graphics 3E © Addison-Wesley 2002 Shear Matrix xy shear ( z values unchanged) Projection matrix General case: H( ,  ) = P = M orth H( ,  ) P = M orth STH( ,  )

34 Angel: Interactive Computer Graphics 3E © Addison-Wesley 2002 Equivalency

35 Angel: Interactive Computer Graphics 3E © Addison-Wesley 2002 Effect on Clipping The projection matrix P = STH transforms the original clipping volume to the default clipping volume top view DOP near plane far plane object clipping volume z = -1 z = 1 x = -1 x = 1 distorted object (projects correctly)

36 Angel: Interactive Computer Graphics 3E © Addison-Wesley 2002 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

37 Angel: Interactive Computer Graphics 3E © Addison-Wesley 2002 Perspective Matrices Simple projection matrix in homogeneous coordinates Note that this matrix is independent of the far clipping plane M =

38 Angel: Interactive Computer Graphics 3E © Addison-Wesley 2002 Generalization N = after persepective divison, the point (x, y, z, 1) goes to x’’ = x/z y’’ = y/z z’’ = -(  +  /z) which projects orthogonally to the desired point regardless of  and 

39 Angel: Interactive Computer Graphics 3E © Addison-Wesley 2002 Picking  and  If we pick  =  = the near plane is mapped to z = -1 the far 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

40 Angel: Interactive Computer Graphics 3E © Addison-Wesley 2002 Normalization Transformation original clipping volume original object new clipping volume distorted object projects correctly

41 Angel: Interactive Computer Graphics 3E © Addison-Wesley 2002 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 z 1 > z 2 in the original clipping volume then the z’s for the transformed points z 1 ’ > z 2 ’ Thus hidden surface removal works if we first apply the normalization transformation However, the formula z’’ = -(  +  /z) implies that the distances are distorted by the normalization which can cause numerical problems especially if the near distance is small

42 Angel: Interactive Computer Graphics 3E © Addison-Wesley 2002 OpenGL Perspective glFrustum allows for an unsymmetric viewing frustum (although gluPerspective does not)

43 Angel: Interactive Computer Graphics 3E © Addison-Wesley 2002 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

44 Angel: Interactive Computer Graphics 3E © Addison-Wesley 2002

45 Angel: Interactive Computer Graphics 3E © Addison-Wesley 2002 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