Presentation is loading. Please wait.

Presentation is loading. Please wait.

Lecture 3: Transforms 1  Principles of Interactive Graphics  CMSCD2012  Dr David England, Room 711,  ex 2271 

Similar presentations


Presentation on theme: "Lecture 3: Transforms 1  Principles of Interactive Graphics  CMSCD2012  Dr David England, Room 711,  ex 2271 "— Presentation transcript:

1 Lecture 3: Transforms 1  Principles of Interactive Graphics  CMSCD2012  Dr David England, Room 711,  ex 2271 d.england@livjm.ac.uk  http://java.cms.livjm.ac.uk/homepage/staff/cmsdengl/Teaching/cmscd2012/ http://java.cms.livjm.ac.uk/homepage/staff/cmsdengl/Teaching/cmscd2012/

2 Lecture 3: Transforms 2 Today’s Lecture and Lab  Review of Tutorial: Circle drawing  This Week Transforms  Today’s tutorial: Transforms in L:\cd2012\transform.cpp

3 Lecture 3: Transforms 3 Review of Tutorial  Last week we looked at a circle drawing algorithm which you translated from pseudo-code to C/C++  The algorithm calculates the points for one octant. The remaining points are generated by symmetry L:\cd2012\circles.cpp has the working solution  The function circle(int x_centre, int y_centre, int radius) generates the octant points  plot_circle_points() generates the complete circle

4 Lecture 3: Transforms 4 Transforms  So far everything we have drawn has been relative to the origin, 0,0,0.  This would make complex scenes hard to managed  Most 3D graphics API’s have functions for  Translating (moving) in x, y and z  Scaling, either  making objects smaller or larger  of flipping them over  Rotation about an axis  Transforms in OpenGL are part of the current graphics context - why is this important?

5 Lecture 3: Transforms 5 Transform functions: Translation  We can use the glTranslated(x,y,z) function to change the current drawing location  For example glTranslated(10.0, 10.0, 0); glRecti(0,0, 15, 10) 10 (x1,y1) (x2,y2)

6 Lecture 3: Transforms 6 Transform functions: Scaling  Similarly we can change the relative size of the drawn objects with glScaled(x,y,z)  Where the sizes are multiplied in the relevant directions by x, y and z  glScaled(2.0, 2.0, 0); glRecti(0,0, 15, 10) 30 20

7 Lecture 3: Transforms 7 Transform functions: Rotation  We can also rotate objects about the axes x,y and z with glRotated(angle, x, y, z)  For example  glRotated( 45.0, 0.0, 0.0, 1.0); glRecti(0,0, 30,20) 20 30

8 Lecture 3: Transforms 8 Transform functions: Combinations  Transforms can be combined but the final effect depends on the order of the transformations 10 20 A B A: Translated then rotated B: Rotated then translated With B we have flipped the X,Y axes around by 45 degrees

9 Lecture 3: Transforms 9 Transform functions: Combinations...  Successive transforms are cumulative  Each translation, rotation and scaling will work relative to the last transformation function we used  This is because there is a transform matrix which is part of the current graphics context  The transform matrix is a 4x4 array of values which is used to re-calculate how the current drawing operation will be translated, rotated and/or scaled  We can reset the 4x4 matrix back to the origin values by calling glLoadIdentity()

10 Lecture 3: Transforms 10 Transform functions: Combinations...  We can use the accumulation of transform operations to draw a set of connected objects in the same location, e.g.  A assembly of parts like a car wheel: tyre, brakes, hub  We can then switch off the accumulated transforms when we wish to move on to drawing another collection of objects  Planning the drawing of a complex object is then a matter of breaking it down into smaller collections  where each smaller part shares a common set of transforms  A common problem is loosing track of which transforms are being applied

11 Lecture 3: Transforms 11 Transform functions: Combinations...  The file L:\cd2012\transform.cpp has examples of  Drawing a translated rectangle  Drawing a translated and scaled rectangle relative to the first  Resetting the transform matrix  Drawing a rectangle translated and rotated relative to the origin  The tutorial will explore what happens when changes are made to transform.cpp

12 Lecture 3: Transforms 12


Download ppt "Lecture 3: Transforms 1  Principles of Interactive Graphics  CMSCD2012  Dr David England, Room 711,  ex 2271 "

Similar presentations


Ads by Google