Download presentation

Presentation is loading. Please wait.

Published byAriana Thornton Modified over 2 years ago

1
11.1 Si23_03 SI23 Introduction to Computer Graphics Lecture 11 – 3D Graphics Transformation Pipeline: Modelling and Viewing Getting Started with OpenGL

2
11.2 Si23_03 3D Transformation Pipeline n 3D graphics objects pass through a series of transformations before they are displayed – Objects created in modelling co- ordinates modg co-ords world co-ords viewing co-ords Modelling Transformn Viewing Transformn Projection Transformn Position object in world Position world with respect to camera Project view from camera onto plane

3
11.3 Si23_03 Modelling Objects and Creating Worlds n We have seen how boundary representations of simple objects can be created n Typically each object is created in its own co-ordinate system translationscaling rotation n 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
11.4 Si23_03 Transformations n 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 n As in 2D graphics, we use homogeneous co-ordinates in order to express all transformations as matrices and allow them to be combined easily

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

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

7
11.7 Si23_03 Scaling n Scaling by Sx, Sy, Sz relative to the origin : xyz1xyz1 Sx 0 0 0 0 Sy 0 0 0 0 Sz 0 0 0 0 1 xyz1xyz1 P = SP = = Sx. x Sy. y Sz. z 1

8
11.8 Si23_03 Rotation n Rotation is specified with respect to an axis - easiest to start with co-ordinate axes n 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 xyz1xyz1 =1 0 0 0 0 cos -sin 0 0 sin cos 0 0 0 0 1 xyz1xyz1 P= R x ( ) P

9
11.9 Si23_03 Composite Transformations n The attraction of homogeneous co-ordinates is that a sequence of transformations may be encapsulated as a single matrix with respect to a fixed position (a,b,c) n 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) n Thus: P = T(a,b,c) S T(-a,-b,-c) P = M P

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

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

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

13
11.13 Si23_03 Rotation about Specified Axis n Thus the sequence is: T -1 R -1 x ( ) R -1 y ( ) R z ( ) R y ( ) R x ( ) T EXERCISE: How are and calculated? n READING: – Hearn and Baker, chapter 11

14
11.14 Si23_03 Interlude: Question n Why does a mirror reflect left-right and not up-down?

15
11.15 Si23_03 Getting Started with OpenGL

16
11.16 Si23_03 What is OpenGL? n 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
11.17 Si23_03 Geometric Primitives n 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
11.18 Si23_03 Modelling, Viewing and Projection n 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
11.19 Si23_03 Modelling n For modelling… set the matrix mode, and create the transformation... n Thus to set a scaling on each axis... glMatrixMode(GL_MODELVIEW); glLoadIdentity(); glScalef(sx,sy,sz); n This creates a 4x4 modelview matrix n Other transformation functions are: glRotatef(angle, ux, uy, uz); glTranslatef(tx, ty, tz); See p10 of OpenGL supplement

20
11.20 Si23_03 OpenGL Utility Library (GLU) OpenGL Utility Toolkit (GLUT) n GLU: – useful set of utility routines written in terms of OpenGL … n 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
11.21 Si23_03 How to Get Started n Look at the SI23 resources page: – http://www.comp.leeds.ac.uk/kwb/si23/ resources.html n Points you to: – example programs – information about GLUT – information about OpenGL – information about Mesa 3D – a simple exercise

22
11.22 Si23_03 Viewing Transformation

23
11.23 Si23_03 Camera Position n 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 x y z VIEWING transforms the world so that it is in the required position with respect to this camera

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

25
11.25 Si23_03 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) n 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
11.26 Si23_03 Viewing Pipeline So Far n We now should understand the viewing pipeline modg co-ords world co-ords viewing co-ords Modelling Transformn Viewing Transformn The next stage is the projection transformation…. Next lecture! Projection Transformn

27
11.27 Si23_03 Perspective and Parallel Projection perspective parallel

Similar presentations

© 2017 SlidePlayer.com Inc.

All rights reserved.

Ads by Google