1] Rx 1] Ry

 3D Transformations
CS475m - Computer Graphics
[ ]
sx 0 0
0 sy 0
S s x , s y , s z =
0 0 sz
0 0 0
Lecture 5 : 3D Transformations
0
0
0
1
1 1 1
S−1 s x , s y , s z =S  , , 
s x sy sz
glScalef(sx, sy, sz)
Scaling
CS475m: Lecture 5
3D Transformations
[
cos  −sin 
sin  cos
R z =
0
0
0
0
0
0
1
0
0
0
0
1
]
−1
[
Y
0
0
0
1
]
−1
O
X
CS475m: Lecture 5
−1
T l , m , n=T −l ,−m ,−n
glTranslatef(l, m, n)
CS475m: Lecture 5
Parag Chaudhuri
[
cos 
0
R y =
−sin 
0
T
R x =R x −=R x
Y
O
X
0 sin 
1
0
0 cos 
0
0
0
0
0
1
]
glRotatef(angle, 0.0, 1.0, 0.0)
Z
Parag Chaudhuri
0 l
0 m
1 n
0 1
−1
T
R y =R y −=R y
Y
Rotation about Y axis
glRotatef(angle, 1.0, 0.0, 0.0)
Z
0
1
0
0
3D Transformations
Rotation about X axis
glRotatef(angle, 0.0, 0.0, 1.0)
Parag Chaudhuri
1
0
0
0 cos  −sin 
R x =
0 sin  cos 
0
0
0
T
R z =R z −=R z
[ ]
1
0
T l , m , n=
0
0
Translation
3D Transformations
Rotation about Z axis
CS475m: Lecture 5
3D Transformations
O
X
Z
Parag Chaudhuri
CS475m: Lecture 5
Parag Chaudhuri
3D Transformations
3D Transformations
3D Transformations
Y
In particular for Rotations
Shear
T
T
R axis  . R axis =R axis  . R axis =I
Rotations are orthogonal matrices.
det  Raxis =1
Rotating a cube about its center (about the z axis).
[ ]
1 d
b 1
Sh=
c f
0 0
g
h
1
0
0
0
0
1
C
O
X
P ' =T C . R z  .T −C  . P
glLoadMatrixf(const Gldouble *m)
Z
glMultMatrixf(const Gldouble *m)
CS475m: Lecture 5
Parag Chaudhuri
3D Transformations
CS475m: Lecture 5
m contains points to 16 consecutive values that are used as the elements of a 4×4 column­major matrix.
Parag Chaudhuri
3D Transformations
Y
Rotating about an arbitrary axis.
C x , C y ,C z
3D Transformations
Y
Rotating about an arbitrary axis.
O
X
Rotating about an arbitrary axis.
P
Translate to the origin
Po
using T −x o ,− y o ,−z o 
Z
Cy
O
Cz
Z
by an angle 
CS475m: Lecture 5
Parag Chaudhuri
Y
Po
Passing through P o  x o , y o , zo 
and
with direction cosines as
CS475m: Lecture 5
X
Cx
CS475m: Lecture 5

Align the vector OP
to the z axis
d = C 2y C 2z
Parag Chaudhuri
CS475m: Lecture 5
Cy
 O
Cz

Rotate such that
Z
OP
it lies on the XZ plane
i.e., rotate about the X axis by 
Consider the unit vector
in the direction C x , C y , C z
Parag Chaudhuri
P
d
cos =
Cz
d
X
Cx
sin =
Cy
d
R x 
Parag Chaudhuri
3D Transformations
3D Transformations
Y
Rotating about an arbitrary axis.
P
 O

Rotate such that
Z
OP
it lies on the XZ plane
i.e., rotate about the X axis by 
d = C yC z
2
2
X
d
cos=
Cz
d
d
Cx
sin =
CS475m: Lecture 5
Cy
d
Y
Rotating about an arbitrary axis.
d

Align the vector OP
to the z axis
3D Transformations
Y
R x 
Parag Chaudhuri
P

Align the vector OP
to the z axis

Rotate around OP
Y axis by −
P'
d=  C y C z
2
2
Rotating about an arbitrary axis.
P
O
d
Cx
Z
cos − =d
X
−
sin − =C x
CS475m: Lecture 5
d
3D Transformations
Rotating about an arbitrary axis.
General 3D transformation:
a d
b e
T=
c f
p q
Parag Chaudhuri
P'
R z delta
CS475m: Lecture 5
Parag Chaudhuri
Transformations in OpenGL
●
When we specify a matrix transformation it is post multiplied with the current transformation matrix.
g l
h m
i n
r s
glLoadIdentity()
Current matrix C 1= I
glRotatef(Ө, x, y, z)
Current matrix C 2=C 1 . R
glTranslatef(tx, ty, tz)
Current matrix C 3 =C 2 . T
glBegin(...)
glVertex3f(45.6, 34.9, .....)
glVertex3f(45.6, 34.9, .....)
:
:
:
:
glEnd()
CS475m: Lecture 5

R y − 
M =T P o  . R x − . R y  . R z  . R y − . R x  .T −P o 
CS475m: Lecture 5
X
Z
[ ]
Now do the inverse transforms in reverse order to get the composite transformation matrix
as:
O
P''
P'
Parag Chaudhuri
3D Transformations
Now rotate about the to the z axis by 
Parag Chaudhuri
CS475m: Lecture 5
v transformed =C 3 . v
=R . T . v
Parag Chaudhuri
Transformations in OpenGL
●
●
●
OpenGL maintains a stack of matrices with the current matrix always on top of the stack.
glPushMatrix copies the matrix on top of the stack and pushes it into the stack.
glPopMatrix pops the matrix on top of the stack.
glLoadIdentity()
glRotatef(?θA, 0, 0, 1)
drawShoulder(...)
glPushMatrix()
glRotatef(?θB, 0, 0, 1)
drawElbow(...)
glPopMatrix()
Elbow
B
Shoulder
A
CS475m: Lecture 5
Parag Chaudhuri