Welcome 1 Note for todays lecture Will be closely following book - - PowerPoint PPT Presentation

welcome
SMART_READER_LITE
LIVE PREVIEW

Welcome 1 Note for todays lecture Will be closely following book - - PowerPoint PPT Presentation

Graphics (INFOGR), 2018-19, Block IV, lecture 12 Deb Panja Today: Matrix reloaded 2 (or Viewing Transformations) Welcome 1 Note for todays lecture Will be closely following book chapter 7 (read it thoroughly to grab the concepts)


slide-1
SLIDE 1

Graphics (INFOGR), 2018-19, Block IV, lecture 12 Deb Panja

Today: Matrix reloaded 2 (or Viewing Transformations)

Welcome

1

slide-2
SLIDE 2

Note for today’s lecture

  • Will be closely following book chapter 7

(read it thoroughly to grab the concepts)

  • Most of the lecture will be in symbols

2

slide-3
SLIDE 3

Today

  • Redo part of last lecture
  • Rotation co-ordinate transformation revisited
  • Viewing transformation (getting world space → screen space)

− viewport transfomation − orthographic tranformation − camera transformation − projection transformation − “graphics pipeline”: putting everything together

  • Summary maths lectures

3

slide-4
SLIDE 4

Redo part of last lecture

4

slide-5
SLIDE 5

From last lecture

  • Point, or active transformations

− translation − projection − reflection − scaling − shearing − rotation − linear transformation properties − combining transformations (and transformation back!)

  • Co-ordinate, or passive transformations

       redo

5

slide-6
SLIDE 6

Translation: a matrix operation

  • We translate a point P (x, y, z) by (ax, ay, az)

i.e., x′ = x + ax, y′ = y + ay, z′ = z + az     x′ y′ z′ 1    

  • wt

=     1 ax 1 ay 1 az 1    

  • Mt(

a)

    x y z 1    

  • v

; a =   ax ay az  

6

slide-7
SLIDE 7

How to think about an extended vector for 2D

  • Note: A “real” vector

v, by construction, satisfies v · ˆ f = 0 e.g., the (2+1)D representation of a real vector in 2D is   vx vy  

7

slide-8
SLIDE 8

Projecting and reflecting vectors

8

slide-9
SLIDE 9

Projecting and reflecting vectors

  • riginal vector

projected vector reflected vector These rules always hold!

9

slide-10
SLIDE 10

Projecting a vector: a matrix operation in (3+1)D

  • wp =

v−( v· ˆ n) ˆ n; for d = 3, wp =    

  • wp · ˆ

x

  • wp · ˆ

y

  • wp · ˆ

z

  • wp · ˆ

f     =    

  • v · ˆ

x − ( v · ˆ n)(ˆ n · ˆ x)

  • v · ˆ

y − ( v · ˆ n)(ˆ n · ˆ y)

  • v · ˆ

z − ( v · ˆ n)(ˆ n · ˆ z)

  • v · ˆ

f    

  • wp = Mp

v; Mp =     1 − n2

x

−nxny −nxnz −nxny 1 − n2

y

−nynz −nxnz −nynz 1 − n2

z

1    

10

slide-11
SLIDE 11

Reflecting a vector: a matrix operation in (3+1)D

  • wr =

v − 2( v · ˆ n)ˆ n; for d = 3, wr =    

  • v · ˆ

x − 2( v · ˆ n)(ˆ n · ˆ x)

  • v · ˆ

y − 2( v · ˆ n)(ˆ n · ˆ y)

  • v · ˆ

z − 2( v · ˆ n)(ˆ n · ˆ z)

  • v · ˆ

f    

  • wr = Mr

v; Mr =     1 − 2n2

x

−2nxny −2nxnz −2nxny 1 − 2n2

y

−2nynz −2nxnz −2nynz 1 − 2n2

z

1    

11

slide-12
SLIDE 12

Projecting and reflecting points

12

slide-13
SLIDE 13

Projecting and reflecting points (on an object)

  • Can we use vector projection/reflection formulae for points as well?

yes, provided care is taken

13

slide-14
SLIDE 14

Projecting and reflecting points (on an object)

  • Can we use vector projection/reflection formulae for points as well?

yes, provided care is taken

  • Why?

because specifying a vector (arrow) does not specify its starting point; although point P (x, y, z) is reached by vector   x y z   from the origin, the origin may “move” upon projection/reflection

14

slide-15
SLIDE 15

Projecting points (on an object)

  • Specifying a vector (arrow) does not specify its starting point;

although point P (x, y, z) is reached by vector   x y z   from the origin, the origin may “move” upon projection/reflection ← − − − →

contrast 15

slide-16
SLIDE 16

Projecting and reflecting points (on an object)

  • Specifying a vector (arrow) does not specify its starting point;

although point P (x, y, z) is reached by vector   x y z   from the origin, the origin may “move” upon projection/reflection ← − − − →

contrast

  • The case for reflection is similar (not shown further)

16

slide-17
SLIDE 17

Rotation co-ordinate transformation revisited

17

slide-18
SLIDE 18

Active rotation in (2+1)D revisited

  • Active:

  x′ y′ 1   =   cos θ − sin θ sin θ cos θ 1     x y 1  

  • Now consider the passive (co-ordinate) rotation

18

slide-19
SLIDE 19

Active rotation in (2+1)D revisited

  • Active:

  x′ y′ 1   =   cos θ − sin θ sin θ cos θ 1     x y 1  

  • Now consider the passive (co-ordinate) rotation

Q.   x′ y′ 1   = Mro   x y 1  ; Mro =?

19

slide-20
SLIDE 20

Active rotation in (2+1)D revisited

  • Active:

  x′ y′ 1   =   cos θ − sin θ sin θ cos θ 1     x y 1  

  • Now consider the passive (co-ordinate) rotation

Q.   x′ y′ 1   = Mro   x y 1  ; Mro =? A.   x′ y′ 1   =   cos θ sin θ − sin θ cos θ 1     x y 1  

20

slide-21
SLIDE 21

Passive rotation in (2+1)D

 x′ y′ 1   =   cos θ sin θ − sin θ cos θ 1     x y 1   cos θ = ˆ x · ˆ x′ = ˆ y · ˆ y′, sin θ = ˆ y · ˆ x′ = −ˆ x · ˆ y′ then   x′ y′ 1   =   ˆ x′ · ˆ x ˆ x′ · ˆ y ˆ y′ · ˆ x ˆ y′ · ˆ y 1     x y 1   =   xx′ yx′ xy′ yy′ 1     x y 1  

21

slide-22
SLIDE 22

Passive rotation in (3+1)D

   u v w 1    =     ˆ u · ˆ x ˆ u · ˆ y ˆ u · ˆ z ˆ v · ˆ x ˆ v · ˆ y ˆ v · ˆ z ˆ w · ˆ x ˆ w · ˆ y ˆ w · ˆ z 1         x y z 1    =     xu yu zu xv yv zv xw yw zw 1         x y z 1    

22

slide-23
SLIDE 23

Viewing transformation

23

slide-24
SLIDE 24

What is viewing transformation?

24

slide-25
SLIDE 25

What is viewing transformation?

  • Will achieve these (passive!) transformations by concatenating matrices

25

slide-26
SLIDE 26

What is viewing transformation?

  • Will achieve these (passive!) transformations by concatenating matrices

(and we need to do that in the reverse order of transformations)

26

slide-27
SLIDE 27

Viewport transformation

27

slide-28
SLIDE 28

Viewport transformation

− − − − → Mvp

28

slide-29
SLIDE 29

Viewport transformation

− − − − → Mvp

  • Canonical view space: (x, y, z) ∈ [−1, 1]3
  • Screen space: nx × ny pixels
  • Mvp: transform [−1, 1]2 → [−0.5, nx − 0.5] × [−0.5, ny − 0.5]

(only for x and y, don’t care about z)

29

slide-30
SLIDE 30

Viewport transformation: Mvp

  • Mvp: transform [−1, 1]2 → [−0.5, nx − 0.5] × [−0.5, ny − 0.5]

(only for x and y, don’t care about z)

  • Concatenate translation after scaling (diagonal matrix):

↓ ↓     1

nx−1 2

1

ny−1 2

1 1        

nx 2 ny 2

1 1    

30

slide-31
SLIDE 31

Viewport transformation: Mvp

  • Mvp: transform [−1, 1]2 → [−0.5, nx − 0.5] × [−0.5, ny − 0.5]

(only for x and y, don’t care about z)

  • Concatenate translation after scaling (diagonal matrix):

↓ ↓     1

nx−1 2

1

ny−1 2

1 1        

nx 2 ny 2

1 1    

31

slide-32
SLIDE 32

Viewport transformation: Mvp

  • Mvp: transform [−1, 1]2 → [−0.5, nx − 0.5] × [−0.5, ny − 0.5]

(only for x and y, don’t care about z)

  • Concatenate translation after scaling (diagonal matrix):

↓ ↓     1

nx−1 2

1

ny−1 2

1 1        

nx 2 ny 2

1 1    

  • After concatenation, we obtain Mvp =

   

nx 2 nx−1 2 ny 2 ny−1 2

1 1    

32

slide-33
SLIDE 33

Orthographic projection transformation

33

slide-34
SLIDE 34

Orthographic transformation

− − − − → Mortho

(canonical view volume)

  • Mortho: transform [l, r] × [b, t] × [n, f] → [−1, 1]3

34

slide-35
SLIDE 35

Orthographic transformation: Mortho

  • Mortho: transform [l, r] × [b, t] × [n, f] → [−1, 1]3
  • Concatenate scaling (diagonal matrix) after translation:

↓ ↓     

2 r−l 2 t−b 2 n−f

1          1 −r+l

2

1 −t+b

2

1 −n+f

2

1    

  • After concatenation we obtain Mortho =

    

2 r−l

−r+l

r−l 2 t−b

−t+b

t−b 2 n−f

−n+f

n−f

1     

35

slide-36
SLIDE 36

Camera transformation

36

slide-37
SLIDE 37

The camera...

  • Camera specifications

− position e − gaze direction ˆ g; ˆ w = −ˆ g − view up vector ˆ t: any vector that symmetrically bisects the viewer’s head into left and right, and points “to the sky” − finally, ˆ u = (ˆ t × ˆ w)/||ˆ t × ˆ w||, and ˆ v = ˆ w × ˆ u (ˆ u, ˆ v, ˆ w) forms a right-handed co-ordinate system

37

slide-38
SLIDE 38

World co-ordinates to camera co-ordinates

  • Mcam: transform (x, y, z) → (u, v, w)

38

slide-39
SLIDE 39

World co-ordinates to camera co-ordinates

  • Mcam: transform (x, y, z) → (u, v, w)
  • Concatenate rotation of axes after translation:

↓ ↓     xu yu zu xv yv zv xw yw zw 1         1 −xe 1 −ye 1 −ze 1    

  • After concatenation we obtain Mcam

39

slide-40
SLIDE 40

Finally we can put things together

  • The “graphics pipeline”:

world space → camera space → canonical view space → screen space ↓ ↓ ↓ Mcam Mortho Mvp

  • M = Mvp Mortho Mcam

40

slide-41
SLIDE 41

Finally we can put things together

  • The “graphics pipeline”:

world space → camera space → canonical view space → screen space ↓ ↓ ↓ Mcam Mortho Mvp

  • M = Mvp Mortho Mcam; no, we are not done yet!

41

slide-42
SLIDE 42

Because we have missed the perspective effect

42

slide-43
SLIDE 43

A simpler perspective case

  • ys = yd

z (this is the principle we need to implement in 3D)

43

slide-44
SLIDE 44

Camera field of view

44

slide-45
SLIDE 45

Camera field of view

45

slide-46
SLIDE 46

Projection transformation

46

slide-47
SLIDE 47

Projection transformation

  • After projection, we want:

− projection P     x y z 1     =    

nx z ny z

? 1    

47

slide-48
SLIDE 48

Projection transformation

  • After projection, we want:

− projection P     x y z 1     =    

nx z ny z

? 1     − constraints: z = {n, f} − →

P {n, f}

48

slide-49
SLIDE 49

Projection transformation

  • After projection, we want:

− projection P     x y z 1     =    

nx z ny z

? 1     − constraints: z = {n, f} − →

P {n, f}

  • No unique choice for P

49

slide-50
SLIDE 50

Fixing P for projection

  • We want P

    x y z 1     =    

nx z ny z

? 1    , with z = {n, f} − →

P {n, f}

  • Cannot be achieved by a simple matrix multiplication by P

50

slide-51
SLIDE 51

Fixing P for projection: follow the book

  • We want P

    x y z 1     =    

nx z ny z

? 1    , with z = {n, f} − →

P {n, f}

  • Cannot be achieved by a simple matrix multiplication by P
  • Choose P =

    n n n + f −fn 1    ; P     x y z 1     =     nx ny (n + f)z − fn z     ∼    

nx z ny z

n + f − fn

z

1    

51

slide-52
SLIDE 52

Finally, the graphics pipeline

  • World space → camera space → canonical view space → screen space

↓ ↓ ↓ Mcam Mortho Mvp

  • M = Mvp Mortho P Mcam

52

slide-53
SLIDE 53

Summary for today’s lecture

  • Redo part of last lecture
  • Rotation co-ordinate transformation revisited
  • Viewing transformation (getting world space → screen space)

− viewport transfomation − orthographic tranformation − camera transformation − projection transformation − “graphics pipeline”: putting everything together

53

slide-54
SLIDE 54

References for today

  • Book chapter 6.5: Co-ordinate transformations
  • Book chapter 7: Viewing tranformations

54

slide-55
SLIDE 55

Summary maths lectures

55

slide-56
SLIDE 56

Summary maths lecture 1

  • Vectors and Vector operations

− addition and subtraction (requires same dimensionality) − scalar multiplication − magnitude/length/norm of a vector; unit, null and basis vectors − Pythagoras theorem − elementary trigonometry: definitions of sin, cos, tan

56

slide-57
SLIDE 57

Summary maths lecture 2

  • Dot product of vectors
  • Shooting rays for a line

− equations: parametric, slope-intercept and implicit forms − parallel and perspective projections of a line − projection of a point on a line, tangent and normal vectors

57

slide-58
SLIDE 58

Summary maths lecture 3

  • Circles, ellipses and shooting rays at them
  • Shooting rays as a line in 3D

− equations: parametric and implicit-like forms

  • Equation of a plane using the normal vector
  • Cross product, left- and right-handed co-ordinate systems

− implicit and parametric equations of a plane − tangent and bitangent vectors

58

slide-59
SLIDE 59

Summary maths lecture 4

  • projections of a line on a plane
  • Spheres and spherical co-ordinate system

− surface normal and tangent planes − shooting rays towards a sphere and their intersections

59

slide-60
SLIDE 60

Summary maths lecture 5

  • Why matrices? The operations defined for them make them special

− matrix dimensions, special matrices (diagonal, identity, null)

  • Matrix operations (addition, scalar multiplication, subtraction,

matrix multiplication, transpose)

  • Determinants (only for square matrices!)
  • Adjoint/adjugate and inverse of matrices (only for square matrices!)
  • Geometric interpretation of determinants
  • Introduction to transformations

− translation and the fictitious coordinate

60

slide-61
SLIDE 61

Summary maths lecture 6

  • Point, or active transformations

− translation − projection − reflection − scaling − shearing − rotation − linear transformation properties − combining transformations (and transformation back!)

  • Co-ordinate, or passive transformations

61

slide-62
SLIDE 62

Finally...

  • Good luck with the rest of the second half of the course!
  • And please do not forget to leave feedback on caracal

62