Post on 24-Jan-2016
description
Introduction to 3D GraphicsIntroduction to 3D Graphics
Lecture 3: General Camera Lecture 3: General Camera ModelModel
Anthony SteedAnthony Steed
University College LondonUniversity College London
OverviewOverview
More MathsMore Maths– Rotations and translationsRotations and translations– Homogenous co-ordinatesHomogenous co-ordinates
General CameraGeneral Camera– SpecificationSpecification– Mapping to world coordinatesMapping to world coordinates
Vectors and MatricesVectors and Matrices
Matrix is an array of numbers with Matrix is an array of numbers with dimensions M (rows) by N (columns)dimensions M (rows) by N (columns)– 3 by 6 matrix3 by 6 matrix– element 2,3element 2,3
is (3)is (3)
Vector can be considered a 1 x M Vector can be considered a 1 x M matrixmatrix–
zyxv
100025
114311
212003
Types of MatrixTypes of Matrix
Identity matrices - Identity matrices - II
Diagonal Diagonal
1001
1000010000100001
Symmetric Symmetric
– Diagonal matrices Diagonal matrices are (of course) are (of course) symmetricsymmetric
– Identity matrices Identity matrices are (of course) are (of course) diagonaldiagonal
4000010000200001
fecedbcba
Operation on MatricesOperation on Matrices
AdditionAddition– Done elementwiseDone elementwise
TransposeTranspose– ““Flip” (M by N becomes N by M)Flip” (M by N becomes N by M)
s d r cq b p a
s rq p
d cb a
389
724
651
376
825
941T
Operations on MatricesOperations on Matrices
MultiplicationMultiplication– Only possible to multiply of dimensionsOnly possible to multiply of dimensions
xx11 by y by y11 and x and x22 by y by y22 iff y iff y11 = x = x22 – resulting matrix is xresulting matrix is x1 1 byby yy22
e.g. Matrix A is 2 by 3 and Matrix by 3 by e.g. Matrix A is 2 by 3 and Matrix by 3 by 44
– resulting matrix is 2 by 4resulting matrix is 2 by 4 Just because A x B is possible doesn’t mean Just because A x B is possible doesn’t mean
B x A is possible! B x A is possible!
Matrix Multiplication OrderMatrix Multiplication Order
A is n by k , B is k by A is n by k , B is k by mm
C = A x B defined byC = A x B defined by
BxA not necessarily BxA not necessarily equal to AxBequal to AxB
k
l
ljilij bac1
*
*****
*****
*.
*.*.*.*.*.
*****
*...
*.*.*.*.*.
*****.....
Example MultiplicationsExample Multiplications
____
____
1011
12
101132
__________________
010001100
111013322
InverseInverse
If A x B = I and B x A = I thenIf A x B = I and B x A = I then
A = BA = B-1-1 and B = A and B = A-1-1
3D Transforms3D Transforms
In 3-space vectors are transformed In 3-space vectors are transformed by 3 by 3 matricesby 3 by 3 matrices
ziyfxczhyexbzgydxa
ihg
fed
cba
zyx
ScaleScale
Scale uses a diagonal matrixScale uses a diagonal matrix
Scale by 2 along x and -2 along zScale by 2 along x and -2 along z
zcybxac
ba
zyx
000000
1046200
010002
543
RotationRotation
Rotation about z axisRotation about z axis
Note Note z values z values remain the same whilst remain the same whilst x and y changex and y change
1000)θcos()θsin(-0)θsin()θcos(
Y
X
θ yx
yθ cosxθ sin yθ sin-xθ cos
Rotation X, Y and ScaleRotation X, Y and Scale
About XAbout X
About YAbout Y
Scale (should look Scale (should look familiar)familiar)
)θcos()θsin(-0
)θsin()θcos(0
001
)θcos(0)θsin(
010
)θsin(-0)θcos(
c
b
a
00
00
00
Homogenous PointsHomogenous Points
Add 1D, but constrain that to be equal Add 1D, but constrain that to be equal to 1 (x,y,z,1)to 1 (x,y,z,1)
Homogeneity means that any point in 3-Homogeneity means that any point in 3-space can be represented by an infinite space can be represented by an infinite variety of homogenous 4D pointsvariety of homogenous 4D points– (2 3 4 1) = (4 6 8 2) = (3 4.5 6 1.5)(2 3 4 1) = (4 6 8 2) = (3 4.5 6 1.5)
Why?Why?– 4D allows as to include 3D translation in 4D allows as to include 3D translation in
matrix formmatrix form
Homogenous VectorsHomogenous Vectors
Vectors != Points Vectors != Points Remember points can not be Remember points can not be
addedadded If A and B are points A-B is a vectorIf A and B are points A-B is a vector Vectors have form (x y z 0)Vectors have form (x y z 0) Addition makes senseAddition makes sense
Translation in Translation in Homogenous FormHomogenous Form
Note that the homogenous Note that the homogenous component is preserved (* * * 1), component is preserved (* * * 1), and aside from the translation the and aside from the translation the matrix is I matrix is I
1
1010000100001
1 czbyax
cba
zyx
Putting it TogetherPutting it Together
R is rotation and scale componentsR is rotation and scale components T is translation componentT is translation component
1000
321
987
654
321
TTTRRRRRRRRR
1432
1432010000100001
1
1432010000100001
1000001001000001
1
YZXYZXZYX
1442
1000
0010
0100
0001
1442
1000
0010
0100
0001
1432
0100
0010
0001
1
YZXZYXZYX
Order MattersOrder Matters
Composition order of transforms Composition order of transforms mattersmatters– Remember that basic vectors change so Remember that basic vectors change so
“direction” of translations changed“direction” of translations changed
OverviewOverview
More MathsMore Maths– Rotations and translationsRotations and translations– Homogenous co-ordinatesHomogenous co-ordinates
General CameraGeneral Camera– SpecificationSpecification– Mapping to world coordinatesMapping to world coordinates
Simple Camera Simple Camera (Cross Section)(Cross Section)
Z -Z
Yd
COP
ymax
ymin
General CameraGeneral Camera
View Reference Point (VRP)View Reference Point (VRP)– where the camera iswhere the camera is
View Plane Normal (VPN)View Plane Normal (VPN)– where the camera pointswhere the camera points
View Up Vector (VUV)View Up Vector (VUV)– which way is up to the camerawhich way is up to the camera
X (or U-axis) forms X (or U-axis) forms LHLH system system
UVN Co-ordindatesUVN Co-ordindates
View Reference Point (VRP)View Reference Point (VRP)– origin of VC systemorigin of VC system
View Plane Normal (VPN)View Plane Normal (VPN)– Z (or N-axis) of VC systemZ (or N-axis) of VC system
View Up Vector (VUV)View Up Vector (VUV)– determines Y (or V-axis) of VCSdetermines Y (or V-axis) of VCS
X (or U-axis) forms X (or U-axis) forms LHLH system system
World Coords and Viewing World Coords and Viewing CoordsCoords
Y
X
Z
V U
N
VUV
VRP
1000
321
987
654
321
TTTRRRRRRRRR
We want to find a general transform (EQ1) of
the above form that will map WC to VC
View from the CameraView from the Camera
VUV
N and VPN into the page
U
V
XYZ
xmin, ymin
xmax, ymax
Finding the basis vectorsFinding the basis vectors
Step 1 - find nStep 1 - find n
Step 2 - find uStep 2 - find u
Step 3 - find vStep 3 - find v
||VPN
VPNn
VUVn
VUVnu
nuv
Finding the Mapping (1)Finding the Mapping (1)
u,v,n must rotate under R to i,j,k of u,v,n must rotate under R to i,j,k of viewing spaceviewing space
Both basis are normalised so this is a Both basis are normalised so this is a pure rotation matrix pure rotation matrix – recall in this case Rrecall in this case RTT = R = R-1-1
IR
nvu
333
232
111
nvunvunvu
R
Finding the Mapping (2)Finding the Mapping (2)
In uvn system VRP (q) is (0 0 0 In uvn system VRP (q) is (0 0 0
1)1)
And we know from EQ1 And we know from EQ1
so so
3
1
3
1
3
1 i
ii
i
ii
i
ii nqvquq
qRt0 tqR
Complete MappingComplete Mapping
Complete matrixComplete matrix
1
000
3
1
3
1
3
1
333
222
111
i
ii
i
ii
i
ii nqvquq
nvunvunvu
M
For you to checkFor you to check
IfIf
ThenThen
1
0qRRM
101
qRM
T
Using this for Ray-CastingUsing this for Ray-Casting
Use a similar camera configuration Use a similar camera configuration (COP is usually, but not always on -(COP is usually, but not always on -n)n)
To trace object must eitherTo trace object must either– transform spheres into VCtransform spheres into VC– transform rays into WCtransform rays into WC
Ray-castingRay-casting
Transforming rays into WCTransforming rays into WC– Transform end-point onceTransform end-point once– Find direction vectors through COP as Find direction vectors through COP as
beforebefore
– Transform vector byTransform vector by
– Intersect spheres in WC Intersect spheres in WC
10
qRT
Ray-castingRay-casting
Transforming spheres into VCTransforming spheres into VC– Centre of sphere is a point so can be Centre of sphere is a point so can be
transformed as usual (WC to VC)transformed as usual (WC to VC)– Radius of sphere is unchanged by Radius of sphere is unchanged by
rotation and translation (and spheres rotation and translation (and spheres are spheroids if there is a non-are spheroids if there is a non-symmetric scale)symmetric scale)
TradeoffTradeoff
If more rays than spheres do the If more rays than spheres do the formerformer– transform spheres into VCtransform spheres into VC
For more complex scenes e.g. with For more complex scenes e.g. with polygons polygons – transform rays into WCtransform rays into WC
Alternative Forms of the Alternative Forms of the CameraCamera
Simple “Look At”Simple “Look At”– Give a VRP and a target (TP)Give a VRP and a target (TP)– VPN = TP-VRPVPN = TP-VRP– VUV = (0 1 0) (i.e. “up” in WC)VUV = (0 1 0) (i.e. “up” in WC)
Field of ViewField of View– Give horizontal and vertical FOV or one or Give horizontal and vertical FOV or one or
the other and an aspect ratiothe other and an aspect ratio
– Calculate viewport and proceed as beforeCalculate viewport and proceed as before
Animated CamerasAnimated Cameras
Animate VRP (observer-cam)Animate VRP (observer-cam) Animate VPN (look around)Animate VPN (look around) Animate TP (track-cam)Animate TP (track-cam) Animate COP Animate COP
– along VPN - zoomalong VPN - zoom– orthogonal to VPN - distortorthogonal to VPN - distort
SummarySummary
We set up the mathematics of We set up the mathematics of transformations between co-transformations between co-ordinate spacesordinate spaces
We created a more general We created a more general camera which we can use to create camera which we can use to create views of our scenes from arbitrary views of our scenes from arbitrary positionspositions
Formulation of mapping from WC Formulation of mapping from WC to VC (and back)to VC (and back)