Download presentation

Presentation is loading. Please wait.

Published byBranden Liggins Modified over 2 years ago

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
What next? 2D transformations: scale, shear, rotation Composing transformations 3D rotations

4
(Nonuniform) Scale

5
Shear

6
Rotations 2D rotations are simple Can we derive it? 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 complex transformation by composing simple ones (for which we have matrix patterns) E.g. first scale then rotate We see now advantage of matrix formulation: Transformation is performed for many points Complex transformation is in advanced put into a single matrix In general not commutative!! Order matters

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

11
Composing example

12
Inverting Composite Transforms Say, we want 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
Orthogonal matrix

15

16
Rotations in 3D Rotations about coordinate axes is a simple extension of 2D rotations Again orthogonal matrices

17
Interpretation 3D Rotations Matrix Rows of matrix are the vectors of new coordinate system (the rotated one) Old coordinate frame: x, y, z versors After transformation: we have new uvw coordinate frame

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

21
?

22
Homogeneous Coordinates We need to add a fourth coordinate (w=1). Its quite common way in linear algebra, to get rid off free terms. 4x4 matrices in 3D space - very common in computer graphics w may look like a dummy variable – but may play its role

23
Representation of Points (4-Vectors) Homogeneous coordinates Divide by 4 th coord (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
What are the Advantages of Homogeneous Coords? Unified framework for translation and other transformations Only 4x4 matrix – easy to concatenate Less problems with perspective viewing No special cases – homogenous formulas

25
General Translation Matrix

26
3 basic Rotation Matrices

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, then TranslationFirst Translation, then Rotation

29
Geometry Transformation Podstawy OpenGL Transformations are composed of four elements Viewing transformation – positioning the camera Modeling transformation - moving objects (Viewing and Modeling are complementary) Projection – on the plane Viewport – mapping on the window

30
Camera analogy Podstawy OpenGL

31
Camera analogy contd. Podstawy OpenGL

32
Two ways of making transformation in OpenGL First approach: we operate directly on matrices Second approach: we hide matrix transformations inside functions Which one is better?

33
Two ways of making transformation in OpenGL Functions typical to old OpenGL. Cancelled in OpenGL 3.0 Transformations and Projections moved to shader programming. Not everyone likes low-level shader programming. Search for new functions…

34
GLM – OpenGL Mathematics Can be easily found on glm.g-truc.net/, along with other information glm.g-truc.net/ Can be treated as enhancement of GLSL. Is included into unofficial OpenGL 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 Projection tutorial Old OpenGL Style Demo

38
What we ve seen so far Transforms (translation, rotation, scale) as 4x4 homogeneous matrices Last row always 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. Orthographic Perspective

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) x z y l r t b n f x z Translate y x z y Scale

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

45
Transformation Matrix ScaleTranslation

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

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 B A B Center of projection (camera/eye location) A Plane of Projection Slides inspired by Greg Humphreys

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

51
In Matrices Note negation of z coord (focal plane –d) (Only) last row affected (no longer ) w coord will no longer = 1. Must divide at end

52
Verify

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

54
Remember projection tutorial

55
Viewing Frustum Near plane Far plane

56
Screen (Projection Plane) Field of view (fovy) width height Aspect ratio = width / height

57

58
gluPerspective gluPerspective(fovy, aspect, zNear > 0, zFar > 0) Fovy, aspect control fov in x, y directions zNear, zFar control viewing frustum

59
In Matrices Simplest form: Aspect ratio taken into account Homogeneous, simpler to multiply through by d Must map z vals based on near, far planes (not yet)

Similar presentations

© 2017 SlidePlayer.com Inc.

All rights reserved.

Ads by Google