Basic Transformations in OPENGL
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
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
This article is contributed by Suprotik Dey. If you like GeeksforGeeks and would like to contribute, you can also write an article using write.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks. Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above.
Please Login to comment...