CSCI 420: Computer Graphics
Hao Li
http://cs420.hao-li.com
Fall 2017
2.2 Transformations
1
2.2 Transformations Hao Li http://cs420.hao-li.com 1 OpenGL - - PowerPoint PPT Presentation
Fall 2017 CSCI 420: Computer Graphics 2.2 Transformations Hao Li http://cs420.hao-li.com 1 OpenGL Transformations Matrices Model-view matrix (4x4 matrix) Projection matrix (4x4 matrix) vertices in canonical 3D world coordinate
CSCI 420: Computer Graphics
http://cs420.hao-li.com
Fall 2017
1
Model-view Projection vertices in canonical 3D world coordinate system vertices in 3D vertices in 2D
2
vertices in 2D vertices in 3D vertices in canonical 3D world coordinate system
Model-view Projection
3
vertices in 2D vertices in 3D vertices in canonical 3D world coordinate system
Model-view Projection
4
Model-view Projection
(must set matrix mode) : glMatrixMode (GL_MODELVIEW); glMatrixMode (GL_PROJECTION;
5
glMatrixMode (GL_MODELVIEW); glLoadIdentity(); // very common usage float m[16] = { … }; glLoadMatrixf(m); // rare, advanced glMultMatrixf(m); // rare, advanced
glTranslatef(dx, dy, dz); glRotatef(angle, vx, vy, vz); glScalef(sx, sy, sz);
6
world
7
world Initially (after glLoadIdentity()) : rendering coordinate system = world coordinate system
8
rendering coordinate system glTranslatef(x, y, z); world [x, y ,z]
9
rendering coordinate system glRotatef(angle,ax, ay, az); world
10
rendering coordinate system glScalef(sx, sy, sz); world
11
rendering coordinate system glMatrixMode (GL_MODELVIEW); glLoadIdentity(); glTranslatef(x, y, z); glRotatef(angle, ax, ay, az); glScalef(sx, sy, sz); renderBunny(); world
12
rendering coordinate system world How to obtain this frame?
13
Find glTranslate(…), glRotatef(…), glScalef(…) world How to obtain this frame?
14
glMatrixMode (GL_MODELVIEW); glLoadIdentity(); // render first bunny glPushMatrix(); // store current matrix glTranslate3f(…); glRotatef(…); renderBunny(); glPopMatrix(); // pop matrix // render second bunny glPushMatrix(); // store current matrix glTranslate3f(…); glRotatef(…); renderBunny(); glPopMatrix(); // pop matrix
15
16
multiplication
17
18
19
for
20
for and
21
22
perpendicular to both and
23
vectors and
24
vectors in a 3-dimensional vector space
for some scalars
25
26
27
28
1
2
3
1
2
3
29
30
, for any scalar
31
by 4x4 matrices world 4-vector 4-vector 4x4 matrix
32
33
34
35
36
37
OpenGL forms the corresponding 4x4 matrix, and multiplies the current modelview matrix with it.
38
39
40
41