Grafika Komputerowa

Projekcja

Alexander Denisjuk

denisjuk@pjwstk.edu.pl

Polsko-Japo ńska Wyższa Szkoła Technik Komputerowych zamiejscowy ośrodek dydaktyczny w Gda ńsku ul. Brzegi 55

80-045 Gda ńsk

Grafika Komputerowa – p. 1

Projekcja

Najnowsza wersja tego dokumentu dost ępna jest pod adresem

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

Grafika Komputerowa – p. 2

Drugi etap renderowania

P

ersp

e tiv

e

View

Mo

deling

Displa

ying

Division

Sele tion

Figure

I

I.1:

The

four

stages

of

the

rendering

pip

eline

in

Op

enGL.

Grafika Komputerowa – p. 3

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

Projekcja prostopadła

l ≤ x ≤ r,

left, right

b ≤ y ≤ t,

bottom, top

n ≤ z ≤ f,

near, far



2

0

0



− r+l

r−l

r−l

 0

2

0

− t+b 



t−b

t−b 

 0

0

2

− f+n 



f −n

f −n 

0

0

0

1

Grafika Komputerowa – p. 5

Projekcja perspektywiczna

V

ertex

hx;

y

;

z

i

Views reen

plane

z

=

d

h

d

x=z

;

d

y

=z

;

di

x

0

z

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

Funkcja gł ęboko ści

0

A

=

A

B

0

B

0

Plane

z

=

d

C

=

C

x

0

z

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

0

transformation

and

B

is

mapp

ed

to

B

.

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

Funkcja gł ęboko ści

gł ębokość(z) = A + Bz,

gdzie A = − f+n ,

B = − 2fn .

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

Zastosowanie projekcji: cie ´

n

x

z

(x, y, z) 7→

, 0,

1 − y/y0

1 − y/y0

ligh

t

y

0

ob

je t

y

shado

w

0

0

x

x

Figure

I

I.22:

A

ligh

t

is

p

ositioned

at

h0;

y

;

0i

.

An

ob

je t

is

p

ositioned

at

0

0

0

hx;

y

;

z

i

.

The

shado

w

of

the

p

oin

t

is

pro

je ted

to

the

p

oin

t

hx

;

0;

z

i

,

where

0

0

x

=

x=(1

y

=y

)

and

z

=

z

=(1

y

=y

)

.

0

0

Grafika Komputerowa – p. 9

Cie ´

n





1

0

0 0

0

0

0 0





0

0

1 0





0 − 1

0 1

y0

Grafika Komputerowa – p. 10

Z-fighting

Grafika Komputerowa – p. 11

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 (GL_POLIGON_OFFSET_FILL

)

g l E n a b l e (

GL_POLIGON_OFFSET_LINE

) ;

GL_POLIGON_OFFSET_POINT

Grafika Komputerowa – p. 12

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

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

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 ) ; View

F

rustum

hr

;

t;

ni

z

=

f

z

=

n

h`;

b;

ni

0

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

Projekcja perspektywiczna

 2n

0

r+l

0 

r−l

r−l

t+b

 0

2n

0 



t−b

t−b



 0

0

− f+n

− 2fn 



f −n

f −n 

0

0

−1

0

Grafika Komputerowa – p. 16

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

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

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żącą macierzą powinna być ModelView.

Grafika Komputerowa – p. 19

Document Outline

  • wyklad
  • Drugi etap renderowania
  • Dwa typy projekcji
  • Projekcja prostopadªa
  • Projekcja perspektywiczna
  • Funkcja gª¦boko±ci
  • Funkcja gª¦boko±ci
  • Zastosowanie projekcji: cie«
  • Cie«
  • Z-fighting
  • Z-fighting
  • Z-fighting. Przykªad
  • Projekcje w OpenGL
  • Projekcje w OpenGL
  • Projekcja perspektywiczna
  • Projekcja perspektywiczna
  • Projekcja perspektywiczna
  • Projekcja perspektywiczna