Professional Documents
Culture Documents
Chapter 06
Chapter 06
COMPUTER GRAPHICS
CHAPTER 06:
Transformations
OUTLINE
Introduction
Transformation in 2D
Transformation in 3D
Transformation in OpenGL
Q=T(P)
a) b) y
Q
y T
Q
P
0
P
x x
z
a) b) y
after
y
after before
before
x x
y P3 y
P2
P1
z x z x
y 1 0 2 y
0 1 1
0 0 1
1
x x
2
x 1 0 0
x
0 1 0
0 0 1
1 0 0
0 2 0
0 0 1
Faculty of Computer Science and Engineering - HCMUT Slide 13
Transformations in 2D
Rotation cos( ) sin( ) 0
Qx = Px cos() – Py sin()
sin( ) cos( ) 0
Qy = Px sin() + Py cos() 0
0 1
0.5 3 / 2 0
y 3/2 0.5 0 y
0 0 1
x 600 x
R P
x
Qx R cos( )
Q y R sin( )
Qx R cos cos R sin sin Px cos Py sin
Q y R sin cos R cos sin Px sin Py cos
x
Faculty of Computer Science and Engineering - HCMUT Slide 16
Transformations in 2D
Concatenation
y Q
T1()
T2()
P
W
T()
x
y Q
T1()
T2()
P
W
T()
x
Qx Px
Qy Py
Q M P
z z
1 1
z x z x z x z x
y
u u x
Q – Rotate u around y (+)
– Then rotate around z (-)
P
Rotate around x (+)
Recover u
z
x – Rotate around z (+)
– Rotate around y (-)
Ru()=Ry(-)Rz()Rx()Rz(-)Ry()
Q
P
Ru()=Ry(-)Rz()Rx()Rz(-)Ry()
z
x
c (1 c )u x2 (1 c )u y u x su z (1 c )uz u x su y 0
(1 c )u x u y su z c (1 c )u 2y (1 c )uz u y su x 0
(1 c )u u su (1 c )u y uz su x c (1 c )uz2 0
x z y
0 0 0 1
V Sx
Q
glColor3f(0, 0, 1);
glTranslatef(4, 5, 0); CTM = CTM* =
glRotatef(60, 0, 0, 1);
drawFigure0();
drawGrid();
glColor3f(0, 0, 1);
glTranslatef(4, 5, 0);
glRotatef(60, 0, 0, 1);
drawFigure0();
glColor3f(1, 0, 0);
drawFigure0();
glColor3f(0, 0, 1);
glTranslatef(4, 5, 0); CTM =
glRotatef(60, 0, 0, 1);
drawFigure0();
glColor3f(1, 0, 0);
drawFigure0();
glPushMatrix();
glColor3f(0, 0, 1);//The blue H
glTranslatef(4, 5, 0); CTM =
glRotatef(60, 0, 0, 1);
drawFigure0();
glPopMatrix();
B’ C’
C
A’ D’
B
D
A
Tìm ma trận biến đổi hình bình hành thành hình chữ nhật
1 0 0 1
0 1 0 1
M1
0 0 1 0
0 0 0 1
1 0 0 0
0.5 1 0 0
M2
0 0 1 0
0 0 0 1
Faculty of Computer Science and Engineering - HCMUT Slide 52
Transformations in OpenGL
5 / 2 0 0 0
0 3/ 4 0 0
M3
0 0 1 0
0 0 0 1
1 0 0 5
0 1 0 6
M4
0 0 1 0
0 0 0 1
5 / 2 0 0 0 1 0 0 5
0 3/ 4 0 0 0 1 0 6
M3 M4
0 0 1 0 0 0 1 0
0 0 0 1 0 0 0 1
M = M4*M3*M2*M1
C’ 5/ 2 0 0 15 / 2
B’ 3 / 8 3 / 4 0 45 / 8
M
C 0 0 1 0
A’ D’
B 0 0 0 1
D
A