projection and clipping

33
Projection and Clipping 網網網網網網 2012.10.02

Upload: uttara

Post on 24-Feb-2016

23 views

Category:

Documents


0 download

DESCRIPTION

Projection and Clipping. 網媒所 林宏祥 2012.10.02. Overview. Orthogonal Projection. X. x camera. x viewport. -Z. Perspective P rojection. X. x camera. x viewport. -Z. d. z. View Volume—orthogonal projection. y. -z. x. Left C lipping Plane. Far C lipping Plane. Top Clipping Plane. - PowerPoint PPT Presentation

TRANSCRIPT

Page 1: Projection and Clipping

Projection and Clipping網媒所林宏祥 2012.10.02

Page 2: Projection and Clipping

Overview

Page 3: Projection and Clipping

Orthogonal Projection

-Z

X

xcameraxviewport

cameraviewport xx

Page 4: Projection and Clipping

Perspective Projection

-Z

X

xcamera

xviewport

d

z

dz

xx cameraviewport

Page 5: Projection and Clipping

View Volume—orthogonal projection

Near Clipping Plane

Far Clipping PlaneLeft Clipping Plane

Right Clipping Plane

Bottom Clipping Plane

Top Clipping Plane

x

y

-z

Page 6: Projection and Clipping

View Volume—Perspective projection model

Far Clipping Plane

Near Clipping Plane

Left Clipping Plane

Right Clipping Plane

Bottom Clipping Plane

Top Clipping Plane

x

y

-z

Page 7: Projection and Clipping

z

x

Clipping Cuboid: transformed volume after projection

Yviewport coordinates

Page 8: Projection and Clipping

Implementation behind OpenGL Functions….

Page 9: Projection and Clipping

In OpenGL, the clipping cuboid is fixed.(Since the screen size is fixed)

Page 10: Projection and Clipping

z

x

Clipping Cuboid: enclosed by: xviewport = 1,xviewport=-1,yviewport=1,yviewport=-1,zviewport =1,zviewport=-1

Y

Page 11: Projection and Clipping

The openGL functions ensure the view volume fits clipping cuboid.

Page 12: Projection and Clipping

glOrtho(left, right, bottom, top, nearVal, farVal)

farValleft

right

bottom

top

nearVal

Page 13: Projection and Clipping

glOrtho(left, right, bottom, top, nearVal, farVal)

1

1000

200

020

002

camera

camera

camera

zyx

nearValfarValnearValfarVal

nearValfarVal

bottomtopbottomtop

bottomtop

leftrightleftright

leftright

Page 14: Projection and Clipping

Orthogonal Projection

-Z

X

xcameraxviewport

cameraviewport xx

some scaling

Page 15: Projection and Clipping

A linear mapping for orthogonal projection

Page 16: Projection and Clipping

A canonical view..

xviewport0

1-1

xcamera

rightleft

Clipping cuboid Viewing Volume

2rightleft

Page 17: Projection and Clipping

1)(10x

leftright2

leftrightxviewport

camera

Same mapping ways in y direction and z direction..

Page 18: Projection and Clipping

gluPerspective(fovy, aspect, zNear, zFar)

Far Clipping Plane

Near Clipping Plane

Left Clipping Plane

Right Clipping Plane

Bottom Clipping Plane

Top Clipping Plane

Page 19: Projection and Clipping

1

0100

200

100

100

camera

camera

camera

zyx

zFarzNearzNearzFar

zFarzNearzNearzFar

faspectf

gluPerspective(fovy, aspect, zNear, zFar)

)2/tan(1fovy

f

Page 20: Projection and Clipping

Perspective Projection

-Z

X

xcamera

xviewport

d

z

= 1

some scaling

-Z

X

xcamera

xviewport

d

z

dz

xx cameraviewport

Page 21: Projection and Clipping

A canonical view..

-Z

-zNear

-zFar

ycamera

zcamerafovy

Y

Page 22: Projection and Clipping

f1

zy)

2fovytan(

camera

camera

-Z

-zNear

-zFar

ycamera

zcamerafovy

Y

Page 23: Projection and Clipping

After projection, the boundaries should map to 1, -1)

fz-(

yycamera

cameraviewport

-Z

-zNear

-zFar

ycamera

zcamerafovy

Y

Page 24: Projection and Clipping

Similarly in x, but consider the aspect.

)f

z-(aspect

xxcamera

cameraviewport

)f

z-(

yycamera

cameraviewport

Page 25: Projection and Clipping

Mapping on z: To present more details in closer objects, the viewport coordinate is inverse proportional to camera coordinates.

cz

m

camera

viewportz

cameraz1

viewportz

Page 26: Projection and Clipping

cz

m

camera

viewportz

-zFar is mapping to 1, -zNear is mapping to -1, then

czFar-m1

czNear-

m1 zFar-zNear

zNearzFar c ,zFar)-(zNear

zNearzFar2m

Page 27: Projection and Clipping

zFar-zNearzNearzFar

)zFar)(-z-(zNearzNearzFar2z

cameraviewport

)f

z-(

yycamera

cameraviewport

)f

z-(aspect

xxcamera

cameraviewport

1

0100

200

100

100

camera

camera

camera

zyx

zFarzNearzNearzFar

zFarzNearzNearzFar

faspectf

Page 28: Projection and Clipping

Remember perspective projection?(xcamera, ycamera coordinates will be divided by zcamera)

Page 29: Projection and Clipping

Perspective projection <--> maintaining homogeneous coordinates

wzyx

1wzwywx

Page 30: Projection and Clipping

In the clipping part of your homework..

Page 31: Projection and Clipping

You need to create your own clipping cuboid which is different from openGL clipping cuboid. NOT modify the viewing volume.

(eg: xviewport: [-0.5,0.5], yviewport:[-0.5,0.5], zviewport:[-0.5, 0.5])

You need to adjust the coordinates in glVertex3f()

Page 32: Projection and Clipping

You need to calculate intersectionIn 2D example,

screen

One capable way to handle it: Cohen-Sutherland Algorithm

Page 33: Projection and Clipping

Any Question?