180 likes | 300 Views
CD2012 Principles of Interactive Graphics Lecture 03. Transforms Abir Hussain www.cms.livjm.ac.uk/cmsahus1. Previous Lecture. Some definitions for computer graphics Vertex and ways of drawing vertex glVertex2i() glVertex3f() Representing colours glColor3f(0.0, 0.0, 0.0);
E N D
CD2012Principles of Interactive GraphicsLecture 03 Transforms Abir Hussain www.cms.livjm.ac.uk/cmsahus1
Previous Lecture • Some definitions for computer graphics • Vertex and ways of drawing vertex • glVertex2i() • glVertex3f() • Representing colours • glColor3f(0.0, 0.0, 0.0); • glClear(GL_COLOR_BUFFER_BIT ); • Graphics content CD2012-03
Today’s lecture and lab CD2012-03
Introduction • The transformation process for viewing the desired scene is analogous to taking pictures using camera. • In this case, the following operation is required: • Pointing the camera to the desired scene (viewing transformation). • Arrange the scene in the desired position (modelling transformation). • Select the zoom (projection transformation) • Selecting how large the final scene (viewport transformation) CD2012-03
Introduction • To Specify viewing, modelling and projection transformations, • it is required to construct a 44 matrix • The matrix is multiplied by the coordinate of each vertex in the scene to perform the transformation. CD2012-03
Transformation • Once a picture or a diagram is constructed • it is usually required to modify it in some systematic way. • As an example, it may be required to enlarge or rotate around some point. • This is known as transformation. • There are three typed of transformations • are translation, rotation and scaling. • In this lecture, we will cover the three of them. CD2012-03
Translation • A point in the (x, y, z) plane can be translated into new position • adding translation amounts to the coordinates of the points. • In OpenGL, this can be performed using • glTranslated(x,y,z) to change the current drawing location. CD2012-03
Translation glTranslated(10.0, 10.0, 0); glRecti(0,0, 15, 10); CD2012-03
Scaling • To scale an object, every coordinate is multiplied by the appropriate scaling factor. • The purpose of such operation is to enlarge or reduce the size of an object. • Using glScaled(x,y,z) in OpenGL, we can change the size of an object. • Where the sizes are multiplied in the relevant directions by x, y and z CD2012-03
Scaling glScaled(2.0, 2.0, 0); glRecti(0,0, 15, 10); CD2012-03
Rotation • The mathematical calculation for rotation is more complex than scaling and translation • In OpenGL, we can also rotate objects about the axes x, y and z with the function • glRotated(angle, x, y, z); CD2012-03
Rotation glRotated( 45.0, 0.0, 0.0, 1.0); glRecti(0,0, 30,20) CD2012-03
Combining transformation • Successive transforms are cumulative. • Each translation, rotation and scaling will work relative to the last transformation function we used. • This is because of the 44 transform matrix which is part of the current graphics context. • The transform matrix is used to re-calculate how the current drawing operation will be translated, rotated and/or scaled CD2012-03
Combining transformation • We can reset the 4x4 matrix back to the origin values by calling glLoadIdentity(). • The function initialises the current projection matrix so that only the specified projection transformation has en effect. • The glMatrixMode() function can be called with the GL_MODELVIEW • indicates that successive transformations affect the modelling matrix and not the projection matrix. CD2012-03
Lab • Continue with last week’s lab. • Perform three transformations: • translation, scaling and rotation. CD2012-03
Lab • Perform three transformations: translation, scaling and rotation. CD2012-03
Summary • Transforms • Translation • glTranslated(x, y, z) • Scaling • glScaled(x, y, z) • Rotation • glRotated(angle, x, y, z) • Combining transformations CD2012-03