Transformations play a very important role in manipulating objects on 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:
- Translation : Translation refers to moving an object to a different position on screen.
Formula: X = x + tx Y = y + ty where tx and ty are translation coordinates The OpenGL function is glTranslatef( tx, ty, tz );
- 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 = cx + (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).
- Scaling : Scaling refers to zooming in and out an object in 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 is 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 contribute.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.
- Creating animations using Transformations in OpenGL
- Getting started with OpenGL
- Rendering a Triangle using OpenGL(using Shaders)
- OpenGL Rendering Pipeline | An Overview
- Scan-line Polygon filling using OPENGL in C
- OpenGL program for Simple Ball Game
- Some Basic Terms Of Chatbots
- List of basic AutoCAD Terminology
- A basic Python Programming Challenge
- Building a Basic Chrome Extension
- How to Start a Career in Software Testing - A Complete Guide!
- Top 8 Video Call Apps That Become Popular During Covid19 Pandemic
- Top 5 Free, Cross-Platform, and Open-Source Database System in 2020
- Methods for Text Clipping in Computer Graphics