2D/3D Model Geometrical �Transformation
Tong-Yee Lee
1
positive rotation
Outline
3
scale
4
Polygon Mesh
Normal vectors
Overview
5
Viewing Transformation
Modeling Transform
6
https://www.programmersought.com/article/32674581372/
7
Its own local coordinate
Modeling Transform
Move each local coordinate to a world coordinate�
8
9
View Transform
Local coordinate systems v.s. global coordinate system
Camera is defined at global coordinate system
2-D Transformations
10
Move each local coordinate to a world coordinate
Model is defined in a local
2-D Transformations
11
2-D Transformations
12
Usually, (0,0) point
is used to align (對位)
local and world coordinates
first
2-D Transformations
13
2-D Transformations
14
2-D Transformations
15
Basic 2D Transformations
16
Basic 2D Transformations
17
Sx>1
Sy>1
Scaling Around A Point
18
Scaling
S = S(sx, sy, sz) =
19
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
20
Angel: Interactive Computer Graphics 5E © Addison-Wesley 2009
original
sx = -1 sy = 1
sx = -1 sy = -1
sx = 1 sy = -1
April 2010
21
Move to origin
Scale
Move back
Basic 2D/3D Transformations
22
Rotation around the origin (2-D)
23
Ex: polar coordinate (極座標)
Rotation around the origin (2-D)
24
Counterclockwise i.e., 逆時針方向 (positive)
Rotation around the origin (2-D)
25
Matrix(矩陣)
Rotation (3-D)
26
Rotation (3-D)
Counterclockwise
i.e., 逆時針方向
(positive)
28
Basic 2D Transformations
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
(i.e., to initialize matrix)
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
(交換律)
51
T*R*P != RT*P
Matrix Composition
52
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
53
w=1
Basic 3D Transformations
54
w=1
Basic 3D Transformations
55
General rotation about an axis t�from a point P
56
Developing the General Rotation Matrix�
57
t= <Xv, Yv, Zv>
→
58
59
60
61
62
63
Developing the General Rotation Matrix
64
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
65
glutWireSphere(0.5, 10, 8);
glutWireSphere(1.0, 10, 8);
Example -1
66
Example -3
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
glPopMatrix();
// swap the front and back buffers
glutSwapBuffers();
}
67
Call GL_ display once
Push (original) i.e., 0
Rotate angles
Pop() to the original, i.e., 0
planet:
from local
to global
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)
}
68
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);
}
}
69
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;
}
70
71
72
Hierarchical Scene
73
child is transformed relative to its parent’s new
position
74
upper
lower
child is transformed relative to its parent
75
3D Example: A robot arm
76
From local to global
OpenGL better implementation
77
From local to global
OpenGL transformation Matrices
78
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
91
Torso
Transformation Hierarchies Scene graphs
Root
Transform
Head Rotate first and then translate
Rotate
Rotate
translate
Store first
Recover
A more complex example
92
93
94
3D Skeleton Animation
95
p1
t1
t2
n
p0
p2
96
p.s.vector will not be changed by translation matrix
97
Inverse Transformation
98
OpenGL transformation Matrices
99
100
101
102
103
104
105
106
107
108
109
110