Projection and Clipping
Download
Report
Transcript Projection and Clipping
Projection and Clipping
網媒所林宏祥 2012.10.02
Overview
Orthogonal Projection
X
xviewport
xcamera
-Z
x viewport x camera
Perspective Projection
X
xcamera
xviewport
-Z
d
z
x viewport
x camera
z
d
View Volume—orthogonal projection
y
-z
x
Left Clipping Plane
Far Clipping Plane
Top Clipping Plane
Bottom Clipping Plane
Near Clipping Plane
Right Clipping Plane
View Volume—Perspective projection model
y
-z
x
Left Clipping Plane
Far Clipping Plane
Top Clipping Plane
Near Clipping Plane
Bottom Clipping Plane
Right Clipping Plane
Clipping Cuboid: transformed volume after projection
Y
viewport coordinates
x
z
Implementation behind OpenGL
Functions….
In OpenGL, the clipping cuboid is
fixed.
(Since the screen size is fixed)
Clipping Cuboid: enclosed by:
xviewport = 1,xviewport=-1,yviewport=1,yviewport=-1,zviewport =1,zviewport=-1
Y
x
z
The openGL functions ensure the view
volume fits clipping cuboid.
glOrtho(left, right, bottom, top, nearVal, farVal)
left
farVal
top
bottom
nearVal
right
glOrtho(left, right, bottom, top, nearVal, farVal)
2
right left
0
0
0
0
2
top bottom
0
0
0
0
2
farVal nearVal
0
right left
right left
top bottom
top bottom
farVal nearVal
farVal nearVal
1
x camera
y
camera
z camera
1
Orthogonal Projection
X
xviewport
xcamera
-Z
some scaling
x viewport x camera
A linear mapping for orthogonal
projection
A canonical view..
Clipping cuboid
Viewing Volume
1
-1
0
xviewport
left
right
left right
2
xcamera
right left
x camera
2
x viewport 0
right left
1 ( 1)
Same mapping ways in y direction and z direction..
gluPerspective(fovy, aspect, zNear, zFar)
Left Clipping Plane
Far Clipping Plane
Top Clipping Plane
Near Clipping Plane
Bottom Clipping Plane
Right Clipping Plane
gluPerspective(fovy, aspect, zNear, zFar)
f
aspect
0
0
0
f
0
0
f
0
zFar zNear
0
zNear zFar
1
0
1
tan( fovy / 2 )
1
2 zFar zNear
zNear zFar
0
1
x camera
y
camera
z camera
1
Perspective Projection
X
xcamera
xviewport
-Z
d =1
z
z
some scaling
x viewport
x camera
z
d
A canonical view..
Y
-zFar
-zNear
ycamera
fovy
zcamera
-Z
Y
-zFar
-zNear
ycamera
fovy
tan(
zcamera
fovy
2
)
y camera
z camera
-Z
1
f
Y
-zFar
-zNear
ycamera
fovy
zcamera
After projection, the boundaries should map to 1, -1
-Z
y viewport
(
y camera
- z camera
f
)
y viewport
y camera
- z camera
(
)
f
Similarly in x, but consider the aspect.
x viewport
x camera
-z
aspect ( camera )
f
Mapping on z: To present more details in closer objects, the viewport
coordinate is inverse proportional to camera coordinates.
z viewport
z viewport
1
z camera
m
z camera
c
z viewport
m
c
z camera
-zFar is mapping to 1, -zNear is mapping to -1, then
1
m
c
- zFar
m 2
1
m
- zNear
c
zFar zNear
(zNear - zFar)
,c
zFar zNear
zNear - zFar
y viewport
(
y camera
- z camera
)
f
x viewport
x camera
-z
aspect ( camera )
f
z viewport 2
f
aspect
0
0
0
zFar zNear
(zNear - zFar)(-z
0
0
f
0
zFar zNear
0
0
zNear zFar
1
camera
)
zFar zNear
zNear - zFar
1
2 zFar zNear
zNear zFar
0
1
x camera
y
camera
z camera
1
Remember perspective projection?
(xcamera, ycamera coordinates will be divided by zcamera)
Perspective projection
<-->
maintaining homogeneous coordinates
x
y
z
w
x
w
y
w
z
w
1
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 intersection
In 2D example,
screen
One capable way to handle it: Cohen-Sutherland Algorithm
Any Question?