background image

Grafika Komputerowa

Projekcja

Alexander Denisjuk

denisjuk@pjwstk.edu.pl

Polsko-Japo ´nska Wy˙zsza Szkoła Technik Komputerowych

zamiejscowy o´srodek dydaktyczny w Gda ´nsku

ul. Brzegi 55

80-045 Gda ´nsk

Grafika Komputerowa – p. 1

background image

Projekcja

Najnowsza wersja tego dokumentu dost ˛epna jest pod
adresem

http://users.pjwstk.edu.pl/~denisjuk/

Grafika Komputerowa – p. 2

background image

Drugi etap renderowania

Mo

deling

View

Sele tion

P

ersp

e tiv

e

Division

Displa

ying

Figure

I

I.1:

The

four

stages

of

the

rendering

pip

eline

in

Op

enGL.

Grafika Komputerowa – p. 3

background image

Dwa typy projekcji

Prostopadła

Perspektywiczna

Figure

I

I.18:

The

ub

e

on

the

left

is

rendered

with

an

orthographi

pro

je tion.

The

one

on

the

righ

t

with

a

p

ersp

e tiv

e

transformation.

With

the

orthographi

pro

je tion,

the

rendered

size

of

a

fa e

of

the

ub

e

is

indep

enden

t

of

its

distan e

from

the

view

er;

ompare,

for

example,

the

fron

t

and

ba

k

fa es.

Under

a

p

ersp

e tiv

e

transformation,

the

loser

a

fa e

is,

the

larger

it

is

rendered.

Grafika Komputerowa – p. 4

background image

Projekcja prostopadła

l ≤ x ≤ r,

left, right

b ≤ y ≤ t,

bottom, top

n ≤ z ≤ f,

near, far




2

r−l

0

0

r+l
r−l

0

2

t−b

0

t+b
t−b

0

0

2

f −n

f +n
f −n

0

0

0

1




Grafika Komputerowa – p. 5

background image

Projekcja perspektywiczna

Views reen

plane

z

=

d

0

V

ertex

hx;

y

;

z

i

h

d



x=z

;

d



y

=z

;

di

z

x

Figure

I

I.19:

P

ersp

e tiv

e

pro

je tion

on

to

a

views reen

at

distan e

d

.

The

view

er

is

at

the

origin,

lo

oking

in

the

dire tion

of

the

negativ

e

z

axis.

The

p

oin

t

hx;

y

;

z

i

is

p

ersp

e tiv

ely

pro

je ted

on

to

the

plane

z

=

d

,

whi

h

is

at

distan e

d

in

fron

t

of

the

view

er

at

the

origin.

Grafika Komputerowa – p. 6

background image

Funkcja gł ˛eboko ´sci

Plane

z

=

d

0

A

=

A

0

C

=

C

0

B

B

0

z

x

Figure

I

I.20:

The

undesirable

transformation

of

a

line

to

a

urv

e.

The

mapping

used

is

hx;

y

;

z

i

7!

h

d



x=z

;

d



y

=z

;

z

i

.

The

p

oin

ts

A

and

C

are

xed

b

y

the

transformation

and

B

is

mapp

ed

to

B

0

.

The

dotted

urv

e

is

the

image

of

the

line

segmen

t

AC

.

(The

small

unlab

eled

ir les

sho

w

the

images

of

A

and

B

under

the

mapping

of

gure

I

I.19.)

Grafika Komputerowa – p. 7

background image

Funkcja gł ˛eboko ´sci

gł ˛eboko´s´c

(z) = A + Bz,

gdzie

A = −

f +n
f −n

,

B = −

2

f n

f −n

.

(x : y : z : 1) 7→ (d · x : d · y : −A · z − B · w : −z)

(x : y : z : w) 7→ (d · x : d · y : −(A · z + B · w) : −z)

(x/w : y/w : z/w : 1) 7→ (d · x/w : d · y/w : −(A · z/w + B) : −z/w)



d 0

0

0

0 d

0

0

d 0 −A −B
d 0 −1

0



Grafika Komputerowa – p. 8

background image

Zastosowanie projekcji: cie ´

n

(x, y, z) 7→



x

1 − y/y

0

, 0,

z

1 − y/y

0



y

0

y

x

x

0

ligh

t

ob

je t

shado

w

0

Figure

I

I.22:

A

ligh

t

is

p

ositioned

at

h0;

y

0

;

0i

.

An

ob

je t

is

p

ositioned

at

hx;

y

;

z

i

.

The

shado

w

of

the

p

oin

t

is

pro

je ted

to

the

p

oin

t

hx

0

;

0;

z

0

i

,

where

x

0

=

x=(1

y

=y

0

)

and

z

0

=

z

=(1

y

=y

0

)

.

Grafika Komputerowa – p. 9

background image

Cie ´

n




1

0

0 0

0

0

0 0

0

0

1 0

0 −

1

y

0

0 1




Grafika Komputerowa – p. 10

background image

Z-fighting

Grafika Komputerowa – p. 11

background image

Z-fighting

g l P o l y g o n O f f s e t ( f l o a t f a c t o r ,

f l o a t u n i t s ) ;

offset = m · factor + r · units

g l E n a b l e (

(

GL_POLIGON_OFFSET_FILL
GL_POLIGON_OFFSET_LINE
GL_POLIGON_OFFSET_POINT

)

) ;

Grafika Komputerowa – p. 12

background image

Z-fighting. Przykład

g l P o l y g o n O f f s e t (

1 ,

1);

draw (

· · ·

) ;

g l E n a b l e ( GL_POLYGON_OFFSET_FILL ) ;

g l C o l o r 3 f ( 0 , 0 , 1 ) ;

draw (

· · ·

) ;

g l D i s a b l e ( GL_POLYGON_OFFSET_FILL ) ;

Grafika Komputerowa – p. 13

background image

Projekcje w OpenGL

Projekcja prostopadła

g l O r t h o ( f l o a t

l

f l o a t

r

f l o a t

b

,

f l o a t

t

f l o a t

n

f l o a t

f

) ;

glOrtho2D ( f l o a t

l

f l o a t

r

,

f l o a t

b

f l o a t

t

) ;

(2D:

n = −1

,

f = 1

)

Grafika Komputerowa – p. 14

background image

Projekcje w OpenGL

Projekcja perspektywiczna

g l F r u s t u m ( f l o a t

l

f l o a t

r

f l o a t

b

,

f l o a t

t

f l o a t

n

f l o a t

f

) ;

0

z

=

n

z

=

f

h`;

b;

ni

hr

;

t;

ni

View

F

rustum

Figure

I

I.23:

The

frustum

view

ed

with

glFrustum(

`

,

r

,

b

,

t

,

n

,

f

).

The

near

lipping

plane

is

z

=

n

.

The

far

lipping

plane

is

z

=

f

.

The

frustum

is

the

set

of

p

oin

ts

satisfying

(I

I.16)

and

(I

I.17).

Grafika Komputerowa – p. 15

background image

Projekcja perspektywiczna




2

n

r−l

0

r+l
r−l

0

0

2

n

t−b

t+b
t−b

0

0

0

f +n
f −n

2

f n

f −n

0

0

1

0




Grafika Komputerowa – p. 16

background image

Projekcja perspektywiczna

g l u P e r s p e c t i v e ( f l o a t

θ

f l o a t aspectRatio ,

f l o a t

n

f l o a t

f

) ;

t = n tg(θ/2),

b = −n tg(θ/2),

r =

aspectRatio

·

t

l =

aspectRatio

·

b

Grafika Komputerowa – p. 17

background image

Projekcja perspektywiczna

void reziseWindow ( i n t w, i n t h ) {

g l V i e w P o r t ( 0 , 0 , w, h ) ;

f l o a t a s p e c t R a t i o ;

h = ( h==0)? 1 : h ;

a s p e c t R a t i o = ( f l o a t )w / ( f l o a t ) h ;

g l Ma tr i xMo d e ( G L _ P r o j e c t i o n ) ;

g l L o a d I d e n t i t y ( ) ;

g l u P e r s p e c t i v e ( 6 0 . 0 , a s p e c t R a t i o , 1 . 0 , 3 0 . 0 ) ;

}

Grafika Komputerowa – p. 18

background image

Projekcja perspektywiczna

g l u L o o k A t ( eye_x , eye_y , eye_z ,

c e n t e r _ x , c e n t e r _ y , c e n t e r _ z ,

up_x , up_y , up_z ) ;

Bie˙z ˛

ac ˛

a macierz ˛

a powinna by´c ModelView.

Grafika Komputerowa – p. 19


Document Outline