LAB6 Transformations
LAB6 Transformations
LAB # 06
TRANSFORMATIONS
TRANSFORMATION
Transformation means changing some graphics into something else by applying rules. We can
have various types of transformations such as:
• Translation
• Scaling up or down Rotation
• Shearing, etc.
When a transformation takes place on a 2D plane, it is called 2D transformation.Transformations
play an important role in computer graphics to reposition the graphics on the screen and change
their size or orientation.
TRANSLATION
Translation refers to the shifting of a point to some other place, whose distance with regard
to the present point is known.
A translation moves an object to a different position on the screen. You can translate a point in 2D
by adding translation coordinate (tx, ty) to the original coordinate (X, Y) to get the new coordinate
(X’, Y’).
1
COMPUTER GRAPHICS
SCALING
To change the size of an object, scaling transformation is used. In the scaling process, you either
expand or compress the dimensions of the object. Scaling can be achieved by multiplying the
original coordinates of the object with the scaling factor to get the desired result.
ROTATION
2
COMPUTER GRAPHICS
In rotation, we rotate the object at particular angle θ (theta) from its origin. From the following
figure, we can see that the point P(X, Y) is located at angle φ from the horizontal X coordinate
with distance r from the origin.
Let us suppose you want to rotate it at the angle θ. After rotating it to a new location, you will get
a new point P’ (X’, Y’).
3
COMPUTER GRAPHICS
4
COMPUTER GRAPHICS
LAB TASKS
TASK # 1
Write Opengl code that shows the following output:
TASK # 2
Re-write the house-building program implemented in the previous lab in a way that:
• On pressing ‘r’ the house should be moved on right side of the original, keeping original
at its place.
• On pressing ‘l’ the house should be moved on left side of the original, keeping original at
its place.
5
COMPUTER GRAPHICS