viewing and projection - university of...
Post on 05-Jun-2018
228 Views
Preview:
TRANSCRIPT
1
Viewing and Projection
Sheelagh Carpendale
Camera metaphor
1. choose camera position 2. set up and organize objects3. choose a lens4. take the picture
2
View Volumes
z
perspective view volumeperspective view volume orthographic view volumeorthographic view volume
x=left
x=right
y=top
y=bottom z=-near z=-farxVCS x
z
VCS
yy
x=lefty=top
x=right
z=-farz=-neary=bottom
• what gets into the scene
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
OCSOCS WCSWCS VCSVCS
NDCSNDCS
DCSDCS
modelingmodelingtransformationtransformation
viewingviewingtransformationtransformation
projectionprojectiontransformationtransformation
viewportviewporttransformationtransformation
/ w/ w
object world viewing/camera
device
normalizeddevice
Model view matrix
Projection matrix
Viewport matrix
clippingclipping
CCSCCSclipping
3
Viewing Transformation
OCSOCS WCSWCS VCSVCSmodelingmodeling
transformationtransformationviewingviewing
transformationtransformation
modM camM
OpenGL ModelView matrix
object world viewing
Arbitrary Viewing Position
• General situation for camera• Keep view frame unchanged• Map object with the inverse of the frame
transformation
-nz
z
y
eye
u
v
n
4
Deriving the model view matrix
• eye point P = (x, y, z, 1)• viewplane normal n = (nx, ny, nz, 0)• up vector v = (vx, vy, vz, 0)• u = v x n• unit vectors u’, v’, n’
-nz
z
y
eye
u
v
n
Model view matrix details
• Rotation matrix: M
• Object rotations: R = M-1 = MT =
• Translation T =
• V = RT
0001
0
0
0u'z
0 00000
-y0-x0
-z00000
u'x
v'x v'y v'z
n'x n'zn'y
u'y
5
Arbitrary Viewing Position
• rotate/translate/scale not intuitive• convenient formulation
• eye point, lookat direction, up vector
Look-at function
• Input• p: eye point• q: look at point• v’: approximation of up vector
• n = p – q• v = v’ – (v’. n) .n• u = v x n• Normalize• OpenGL utility function
gluLookAt(ex, ey, ez, lx, ly, lz, ux, uy, uz)
6
Viewing Transformation
• OpenGL• gluLookAt(ex,ey,ez,lx,ly,lz,ux,uy,uz)
usually use as follows:
glMatrixMode(GL_MODELVIEW);glLoadIdentity();gluLookAt(ex,ey,ez,lx,ly,lz,ux,uy,uz)// now ok to do model transformations
Field-of-View Formulation
• FOV in one direction + aspect ratio (w/h)• determines FOV in other direction• also set near, far (reasonably intuitive)
--zz
xx
FrustumFrustum
z=z=--nn z=z=--ff
ααfovx/2fovx/2
fovy/2fovy/2hh
ww
7
Viewing and Projection
• Standard situation• camera at origin, pointing in –z direction, orthogonal
projection
• Map camera to a general situation
Or
• Map all objects in to the standard situation of camera
Canonical view volume
• transform an arbitrary orthogonal to • canonical view volume
x = +/- 1, y = +/- 1, z = +/- 1• translate centre• scale• matrix?
8
Orthographic Derivation• scale, translate, reflect for new coord sys
x
z
VCS
yx=left
y=top
x=right
z=-farz=-neary=bottom
x
z
NDCS
y
(-1,-1,-1)
(1,1,1)
Orthographic Derivation
solving for a and b gives:solving for a and b gives:
same idea for right/left, far/near same idea for right/left, far/near
byay +⋅='
1'1'−=→=
=→=
ybotyytopy
bottopa
−= 2
bottopbottop
b−+−
= )(
9
Orthographic Derivation• scale, translate, reflect for new coord sys
P
nearfarnearfar
nearfar
bottopbottop
bottop
leftrightleftright
leftright
P
−+
−−−
−+
−−
−+−
−
=
1000
200
02
0
002
'
Perspective normalization
• simple case • COP at origin • projection plane at z = -1
x = +/- 1, y = +/- 1• matrix?
10
Projective Transformations
• transformation of space• center of projection moves to infinity• viewing frustum transformed into a parallelepiped
--zz
xx
--zz
xx
FrustumFrustum
Projective Transformations
• can express as homogeneous 4x4 matrices!• 16 matrix entries• multiples of same matrix all describe same
transformation• 15 degrees of freedom• mapping of 5 points uniquely determines
transformation
11
Projective Transformations
• determining the matrix representation• need to observe 5 points in general position, e.g.
• [left,0,0,1] T→[1,0,0,1] T
• [0,top,0,1] T→[0,1,0,1] T
• [0,0,-f,1]T→[0,0,1,1] T
• [0,0,-n,1]T→[0,0,0,1] T
• [left*f/n,top*f/n,-f,1]T→[1,1,1,1] T
• solve resulting equation system to obtain matrix
Perspective Derivation
x
z
NDCS
y
(-1,-1,-1)
(1,1,1)x=left
x=right
y=top
y=bottom z=-near z=-farx
VCS
y
z
12
Normalized Device Coordinates
left/right x =+/- 1, top/bottom y =+/- 1, near/far z =+/- 1
--zz
xx
FrustumFrustum
z=z=--nn z=z=--ff
rightright
leftleftzz
xx
x= x= --11z=1z=1
x=1x=1
Camera coordinatesCamera coordinates NDCNDC
z= z= --11
Perspective Derivation
earlier:earlier:
complete: shear, scale, projectioncomplete: shear, scale, projection--normalizationnormalization
=
10/100010000100001
/zyx
ddzzyx
−
=
1010000
0000
''''
zyx
DCBFAE
hzyx
13
Perspective Derivation• similarly for other 5 planes• 6 planes, 6 unknowns
−−
−−+−
−+
−
−+
−
0100
2)(00
02
0
002
nffn
nfnf
btbt
btn
lrlr
lrn
14
Perspective Example
view volume• left = -1, right = 1• bot = -1, top = 1• near = 1, far = 4
−−
−−+−
−+
−
−+
−
0100
2)(00
020
002
nffn
nfnf
btbt
btn
lrlr
lrn
−−−
0100
3/83/500
00100001
Perspective Example
tracks in VCS:left x=-1, y=-1right x=1, y=-1
view volumeleft = -1, right = 1bot = -1, top = 1near = 1, far = 4
z=-1
z=-4
x
zVCS
top view
-1-1 1
1
-1NDCS
(z not shown)
realmidpoint
0 xmax-10DCS
(z not shown)
ymax-1
x=-1 x=1
15
Viewport Transformation• generate pixel coordinates• map x, y from range –1…1 (normalized device
coordinates) to pixel coordinates on the display• involves 2D scaling and translation
xx
yydisplaydisplay
viewportviewport
Holbein the younger
1497-1543
First discussed by da Vinci as ‘Anamorphosis’From Greek word meaning to transform
16
Holbein the younger 1497-1543
No record or any mention of this skull until 1873
Portrait of Prince Edward VI
William Scrots 1546
17
Portrait of Prince Edward VI
William Scrots 1546
top related