1 of 114

Geometrical �Transformation

1

positive rotation

Tong-Yee Lee

2 of 114

  • 3D Graphics Pipeline

3 of 114

Outline

  • General Geometry Transform
    • Scaling, rotation, translation etc

3

scale

4 of 114

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

5 of 114

5

Basic Concept

Local coordinate systems v.s. global coordinate system

6 of 114

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

6

Viewing Transformation

7 of 114

7

Rotate C1: will globally

change locations but relatively not

change local relationship C2 and C3

8 of 114

2-D Transformations

8

Move each local coordinate to a world coordinate

Model is defined in a local coordinate

9 of 114

2-D Transformations

9

10 of 114

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

11 of 114

2-D Transformations

11

12 of 114

2-D Transformations

12

13 of 114

2-D Transformations

13

14 of 114

Basic 2D Transformations

14

15 of 114

Basic 2D Transformations

15

Sx>1

Sy>1

16 of 114

Scaling Around A Point

16

17 of 114

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

18 of 114

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

19 of 114

 

April 2010

19

Move to origin

Scale

Move back

20 of 114

Basic 2D Transformations

20

 

21 of 114

Rotation around the origin (2-D)

21

Ex: polar coordinate (極座標)

22 of 114

Rotation around the origin (2-D)

22

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

23 of 114

Rotation around the origin (2-D)

23

24 of 114

Rotation (3-D)

24

25 of 114

Rotation (3-D)

Counterclockwise

i.e., 逆時針方向

(positive)

26 of 114

26

27 of 114

Basic 2D Transformations

27

28 of 114

28

29 of 114

2D Rotation at any pivot

29

樞軸;支點

30 of 114

Basic 2D Transformations

30

31 of 114

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

32 of 114

Basic 2D Transformations

32

33 of 114

General 2D Rotation at (Xr,Yr)

April 2010

33

Move to origin

Rotate

Move back

34 of 114

Matrix Representation

34

35 of 114

Matrix Representation

35

36 of 114

2x2 Matrix

36

37 of 114

2x2 Matrix

37

38 of 114

Shear (2-D)

38

39 of 114

Shear (3-D)

39

40 of 114

2x2 Matrix

40

41 of 114

2x2 Matrix

41

42 of 114

2D Reflections

April 2010

42

43 of 114

2x2 Matrix

43

44 of 114

2D Translation

44

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

45 of 114

Basic 2D Transformations

45

46 of 114

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

47 of 114

Matrix Composition

47

w=1

48 of 114

Matrix Composition

48

i.e. 1 point is OK

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

49 of 114

Matrix Composition

49

(交換律)

T*R*P != RT*P

50 of 114

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

51 of 114

3D Transformations

51

w=1

52 of 114

Basic 3D Transformations

52

w=1

53 of 114

Basic 3D Transformations

53

54 of 114

General rotation about an axis

54

55 of 114

Developing the General Rotation Matrix

55

t= <Xv, Yv, Zv>

56 of 114

56

57 of 114

57

58 of 114

58

59 of 114

59

60 of 114

60

61 of 114

61

62 of 114

Developing the General Rotation Matrix

  • Be careful …………

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

63 of 114

OpenGL transformation Matrices

object

object

glutSolidSphere(1.0, 50, 50);

(4,5,6)

64 of 114

Example -1

  • planet.c
    • Control:
      • ‘d’day ;自轉
      • ‘y’year ; 公轉 along sun
      • ‘a’; 自轉 & 公轉
      • ‘A’
      • ESC

64

65 of 114

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

66 of 114

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

67 of 114

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

68 of 114

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

69 of 114

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

70

71 of 114

71

upper

lower

child is transformed relative to its parent

72 of 114

72

child is transformed relative to its parent’s new

position

73 of 114

73

3D Example: A robot arm

74 of 114

74

75 of 114

OpenGL better implementation

75

changed

76 of 114

A More Complex Example: Human Figure

torso

77 of 114

A More Complex Example: Human Figure

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

torso

78 of 114

A More Complex Example: Human Figure

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

torso

79 of 114

A More Complex Example: Human Figure

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

torso

80 of 114

A More Complex Example: Human Figure

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

torso

81 of 114

A More Complex Example: Human Figure

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

torso

82 of 114

A More Complex Example: Human Figure

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

torso

83 of 114

A More Complex Example: Human Figure

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

torso

84 of 114

A More Complex Example: Human Figure

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

torso

85 of 114

A More Complex Example: Human Figure

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

torso

86 of 114

A More Complex Example: Human Figure

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

torso

87 of 114

A More Complex Example: Human Figure

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

torso

88 of 114

88

Torso

Transformation Hierarchies Scene graphs

Root

Transform

Head Rotate first and then translate

Rotate

Rotate

translate

Store first

Recover

89 of 114

OpenGL transformation Matrices

89

90 of 114

A more complex example

90

91 of 114

91

92 of 114

92

p1

t1

t2

n

p0

p2

93 of 114

93

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

94 of 114

94

95 of 114

Inverse Transformation

95

96 of 114

OpenGL transformation Matrices

96

97 of 114

97

98 of 114

98

99 of 114

99

100 of 114

100

101 of 114

101

102 of 114

102

103 of 114

103

104 of 114

104

105 of 114

105

106 of 114

106

107 of 114

107

108 of 114

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

109

OpenGL Skeletal Animation Tutorial 

110 of 114

110

111 of 114

111

112 of 114

112

(a)

(b)

Step 1:

Separate

x vector

Note: vector a

is a unit vector

i.e: cos(90-Ɵ) = sin(Ɵ)

��Angular displacementglRotate(θ, Ax,Ay,Az)�

113 of 114

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

114