Presentation is loading. Please wait.

Presentation is loading. Please wait.

SI23 Introduction to Computer Graphics

Similar presentations


Presentation on theme: "SI23 Introduction to Computer Graphics"— Presentation transcript:

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

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

3 Modelling Objects and Creating Worlds
We have seen how boundary representations of 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 8

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 homogeneous co-ordinates in order to express all transformations as matrices and allow them to be combined easily 9

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 10

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 Tx Ty Tz = x + Tx y + Ty z + Tz 1 = T P P’ 11

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

8 Rotation Rotation is specified with respect to an axis - easiest to start with co-ordinate axes To rotate about the x-axis: x’ y’ z’ 1 = 0 cos -sin 0 0 sin cos 0 x y z P’ Rx () P 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 13

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 14

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 15

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

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 18

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 4 4

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 5 5

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 6 6

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)
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 8 8

21 How to Get Started Look at the SI23 resources page: Points you to:
resources.html Points you to: example programs information about GLUT information about OpenGL information about Mesa 3D a simple exercise

22 Viewing Transformation

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

24 Specifying the Viewing Transformation
Look at position 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 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 Pipeline So Far
We now should understand the viewing pipeline mod’g co-ords world viewing Viewing Transform’n Projection Transform’n Modelling Transform’n The next stage is the projection transformation…. Next lecture! 14 14

27 Perspective and Parallel Projection


Download ppt "SI23 Introduction to Computer Graphics"

Similar presentations


Ads by Google