• No results found

Viewing Transformations

N/A
N/A
Protected

Academic year: 2021

Share "Viewing Transformations"

Copied!
29
0
0

Loading.... (view fulltext now)

Full text

(1)

Viewing Transformations

CS425: Computer Graphics I

Fabio Miranda

https://fmiranda.me

(2)

• Coordinate systems

• Camera

• Viewing transformations

• Orthographic and perspective projections

• Hidden surface removal

Overview

(3)

• Viewing transformation is the mapping of coordinates of points and lines from world coordinates into screen space pixels.

Viewing transformations

Modeling Camera Projection Viewport

World coordinates

Screen

Space

(pixels)

(4)

• Previously, we saw how transformations can manipulate primitives (points, vectors) in space.

• Today, we will see how transformations can manipulate primitives to 2D screen coordinates (that will be later rasterized).

Viewing transformations

(5)

Perspective projection

Distant objects appear smaller

Parallel lines converge at the

horizon

(6)

Early paintings

(7)

Perspective in art

Giotto di Bondone (14

th

century) Giotto di Bondone (14

th

century)

(8)

Birth of perspective in art:

One-point perspective

Giovanni di Paolo (15

th

century) Piero della Francesca (15

th

century)

(9)

Birth of perspective in art: One-point perspective

Perugino (15

th

century)

(10)

Birth of perspective in art: One-point perspective

The Ideal City (15

th

century)

(11)

Birth of perspective in art: One-point perspective

Rafael (16

th

century)

(12)

Birth of perspective in art:

Two-point perspective

Jean Pélérin (16

th

century) Gustave Caillebotte (19

th

century)

(13)

Birth of perspective in art:

Three-point perspective

(14)

Multi perspective

The Frozen City by Matthias A. K.

Zimmermann (2006)

(15)

Perspective in computer graphics

(16)

Rejection of perspective in CG

SimCity 2000

“Automated Generation of Interactive 3D

(17)

Coordinate spaces

From: Mark Pauly

Object coordinates World coordinates Camera coordinates Screen coordinates

(18)

Viewing transformation

Model

Camera Projection

Viewport

Object space Camera space

Canonical view volume

Screen space

(19)

• Construct the camera reference system:

• The eye position 𝐞𝐞.

• The forward direction 𝐝𝐝.

• The view-up vector 𝐮𝐮.

• A view matrix transform all coordinates into view coordinates.

Camera transformation

𝐞𝐞 𝐮𝐮 𝐠𝐠

𝐮𝐮 × 𝐠𝐠

𝐌𝐌 𝑐𝑐𝑐𝑐𝑐𝑐𝑐𝑐𝑐𝑐𝑐𝑐𝑐𝑐𝑐𝑐𝑐𝑐𝑐𝑐𝑐𝑐𝑐 = 𝐮𝐮 × 𝐠𝐠 𝐮𝐮 𝐝𝐝 𝐞𝐞 0 0 0 1

𝐌𝐌 𝑐𝑐𝑐𝑐𝑐𝑐𝑐𝑐𝑐𝑐𝑐𝑐𝑐𝑐𝑐𝑐𝑐𝑐𝑐𝑐𝑐𝑐𝑐 = 𝐮𝐮 × 𝐠𝐠 𝐮𝐮 𝐝𝐝 𝐞𝐞 0 0 0 1

−1

(20)

Orthographic and perspective projections

https://en.wikipedia.org/wiki/File:Various_projections_of_cube_above_plane.svg

(21)

View frustum

Camera space

(𝑥𝑥

𝑐𝑐𝑐𝑐𝑙𝑙𝑙𝑙

, 𝑦𝑦

𝑏𝑏𝑐𝑐𝑙𝑙𝑙𝑙𝑐𝑐𝑏𝑏

, 𝑧𝑧

𝑏𝑏𝑐𝑐𝑐𝑐𝑐𝑐

) × (𝑥𝑥

𝑐𝑐𝑟𝑟𝑟𝑟𝑟𝑙𝑙

, 𝑦𝑦

𝑙𝑙𝑐𝑐𝑡𝑡

, 𝑧𝑧

𝑙𝑙𝑐𝑐𝑐𝑐

)

Far plane

Near plane

(22)

View frustum

(23)

Orthographic transformation

Camera space

Projection

𝑥𝑥 𝑦𝑦 1 𝑧𝑧

=

2

(𝑟𝑟𝑟𝑟𝑟𝑟𝑟𝑟𝑟 − 𝑙𝑙𝑙𝑙𝑙𝑙𝑟𝑟) 0 0 −𝑥𝑥

𝑐𝑐𝑟𝑟𝑐𝑐

0 2

(𝑟𝑟𝑡𝑡𝑡𝑡 − 𝑏𝑏𝑡𝑡𝑟𝑟𝑟𝑟𝑡𝑡𝑏𝑏) 0 −𝑦𝑦

𝑐𝑐𝑟𝑟𝑐𝑐

0 0 −2

𝑥𝑥 𝑦𝑦 1 𝑧𝑧

Canonical view volume

(−1, −1, −1) × (1,1,1)

(24)

Basic orthographic projection

𝐱𝐱 = 𝐱𝐱, 𝐲𝐲′ = 𝐲𝐲

y’ y

z

𝑥𝑥

𝑦𝑦′ z′

1

=

1 0 0 0 0 1 0 0 0 0 0 0 0 0 0 1

𝑥𝑥 𝑦𝑦 1 𝑧𝑧

Projection plane

(z = 0)

(25)

Basic perspective projection

-f y’

y

z

𝑥𝑥 = 𝑙𝑙 𝑥𝑥

𝑧𝑧 , 𝑦𝑦′ = 𝑙𝑙

𝑦𝑦 𝑧𝑧

f

y’ y

z

𝑟𝑟𝑙𝑙 𝑙𝑙 = 1:

𝑥𝑥 = 𝑥𝑥

𝑧𝑧 , 𝑦𝑦 = 𝑦𝑦

𝑧𝑧 , 𝑙𝑙 = 1

𝑥𝑥

𝑦𝑦

𝑧𝑧′ 1

→ 𝑥𝑥 𝑦𝑦 𝑧𝑧 𝑧𝑧

=

1 0 0 0 0 1 0 0 0 0 0 0 0 0 1 0

𝑥𝑥 𝑦𝑦

1 𝑧𝑧

(26)

Perspective transformation

Camera space

Projection

𝑥𝑥 𝑦𝑦 1 𝑧𝑧

=

𝑙𝑙

(𝑓𝑓𝑎𝑎𝑡𝑡𝑙𝑙𝑎𝑎𝑟𝑟) 0 0 0

0 𝑙𝑙 0 0

0 0 𝑛𝑛𝑙𝑙𝑓𝑓𝑟𝑟 + 𝑙𝑙𝑓𝑓𝑟𝑟 (𝑛𝑛𝑙𝑙𝑓𝑓𝑟𝑟 − 𝑙𝑙𝑓𝑓𝑟𝑟)

2 ∗ 𝑙𝑙𝑓𝑓𝑟𝑟 ∗ 𝑛𝑛𝑙𝑙𝑓𝑓𝑟𝑟 (𝑛𝑛𝑙𝑙𝑓𝑓𝑟𝑟 − 𝑙𝑙𝑓𝑓𝑟𝑟)

𝑥𝑥 𝑦𝑦 𝑧𝑧 1

Canonical view volume (−1, −1, −1) × (1,1,1)

𝑙𝑙 = 1 tan(𝑙𝑙𝑡𝑡𝑓𝑓 2 )

, 𝑓𝑓𝑎𝑎𝑡𝑡𝑙𝑙𝑎𝑎𝑟𝑟 = 𝑤𝑤𝑟𝑟𝑤𝑤𝑟𝑟𝑟

𝑟𝑙𝑙𝑟𝑟𝑟𝑟𝑟𝑟𝑟

(27)

• Why?

• Makes clipping much easier! GL can quickly discard geometry outside -1,1.

Canonical view volume

From: https://paroj.github.io/gltut/

(28)

Viewport transformation

Canonical view volume (−1, −1, −1) × (1,1,1)

Viewport

Screen space

𝑥𝑥 𝑠𝑠𝑐𝑐𝑐𝑐𝑐𝑐𝑐𝑐𝑏𝑏

𝑦𝑦 𝑠𝑠𝑐𝑐𝑐𝑐𝑐𝑐𝑐𝑐𝑏𝑏

𝑧𝑧 𝑐𝑐𝑐𝑐𝑡𝑡𝑙𝑙𝑟 1

=

𝑐𝑐𝑟𝑟𝑐𝑐𝑙𝑙𝑟

𝑐 0 0 𝑐𝑐𝑟𝑟𝑐𝑐𝑙𝑙𝑟 𝑐

0 𝑟𝑐𝑐𝑟𝑟𝑟𝑟𝑟𝑙𝑙 𝑐 0 𝑟𝑐𝑐𝑟𝑟𝑟𝑟𝑟𝑙𝑙 𝑐

0 0 1 0

𝑥𝑥 𝑦𝑦

1 𝑧𝑧

(29)

• Draw a cube on screen with size (−1, −1, −1) × (1,1,1).

• Apply a model transformation that scales it by 0.5, and tilts it slightly.

• Apply a projection matrix (orthographic and perspective).

Lab

References

Related documents

Analyses of fish and seafood markets have evolved continually over the past thirty years. This study is an excellent example of seafood market analysis, where several levels of

[r]

Simultaneously hold down the “Ctrl” key and “V” key one time to paste the email header into the word processor, text editor, or email application/program. Or, select “Edit”

작은어머니 작은어머니 wife of father's younger brother 1138.. 잘생기다 잘생기다 to be handsome, to be good

2013—The State of Play of Judicial Selection in Tennessee On April 19, 2013, the 108th Tennessee General Assembly adjourned without passing any legislation regarding the

effect on filtration time, total eDNA recovered, probability of species detection, repeatability, and the relationship between read counts and known fish abundance or biomass in

That report is an integral part of an audit performed in accordance with Government Auditing Standards in considering the Delaware County Solid Waste Disposal

Models were adjusted for age, sex, ethnicity, educational attainment, block group annual income and occupation class, years since diabetes diagnosis, diabetes therapy refill