Date post: | 05-Jan-2016 |
Category: |
Documents |
Upload: | loraine-foster |
View: | 220 times |
Download: | 2 times |
CS 450: COMPUTER GRAPHICS
PROJECTIONSSPRING 2015
DR. MICHAEL J. REALE
TRANSFORMS IN REVIEW
• Model and view transform are AFFINE transformations (parallel lines stay parallel)
• Model transform any kind of transformation we’ve seen so far
• Rotation, scaling, translation, shear, etc.
• View transform translation followed by rotation
• Centers camera at origin and orients it to look down –z axis
• Projection transform depends on which we use
• Orthographic affine
• Perspective NOT affine affects w component!
PROJECTION APPROACHES
• One can approach projection in one of two ways:
• Transform x and y, but zero out z component flattening to a 2D plane
• Not invertible (can’t get z information back)
• Doesn’t help us if we’re using z buffers
• Doesn’t restrict which points in z we want (usually want to avoid points BEHIND camera)
• Transform camera volume into unit volume
• Gives us near and far planes limits which range of z coordinates we allow
• Preserves z information (although it does transform it)
• Remember: from here on out, we are assuming that we have performed the view transform and we are already looking down the –z axis
• Either way, output will be normalized device coordinates
ORTHOGRAPHIC PROJECTION
INTRODUCTION
• Orthographic projection
• Parallel lines stay parallel affine transformation
• Does not affect w component
FLATTENING TO A PLANE
• Simple example of flattening to a plane:
1000
0000
0010
0001
oP
USING A VIEW VOLUME
• Define Axis-Aligned Bounding Box (AABB) with 6 values: left, right, bottom, top, near, far
• Goes from (l,b,n) to (r,t,f)
• Points to render must be inside AABB
• Near plane, far plane = extents of z values
• Transform AABB to unit cube
• Translation, then scale
• Makes clipping more efficient
• OpenGL (-1,-1,-1) to (1,1,1)
1000
200
02
0
002
10002
100
2010
2001
1000
02
00
002
0
0002
)()(
nf
nf
nf
bt
bt
bt
lr
lr
lr
nf
bt
lr
nf
bt
lr
tTsSPo
FLIPPING Z
• Technically, because we’re looking down NEGATVE z axis near > far!
• Often switch to LEFT-handed coordinate system by using reflection matrix before projection
• Looking down POSITIVE z axis
• Then, specify near and far values with 0 < n’ < f’ (positive z values)
1000
0100
0010
0001
)1,1,1(S
PERSPECTIVE PROJECTION
INTRODUCTION
• Perspective projection
• NOT affine parallel lines are generally NOT parallel after projection
• Lines may converge to a single point
• Matches more closely how we see things in real life (farther away = looks smaller) more commonly used
FLATTENING TOA PLANE
• Let’s say we have a plane z = -d, d > 0
• Camera is at origin
• We want to project a point p onto the plane z = -d, giving us a new point q = (qx , qy , -d)
• Using similar triangles, we can get the new x and y components:
z
xx
zx
x
p
pdq
p
d
p
q
z
yy
zy
y
p
pdq
p
d
p
q
FLATTENING TO A PLANE• The corresponding perspective projection matrix is given by:
• NOTICE: The last row isn’t just (0,0,0,1) anymore! will alter point’s w coordinate must divide vector by w!
z
xx p
pdq
z
yy p
pdq
0/100
0100
0010
0001
d
Pp
1
/
/
1
/
/
/
/10/100
0100
0010
0001
d
pdp
pdp
pdp
pdp
pdp
dp
p
p
p
p
p
p
d
pPq zy
zx
zz
zy
zx
z
z
y
x
z
y
x
p
USING A VIEW VOLUME
• The view volume (or frustum) of a perspective projection is defined a little differently:
• Near and far plane
• (Left, bottom) and (right, top) corners of NEAR plane
PERSPECTIVE PROJECTION MATRIX
• The perspective projection matrix is given by:
• Example: point already at near plane:
0100
200
02
0
002
nf
fn
nf
nfbt
bt
bt
nlr
lr
lr
n
Pp
1
1
)2(
)2(
1
)(
)2(
)2(
1
)2(
)2(
)2(
)2(
)2(
)2(
2)(
)(2
)(2
10100
200
02
0
002
bt
btplr
lrp
nf
nfbt
btplr
lrp
nf
fnfbt
btplr
lrp
nnf
fnfnbt
btpnlr
lrpn
nnf
fnnfnbt
btnnplr
lrnnp
n
p
p
nf
fn
nf
nfbt
bt
bt
nlr
lr
lr
n
pPq y
x
y
x
y
x
y
x
y
x
y
x
p
FLIPPING Z
• Same as with the orthographic projection, z can be flipped before projection
• After that, use 0 < n’ < f’
• OpenGL matrix with flipping:
0100''
''2
''
''00
0'2
0
00'2
nf
nf
nf
nfbt
bt
bt
nlr
lr
lr
n
POpenGL
FIELD OF VIEW
• Often can define horizontal and vertical field of view (FOV) angles
• Too wide see distortion on edges (fish-eye lens effect)
• Too narrow everything very “zoomed in”
• Can compute horizontal FOV based on w = width of monitor and d = distance from user:
• Asymmetric frustums = where either r != -l or t != -b used in stereo viewing
))2/(arctan(2 dw
EFFECTS OF FOV
FOV = 109°
FOV = 70°
FOV = 30°
EFFECT ON Z VALUE
• With perspective projection resulting z values do NOT vary linearly with input pz value!
• Placement of near and far planes affects precision of z buffer!
• Example: abs(f – n) = 100, varying how close near plane is to camera: