🎯 What Are Transformations?
Transformations are operations used to change the position, size, or orientation of any object in a 3D scene. The three main transformation types are:
Translation – moving the object
Rotation – rotating the object
Scaling – resizing the object
OpenGL uses matrices, and each transformation modifies the current matrix.
1️⃣ Translation — Moving an Object
Used to move an object along the X, Y, or Z axis.
Function:
glTranslatef(x, y, z);
✔ Meaning of values:
x → move right/left
y → move up/down
z → move forward/backward
Example:
glTranslatef(100, 0, 0); // move object 100 units to the right
2️⃣ Rotation — Rotating an Object
Function:
glRotatef(angle, x, y, z);
✔ Meaning of values:
angle → rotation amount in degrees
x, y, z → axis of rotation
Example:
glRotatef(90, 1, 1, 0); // rotate 90° around a diagonal axis between X and Y
Common rotation axes:
(1, 0, 0) → rotate around X-axis
(0, 1, 0) → rotate around Y-axis
(0, 0, 1) → rotate around Z-axis
3️⃣ Scaling — Resizing an Object
Function:
glScalef(sx, sy, sz);
✔ Meaning of values:
Greater than 1 → enlarge
Less than 1 → shrink
Zero → object disappears
Example:
glScalef(2, 2, 2); // double the object's size
⚠ Transformation Order Matters
Order is extremely important in OpenGL!
glTranslatef(2, 0, 0);
glRotatef(45, 0, 1, 0);
is NOT the same as:
glRotatef(45, 0, 1, 0);
glTranslatef(2, 0, 0);
Because OpenGL multiplies transformation matrices in reverse order.