Viewing
Viewing
1
Clipping Window
ywmax
World Coordinates
xwmin xwmax
Viewing world has its own
Viewport
yvmax coordinates, which may be
a non-uniform scaling of
world coordinates.
yvmin
Viewport Coordinates
xvmin xvmax
2
2D viewing transformation pipeline
Construct World-
Modeling World Convert World-
Coordinates Coordinate Scene Coordinates Coordinates to
From Modeling-
Viewing-
Coordinate
Coordinates
Transformations
Viewing Coordinates
3
Normalization and Viewport Transformations
• First approach:
– Normalization and window-to-viewport transformations are
combined into one operation.
– Viewport range can be in [0,1] x [0,1].
– Clipping takes place in [0,1] x [0,1].
– Viewport is then mapped to display device.
• Second approach:
– Normalization and clipping take place before viewport
transformation.
– Viewport coordinates are specified in screen coordinates.
4
1
Clipping Window
ywmax Normalized Viewport
yvmax
xw, yw
xv, yv
ywmin yvmin
0
xwmin xwmax xvmin xvmax1
Maintain relative size and position between clipping window and viewport.
5
Solving for xv, yv obtains:
xv sx xw t x , yv s y yw t y , where
xvmax xvmin yvmax yvmin
Scaling factors: sx , sy
xwmax xwmin ywmax ywmin
Translation factors:
xwmax xvmin xwmin xvmax ywmax yvmin ywmin yvmax
tx , ty
xwmax xwmin ywmax ywmin
This can also be obtained by composing transformations:
M window,
norm_viewport
sx 0 tx
T xvmin , yvmin S sx , s y T xwmin , ywmin 0 sy t y
0 0 1
6
World clipping window can first be mapped to normalized square between -1
and +1, where clipping algorithm takes place, and then transform the scene
into viewport given in display coordinates.
2 xwmax xwmin
xw xw 0
xwmax xwmin
max min
2 yw ywmin
M window, 0 max
norm_square
ywmax ywmin ywmax ywmin
0 0 1
7
Clipping Algorithms
p9
Before Clipping After Clipping
p4 p10
p2 p2
p1 p1
p8
p6 p6 p8
p3 p5 p5
p7 p7
x x0 u xend x0 , y y0 u yend y0 , 0 u 1.
intersection calculations.
9
Cohen-Sutherland Line Clipping Algorithm
x xwmin xwmax x
1 0 0 1 1 0 0 0 1 0 1 0
ywmax y
0 0 0 1 0 0 0 0 0 0 1 0
y ywmin
0 1 0 1 0 1 0 0 0 1 1 0
Endpoint codes are 0000 for both iff line is completely inside.
If endpoint codes has 1 in same bit, line is certainly outside.
11
Lines that cannot be decided are intersected with window
border lines.
Each test clips the line and the remaining is tested again
for full inclusion or certain exclusion, until remaining is
either empty or fully contained.
12
p2
1 0 0 1 1 0 0 0
p2
p2
0 0 0 1 0 0 0 0
p3
p1
p3
0 1 0 1 p4 0 1 0 0 p1
13
Liang-Barsky Line Clipping Algorithm
Treat undecided lines in Cohen-Sutherland more efficiently.
xend , yend
xwmin xwmax
ywmax
x0 , y0 ywmin
14
Parametric presentation:
x x0 u xend x0 , y y0 u yend y0 , 0 u 1.
border).
occurs at u qk pk .
16
We calculate and update u0 and uend progressively for
18
This is more efficient than Cohen-Sutherland Alg,
which computes intersection with clipping window
borders for each undecided line, as a part of the
feasibility tests.
19
Sutherland-Hodgman Polygon Clipping
1
1’’ 1’’
1’ 3’’ 1’ 3’’
Clipping
Clipping Window 3
3’ 3’
2’ 2’’ 2’ 2’’
2
Efficient algorithm for clipping convex polygons.
Edges are clipped against every border line of clipping window. Edges
are processed successively.
20
The four possible outputs generated by the left clipper, depending on
the relative position of pair of edge endpoints.
out in in in
v2
output: v1 v 2 output: v 2
v2 v1
v1
v1
out out
v1
v1 output: none
v2 v1
in out
output: v1
v2
21
2
2’
3 2”
1’
3’
1
Input Left Clipper Right Clipper Bottom Clipper Top Clipper
[1,2]: (in-in)>{2}
22
• The four clippers can work in parallel.
– Once a pair of endpoints it output by the first clipper,
the second clipper can start working.
– The more edges in a polygon, the more effective
parallelism is.
23
3D Viewing Concepts
24
2D Reminder
Choose viewing position, direction and orientation of the
camera in the world.
25
Clipping window: Selects what we want to see.
Viewport: Indicates where it is to be viewed on the output
device (still in world coordinates).
Display window: Setting into screen coordinates.
Construct World-
Coordinate Scene Convert World-
Coordinates to Projection
From Modeling-
Coordinate Viewing- Transformation
Transformations Coordinates
Projection Coordinates
27
Model is given in model (self) coordinates.
Conversion to world coordinates takes place.
yworld
yview
view point
v
p0 view-up vector
xworld u
n
zworld zview xview
30
n : viewing directionon yview
u v : viewing plane view point
v
u u x , u y , u z
p0 view-up vector
u
v vx , v y , vz n
n nx , n y , nz
zview xview
p 0 x0 , y0 , z0
u x uy uz 0 1 0 0 x0
v vy vz 0 0 1 0 y0
world to viewing M WC,VC x
transformation nx ny nz 0 0 0 1 z0
0 0 0 1 0 0 0 1
rotation translation
31
Projection Transformations
Next step in 3D viewing pipeline is projection of object to
viewing plane
Parallel Projection
View Plane
32
Perspective Projection
33
Orthogonal (orthographic) projections
Plane View
Front
Elevation Side
View Elevation
View
Far
Clipping
Plane
Near
Clipping yview
Plane
Clipping window
xview
zview
35
Normalizing Orthogonal Projection
Orthogonal Projection View Volume ynorm
yview
2 xwmax xwmin
xw xw 0 0
xwmax xwmin
max min
2 yw ywmin
0 0 max
ywmax ywmin ywmax ywmin
2 znear zfar
0 0
znear zfar znear zfar
0 0 0 1
x , y
p p , zvp
Vp x, y , z
vp
x, y , z
38
xp x
V px x , y
p p , zvp
zvp z V pz
L
Not orthogonal
yp y V py as viewed
zvp z V pz
Vp x, y , z
vp
x, y , z
Clipping
Window View
Volume
(Side)
Near Vp
Plane
View
Volume Vp
(Top) Far
Plane
40
V px V px
1 0 zvp
V pz V pz This is a 3D shear
V py V py transformation.
M oblique 0 1 zvp
V pz V pz x and y are displaced by
0 0 1 0 amount proportional to z.
0 0 0 1
41
Perspective Projections
View Plane
Closer objects look larger.
Projection
Reference
Point
Projection Point
p x, y , z x , y , zvp
p p yview
p prp x prp , y prp , z prp
43
The problem with the above representation is that Z appears in
denominator, so matrix multiplication representation of X and Y
on view plane as a function of Z is not straight forward.
44
Vanishing Points
Vanishing points occur when the viewing plane intersects with the
axes of viewing coordinate system.
y Vanishing
Point
z
Principle axes for cube One-Point perspective Projection
View
Rectangular Frustum
Plane
View Volume
Near yview
Clipping
Plane
xview
Field-of-view Angle Projection
zview Reference Point
May 2010 47
Symmetric Frustum Parallel Piped
View Volume View Volume
Far Plane
Perspective
Mapping
Near Plane
View Plane
Clipping Window
Projection
Reference Point
May 2010 48
Oblique Frustum Parallel Piped
View Volume View Volume
Perspective
Mapping
xwmin xwmax
Projection
Reference Point
May 2010 49
3D Viewport Transformation
The normalized view volume cube extending from 1, 1, 1 to
May 2010 50
Settings of Perspective Projection
• Perspective projection point
– Where the viewer (camera, eye) is positioned in the world.
• Positioning viewing plane with respect to viewing
coordinates
– Results vanishing points, one, two or three.
• Clipping window on viewing plane
– Defines the infinite pyramid view volume.
• Near and far clipping planes (parallel to view plane)
– Define the rectangular frustum view volume.
• Scale and translation parameters of perspective matrix
– Define the normalization range.
May 2010 51
3D Clipping
Clipping can take place on normalized cube:
Similar to 2D, we add two bits to code the far and near planes.
Far bit Near bit Top bit Bottom bit Right bit Left bit
h xh h, h yh h, h z h h if h 0
h xh h, h yh h, h zh h if h 0
52
Top
y
Far
Near
Bottom
Left
x
Right
z
53
A line is completely accepted if the codes of its ends are both 000000, or
equivalently, if the logical OR between codes is zero.
A line is rejected if the codes of its ends has at least one 1 in same bit, or
equivalently, if the logical AND between codes is nonzero.
Otherwise, the line is tested against each of the planes and the 2D Liang-
Barsky algorithm can be extended to 3D.
A point P of a line segment P1P2 extending from P1 xh1 , yh1 , zh1 , h1
to P2 xh2 , yh2 , zh2 , h2 is given by P P1 P2 P1 u, 0 u 1.
54
If for instance the codes of the two end points of P1P2 w.r.t the right
from x p xh h xh1 xh2 xh1 u h1 h2 h1 u 1.
Solving for u yields u xh1 h1 xh1 h1 xh2 h2 .
Such calculation proceeds for each upk qk , 1 k 6, while
55