slides6
slides6
Clipping
Tom Thorne
View transformation
Clipping
I Homogeneous transformation
I Parallel projection
I Perspective projection
I Canonical view volume
Homogeneous transformations
I As used by OpenGL
Parallel (orthographic) projection
0 0 0 1
1 0 0 0 x x
0 1 0 0 y y
=
0 0 0 0 z 0
0 0 0 1 1 1
Perspective projection
0
−d xz
x x
y 0 −d y y
=
z=
−d −d z
1 1 −z/d
0 0 − d1 0
Perspective projection
1 0 0 0 x x x
0 1 0 0 y y −z/d
y
Vp = Mproj Vc = = = −z/d
0 0 1 0 z z
0 0 − d1 0 1 − dz −d
Alternative formulation
Alternative formulation
1 0 0 0
0 1 0 0
Mproj =
0 0 0 0
−1
0 0 d 1
Exercise
1 0 0 0
0 1 0 0
Mproj =
0 0 0 0
0 0 − d1 1
Problems
2n r +l
r −l 0 r −l 0
0 2n t+b
t−b t−b 0
Mcan =
− ff +n − f2fn
0 0 −n −n
0 0 −1 0
Final steps
−1 ≤ x ≤ 1,−1 ≤ y ≤ 1,−1 ≤ z ≤ 1
Example
Mcan =
2n r +l
r −l 0 r −l 0
0 2n t+b
t−b t−b 0
− ff +n − f2fn
0 0 −n −n
0 0 −1 0
Example
M
can =
2n r +l
r −l 0 r −l 0
0 2n t+b
t−b t−b 0
=
− ff +n
− f2fn
0 0 −n −n
0 0 −1 0
1 0 0 0
0 1 0 0
0 0 −2 −3
0 0 −1 0
n = 1,f = 3,r = 1,l = −1,t =
1,b = −1
3
1 0 0 0 3 3 2
0 1 0 0 0 0 0
= =
0 0 −2 −3 −2 1 12
0 0 −1 0 1 2 1
Projection summary
View transformation
Clipping
Outcodes:
Outcodes:
0 OR 0 = 0
0 OR 1 = 1
1 OR 0 = 1
1 OR 1 = 1
0 AND 0 = 0
0 AND 1 = 0
1 AND 0 = 0
1 AND 1 = 1
Trivial accept
All line endpoints are inside the screen
Both line endpoints are outside of the screen on the same side
A
A'
A''
B
Cohen-Sutherland algorithm
Extension to 3D
Sutherland-Hodgman algorithm
Input 2D polygon
Output List of clipped vertices
Projection
Clipping
I Cohen-Sutherland algorithm
I Sutherland-Hodgman algorithm
References
View transformation
I Shirley, Chapter 7
I Foley, Chapter 6
Clipping