Introduction to 3D Graphics Lecture 3: General Camera Model Anthony Steed University College London
Overview n More Maths –Rotations and translations –Homogenous co-ordinates n General Camera –Specification –Mapping to world coordinates
Vectors and Matrices n Matrix is an array of numbers with dimensions M (rows) by N (columns) –3 by 6 matrix –element 2,3 is (3) is (3) n Vector can be considered a 1 x M matrix –
Types of Matrix n Identity matrices - I n Diagonal n Symmetric –Diagonal matrices are (of course) symmetric –Identity matrices are (of course) diagonal
Operation on Matrices n Addition –Done elementwise n Transpose –“Flip” (M by N becomes N by M)
Operations on Matrices n Multiplication –Only possible to multiply of dimensions n x 1 by y 1 and x 2 by y 2 iff y 1 = x 2 –resulting matrix is x 1 by y 2 n e.g. Matrix A is 2 by 3 and Matrix by 3 by 4 –resulting matrix is 2 by 4 n Just because A x B is possible doesn’t mean B x A is possible!
Matrix Multiplication Order n A is n by k, B is k by m n C = A x B defined by n BxA not necessarily equal to AxB
Example Multiplications
Inverse n If A x B = I and B x A = I then A = B -1 and B = A -1
3D Transforms n In 3-space vectors are transformed by 3 by 3 matrices
Scale n Scale uses a diagonal matrix n Scale by 2 along x and -2 along z
Rotation n Rotation about z axis n Note z values remain the same whilst x and y change Y X
Rotation X, Y and Scale n About X n About Y n Scale (should look familiar)
Homogenous Points n Add 1D, but constrain that to be equal to 1 (x,y,z,1) n Homogeneity means that any point in 3-space can be represented by an infinite variety of homogenous 4D points –( ) = ( ) = ( ) n Why? –4D allows as to include 3D translation in matrix form
Homogenous Vectors n Vectors != Points n Remember points can not be added n If A and B are points A-B is a vector n Vectors have form (x y z 0) n Addition makes sense
Translation in Homogenous Form n Note that the homogenous component is preserved (* * * 1), and aside from the translation the matrix is I
Putting it Together n R is rotation and scale components n T is translation component
Order Matters n Composition order of transforms matters –Remember that basic vectors change so “direction” of translations changed
Overview n More Maths –Rotations and translations –Homogenous co-ordinates n General Camera –Specification –Mapping to world coordinates
Simple Camera (Cross Section) Z-Z Y d COP y max y min
General Camera n View Reference Point (VRP) –where the camera is n View Plane Normal (VPN) –where the camera points n View Up Vector (VUV) –which way is up to the camera n X (or U-axis) forms LH system
UVN Co-ordindates n View Reference Point (VRP) –origin of VC system n View Plane Normal (VPN) –Z (or N-axis) of VC system n View Up Vector (VUV) –determines Y (or V-axis) of VCS n X (or U-axis) forms LH system
World Coords and Viewing Coords Y X Z V U N VUV VRP We want to find a general transform (EQ1) of the above form that will map WC to VC
View from the Camera VUV N and VPN into the page U V XY Z xmin, ymin xmax, ymax
Finding the basis vectors n Step 1 - find n n Step 2 - find u n Step 3 - find v
Finding the Mapping (1) n u,v,n must rotate under R to i,j,k of viewing space n Both basis are normalised so this is a pure rotation matrix –recall in this case R T = R -1
Finding the Mapping (2) n In uvn system VRP (q) is ( ) n And we know from EQ1 so
Complete Mapping n Complete matrix
For you to check n If n Then
Using this for Ray-Casting n Use a similar camera configuration (COP is usually, but not always on -n) n To trace object must either –transform spheres into VC –transform rays into WC
Ray-casting n Transforming rays into WC –Transform end-point once –Find direction vectors through COP as before –Transform vector by –Intersect spheres in WC
Ray-casting n Transforming spheres into VC –Centre of sphere is a point so can be transformed as usual (WC to VC) –Radius of sphere is unchanged by rotation and translation (and spheres are spheroids if there is a non-symmetric scale)
Tradeoff n If more rays than spheres do the former –transform spheres into VC n For more complex scenes e.g. with polygons –transform rays into WC
Alternative Forms of the Camera n Simple “Look At” –Give a VRP and a target (TP) –VPN = TP-VRP –VUV = (0 1 0) (i.e. “up” in WC) n Field of View –Give horizontal and vertical FOV or one or the other and an aspect ratio –Calculate viewport and proceed as before
Animated Cameras n Animate VRP (observer-cam) n Animate VPN (look around) n Animate TP (track-cam) n Animate COP –along VPN - zoom –orthogonal to VPN - distort
Summary n We set up the mathematics of transformations between co-ordinate spaces n We created a more general camera which we can use to create views of our scenes from arbitrary positions n Formulation of mapping from WC to VC (and back)