View
15
Download
0
Category
Preview:
Citation preview
1
Projection Matricesfor Viewing
andClipping
2
Objectives
•Derive projection matrice for
perspective projections
• Introduce camera frame
•Clipping
• Introduce projection normalization
•Camera's in GL
2
3
Computer Viewing
• Need to build transformation that defines the projection plane based on the chosen projection
4
Orthogonal Projection
3
5
Orthogonal Projection
6
Orthogonal Projection
• Set z =0
• Equivalent homogeneous coordinate transformation:
1000
0000
0010
0001
Morth
1
pz
py
px
=
1
0
'
'
py
px
4
7
Oblique Projections
8
Direction of projection dop = (dopx,dopy,dopz)
x
zdop
Lets say we project onto z = 0 plane
Oblique Projections
5
9
Direction of projection dop = (dopx,dopy,dopz)
x
z
=
1
pz
py
px
1
0
'
'
py
px
dop
1000
0000
0dopy/dopz-10
0-dopx/dopz01
Oblique Projections
note: tan = dopz/dopx
10
•Equivalent to pulling faces in opposite directions
Shear Matrix
6
11
Shear Matrix
Consider simple shear along x axis
x’ = x + y shy
y’ = yz’ = z
1000
0100
0010
00sh1 y
H =
12
Oblique Projection
=
1000
0000
0dopy/dopz-10
0-dopx/dopz01
H
Projection matrix:
Mprojection = Morth H
xy shear (z value stays unchanged)
7
13
Simple Perspective
Consider a simple perspective with the COP at (0,0,0), the image plane at z = d
z = d
(0,0,0)
(xo,yo,zo)
(xp,yp,d)
z
14
Simple Perspective
Consider a simple perspective with the COP at (0,0,0), the image plane at z = d
0/100
0100
0010
0001
d
1
pz
py
px
=
1
d
'py
'px
Mpersp
Projection matrix:Mprojection = Mpersp
8
15
Computer Viewing
There are three aspects of the viewing process:
- Selecting a lensSetting the projection matrix
- Positioning the cameraSetting the view-orientation matrix
- ClippingSetting the view volume
16
Defining and moving the camera
default camera(from transform)
wanted camera
9
17
Moving the Camera
•We can move the camera to any desired position by a sequence of rotations and translations
•Example: side view-Rotate after moving
camera away from origin
-Camera View matrix, VcamVcam = Rcam Tcam
18
Whole camera transform
•We can put these together as:
Ttotal = Mprojection Vcam
•Note, while Mprojection is different for persp and parallel,they are both projections...
10
19
Camera coordinates
Camera coordinate frame relative to global from user input
20
OpenGL Orthogonal Viewing
glOrtho(xmin,xmax,ymin,ymax,near,far)glOrtho(left,right,bottom,top,near,far)
near and far measured from camera
11
21
OpenGL Perspective
glFrustum(xmin,xmax,ymin,ymax,near,far)
22
Using Field of View
•With glFrustum it is often difficult to get the desired view•gluPerpective(fov, aspect, near, far)
often provides a better interface
aspect = w/h
front plane
12
23
Clipping
Clipping remove unseen geometry
Direct solution:
Solve for intersections
(simultaneous equations)
between lines/edges
at window sides
A point or vertex isvisible if
left < x < rightand
bottom < y < top
Clipping lines
Pipeline, clip each edge of the window separately:
TopClip
BottomClip
RightClip
LeftClip
13
25
Clip the verticesthat are outside ofthe window andcreate new verticesat window border
Result is still a single polygonbut may have morevertices and an oddshape
Clipping polygons
26
Clipping polygons
TopClip
BottomClip
RightClip
LeftClip
14
27
Clipping polygons
Bounding box - surrounds each polygon
Accelerations:
28
Clipping polygons
Trivially reject or accept if the bounding box falls completely inside or outside.
Accelerations:
15
29
Cohen-Sutherland Algorithm
• Region Checks: Trivially reject or accept for clipping
• Each vertex is assigned an 4-bit outcode
- bit 1 - sign of (top - y), point is above window
- bit 2 - sign of (y-bottom), point is below window
- bit 3 - sign of (right-x), point is right of window
- bit 4 - sign of (x - left), point is left of window
30
1001
0001
0101
1000
0000
0100
1010
0010
0110
A line can be trivially accepted if both endpoints have anoutcode of 0000.
A line can be trivially rejected if any of the same two bits in the outcodes are both equal to 1 (both endpoints are left,right,above, below the window)
Cohen-Sutherland Algorithm
16
31
Clipping 3D
Adds far and nearclipping planes for3D viewing volume
32
Normalization
• Rather than derive a different projection matrix for each type of projection, we can convert all projections to basic projections with a default view volume
• This strategy allows us to use standard transformations in the pipeline and makes for efficient clipping
• Volume known as canonical view volume
17
33
Orthogonal Normalization
Normalization find transformation to convertspecified clipping volume to default
canonical volume
(right,top,far)
(left,bottom,near)
(1,1,1)
(-1,-1,-1)
34
• Two steps
- Move center to origin
T(-(left+right)/2, -(bottom+top)/2,-(near+far)/2))
- Scale to have sides of length 2
S(2/(right-left),2/(top-bottom),2/(near-far))
Orthogonal Normalization
18
35
1000
200
02
0
002
nearfar
nearfar
farnear
bottomtop
bottomtop
bottomtop
leftright
leftright
leftright
ST =
Orthogonal Normalization
P = MorthST
Combined with orthogonal projection yields:
36
To use the same projection, we shear but don't project
x
z
=
1
pz
py
px
1
'
'
'
pz
py
px
dop
Oblique with Normalization
1000
0100
0dopy/dopz-10
0-dopx/dopz01
19
37
Oblique with Normalization
xy shear (z values unchanged)
Projection matrix
Normalize as:
H =
P = Morth H
P = Morth STH
1000
0100
0dopy/dopz-10
0-dopx/dopz01
38
Equivalency
20
39
Effect on Clipping
•The projection matrix P = STH transforms the original clipping volume to the default clipping volume
(seen from top view)
DOP DOP
near plane
far planeobject
ClippingVolume
z = -1
z = 1
x = -1x = 1
distorted object(projects correctly)
40
Perspective Projection
•How do we normalize the frustrum of the
perspective view?
• Want to make a canonical volume to clip against, just like in the parallel case
21
41
Canonical Perspective
Consider a simple perspective with the COP at the origin, the far plane at z = 1, and a 90 degree field of view determined by the planes x = z,
y = z
Z = 1
Zfar
xmin xmax
x=zx=-z
x x
z
42
Effect on Clipping
•Extension to Cohen-Sutherland Clipping
Z = 1
x=zx=-z
x
zmin
Bit 1 – above volume y> zBit 2 – below volume y<-zBit 3 – right of volume x >zBit 4 – left of volume x <-zBit 5 – behind volume z > 1Bit 6 – in front of volume z< zmin
22
43
Pipeline View
camera viewtransformation
transform projection to
canonical view
clipping projection
against canonical 3D 2D
•Must add shear for asymmetric views, slightly different for persp vs. parallel
same for all projections
44
Why do we do it this way?
• Normalization allows for a single pipeline to be used with all (perspective and parallel) desired views
• Keep in four dimensional homogeneous coordinates as long as possible to retain three-dimensional information needed for hidden-surface removal and shading
• Standardize clipping
Recommended