110 likes | 125 Views
Projection in 3-D. Glenn G. Chappell CHAPPELLG@member.ams.org U. of Alaska Fairbanks CS 381 Lecture Notes Wednesday, October 29, 2003. Review: OpenGL Geometry Pipeline. Model/view Transformation. Lighting. Projection Transformation. Clipping (view-frustum). Viewport Transformation.
E N D
Projection in 3-D Glenn G. ChappellCHAPPELLG@member.ams.org U. of Alaska Fairbanks CS 381 Lecture Notes Wednesday, October 29, 2003
Review:OpenGL Geometry Pipeline Model/view Transformation Lighting Projection Transformation Clipping(view-frustum) Viewport Transformation ObjectCoordinates WindowCoordinates WorldCoordinates EyeCoordinates VertexOperations Rasterization FragmentOperations Vertex enters here To framebuffer Vertices(objectcoord’s) Vertices(windowcoord’s) Fragments Fragments Convert vertex data to fragment data Depth test, etc. CS 381
Review:Introduction to 3-D Viewing [1/3] • The model/view matrix can store a sequence of transformations. • Two kinds of transformations go into model/view: modeling and viewing. • The math and the code for these are identical. • But conceptually they are different. • Modeling transformations move objects or the scene. • Viewing transformations can be thought of as moving the camera. • Issues such as wide- vs. narrow-angle and perspective vs. parallel projection are not handled via model/view. • With model/view we place objects & the camera in the world. • Camera properties, such as those mentioned above, are set with the projection transformation. Model/view transformation Transformation#1 Transformation#2 Transformation#3 Transformation#4 CS 381
Review:Introduction to 3-D Viewing [2/3] • To move an object, put in a new transformation just before the object is drawn. • To move the entire scene, put in a new transformation at the beginning of the modeling transformations. • Where this is depends on how you think about things. • To move the camera, put in a new transformation at the very beginning of the transformation-setting code. • Moving the camera is backwards from moving objects • Object forward = camera backward. • Camera positioning using glTranslate*, glRotate* is often tricky. Using gluLookAt is sometimes more convenient. • With gluLookAt, we specify where we look (“at point”). We can also easily use gluLookAt to set up what direction we look (“view-plane normal”). • Push-pop pairs go around everything! • You can never have too many of these. CS 381
Review:Introduction to 3-D Viewing [3/3] • When we do lighting (soon!), doing things “wrong” can more easily lead to poor results. • So get in the habit of doing things “right” now. • Use model/view & projection properly. • Draw your polygons front-side-out. • If you do both lighting and scaling: glEnable(GL_NORMALIZE); • Drawing an Object Conveniently • Write a function that draws the object in “standard” position. • In particular, the point you want to rotate about (the center of the object?) goes at the origin. • To position the object, set up a transformation, then call this function. • Don’t forget the push-pop pair! • The same function can be used to draw multiple copies of the object. CS 381
Projection in 3-D:Introduction • We use the projection transformation to handle camera properties. • Perspective or parallel (orthogonal) projection. • Wide or narrow angle. • But not camera position & orientation. • Using 44 matrices with the 4th-coordinate division, we can create any such projection we want. • Both perspective and parallel. • Including all of the classical views. • Plan, elevation, isometric. • 1-, 2-, and 3-point perspective. • We do it all based on the synthetic camera model. • Now we look at some of the mathematics. CS 381
Projection in 3-D:Projecting a Point [1/2] • We have discussed the synthetic-camera model. • Now we apply it, to determine the coordinates of a projected point. Screen Center of Projection (“eye”)(0, 0, 0) (x, y, z) –z (?, ?, ?) z = –near View Frustum z = –far CS 381
Projection in 3-D:Projecting a Point [2/2] • Let b be the y-coordinate of the projection. • Using similar triangles (outlined in red), we see that b/near = y/(–z), and so b is the value given below. • We handle the x-coordinate similarly. Screen Center of Projection (“eye”)(0, 0, 0) (x, y, z) –z (x/[–z/near],y/[–z/near],–near) z = –near View Frustum z = –far CS 381
Projection in 3-D:A Matrix for Perspective • What happens if we use the following matrix in the pipeline? • Result: perspective! • Is this matrix what glFrustum produces? • Not quite; it deals with right, left, top, bottom, far, too. CS 381
Projection in 3-D:Wide vs. Narrow Angles • How do we determine wide & narrow angle using glFrustum or gluPerspective? • Example time … CS 381
More on OpenGL Matrices:Saving & Restoring • Next time we will look at more advanced viewing interfaces. • Zoom & pan. • Flying. • In order to implement these conveniently, we must be able to save and restore the value of a transformation matrix. • See printmatrix.cpp. CS 381