Upload
others
View
4
Download
0
Embed Size (px)
Citation preview
Chapter 3:
Modeling Transformation
Graphics Programming, 8th Sep.
Graphics and Media Lab.
Seoul National University 2011 Fall
2 Graphics and Media Lab. at Seoul National University
• Every step in the graphics pipeline is related to the transformation.
OpenGL Steps
3 Graphics and Media Lab. at Seoul National University
• Euclidean (Rigid) motion– Preserves distance & angle.
• Similarity motion– Preserves angle.
• Linear motion– Preserves linearity.
Related Transformations (1/2)
4 Graphics and Media Lab. at Seoul National University
• Affine motion– Preserves parallel line.
• Projective motion– Preserves line.
How to represent ?
Related Transformations (2/2)
5 Graphics and Media Lab. at Seoul National University
• Euclidean transformation(SE3)
– Preserves distance & angle.(Translation, Rotation)
• Similarity transformation– Preserves angles.(Rotation, Isotropic scaling)
• Linear transformation(GL3)
– Preserves linearity.(Rotation,Scaling,Reflection,Shear)
• Affine transformation– Preserves parallel lines.
• Projective transformation– Preserves lines.
4x4 Matrix !
How about 3D points ?
Transformation Classes
6 Graphics and Media Lab. at Seoul National University
• We augment a point in R3 for the transformation matrices.– Modelview matrix has the form
– Projection matrix has the form (The next class!)
– Point [x y z 1]T
• The result of transformation needs to be divided by w to give the 3D position. (homogeneous)
– Vector [x y z 0]T
• w=0 represents a point at “ infinity”.
(Only direction differentiates.)
Homogeneous Coordinates
1000
3222120
2121110
1020100
taaa
taaa
taaa
7 Graphics and Media Lab. at Seoul National University
• OpenGL helps us to change the two most important transformation matrices:– Modelview Matrix
• The relative transformation between object and camera
– Projection Matrix
• Clipping volume (viewing frustum)
• Projection to screen
• Vertices(primitives) are transformed by P*M.
Modelview & Projection matrix
P M* *
8 Graphics and Media Lab. at Seoul National University
• Draw a transformed box in 3d.
Code Example from Ch.2
9 Graphics and Media Lab. at Seoul National University
• Resize() function was added.
• A few experiments with modeling transform
Code Example 1
10 Graphics and Media Lab. at Seoul National University
Result
11 Graphics and Media Lab. at Seoul National University
• glutMainLoop() instructs the program to enter the event processing loop.
• glutReshapeFunc() registers the resizing function as the callback function.
• glClear(…) clears video buffers.
• glViewport(x,y,w,h) sets the screen space.
• glMatrixMode(GL_PROJECTION) tells that we modify the projection matrix.
• glMatrixMode(GL_MODELVIEW) tells that we modify the modelviewmatrix.
• glLoadIdentity() replaces the current matrix with the identity matrix.
• glOrtho(l,r,b,t,zn,zf) sets the clipping space orthographically. This changes the projection matrix.
• glTranslatef(),glRotatef(), and glScalef() change the modelview matrix.
Code Example 1 - Explanation
12 Graphics and Media Lab. at Seoul National University
glLoadIdentity(); // C = I
glMultMatrixf(N); // C = N
glMultMatrixf(M); // C = NM
glMultMatrixf(L); // C = NML
glBegin(GL_POINTS);
glVertex3f(v); // NMLv
glEnd();
The Order of Transformations
Application
13 Graphics and Media Lab. at Seoul National University
• 45 deg rotation around z-axis then 10 unit translation along +x, and vice versa.
The Order is Important
14 Graphics and Media Lab. at Seoul National University
• Code for rot then trans wrt fixed coords.
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glMultMatrixf(T);
glMultMatrixf(R);
draw_the_object();
Thinking in Terms of Fixed Coords
15 Graphics and Media Lab. at Seoul National University
• Code for trans then rot wrt local coords.
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glMultMatrixf(T);
glMultMatrixf(R);
draw_the_object();
Thinking in Terms of Local Coords
16 Graphics and Media Lab. at Seoul National University
• Code for rot then trans wrt local coords.
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glMultMatrixf(R);
glMultMatrixf(T);
draw_the_object();
Thinking in Terms of Local Coords
17 Graphics and Media Lab. at Seoul National University
• We can manage the hierarchy by glPushMatrix(), glPopMatrix().
Push & Pop
P M*
M1
Vertices
of shoulder
Vertices
of body
Vertices
of arm
M2
* * *
Push
Push
Pop
Pop
18 Graphics and Media Lab. at Seoul National University
• Robot arm
Code Example 2
unit cube: [-0.5,0.5]^3
19 Graphics and Media Lab. at Seoul National University
Result
20 Graphics and Media Lab. at Seoul National University
• glutKeyboardFunc() registers the key function as the callback function:– If „s‟ is pressed, rotate shoulder– If „S‟ is pressed, rotate shoulder reversely– If „e‟ is pressed, rotate elbow– If „E‟ is pressed, rotate elbow reversely
• glPushMatrix() saves the current matrix.
• glPopMatrix() loads the saved matrix.
• gluPerpective(fov,ratio,zn,zf) sets the view frustum. This changes the projection matrix.
• glTranslatef(0,0,-1);glRotatef(-angle,0,0,1);glTranslatef(0,0,1);– The rotation about a point
Code Example 2 - Explanation