1 / 32

SI31 Advanced Computer Graphics AGR

SI31 Advanced Computer Graphics AGR. Lecture 3 Viewing Transformation Getting Started with OpenGL Introduction to Projections. Viewing Transformation. world co-ordinates. modelling co-ordinates. MODELLING TRANSFORMATION. The Story So Far...Lecture 2.

rendor
Download Presentation

SI31 Advanced Computer Graphics AGR

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. SI31Advanced Computer GraphicsAGR Lecture 3 Viewing Transformation Getting Started with OpenGL Introduction to Projections

  2. Viewing Transformation

  3. world co-ordinates modelling co-ordinates MODELLINGTRANSFORMATION The Story So Far...Lecture 2 • We have seen how we can model objects, by transforming them from their local co-ordinate representation into a world co-ordinate system

  4. Viewing • Graphics display devices are 2D rectangular screens • Hence we need to understand how to transform our 3D world to a 2D surface • This involves: • selecting the observer position (or camera position) • selecting the view plane (or camera film plane) • selecting the type of projection

  5. Viewing Co-ordinate System - View Reference Point yW • In our world co-ordinate system, we need to specify where the camera is • We call this the view reference point... • … and transform the world so that camera is at the origin • We call this the view co-ordinate system P0 xW zW

  6. Viewing Co-ordinate System - View Plane Normal • Next we need to specify the direction in which the camera is pointing - the normal from the view plane to camera is the view plane normal, N • Some graphics systems require you to specify N ... • ... others (including OpenGL) allow you to specify a ‘look at’ point, Q, from which N is calculated as direction from the ‘look at’ point to the view reference point N yW P0 xW zW Q yW P0 xW zW

  7. Viewing Co-ordinate System - View Up Direction • Next we need to specify the ‘up-direction’ of the camera - this is known as the upward direction, UP • Often we take UP=(0,1,0), the positive y-axis • Both N and UP are normalised - ie unit vectors UP yW N P0 xW zW

  8. Viewing Co-ordinate System • This gives us a view reference point P0, and vectors N (view plane normal) and UP (upwards direction) • We now construct a right-handed viewing co-ordinate system as follows: • construct U = UPxN to create a vector orthogonal to N and to UP • construct V = N x U to complete the viewing co-ordinate system: U, V, N V UP V U yW N P0 xW zW

  9. Interlude: Today’s Puzzle • Why does a mirror reflect left-right and not up-down?

  10. Transformation from World to Viewing Co-ordinates • Given an object with positions defined in world co-ordinates, we need to calculate the transformation to viewing co-ordinates • The view reference point must be transformed to the origin, and lines along the U, V, N directions must be transformed to lie along the x, y, z directions

  11. T = 1 0 0 -x0 0 1 0 -y0 0 0 1 -z0 0 0 0 1 Transformation from World to Viewing Co-ordinates • Translate so that P0 lies at the origin V U yW P0 N (x0, y0, z0) xW zW - apply translation by (-x0, -y0, -z0)

  12. Transformation from World to Viewing Co-ordinates • Apply rotations so that the U, V and N axes are aligned with the xW, yW and zW directions • This involves three rotations Rx, then Ry, then Rz • first rotate around xW to bring N into the xW-zW plane • second, rotate around yW to align N with zW • third, rotate around zW to align V with yW • Composite rotation R = Rz. Ry. Rx

  13. Rotation Matrix • Fortunately there is an easy way to calculate R, from U, V and N: R = u1 u2 u3 0 v1 v2 v3 0 n1 n2 n3 0 0 0 0 1 where U = (u1 u2 u3 )T etc

  14. Viewing Transformation • Thus the viewing transformation is: ViewMatrix = R T • This transforms object positions in world co-ordinates to positions in the viewing co-ordinate system.. .. with camera pointing along negative z-axis at a view plane parallel to x-y plane • We can then apply the projection transformation - to be described later

  15. Exercises • Convince yourself that the rotation matrix on ‘Rotation Matrix’ slide will have the required effect • Build the view matrix that results from: • camera at (1,2,3) • looking at (3,2,1) • with up direction (0,1,0)

  16. Getting Started with OpenGL

  17. What is OpenGL? • OpenGL provides a set of routines (API) for advanced 3D graphics • derived from Silicon Graphics GL • acknowledged industry standard, even on PCs (OpenGL graphics cards available) • integrates 3D drawing into X (and other window systems such as Windows NT) • draws simple primitives (points, lines, polygons) but NOT complex primitives such as spheres • provides control over transformations, lighting, etc • Mesa is publically available equivalent

  18. Geometric Primitives • Defined by a group of vertices - for example to draw a triangle: glBegin (GL_POLYGON); glVertex3i (0, 0, 0); glVertex3i (0, 1, 0); glVertex3i (1, 0, 1); glEnd(); • See Chapter 2 of the OpenGL Programming Guide

  19. Modelling, Viewing and Projection • OpenGL maintains two matrix transformation modes • MODELVIEW to specify modelling transformations, and transformations to align camera • PROJECTION to specify the type of projection (parallel or perspective) and clipping planes • See Chapter 3 of OpenGL Programming Guide

  20. Modelling • For modelling… set the matrix mode, and create the transformation... • Thus to set a scaling on each axis... glMatrixMode(GL_MODELVIEW); glLoadIdentity(); glScaled(sx,sy,sz);

  21. Viewing • For viewing, use gluLookAt()to create a view transformation matrix gluLookAt(eyex,eyey,eyez, lookx,looky,lookz, upx,upy,upz) • Thus glMatrixMode(GL_MODELVIEW); glLoadIdentity(); glScaled(sx,sy,sz); gluLookAt(eyex,eyey,eyez, lookx,looky,lookz, upx,upy,upz); creates a model-view matrix

  22. OpenGL Utility Library (GLU)OpenGL Utility Toolkit (GLUT) • GLU: • useful set of utility routines written in terms of OpenGL … such as gluLookAt() • GLUT (Appendix D of OpenGL Guide): • Set of routines to provide an interface to the underlying windowing system - plus many useful high-level primitives (even a teapot - glutSolidTeapot()!) • Allows you to write ‘event driven’ applications • you specify call back functions which are executed when an event (eg window resize) occurs

  23. How to Get Started • Look at the SI31/AGR resources page: • http://www.comp.leeds.ac.uk/kwb/si31/ resources.html • Points you to: • example programs • information about GLUT • information about OpenGL • information about Mesa 3D • a simple exercise

  24. Introduction to Projections

  25. viewing co-ords Projection Transform’n mod’g co-ords world co-ords Viewing Pipeline So Far • We now should understand the viewing pipeline Viewing Transform’n Modelling Transform’n The next stage is the projection transformation….

  26. Puzzle from Lecture 2

  27. For further reading see: www.illusionworks.com/ html/ames_room.html www.psych.uleth.ca/People/Douglas/Winter99/01/ Ames.html Ames Room

  28. Another Example

  29. Perspective Projections • There are two types of projection: perspective and parallel • In a perspective projection, object positions are projected onto the view plane along lines which converge at the observer P1 P1’ camera P2 P2’ view plane

  30. Parallel Projection • In a parallel projection, the observer position is at an infinite distance, so the projection lines are parallel P1 P2 view plane

  31. Perspective and Parallel Projection • Parallel projection preserves the relative proportions of objects, but does not give a realistic view • Perspective projection gives realistic views, but does not preserve proportions • Projections of distant objects are smaller than projections of objects of the same size which are closer to the view plane

  32. Perspective and Parallel Projection parallel perspective

More Related