1 / 59

Lecture 3: Transformations a nd Viewing

Lecture 3: Transformations a nd Viewing. General Idea. Object in model coordinates Transform into world coordinates Represent points on object as vectors Multiply by matrices. What next ?. 2D transformations: scale , shear , rotation Composing transform ations 3D rotations.

nerice
Download Presentation

Lecture 3: Transformations a nd Viewing

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Lecture 3: Transformations and Viewing

  2. General Idea • Object in model coordinates • Transform into world coordinates • Represent points on object as vectors • Multiply by matrices

  3. Whatnext? • 2D transformations: scale, shear, rotation • Composing transformations • 3D rotations

  4. (Nonuniform) Scale

  5. Shear

  6. Rotations 2D rotationsaresimple • Can we deriveit? x’,y’ x,y  

  7. Rotations, contd. Basic properties… • Linear • Commutative • R(X+Y)=R(X)+R(Y)

  8. Outline • 2D transformations: rotation, scale, shear • Composing transforms • 3D rotations • Translation: Homogeneous Coordinates • Transforming Normals

  9. Composing Transforms • Usually we build a complextransformation by composingsimpleones (for which we havematrixpatterns) • E.g. first scale then rotate • We seenowadvantageof matrix formulation: • Transformationisperformed for manypoints • Complextransformationis in advancedputinto a single matrix • In generalnotcommutative!! Order matters

  10. E.g. Composing rotations, scales • In terms of functions: • In terms of matrices: RS isalso a matrix • RS ≠ SR, not commutative

  11. Composingexample

  12. Inverting Composite Transforms • Say,wewant to invert a combination of 3 transforms • Option 1: Find composite matrix, invert • Option 2: Invert each transform and swap order • Obvious from properties of matrices

  13. Outline • 2D transformations: rotation, scale, shear • Composing transforms • 3D rotations • Translation: Homogeneous Coordinates • Transforming Normals

  14. Orthogonalmatrix Matrix Aisorthogonalif and onlyif E.g. Rotationmatrixisorthogonal. Checkit.

  15. Orthogonalmatrix Important and usefulproperty: It is much faster to transpose a matrix, than to invertit

  16. Rotations in 3D • Rotations about coordinate axes is a simpleextension of 2D rotations • Againorthogonalmatrices

  17. Interpretation 3D RotationsMatrix • Rows of matrix are thevectors of new coordinatesystem(the rotated one) • Oldcoordinateframe: x, y, z versors • Aftertransformation: • we havenewuvwcoordinateframe

  18. Geometric Interpretation 3D Rotations • Rows of matrix are 3 unit vectors of new coord frame • Can construct rotation matrix from 3 orthonormal vectors • Effectively, projections of point into new coord frame • New coord frame uvw taken to cartesian components xyz • Inverse or transpose takes xyz cartesian to uvw

  19. Non-Commutativity • Not Commutative (unlike in 2D)!! • Rotate by x, then y is not same as y then x • Order of applying rotations does matter • Follows from matrix multiplication not commutative • R1 * R2 is not the same as R2 * R1

  20. Translation • Translation isprobably the simplesttransformation (isit?), but there’ssomethingtrickyaboutit • E.g. move x by +7units, leave y, z unchanged: • How to express it in a matrix form? I.e.

  21. ?

  22. Homogeneous Coordinates • We need to adda fourth coordinate (w=1). It’squitecommonway in linear algebra, to getrid off freeterms. • 4x4 matrices in 3D space -very common in computergraphics • w maylooklike a dummyvariable – but mayplayit’s role

  23. Representation of Points (4-Vectors) Homogeneous coordinates • Divide by 4thcoord (w) to get (inhomogeneous) point • Multiplication by w > 0, no effect • Assume w ≥ 0. For w > 0, normal finite point. For w = 0, point at infinity (used for vectors to stop translation)

  24. Whatare the Advantages of Homogeneous Coords? • Unified framework for translationand othertransformations • Only4x4 matrix – easy to concatenate • Less problems with perspectiveviewing • No special cases – homogenousformulas

  25. General Translation Matrix

  26. 3 basicRotationMatrices

  27. Combining Translations, Rotations • Order matters!! TR is not the same as RT (demo) • General form for rigid body transforms • We show rotation first, then translation (commonly used to position objects) on next slide. Slide after that works it out the other way

  28. Combining Translations, Rotations First Rotation, thenTranslation First Translation, thenRotation

  29. Geometry Transformation • Transformationsarecomposed of fourelements • Viewingtransformation – positioning the camera • Modelingtransformation - movingobjects • (Viewing and Modelingarecomplementary) • Projection – on the plane • Viewport – mapping on the window Podstawy OpenGL

  30. Cameraanalogy Podstawy OpenGL

  31. Cameraanalogycontd. Podstawy OpenGL

  32. Twoways of makingtransformation in OpenGL • First approach: we operatedirectly on matrices • Second approach: we hidematrixtransformationsinsidefunctions • Which one isbetter?

  33. Twoways of makingtransformation in OpenGL • Functionstypical to ”old” OpenGL. • Cancelled in OpenGL 3.0 • Transformations and Projectionsmoved to shaderprogramming. • Not everyonelikeslow-levelshaderprogramming. • Search for newfunctions…

  34. GLM – OpenGLMathematics • Can be easilyfound onglm.g-truc.net/  , along with otherinformation • Can be treated as enhancement of GLSL. • IsincludedintounofficialOpenGL SDK

  35. Viewing

  36. Motivation • We have seen transforms (between coord systems) • But all that is in 3D • We still need to make a 2D picture • Project 3D to 2D. How do we do this? • This lecture is about viewing transformations

  37. Demo (Projection Tutorial) • Nate Robbins OpenGL tutors • http://user.xmission.com/~nate/ • Projection tutorial • OldOpenGL Style • Demo

  38. What we’ve seen so far • Transforms (translation, rotation, scale) as 4x4 homogeneous matrices • Last row always 0 0 0 1. Last w component always 1 • For viewing (perspective), we will use that last row and w component no longer 1 (must divide by it)

  39. Outline • Orthographic projection (simpler) • Perspective projection, basic idea • Derivation of gluPerspective (handout: glFrustum) • Brief discussion of nonlinear mapping in z

  40. Projections • To lower dimensional space (here 3D -> 2D) • Preserve straight lines • Trivial example: Drop one coordinate (Orthographic)

  41. Orthographic Projection • Characteristic: Parallel lines remain parallel • Useful for technical drawings etc. Perspective Orthographic

  42. Example • Simply project onto xy plane, drop z coordinate

  43. In general • We have a cuboid that we want to map to the normalized or square cube from [-1, +1] in all axes • We have parameters of cuboid (l,r ; t,b; n,f) t f y n b r l y y Translate Scale x x x z z z

  44. Orthographic Matrix • First center cuboid by translating • Then scale into unit cube t f y n b r l y y Translate Scale x x x z z z

  45. Transformation Matrix Scale Translation

  46. Caveats • Looking down –z, f and n are negative (n > f) • OpenGL convention: positive n, f, negate internally t f y n b r l y y Translate Scale x x x z z z

  47. Final Result

  48. Outline • Orthographic projection (simpler) • Perspective projection, basic idea • Derivation of gluPerspective (handout: glFrustum) • Brief discussion of nonlinear mapping in z

  49. Perspective Projection • Most common computer graphics, art, visual system • Further objects are smaller (size, inverse distance) • Parallel lines not parallel; converge to single point A Plane of Projection A’ B B’ Center of projection (camera/eye location) Slides inspired by Greg Humphreys

  50. Overhead View of Our Screen (x,y,z) (x’,y’,z’) (0,0,0) d Looks like we’ve got some nice similar triangles here?

More Related