1 / 27

SI23 Introduction to Computer Graphics

SI23 Introduction to Computer Graphics. Lecture 11 – 3D Graphics Transformation Pipeline: Modelling and Viewing Getting Started with OpenGL. viewing co-ords. Viewing Transform’n. Projection Transform’n. mod’g co-ords. world co-ords. Project view from camera onto plane.

siusan
Télécharger la présentation

SI23 Introduction to Computer Graphics

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. SI23Introduction to Computer Graphics Lecture 11 – 3D Graphics Transformation Pipeline: Modelling and Viewing Getting Started with OpenGL

  2. viewing co-ords Viewing Transform’n Projection Transform’n mod’g co-ords world co-ords Project view from camera onto plane Position world with respect to camera Position object in world 3D Transformation Pipeline • 3D graphics objects pass through a series of transformations before they are displayed • Objects created in modelling co-ordinates Modelling Transform’n

  3. Modelling Objects and Creating Worlds • We have seen how boundary representationsof simple objects can be created • Typically each object is created in its own co-ordinate system • To create a world, we need to understand how to transform objects so as to place them in the right place - translation, at the right size - scaling, in the right orientation- rotation This process is known as MODELLING

  4. Transformations • The basic linear transformations are: • translation: P = P + T, where T is translation vector • scaling: P’ = S P, where S is a scaling matrix • rotation: P’ = R P, where R is a rotation matrix • As in 2D graphics, we use homogeneousco-ordinates in order to express all transformations as matrices and allow them to be combined easily

  5. Homogeneous Co-ordinates • In homogeneous coordinates, a 3D point P = (x,y,z)T is represented as: P = (x,y,z,1)T • That is, a point in 4D space, with its ‘extra’ co-ordinate equal to 1 • Note: in homogeneous co-ordinates, multiplication by a constant leaves point unchanged • ie (x, y, z, 1)T = (wx, wy, wz, w)T

  6. Translation • Suppose we want to translate P (x,y,z)T by a distance (Tx, Ty, Tz)T • We express P as (x, y, z, 1)T and form a translation matrix T as below • The translated point is P’ x y z 1 = x’ y’ z’ 1 1 0 0 Tx 0 1 0 Ty 0 0 1 Tz 0 0 0 1 = x + Tx y + Ty z + Tz 1 = T P P’

  7. = x’ y’ z’ 1 Sx 0 0 0 0 Sy 0 0 0 0 Sz 0 0 0 0 1 x y z 1 P’ S P = Scaling • Scaling by Sx, Sy, Sz relative to the origin: = Sx . x Sy . y Sz . z 1

  8. x’ y’ z’ 1 = 1 0 0 0 0 cos -sin 0 0 sin cos 0 0 0 0 1 x y z 1 P’ = Rx () P Rotation • Rotation is specified with respect to an axis- easiest to start with co-ordinate axes • To rotate about the x-axis: a positive angle corresponds to counterclockwise direction looking at origin from positive position on axis EXERCISE: write down the matrices for rotation about y and z axes

  9. Composite Transformations • The attraction of homogeneous co-ordinates is that a sequence of transformations may be encapsulated as a single matrix • For example, scaling with respect to a fixed position (a,b,c)can be achieved by: • translate fixed point to origin- say, T(-a,-b,-c) • scale- S • translate fixed point back to its starting position- T(a,b,c) • Thus: P’ = T(a,b,c) S T(-a,-b,-c) P = M P

  10. Rotation about a Specified Axis • It is useful to be able to rotate about any axis in 3D space • This is achieved by composing 7 elementary transformations

  11. y x z rotate so that P2 lies on z-axis (2 rotations) translate P1 to origin initial position y x z rotate axis to orig orientation translate back Rotation through  about Specified Axis y y P2 P1 x x z z y y P2 P1 x x z z rotate through requ’d angle, 

  12. Inverse Transformations • As in this example, it is often useful to calculate the inverse of a transformation • ie the transformation that returns to original state • Translation: T-1 (a, b, c) = T (-a, -b, -c) • Scaling: S-1 ( Sx, Sy, Sz ) = S ............ • Rotation: R-1z () = Rz (…….) Exercise: Check T-1 T = I (identity matrix)

  13. Rotation about Specified Axis • Thus the sequence is: T-1 R-1x() R-1 y() Rz() Ry() Rx() T • EXERCISE: How are  and  calculated? • READING: • Hearn and Baker, chapter 11

  14. Interlude: Question • Why does a mirror reflect left-right and not up-down?

  15. Getting Started with OpenGL

  16. 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 MS Windows) • draws simple primitives (points, lines, polygons) but NOT complex primitives such as spheres • provides control over transformations, lighting, etc • Mesa is publically available equivalent

  17. 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 OpenGL supplement pp3-6 for output primitives

  18. 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

  19. Modelling • For modelling… set the matrix mode, and create the transformation... • Thus to set a scaling on each axis... glMatrixMode(GL_MODELVIEW); glLoadIdentity(); glScalef(sx,sy,sz); • This creates a 4x4 modelview matrix • Other transformation functions are: glRotatef(angle, ux, uy, uz); glTranslatef(tx, ty, tz); See p10 of OpenGL supplement

  20. OpenGL Utility Library (GLU)OpenGL Utility Toolkit (GLUT) • GLU: • useful set of utility routines written in terms of OpenGL … • GLUT: • 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 See pp1-3 of OpenGL supplement

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

  22. Viewing Transformation

  23. In OpenGL (and many other graphics systems) the camera is placed at a fixed position At origin Looking down negative z-axis Upright direction in positive y-axis Camera Position y x z VIEWING transforms the world so that it is in the required position with respect to this camera

  24. OpenGL will build this transformation for us from: Where camera is to be Point we are looking at Upright direction Becomes part of an overall MODELVIEW matrix Specifying the Viewing Transformation Look at position Upright position Eye position

  25. Specifying the Viewing Transformation in OpenGL • 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(); glScalef(sx,sy,sz); gluLookAt(eyex,eyey,eyez, lookx,looky,lookz, upx,upy,upz); creates a model-view matrix See pp11-12 of OpenGL Supp.

  26. 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…. Next lecture!

  27. Perspective and Parallel Projection parallel perspective

More Related