Thanks to visit codestin.com
Credit goes to www.scribd.com

0% found this document useful (0 votes)
73 views5 pages

03 Transforms 3 D

Uploaded by

Wafa Elgalhoud
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
73 views5 pages

03 Transforms 3 D

Uploaded by

Wafa Elgalhoud
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

Translation

3D Transformations

CS 4620 Lecture 3

Cornell CS4620 Fall 2010 •!Lecture 3 © 2010 Doug James • 1 Cornell CS4620 Fall 2010 •!Lecture 3 © 2010 Doug James • 2

Scaling Rotation about z axis

Cornell CS4620 Fall 2010 •!Lecture 3 © 2010 Doug James • 3 Cornell CS4620 Fall 2010 •!Lecture 3 © 2010 Doug James • 4
Rotation about x axis Rotation about y axis

Cornell CS4620 Fall 2010 •!Lecture 3 © 2010 Doug James • 5 Cornell CS4620 Fall 2010 •!Lecture 3 © 2010 Doug James • 6

Transformations in OpenGL Transformations in OpenGL!


• Stack-based manipulation of model-view transformation, M glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
• glMatrixMode(GL_MODELVIEW) Specifies model-view matrix
{// Draw something:
glPushMatrix();
• glLoadIdentity() M ! 4x4 identity glTranslatef(...);
glRotatef(15f, ...);
• glTranslatef(float ux, float uy, float uz) M ! MT {// set color and draw simplices
glBegin(GL_TRIANGLES);
glColor3f(...);
• glRotatef(float theta, float ux, float uy, float uz) M!MR glVertex3f(...);
glVertex3f(...);
• glScalef(float sx, float sy, float sz) M!MS glVertex3f(...);
glEnd();
}
• glLoadMatrixf(float[] A) M !A (Note: column major) glPopMatrix(); // toss old transform
}
• glMultMatrixf(float[] A) M ! M A (Note: column major) {// Draw something else:
glPushMatrix();
• Manipulate matrix stack using: ...
glPopMatrix(); // toss old transform
– glPushMatrix()
}
– glPopMatrix()
Cornell CS4620 Fall 2010 •!Lecture 3 © 2010 Doug James • 7 Cornell CS4620 Fall 2010 •!Lecture 3 © 2010 Doug James • 8
Transformations in OpenGL! General Rotation Matrices
• A rotation in 2D is around a point
– Tutors demo
• A rotation in 3D is around an axis
– so 3D rotation is w.r.t a line, not just a point
– there are many more 3D rotations than 2D
• a 3D space around a given point, not just 1D

2D 3D
Cornell CS4620 Fall 2010 •!Lecture 3 © 2010 Doug James • 9 Cornell CS4620 Fall 2010 •!Lecture 3 © 2010 Doug James • 10

Properties of Rotation Matrices Specifying rotations


• Columns of R are mutually orthonormal: RRT=RTR=I • In 2D, a rotation just has an angle
– if it’s about a particular center, it’s a point and angle
• Right-handed coordinate systems: det(R)=1
– Recall definition of det(R)=r1T(r2xr3) • In 3D, specifying a rotation is more complex
– basic rotation about origin: unit vector (axis) and angle
• Such 3x3 rotation matrices belong to group, SO(3) • convention: positive rotation is CCW when vector is pointing at you
– Special orthogonal – about different center: point (center), unit vector, and angle
– Special --> det(R)=1 • this is redundant: think of a second point on the same axis...

• Alternative: Euler angles


– stack up three coord axis rotations
• ZYX case: Rz(az)*Ry(ay)*Rx(ax)
– degeneracies exist for some angles
– E.g., gimbal lock
– Black board
Unlocked Gimbal lock
Cornell CS4620 Fall 2010 •!Lecture 3 © 2010 Doug James • 11 Cornell CS4620 Fall 2010 •!Lecture 3 © 2010 Doug James • 12
Coming up with the matrix Building general rotations
• Showed matrices for coordinate axis rotations • Using elementary transforms you need three
– but what if we want rotation about some random axis? – translate axis to pass through origin
– rotate about y to get into x-y plane
• Can compute by composing elementary transforms – rotate about z to align with x axis
– transform rotation axis to align with x axis
– apply rotation • Alternative: construct frame and change coordinates
– inverse transform back into position – choose p, u, v, w to be orthonormal frame with p and u matching the
rotation axis
• Just as in 2D this can be interpreted as a similarity transform
– apply similarity transform T = F Rx(! ) F–1

Cornell CS4620 Fall 2010 •!Lecture 3 © 2010 Doug James • 13 Cornell CS4620 Fall 2010 •!Lecture 3 © 2010 Doug James • 14

Orthonormal frames in 3D! Building 3D frames


• Useful tools for constructing transformations • Given a vector a and a secondary vector b
– The u axis should be parallel to a; the u–v plane should contain b
• Recall rigid motions • u = u / ||u||
– affine transforms with pure rotation • w = u x b; w = w / ||w||
– columns (and rows) form right-handed ONB • v=wxu
• that is, an orthonormal basis
• Given just a vector a
– The u axis should be parallel to a; don’t care about orientation about
that axis
• Same process but choose arbitrary b first
• Good choice is not near a: e.g. set smallest entry to 1

Cornell CS4620 Fall 2010 •!Lecture 3 © 2010 Doug James • 15 Cornell CS4620 Fall 2010 •!Lecture 3 © 2010 Doug James • 16
Building general rotations Derivation of General Rotation Matrix
• Alternative: construct frame and change coordinates • General 3x3 3D rotation matrix
– choose p, u, v, w to be orthonormal frame with p and u matching the
rotation axis • General 4x4 rotation about an arbitrary point
– apply similarity transform T = F Rx(! ) F–1
– interpretation: move to x axis, rotate, move back
– interpretation: rewrite u-axis rotation in new coordinates
– (each is equally valid)

• Or just derive the formula once, and reuse it (more later)

Cornell CS4620 Fall 2010 •!Lecture 3 © 2010 Doug James • 17 Cornell CS4620 Fall 2010 •!Lecture 3 © 2010 Doug James • 18

Building transforms from points Transforming normal vectors


• Recall: 2D affine transformation has 6 degrees of freedom • Transforming surface normals
(DOFs) – differences of points (and therefore tangents) transform OK
– this is the number of “knobs” we have to set to define one – normals do not --> use inverse transpose matrix
• Therefore 6 constraints suffice to define the transformation
– handy kind of constraint: point p maps to point q (2 constraints at once)
– three point constraints add up to constrain all 6 DOFs
(i.e. can map any triangle to any other triangle)
• 3D affine transformation has 12 degrees of freedom
– count them by looking at the matrix entries we’re allowed to change
• Therefore 12 constraints suffice to define the transformation
– in 3D, this is 4 point constraints
(i.e. can map any tetrahedron to any other tetrahedron)

Cornell CS4620 Fall 2010 •!Lecture 3 © 2010 Doug James • 19 Cornell CS4620 Fall 2010 •!Lecture 3 © 2010 Doug James • 20

You might also like