Geometrical Transformation TongYee Lee 1 Course Outline 3




























































































- Slides: 92
Geometrical Transformation Tong-Yee Lee 1
Course Outline 3 D Graphics Pipeline Modeling (Creating 3 D Geometry, viewing, animating) Rendering (Shading images from geometry, lighting, materials)
Outline General Transform Scale, rotation, translation etc scale
Modeling Transform Specify transformation for objects Allow definitions of objects in own local coordinate systems Allow use of object definition multiple times in a scene Insert each local object into different locations of world coordinate 4
Overview 2 D transformations Basic 2 -D transformations Matrix representation Matrix composition 3 D transformations Basic 3 -D transformation Same as 2 -D Transformation Hierarchies Scene graphs Torso Viewing Transformation 5
2 -D Transformations Model is defined in a local Move each local coordinate to a world coordinate 6
2 -D Transformations 7
2 -D Transformations Usually, (0, 0) point is used to align local and world coordinates first 8
2 -D Transformations 9
2 -D Transformations 10
2 -D Transformations 11
Basic 2 D Transformations 12
Basic 2 D Transformations Sx>1 Sy>1 13
Scaling Around A Point 14
Scaling Expand or contract along each axis (fixed point of origin) Sx=0. 5 Sy=1. 5 Sz=1. 0 x’=sxx y’=syy z’=szz p’=Sp S = S(sx, sy, sz) = Sx=Sy=Sz=0. 5 15 Angel: Interactive Computer Graphics 5 E © Addison-Wesley 2009
Reflection corresponds to negative scale factors sx = -1 sy = 1 original sx = -1 sy = -1 sx = 1 sy = -1 16 Angel: Interactive Computer Graphics 5 E © Addison-Wesley 2009
Move to origin April 2010 Scale Move back 17
Basic 2 D Transformations 18
Rotation around the origin (2 -D) Ex: polar coordinate (極座標) 19
Rotation around the origin (2 -D) Counterclockwise i. e. , 逆時針方向 (positive) 20
Rotation around the origin (2 -D) 21
Rotation (3 -D) 22
Rotation (3 -D) Counterclockwise i. e. , 逆時針方向 (positive)
24
Basic 2 D Transformations 25
2 D Rotation at any pivot 樞軸;支點 26
Basic 2 D Transformations 27
Translation Although we can move a point to a new location in infinite ways, when we move many points there is usually one way object 28 translation: every point displaced by same vector Angel: Interactive Computer Graphics 5 E © Addison-Wesley 2009
Basic 2 D Transformations 29
General 2 D Rotation at (Xr, Yr) Move to origin April 2010 Rotate Move back 30
Matrix Representation 31
Matrix Representation 32
2 x 2 Matrix 33
2 x 2 Matrix 34
Shear (2 -D) 35
Shear (3 -D) 36
2 x 2 Matrix 37
2 x 2 Matrix 38
2 D Reflections April 2010 39
2 x 2 Matrix 40
2 D Translation Ex: (x, y) is represented by (x, y, 1) in homogenous coordinate 41
Basic 2 D Transformations 42
Homogeneous Coordinates i. e. , projection, w is related to depth from eye i. e. , vector (x 1, y 1, 1) – (x 2, y 2, 1) = (x 1 -x 2. y 1 -y 2, 0) i. e. depth in w coordinate 43
Matrix Composition w=1 44
Matrix Composition i. e. 1 point is OK i. e. if many points are used, matries are composed first 45
Matrix Composition (交換律) T*R*P != RT*P 46
Matrix Composition i. e. , M= T(a, b)*R(Q)*T(-a, -b) P’=M*P 47
3 D Transformations w=1 48
Basic 3 D Transformations w=1 49
Basic 3 D Transformations 50
General rotation about an axis 51
Developing the General Rotation Matrix → t= <Xv, Yv, Zv> 52
53
54
55
56
57
58
Developing the General Rotation Matrix Be careful ………… X (+, +) Z (-, -) In both cases, tan(y/x) are positive. So, we need to carefully choose it by checking the signs of x and y 59
Example -1 planet. c Control: • • • ‘d’ ‘y’ ‘a’ ‘A’ ESC 60
Example -3 void GL_display() // GLUT display function { // clear t he buffer gl. Clear(GL_COLOR_BUFFER_BIT); gl. Color 3 f(1. 0, 1. 0); gl. Push. Matrix(); glut. Wire. Sphere(1. 0, 20, 16); gl. Rotatef(year, 0. 0, 1. 0, 0. 0); gl. Translatef(3. 0, 0. 0); gl. Rotatef(day, 0. 0, 1. 0, 0. 0); glut. Wire. Sphere(0. 5, 10, 8); gl. Pop. Matrix(); // swap the front and back buffers glut. Swap. Buffers(); Call GL_ display once Push (original) i. e. , 0 Rotate angles Pop() to the original, i. e. , 0 // the Sun // the Planet } 61
Example -4 void GL_idle() // GLUT idle function { day += 10. 0; if(day > 360. 0) day -= 360. 0; year += 1. 0; if(year > 360. 0) year -= 360. 0; (i. e. , planet self-rotation +10 degrees, faster) (i. e. , planet rotate sun + 1 degree, slower) // recall GL_display() function glut. Post. Redisplay(); (i. e. , call run display function) } 62
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; glut. Post. Redisplay(); break; case 'y': year += 1. 0; if(year > 360. 0) year -= 360. 0; glut. Post. Redisplay(); break; case 'a': glut. Idle. Func(GL_idle); // assign idle function break; case 'A': glut. Idle. Func(0); break; case 27: exit(0); } } 63
Example -6 int main(int argc, char** argv) { glut. Init(&argc, argv); glut. Init. Window. Size(500, 500); glut. Init. Window. Position(0, 0); glut. Init. Display. Mode(GLUT_DOUBLE | GLUT_RGB); glut. Create. Window("Planet"); init(); glut. Display. Func(GL_display); glut. Reshape. Func(GL_reshape); glut. Keyboard. Func(GL_keyboard); glut. Main. Loop(); return 0; } 64
Another Example: Robot 65
Rotation center is at (-1, 0, 0) instead of (0, 0, 0) Note: repeat if we add longer shoulder elbow 66 i. e. , Green bone is related to blue bone coordinat
67
n p 0 t 2 t 1 p 2 p 1 68
p. s. vector will not be changed by translation matrix 69
70
Inverse Transformation 71
Open. GL transformation Matrices 72
Open. GL transformation Matrices 73
Open. GL transformation Matrices 74
Hierarchical Object Animation Example Using Open. GL 75
76
77
78
79
80
81
82
83
84
85
86
Developing the General Rotation Matrix Another problem is: rotation interpolation is not easy and not good reported in many papers. 87
88
89
Angular displacement gl. Rotate(q, Ax, Ay, Az) ( , n) defines an angular displacement of about an axis u or n for rotating a vector v 90
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 91
92