viewing - UBC Computer Sciencetmm/courses/314-13/slides/viewing.pdf2 Reading for This Module • FCG...
Transcript of viewing - UBC Computer Sciencetmm/courses/314-13/slides/viewing.pdf2 Reading for This Module • FCG...
![Page 1: viewing - UBC Computer Sciencetmm/courses/314-13/slides/viewing.pdf2 Reading for This Module • FCG Chapter 7 Viewing • FCG Section 6.3.1 Windowing Transforms • RB rest of Chap](https://reader031.fdocuments.us/reader031/viewer/2022030422/5aa961b67f8b9a81188cb366/html5/thumbnails/1.jpg)
University of British Columbia CPSC 314 Computer Graphics
Jan-Apr 2013
Tamara Munzner
http://www.ugrad.cs.ubc.ca/~cs314/Vjan2013
Viewing
![Page 2: viewing - UBC Computer Sciencetmm/courses/314-13/slides/viewing.pdf2 Reading for This Module • FCG Chapter 7 Viewing • FCG Section 6.3.1 Windowing Transforms • RB rest of Chap](https://reader031.fdocuments.us/reader031/viewer/2022030422/5aa961b67f8b9a81188cb366/html5/thumbnails/2.jpg)
2
Reading for This Module
• FCG Chapter 7 Viewing • FCG Section 6.3.1 Windowing Transforms
• RB rest of Chap Viewing • RB rest of App Homogeneous Coords
• RB Chap Selection and Feedback • RB Sec Object Selection Using the Back
Buffer • (in Chap Now That You Now )
![Page 3: viewing - UBC Computer Sciencetmm/courses/314-13/slides/viewing.pdf2 Reading for This Module • FCG Chapter 7 Viewing • FCG Section 6.3.1 Windowing Transforms • RB rest of Chap](https://reader031.fdocuments.us/reader031/viewer/2022030422/5aa961b67f8b9a81188cb366/html5/thumbnails/3.jpg)
3
Viewing
![Page 4: viewing - UBC Computer Sciencetmm/courses/314-13/slides/viewing.pdf2 Reading for This Module • FCG Chapter 7 Viewing • FCG Section 6.3.1 Windowing Transforms • RB rest of Chap](https://reader031.fdocuments.us/reader031/viewer/2022030422/5aa961b67f8b9a81188cb366/html5/thumbnails/4.jpg)
4
Using Transformations • three ways
• modelling transforms • place objects within scene (shared world) • affine transformations
• viewing transforms • place camera • rigid body transformations: rotate, translate
• projection transforms • change type of camera • projective transformation
![Page 5: viewing - UBC Computer Sciencetmm/courses/314-13/slides/viewing.pdf2 Reading for This Module • FCG Chapter 7 Viewing • FCG Section 6.3.1 Windowing Transforms • RB rest of Chap](https://reader031.fdocuments.us/reader031/viewer/2022030422/5aa961b67f8b9a81188cb366/html5/thumbnails/5.jpg)
5
Rendering Pipeline
Scene graph Object geometry
Modelling Transforms
Viewing Transform
Projection Transform
![Page 6: viewing - UBC Computer Sciencetmm/courses/314-13/slides/viewing.pdf2 Reading for This Module • FCG Chapter 7 Viewing • FCG Section 6.3.1 Windowing Transforms • RB rest of Chap](https://reader031.fdocuments.us/reader031/viewer/2022030422/5aa961b67f8b9a81188cb366/html5/thumbnails/6.jpg)
6
Scene graph Object geometry
Modelling Transforms
Viewing Transform
Projection Transform
Rendering Pipeline
• result • all vertices of scene in shared
3D world coordinate system
![Page 7: viewing - UBC Computer Sciencetmm/courses/314-13/slides/viewing.pdf2 Reading for This Module • FCG Chapter 7 Viewing • FCG Section 6.3.1 Windowing Transforms • RB rest of Chap](https://reader031.fdocuments.us/reader031/viewer/2022030422/5aa961b67f8b9a81188cb366/html5/thumbnails/7.jpg)
7
Scene graph Object geometry
Modelling Transforms
Viewing Transform
Projection Transform
Rendering Pipeline
• result • scene vertices in 3D view
(camera) coordinate system
![Page 8: viewing - UBC Computer Sciencetmm/courses/314-13/slides/viewing.pdf2 Reading for This Module • FCG Chapter 7 Viewing • FCG Section 6.3.1 Windowing Transforms • RB rest of Chap](https://reader031.fdocuments.us/reader031/viewer/2022030422/5aa961b67f8b9a81188cb366/html5/thumbnails/8.jpg)
8
Scene graph Object geometry
Modelling Transforms
Viewing Transform
Projection Transform
Rendering Pipeline
• result • 2D screen coordinates of
clipped vertices
![Page 9: viewing - UBC Computer Sciencetmm/courses/314-13/slides/viewing.pdf2 Reading for This Module • FCG Chapter 7 Viewing • FCG Section 6.3.1 Windowing Transforms • RB rest of Chap](https://reader031.fdocuments.us/reader031/viewer/2022030422/5aa961b67f8b9a81188cb366/html5/thumbnails/9.jpg)
9
Viewing and Projection
• need to get from 3D world to 2D image • projection: geometric abstraction
• what eyes or cameras do • two pieces
• viewing transform: • where is the camera, what is it pointing at?
• perspective transform: 3D to 2D • flatten to image
![Page 10: viewing - UBC Computer Sciencetmm/courses/314-13/slides/viewing.pdf2 Reading for This Module • FCG Chapter 7 Viewing • FCG Section 6.3.1 Windowing Transforms • RB rest of Chap](https://reader031.fdocuments.us/reader031/viewer/2022030422/5aa961b67f8b9a81188cb366/html5/thumbnails/10.jpg)
10
Rendering Pipeline
Geometry Database
Model/View Transform. Lighting Perspective
Transform. Clipping
Scan Conversion
Depth Test Texturing Blending
Frame- buffer
![Page 11: viewing - UBC Computer Sciencetmm/courses/314-13/slides/viewing.pdf2 Reading for This Module • FCG Chapter 7 Viewing • FCG Section 6.3.1 Windowing Transforms • RB rest of Chap](https://reader031.fdocuments.us/reader031/viewer/2022030422/5aa961b67f8b9a81188cb366/html5/thumbnails/11.jpg)
11
Rendering Pipeline
Geometry Database
Model/View Transform. Lighting Perspective
Transform. Clipping
Scan Conversion
Depth Test Texturing Blending
Frame- buffer
![Page 12: viewing - UBC Computer Sciencetmm/courses/314-13/slides/viewing.pdf2 Reading for This Module • FCG Chapter 7 Viewing • FCG Section 6.3.1 Windowing Transforms • RB rest of Chap](https://reader031.fdocuments.us/reader031/viewer/2022030422/5aa961b67f8b9a81188cb366/html5/thumbnails/12.jpg)
12
OpenGL Transformation Storage • modeling and viewing stored together
• possible because no intervening operations • perspective stored in separate matrix
• specify which matrix is target of operations • common practice: return to default modelview
mode after doing projection operations glMatrixMode(GL_MODELVIEW); glMatrixMode(GL_PROJECTION);
![Page 13: viewing - UBC Computer Sciencetmm/courses/314-13/slides/viewing.pdf2 Reading for This Module • FCG Chapter 7 Viewing • FCG Section 6.3.1 Windowing Transforms • RB rest of Chap](https://reader031.fdocuments.us/reader031/viewer/2022030422/5aa961b67f8b9a81188cb366/html5/thumbnails/13.jpg)
13
Coordinate Systems • result of a transformation • names
• convenience • animal: leg, head, tail
• standard conventions in graphics pipeline • object/modelling • world • camera/viewing/eye • screen/window • raster/device
![Page 14: viewing - UBC Computer Sciencetmm/courses/314-13/slides/viewing.pdf2 Reading for This Module • FCG Chapter 7 Viewing • FCG Section 6.3.1 Windowing Transforms • RB rest of Chap](https://reader031.fdocuments.us/reader031/viewer/2022030422/5aa961b67f8b9a81188cb366/html5/thumbnails/14.jpg)
14
Projective Rendering Pipeline
OCS - object/model coordinate system
WCS - world coordinate system
VCS - viewing/camera/eye coordinate system
CCS - clipping coordinate system
NDCS - normalized device coordinate system
DCS - device/display/screen coordinate system
OCS O2W VCS
CCS
NDCS
DCS
modeling transformation
viewing transformation
projection transformation
viewport transformation
perspective divide
object world viewing
device
normalized device
clipping
W2V V2C
N2D
C2N
WCS
![Page 15: viewing - UBC Computer Sciencetmm/courses/314-13/slides/viewing.pdf2 Reading for This Module • FCG Chapter 7 Viewing • FCG Section 6.3.1 Windowing Transforms • RB rest of Chap](https://reader031.fdocuments.us/reader031/viewer/2022030422/5aa961b67f8b9a81188cb366/html5/thumbnails/15.jpg)
15
Viewing Transformation
OCS WCS VCS modeling
transformation viewing
transformation
OpenGL ModelView matrix
object world viewing
y
x
VCS
Peye z
y x WCS
y
z OCS
image plane
Mmod Mcam
![Page 16: viewing - UBC Computer Sciencetmm/courses/314-13/slides/viewing.pdf2 Reading for This Module • FCG Chapter 7 Viewing • FCG Section 6.3.1 Windowing Transforms • RB rest of Chap](https://reader031.fdocuments.us/reader031/viewer/2022030422/5aa961b67f8b9a81188cb366/html5/thumbnails/16.jpg)
16
Basic Viewing • starting spot - OpenGL
• camera at world origin • probably inside an object
• y axis is up • looking down negative z axis
• why? RHS with x horizontal, y vertical, z out of screen • translate backward so scene is visible
• move distance d = focal length
• where is camera in P1 template code? • 5 units back, looking down -z axis
![Page 17: viewing - UBC Computer Sciencetmm/courses/314-13/slides/viewing.pdf2 Reading for This Module • FCG Chapter 7 Viewing • FCG Section 6.3.1 Windowing Transforms • RB rest of Chap](https://reader031.fdocuments.us/reader031/viewer/2022030422/5aa961b67f8b9a81188cb366/html5/thumbnails/17.jpg)
17
Convenient Camera Motion
• rotate/translate/scale versus • eye point, gaze/lookat direction, up vector
• demo: Robins transformation, projection
![Page 18: viewing - UBC Computer Sciencetmm/courses/314-13/slides/viewing.pdf2 Reading for This Module • FCG Chapter 7 Viewing • FCG Section 6.3.1 Windowing Transforms • RB rest of Chap](https://reader031.fdocuments.us/reader031/viewer/2022030422/5aa961b67f8b9a81188cb366/html5/thumbnails/18.jpg)
18
OpenGL Viewing Transformation
gluLookAt(ex,ey,ez,lx,ly,lz,ux,uy,uz)
• postmultiplies current matrix, so to be safe: glMatrixMode(GL_MODELVIEW); glLoadIdentity(); gluLookAt(ex,ey,ez,lx,ly,lz,ux,uy,uz) // now ok to do model transformations
• demo: Nate Robins tutorial projection
![Page 19: viewing - UBC Computer Sciencetmm/courses/314-13/slides/viewing.pdf2 Reading for This Module • FCG Chapter 7 Viewing • FCG Section 6.3.1 Windowing Transforms • RB rest of Chap](https://reader031.fdocuments.us/reader031/viewer/2022030422/5aa961b67f8b9a81188cb366/html5/thumbnails/19.jpg)
19
Convenient Camera Motion
• rotate/translate/scale versus • eye point, gaze/lookat direction, up vector
Peye
Pref
up view
eye
lookat y
z
x WCS
![Page 20: viewing - UBC Computer Sciencetmm/courses/314-13/slides/viewing.pdf2 Reading for This Module • FCG Chapter 7 Viewing • FCG Section 6.3.1 Windowing Transforms • RB rest of Chap](https://reader031.fdocuments.us/reader031/viewer/2022030422/5aa961b67f8b9a81188cb366/html5/thumbnails/20.jpg)
20
Placing Camera in World Coords: V2W
• treat camera as if it’s just an object • translate from origin to eye • rotate view vector (lookat – eye) to w axis • rotate around w to bring up into vw-plane
y
z
x WCS
v
u
VCS
Peye w
Pref
up view
eye
lookat
![Page 21: viewing - UBC Computer Sciencetmm/courses/314-13/slides/viewing.pdf2 Reading for This Module • FCG Chapter 7 Viewing • FCG Section 6.3.1 Windowing Transforms • RB rest of Chap](https://reader031.fdocuments.us/reader031/viewer/2022030422/5aa961b67f8b9a81188cb366/html5/thumbnails/21.jpg)
21
Deriving V2W Transformation
• translate origin to eye
!
T =
1 0 0 ex
0 1 0 ey
0 0 1 ez
0 0 0 1
"
#
$ $ $ $
%
&
' ' ' '
y
z
x WCS
v
u
VCS
Peye w
Pref
up view
eye
lookat
![Page 22: viewing - UBC Computer Sciencetmm/courses/314-13/slides/viewing.pdf2 Reading for This Module • FCG Chapter 7 Viewing • FCG Section 6.3.1 Windowing Transforms • RB rest of Chap](https://reader031.fdocuments.us/reader031/viewer/2022030422/5aa961b67f8b9a81188cb366/html5/thumbnails/22.jpg)
22
Deriving V2W Transformation • rotate view vector (lookat – eye) to w axis
• w: normalized opposite of view/gaze vector g
!
w = "ˆ g = "g
g
y
z
x WCS
v
u
VCS
Peye w
Pref
up view
eye
lookat
![Page 23: viewing - UBC Computer Sciencetmm/courses/314-13/slides/viewing.pdf2 Reading for This Module • FCG Chapter 7 Viewing • FCG Section 6.3.1 Windowing Transforms • RB rest of Chap](https://reader031.fdocuments.us/reader031/viewer/2022030422/5aa961b67f8b9a81188cb366/html5/thumbnails/23.jpg)
23
Deriving V2W Transformation • rotate around w to bring up into vw-plane
• u should be perpendicular to vw-plane, thus perpendicular to w and up vector t
• v should be perpendicular to u and w
!
u =t "w
t "w
!
v = w " u
y
z
x WCS
v
u
VCS
Peye w
Pref
up view
eye
lookat
![Page 24: viewing - UBC Computer Sciencetmm/courses/314-13/slides/viewing.pdf2 Reading for This Module • FCG Chapter 7 Viewing • FCG Section 6.3.1 Windowing Transforms • RB rest of Chap](https://reader031.fdocuments.us/reader031/viewer/2022030422/5aa961b67f8b9a81188cb366/html5/thumbnails/24.jpg)
24
Deriving V2W Transformation • rotate from WCS xyz into uvw coordinate system with matrix that has
columns u, v, w
• reminder: rotate from uvw to xyz coord sys with matrix M that has columns u,v,w
!
u =t "w
t "w
!
v = w " u
!
w = "ˆ g = "g
g
!
R =
uxvxwx0
uyvywy0
uzvzwz0
0 0 0 1
"
#
$ $ $ $
%
&
' ' ' '
MV2W=TR
!
T=
1 0 0 ex
0 1 0 ey
0 0 1 ez
0 0 0 1
"
#
$ $ $ $
%
&
' ' ' '
![Page 25: viewing - UBC Computer Sciencetmm/courses/314-13/slides/viewing.pdf2 Reading for This Module • FCG Chapter 7 Viewing • FCG Section 6.3.1 Windowing Transforms • RB rest of Chap](https://reader031.fdocuments.us/reader031/viewer/2022030422/5aa961b67f8b9a81188cb366/html5/thumbnails/25.jpg)
25
V2W vs. W2V
• MV2W=TR
• we derived position of camera as object in world • invert for gluLookAt: go from world to camera!
• MW2V=(MV2W)-1=R-1T-1
• inverse is transpose for orthonormal matrices • inverse is negative for translations
!
T"1 =
1 0 0 "ex
0 1 0 "ey
0 0 1 "ez
0 0 0 1
#
$
% % % %
&
'
( ( ( (
!
R"1 =
ux
uy
uz0
vx
vy
vz0
wxwywz0
0 0 0 1
#
$
% % % %
&
'
( ( ( (
!
T=
1 0 0 ex
0 1 0 ey
0 0 1 ez
0 0 0 1
"
#
$ $ $ $
%
&
' ' ' '
!
R =
uxvxwx0
uyvywy0
uzvzwz0
0 0 0 1
"
#
$ $ $ $
%
&
' ' ' '
![Page 26: viewing - UBC Computer Sciencetmm/courses/314-13/slides/viewing.pdf2 Reading for This Module • FCG Chapter 7 Viewing • FCG Section 6.3.1 Windowing Transforms • RB rest of Chap](https://reader031.fdocuments.us/reader031/viewer/2022030422/5aa961b67f8b9a81188cb366/html5/thumbnails/26.jpg)
26
V2W vs. W2V
• MW2V=(MV2W)-1=R-1T-1
!
Mworld2view
=
ux uy uz 0
vx vy vz 0
wx wy wz 0
0 0 0 1
"
#
$ $ $ $
%
&
' ' ' '
1 0 0 (ex0 1 0 (ey0 0 1 (ez0 0 0 1
"
#
$ $ $ $
%
&
' ' ' '
=
ux uy uz (e •u
vx vy vz (e • v
wx wy wz (e •w
0 0 0 1
"
#
$ $ $ $
%
&
' ' ' '
!
MW 2V
=
ux uy uz "ex # ux + "ey # uy + "ez # uzvx vy vz "ex #vx + "ey #vy + "ez #vzwx wy wz "ex #wx + "ey #wy + "ez #wz
0 0 0 1
$
%
& & & &
'
(
) ) ) )
![Page 27: viewing - UBC Computer Sciencetmm/courses/314-13/slides/viewing.pdf2 Reading for This Module • FCG Chapter 7 Viewing • FCG Section 6.3.1 Windowing Transforms • RB rest of Chap](https://reader031.fdocuments.us/reader031/viewer/2022030422/5aa961b67f8b9a81188cb366/html5/thumbnails/27.jpg)
27
Moving the Camera or the World? • two equivalent operations • move camera one way vs. move world other way
• example • initial OpenGL camera: at origin, looking along -z axis • create a unit square parallel to camera at z = -10 • translate in z by 3 possible in two ways
• camera moves to z = -3 • Note OpenGL models viewing in left-hand coordinates
• camera stays put, but world moves to -7 • resulting image same either way
• possible difference: are lights specified in world or view coordinates?
![Page 28: viewing - UBC Computer Sciencetmm/courses/314-13/slides/viewing.pdf2 Reading for This Module • FCG Chapter 7 Viewing • FCG Section 6.3.1 Windowing Transforms • RB rest of Chap](https://reader031.fdocuments.us/reader031/viewer/2022030422/5aa961b67f8b9a81188cb366/html5/thumbnails/28.jpg)
28
World vs. Camera Coordinates Example
W
a = (1,1)W
a
b = (1,1)C1 = (5,3)W
c = (1,1)C2= (1,3)C1 = (5,5)W
C1
b
C2
c
![Page 29: viewing - UBC Computer Sciencetmm/courses/314-13/slides/viewing.pdf2 Reading for This Module • FCG Chapter 7 Viewing • FCG Section 6.3.1 Windowing Transforms • RB rest of Chap](https://reader031.fdocuments.us/reader031/viewer/2022030422/5aa961b67f8b9a81188cb366/html5/thumbnails/29.jpg)
29
Projections I
![Page 30: viewing - UBC Computer Sciencetmm/courses/314-13/slides/viewing.pdf2 Reading for This Module • FCG Chapter 7 Viewing • FCG Section 6.3.1 Windowing Transforms • RB rest of Chap](https://reader031.fdocuments.us/reader031/viewer/2022030422/5aa961b67f8b9a81188cb366/html5/thumbnails/30.jpg)
30
Pinhole Camera
• ingredients • box, film, hole punch
• result • picture
www.kodak.com
www.pinhole.org
www.debevec.org/Pinhole
![Page 31: viewing - UBC Computer Sciencetmm/courses/314-13/slides/viewing.pdf2 Reading for This Module • FCG Chapter 7 Viewing • FCG Section 6.3.1 Windowing Transforms • RB rest of Chap](https://reader031.fdocuments.us/reader031/viewer/2022030422/5aa961b67f8b9a81188cb366/html5/thumbnails/31.jpg)
31
Pinhole Camera
• theoretical perfect pinhole • light shining through tiny hole into dark space
yields upside-down picture
film plane
perfect pinhole
one ray of projection
![Page 32: viewing - UBC Computer Sciencetmm/courses/314-13/slides/viewing.pdf2 Reading for This Module • FCG Chapter 7 Viewing • FCG Section 6.3.1 Windowing Transforms • RB rest of Chap](https://reader031.fdocuments.us/reader031/viewer/2022030422/5aa961b67f8b9a81188cb366/html5/thumbnails/32.jpg)
32
Pinhole Camera
• non-zero sized hole • blur: rays hit multiple points on film plane
film plane
actual pinhole
multiple rays of projection
![Page 33: viewing - UBC Computer Sciencetmm/courses/314-13/slides/viewing.pdf2 Reading for This Module • FCG Chapter 7 Viewing • FCG Section 6.3.1 Windowing Transforms • RB rest of Chap](https://reader031.fdocuments.us/reader031/viewer/2022030422/5aa961b67f8b9a81188cb366/html5/thumbnails/33.jpg)
33
Real Cameras • pinhole camera has small aperture (lens
opening) • minimize blur
• problem: hard to get enough light to expose the film
• solution: lens • permits larger apertures • permits changing distance to film plane
without actually moving it • cost: limited depth of field where image is
in focus
aperture
lens depth
of field
http://en.wikipedia.org/wiki/Image:DOF-ShallowDepthofField.jpg
![Page 34: viewing - UBC Computer Sciencetmm/courses/314-13/slides/viewing.pdf2 Reading for This Module • FCG Chapter 7 Viewing • FCG Section 6.3.1 Windowing Transforms • RB rest of Chap](https://reader031.fdocuments.us/reader031/viewer/2022030422/5aa961b67f8b9a81188cb366/html5/thumbnails/34.jpg)
34
Graphics Cameras
• real pinhole camera: image inverted
image plane
eye point
computer graphics camera: convenient equivalent
image plane
eye point
center of projection
![Page 35: viewing - UBC Computer Sciencetmm/courses/314-13/slides/viewing.pdf2 Reading for This Module • FCG Chapter 7 Viewing • FCG Section 6.3.1 Windowing Transforms • RB rest of Chap](https://reader031.fdocuments.us/reader031/viewer/2022030422/5aa961b67f8b9a81188cb366/html5/thumbnails/35.jpg)
35
General Projection
• image plane need not be perpendicular to view plane
image plane
eye point
image plane
eye point
![Page 36: viewing - UBC Computer Sciencetmm/courses/314-13/slides/viewing.pdf2 Reading for This Module • FCG Chapter 7 Viewing • FCG Section 6.3.1 Windowing Transforms • RB rest of Chap](https://reader031.fdocuments.us/reader031/viewer/2022030422/5aa961b67f8b9a81188cb366/html5/thumbnails/36.jpg)
36
Perspective Projection
• our camera must model perspective
![Page 37: viewing - UBC Computer Sciencetmm/courses/314-13/slides/viewing.pdf2 Reading for This Module • FCG Chapter 7 Viewing • FCG Section 6.3.1 Windowing Transforms • RB rest of Chap](https://reader031.fdocuments.us/reader031/viewer/2022030422/5aa961b67f8b9a81188cb366/html5/thumbnails/37.jpg)
37
Perspective Projection
• our camera must model perspective
![Page 38: viewing - UBC Computer Sciencetmm/courses/314-13/slides/viewing.pdf2 Reading for This Module • FCG Chapter 7 Viewing • FCG Section 6.3.1 Windowing Transforms • RB rest of Chap](https://reader031.fdocuments.us/reader031/viewer/2022030422/5aa961b67f8b9a81188cb366/html5/thumbnails/38.jpg)
38
Projective Transformations
• planar geometric projections • planar: onto a plane • geometric: using straight lines • projections: 3D -> 2D
• aka projective mappings
• counterexamples?
![Page 39: viewing - UBC Computer Sciencetmm/courses/314-13/slides/viewing.pdf2 Reading for This Module • FCG Chapter 7 Viewing • FCG Section 6.3.1 Windowing Transforms • RB rest of Chap](https://reader031.fdocuments.us/reader031/viewer/2022030422/5aa961b67f8b9a81188cb366/html5/thumbnails/39.jpg)
39
Projective Transformations • properties • lines mapped to lines and triangles to triangles • parallel lines do NOT remain parallel
• e.g. rails vanishing at infinity
• affine combinations are NOT preserved • e.g. center of a line does not map to center of
projected line (perspective foreshortening)
![Page 40: viewing - UBC Computer Sciencetmm/courses/314-13/slides/viewing.pdf2 Reading for This Module • FCG Chapter 7 Viewing • FCG Section 6.3.1 Windowing Transforms • RB rest of Chap](https://reader031.fdocuments.us/reader031/viewer/2022030422/5aa961b67f8b9a81188cb366/html5/thumbnails/40.jpg)
40
Perspective Projection
• project all geometry • through common center of projection (eye point) • onto an image plane
x z x z
y
x
-z
![Page 41: viewing - UBC Computer Sciencetmm/courses/314-13/slides/viewing.pdf2 Reading for This Module • FCG Chapter 7 Viewing • FCG Section 6.3.1 Windowing Transforms • RB rest of Chap](https://reader031.fdocuments.us/reader031/viewer/2022030422/5aa961b67f8b9a81188cb366/html5/thumbnails/41.jpg)
41
Perspective Projection
how tall should this bunny be?
projection plane
center of projection (eye point)
![Page 42: viewing - UBC Computer Sciencetmm/courses/314-13/slides/viewing.pdf2 Reading for This Module • FCG Chapter 7 Viewing • FCG Section 6.3.1 Windowing Transforms • RB rest of Chap](https://reader031.fdocuments.us/reader031/viewer/2022030422/5aa961b67f8b9a81188cb366/html5/thumbnails/42.jpg)
42
Basic Perspective Projection
similar triangles
z
P(x,y,z)
P(x’,y’,z’)
z’=d
y
• nonuniform foreshortening • not affine
but
!
z'= d
![Page 43: viewing - UBC Computer Sciencetmm/courses/314-13/slides/viewing.pdf2 Reading for This Module • FCG Chapter 7 Viewing • FCG Section 6.3.1 Windowing Transforms • RB rest of Chap](https://reader031.fdocuments.us/reader031/viewer/2022030422/5aa961b67f8b9a81188cb366/html5/thumbnails/43.jpg)
43
Perspective Projection • desired result for a point [x, y, z, 1]T projected
onto the view plane:
• what could a matrix look like to do this?
dzdz
y
z
dyy
dz
x
z
dxx
z
y
d
y
z
x
d
x
==!
==!
=
==
',','
',
'
![Page 44: viewing - UBC Computer Sciencetmm/courses/314-13/slides/viewing.pdf2 Reading for This Module • FCG Chapter 7 Viewing • FCG Section 6.3.1 Windowing Transforms • RB rest of Chap](https://reader031.fdocuments.us/reader031/viewer/2022030422/5aa961b67f8b9a81188cb366/html5/thumbnails/44.jpg)
44
Simple Perspective Projection Matrix
!!!!!!!
"
#
$$$$$$$
%
&
d
dz
y
dz
x
/
/
![Page 45: viewing - UBC Computer Sciencetmm/courses/314-13/slides/viewing.pdf2 Reading for This Module • FCG Chapter 7 Viewing • FCG Section 6.3.1 Windowing Transforms • RB rest of Chap](https://reader031.fdocuments.us/reader031/viewer/2022030422/5aa961b67f8b9a81188cb366/html5/thumbnails/45.jpg)
45
Simple Perspective Projection Matrix
!!!!!!!
"
#
$$$$$$$
%
&
d
dz
y
dz
x
/
/ is homogenized version of where w = z/d
!!!!
"
#
$$$$
%
&
dz
z
y
x
/
![Page 46: viewing - UBC Computer Sciencetmm/courses/314-13/slides/viewing.pdf2 Reading for This Module • FCG Chapter 7 Viewing • FCG Section 6.3.1 Windowing Transforms • RB rest of Chap](https://reader031.fdocuments.us/reader031/viewer/2022030422/5aa961b67f8b9a81188cb366/html5/thumbnails/46.jpg)
46
Simple Perspective Projection Matrix
!!!!
"
#
$$$$
%
&
!!!!
"
#
$$$$
%
&
=
!!!!
"
#
$$$$
%
&
10100
0100
0010
0001
/
z
y
x
ddz
z
y
x!!!!!!!
"
#
$$$$$$$
%
&
d
dz
y
dz
x
/
/ is homogenized version of where w = z/d
!!!!
"
#
$$$$
%
&
dz
z
y
x
/
![Page 47: viewing - UBC Computer Sciencetmm/courses/314-13/slides/viewing.pdf2 Reading for This Module • FCG Chapter 7 Viewing • FCG Section 6.3.1 Windowing Transforms • RB rest of Chap](https://reader031.fdocuments.us/reader031/viewer/2022030422/5aa961b67f8b9a81188cb366/html5/thumbnails/47.jpg)
47
Perspective Projection
• expressible with 4x4 homogeneous matrix • use previously untouched bottom row
• perspective projection is irreversible • many 3D points can be mapped to same
(x, y, d) on the projection plane • no way to retrieve the unique z values
![Page 48: viewing - UBC Computer Sciencetmm/courses/314-13/slides/viewing.pdf2 Reading for This Module • FCG Chapter 7 Viewing • FCG Section 6.3.1 Windowing Transforms • RB rest of Chap](https://reader031.fdocuments.us/reader031/viewer/2022030422/5aa961b67f8b9a81188cb366/html5/thumbnails/48.jpg)
48
Moving COP to Infinity
• as COP moves away, lines approach parallel • when COP at infinity, orthographic view
![Page 49: viewing - UBC Computer Sciencetmm/courses/314-13/slides/viewing.pdf2 Reading for This Module • FCG Chapter 7 Viewing • FCG Section 6.3.1 Windowing Transforms • RB rest of Chap](https://reader031.fdocuments.us/reader031/viewer/2022030422/5aa961b67f8b9a81188cb366/html5/thumbnails/49.jpg)
49
Orthographic Camera Projection • camera’s back plane
parallel to lens • infinite focal length • no perspective
convergence
• just throw away z values
!!!
"
#
$$$
%
&
=
!!!
"
#
$$$
%
&
0
y
x
z
y
x
p
p
p
!!!!
"
#
$$$$
%
&
!!!!
"
#
$$$$
%
&
=
!!!!
"
#
$$$$
%
&
11000
0000
0010
0001
1
z
y
x
z
y
x
p
p
p
![Page 50: viewing - UBC Computer Sciencetmm/courses/314-13/slides/viewing.pdf2 Reading for This Module • FCG Chapter 7 Viewing • FCG Section 6.3.1 Windowing Transforms • RB rest of Chap](https://reader031.fdocuments.us/reader031/viewer/2022030422/5aa961b67f8b9a81188cb366/html5/thumbnails/50.jpg)
50
Perspective to Orthographic • transformation of space • center of projection moves to infinity • view volume transformed
• from frustum (truncated pyramid) to parallelepiped (box)
-z
x
-z
x
Frustum Parallelepiped
![Page 51: viewing - UBC Computer Sciencetmm/courses/314-13/slides/viewing.pdf2 Reading for This Module • FCG Chapter 7 Viewing • FCG Section 6.3.1 Windowing Transforms • RB rest of Chap](https://reader031.fdocuments.us/reader031/viewer/2022030422/5aa961b67f8b9a81188cb366/html5/thumbnails/51.jpg)
51
View Volumes • specifies field-of-view, used for clipping • restricts domain of z stored for visibility test
z
perspective view volume orthographic view volume
x=left
x=right
y=top
y=bottom z=-near z=-far x VCS x
z
VCS
y y
x=left y=top
x=right
z=-far z=-near y=bottom
![Page 52: viewing - UBC Computer Sciencetmm/courses/314-13/slides/viewing.pdf2 Reading for This Module • FCG Chapter 7 Viewing • FCG Section 6.3.1 Windowing Transforms • RB rest of Chap](https://reader031.fdocuments.us/reader031/viewer/2022030422/5aa961b67f8b9a81188cb366/html5/thumbnails/52.jpg)
52
Canonical View Volumes • standardized viewing volume representation
perspective orthographic orthogonal parallel
x or y
-z
1
-1
-1 front plane
back plane
x or y
-z front plane
back plane
x or y = +/- z
![Page 53: viewing - UBC Computer Sciencetmm/courses/314-13/slides/viewing.pdf2 Reading for This Module • FCG Chapter 7 Viewing • FCG Section 6.3.1 Windowing Transforms • RB rest of Chap](https://reader031.fdocuments.us/reader031/viewer/2022030422/5aa961b67f8b9a81188cb366/html5/thumbnails/53.jpg)
53
Why Canonical View Volumes?
• permits standardization • clipping
• easier to determine if an arbitrary point is enclosed in volume with canonical view volume vs. clipping to six arbitrary planes
• rendering • projection and rasterization algorithms can be
reused
![Page 54: viewing - UBC Computer Sciencetmm/courses/314-13/slides/viewing.pdf2 Reading for This Module • FCG Chapter 7 Viewing • FCG Section 6.3.1 Windowing Transforms • RB rest of Chap](https://reader031.fdocuments.us/reader031/viewer/2022030422/5aa961b67f8b9a81188cb366/html5/thumbnails/54.jpg)
54
Normalized Device Coordinates
• convention • viewing frustum mapped to specific
parallelepiped • Normalized Device Coordinates (NDC) • same as clipping coords
• only objects inside the parallelepiped get rendered
• which parallelepiped? • depends on rendering system
![Page 55: viewing - UBC Computer Sciencetmm/courses/314-13/slides/viewing.pdf2 Reading for This Module • FCG Chapter 7 Viewing • FCG Section 6.3.1 Windowing Transforms • RB rest of Chap](https://reader031.fdocuments.us/reader031/viewer/2022030422/5aa961b67f8b9a81188cb366/html5/thumbnails/55.jpg)
55
Normalized Device Coordinates
left/right x =+/- 1, top/bottom y =+/- 1, near/far z =+/- 1
-z
x
Frustum
z=-n z=-f
right
left z
x
x= -1 z=1
x=1
Camera coordinates NDC
z= -1
![Page 56: viewing - UBC Computer Sciencetmm/courses/314-13/slides/viewing.pdf2 Reading for This Module • FCG Chapter 7 Viewing • FCG Section 6.3.1 Windowing Transforms • RB rest of Chap](https://reader031.fdocuments.us/reader031/viewer/2022030422/5aa961b67f8b9a81188cb366/html5/thumbnails/56.jpg)
56
Understanding Z
• z axis flip changes coord system handedness • RHS before projection (eye/view coords) • LHS after projection (clip, norm device coords)
x
z
VCS
y x=left
y=top
x=right
z=-far z=-near y=bottom
x
z
NDCS
y
(-1,-1,-1)
(1,1,1)
![Page 57: viewing - UBC Computer Sciencetmm/courses/314-13/slides/viewing.pdf2 Reading for This Module • FCG Chapter 7 Viewing • FCG Section 6.3.1 Windowing Transforms • RB rest of Chap](https://reader031.fdocuments.us/reader031/viewer/2022030422/5aa961b67f8b9a81188cb366/html5/thumbnails/57.jpg)
57
Understanding Z near, far always positive in OpenGL calls glOrtho(left,right,bot,top,near,far); glFrustum(left,right,bot,top,near,far); glPerspective(fovy,aspect,near,far);
orthographic view volume
x
z
VCS
y x=left
y=top
x=right
z=-far z=-near y=bottom
perspective view volume
x=left
x=right
y=top
y=bottom z=-near z=-far x VCS
y
![Page 58: viewing - UBC Computer Sciencetmm/courses/314-13/slides/viewing.pdf2 Reading for This Module • FCG Chapter 7 Viewing • FCG Section 6.3.1 Windowing Transforms • RB rest of Chap](https://reader031.fdocuments.us/reader031/viewer/2022030422/5aa961b67f8b9a81188cb366/html5/thumbnails/58.jpg)
58
Understanding Z
• why near and far plane? • near plane:
• avoid singularity (division by zero, or very small numbers)
• far plane: • store depth in fixed-point representation
(integer), thus have to have fixed range of values (0…1)
• avoid/reduce numerical precision artifacts for distant objects
![Page 59: viewing - UBC Computer Sciencetmm/courses/314-13/slides/viewing.pdf2 Reading for This Module • FCG Chapter 7 Viewing • FCG Section 6.3.1 Windowing Transforms • RB rest of Chap](https://reader031.fdocuments.us/reader031/viewer/2022030422/5aa961b67f8b9a81188cb366/html5/thumbnails/59.jpg)
59
Orthographic Derivation
• scale, translate, reflect for new coord sys
x
z
VCS
y x=left
y=top
x=right
z=-far z=-near y=bottom
x
z
NDCS
y
(-1,-1,-1)
(1,1,1)
![Page 60: viewing - UBC Computer Sciencetmm/courses/314-13/slides/viewing.pdf2 Reading for This Module • FCG Chapter 7 Viewing • FCG Section 6.3.1 Windowing Transforms • RB rest of Chap](https://reader031.fdocuments.us/reader031/viewer/2022030422/5aa961b67f8b9a81188cb366/html5/thumbnails/60.jpg)
60
Orthographic Derivation
• scale, translate, reflect for new coord sys
x
z
VCS
y x=left
y=top
x=right
z=-far z=-near y=bottom
x
z
NDCS
y
(-1,-1,-1)
(1,1,1)
byay +!='1'
1'
!="=
="=
yboty
ytopy
![Page 61: viewing - UBC Computer Sciencetmm/courses/314-13/slides/viewing.pdf2 Reading for This Module • FCG Chapter 7 Viewing • FCG Section 6.3.1 Windowing Transforms • RB rest of Chap](https://reader031.fdocuments.us/reader031/viewer/2022030422/5aa961b67f8b9a81188cb366/html5/thumbnails/61.jpg)
61
Orthographic Derivation
• scale, translate, reflect for new coord sys
byay +!='1'
1'
!="=
="=
yboty
ytopy
bottop
bottopb
bottop
topbottopb
bottop
topb
btopbottop
!
!!=
!
"!!=
!
"!=
+!
=
2)(
21
21
bbota
btopa
+!="
+!=
1
1
bottopa
topbota
topabota
botatopa
botabtopab
!=
+!=
"!!"!=!!
"!!="!
"!!="!=
2
)(2
)()1(1
11
1,1
![Page 62: viewing - UBC Computer Sciencetmm/courses/314-13/slides/viewing.pdf2 Reading for This Module • FCG Chapter 7 Viewing • FCG Section 6.3.1 Windowing Transforms • RB rest of Chap](https://reader031.fdocuments.us/reader031/viewer/2022030422/5aa961b67f8b9a81188cb366/html5/thumbnails/62.jpg)
62
Orthographic Derivation
• scale, translate, reflect for new coord sys
x
z
VCS
y x=left
y=top
x=right
z=-far z=-near y=bottom
byay +!='1'
1'
!="=
="=
yboty
ytopy
bottop
bottopb
bottopa
!
+!=
!=
2
same idea for right/left, far/near
![Page 63: viewing - UBC Computer Sciencetmm/courses/314-13/slides/viewing.pdf2 Reading for This Module • FCG Chapter 7 Viewing • FCG Section 6.3.1 Windowing Transforms • RB rest of Chap](https://reader031.fdocuments.us/reader031/viewer/2022030422/5aa961b67f8b9a81188cb366/html5/thumbnails/63.jpg)
63
Orthographic Derivation
• scale, translate, reflect for new coord sys
P
nearfar
nearfar
nearfar
bottop
bottop
bottop
leftright
leftright
leftright
P
!!!!!!!!!!
"
#
$$$$$$$$$$
%
&
'
+'
'
'
'
+'
'
'
+'
'
=
1000
200
02
0
002
'
![Page 64: viewing - UBC Computer Sciencetmm/courses/314-13/slides/viewing.pdf2 Reading for This Module • FCG Chapter 7 Viewing • FCG Section 6.3.1 Windowing Transforms • RB rest of Chap](https://reader031.fdocuments.us/reader031/viewer/2022030422/5aa961b67f8b9a81188cb366/html5/thumbnails/64.jpg)
64
Orthographic Derivation
• scale, translate, reflect for new coord sys
P
nearfar
nearfar
nearfar
bottop
bottop
bottop
leftright
leftright
leftright
P
!!!!!!!!!!
"
#
$$$$$$$$$$
%
&
'
+'
'
'
'
+'
'
'
+'
'
=
1000
200
02
0
002
'
![Page 65: viewing - UBC Computer Sciencetmm/courses/314-13/slides/viewing.pdf2 Reading for This Module • FCG Chapter 7 Viewing • FCG Section 6.3.1 Windowing Transforms • RB rest of Chap](https://reader031.fdocuments.us/reader031/viewer/2022030422/5aa961b67f8b9a81188cb366/html5/thumbnails/65.jpg)
65
Orthographic Derivation
• scale, translate, reflect for new coord sys
P
nearfar
nearfar
nearfar
bottop
bottop
bottop
leftright
leftright
leftright
P
!!!!!!!!!!
"
#
$$$$$$$$$$
%
&
'
+'
'
'
'
+'
'
'
+'
'
=
1000
200
02
0
002
'
![Page 66: viewing - UBC Computer Sciencetmm/courses/314-13/slides/viewing.pdf2 Reading for This Module • FCG Chapter 7 Viewing • FCG Section 6.3.1 Windowing Transforms • RB rest of Chap](https://reader031.fdocuments.us/reader031/viewer/2022030422/5aa961b67f8b9a81188cb366/html5/thumbnails/66.jpg)
66
Orthographic Derivation
• scale, translate, reflect for new coord sys
P
nearfar
nearfar
nearfar
bottop
bottop
bottop
leftright
leftright
leftright
P
!!!!!!!!!!
"
#
$$$$$$$$$$
%
&
'
+'
'
'
'
+'
'
'
+'
'
=
1000
200
02
0
002
'
![Page 67: viewing - UBC Computer Sciencetmm/courses/314-13/slides/viewing.pdf2 Reading for This Module • FCG Chapter 7 Viewing • FCG Section 6.3.1 Windowing Transforms • RB rest of Chap](https://reader031.fdocuments.us/reader031/viewer/2022030422/5aa961b67f8b9a81188cb366/html5/thumbnails/67.jpg)
67
Orthographic OpenGL
glMatrixMode(GL_PROJECTION); glLoadIdentity(); glOrtho(left,right,bot,top,near,far);
![Page 68: viewing - UBC Computer Sciencetmm/courses/314-13/slides/viewing.pdf2 Reading for This Module • FCG Chapter 7 Viewing • FCG Section 6.3.1 Windowing Transforms • RB rest of Chap](https://reader031.fdocuments.us/reader031/viewer/2022030422/5aa961b67f8b9a81188cb366/html5/thumbnails/68.jpg)
68
Demo
• Brown applets: viewing techniques • parallel/orthographic cameras • projection cameras
• http://www.cs.brown.edu/exploratories/freeSoftware/catalogs/viewing_techniques.html
![Page 69: viewing - UBC Computer Sciencetmm/courses/314-13/slides/viewing.pdf2 Reading for This Module • FCG Chapter 7 Viewing • FCG Section 6.3.1 Windowing Transforms • RB rest of Chap](https://reader031.fdocuments.us/reader031/viewer/2022030422/5aa961b67f8b9a81188cb366/html5/thumbnails/69.jpg)
69
Projections II
![Page 70: viewing - UBC Computer Sciencetmm/courses/314-13/slides/viewing.pdf2 Reading for This Module • FCG Chapter 7 Viewing • FCG Section 6.3.1 Windowing Transforms • RB rest of Chap](https://reader031.fdocuments.us/reader031/viewer/2022030422/5aa961b67f8b9a81188cb366/html5/thumbnails/70.jpg)
70
Asymmetric Frusta
• our formulation allows asymmetry • why bother?
-z
x
Frustum right
left -z
x
Frustum
z=-n z=-f
right
left
![Page 71: viewing - UBC Computer Sciencetmm/courses/314-13/slides/viewing.pdf2 Reading for This Module • FCG Chapter 7 Viewing • FCG Section 6.3.1 Windowing Transforms • RB rest of Chap](https://reader031.fdocuments.us/reader031/viewer/2022030422/5aa961b67f8b9a81188cb366/html5/thumbnails/71.jpg)
71
Asymmetric Frusta
• our formulation allows asymmetry • why bother? binocular stereo
• view vector not perpendicular to view plane
Right Eye
Left Eye
![Page 72: viewing - UBC Computer Sciencetmm/courses/314-13/slides/viewing.pdf2 Reading for This Module • FCG Chapter 7 Viewing • FCG Section 6.3.1 Windowing Transforms • RB rest of Chap](https://reader031.fdocuments.us/reader031/viewer/2022030422/5aa961b67f8b9a81188cb366/html5/thumbnails/72.jpg)
72
Simpler Formulation
• left, right, bottom, top, near, far • nonintuitive • often overkill
• look through window center • symmetric frustum
• constraints • left = -right, bottom = -top
![Page 73: viewing - UBC Computer Sciencetmm/courses/314-13/slides/viewing.pdf2 Reading for This Module • FCG Chapter 7 Viewing • FCG Section 6.3.1 Windowing Transforms • RB rest of Chap](https://reader031.fdocuments.us/reader031/viewer/2022030422/5aa961b67f8b9a81188cb366/html5/thumbnails/73.jpg)
73
Field-of-View Formulation
• FOV in one direction + aspect ratio (w/h) • determines FOV in other direction • also set near, far (reasonably intuitive)
-z
x
Frustum
z=-n z=-f
α fovx/2
fovy/2 h
w
![Page 74: viewing - UBC Computer Sciencetmm/courses/314-13/slides/viewing.pdf2 Reading for This Module • FCG Chapter 7 Viewing • FCG Section 6.3.1 Windowing Transforms • RB rest of Chap](https://reader031.fdocuments.us/reader031/viewer/2022030422/5aa961b67f8b9a81188cb366/html5/thumbnails/74.jpg)
74
Perspective OpenGL
glMatrixMode(GL_PROJECTION); glLoadIdentity(); glFrustum(left,right,bot,top,near,far); or glPerspective(fovy,aspect,near,far);
![Page 75: viewing - UBC Computer Sciencetmm/courses/314-13/slides/viewing.pdf2 Reading for This Module • FCG Chapter 7 Viewing • FCG Section 6.3.1 Windowing Transforms • RB rest of Chap](https://reader031.fdocuments.us/reader031/viewer/2022030422/5aa961b67f8b9a81188cb366/html5/thumbnails/75.jpg)
75
Demo: Frustum vs. FOV
• Nate Robins tutorial (take 2): • http://www.xmission.com/~nate/tutors.html
![Page 76: viewing - UBC Computer Sciencetmm/courses/314-13/slides/viewing.pdf2 Reading for This Module • FCG Chapter 7 Viewing • FCG Section 6.3.1 Windowing Transforms • RB rest of Chap](https://reader031.fdocuments.us/reader031/viewer/2022030422/5aa961b67f8b9a81188cb366/html5/thumbnails/76.jpg)
76
Projective Rendering Pipeline
OCS - object/model coordinate system
WCS - world coordinate system
VCS - viewing/camera/eye coordinate system
CCS - clipping coordinate system
NDCS - normalized device coordinate system
DCS - device/display/screen coordinate system
OCS O2W VCS
CCS
NDCS
DCS
modeling transformation
viewing transformation
projection transformation
viewport transformation
perspective divide
object world viewing
device
normalized device
clipping
W2V V2C
N2D
C2N
WCS
![Page 77: viewing - UBC Computer Sciencetmm/courses/314-13/slides/viewing.pdf2 Reading for This Module • FCG Chapter 7 Viewing • FCG Section 6.3.1 Windowing Transforms • RB rest of Chap](https://reader031.fdocuments.us/reader031/viewer/2022030422/5aa961b67f8b9a81188cb366/html5/thumbnails/77.jpg)
77
Projection Warp
• warp perspective view volume to orthogonal view volume
• render all scenes with orthographic projection! • aka perspective warp
Z
x
z=α z=d
Z
x
z=0 z=d
![Page 78: viewing - UBC Computer Sciencetmm/courses/314-13/slides/viewing.pdf2 Reading for This Module • FCG Chapter 7 Viewing • FCG Section 6.3.1 Windowing Transforms • RB rest of Chap](https://reader031.fdocuments.us/reader031/viewer/2022030422/5aa961b67f8b9a81188cb366/html5/thumbnails/78.jpg)
78
Perspective Warp • perspective viewing frustum transformed to
cube • orthographic rendering of cube produces same
image as perspective rendering of original frustum
![Page 79: viewing - UBC Computer Sciencetmm/courses/314-13/slides/viewing.pdf2 Reading for This Module • FCG Chapter 7 Viewing • FCG Section 6.3.1 Windowing Transforms • RB rest of Chap](https://reader031.fdocuments.us/reader031/viewer/2022030422/5aa961b67f8b9a81188cb366/html5/thumbnails/79.jpg)
79
Predistortion
![Page 80: viewing - UBC Computer Sciencetmm/courses/314-13/slides/viewing.pdf2 Reading for This Module • FCG Chapter 7 Viewing • FCG Section 6.3.1 Windowing Transforms • RB rest of Chap](https://reader031.fdocuments.us/reader031/viewer/2022030422/5aa961b67f8b9a81188cb366/html5/thumbnails/80.jpg)
80
Projective Rendering Pipeline
OCS - object/model coordinate system
WCS - world coordinate system
VCS - viewing/camera/eye coordinate system
CCS - clipping coordinate system
NDCS - normalized device coordinate system
DCS - device/display/screen coordinate system
OCS O2W VCS
CCS
NDCS
DCS
modeling transformation
viewing transformation
projection transformation
viewport transformation
perspective divide
object world viewing
device
normalized device
clipping
W2V V2C
N2D
C2N
WCS
![Page 81: viewing - UBC Computer Sciencetmm/courses/314-13/slides/viewing.pdf2 Reading for This Module • FCG Chapter 7 Viewing • FCG Section 6.3.1 Windowing Transforms • RB rest of Chap](https://reader031.fdocuments.us/reader031/viewer/2022030422/5aa961b67f8b9a81188cb366/html5/thumbnails/81.jpg)
81
Separate Warp From Homogenization
• warp requires only standard matrix multiply • distort such that orthographic projection of distorted
objects is desired persp projection • w is changed
• clip after warp, before divide • division by w: homogenization
CCS NDCS
alter w / w
VCS projection
transformation
viewing normalized device
clipping
perspective division
V2C C2N
![Page 82: viewing - UBC Computer Sciencetmm/courses/314-13/slides/viewing.pdf2 Reading for This Module • FCG Chapter 7 Viewing • FCG Section 6.3.1 Windowing Transforms • RB rest of Chap](https://reader031.fdocuments.us/reader031/viewer/2022030422/5aa961b67f8b9a81188cb366/html5/thumbnails/82.jpg)
82
Perspective Divide Example
• specific example • assume image plane at z = -1
• a point [x,y,z,1]T projects to [-x/z,-y/z,-z/z,1]T ≡ [x,y,z,-z]T
-z
!!!!
"
#
$$$$
%
&
1
z
y
x
!!!!
"
#
$$$$
%
&
' z
z
y
x
![Page 83: viewing - UBC Computer Sciencetmm/courses/314-13/slides/viewing.pdf2 Reading for This Module • FCG Chapter 7 Viewing • FCG Section 6.3.1 Windowing Transforms • RB rest of Chap](https://reader031.fdocuments.us/reader031/viewer/2022030422/5aa961b67f8b9a81188cb366/html5/thumbnails/83.jpg)
83
Perspective Divide Example
!!!!
"
#
$$$$
%
&
'
'
'
(
!!!!
"
#
$$$$
%
&
'
=
!!!!
"
#
$$$$
%
&
)
!!!!
"
#
$$$$
%
&
'
=
*****
+
,
-----
.
/
!!!!
"
#
$$$$
%
&
1
1
/
/
10100
0100
0010
0001
1
zy
zx
z
z
y
x
z
y
x
z
y
x
T
alter w / w
projection transformation
perspective division
• after homogenizing, once again w=1
![Page 84: viewing - UBC Computer Sciencetmm/courses/314-13/slides/viewing.pdf2 Reading for This Module • FCG Chapter 7 Viewing • FCG Section 6.3.1 Windowing Transforms • RB rest of Chap](https://reader031.fdocuments.us/reader031/viewer/2022030422/5aa961b67f8b9a81188cb366/html5/thumbnails/84.jpg)
Perspective Normalization • matrix formulation
• warp and homogenization both preserve relative depth (z coordinate)
!!!!!!
"
#
$$$$$$
%
&
'(
)*+
,
-
.-=
!!!!
"
#
$$$$
%
&
!!!!!!
"
#
$$$$$$
%
&
-
.-
-
d
z
d
dz
y
x
z
y
x
d
d
d
d
d
/
/
/
/
/
)(
101
00
00
0010
0001
!!!!!!
"
#
$$$$$$
%
&
'(
)*+
,-
-
=
!!!
"
#
$$$
%
&
zd
ddz
ydz
x
z
y
x
p
p
p
.
.1
/
/
2
![Page 85: viewing - UBC Computer Sciencetmm/courses/314-13/slides/viewing.pdf2 Reading for This Module • FCG Chapter 7 Viewing • FCG Section 6.3.1 Windowing Transforms • RB rest of Chap](https://reader031.fdocuments.us/reader031/viewer/2022030422/5aa961b67f8b9a81188cb366/html5/thumbnails/85.jpg)
85
Demo
• Brown applets: viewing techniques • parallel/orthographic cameras • projection cameras
• http://www.cs.brown.edu/exploratories/freeSoftware/catalogs/viewing_techniques.html
![Page 86: viewing - UBC Computer Sciencetmm/courses/314-13/slides/viewing.pdf2 Reading for This Module • FCG Chapter 7 Viewing • FCG Section 6.3.1 Windowing Transforms • RB rest of Chap](https://reader031.fdocuments.us/reader031/viewer/2022030422/5aa961b67f8b9a81188cb366/html5/thumbnails/86.jpg)
86
Perspective To NDCS Derivation
x
z
NDCS
y
(-1,-1,-1)
(1,1,1) x=left
x=right
y=top
y=bottom z=-near z=-far x
VCS
y
z
![Page 87: viewing - UBC Computer Sciencetmm/courses/314-13/slides/viewing.pdf2 Reading for This Module • FCG Chapter 7 Viewing • FCG Section 6.3.1 Windowing Transforms • RB rest of Chap](https://reader031.fdocuments.us/reader031/viewer/2022030422/5aa961b67f8b9a81188cb366/html5/thumbnails/87.jpg)
87
Perspective Derivation
simple example earlier:
complete: shear, scale, projection-normalization !
x '
y '
z'
w '
"
#
$ $ $ $
%
&
' ' ' '
=
1 0 0 0
0 1 0 0
0 0 1 0
0 0 1/d 0
"
#
$ $ $ $
%
&
' ' ' '
x
y
z
1
"
#
$ $ $ $
%
&
' ' ' '
!
" x
" y
" z
" w
#
$
% % % %
&
'
( ( ( (
=
E 0 A 0
0 F B 0
0 0 C D
0 0 )1 0
#
$
% % % %
&
'
( ( ( (
x
y
z
1
#
$
% % % %
&
'
( ( ( (
![Page 88: viewing - UBC Computer Sciencetmm/courses/314-13/slides/viewing.pdf2 Reading for This Module • FCG Chapter 7 Viewing • FCG Section 6.3.1 Windowing Transforms • RB rest of Chap](https://reader031.fdocuments.us/reader031/viewer/2022030422/5aa961b67f8b9a81188cb366/html5/thumbnails/88.jpg)
88
Perspective Derivation
earlier:
complete: shear, scale, projection-normalization !
x '
y '
z'
w '
"
#
$ $ $ $
%
&
' ' ' '
=
1 0 0 0
0 1 0 0
0 0 1 0
0 0 1/d 0
"
#
$ $ $ $
%
&
' ' ' '
x
y
z
1
"
#
$ $ $ $
%
&
' ' ' '
!
" x
" y
" z
" w
#
$
% % % %
&
'
( ( ( (
=
E 0 A 0
0 F B 0
0 0 C D
0 0 )1 0
#
$
% % % %
&
'
( ( ( (
x
y
z
1
#
$
% % % %
&
'
( ( ( (
![Page 89: viewing - UBC Computer Sciencetmm/courses/314-13/slides/viewing.pdf2 Reading for This Module • FCG Chapter 7 Viewing • FCG Section 6.3.1 Windowing Transforms • RB rest of Chap](https://reader031.fdocuments.us/reader031/viewer/2022030422/5aa961b67f8b9a81188cb366/html5/thumbnails/89.jpg)
89
Perspective Derivation
earlier:
complete: shear, scale, projection-normalization !
x '
y '
z'
w '
"
#
$ $ $ $
%
&
' ' ' '
=
1 0 0 0
0 1 0 0
0 0 1 0
0 0 1/d 0
"
#
$ $ $ $
%
&
' ' ' '
x
y
z
1
"
#
$ $ $ $
%
&
' ' ' '
!
" x
" y
" z
" w
#
$
% % % %
&
'
( ( ( (
=
E 0 A 0
0 F B 0
0 0 C D
0 0 )1 0
#
$
% % % %
&
'
( ( ( (
x
y
z
1
#
$
% % % %
&
'
( ( ( (
![Page 90: viewing - UBC Computer Sciencetmm/courses/314-13/slides/viewing.pdf2 Reading for This Module • FCG Chapter 7 Viewing • FCG Section 6.3.1 Windowing Transforms • RB rest of Chap](https://reader031.fdocuments.us/reader031/viewer/2022030422/5aa961b67f8b9a81188cb366/html5/thumbnails/90.jpg)
90
Recorrection: Perspective Derivation
!
x '
y '
z'
w '
"
#
$ $ $ $
%
&
' ' ' '
=
E 0 A 0
0 F B 0
0 0 C D
0 0 (1 0
"
#
$ $ $ $
%
&
' ' ' '
x
y
z
1
"
#
$ $ $ $
%
&
' ' ' '
!
y '= Fy + Bz, y '
w '=Fy + Bz
w', 1=
Fy + Bz
w ', 1=
Fy + Bz
"z,
1 = Fy
"z+ B
z
"z, 1 = F
y
"z" B, 1= F
top
"("near)" B,
!
x '= Ex + Az
y '= Fy + Bz
z'= Cz + D
w '= "z
x = left ! "x / "w = #1
x = right ! "x / "w =1
y = top ! "y / "w =1
y = bottom ! "y / "w = #1
z = #near ! "z / "w = #1
z = # far ! "z / "w =1
!
1 = Ftop
near" B
z axis flip!
L/R sign error
![Page 91: viewing - UBC Computer Sciencetmm/courses/314-13/slides/viewing.pdf2 Reading for This Module • FCG Chapter 7 Viewing • FCG Section 6.3.1 Windowing Transforms • RB rest of Chap](https://reader031.fdocuments.us/reader031/viewer/2022030422/5aa961b67f8b9a81188cb366/html5/thumbnails/91.jpg)
91
Perspective Derivation
• similarly for other 5 planes • 6 planes, 6 unknowns
!
2n
r " l0
r + l
r " l0
02n
t "b
t + b
t " b0
0 0"( f + n)
f " n
"2 fn
f " n0 0 "1 0
#
$
% % % % % % %
&
'
( ( ( ( ( ( (
![Page 92: viewing - UBC Computer Sciencetmm/courses/314-13/slides/viewing.pdf2 Reading for This Module • FCG Chapter 7 Viewing • FCG Section 6.3.1 Windowing Transforms • RB rest of Chap](https://reader031.fdocuments.us/reader031/viewer/2022030422/5aa961b67f8b9a81188cb366/html5/thumbnails/92.jpg)
92
Projective Rendering Pipeline
OCS - object/model coordinate system
WCS - world coordinate system
VCS - viewing/camera/eye coordinate system
CCS - clipping coordinate system
NDCS - normalized device coordinate system
DCS - device/display/screen coordinate system
OCS O2W VCS
CCS
NDCS
DCS
modeling transformation
viewing transformation
projection transformation
viewport transformation
perspective divide
object world viewing
device
normalized device
clipping
W2V V2C
N2D
C2N
WCS
![Page 93: viewing - UBC Computer Sciencetmm/courses/314-13/slides/viewing.pdf2 Reading for This Module • FCG Chapter 7 Viewing • FCG Section 6.3.1 Windowing Transforms • RB rest of Chap](https://reader031.fdocuments.us/reader031/viewer/2022030422/5aa961b67f8b9a81188cb366/html5/thumbnails/93.jpg)
93
NDC to Device Transformation • map from NDC to pixel coordinates on display
• NDC range is x = -1...1, y = -1...1, z = -1...1 • typical display range: x = 0...500, y = 0...300
• maximum is size of actual screen • z range max and default is (0, 1), use later for visibility
x y
viewport NDC
0 500
300
0
-1 1
1
-1
x
y
glViewport(0,0,w,h); glDepthRange(0,1); // depth = 1 by default
![Page 94: viewing - UBC Computer Sciencetmm/courses/314-13/slides/viewing.pdf2 Reading for This Module • FCG Chapter 7 Viewing • FCG Section 6.3.1 Windowing Transforms • RB rest of Chap](https://reader031.fdocuments.us/reader031/viewer/2022030422/5aa961b67f8b9a81188cb366/html5/thumbnails/94.jpg)
94
Origin Location • yet more (possibly confusing) conventions
• OpenGL origin: lower left • most window systems origin: upper left
• then must reflect in y • when interpreting mouse position, have to flip your y
coordinates x
y
viewport NDC
0 500
300
0
-1 1
1
-1
x
y
![Page 95: viewing - UBC Computer Sciencetmm/courses/314-13/slides/viewing.pdf2 Reading for This Module • FCG Chapter 7 Viewing • FCG Section 6.3.1 Windowing Transforms • RB rest of Chap](https://reader031.fdocuments.us/reader031/viewer/2022030422/5aa961b67f8b9a81188cb366/html5/thumbnails/95.jpg)
95
N2D Transformation • general formulation
• reflect in y for upper vs. lower left origin • scale by width, height, depth • translate by width/2, height/2, depth/2
• FCG includes additional translation for pixel centers at (.5, .5) instead of (0,0)
x y
viewport NDC
0 500
300
0
-1 -1
1
1 height
width
x
y
![Page 96: viewing - UBC Computer Sciencetmm/courses/314-13/slides/viewing.pdf2 Reading for This Module • FCG Chapter 7 Viewing • FCG Section 6.3.1 Windowing Transforms • RB rest of Chap](https://reader031.fdocuments.us/reader031/viewer/2022030422/5aa961b67f8b9a81188cb366/html5/thumbnails/96.jpg)
96
N2D Transformation
x y
viewport NDC
0 500
300
0
-1 -1
1
1 height
width
x
y
!
xD
yD
zD
1
"
#
$ $ $ $
%
&
' ' ' '
=
1 0 0width
2(1
2
0 1 0height
2(1
2
0 0 1depth
20 0 0 1
"
#
$ $
$ $
$ $ $
%
&
' ' ' ' ' ' '
width
20 0 0
0height
20 0
0 0depth
20
0 0 0 1
"
#
$ $
$ $
$ $ $
%
&
' ' ' ' ' ' '
1 0 0 0
0 (1 0 0
0 0 1 0
0 0 0 1
"
#
$ $
$ $
%
&
' ' ' '
xN
yN
zN
1
"
#
$ $ $ $
%
&
' ' ' '
=
width (xN
+ 1) (1
2height(( y
N+1) (1
2depth(z
N+1)
21
"
#
$ $ $ $ $ $ $
%
&
' ' ' ' ' ' '
reminder: NDC z range is -1 to 1
Display z range is 0 to 1. glDepthRange(n,f) can constrain further, but depth = 1 is both max and default
![Page 97: viewing - UBC Computer Sciencetmm/courses/314-13/slides/viewing.pdf2 Reading for This Module • FCG Chapter 7 Viewing • FCG Section 6.3.1 Windowing Transforms • RB rest of Chap](https://reader031.fdocuments.us/reader031/viewer/2022030422/5aa961b67f8b9a81188cb366/html5/thumbnails/97.jpg)
97
Device vs. Screen Coordinates • viewport/window location wrt actual display not available
within OpenGL • usually don’t care
• use relative information when handling mouse events, not absolute coordinates
• could get actual display height/width, window offsets from OS • loose use of terms: device, display, window, screen...
x
display viewport
0 1024
768
0
300
500
display height
display width
x offset
y offset y
viewport
x 0 0 y
![Page 98: viewing - UBC Computer Sciencetmm/courses/314-13/slides/viewing.pdf2 Reading for This Module • FCG Chapter 7 Viewing • FCG Section 6.3.1 Windowing Transforms • RB rest of Chap](https://reader031.fdocuments.us/reader031/viewer/2022030422/5aa961b67f8b9a81188cb366/html5/thumbnails/98.jpg)
98
Projective Rendering Pipeline
OCS - object coordinate system
WCS - world coordinate system
VCS - viewing coordinate system
CCS - clipping coordinate system
NDCS - normalized device coordinate system
DCS - device coordinate system
OCS WCS VCS
CCS
NDCS
DCS
modeling transformation
viewing transformation
projection transformation
viewport transformation
alter w
/ w
object world viewing
device
normalized device
clipping
perspective division
glVertex3f(x,y,z)
glTranslatef(x,y,z) glRotatef(a,x,y,z) ....
gluLookAt(...)
glFrustum(...)
glutInitWindowSize(w,h) glViewport(x,y,a,b)
O2W W2V V2C
N2D
C2N
![Page 99: viewing - UBC Computer Sciencetmm/courses/314-13/slides/viewing.pdf2 Reading for This Module • FCG Chapter 7 Viewing • FCG Section 6.3.1 Windowing Transforms • RB rest of Chap](https://reader031.fdocuments.us/reader031/viewer/2022030422/5aa961b67f8b9a81188cb366/html5/thumbnails/99.jpg)
99
Coordinate Systems viewing (4-space, W=1)
clipping (4-space parallelepiped, with COP moved backwards to infinity
normalized device (3-space parallelepiped)
device (3-space parallelipiped)
projection matrix
divide by w
scale & translate
framebuffer
![Page 100: viewing - UBC Computer Sciencetmm/courses/314-13/slides/viewing.pdf2 Reading for This Module • FCG Chapter 7 Viewing • FCG Section 6.3.1 Windowing Transforms • RB rest of Chap](https://reader031.fdocuments.us/reader031/viewer/2022030422/5aa961b67f8b9a81188cb366/html5/thumbnails/100.jpg)
100
Perspective Example
tracks in VCS: left x=-1, y=-1 right x=1, y=-1
view volume left = -1, right = 1 bot = -1, top = 1 near = 1, far = 4
z=-1
z=-4
x
zVCS
top view
-1 -1 1
1
-1 NDCS
(z not shown)
real midpoint
0 xmax-1 0 DCS
(z not shown)
ymax-1
x=-1 x=1
![Page 101: viewing - UBC Computer Sciencetmm/courses/314-13/slides/viewing.pdf2 Reading for This Module • FCG Chapter 7 Viewing • FCG Section 6.3.1 Windowing Transforms • RB rest of Chap](https://reader031.fdocuments.us/reader031/viewer/2022030422/5aa961b67f8b9a81188cb366/html5/thumbnails/101.jpg)
101
Perspective Example
view volume • left = -1, right = 1 • bot = -1, top = 1 • near = 1, far = 4
!
2n
r " l0
r + l
r " l0
02n
t "b
t + b
t " b0
0 0"( f + n)
f " n
"2 fn
f " n0 0 "1 0
#
$
% % % % % % %
&
'
( ( ( ( ( ( (
!
1 0 0 0
0 1 0 0
0 0 "5 /3 "8 /3
0 0 "1 0
#
$
% % % %
&
'
( ( ( (
![Page 102: viewing - UBC Computer Sciencetmm/courses/314-13/slides/viewing.pdf2 Reading for This Module • FCG Chapter 7 Viewing • FCG Section 6.3.1 Windowing Transforms • RB rest of Chap](https://reader031.fdocuments.us/reader031/viewer/2022030422/5aa961b67f8b9a81188cb366/html5/thumbnails/102.jpg)
102
Perspective Example
/ w
!
xNDCS = "1/ zVCS
yNDCS =1/zVCS
zNDCS =5
3+
8
3zVCS
!
1
"1
"5zVCS/3" 8 / 3
"zVCS
#
$
% % % %
&
'
( ( ( (
=
1
1
"5 / 3 "8 /3
"1
#
$
% % % %
&
'
( ( ( (
1
"1
zVCS
1
#
$
% % % %
&
'
( ( ( (
![Page 103: viewing - UBC Computer Sciencetmm/courses/314-13/slides/viewing.pdf2 Reading for This Module • FCG Chapter 7 Viewing • FCG Section 6.3.1 Windowing Transforms • RB rest of Chap](https://reader031.fdocuments.us/reader031/viewer/2022030422/5aa961b67f8b9a81188cb366/html5/thumbnails/103.jpg)
103
OpenGL Example
glMatrixMode( GL_PROJECTION ); glLoadIdentity(); gluPerspective( 45, 1.0, 0.1, 200.0 ); glMatrixMode( GL_MODELVIEW ); glLoadIdentity(); glTranslatef( 0.0, 0.0, -5.0 ); glPushMatrix() glTranslate( 4, 4, 0 ); glutSolidTeapot(1); glPopMatrix(); glTranslate( 2, 2, 0); glutSolidTeapot(1); OCS2
O2W VCS modeling
transformation viewing
transformation projection
transformation
object world viewing W2V V2C WCS
• transformations that are applied to object first are specified last
OCS1
WCS
VCS
W2O
W2O
CCS clipping
CCS
OCS
![Page 104: viewing - UBC Computer Sciencetmm/courses/314-13/slides/viewing.pdf2 Reading for This Module • FCG Chapter 7 Viewing • FCG Section 6.3.1 Windowing Transforms • RB rest of Chap](https://reader031.fdocuments.us/reader031/viewer/2022030422/5aa961b67f8b9a81188cb366/html5/thumbnails/104.jpg)
104
Reading for Next Time
• RB Chap Color
• FCG Sections 3.2-3.3 • FCG Chap 20 Color • FCG Chap 21.2.2 Visual Perception (Color)
![Page 105: viewing - UBC Computer Sciencetmm/courses/314-13/slides/viewing.pdf2 Reading for This Module • FCG Chapter 7 Viewing • FCG Section 6.3.1 Windowing Transforms • RB rest of Chap](https://reader031.fdocuments.us/reader031/viewer/2022030422/5aa961b67f8b9a81188cb366/html5/thumbnails/105.jpg)
105
Viewing: More Camera Motion
![Page 106: viewing - UBC Computer Sciencetmm/courses/314-13/slides/viewing.pdf2 Reading for This Module • FCG Chapter 7 Viewing • FCG Section 6.3.1 Windowing Transforms • RB rest of Chap](https://reader031.fdocuments.us/reader031/viewer/2022030422/5aa961b67f8b9a81188cb366/html5/thumbnails/106.jpg)
106
Fly "Through The Lens": Roll/Pitch/Yaw
![Page 107: viewing - UBC Computer Sciencetmm/courses/314-13/slides/viewing.pdf2 Reading for This Module • FCG Chapter 7 Viewing • FCG Section 6.3.1 Windowing Transforms • RB rest of Chap](https://reader031.fdocuments.us/reader031/viewer/2022030422/5aa961b67f8b9a81188cb366/html5/thumbnails/107.jpg)
107
Viewing: Incremental Relative Motion • how to move relative to current camera coordinate system?
• what you see in the window • computation in coordinate system used to draw previous
frame is simple: • incremental change I to current C • at time k, want p' = IkIk-1Ik-2Ik-3 ... I5I4I3I2I1Cp
• each time we just want to premultiply by new matrix • p’=ICp
• but we know that OpenGL only supports postmultiply by new matrix
• p’=CIp
![Page 108: viewing - UBC Computer Sciencetmm/courses/314-13/slides/viewing.pdf2 Reading for This Module • FCG Chapter 7 Viewing • FCG Section 6.3.1 Windowing Transforms • RB rest of Chap](https://reader031.fdocuments.us/reader031/viewer/2022030422/5aa961b67f8b9a81188cb366/html5/thumbnails/108.jpg)
108
Viewing: Incremental Relative Motion • sneaky trick: OpenGL modelview matrix has the info we
want! • dump out modelview matrix from previous frame with
glGetDoublev() • C = current camera coordinate matrix
• wipe the matrix stack with glIdentity() • apply incremental update matrix I • apply current camera coord matrix C
• must leave the modelview matrix unchanged by object transformations after your display call • use push/pop
• using OpenGL for storage and calculation • querying pipeline is expensive
• but safe to do just once per frame
![Page 109: viewing - UBC Computer Sciencetmm/courses/314-13/slides/viewing.pdf2 Reading for This Module • FCG Chapter 7 Viewing • FCG Section 6.3.1 Windowing Transforms • RB rest of Chap](https://reader031.fdocuments.us/reader031/viewer/2022030422/5aa961b67f8b9a81188cb366/html5/thumbnails/109.jpg)
109
Caution: OpenGL Matrix Storage
• OpenGL internal matrix storage is columnwise, not rowwise a e i m b f j n c g k o d h l p • opposite of standard C/C++/Java convention • possibly confusing if you look at the matrix
from glGetDoublev()!
![Page 110: viewing - UBC Computer Sciencetmm/courses/314-13/slides/viewing.pdf2 Reading for This Module • FCG Chapter 7 Viewing • FCG Section 6.3.1 Windowing Transforms • RB rest of Chap](https://reader031.fdocuments.us/reader031/viewer/2022030422/5aa961b67f8b9a81188cb366/html5/thumbnails/110.jpg)
110
Viewing: Virtual Trackball
• interface for spinning objects around • drag mouse to control rotation of view volume
• orbit/spin metaphor • vs. flying/driving
• rolling glass trackball • center at screen origin, surrounds world • hemisphere “sticks up” in z, out of screen • rotate ball = spin world
![Page 111: viewing - UBC Computer Sciencetmm/courses/314-13/slides/viewing.pdf2 Reading for This Module • FCG Chapter 7 Viewing • FCG Section 6.3.1 Windowing Transforms • RB rest of Chap](https://reader031.fdocuments.us/reader031/viewer/2022030422/5aa961b67f8b9a81188cb366/html5/thumbnails/111.jpg)
111
Clarify: Virtual Trackball
• know screen click: (x, y, 0) • want to infer point on trackball: (x,y,z)
• ball is unit sphere, so ||x, y, z|| = 1.0 • solve for z
eye
image plane
y
z
(x, y, 0)
![Page 112: viewing - UBC Computer Sciencetmm/courses/314-13/slides/viewing.pdf2 Reading for This Module • FCG Chapter 7 Viewing • FCG Section 6.3.1 Windowing Transforms • RB rest of Chap](https://reader031.fdocuments.us/reader031/viewer/2022030422/5aa961b67f8b9a81188cb366/html5/thumbnails/112.jpg)
112 y
z
Clarify: Trackball Rotation • user drags between two points on image plane
• mouse down at i1 = (x, y), mouse up at i2 = (a, b) • find corresponding points on virtual ball
• p1 = (x, y, z), p2 = (a, b, c)
• compute rotation angle and axis for ball • axis of rotation is plane normal: cross product p1 x p2
• amount of rotation θ from angle between lines • p1 • p2 = |p1| |p2| cos θ
i1 = (x, y)
i2 = (a, b)
screen plane
screen plane
virtual ball hemisphere
![Page 113: viewing - UBC Computer Sciencetmm/courses/314-13/slides/viewing.pdf2 Reading for This Module • FCG Chapter 7 Viewing • FCG Section 6.3.1 Windowing Transforms • RB rest of Chap](https://reader031.fdocuments.us/reader031/viewer/2022030422/5aa961b67f8b9a81188cb366/html5/thumbnails/113.jpg)
113
Clarify: Trackball Rotation • finding location on ball corresponding to click on image
plane • ball radius r is 1
z
r=1 z
screen plane
d
virtual ball hemisphere (x, y)
d
(width/2, height/2) screen plane
(x, y, z)
(x, y)
![Page 114: viewing - UBC Computer Sciencetmm/courses/314-13/slides/viewing.pdf2 Reading for This Module • FCG Chapter 7 Viewing • FCG Section 6.3.1 Windowing Transforms • RB rest of Chap](https://reader031.fdocuments.us/reader031/viewer/2022030422/5aa961b67f8b9a81188cb366/html5/thumbnails/114.jpg)
114
Trackball Computation • user defines two points
• place where first clicked p1 = (x, y, z) • place where released p2 = (a, b, c)
• create plane from vectors between points, origin • axis of rotation is plane normal: cross product
• (p1 - o) x (p2 - o): p1 x p2 if origin = (0,0,0) • amount of rotation depends on angle between
lines • p1 • p2 = |p1| |p2| cos θ • |p1 x p2 | = |p1| |p2| sin θ
• compute rotation matrix, use to rotate world
![Page 115: viewing - UBC Computer Sciencetmm/courses/314-13/slides/viewing.pdf2 Reading for This Module • FCG Chapter 7 Viewing • FCG Section 6.3.1 Windowing Transforms • RB rest of Chap](https://reader031.fdocuments.us/reader031/viewer/2022030422/5aa961b67f8b9a81188cb366/html5/thumbnails/115.jpg)
115
Picking
![Page 116: viewing - UBC Computer Sciencetmm/courses/314-13/slides/viewing.pdf2 Reading for This Module • FCG Chapter 7 Viewing • FCG Section 6.3.1 Windowing Transforms • RB rest of Chap](https://reader031.fdocuments.us/reader031/viewer/2022030422/5aa961b67f8b9a81188cb366/html5/thumbnails/116.jpg)
116
Reading
• Red Book • Selection and Feedback Chapter
• all • Now That You Know Chapter
• only Object Selection Using the Back Buffer
![Page 117: viewing - UBC Computer Sciencetmm/courses/314-13/slides/viewing.pdf2 Reading for This Module • FCG Chapter 7 Viewing • FCG Section 6.3.1 Windowing Transforms • RB rest of Chap](https://reader031.fdocuments.us/reader031/viewer/2022030422/5aa961b67f8b9a81188cb366/html5/thumbnails/117.jpg)
117
Interactive Object Selection • move cursor over object, click
• how to decide what is below? • inverse of rendering pipeline flow
• from pixel back up to object • ambiguity
• many 3D world objects map to same 2D point • four common approaches
• manual ray intersection • bounding extents • backbuffer color coding • selection region with hit list
![Page 118: viewing - UBC Computer Sciencetmm/courses/314-13/slides/viewing.pdf2 Reading for This Module • FCG Chapter 7 Viewing • FCG Section 6.3.1 Windowing Transforms • RB rest of Chap](https://reader031.fdocuments.us/reader031/viewer/2022030422/5aa961b67f8b9a81188cb366/html5/thumbnails/118.jpg)
118
Manual Ray Intersection • do all computation at application level
• map selection point to a ray • intersect ray with all objects in scene.
• advantages • no library dependence
• disadvantages • difficult to program • slow: work to do depends on total number and
complexity of objects in scene
x VCS
y
![Page 119: viewing - UBC Computer Sciencetmm/courses/314-13/slides/viewing.pdf2 Reading for This Module • FCG Chapter 7 Viewing • FCG Section 6.3.1 Windowing Transforms • RB rest of Chap](https://reader031.fdocuments.us/reader031/viewer/2022030422/5aa961b67f8b9a81188cb366/html5/thumbnails/119.jpg)
119
Bounding Extents • keep track of axis-aligned bounding
rectangles
• advantages • conceptually simple • easy to keep track of boxes in world space
![Page 120: viewing - UBC Computer Sciencetmm/courses/314-13/slides/viewing.pdf2 Reading for This Module • FCG Chapter 7 Viewing • FCG Section 6.3.1 Windowing Transforms • RB rest of Chap](https://reader031.fdocuments.us/reader031/viewer/2022030422/5aa961b67f8b9a81188cb366/html5/thumbnails/120.jpg)
120
Bounding Extents • disadvantages
• low precision • must keep track of object-rectangle relationship
• extensions • do more sophisticated bound bookkeeping
• first level: box check. • second level: object check
![Page 121: viewing - UBC Computer Sciencetmm/courses/314-13/slides/viewing.pdf2 Reading for This Module • FCG Chapter 7 Viewing • FCG Section 6.3.1 Windowing Transforms • RB rest of Chap](https://reader031.fdocuments.us/reader031/viewer/2022030422/5aa961b67f8b9a81188cb366/html5/thumbnails/121.jpg)
121
Backbuffer Color Coding
• use backbuffer for picking • create image as computational entity • never displayed to user
• redraw all objects in backbuffer • turn off shading calculations • set unique color for each pickable object
• store in table • read back pixel at cursor location
• check against table
![Page 122: viewing - UBC Computer Sciencetmm/courses/314-13/slides/viewing.pdf2 Reading for This Module • FCG Chapter 7 Viewing • FCG Section 6.3.1 Windowing Transforms • RB rest of Chap](https://reader031.fdocuments.us/reader031/viewer/2022030422/5aa961b67f8b9a81188cb366/html5/thumbnails/122.jpg)
122
• advantages • conceptually simple • variable precision
• disadvantages • introduce 2x redraw delay • backbuffer readback very slow
Backbuffer Color Coding
![Page 123: viewing - UBC Computer Sciencetmm/courses/314-13/slides/viewing.pdf2 Reading for This Module • FCG Chapter 7 Viewing • FCG Section 6.3.1 Windowing Transforms • RB rest of Chap](https://reader031.fdocuments.us/reader031/viewer/2022030422/5aa961b67f8b9a81188cb366/html5/thumbnails/123.jpg)
123
for(int i = 0; i < 2; i++) for(int j = 0; j < 2; j++) { glPushMatrix(); switch (i*2+j) { case 0: glColor3ub(255,0,0);break; case 1: glColor3ub(0,255,0);break; case 2: glColor3ub(0,0,255);break; case 3: glColor3ub(250,0,250);break; } glTranslatef(i*3.0,0,-j * 3.0) glCallList(snowman_display_list); glPopMatrix(); }
glColor3f(1.0, 1.0, 1.0); for(int i = 0; i < 2; i++)
for(int j = 0; j < 2; j++) { glPushMatrix(); glTranslatef(i*3.0,0,-j * 3.0); glColor3f(1.0, 1.0, 1.0); glCallList(snowman_display_list); glPopMatrix();
}
Backbuffer Example
http://www.lighthouse3d.com/opengl/picking/
![Page 124: viewing - UBC Computer Sciencetmm/courses/314-13/slides/viewing.pdf2 Reading for This Module • FCG Chapter 7 Viewing • FCG Section 6.3.1 Windowing Transforms • RB rest of Chap](https://reader031.fdocuments.us/reader031/viewer/2022030422/5aa961b67f8b9a81188cb366/html5/thumbnails/124.jpg)
124
Select/Hit
• use small region around cursor for viewport • assign per-object integer keys (names) • redraw in special mode • store hit list of objects in region • examine hit list
• OpenGL support
![Page 125: viewing - UBC Computer Sciencetmm/courses/314-13/slides/viewing.pdf2 Reading for This Module • FCG Chapter 7 Viewing • FCG Section 6.3.1 Windowing Transforms • RB rest of Chap](https://reader031.fdocuments.us/reader031/viewer/2022030422/5aa961b67f8b9a81188cb366/html5/thumbnails/125.jpg)
125
Viewport
• small rectangle around cursor • change coord sys so fills viewport
• why rectangle instead of point? • people aren’t great at positioning mouse
• Fitts’ Law: time to acquire a target is function of the distance to and size of the target
• allow several pixels of slop
![Page 126: viewing - UBC Computer Sciencetmm/courses/314-13/slides/viewing.pdf2 Reading for This Module • FCG Chapter 7 Viewing • FCG Section 6.3.1 Windowing Transforms • RB rest of Chap](https://reader031.fdocuments.us/reader031/viewer/2022030422/5aa961b67f8b9a81188cb366/html5/thumbnails/126.jpg)
126
• nontrivial to compute • invert viewport matrix, set up new orthogonal
projection • simple utility command
• gluPickMatrix(x,y,w,h,viewport) • x,y: cursor point • w,h: sensitivity/slop (in pixels)
• push old setup first, so can pop it later
Viewport
![Page 127: viewing - UBC Computer Sciencetmm/courses/314-13/slides/viewing.pdf2 Reading for This Module • FCG Chapter 7 Viewing • FCG Section 6.3.1 Windowing Transforms • RB rest of Chap](https://reader031.fdocuments.us/reader031/viewer/2022030422/5aa961b67f8b9a81188cb366/html5/thumbnails/127.jpg)
127
Render Modes
• glRenderMode(mode)
• GL_RENDER: normal color buffer • default
• GL_SELECT: selection mode for picking
• (GL_FEEDBACK: report objects drawn)
![Page 128: viewing - UBC Computer Sciencetmm/courses/314-13/slides/viewing.pdf2 Reading for This Module • FCG Chapter 7 Viewing • FCG Section 6.3.1 Windowing Transforms • RB rest of Chap](https://reader031.fdocuments.us/reader031/viewer/2022030422/5aa961b67f8b9a81188cb366/html5/thumbnails/128.jpg)
128
Name Stack
• again, "names" are just integers glInitNames() • flat list glLoadName(name) • or hierarchy supported by stack glPushName(name), glPopName
• can have multiple names per object
![Page 129: viewing - UBC Computer Sciencetmm/courses/314-13/slides/viewing.pdf2 Reading for This Module • FCG Chapter 7 Viewing • FCG Section 6.3.1 Windowing Transforms • RB rest of Chap](https://reader031.fdocuments.us/reader031/viewer/2022030422/5aa961b67f8b9a81188cb366/html5/thumbnails/129.jpg)
129
for(int i = 0; i < 2; i++) { glPushName(i); for(int j = 0; j < 2; j++) { glPushMatrix(); glPushName(j); glTranslatef(i*10.0,0,j * 10.0); glPushName(HEAD); glCallList(snowManHeadDL); glLoadName(BODY); glCallList(snowManBodyDL); glPopName(); glPopName(); glPopMatrix(); } glPopName(); }
Hierarchical Names Example
http://www.lighthouse3d.com/opengl/picking/
![Page 130: viewing - UBC Computer Sciencetmm/courses/314-13/slides/viewing.pdf2 Reading for This Module • FCG Chapter 7 Viewing • FCG Section 6.3.1 Windowing Transforms • RB rest of Chap](https://reader031.fdocuments.us/reader031/viewer/2022030422/5aa961b67f8b9a81188cb366/html5/thumbnails/130.jpg)
130
Hit List • glSelectBuffer(buffersize, *buffer)
• where to store hit list data • on hit, copy entire contents of name stack to output buffer. • hit record
• number of names on stack • minimum and maximum depth of object vertices
• depth lies in the NDC z range [0,1] • format: multiplied by 2^32 -1 then rounded to nearest int
![Page 131: viewing - UBC Computer Sciencetmm/courses/314-13/slides/viewing.pdf2 Reading for This Module • FCG Chapter 7 Viewing • FCG Section 6.3.1 Windowing Transforms • RB rest of Chap](https://reader031.fdocuments.us/reader031/viewer/2022030422/5aa961b67f8b9a81188cb366/html5/thumbnails/131.jpg)
131
Integrated vs. Separate Pick Function
• integrate: use same function to draw and pick • simpler to code • name stack commands ignored in render mode
• separate: customize functions for each • potentially more efficient • can avoid drawing unpickable objects
![Page 132: viewing - UBC Computer Sciencetmm/courses/314-13/slides/viewing.pdf2 Reading for This Module • FCG Chapter 7 Viewing • FCG Section 6.3.1 Windowing Transforms • RB rest of Chap](https://reader031.fdocuments.us/reader031/viewer/2022030422/5aa961b67f8b9a81188cb366/html5/thumbnails/132.jpg)
132
Select/Hit • advantages
• faster • OpenGL support means hardware acceleration • avoid shading overhead
• flexible precision • size of region controllable
• flexible architecture • custom code possible, e.g. guaranteed frame rate
• disadvantages • more complex
![Page 133: viewing - UBC Computer Sciencetmm/courses/314-13/slides/viewing.pdf2 Reading for This Module • FCG Chapter 7 Viewing • FCG Section 6.3.1 Windowing Transforms • RB rest of Chap](https://reader031.fdocuments.us/reader031/viewer/2022030422/5aa961b67f8b9a81188cb366/html5/thumbnails/133.jpg)
133
Hybrid Picking
• select/hit approach: fast, coarse • object-level granularity
• manual ray intersection: slow, precise • exact intersection point
• hybrid: both speed and precision • use select/hit to find object • then intersect ray with that object
![Page 134: viewing - UBC Computer Sciencetmm/courses/314-13/slides/viewing.pdf2 Reading for This Module • FCG Chapter 7 Viewing • FCG Section 6.3.1 Windowing Transforms • RB rest of Chap](https://reader031.fdocuments.us/reader031/viewer/2022030422/5aa961b67f8b9a81188cb366/html5/thumbnails/134.jpg)
134
OpenGL Precision Picking Hints • gluUnproject
• transform window coordinates to object coordinates given current projection and modelview matrices
• use to create ray into scene from cursor location • call gluUnProject twice with same (x,y) mouse
location • z = near: (x,y,0) • z = far: (x,y,1) • subtract near result from far result to get direction
vector for ray • use this ray for line/polygon intersection
![Page 135: viewing - UBC Computer Sciencetmm/courses/314-13/slides/viewing.pdf2 Reading for This Module • FCG Chapter 7 Viewing • FCG Section 6.3.1 Windowing Transforms • RB rest of Chap](https://reader031.fdocuments.us/reader031/viewer/2022030422/5aa961b67f8b9a81188cb366/html5/thumbnails/135.jpg)
135
Projective Rendering Pipeline
OCS - object coordinate system
WCS - world coordinate system
VCS - viewing coordinate system
CCS - clipping coordinate system
NDCS - normalized device coordinate system
DCS - device coordinate system
OCS WCS VCS
CCS
NDCS
DCS
modeling transformation
viewing transformation
projection transformation
viewport transformation
alter w
/ w
object world viewing
device
normalized device
clipping
perspective division
glVertex3f(x,y,z)
glTranslatef(x,y,z) glRotatef(a,x,y,z) ....
gluLookAt(...)
glFrustum(...)
glutInitWindowSize(w,h) glViewport(x,y,a,b)
O2W W2V V2C
N2D
C2N
following pipeline from top/left to bottom/right: moving object POV
![Page 136: viewing - UBC Computer Sciencetmm/courses/314-13/slides/viewing.pdf2 Reading for This Module • FCG Chapter 7 Viewing • FCG Section 6.3.1 Windowing Transforms • RB rest of Chap](https://reader031.fdocuments.us/reader031/viewer/2022030422/5aa961b67f8b9a81188cb366/html5/thumbnails/136.jpg)
136
OpenGL Example
glMatrixMode( GL_PROJECTION ); glLoadIdentity(); gluPerspective( 45, 1.0, 0.1, 200.0 ); glMatrixMode( GL_MODELVIEW ); glLoadIdentity(); glTranslatef( 0.0, 0.0, -5.0 ); glPushMatrix() glTranslate( 4, 4, 0 ); glutSolidTeapot(1); glPopMatrix(); glTranslate( 2, 2, 0); glutSolidTeapot(1); OCS2
O2W VCS modeling transformation
viewing transformation
projection transformation
object world viewing W2V V2C WCS
• transformations that are applied to object first are specified last
OCS1
WCS
VCS
W2O
W2O
CCS clipping
CCS
OCS
go back from end of pipeline to beginning: coord frame POV!
V2W
![Page 137: viewing - UBC Computer Sciencetmm/courses/314-13/slides/viewing.pdf2 Reading for This Module • FCG Chapter 7 Viewing • FCG Section 6.3.1 Windowing Transforms • RB rest of Chap](https://reader031.fdocuments.us/reader031/viewer/2022030422/5aa961b67f8b9a81188cb366/html5/thumbnails/137.jpg)
137
NDCS
object
world
viewing
OCS
WCS
VCS W2V
O2W
read down: transforming between coordinate frames, from frame A to frame B
V2N
DCS
normalized device
display
read up: transforming points, up from frame B coords to frame A coords
V2W
W2O
N2V
D2N N2D
Coord Sys: Frame vs Point
OpenGL command order
pipeline interpretation
gluLookAt(...)
glViewport(x,y,a,b)
glFrustum(...)
glVertex3f(x,y,z)
glRotatef(a,x,y,z)
![Page 138: viewing - UBC Computer Sciencetmm/courses/314-13/slides/viewing.pdf2 Reading for This Module • FCG Chapter 7 Viewing • FCG Section 6.3.1 Windowing Transforms • RB rest of Chap](https://reader031.fdocuments.us/reader031/viewer/2022030422/5aa961b67f8b9a81188cb366/html5/thumbnails/138.jpg)
138
Coord Sys: Frame vs Point • is gluLookat viewing transformation V2W or W2V?
depends on which way you read! • coordinate frames: V2W
• takes you from view to world coordinate frame • points/objects: W2V
• point is transformed from world to view coords when multiply by gluLookAt matrix
• H2 uses the object/pipeline POV • Q1/4 is W2V (gluLookAt) • Q2/5-6 is V2N (glFrustum) • Q3/7 is N2D (glViewport)