1 of 120

Geometrical Transformation

1

positive rotation

Tong-Yee Lee

2 of 120

3D Graphics Pipeline

3 of 120

Outline

  • General Geometry Transform
    • Scaling, rotation, translation etc

3

scale

4 of 120

Modeling Transform

  • Specify transformation for objects
    • Allow definitions of objects in own local coordinate systems, i.e., defined by struct in C or C++ malloc
    • Allow use of object definition multiple times in a scene
    • Insert each local object into different locations of world coordinate
    • http://www.cburch.com/cs/490/sched/feb8/

4

glutSolidSphere(1.0, 10, 10)

5 of 120

5

Basic Concept

Local coordinate systems v.s. global coordinate system

View coordinate

systems

6 of 120

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 120

7

Hierarchical modeling

8 of 120

8

Rotate C1: will globally

change locations but relatively not

change local relationship C2 and C3

9 of 120

2-D Transformations

9

Move each local coordinate to a world coordinate

Model is defined in a local coordinate

10 of 120

2-D Transformations

10

11 of 120

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

12 of 120

2-D Transformations

12

13 of 120

2-D Transformations

13

14 of 120

2-D Transformations

14

15 of 120

Basic 2D Transformations

15

16 of 120

Basic 2D Transformations

16

Sx>1

Sy>1

17 of 120

Scaling Around A Point

17

18 of 120

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

19 of 120

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

20 of 120

 

April 2010

20

Move to origin

Scale

Move back

21 of 120

Basic 2D Transformations

21

 

22 of 120

Rotation around the origin (2-D)

22

Ex: polar coordinate (極座標)

23 of 120

Rotation around the origin (2-D)

23

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

24 of 120

Rotation around the origin (2-D)

24

25 of 120

Rotation (3-D)

25

26 of 120

Rotation (3-D)

Counterclockwise

i.e., 逆時針方向

(positive)

27 of 120

27

28 of 120

Basic 2D Transformations

28

29 of 120

29

30 of 120

2D Rotation at any pivot

30

樞軸;支點

31 of 120

Basic 2D Transformations

31

32 of 120

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 120

Basic 2D Transformations

33

34 of 120

General 2D Rotation at (Xr,Yr)

April 2010

34

Move to origin

Rotate

Move back

35 of 120

Matrix Representation

35

36 of 120

Matrix Representation

36

37 of 120

2x2 Matrix

37

38 of 120

2x2 Matrix

38

39 of 120

Shear (2-D)

39

40 of 120

Shear (3-D)

40

41 of 120

2x2 Matrix

41

42 of 120

2x2 Matrix

42

43 of 120

2D Reflections

April 2010

43

44 of 120

2x2 Matrix

44

45 of 120

2D Translation

45

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

46 of 120

Basic 2D Transformations

46

47 of 120

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 120

Matrix Composition

48

w=1

49 of 120

Matrix Composition

49

i.e. 1 point is OK

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

50 of 120

Matrix Composition

50

(交換律)

T*R*P != RT*P

51 of 120

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

52 of 120

3D Transformations

52

w=1

53 of 120

Basic 3D Transformations

53

w=1

54 of 120

Basic 3D Transformations

54

55 of 120

General rotation about an axis

55

56 of 120

Developing the General Rotation Matrix

56

t= <Xv, Yv, Zv>

57 of 120

57

58 of 120

58

59 of 120

59

60 of 120

60

61 of 120

61

62 of 120

62

Q’ = Q x

Q

Q’

63 of 120

Developing the General Rotation Matrix

  • Be careful..for example,

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

64 of 120

OpenGL transformation Matrices

object

object

glutSolidSphere(1.0, 50, 50);

65 of 120

Example -1

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

65

66 of 120

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

67 of 120

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

68 of 120

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

69 of 120

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

70 of 120

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

71

72 of 120

72

Rotate C1: will globally

change locations but relatively not

change local relationship C2 and C3

73 of 120

73

upper

lower

child is transformed relative to its parent

74 of 120

74

child is transformed relative to its parent’s new

position

75 of 120

75

3D Example: A robot arm

76 of 120

76

/**upper_arm;

/**lower_arm;

77 of 120

OpenGL better implementation

77

changed

78 of 120

A More Complex Example: Human Figure

torso

79 of 120

A More Complex Example: Human Figure

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

torso

80 of 120

A More Complex Example: Human Figure

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

torso

81 of 120

A More Complex Example: Human Figure

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

torso

82 of 120

A More Complex Example: Human Figure

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

torso

83 of 120

A More Complex Example: Human Figure

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

torso

84 of 120

A More Complex Example: Human Figure

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

torso

85 of 120

A More Complex Example: Human Figure

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

torso

86 of 120

A More Complex Example: Human Figure

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

torso

87 of 120

A More Complex Example: Human Figure

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

torso

88 of 120

A More Complex Example: Human Figure

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

torso

89 of 120

A More Complex Example: Human Figure

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

torso

90 of 120

90

Torso

Transformation Hierarchies Scene graphs

Root

Transform

Head Rotate first and then translate

Rotate

Rotate

translate

Store first

Recover

91 of 120

OpenGL transformation Matrices

91

92 of 120

A more complex example

92

93 of 120

93

94 of 120

94

p1

t1

t2

n

p0

p2

95 of 120

95

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

96 of 120

96

97 of 120

Inverse Transformation

97

98 of 120

OpenGL transformation Matrices

98

99 of 120

99

100 of 120

100

101 of 120

101

102 of 120

102

103 of 120

103

104 of 120

104

105 of 120

105

106 of 120

106

107 of 120

107

108 of 120

108

109 of 120

109

110 of 120

110

Skeleton Animation

Animation Setup Transfer for 3D Characters

111 of 120

111

112 of 120

112

113 of 120

113

OpenGL Skeletal Animation Tutorial 

114 of 120

114

115 of 120

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

116

117 of 120

117

118 of 120

118

(a)

(b)

Step 1:

Separate

x vector

Note: vector a

is a unit vector

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

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

119 of 120

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

120