Lecture slides (CT4201/EC4215 – Computer Graphics) … · 2021. 8. 23. · Viewport...
Transcript of Lecture slides (CT4201/EC4215 – Computer Graphics) … · 2021. 8. 23. · Viewport...
![Page 1: Lecture slides (CT4201/EC4215 – Computer Graphics) … · 2021. 8. 23. · Viewport Transformation • Primitives (or line segments) within the canonical view volume will be mapped](https://reader036.fdocuments.net/reader036/viewer/2022071609/61485267cee6357ef925473e/html5/thumbnails/1.jpg)
Lecturer: Bochang Moon
ProjectionsLecture slides (CT4201/EC4215 – Computer Graphics)
1
![Page 2: Lecture slides (CT4201/EC4215 – Computer Graphics) … · 2021. 8. 23. · Viewport Transformation • Primitives (or line segments) within the canonical view volume will be mapped](https://reader036.fdocuments.net/reader036/viewer/2022071609/61485267cee6357ef925473e/html5/thumbnails/2.jpg)
Graphics PipelineModeling
Transformation
Illumination
Viewing Transformation
Clipping
Projection
Rasterization
Display
![Page 3: Lecture slides (CT4201/EC4215 – Computer Graphics) … · 2021. 8. 23. · Viewport Transformation • Primitives (or line segments) within the canonical view volume will be mapped](https://reader036.fdocuments.net/reader036/viewer/2022071609/61485267cee6357ef925473e/html5/thumbnails/3.jpg)
Sequence of Spaces and TransformationsObject space
Modeling transformation
World space
Viewingtransformation
Eye (camera) space
![Page 4: Lecture slides (CT4201/EC4215 – Computer Graphics) … · 2021. 8. 23. · Viewport Transformation • Primitives (or line segments) within the canonical view volume will be mapped](https://reader036.fdocuments.net/reader036/viewer/2022071609/61485267cee6357ef925473e/html5/thumbnails/4.jpg)
Sequence of Spaces and TransformationsObject space
Modeling transformation
World space
Viewingtransformation
Eye (camera) space
ProjectionTransformation
Canonical view volume (normalized device coordinates)
ViewportTransformation
Screen space
![Page 5: Lecture slides (CT4201/EC4215 – Computer Graphics) … · 2021. 8. 23. · Viewport Transformation • Primitives (or line segments) within the canonical view volume will be mapped](https://reader036.fdocuments.net/reader036/viewer/2022071609/61485267cee6357ef925473e/html5/thumbnails/5.jpg)
Canonical View Volume
(-1,-1,-1)
(1,1,1)
x
yz
![Page 6: Lecture slides (CT4201/EC4215 – Computer Graphics) … · 2021. 8. 23. · Viewport Transformation • Primitives (or line segments) within the canonical view volume will be mapped](https://reader036.fdocuments.net/reader036/viewer/2022071609/61485267cee6357ef925473e/html5/thumbnails/6.jpg)
Viewport Transformation• Primitives (or line segments) within the canonical view volume will be mapped to the
image
(-1,-1,-1)
(1,1,1)
x
yz
Image (or window on the screen)
𝑛𝑛𝑥𝑥 pixels
𝑛𝑛𝑦𝑦 pixels
![Page 7: Lecture slides (CT4201/EC4215 – Computer Graphics) … · 2021. 8. 23. · Viewport Transformation • Primitives (or line segments) within the canonical view volume will be mapped](https://reader036.fdocuments.net/reader036/viewer/2022071609/61485267cee6357ef925473e/html5/thumbnails/7.jpg)
Viewport Transformation• Ignore the z-coordinates of points for now
o In practice, we need the z-coordinates and this will be covered later.
• Map the square −1,1 2to the rectangle −0.5,𝑛𝑛𝑥𝑥 − 0.5 × [−0.5,𝑛𝑛𝑦𝑦 − 0.5]
(-1,-1,-1)
(1,1,1)
x
yz
Image (or window on the screen)
𝑛𝑛𝑥𝑥 pixels
𝑛𝑛𝑦𝑦 pixels
![Page 8: Lecture slides (CT4201/EC4215 – Computer Graphics) … · 2021. 8. 23. · Viewport Transformation • Primitives (or line segments) within the canonical view volume will be mapped](https://reader036.fdocuments.net/reader036/viewer/2022071609/61485267cee6357ef925473e/html5/thumbnails/8.jpg)
Raster Image (again)• Ignore the z-coordinates of points for now
o In practice, we need the z-coordinates and this will be covered later.
• Map the square −1,1 2to the rectangle −0.5,𝑛𝑛𝑥𝑥 − 0.5 × [−0.5,𝑛𝑛𝑦𝑦 − 0.5]
• Where do we need to locate pixels in 2D space?
4x4 imagey
x(0,0)
x=-0.5 x=3.5y=-0.5
y=3.5
![Page 9: Lecture slides (CT4201/EC4215 – Computer Graphics) … · 2021. 8. 23. · Viewport Transformation • Primitives (or line segments) within the canonical view volume will be mapped](https://reader036.fdocuments.net/reader036/viewer/2022071609/61485267cee6357ef925473e/html5/thumbnails/9.jpg)
Raster Image (again)• Ignore the z-coordinates of points for now
o In practice, we need the z-coordinates and this will be covered later.
• Map the square −1,1 2to the rectangle −0.5,𝑛𝑛𝑥𝑥 − 0.5 × [−0.5,𝑛𝑛𝑦𝑦 − 0.5]
• Where do we need to locate pixels in 2D space?
• The rectangular domain of a 𝑛𝑛𝑥𝑥 × 𝑛𝑛𝑦𝑦 imageo 𝑅𝑅 = −0.5,𝑛𝑛𝑥𝑥 − 0.5 × [−0.5,𝑛𝑛𝑦𝑦 − 0.5]
![Page 10: Lecture slides (CT4201/EC4215 – Computer Graphics) … · 2021. 8. 23. · Viewport Transformation • Primitives (or line segments) within the canonical view volume will be mapped](https://reader036.fdocuments.net/reader036/viewer/2022071609/61485267cee6357ef925473e/html5/thumbnails/10.jpg)
Viewport Transformation• Ignore the z-coordinates of points for now
o In practice, we need the z-coordinates and this will be covered later.
• Map the square −1,1 2to the rectangle −0.5,𝑛𝑛𝑥𝑥 − 0.5 × [−0.5,𝑛𝑛𝑦𝑦 − 0.5]
• Q. How do we transform a rectangle to another rectangle?
![Page 11: Lecture slides (CT4201/EC4215 – Computer Graphics) … · 2021. 8. 23. · Viewport Transformation • Primitives (or line segments) within the canonical view volume will be mapped](https://reader036.fdocuments.net/reader036/viewer/2022071609/61485267cee6357ef925473e/html5/thumbnails/11.jpg)
Example: Windowing Transform• Problem specification: move a 2D rectangle into a new position
y
x
(𝑥𝑥𝑙𝑙 ,𝑦𝑦𝑙𝑙)
(𝑥𝑥ℎ,𝑦𝑦ℎ) y
x
(𝑥𝑥𝑙𝑙′,𝑦𝑦𝑙𝑙′)
(𝑥𝑥ℎ′ ,𝑦𝑦ℎ′ )
![Page 12: Lecture slides (CT4201/EC4215 – Computer Graphics) … · 2021. 8. 23. · Viewport Transformation • Primitives (or line segments) within the canonical view volume will be mapped](https://reader036.fdocuments.net/reader036/viewer/2022071609/61485267cee6357ef925473e/html5/thumbnails/12.jpg)
Example: Windowing Transform• Problem specification: move a 2D rectangle into a new position
o Step1. translate: move the point 𝑥𝑥𝑙𝑙 ,𝑦𝑦𝑙𝑙 to the origin
y
x
(𝑥𝑥𝑙𝑙 ,𝑦𝑦𝑙𝑙)
(𝑥𝑥ℎ,𝑦𝑦ℎ) y
x
(𝑥𝑥ℎ − 𝑥𝑥𝑙𝑙 ,𝑦𝑦ℎ − 𝑦𝑦𝑙𝑙)
![Page 13: Lecture slides (CT4201/EC4215 – Computer Graphics) … · 2021. 8. 23. · Viewport Transformation • Primitives (or line segments) within the canonical view volume will be mapped](https://reader036.fdocuments.net/reader036/viewer/2022071609/61485267cee6357ef925473e/html5/thumbnails/13.jpg)
Example: Windowing Transform• Problem specification: move a 2D rectangle into a new position
o Step2. scale: resize the rectangle to be the same size of the target.
y
x
y
x
(𝑥𝑥ℎ − 𝑥𝑥𝑙𝑙 ,𝑦𝑦ℎ − 𝑦𝑦𝑙𝑙)(𝑥𝑥ℎ′ − 𝑥𝑥𝑙𝑙′,𝑦𝑦ℎ′ − 𝑦𝑦𝑙𝑙′)
![Page 14: Lecture slides (CT4201/EC4215 – Computer Graphics) … · 2021. 8. 23. · Viewport Transformation • Primitives (or line segments) within the canonical view volume will be mapped](https://reader036.fdocuments.net/reader036/viewer/2022071609/61485267cee6357ef925473e/html5/thumbnails/14.jpg)
Example: Windowing Transform• Problem specification: move a 2D rectangle into a new position
o Step3. translate: move the origin to point (𝑥𝑥𝑙𝑙′,𝑦𝑦𝑙𝑙′)
y
x
y
x
(𝑥𝑥ℎ′ − 𝑥𝑥𝑙𝑙′,𝑦𝑦ℎ′ − 𝑦𝑦𝑙𝑙′)
(𝑥𝑥𝑙𝑙′,𝑦𝑦𝑙𝑙′)
(𝑥𝑥ℎ′ ,𝑦𝑦ℎ′ )
![Page 15: Lecture slides (CT4201/EC4215 – Computer Graphics) … · 2021. 8. 23. · Viewport Transformation • Primitives (or line segments) within the canonical view volume will be mapped](https://reader036.fdocuments.net/reader036/viewer/2022071609/61485267cee6357ef925473e/html5/thumbnails/15.jpg)
Example: Windowing Transform• Problem specification: move a 2D rectangle into a new position
o Target = translate(𝑥𝑥𝑙𝑙′,𝑦𝑦𝑙𝑙′) 𝑠𝑠𝑠𝑠𝑠𝑠𝑠𝑠𝑠𝑠𝑥𝑥ℎ′ −𝑥𝑥𝑙𝑙
′
𝑥𝑥ℎ−𝑥𝑥𝑙𝑙, 𝑦𝑦ℎ
′−𝑦𝑦𝑙𝑙′
𝑦𝑦ℎ−𝑦𝑦𝑙𝑙𝑡𝑡𝑡𝑡𝑠𝑠𝑛𝑛𝑠𝑠𝑠𝑠𝑠𝑠𝑡𝑡𝑠𝑠(−𝑥𝑥𝑙𝑙 ,−𝑦𝑦𝑙𝑙)
o =1 0 𝑥𝑥𝑙𝑙′
0 1 𝑦𝑦𝑙𝑙′0 0 1
𝑥𝑥ℎ′ −𝑥𝑥𝑙𝑙
′
𝑥𝑥ℎ−𝑥𝑥𝑙𝑙0 0
0 𝑦𝑦ℎ′−𝑦𝑦𝑙𝑙
′
𝑦𝑦ℎ−𝑦𝑦𝑙𝑙0
0 0 1
1 0 −𝑥𝑥𝑙𝑙0 1 −𝑦𝑦𝑙𝑙0 0 1
o =
𝑥𝑥ℎ′ −𝑥𝑥𝑙𝑙
′
𝑥𝑥ℎ−𝑥𝑥𝑙𝑙0 𝑥𝑥𝑙𝑙
′𝑥𝑥ℎ−𝑥𝑥ℎ′ 𝑥𝑥𝑙𝑙
𝑥𝑥ℎ−𝑥𝑥𝑙𝑙
0 𝑦𝑦ℎ′−𝑦𝑦𝑙𝑙
′
𝑦𝑦ℎ−𝑦𝑦𝑙𝑙
𝑦𝑦𝑙𝑙′𝑦𝑦ℎ−𝑦𝑦ℎ
′𝑦𝑦𝑙𝑙𝑦𝑦ℎ−𝑦𝑦𝑙𝑙
0 0 1
![Page 16: Lecture slides (CT4201/EC4215 – Computer Graphics) … · 2021. 8. 23. · Viewport Transformation • Primitives (or line segments) within the canonical view volume will be mapped](https://reader036.fdocuments.net/reader036/viewer/2022071609/61485267cee6357ef925473e/html5/thumbnails/16.jpg)
Viewport Transformation• Ignore the z-coordinates of points for now
o In practice, we need the z-coordinates and this will be covered later.
• Map the square −1,1 2to the rectangle −0.5,𝑛𝑛𝑥𝑥 − 0.5 × [−0.5,𝑛𝑛𝑦𝑦 − 0.5]
•𝑥𝑥𝑠𝑠𝑐𝑐𝑐𝑐𝑐𝑐𝑐𝑐𝑐𝑐𝑦𝑦𝑠𝑠𝑐𝑐𝑐𝑐𝑐𝑐𝑐𝑐𝑐𝑐
1=
𝑐𝑐𝑥𝑥2
0 𝑐𝑐𝑥𝑥−12
0 𝑐𝑐𝑦𝑦2
𝑐𝑐𝑦𝑦−12
0 0 1
𝑥𝑥𝑐𝑐𝑎𝑎𝑐𝑐𝑎𝑎𝑐𝑐𝑎𝑎𝑐𝑐𝑎𝑎𝑙𝑙𝑦𝑦𝑐𝑐𝑎𝑎𝑐𝑐𝑎𝑎𝑐𝑐𝑎𝑎𝑐𝑐𝑎𝑎𝑙𝑙
1
• For the case with z-coordinates,
o 𝑀𝑀𝑣𝑣𝑎𝑎𝑐𝑐𝑣𝑣𝑣𝑣𝑎𝑎𝑐𝑐𝑣𝑣 =
𝑐𝑐𝑥𝑥2
0
0 𝑐𝑐𝑦𝑦2
0 𝑐𝑐𝑥𝑥−12
0 𝑐𝑐𝑦𝑦−12
0 00 0
1 00 1
![Page 17: Lecture slides (CT4201/EC4215 – Computer Graphics) … · 2021. 8. 23. · Viewport Transformation • Primitives (or line segments) within the canonical view volume will be mapped](https://reader036.fdocuments.net/reader036/viewer/2022071609/61485267cee6357ef925473e/html5/thumbnails/17.jpg)
Sequence of Spaces and TransformationsObject space
Modeling transformation
World space
Viewingtransformation
Eye (camera) space
ProjectionTransformation
Canonical view volume (normalized device coordinates)
ViewportTransformation
Screen space
![Page 18: Lecture slides (CT4201/EC4215 – Computer Graphics) … · 2021. 8. 23. · Viewport Transformation • Primitives (or line segments) within the canonical view volume will be mapped](https://reader036.fdocuments.net/reader036/viewer/2022071609/61485267cee6357ef925473e/html5/thumbnails/18.jpg)
Projections• Transform 3D points in eye space to 2D points in image space
• Two types of projectionso Orthographic projectiono Perspective projection
Modeling Transformation
Illumination
Viewing Transformation
Clipping
Projection
Rasterization
Display
x
y
z
![Page 19: Lecture slides (CT4201/EC4215 – Computer Graphics) … · 2021. 8. 23. · Viewport Transformation • Primitives (or line segments) within the canonical view volume will be mapped](https://reader036.fdocuments.net/reader036/viewer/2022071609/61485267cee6357ef925473e/html5/thumbnails/19.jpg)
Orthographic Projection• Assumption
o A viewer is looking along the minus z-axis with his head pointing in the y-direction Implies n > f
x
y
z(l,b,n)
(r,t,f)
![Page 20: Lecture slides (CT4201/EC4215 – Computer Graphics) … · 2021. 8. 23. · Viewport Transformation • Primitives (or line segments) within the canonical view volume will be mapped](https://reader036.fdocuments.net/reader036/viewer/2022071609/61485267cee6357ef925473e/html5/thumbnails/20.jpg)
Orthographic Projection• The view volume (orthographic view volume) is an axis-aligned box
o [l, r] x [b, t] x [f, n]
• Notationso 𝑥𝑥 = 𝑠𝑠 ≡ 𝑠𝑠𝑠𝑠𝑙𝑙𝑡𝑡 𝑝𝑝𝑠𝑠𝑠𝑠𝑛𝑛𝑠𝑠, 𝑥𝑥 = 𝑡𝑡 ≡ 𝑡𝑡𝑟𝑟𝑟𝑟𝑟𝑡𝑡 𝑝𝑝𝑠𝑠𝑠𝑠𝑛𝑛𝑠𝑠
o 𝑦𝑦 = 𝑏𝑏 ≡ 𝑏𝑏𝑏𝑏𝑡𝑡𝑡𝑡𝑏𝑏𝑏𝑏 𝑝𝑝𝑠𝑠𝑠𝑠𝑛𝑛𝑠𝑠,𝑦𝑦 = 𝑡𝑡 ≡ 𝑡𝑡𝑏𝑏𝑝𝑝 𝑝𝑝𝑠𝑠𝑠𝑠𝑛𝑛𝑠𝑠
o 𝑧𝑧 = 𝑛𝑛 ≡ 𝑛𝑛𝑠𝑠𝑠𝑠𝑡𝑡 𝑝𝑝𝑠𝑠𝑠𝑠𝑛𝑛𝑠𝑠, 𝑧𝑧 = 𝑙𝑙 ≡ 𝑙𝑙𝑠𝑠𝑡𝑡 𝑝𝑝𝑠𝑠𝑠𝑠𝑛𝑛𝑠𝑠
x
y
z(l,b,n)
(r,t,f)
![Page 21: Lecture slides (CT4201/EC4215 – Computer Graphics) … · 2021. 8. 23. · Viewport Transformation • Primitives (or line segments) within the canonical view volume will be mapped](https://reader036.fdocuments.net/reader036/viewer/2022071609/61485267cee6357ef925473e/html5/thumbnails/21.jpg)
Orthographic Projection• Transform points in orthographic view volume to the canonical view volume
o Also windowing transform (3D)
(l,b,n)
(r,t,f)
(-1,-1,-1)
(1,1,1)
Projectiontransformation
![Page 22: Lecture slides (CT4201/EC4215 – Computer Graphics) … · 2021. 8. 23. · Viewport Transformation • Primitives (or line segments) within the canonical view volume will be mapped](https://reader036.fdocuments.net/reader036/viewer/2022071609/61485267cee6357ef925473e/html5/thumbnails/22.jpg)
Orthographic Projection• Transform points in orthographic view volume to the canonical view volume
o Also windowing transform (3D) Map a box 𝑥𝑥𝑙𝑙 , 𝑥𝑥ℎ × 𝑦𝑦𝑙𝑙 ,𝑦𝑦ℎ × 𝑧𝑧𝑙𝑙 , 𝑧𝑧ℎ to another box 𝑥𝑥𝑙𝑙′, 𝑥𝑥ℎ′ × 𝑦𝑦𝑙𝑙′,𝑦𝑦ℎ′ × [𝑧𝑧𝑙𝑙′, 𝑧𝑧ℎ′ ]
𝑥𝑥ℎ′ −𝑥𝑥𝑙𝑙
′
𝑥𝑥ℎ−𝑥𝑥𝑙𝑙0
0 𝑦𝑦ℎ′−𝑦𝑦𝑙𝑙
′
𝑦𝑦ℎ−𝑦𝑦𝑙𝑙
0 𝑥𝑥𝑙𝑙′𝑥𝑥ℎ−𝑥𝑥ℎ
′ 𝑥𝑥𝑙𝑙𝑥𝑥ℎ−𝑥𝑥𝑙𝑙
0 𝑦𝑦𝑙𝑙′𝑦𝑦ℎ−𝑦𝑦ℎ
′𝑦𝑦𝑙𝑙𝑦𝑦ℎ−𝑦𝑦𝑙𝑙
0 00 0
𝑧𝑧ℎ′−𝑧𝑧𝑙𝑙′𝑧𝑧ℎ−𝑧𝑧𝑙𝑙
𝑧𝑧𝑙𝑙′𝑧𝑧ℎ−𝑧𝑧ℎ
′ 𝑧𝑧𝑙𝑙𝑧𝑧ℎ−𝑧𝑧𝑙𝑙
0 1
![Page 23: Lecture slides (CT4201/EC4215 – Computer Graphics) … · 2021. 8. 23. · Viewport Transformation • Primitives (or line segments) within the canonical view volume will be mapped](https://reader036.fdocuments.net/reader036/viewer/2022071609/61485267cee6357ef925473e/html5/thumbnails/23.jpg)
Orthographic Projection• Transform points in orthographic view volume to the canonical view volume
o Also windowing transform (3D)
• 𝑀𝑀𝑎𝑎𝑐𝑐𝑣𝑣ℎ𝑎𝑎 =
2𝑐𝑐−𝑙𝑙
0
0 2𝑣𝑣−𝑏𝑏
0 −𝑐𝑐+𝑙𝑙𝑐𝑐−𝑙𝑙
0 − 𝑣𝑣+𝑏𝑏𝑣𝑣−𝑏𝑏
0 00 0
2𝑐𝑐−𝑓𝑓
− 𝑐𝑐+𝑓𝑓𝑐𝑐−𝑓𝑓
0 1
![Page 24: Lecture slides (CT4201/EC4215 – Computer Graphics) … · 2021. 8. 23. · Viewport Transformation • Primitives (or line segments) within the canonical view volume will be mapped](https://reader036.fdocuments.net/reader036/viewer/2022071609/61485267cee6357ef925473e/html5/thumbnails/24.jpg)
Composite Transformation• The matrix that transforms points in world space to screen coordinate:
• 𝑀𝑀 = 𝑀𝑀𝑣𝑣𝑎𝑎𝑐𝑐𝑣𝑣𝑣𝑣𝑎𝑎𝑐𝑐𝑣𝑣𝑀𝑀𝑎𝑎𝑐𝑐𝑣𝑣ℎ𝑎𝑎𝑀𝑀𝑣𝑣𝑎𝑎𝑐𝑐𝑣𝑣𝑎𝑎𝑐𝑐𝑣𝑣
![Page 25: Lecture slides (CT4201/EC4215 – Computer Graphics) … · 2021. 8. 23. · Viewport Transformation • Primitives (or line segments) within the canonical view volume will be mapped](https://reader036.fdocuments.net/reader036/viewer/2022071609/61485267cee6357ef925473e/html5/thumbnails/25.jpg)
Orthographic Projection• Transform points in orthographic view volume to the canonical view volume
o Also windowing transform (3D)
• Tend to ignore relative distances between objects and eyeo Unrealistic
• In practice, o We usually do not use this projection.o It can be useful in applications where relative lengths should be judged.
![Page 26: Lecture slides (CT4201/EC4215 – Computer Graphics) … · 2021. 8. 23. · Viewport Transformation • Primitives (or line segments) within the canonical view volume will be mapped](https://reader036.fdocuments.net/reader036/viewer/2022071609/61485267cee6357ef925473e/html5/thumbnails/26.jpg)
Orthographic Projection in OpenGL• void glOrtho(GLdouble left, GLdouble right,
• GLdouble bottom, GLdouble top,
• GLdouble nearVal, GLdouble farVal);
(l,b,n)
(r,t,f)
![Page 27: Lecture slides (CT4201/EC4215 – Computer Graphics) … · 2021. 8. 23. · Viewport Transformation • Primitives (or line segments) within the canonical view volume will be mapped](https://reader036.fdocuments.net/reader036/viewer/2022071609/61485267cee6357ef925473e/html5/thumbnails/27.jpg)
Perspective Projection• Objects in an image become smaller as their distance from the eye increases.
• History of perspective:o Artists from the Renaissance period employed the perspective property.
Images from wikipedia
![Page 28: Lecture slides (CT4201/EC4215 – Computer Graphics) … · 2021. 8. 23. · Viewport Transformation • Primitives (or line segments) within the canonical view volume will be mapped](https://reader036.fdocuments.net/reader036/viewer/2022071609/61485267cee6357ef925473e/html5/thumbnails/28.jpg)
Perspective Projection• Objects in an image become smaller as their distance from the eye increases.
• History of perspective:o Artists from the Renaissance period employed the perspective property.
• In everyday life?
![Page 29: Lecture slides (CT4201/EC4215 – Computer Graphics) … · 2021. 8. 23. · Viewport Transformation • Primitives (or line segments) within the canonical view volume will be mapped](https://reader036.fdocuments.net/reader036/viewer/2022071609/61485267cee6357ef925473e/html5/thumbnails/29.jpg)
Perspective Projection• 𝑦𝑦𝑠𝑠 = 𝑑𝑑
𝑧𝑧𝑦𝑦
o 𝑦𝑦𝑠𝑠: y-axis coordinate in view planeo y: distance of the point along the y-axis
d
view
pla
ne
e g
z
𝑦𝑦
𝑦𝑦𝑠𝑠
![Page 30: Lecture slides (CT4201/EC4215 – Computer Graphics) … · 2021. 8. 23. · Viewport Transformation • Primitives (or line segments) within the canonical view volume will be mapped](https://reader036.fdocuments.net/reader036/viewer/2022071609/61485267cee6357ef925473e/html5/thumbnails/30.jpg)
Homogeneous Coordinate• Represent a point 𝑥𝑥,𝑦𝑦, 𝑧𝑧 with an extra coordinate w
o 𝑥𝑥,𝑦𝑦, 𝑧𝑧,𝑤𝑤o In the previous lecture, 𝑤𝑤 = 1
• Let’s define 𝑤𝑤 to be the denominator of the x-, y-, z-coordinateso (𝑥𝑥, 𝑦𝑦, 𝑧𝑧,𝑤𝑤) represent the 3D point (𝑥𝑥
𝑣𝑣, 𝑦𝑦𝑣𝑣
, 𝑧𝑧𝑣𝑣
)
o A special case, 𝑤𝑤 = 1, is still valid.
o 𝑤𝑤 can be any values
![Page 31: Lecture slides (CT4201/EC4215 – Computer Graphics) … · 2021. 8. 23. · Viewport Transformation • Primitives (or line segments) within the canonical view volume will be mapped](https://reader036.fdocuments.net/reader036/viewer/2022071609/61485267cee6357ef925473e/html5/thumbnails/31.jpg)
Projective Transform• Let’s define 𝑤𝑤 to be the denominator of the x-, y-, z-coordinates
o (𝑥𝑥,𝑦𝑦, 𝑧𝑧,𝑤𝑤) represent the 3D point (𝑥𝑥𝑣𝑣
, 𝑦𝑦𝑣𝑣
, 𝑧𝑧𝑣𝑣
)
o A special case, 𝑤𝑤 = 1, is still valid.o 𝑤𝑤 can be any values
• Projective transformation
o
�𝑥𝑥�𝑦𝑦�̃�𝑧�𝑤𝑤
=
𝑠𝑠1 𝑏𝑏1𝑠𝑠2 𝑏𝑏2
𝑠𝑠1 𝑑𝑑1𝑠𝑠2 𝑑𝑑2
𝑠𝑠3 𝑏𝑏3𝑠𝑠 𝑙𝑙
𝑠𝑠3 𝑑𝑑3𝑟𝑟 𝑟
𝑥𝑥𝑦𝑦𝑧𝑧1
o 𝑥𝑥′,𝑦𝑦′, 𝑧𝑧′ = ( �𝑥𝑥�𝑣𝑣
, �𝑦𝑦�𝑣𝑣
, �𝑧𝑧�𝑣𝑣
)
![Page 32: Lecture slides (CT4201/EC4215 – Computer Graphics) … · 2021. 8. 23. · Viewport Transformation • Primitives (or line segments) within the canonical view volume will be mapped](https://reader036.fdocuments.net/reader036/viewer/2022071609/61485267cee6357ef925473e/html5/thumbnails/32.jpg)
Perspective Projection• Example with 2D homogeneous vector 𝑦𝑦 𝑧𝑧 1 𝑇𝑇
o𝑦𝑦𝑠𝑠1 = 𝑑𝑑 0 0
0 1 0
𝑦𝑦𝑧𝑧1
o This is corresponding to the perspective equation, 𝑦𝑦𝑠𝑠 = 𝑑𝑑𝑧𝑧𝑦𝑦.
![Page 33: Lecture slides (CT4201/EC4215 – Computer Graphics) … · 2021. 8. 23. · Viewport Transformation • Primitives (or line segments) within the canonical view volume will be mapped](https://reader036.fdocuments.net/reader036/viewer/2022071609/61485267cee6357ef925473e/html5/thumbnails/33.jpg)
Perspective Projection• Some info. for perspective matrix
o Define our project plane as the near planeo Distance to the near plane: −𝑛𝑛o Distance to the far plane: −𝑙𝑙
• Perspective equation: 𝑦𝑦𝑠𝑠 = 𝑐𝑐𝑧𝑧𝑦𝑦
• Perspective matrix
o 𝑃𝑃 =𝑛𝑛 00 𝑛𝑛
0 00 0
0 00 0
𝑛𝑛 + 𝑙𝑙 −𝑙𝑙𝑛𝑛1 0
![Page 34: Lecture slides (CT4201/EC4215 – Computer Graphics) … · 2021. 8. 23. · Viewport Transformation • Primitives (or line segments) within the canonical view volume will be mapped](https://reader036.fdocuments.net/reader036/viewer/2022071609/61485267cee6357ef925473e/html5/thumbnails/34.jpg)
Perspective Projection• Perspective matrix
o 𝑃𝑃 =𝑛𝑛 00 𝑛𝑛
0 00 0
0 00 0
𝑛𝑛 + 𝑙𝑙 −𝑙𝑙𝑛𝑛1 0
• A mapping with the perspective matrix:
o 𝑃𝑃
𝑥𝑥𝑦𝑦𝑧𝑧1
=
𝑛𝑛𝑥𝑥𝑛𝑛𝑦𝑦
𝑛𝑛 + 𝑙𝑙 𝑧𝑧 − 𝑙𝑙𝑛𝑛𝑧𝑧
=
𝑐𝑐𝑥𝑥𝑧𝑧𝑐𝑐𝑦𝑦𝑧𝑧
𝑛𝑛 + 𝑙𝑙 − 𝑓𝑓𝑐𝑐𝑧𝑧
1
![Page 35: Lecture slides (CT4201/EC4215 – Computer Graphics) … · 2021. 8. 23. · Viewport Transformation • Primitives (or line segments) within the canonical view volume will be mapped](https://reader036.fdocuments.net/reader036/viewer/2022071609/61485267cee6357ef925473e/html5/thumbnails/35.jpg)
Perspective Projection• A mapping with the perspective matrix:
o 𝑃𝑃
𝑥𝑥𝑦𝑦𝑧𝑧1
=
𝑛𝑛𝑥𝑥𝑛𝑛𝑦𝑦
𝑛𝑛 + 𝑙𝑙 𝑧𝑧 − 𝑙𝑙𝑛𝑛𝑧𝑧
=
𝑐𝑐𝑥𝑥𝑧𝑧𝑐𝑐𝑦𝑦𝑧𝑧
𝑛𝑛 + 𝑙𝑙 − 𝑓𝑓𝑐𝑐𝑧𝑧
1
• Propertieso The first, second, and fourth rows are for the perspective equation.o The third row is for keeping z coordinate at least approximately.
E.g., when z = n, transformed z coordinate is still n. E.g., when 𝑧𝑧 > 𝑛𝑛, we cannot preserve the z coordinate exactly, but relative orders between points
will be preserved.
![Page 36: Lecture slides (CT4201/EC4215 – Computer Graphics) … · 2021. 8. 23. · Viewport Transformation • Primitives (or line segments) within the canonical view volume will be mapped](https://reader036.fdocuments.net/reader036/viewer/2022071609/61485267cee6357ef925473e/html5/thumbnails/36.jpg)
Perspective Projection• Perspective matrix
o Map the perspective view volume to the orthographic view volume.
![Page 37: Lecture slides (CT4201/EC4215 – Computer Graphics) … · 2021. 8. 23. · Viewport Transformation • Primitives (or line segments) within the canonical view volume will be mapped](https://reader036.fdocuments.net/reader036/viewer/2022071609/61485267cee6357ef925473e/html5/thumbnails/37.jpg)
Composite Transformation• The matrix that transforms points in world space to screen coordinate:
• 𝑀𝑀 = 𝑀𝑀𝑣𝑣𝑎𝑎𝑐𝑐𝑣𝑣𝑣𝑣𝑎𝑎𝑐𝑐𝑣𝑣𝑀𝑀𝑎𝑎𝑐𝑐𝑣𝑣ℎ𝑎𝑎𝑃𝑃𝑀𝑀𝑣𝑣𝑎𝑎𝑐𝑐𝑣𝑣𝑎𝑎𝑐𝑐𝑣𝑣 = 𝑀𝑀𝑣𝑣𝑎𝑎𝑐𝑐𝑣𝑣𝑣𝑣𝑎𝑎𝑐𝑐𝑣𝑣𝑀𝑀𝑣𝑣𝑐𝑐𝑐𝑐𝑀𝑀𝑣𝑣𝑎𝑎𝑐𝑐𝑣𝑣𝑎𝑎𝑐𝑐𝑣𝑣
• 𝑀𝑀𝑣𝑣𝑐𝑐𝑐𝑐 = 𝑀𝑀𝑎𝑎𝑐𝑐𝑣𝑣ℎ𝑎𝑎𝑃𝑃 (perspective projection matrix)
𝑀𝑀𝑣𝑣𝑐𝑐𝑐𝑐 =
2𝑐𝑐𝑐𝑐−𝑙𝑙
0
0 2𝑐𝑐𝑣𝑣−𝑏𝑏
𝑙𝑙+𝑐𝑐𝑙𝑙−𝑐𝑐
0𝑏𝑏+𝑣𝑣𝑏𝑏−𝑣𝑣
0
0 00 0
𝑓𝑓+𝑐𝑐𝑐𝑐−𝑓𝑓
2𝑓𝑓𝑐𝑐𝑓𝑓−𝑐𝑐
1 0
![Page 38: Lecture slides (CT4201/EC4215 – Computer Graphics) … · 2021. 8. 23. · Viewport Transformation • Primitives (or line segments) within the canonical view volume will be mapped](https://reader036.fdocuments.net/reader036/viewer/2022071609/61485267cee6357ef925473e/html5/thumbnails/38.jpg)
Perspective Projection in OpenGL• void glFrustum(GLdouble left, GLdouble right,
• GLdouble bottom, GLdouble top,
• GLdouble nearVal, GLdouble farVal);
![Page 39: Lecture slides (CT4201/EC4215 – Computer Graphics) … · 2021. 8. 23. · Viewport Transformation • Primitives (or line segments) within the canonical view volume will be mapped](https://reader036.fdocuments.net/reader036/viewer/2022071609/61485267cee6357ef925473e/html5/thumbnails/39.jpg)
Perspective Projection in OpenGL• void gluPerspective(GLdouble fovy, GLdouble aspect,
• GLdouble zNear, GLdouble zFar);
• Parameters o fovy: field of view (in degrees) in the y direction
o aspect: aspect ratio is the ratio of x (width) to y (height)
• Symmetric constraints are implicitly applied.o l = -r, b = -t
• A constraint to prevent image distortion
o 𝑐𝑐𝑥𝑥𝑐𝑐𝑦𝑦
= 𝑐𝑐𝑣𝑣 x
y
z
𝜃𝜃2
![Page 40: Lecture slides (CT4201/EC4215 – Computer Graphics) … · 2021. 8. 23. · Viewport Transformation • Primitives (or line segments) within the canonical view volume will be mapped](https://reader036.fdocuments.net/reader036/viewer/2022071609/61485267cee6357ef925473e/html5/thumbnails/40.jpg)
Further Reading• In our textbook, Fundamentals of Computer Graphics (4th edition)
o Chapter 7