Geometrical Transformation
1
positive rotation
Tong-Yee Lee
3D Graphics Pipeline
Outline
3
scale
Modeling Transform
4
glutSolidSphere(1.0, 10, 10)
5
Basic Concept
Local coordinate systems v.s. global coordinate system
View coordinate
systems
Overview
6
Viewing Transformation
7
Hierarchical modeling
8
Rotate C1: will globally
change locations but relatively not
change local relationship C2 and C3
2-D Transformations
9
Move each local coordinate to a world coordinate
Model is defined in a local coordinate
2-D Transformations
10
2-D Transformations
11
a. Usually, (0,0) point
is used to align
local and world coordinates
First
b. (0,0) will not be
Changed for scaling
and rotation
2-D Transformations
12
2-D Transformations
13
2-D Transformations
14
Basic 2D Transformations
15
Basic 2D Transformations
16
Sx>1
Sy>1
Scaling Around A Point
17
Scaling
S = S(sx, sy, sz) =
18
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
19
Angel: Interactive Computer Graphics 5E © Addison-Wesley 2009
original
sx = -1 sy = 1
sx = -1 sy = -1
sx = 1 sy = -1
April 2010
20
Move to origin
Scale
Move back
Basic 2D Transformations
21
Rotation around the origin (2-D)
22
Ex: polar coordinate (極座標)
Rotation around the origin (2-D)
23
Counterclockwise i.e., 逆時針方向 (positive)
Rotation around the origin (2-D)
24
Rotation (3-D)
25
Rotation (3-D)
Counterclockwise
i.e., 逆時針方向
(positive)
27
Basic 2D Transformations
28
29
2D Rotation at any pivot
30
樞軸;支點
Basic 2D Transformations
31
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
32
Angel: Interactive Computer Graphics 5E © Addison-Wesley 2009
object
translation: every point displaced
by same vector
Basic 2D Transformations
33
General 2D Rotation at (Xr,Yr)
April 2010
34
Move to origin
Rotate
Move back
Matrix Representation
35
Matrix Representation
36
2x2 Matrix
37
2x2 Matrix
38
Shear (2-D)
39
Shear (3-D)
40
2x2 Matrix
41
2x2 Matrix
42
2D Reflections
April 2010
43
2x2 Matrix
44
2D Translation
45
Ex: (x,y) is represented by (x,y,1) in homogenous coordinate
Basic 2D Transformations
46
Homogeneous Coordinates
47
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
48
w=1
Matrix Composition
49
i.e. 1 point is OK
i.e. if many points are used, matries are composed first
Matrix Composition
50
(交換律)
T*R*P != RT*P
Matrix Composition
51
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
52
w=1
Basic 3D Transformations
53
w=1
Basic 3D Transformations
54
General rotation about an axis
55
Developing the General Rotation Matrix�
56
t= <Xv, Yv, Zv>
→
57
58
59
60
61
62
Q’ = Q x
Q
Q’
Developing the General Rotation Matrix
63
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
Rotation y axis by
OpenGL transformation Matrices
object
object
glutSolidSphere(1.0, 50, 50);
Example -1
65
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 earth
Adding more …………………………….. // the moon
glPopMatrix();
// swap the front and back buffers
glutSwapBuffers();
}
66
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)
}
67
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);
}
}
68
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;
}
69
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();
}
70
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 土星
71
72
Rotate C1: will globally
change locations but relatively not
change local relationship C2 and C3
73
upper
lower
child is transformed relative to its parent
74
child is transformed relative to its parent’s new
position
75
3D Example: A robot arm
76
/**upper_arm;
/**lower_arm;
OpenGL better implementation
77
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
90
Torso
Transformation Hierarchies Scene graphs
Root
Transform
Head Rotate first and then translate
Rotate
Rotate
translate
Store first
Recover
OpenGL transformation Matrices
91
A more complex example
92
93
94
p1
t1
t2
n
p0
p2
95
p.s.vector will not be changed by translation matrix
96
Inverse Transformation
97
OpenGL transformation Matrices
98
99
100
101
102
103
104
105
106
107
108
109
110
Skeleton Animation
Animation Setup Transfer for 3D Characters
111
112
113
OpenGL Skeletal Animation Tutorial
115
https://youtu.be/PA_e9EyzHe0
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
116
117
118
(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)�
119
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
120