projection and clipping
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 PresentationTRANSCRIPT
Projection and Clipping網媒所林宏祥 2012.10.02
Overview
Orthogonal Projection
-Z
X
xcameraxviewport
cameraviewport xx
Perspective Projection
-Z
X
xcamera
xviewport
d
z
dz
xx cameraviewport
View Volume—orthogonal projection
Near Clipping Plane
Far Clipping PlaneLeft Clipping Plane
Right Clipping Plane
Bottom Clipping Plane
Top Clipping Plane
x
y
-z
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
z
x
Clipping Cuboid: transformed volume after projection
Yviewport coordinates
Implementation behind OpenGL Functions….
In OpenGL, the clipping cuboid is fixed.(Since the screen size is fixed)
z
x
Clipping Cuboid: enclosed by: xviewport = 1,xviewport=-1,yviewport=1,yviewport=-1,zviewport =1,zviewport=-1
Y
The openGL functions ensure the view volume fits clipping cuboid.
glOrtho(left, right, bottom, top, nearVal, farVal)
farValleft
right
bottom
top
nearVal
glOrtho(left, right, bottom, top, nearVal, farVal)
1
1000
200
020
002
camera
camera
camera
zyx
nearValfarValnearValfarVal
nearValfarVal
bottomtopbottomtop
bottomtop
leftrightleftright
leftright
Orthogonal Projection
-Z
X
xcameraxviewport
cameraviewport xx
some scaling
A linear mapping for orthogonal projection
A canonical view..
xviewport0
1-1
xcamera
rightleft
Clipping cuboid Viewing Volume
2rightleft
1)(10x
leftright2
leftrightxviewport
camera
Same mapping ways in y direction and z direction..
gluPerspective(fovy, aspect, zNear, zFar)
Far Clipping Plane
Near Clipping Plane
Left Clipping Plane
Right Clipping Plane
Bottom Clipping Plane
Top Clipping Plane
1
0100
200
100
100
camera
camera
camera
zyx
zFarzNearzNearzFar
zFarzNearzNearzFar
faspectf
gluPerspective(fovy, aspect, zNear, zFar)
)2/tan(1fovy
f
Perspective Projection
-Z
X
xcamera
xviewport
d
z
= 1
some scaling
-Z
X
xcamera
xviewport
d
z
dz
xx cameraviewport
A canonical view..
-Z
-zNear
-zFar
ycamera
zcamerafovy
Y
f1
zy)
2fovytan(
camera
camera
-Z
-zNear
-zFar
ycamera
zcamerafovy
Y
After projection, the boundaries should map to 1, -1)
fz-(
yycamera
cameraviewport
-Z
-zNear
-zFar
ycamera
zcamerafovy
Y
Similarly in x, but consider the aspect.
)f
z-(aspect
xxcamera
cameraviewport
)f
z-(
yycamera
cameraviewport
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
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
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
Remember perspective projection?(xcamera, ycamera coordinates will be divided by zcamera)
Perspective projection <--> maintaining homogeneous coordinates
wzyx
1wzwywx
In the clipping part of your homework..
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()
You need to calculate intersectionIn 2D example,
screen
One capable way to handle it: Cohen-Sutherland Algorithm
Any Question?