CS-378: Game Technology Lecture #2.1: Projection Prof. Okan Arikan University of Texas, Austin...
-
Upload
beverley-audra-adams -
Category
Documents
-
view
232 -
download
0
Transcript of CS-378: Game Technology Lecture #2.1: Projection Prof. Okan Arikan University of Texas, Austin...
CS-378: Game TechnologyLecture #2.1: Projection
Prof. Okan ArikanUniversity of Texas, Austin
Thanks to James O’Brien, Steve Chenney, Zoran Popovic, Jessica Hodgins
V2005-05-1.3
22
Today
Windowing and Viewing Transformations
Windows and viewports
Orthographic projection
Perspective projection
33
Screen Space
Monitor has some number of pixelse.g. 1024 x 768
Some sub-region used for given program
You call it a window
Let’s call it a viewport instead
44
Screen Space
May not really be a “screen”Image file
Printer
Other
Little pixel details
Sometimes oddUpside down
HexagonalFrom Shirley textbook.
55
Screen Space
Viewport is somewhere on screenYou probably don’t care where
Window System likely manages this detail
Sometimes you care exactly where
Viewport has a size in pixelsSometimes you care (images, text, etc.)
Sometimes you don’t (using high-level library)
66
Canonical View Space
Canonical view region2D: [-1,-1] to [+1,+1]
From
Sh
irle
y
textb
ook.
77
Canonical View Space
Canonical view region2D: [-1,-1] to [+1,+1]
From
Sh
irle
y
textb
ook.
88
Canonical View Space
Canonical view region
2D: [-1,-1] to [+1,+1]
Define arbitrary window and define objects
Transform window to canonical region
Do other things (we’ll see clipping latter)
Transform canonical to screen space
Draw it.
99
Canonical View Space
World Coordinates Canonical Screen Space
(Meters) (Pixels)
Note distortion issues...
1010
Projection
Process of going from 3D to 2D
Studies throughout history (e.g. painters)
Different types of projectionLinear
Orthographic
Perspective
Nonlinear
Orthographic is special case ofperspective...
Many special cases in books just one of these two...
1111
Linear Projection
Projection onto a planar surface
Projection directions eitherConverge to a point
Are parallel (converge at infinity)
1212
Linear Projection
A 2D view
OrthographicPerspective
1313
Linear Projection
Orthographic Perspective
1414
Linear Projection
Orthographic Perspective
1515
OrthographicPerspective
Note how different things can be seen
Parallel lines ŅmeetÓ at infinity
Linear Projection
A 2D view
1616
Orthographic Projection
No foreshortening
Parallel lines stay parallel
Poor depth cues
1717
Canonical View Space
Canonical view region3D: [-1,-1,-1] to [+1,+1,+1]
Assume looking down -Z axisRecall that “Z is in your face”
[1,1,1][-1,-1,-1]
-Z
[1,1,1][-1,-1,-1]
-Z
1818
Orthographic Projection
Convert arbitrary view volume to canonical
[1,1,1] [-1,-1,-1]
-Z
[1,1,1] [-1,-1,-1]
-Z
1919
Orthographic Projection
View vector
Up vector
Right = view X up
Origin
Center
near,top,right
far,bottom,left
*Assume up is perpendicular to view.
2020
Orthographic Projection
Step 1: translate center to origin
2121
Orthographic Projection
Step 1: translate center to origin
Step 2: rotate view to -Z and up to +Y
2222
Orthographic Projection
Step 1: translate center to origin
Step 2: rotate view to -Z and up to +Y
Step 3: center view volume
2323
Orthographic Projection
Step 1: translate center to origin
Step 2: rotate view to -Z and up to +Y
Step 3: center view volume
Step 4: scale to canonical size
2424
Orthographic ProjectionOrthographic Projection
Step 1: translate center to origin
Step 2: rotate view to -Z and up to +Y
Step 3: center view volume
Step 4: scale to canonical size
2525
Perspective Projection
Foreshortening: further objects appear smaller
Some parallel line stay parallel, most don’t
Lines still look like lines
Z ordering preserved (where we care)
2626
Perspective Projection
Pinhole a.k.a center of projection
Image f
rom
D.
Fors
yth
2727
Perspective Projection
Foreshortening: distant objects appear smaller
Image f
rom
D.
Fors
yth
2828
Perspective Projection
Vanishing pointsDepend on the scene
Not intrinsic to camera
“One point perspective”
2929
Perspective Projection
Vanishing pointsDepend on the scene
Nor intrinsic to camera
“Two point perspective”
3030
Perspective Projection
Vanishing pointsDepend on the scene
Not intrinsic to camera
“Three point perspective”
3131
Perspective Projection
u
v
n
u
v
n
View Frustum
3232
Perspective Projection
ViewUp
Distance to image planei
Y
-Z
Topt
Bottomb
Nearn
Farf
Center
3333
Perspective Projection
Step 1: Translate center to origin
Y
-Z
Y
-Z
3434
Perspective Projection
Step 1: Translate center to origin
Step 2: Rotate view to -Z, up to +Y
Y
-Z
Y
-Z
3535
Perspective Projection
Step 1: Translate center to origin
Step 2: Rotate view to -Z, up to +Y
Step 3: Shear center-line to -Z axis
Y
-Z
Y
-Z
3636
Perspective Projection
Step 1: Translate center to origin
Step 2: Rotate view to -Z, up to +Y
Step 3: Shear center-line to -Z axis
Step 4: Perspective
-Z-Z
01
00
00
0010
0001
i
fi
fi
3737
Perspective Projection
Step 4: PerspectivePoints at z=-i stay at z=-i
Points at z=-f stay at z=-f
Points at z=0 goto z=±∞
Points at z=-∞ goto z=-(i+f)
x and y values divided by -z/i
Straight lines stay straightDepth ordering preserved in [-i,-f ]
Movement along lines distorted
-Z-Z
01
00
00
0010
0001
i
fi
fi
01
00
00
0010
0001
i
fi
fi
3838
From
Sh
irle
y
textb
ook.
From
Sh
irle
y
textb
ook.
Perspective Projection
WRONG!WRONG!
01
00
00
0010
0001
i
fi
fi
01
00
00
0010
0001
i
fi
fi
3939
Perspective Projection“Eye” plane
Top
Near Far
Som
e ho
rizon
tal
lines
View vector
4040
Perspective Projection
Visualizing division of x and y but not z
4141
Perspective Projection
Motion in x,y
4242
Perspective Projection
Note that points on near plane fixed
4343
Perspective Projection
Recall that points on far plane willstay there...
4444
Perspective Projection
When we also divide z points mustremain on straight lines
4545
Perspective Projection
Lines extend outside view volume
4646
Perspective Projection
Motion in z
4747
Perspective Projection
Motion in z
4848
Perspective Projection
Motion in z
4949
Perspective Projection
Total motionTotal motion
5050
Perspective Projection
Step 1: Translate center to orange
Step 2: Rotate view to -Z, up to +Y
Step 3: Shear center-line to -Z axis
Step 4: Perspective
Step 5: center view volume
Step 6: scale to canonical size
-Z-Z
5151
Perspective Projection
Step 1: Translate center to orange
Step 2: Rotate view to -Z, up to +Y
Step 3: Shear center-line to -Z axis
Step 4: Perspective
Step 5: center view volume
Step 6: scale to canonical size
-Z-Z
5252
Perspective Projection
There are other ways to set up the projection matrix
View plane at z=0 zero
Looking down another axis
etc...
Functionally equivalent
5353
Vanishing Points
Consider a ray:
dp dp
5454
Vanishing Points
Ignore Z part of matrix
X and Y will give location in image plane
Assume image plane at z=-i
0100
0010
0001
z
y
x
I
I
I
w
y
x
100
010
001
0100
0010
0001
z
y
x
I
I
I
w
y
x
100
010
001
whateverwhatever
5555
Vanishing Points
z
y
x
z
y
x
I
I
I
w
y
x
100
010
001
zy
zx
II
II
wy
wx
/
/
/
/
z
y
x
z
y
x
I
I
I
w
y
x
100
010
001
zy
zx
II
II
wy
wx
/
/
/
/
5656
Vanishing Points
Assume
tp
tdptp
tdp
zy
zx
II
II
z
yy
z
xx
wy
wx
/
/
/
/
y
x
d
d
t
Lim
tp
tdptp
tdp
zy
zx
II
II
z
yy
z
xx
wy
wx
/
/
/
/
y
x
d
d
t
Lim
5757
Vanishing Points
All lines in direction d converge to same point in the image plane -- the vanishing point
Every point in plane is a v.p. for some set of lines
Lines parallel to image plane ( ) vanish at infinity
y
x
d
d
t
Lim
y
x
d
d
t
Lim
What’s a horizon?
5858
Ray Picking
Pick object by picking point on screen
Compute ray from pixel coordinates.
5959
Ray Picking
Transform from World to Screen is:
Inverse:
What Z value?
w
z
y
x
w
z
y
x
W
W
W
W
I
I
I
I
M
w
z
y
x
w
z
y
x
W
W
W
W
I
I
I
I
M
w
z
y
x
w
z
y
x
I
I
I
I
W
W
W
W
1M
w
z
y
x
w
z
y
x
I
I
I
I
W
W
W
W
1M
6060
Ray Picking
Recall that:Points at z=-i stay at z=-i
Points at z=-f stay at z=-f
Depends on screen details, YMMVGeneral idea should translate...
6161
Suggested Reading
Fundamentals of Computer Graphics by Pete Shirley
Chapter 6