Professional Documents
Culture Documents
Chapter 5
Geometrical Transformation
For example;
y’ = rsin ()
x = r cos
= rsincos + rcossin
y = r sin
= xsin + ycos
2/18/23 Computer Graphics MTU – CS
Contd…
6
Translation
Two successive translation:
OR
OR
y y=x
x
2/18/23 Computer Graphics MTU – CS
23
3D Transformation
Similar to the 2D transform: 3D transform
has 3 basic transformations
Translation
Rotation
Scaling
Reflection
glTranslatef(, , )
2/18/23 Computer Graphics MTU – CS
Rotation
25
Rotation based on z–
axis
x – axis y – axis
rotation rotation
x
Matrix form
z
Translation first
Rotation first
Let Display(){
…
- glTranslate = Mat TransglMatrixMode(GL_MODELVIEW);
glLoadIdentity();
- glRotate = Mat Rot glTranslatef(0.0, 0.0, -6.0);
glRotatef(45.0,0.0,1.0, 0.0);
- glScale = Mat Scale glScalef(2.0, 2.0, 2.0);
DrawCube();
- DrawCube = v …}
Modelview matrix:
- Identity -> Trans -> Trans*Rot -> Trans*Rot*Scale ->
Trans*Rot*Scale*v
- Or, Trans(Rot(Scale*v)))
- So Scale is applied first, then Rot, then Trans
// Example 1 // Example 1
Display(){ Display(){
… …
glMatrixMode(GL_MODELVIEW); glMatrixMode(GL_MODELVIEW);
glLoadIdentity(); glLoadIdentity();
glTranslatef(0.0, 0.0, -6.0); glRotatef(45.0, 0.0, 1.0, 0.0);
glRotatef(45.0, 0.0, 1.0, 0.0); glTranslatef(0.0, 0.0, -6.0);
glScalef(2.0, 2.0, 2.0); glScalef(2.0, 2.0, 2.0);
DrawCube(); DrawCube();
…} …}
= Trans * Rot * Scale * v = Trans * Rot * Scale * v
y
tipl
glLoadIdentity();
ul
tm
glTranslated(2.0, 2.0, 0.0);
os
sp
glRotated(90.0, 0.0, 0.0, 1.0);
ay
w
al
glTranslated(-2.0, -2.0, 0.0);
L
nG
pe
O
2/18/23 Computer Graphics MTU – CS
38
Question
s?
Thank You!
2/18/23 Computer Graphics MTU – CS