University of Palestine Computer Graphics ITGD3107 Presentation name : Three Dimensional Viewing Prepare: Mohammed J. el-masre Nidal M. El-Borbar Supervision: Dr. Sana'a p_ moc.liamtoh@10 _16 4tievermoc.liamtoh@2008 1 Contents 3D Viewing Camera Analogy Viewing Pipeline Camera Modeling w/ OpenGL Projections Types of Projections Perspective Projection Parallel Projection Projection Matrix Projection of Lines 3D Viewing with OpenGL Matrix Modes Three Dimensional Viewing p_ moc.liamtoh@10 _16 4tievermoc.liamtoh@2008 2 3D Viewing The steps for computer generation of a view of a three dimensional scene are somewhat analogous to the processes involved in taking a photograph. p_ moc.liamtoh@10 _16 4tievermoc.liamtoh@2008 3 Camera Analogy 1. 2. 3. Viewing position Camera orientation Size of clipping window Orientation Window (aperture) of the camera Position p_ moc.liamtoh@10 _16 4tievermoc.liamtoh@2008 4 Viewing Pipeline The general processing steps for modeling and converting a world coordinate description of a scene to device coordinates: p_ moc.liamtoh@10 _16 4tievermoc.liamtoh@2008 5 Viewing Pipeline 1. Construct the shape of individual objects in a scene within modeling coordinate, and place the objects into appropriate positions within the scene (world coordinate). p_ moc.liamtoh@10 _16 4tievermoc.liamtoh@2008 6 Viewing Pipeline World coordinate positions are converted to viewing coordinates. p_ moc.liamtoh@10 _16 4tievermoc.liamtoh@2008 7 Viewing Pipeline Convert the viewing coordinate description of the scene to coordinate positions on the projection plane. p_ moc.liamtoh@10 _16 4tievermoc.liamtoh@2008 8 Viewing Pipeline Positions on the projection plane, will then mapped to the Normalized coordinate and output device. p_ moc.liamtoh@10 _16 4tievermoc.liamtoh@2008 9 Camera Modeling w/ OpenGL camera coordinate system viewport coordinate system glMatrixMode(GL_MODELVIEW) ... device/screen coordinate system glViewport(0,0,xres,yres) glMatrixMode(GL_PROJECTION) ... p_ moc.liamtoh@10 _16 4tievermoc.liamtoh@2008 10 Projections Once the view volume is determined, a projection transformation will convert the object in the 3D view volume to a 2D image on the projection plane. p_ moc.liamtoh@10 _16 4tievermoc.liamtoh@2008 11 Types of Projections Perspective Projection Parallel Projection p_ moc.liamtoh@10 _16 4tievermoc.liamtoh@2008 12 Perspective Projection (1/2) Give a realistic view of 3D objects, but does not preserve shape of object or scale Perspective images of parallel lines not parallel with projection plane converge to a point called vanishing point Size of object is diminished with distance Used in architectural, engineering, industrial design, and advertising drawings p_ moc.liamtoh@10 _16 4tievermoc.liamtoh@2008 13 Perspective Projection (2/2) 1-point perspective Most popular 2-point perspective 3-point perspective p_ moc.liamtoh@10 _16 4tievermoc.liamtoh@2008 14 Parallel Projection Accurate and same-scale measurements Not realistic, and may require multiple projections to get a complete feeling of the object Used in drawings of machine parts and in working architectural drawings p_ moc.liamtoh@10 _16 4tievermoc.liamtoh@2008 15 Parallel Projection (3/3) Isometric Multi-view orthographic cavalier cabinet p_ moc.liamtoh@10 _16 4tievermoc.liamtoh@2008 Oblique 16 Projection Matrix (1/3) y Pp(xp,yp,d) = ??? P(x,y,z) x COP = Mper/ort Mort = 1 0 0 0 . x y z 1 z d Mper = xp yp d 1 1 0 0 0 0 0 1 0 0 1 0 1/d 0 0 0 0 p_ moc.liamtoh@10 _16 4tievermoc.liamtoh@2008 0 0 1 0 0 0 0 0 0 0 d 1 17 Projection Matrix (2/3) y Pp(xp,yp,0) = ??? P(x,y,z) x COP = Mper/ort Mort = 1 0 0 0 . x y z 1 z d Mper = xp yp 0 1 1 0 0 0 0 0 1 0 0 0 0 1/d 0 0 0 1 p_ moc.liamtoh@10 _16 4tievermoc.liamtoh@2008 0 0 1 0 0 0 0 0 0 0 0 1 18 Projection Matrix (3/3) Pp(xp,yp,0) = ??? Mgeneral = x or y COP Q 1 0 0 0 0 1 0 0 –a/c –b/c –d/Q/c –1/Q/c da/c db/c d2/Q/c+d d/Q/c+1 P(x,y,z) z d (a, b, c) p_ moc.liamtoh@10 _16 4tievermoc.liamtoh@2008 19 Projection of Lines y Parametric representation of a line that goes through P(px, py, pz) and has direction c = (cx, cy, cz) x l(t) = P+ct where t (-, + ) The projected line is x(t) = d(px+cxt)/(pz+czt) COP d z y(t) = d(py+cyt)/(pz+czt) If the original line is parallel to the projection plane (cz = 0) x(t) = d(px+cxt)/pz, y(t) = d(py+cyt)/pz, the slope of the projected line is cy/cx, independent of the position of the original line. The projected lines of parallel lines must be parallel p_ moc.liamtoh@10 _16 4tievermoc.liamtoh@2008 20 3D Viewing with OpenGL Viewing transformation: set the position and orientation of the viewpoint Modeling transformation: set the orientation of the model (translate, rotate, scale) Projection transformation: set the view volume and do the projection Viewport transformation: Set the viewport on the computer screen where the scene will be drawn p_ moc.liamtoh@10 _16 4tievermoc.liamtoh@2008 21 Matrix Modes Modelview matrix Set the viewpoint and object location by modifying this matrix glMatrixMode(GL_MODELVIEW) If projection matrix is modified Specify the view volume by modifying this matrix glMatrixMode(GL_PROJECTION) If texture matrix is modified glMatrixMode(GL_TEXTURE) p_ moc.liamtoh@10 _16 4tievermoc.liamtoh@2008 22 References & External links •http://en.wikipedia.org/wiki/3dviewing •http://anonymouse.org/cgi-bin/anonwww.cgi/http://www.eazyupload.net/download/jtg3c0c6/0135309247.zip.htm •http://eazy1.eazyupload.net/download/0ea47c0c7d5c5b872be23f3a8933086 3/0135309247.zip •http://dl1.s24.ifile.it/9gtkix4c/prentice_hall__computer_graphics_c_version_2ed_-_hearn__baker.pdf Our Book computer_graphics_c_version_2ed p_ moc.liamtoh@10 _16 4tievermoc.liamtoh@2008 23