CSC 305 Perspective Viewing -...
Transcript of CSC 305 Perspective Viewing -...
![Page 1: CSC 305 Perspective Viewing - webhome.cs.uvic.cawebhome.cs.uvic.ca/~blob/courses/305/notes/pdf/perspective.pdf · Perspective View Transformation The view frustrum is an inconvenient](https://reader033.fdocuments.net/reader033/viewer/2022060509/5f249b5cd793b365b07d8634/html5/thumbnails/1.jpg)
CSC 305Perspective Viewing
by Brian Wyvill
The University of VictoriaGraphics Group
(1,1)
y
xz
(-1,-1)
C.O.P.
1442443
d
![Page 2: CSC 305 Perspective Viewing - webhome.cs.uvic.cawebhome.cs.uvic.ca/~blob/courses/305/notes/pdf/perspective.pdf · Perspective View Transformation The view frustrum is an inconvenient](https://reader033.fdocuments.net/reader033/viewer/2022060509/5f249b5cd793b365b07d8634/html5/thumbnails/2.jpg)
University of Victoria Graphics Lab. CSC 305 2007 page 2
Perspective Viewing Transformation
Tools for creating and manipulating a “camera” that produces pictures of a 3D sceneViewing transformations and projectionsPerform culling or back-face eliminationThe graphics pipeline
![Page 3: CSC 305 Perspective Viewing - webhome.cs.uvic.cawebhome.cs.uvic.ca/~blob/courses/305/notes/pdf/perspective.pdf · Perspective View Transformation The view frustrum is an inconvenient](https://reader033.fdocuments.net/reader033/viewer/2022060509/5f249b5cd793b365b07d8634/html5/thumbnails/3.jpg)
University of Victoria Graphics Lab. CSC 305 2007 page 3
xu yu zu 0xv yv zv 0xw yw zw 00 0 0 1
View volume coordinates:origin o and xyz axes.
need to convert these toorigin e and uvw axes.
We can use:
1 0 0 -xe
0 1 0 -ye0 0 1 -ze0 0 0 1
=Mv
Viewing
![Page 4: CSC 305 Perspective Viewing - webhome.cs.uvic.cawebhome.cs.uvic.ca/~blob/courses/305/notes/pdf/perspective.pdf · Perspective View Transformation The view frustrum is an inconvenient](https://reader033.fdocuments.net/reader033/viewer/2022060509/5f249b5cd793b365b07d8634/html5/thumbnails/4.jpg)
University of Victoria Graphics Lab. CSC 305 2007 page 4
xu yu zu 0xv yv zv 0xw yw zw 00 0 0 1
=Mvrot
Why is Mv computed this way?
Orthogonal Matrix Properties –upper 3x3 rotates row vectors into the major axesapplies to any rotation matrix or rotation translation (+normalization).
cosθ -sinθ 0sinθ cosθ 00 0 1
cosθ-sin
0
100
=
![Page 5: CSC 305 Perspective Viewing - webhome.cs.uvic.cawebhome.cs.uvic.ca/~blob/courses/305/notes/pdf/perspective.pdf · Perspective View Transformation The view frustrum is an inconvenient](https://reader033.fdocuments.net/reader033/viewer/2022060509/5f249b5cd793b365b07d8634/html5/thumbnails/5.jpg)
University of Victoria Graphics Lab. CSC 305 2007 page 5
![Page 6: CSC 305 Perspective Viewing - webhome.cs.uvic.cawebhome.cs.uvic.ca/~blob/courses/305/notes/pdf/perspective.pdf · Perspective View Transformation The view frustrum is an inconvenient](https://reader033.fdocuments.net/reader033/viewer/2022060509/5f249b5cd793b365b07d8634/html5/thumbnails/6.jpg)
University of Victoria Graphics Lab. CSC 305 2007 page 6
![Page 7: CSC 305 Perspective Viewing - webhome.cs.uvic.cawebhome.cs.uvic.ca/~blob/courses/305/notes/pdf/perspective.pdf · Perspective View Transformation The view frustrum is an inconvenient](https://reader033.fdocuments.net/reader033/viewer/2022060509/5f249b5cd793b365b07d8634/html5/thumbnails/7.jpg)
University of Victoria Graphics Lab. CSC 305 2007 page 7
![Page 8: CSC 305 Perspective Viewing - webhome.cs.uvic.cawebhome.cs.uvic.ca/~blob/courses/305/notes/pdf/perspective.pdf · Perspective View Transformation The view frustrum is an inconvenient](https://reader033.fdocuments.net/reader033/viewer/2022060509/5f249b5cd793b365b07d8634/html5/thumbnails/8.jpg)
University of Victoria Graphics Lab. CSC 305 2007 page 8
Example
gaze g= (0,0,0) – (6,7.5,8) sqrt(6*6+7.5*7.5+8*8) = 12.5w = -g/||g|| = (6/12.5 , 7.5/12.5, 8/12.5 )=(0.48, 0.6, 0.64)
u=(t x w)/||t x W||v=(w x u)
x
y
z
u
v
w
eye (6, 7.5, 8 )vup t(0, 1, 0)atpt (0, 0, 0)
![Page 9: CSC 305 Perspective Viewing - webhome.cs.uvic.cawebhome.cs.uvic.ca/~blob/courses/305/notes/pdf/perspective.pdf · Perspective View Transformation The view frustrum is an inconvenient](https://reader033.fdocuments.net/reader033/viewer/2022060509/5f249b5cd793b365b07d8634/html5/thumbnails/9.jpg)
University of Victoria Graphics Lab. CSC 305 2007 page 9
w= 1/12.5 (6, 7.5, 8) t =(0, 1, 0)
u=(t x w)/||t x w|| = (1/12.5)det
t x w = 1/12.5 ( 8, -0.0, -6.0)= (0.6, 0.0, -0.48)
i j k0 1 06 7.5 8
1/12.5 ( 8, -0.0, -6.0)1/12.5 * sqrt(64+36)
t x w||t x w||
= = ( 0.8, 0.0, -0.6)
Calculate U-vector
![Page 10: CSC 305 Perspective Viewing - webhome.cs.uvic.cawebhome.cs.uvic.ca/~blob/courses/305/notes/pdf/perspective.pdf · Perspective View Transformation The view frustrum is an inconvenient](https://reader033.fdocuments.net/reader033/viewer/2022060509/5f249b5cd793b365b07d8634/html5/thumbnails/10.jpg)
University of Victoria Graphics Lab. CSC 305 2007 page 10
v = w x uw = 1/12.5 (6, 7.5, 8)u = ( 0.8, 0.0, -0.6)
i j k6 7.5 810 0 -7.5
Calculate V-vector
(1/12.5* 1/12.5) det
v = 1/(12.5 *12.5)( -56.25, 35, -75)v = 1/12.5(-4.5, 10, -6)v = (-0.36, 0.8, -0.48)
![Page 11: CSC 305 Perspective Viewing - webhome.cs.uvic.cawebhome.cs.uvic.ca/~blob/courses/305/notes/pdf/perspective.pdf · Perspective View Transformation The view frustrum is an inconvenient](https://reader033.fdocuments.net/reader033/viewer/2022060509/5f249b5cd793b365b07d8634/html5/thumbnails/11.jpg)
University of Victoria Graphics Lab. CSC 305 2007 page 11
0.8 0.0 -0.6 -6-0.36 0.8 -0.48 -750.48 0.6 0.64 -80 0 0 1
=Mvrot
Calculate Mvrot
for eye at ( 6, 7.5, 8 )
check the matrix:
0.8 0.0 -0.6-0.36 0.8 -0.480.48 0.6 0.64
0.80.0-0.6
=100
similarly2nd row into y-axis3rd row into z-axis
![Page 12: CSC 305 Perspective Viewing - webhome.cs.uvic.cawebhome.cs.uvic.ca/~blob/courses/305/notes/pdf/perspective.pdf · Perspective View Transformation The view frustrum is an inconvenient](https://reader033.fdocuments.net/reader033/viewer/2022060509/5f249b5cd793b365b07d8634/html5/thumbnails/12.jpg)
University of Victoria Graphics Lab. CSC 305 2007 page 12
3 Point Perspective
Objective is to simulatethis method
![Page 13: CSC 305 Perspective Viewing - webhome.cs.uvic.cawebhome.cs.uvic.ca/~blob/courses/305/notes/pdf/perspective.pdf · Perspective View Transformation The view frustrum is an inconvenient](https://reader033.fdocuments.net/reader033/viewer/2022060509/5f249b5cd793b365b07d8634/html5/thumbnails/13.jpg)
University of Victoria Graphics Lab. CSC 305 2007 page 13
uv
-w
![Page 14: CSC 305 Perspective Viewing - webhome.cs.uvic.cawebhome.cs.uvic.ca/~blob/courses/305/notes/pdf/perspective.pdf · Perspective View Transformation The view frustrum is an inconvenient](https://reader033.fdocuments.net/reader033/viewer/2022060509/5f249b5cd793b365b07d8634/html5/thumbnails/14.jpg)
University of Victoria Graphics Lab. CSC 305 2007 page 14
Geometry for the View Volume
vup
u
(0.5,0.5)
0 .5, 0 .5( )x yn n+ +
w
![Page 15: CSC 305 Perspective Viewing - webhome.cs.uvic.cawebhome.cs.uvic.ca/~blob/courses/305/notes/pdf/perspective.pdf · Perspective View Transformation The view frustrum is an inconvenient](https://reader033.fdocuments.net/reader033/viewer/2022060509/5f249b5cd793b365b07d8634/html5/thumbnails/15.jpg)
University of Victoria Graphics Lab. CSC 305 2007 page 15
“True” Perspective in 2D
y
x
(x,y)
444 3444 21 g
⎪⎭
⎪⎬
⎫
ys
View Plane
size of an object proportional to 1/zys = (d/z) y
d
![Page 16: CSC 305 Perspective Viewing - webhome.cs.uvic.cawebhome.cs.uvic.ca/~blob/courses/305/notes/pdf/perspective.pdf · Perspective View Transformation The view frustrum is an inconvenient](https://reader033.fdocuments.net/reader033/viewer/2022060509/5f249b5cd793b365b07d8634/html5/thumbnails/16.jpg)
University of Victoria Graphics Lab. CSC 305 2007 page 16
![Page 17: CSC 305 Perspective Viewing - webhome.cs.uvic.cawebhome.cs.uvic.ca/~blob/courses/305/notes/pdf/perspective.pdf · Perspective View Transformation The view frustrum is an inconvenient](https://reader033.fdocuments.net/reader033/viewer/2022060509/5f249b5cd793b365b07d8634/html5/thumbnails/17.jpg)
University of Victoria Graphics Lab. CSC 305 2007 page 17
Perspective View Transformation
The view frustrum is aninconvenient shape.
ClippingZ depth calculationHidden surface calculation
nf
f
n
![Page 18: CSC 305 Perspective Viewing - webhome.cs.uvic.cawebhome.cs.uvic.ca/~blob/courses/305/notes/pdf/perspective.pdf · Perspective View Transformation The view frustrum is an inconvenient](https://reader033.fdocuments.net/reader033/viewer/2022060509/5f249b5cd793b365b07d8634/html5/thumbnails/18.jpg)
University of Victoria Graphics Lab. CSC 305 2007 page 18
We want to find a matrix that
1. does not change points on z=n plane
2. maps large rectangle at z=f to small rectangle at z=n
3. achieve division by z by usinghomogeneous to cartesianconversion i.e. homogenize
n
f
Perspective View Transformation
![Page 19: CSC 305 Perspective Viewing - webhome.cs.uvic.cawebhome.cs.uvic.ca/~blob/courses/305/notes/pdf/perspective.pdf · Perspective View Transformation The view frustrum is an inconvenient](https://reader033.fdocuments.net/reader033/viewer/2022060509/5f249b5cd793b365b07d8634/html5/thumbnails/19.jpg)
University of Victoria Graphics Lab. CSC 305 2007 page 19
Perspective Matrix
Mp=
1 0 0 00 1 0 0
0 0 -f
0 0 0n
n+f
Mp
xyz1
=
1n
x
y
z –fnn+f
homogenize
nx/z
ny/z
n + f –
1 zfn
for homogenous point (x,y,z,1) = (x/h, y/h, z/h, h)
![Page 20: CSC 305 Perspective Viewing - webhome.cs.uvic.cawebhome.cs.uvic.ca/~blob/courses/305/notes/pdf/perspective.pdf · Perspective View Transformation The view frustrum is an inconvenient](https://reader033.fdocuments.net/reader033/viewer/2022060509/5f249b5cd793b365b07d8634/html5/thumbnails/20.jpg)
University of Victoria Graphics Lab. CSC 305 2007 page 20
for homogenous point (x,y,z,1) = (x/h, y/h, z/h, h)thus we can multiply any transformation matrix by a constant.
M(hp) = (hM)p = Mp so we can multiply perspective matrix by n:
Mp=
n 0 0 00 n 0 0
0 0 n+f –fn
0 0 1 0
Perspective Matrix
![Page 21: CSC 305 Perspective Viewing - webhome.cs.uvic.cawebhome.cs.uvic.ca/~blob/courses/305/notes/pdf/perspective.pdf · Perspective View Transformation The view frustrum is an inconvenient](https://reader033.fdocuments.net/reader033/viewer/2022060509/5f249b5cd793b365b07d8634/html5/thumbnails/21.jpg)
University of Victoria Graphics Lab. CSC 305 2007 page 21
Mp=
1/n 0 0 00 1/n 0 0
0 0 0 1
0 0 –1/fn
Inverse Perspective Matrix
n+ffn
Tidy this up by multiplying by nf
M-1p=
f 0 0 00 f 0 0
0 0 0 fn
0 0 –1 n+f
e.g. for picking
![Page 22: CSC 305 Perspective Viewing - webhome.cs.uvic.cawebhome.cs.uvic.ca/~blob/courses/305/notes/pdf/perspective.pdf · Perspective View Transformation The view frustrum is an inconvenient](https://reader033.fdocuments.net/reader033/viewer/2022060509/5f249b5cd793b365b07d8634/html5/thumbnails/22.jpg)
University of Victoria Graphics Lab. CSC 305 2007 page 22
Perspective Projection Algorithm
Again Arbitrary View Point
compute Mvcompute M0compute Mp
M=M0MvMp
for each line segment in 3D (ai, bi) do {p = Maiq = Mbidrawline( )
}
We can now use the mechanism we used before for orthographic projection
hxp ,
hyp ,
hyq
hxq ,