Geometrical �Transformation
1
positive rotation
Tong-Yee Lee
Outline
3
scale
Modeling Transform
4
5
Basic Concept
Local coordinate systems v.s. global coordinate system
Overview
6
Viewing Transformation
7
Rotate C1: will globally
change locations but relatively not
change local relationship C2 and C3
2-D Transformations
8
Move each local coordinate to a world coordinate
Model is defined in a local coordinate
2-D Transformations
9
2-D Transformations
10
a. Usually, (0,0) point
is used to align
local and world coordinates
First
b. (0,0) will not changed
for scaling and rotation
2-D Transformations
11
2-D Transformations
12
2-D Transformations
13
Basic 2D Transformations
14
Basic 2D Transformations
15
Sx>1
Sy>1
Scaling Around A Point
16
Scaling
S = S(sx, sy, sz) =
17
Angel: Interactive Computer Graphics 5E © Addison-Wesley 2009
x’=sxx
y’=syy
z’=szz
p’=Sp
Expand or contract along each axis (fixed point of origin)
Sx=Sy=Sz=0.5
Sx=0.5
Sy=1.5
Sz=1.0
Reflection
corresponds to negative scale factors
18
Angel: Interactive Computer Graphics 5E © Addison-Wesley 2009
original
sx = -1 sy = 1
sx = -1 sy = -1
sx = 1 sy = -1
April 2010
19
Move to origin
Scale
Move back
Basic 2D Transformations
20
Rotation around the origin (2-D)
21
Ex: polar coordinate (極座標)
Rotation around the origin (2-D)
22
Counterclockwise i.e., 逆時針方向 (positive)
Rotation around the origin (2-D)
23
Rotation (3-D)
24
Rotation (3-D)
Counterclockwise
i.e., 逆時針方向
(positive)
26
Basic 2D Transformations
27
28
2D Rotation at any pivot
29
樞軸;支點
Basic 2D Transformations
30
Translation
Although we can move a point to a new location in infinite ways, when we move many points there is usually only one way
31
Angel: Interactive Computer Graphics 5E © Addison-Wesley 2009
object
translation: every point displaced
by same vector
Basic 2D Transformations
32
General 2D Rotation at (Xr,Yr)
April 2010
33
Move to origin
Rotate
Move back
Matrix Representation
34
Matrix Representation
35
2x2 Matrix
36
2x2 Matrix
37
Shear (2-D)
38
Shear (3-D)
39
2x2 Matrix
40
2x2 Matrix
41
2D Reflections
April 2010
42
2x2 Matrix
43
2D Translation
44
Ex: (x,y) is represented by (x,y,1) in homogenous coordinate
Basic 2D Transformations
45
Homogeneous Coordinates
46
i.e., vector
(x1,y1,1) – (x2,y2,1)
= (x1-x2.y1-y2,0)
i.e., projection, w is related
to depth from eye
i.e. depth in w coordinate
Matrix Composition
47
w=1
Matrix Composition
48
i.e. 1 point is OK
i.e. if many points are used, matries are composed first
Matrix Composition
49
(交換律)
T*R*P != RT*P
Matrix Composition
50
i.e., M= T(a,b)*R(Q)*T(-a,-b)
P’=M*P
i.e., M= T(a,b)*S(Q)*T(-a,-b)
P’=M*P
3D Transformations
51
w=1
Basic 3D Transformations
52
w=1
Basic 3D Transformations
53
General rotation about an axis
54
Developing the General Rotation Matrix�
55
t= <Xv, Yv, Zv>
→
56
57
58
59
60
61
Developing the General Rotation Matrix
62
Z
X
(+,+)
(-,-)
In both cases, tan(y/x) are positive.
So, we need to carefully choose
it by checking the signs of x and y
OpenGL transformation Matrices
object
object
glutSolidSphere(1.0, 50, 50);
(4,5,6)
Example -1
64
Example
void GL_display() // GLUT display function
{
// clear t he buffer
glClear(GL_COLOR_BUFFER_BIT);
glColor3f(1.0, 1.0, 1.0);
glPushMatrix();
glutWireSphere(1.0, 20, 16); // the Sun
glRotatef(year, 0.0, 1.0, 0.0);
glTranslatef(3.0, 0.0, 0.0);
glRotatef(day, 0.0, 1.0, 0.0);
glutWireSphere(0.5, 10, 8); // the Planet
Adding more ……………………………..
glPopMatrix();
// swap the front and back buffers
glutSwapBuffers();
}
65
Call GL_ display once
Push (original) i.e., 0
Rotate angles
Pop() to the original, i.e., 0
Example -4
void GL_idle() // GLUT idle function
{
day += 10.0;
if(day > 360.0) day -= 360.0; (i.e., planet self-rotation +10 degrees, faster)
year += 1.0;
if(year > 360.0) year -= 360.0; (i.e., planet rotate sun + 1 degree, slower)
// recall GL_display() function
glutPostRedisplay(); (i.e., call run display function)
}
66
Example -5
void GL_keyboard(unsigned char key, int x, int y) // GLUT keyboard function
{
switch(key)
{
case 'd': day += 10.0;
if(day > 360.0) day -= 360.0;
glutPostRedisplay();
break;
case 'y': year += 1.0;
if(year > 360.0) year -= 360.0;
glutPostRedisplay();
break;
case 'a': glutIdleFunc(GL_idle); // assign idle function
break;
case 'A': glutIdleFunc(0);
break;
case 27: exit(0);
}
}
67
Example -6
int main(int argc, char** argv)
{
glutInit(&argc, argv);
glutInitWindowSize(500, 500);
glutInitWindowPosition(0, 0);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB);
glutCreateWindow("Planet");
init();
glutDisplayFunc(GL_display);
glutReshapeFunc(GL_reshape);
glutKeyboardFunc(GL_keyboard);
glutMainLoop();
return 0;
}
68
Example
void GL_display() // GLUT display function
{
// clear t he buffer
glClear(GL_COLOR_BUFFER_BIT);
glColor3f(1.0, 1.0, 1.0);
glPushMatrix();
glutWireSphere(1.0, 20, 16); // the Sun
glRotatef(year, 0.0, 1.0, 0.0);
glTranslatef(3.0, 0.0, 0.0);
glRotatef(day, 0.0, 1.0, 0.0);
glutWireSphere(0.5, 10, 8); // the Planet
Adding more ……………………………..
glPopMatrix();
// swap the front and back buffers
glutSwapBuffers();
}
69
Call GL_ display once
Push (original) i.e., 0
Rotate angles
Pop() to the original, i.e., 0
Add more
like moon
Add more
like 土星
70
71
upper
lower
child is transformed relative to its parent
72
child is transformed relative to its parent’s new
position
73
3D Example: A robot arm
74
OpenGL better implementation
75
changed
A More Complex Example: Human Figure
torso
A More Complex Example: Human Figure
What’s the most efficient way to draw this figure?
torso
A More Complex Example: Human Figure
What’s the most sensible way to traverse this tree?
torso
A More Complex Example: Human Figure
What’s the most sensible way to traverse this tree?
torso
A More Complex Example: Human Figure
What’s the most sensible way to traverse this tree?
torso
A More Complex Example: Human Figure
What’s the most sensible way to traverse this tree?
torso
A More Complex Example: Human Figure
What’s the most sensible way to traverse this tree?
torso
A More Complex Example: Human Figure
What’s the most sensible way to traverse this tree?
torso
A More Complex Example: Human Figure
What’s the most sensible way to traverse this tree?
torso
A More Complex Example: Human Figure
What’s the most sensible way to traverse this tree?
torso
A More Complex Example: Human Figure
What’s the most sensible way to traverse this tree?
torso
A More Complex Example: Human Figure
What’s the most sensible way to traverse this tree?
torso
88
Torso
Transformation Hierarchies Scene graphs
Root
Transform
Head Rotate first and then translate
Rotate
Rotate
translate
Store first
Recover
OpenGL transformation Matrices
89
A more complex example
90
91
92
p1
t1
t2
n
p0
p2
93
p.s.vector will not be changed by translation matrix
94
Inverse Transformation
95
OpenGL transformation Matrices
96
97
98
99
100
101
102
103
104
105
106
107
108
Animated Spider using Hierarchical Transformations in OpenGL
A project where a spider is modeled in OpenGL using the gluSphere and gluCylinder and is animated using hierarchical transformations. Note: The animation is not meant to be realistic
109
OpenGL Skeletal Animation Tutorial
110
111
112
(a)
(b)
Step 1:
Separate
x vector
Note: vector a
is a unit vector
i.e: cos(90-Ɵ) = sin(Ɵ)
��Angular displacement �glRotate(θ, Ax,Ay,Az)�
113
The above formula is a matrix form, so we can use Matrix to compute rotation
In above equation, v=(x,y,z)T and n=(ax,ay,az)T
114