1 of 110

2D/3D Model Geometrical �Transformation

Tong-Yee Lee

1

positive rotation

2 of 110

  • 3D Graphics Pipeline

3 of 110

Outline

  • General Geometry Transform
    • Scaling, rotation, translation etc

3

scale

4 of 110

4

Polygon Mesh

Normal vectors

5 of 110

Overview

  • 2D transformations
    • Basic 2-D transformations
    • Matrix representation
    • Matrix composition
  • 3D transformations
    • Basic 3-D transformation
    • Same as 2-D
  • Transformation Hierarchies
    • Scene graphs

5

Viewing Transformation

6 of 110

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

6

https://www.programmersought.com/article/32674581372/

7 of 110

7

Its own local coordinate

Modeling Transform

8 of 110

Move each local coordinate to a world coordinate

8

9 of 110

9

View Transform

Local coordinate systems v.s. global coordinate system

Camera is defined at global coordinate system

10 of 110

2-D Transformations

10

Move each local coordinate to a world coordinate

Model is defined in a local

11 of 110

2-D Transformations

11

12 of 110

2-D Transformations

12

Usually, (0,0) point

is used to align (對位)

local and world coordinates

first

13 of 110

2-D Transformations

13

14 of 110

2-D Transformations

14

15 of 110

2-D Transformations

15

16 of 110

Basic 2D Transformations

16

17 of 110

Basic 2D Transformations

17

Sx>1

Sy>1

18 of 110

Scaling Around A Point

18

19 of 110

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

20 of 110

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

21 of 110

 

April 2010

21

Move to origin

Scale

Move back

22 of 110

Basic 2D/3D Transformations

22

 

23 of 110

Rotation around the origin (2-D)

23

Ex: polar coordinate (極座標)

24 of 110

Rotation around the origin (2-D)

24

Counterclockwise i.e., 逆時針方向 (positive)

25 of 110

Rotation around the origin (2-D)

25

Matrix(矩陣)

26 of 110

Rotation (3-D)

26

27 of 110

Rotation (3-D)

Counterclockwise

i.e., 逆時針方向

(positive)

28 of 110

28

29 of 110

Basic 2D Transformations

29

30 of 110

2D Rotation at any pivot

30

樞軸;支點

31 of 110

Basic 2D Transformations

31

32 of 110

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

33 of 110

Basic 2D Transformations

33

34 of 110

General 2D Rotation at (Xr,Yr)

April 2010

34

Move to origin

Rotate

Move back

35 of 110

Matrix Representation

35

36 of 110

Matrix Representation

36

37 of 110

2x2 Matrix

37

(i.e., to initialize matrix)

38 of 110

2x2 Matrix

38

39 of 110

Shear (2-D)

39

40 of 110

Shear (3-D)

40

41 of 110

2x2 Matrix

41

42 of 110

2x2 Matrix

42

43 of 110

2D Reflections

April 2010

43

44 of 110

2x2 Matrix

44

45 of 110

2D Translation

45

Ex: (x,y) is represented by (x,y,1) in homogenous coordinate

46 of 110

Basic 2D Transformations

46

47 of 110

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

48 of 110

Matrix Composition

48

w=1

49 of 110

Matrix Composition

49

i.e. 1 point is OK

i.e. if many points are used, matries are composed first

50 of 110

Matrix Composition

50

(交換律)

51 of 110

51

T*R*P != RT*P

 

52 of 110

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

53 of 110

3D Transformations

53

w=1

54 of 110

Basic 3D Transformations

54

w=1

55 of 110

Basic 3D Transformations

55

56 of 110

General rotation about an axis t�from a point P

56

57 of 110

Developing the General Rotation Matrix

57

t= <Xv, Yv, Zv>

58 of 110

58

59 of 110

59

60 of 110

60

61 of 110

61

62 of 110

62

63 of 110

63

64 of 110

Developing the General Rotation Matrix

  • Be careful …………

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

65 of 110

OpenGL transformation Matrices

65

glutWireSphere(0.5, 10, 8);

glutWireSphere(1.0, 10, 8);

66 of 110

Example -1

  • planet.c
    • Control:
      • ‘d’
      • ‘y’
      • ‘a’
      • ‘A’
      • ESC

66

67 of 110

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

68 of 110

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

69 of 110

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

70 of 110

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 of 110

71

72 of 110

72

Hierarchical Scene

73 of 110

73

child is transformed relative to its parent’s new

position

74 of 110

74

upper

lower

child is transformed relative to its parent

75 of 110

75

3D Example: A robot arm

76 of 110

76

From local to global

77 of 110

OpenGL better implementation

77

From local to global

78 of 110

OpenGL transformation Matrices

78

79 of 110

A More Complex Example: Human Figure

torso

80 of 110

A More Complex Example: Human Figure

What’s the most efficient way to draw this figure?

torso

81 of 110

A More Complex Example: Human Figure

What’s the most sensible way to traverse this tree?

torso

82 of 110

A More Complex Example: Human Figure

What’s the most sensible way to traverse this tree?

torso

83 of 110

A More Complex Example: Human Figure

What’s the most sensible way to traverse this tree?

torso

84 of 110

A More Complex Example: Human Figure

What’s the most sensible way to traverse this tree?

torso

85 of 110

A More Complex Example: Human Figure

What’s the most sensible way to traverse this tree?

torso

86 of 110

A More Complex Example: Human Figure

What’s the most sensible way to traverse this tree?

torso

87 of 110

A More Complex Example: Human Figure

What’s the most sensible way to traverse this tree?

torso

88 of 110

A More Complex Example: Human Figure

What’s the most sensible way to traverse this tree?

torso

89 of 110

A More Complex Example: Human Figure

What’s the most sensible way to traverse this tree?

torso

90 of 110

A More Complex Example: Human Figure

What’s the most sensible way to traverse this tree?

torso

91 of 110

91

Torso

Transformation Hierarchies Scene graphs

Root

Transform

Head Rotate first and then translate

Rotate

Rotate

translate

Store first

Recover

92 of 110

A more complex example

92

93 of 110

93

94 of 110

94

3D Skeleton Animation

95 of 110

95

p1

t1

t2

n

p0

p2

96 of 110

96

p.s.vector will not be changed by translation matrix

97 of 110

97

98 of 110

Inverse Transformation

98

99 of 110

OpenGL transformation Matrices

99

100 of 110

100

101 of 110

101

102 of 110

102

103 of 110

103

104 of 110

104

105 of 110

105

106 of 110

106

107 of 110

107

108 of 110

108

109 of 110

109

110 of 110

110