Basic Transformations in OPENGL
Last Updated :
19 Sep, 2023
Transformations play a very important role in manipulating objects on the screen. It should be noted that here the algorithms will be implemented in code and the built-in functions will not be used to give a good understanding of how the algorithms work. Also, note that all transformations are implemented in 2D. There are three basic kinds of Transformations in Computer Graphics: 1. Translation 2. Rotation 3. Scaling
Algorithms:
1. Translation: Translation refers to moving an object to a different position on the screen.
Formula: X = x + tx
Y = y + ty
where tx and ty are translation coordinates
The OpenGL function is glTranslatef( tx, ty, tz );
2. Rotation: Rotation refers to rotating a point.
Formula: X = xcosA - ysinA
Y = xsinA + ycosA,
A is the angle of rotation.
The above formula will rotate the point around the origin.
To rotate around a different point, the formula:
X = cx + (x-cx)*cosA - (y-cy)*sinA,
Y = cy + (x-cx)*sinA + (y-cy)*cosA,
cx, cy is centre coordinates,
A is the angle of rotation.
The OpenGL function is glRotatef (A, x, y, z).
3. Scaling: Scaling refers to zooming in and out an object on different scales across axes.
Formula: X = x*sx
Y = y*sy, sx, sy being scaling factors.
The OpenGL function is glScalef(float x, float y, float z)
Note: If combined transformations are to be applied, follow the order: translate, rotate, scale
Implementation:
Like Article
Suggest improvement
Share your thoughts in the comments
Please Login to comment...