Matrix Composition Be aware: order of transformations matters Matrix multiplication is not commutative transformation order P’ = T * S * R * p “Global” “Local” 43
Matrix Composition Be aware: order of transformations matters Matrix multiplication is not commutative 44
Problem: local rotation angle φ 45
Matrix Composition Rotate around an arbitrary point (a,b) Translate (a,b) to the origin Rotate around origin Translate back 46
Matrix Composition Rotate around an arbitrary point (a,b) Translate (a,b) to the origin Rotate around origin Translate back M = T(a, b) * R( 𝜄 ) * T(-a, -b) 47
Matrix Composition translate rotation center to origin: t(t x ,t y ) 1. rotate by φ 2. inverse translate by t´(-t x ,-t y ) 3. Matrix notation: 1 0 0 cos sin 0 1 0 0 = − ( ' , ' , 1 ) ( , , 1 ) 0 1 0 sin cos 0 0 1 0 x y x y − − 1 0 0 1 1 t t t t x y x y 48
Matrix Composition Scale by sx, sy around arbitrary point (a, b) Use the same approach … 49
Matrix Composition Scale by sx, sy around arbitrary point (a, b) Use the same approach … M = T(a, b) * S( 𝑡 𝑦 , 𝑡 𝑧 ) * T(-a, -b) 50
Overview 2D Transformations Basic 2D transformations Matrix representation Matrix composition 3D Transformations Basic 3D transformations Same as 2D 51
3D Transformations Right-handed coordinate system Left-handed coordinate system rotation direction 52
3D Transformations Same idea as 2D transformations Homogenous coordinates (x,y,z,w) 4x4 transformation matrices 𝑦 ′ 𝑏 𝑐 𝑑 𝑒 𝑦 𝑧 ′ 𝑓 𝑔 ℎ 𝑧 = 𝑨 𝑨 ′ 𝑗 𝑘 𝑙 𝑚 𝑥 𝑛 𝑜 𝑝 𝑞 𝑥′ 53
Basic 3D Transformations 𝑦 ′ 𝑡 𝑦 0 0 0 𝑦 ′ 𝑦 𝑦 1 0 0 0 𝑧 ′ 𝑧 ′ 𝑧 0 𝑡 𝑧 0 0 𝑧 0 1 0 0 = = 𝑨 ′ 𝑨 𝑨 𝑨 ′ 0 0 1 0 0 0 𝑡 𝑨 0 𝑥 𝑥 0 0 0 1 𝑥′ 0 0 0 1 𝑥′ Identity Scale 𝑦 ′ 𝑦 ′ 𝑦 1 0 0 𝑢 𝑦 𝑦 1 0 0 0 𝑧 ′ 𝑧 ′ 𝑧 𝑧 0 1 0 𝑢 𝑧 0 −1 0 0 = = 𝑨 𝑨 𝑨 ′ 𝑨 ′ 0 0 −1 0 0 0 1 𝑢 𝑨 𝑥 𝑥 0 0 0 1 𝑥′ 𝑥′ 0 0 0 1 Translation Mirror over X 54
Basic 3D Transformations Rotation around Z axis 𝑦 ′ 𝑦 cos 𝜄 −sin 𝜄 0 0 𝑧 ′ 𝑧 sin 𝜄 cos 𝜄 0 0 = 𝑨 𝑨 ′ 0 0 1 0 𝑥 0 0 0 1 𝑥′ Rotation around Y axis 𝑦 ′ 𝑦 cos 𝜄 0 sin 𝜄 0 𝑧 ′ 𝑧 0 1 0 0 = 𝑨 𝑨 ′ −sin 𝜄 0 cos 𝜄 0 𝑥 0 0 0 1 𝑥′ Rotation around X axis 𝑦 ′ 𝑦 1 0 0 0 𝑧 ′ 𝑧 0 cos 𝜄 −sin 𝜄 0 = 𝑨 𝑨 ′ 0 sin 𝜄 cos 𝜄 0 𝑥 0 0 0 1 𝑥′ 55
Same as 2D Everything else is the same as 2D In fact 2D is actually 3D in OpenGL z is either 0 or ignored 56
How the lectures should look like #3 Ask questions, please!!! - Be communicative - www.slido.com #PPGSO02 - More active you are, the better for you! - 57
Projections 58
Projection General definition: Maps points in n-space to m-space (m<n) In Computer Graphics: Map 3D camera coordinates to 2D screen coordinates 59
Viewing transformation Convert from local/world coordinates to camera/viewport coordinates rotate scene so that camera lies in z-axis 1. projection transformation 2. viewport transformation 3. 60
Stage 0 61
Stage 1 - translate P→P’ 62
Stage 2 - rotate P’→P’’→P’’’ 63
Stage 2 - rotate P’→P’’→P’’’ 64
Orthogonal projection 65
Orthogonal projection 𝑦 𝑄 = x’’’ 𝑧 𝑄 = y’’’ z’’’ is simply left out Matrix notation 1 0 0 0 0 1 0 0 = ( , , , 1 ) ( ' ' ' , ' ' ' , ' ' ' , 1 ) x y z x y z P P p 0 0 0 0 0 0 0 1 66
Perspective projection 67
Taxonomy of Projections 68
Taxonomy of Projections 69
Parallel Projection Center of projection is at infinity Direction of projection (DOP) same for all points 70
Orthographic Projections DOP perpendicular to view plane 71
Oblique Projections DOP not perpendicular to view plane 72
Parallel Projection View Volume 73
Parallel Projection Matrix General parallel projection transformation 74
Taxonomy of Projections 75
Perspective Projection Maps points onto a view plane along projectors emitting from center of projection (COP) 76
Perspective Projection N-point perspective How many vanishing points? 3-point 2-point 1-point perspective perspective perspective 77
Perspective Projection Compute 2D coordinates from 3D coordinates using triangle similarity principle 78
Perspective Projection Compute 2D coordinates from 3D coordinates using triangle similarity principle 79
Perspective Projection 4x4 matrix representation 𝑦 𝑇 = 𝑦 𝐷 𝐸/𝑨 𝐷 𝑧 𝑇 = 𝑧 𝐷 𝐸/𝑨 𝐷 𝑨 𝑇 = 𝐸 𝑥 𝑇 = 1 𝑦 𝑡 𝑦 𝑑 𝑏 𝑐 𝑑 𝑒 𝑧 𝑡 𝑧 𝑑 𝑓 𝑔 ℎ = 𝑨 𝑡 𝑨 𝑑 𝑗 𝑘 𝑙 𝑚 𝑥 𝑡 𝑛 𝑜 𝑝 𝑞 1 80
Perspective Projection 4x4 matrix representation 𝑦 𝑇 = 𝑦 𝐷 𝐸/𝑨 𝐷 𝑦 𝑇 = 𝑦 𝐷 𝑧 𝑇 = 𝑧 𝐷 𝐸/𝑨 𝐷 𝑧 𝑇 = 𝑧 𝐷 depth is stored 𝑨 𝑇 = 𝑨 𝐷 𝑨 𝑇 = 𝐸 𝑥 𝑇 = 1 𝑥 𝑇 = 𝑨 𝐷 /𝐸 𝑦 𝑡 𝑦 𝑑 𝑏 𝑐 𝑑 𝑒 𝑧 𝑡 𝑧 𝑑 𝑓 𝑔 ℎ = 𝑨 𝑡 𝑨 𝑑 𝑗 𝑘 𝑙 𝑚 𝑥 𝑡 𝑛 𝑜 𝑝 𝑞 1 81
Perspective Projection 4x4 matrix representation 𝑦 𝑇 = 𝑦 𝐷 𝐸/𝑨 𝐷 𝑦 𝑇 = 𝑦 𝐷 𝑧 𝑇 = 𝑧 𝐷 𝐸/𝑨 𝐷 𝑧 𝑇 = 𝑧 𝐷 𝑨 𝑇 = 𝐸 𝑨 𝑇 = 𝑨 𝐷 𝑥 𝑇 = 1 𝑥 𝑇 = 𝑨 𝐷 /𝐸 𝑦 𝑡 𝑦 𝑑 1 0 0 0 𝑧 𝑡 𝑓 𝑔 ℎ 𝑧 𝑑 = 𝑨 𝑡 𝑨 𝑑 𝑗 𝑘 𝑙 𝑚 𝑥 𝑡 𝑛 𝑜 𝑝 𝑞 1 82
Perspective Projection 4x4 matrix representation 𝑦 𝑇 = 𝑦 𝐷 𝐸/𝑨 𝐷 𝑦 𝑇 = 𝑦 𝐷 𝑧 𝑇 = 𝑧 𝐷 𝐸/𝑨 𝐷 𝑧 𝑇 = 𝑧 𝐷 𝑨 𝑇 = 𝐸 𝑨 𝑇 = 𝑨 𝐷 𝑥 𝑇 = 1 𝑥 𝑇 = 𝑨 𝐷 /𝐸 𝑦 𝑡 𝑦 𝑑 1 0 0 0 𝑧 𝑡 𝑧 𝑑 0 1 0 0 = 𝑨 𝑡 𝑨 𝑑 𝑗 𝑘 𝑙 𝑚 𝑥 𝑡 𝑛 𝑜 𝑝 𝑞 1 83
Perspective Projection 4x4 matrix representation 𝑦 𝑇 = 𝑦 𝐷 𝐸/𝑨 𝐷 𝑦 𝑇 = 𝑦 𝐷 𝑧 𝑇 = 𝑧 𝐷 𝐸/𝑨 𝐷 𝑧 𝑇 = 𝑧 𝐷 𝑨 𝑇 = 𝐸 𝑨 𝑇 = 𝑨 𝐷 𝑥 𝑇 = 1 𝑥 𝑇 = 𝑨 𝐷 /𝐸 𝑦 𝑡 𝑦 𝑑 1 0 0 0 𝑧 𝑡 𝑧 𝑑 0 1 0 0 = 𝑨 𝑡 𝑨 𝑑 0 0 1 0 𝑥 𝑡 𝑛 𝑜 𝑝 𝑞 1 84
Perspective Projection 4x4 matrix representation 𝑦 𝑇 = 𝑦 𝐷 𝐸/𝑨 𝐷 𝑦 𝑇 = 𝑦 𝐷 𝑧 𝑇 = 𝑧 𝐷 𝐸/𝑨 𝐷 𝑧 𝑇 = 𝑧 𝐷 𝑨 𝑇 = 𝐸 𝑨 𝑇 = 𝑨 𝐷 𝑥 𝑇 = 1 𝑥 𝑇 = 𝑨 𝐷 /𝐸 𝑦 𝑡 𝑦 𝑑 1 0 0 0 𝑧 𝑡 𝑧 𝑑 0 1 0 0 = 𝑨 𝑡 𝑨 𝑑 0 0 1 0 𝑥 𝑡 0 0 1/𝐸 0 1 85
Perspective vs. Parallel Perspective Projection + Size varies inversely with distance - looks realistic - Distance and angles are not (in general) preserved - Parallel lines do not (in general) remain parallel Parallel Projection + Good for exact measurements + Parallel lines remain parallel - Angles are not (in general) preserved - Less realistic looking 86
Classical Projections 87
Viewport transformation 88
Viewport transformation s x , s y – scale factors − − xv xv yv yv = = max min max min s x s y − − xc xc yc yc max min max min Matrix notation 0 0 s x = ( , , 1 ) ( , , 1 ) 0 0 x y x y s v v p p y − + − + 1 s xc xv s yc yv x min min y min min 89
Welcome to the matrix! local → global coordinates 1. translate, rotate, scale, translate global → camera 2. translate, rotate, rotate, project camera → viewport 3. translate, scale, translate Transformation combine = matrix multiply 90
3D rendering pipeline 3D polygons Modeling 1 Transformation Lighting Model transformation local → global / world coordinates Viewing Viewport transformation Transformation global → camera Projection transformation Projection global → normalized device Transformation Clipping Rasterization Clipping Texturing & Lighting Scan Conversion 2D Image 91
How the lectures should look like #2 Ask questions, please!!! - Be communicative - www.slido.com #PPGSO02 - More active you are, the better for you! - 92
Fast Forward to Practical Assignment Bezier Curve 93
Drawing Curves Parametric curves Both x and y are functions of additional parameter 94
Drawing Curves How to display? 95
Drawing Curves Draw many direct line segments Careful at the ends How long should each segment be? 96
Drawing Curves Draw many direct line segments Careful at the ends What about variable segment length? 97
Drawing Curves Midpoint-test subdivision 98
Drawing Curves Midpoint-test subdivision 99
Drawing Curves Midpoint-test subdivision 100
Recommend
More recommend