11Projection and 3D TransformationsCS-184: Computer GraphicsProf. James O’Brien2Projection Process of going from 3D scene to 2D scene Studied throughout history (e.g. painters) Different types of projection– Linear Orthographic Perspective– Nonlinear Many other “types” of linear mentioned in books– Just special cases of orthographic or perspective3Linear Projection Projection onto planar surface Projection directions either– converge to point – are all parallel (a point at infinity)4Linear Projection A 2D viewOrthographicPerspective5Linear Projection A 2D viewOrthographicPerspectiveNote how different things can be seenParallel lines “meet” at infinity6Orthographic Projection No foreshortening Parallel lines stay parallel Examples:27Orthographic Projection Assume looking down –Z axis – “Z is in your face” View center at the origin View region is box defined by [-1,-1,-1] and [1,1,1]Throw X and Y coordinates map to normalized view port[1,1,1][-1,-1,-1]-Z8Orthographic Projection Converting to canonical view setup [1,1,1][-1,-1,-1]-Z9Orthographic ProjectionView vectorUp vectorRight = view upOriginCenternear,top,rightfar,bottom,left*Assume up is perpendicular to view.10Orthographic ProjectionStep 1: translate center to origin11Orthographic ProjectionStep 2: Rotate so that view aligns with –Z axis andup with +Y axis12Orthographic ProjectionStep 3: Center view volumeStep 4: Scale view volume313Orthographic ProjectionStep 1: translate center to originStep 2: Rotate so that view aligns with –Z axis andup with +Y axisStep 3: Center view volumeStep 4: Scale view volume12RTSTM =14Orthographic ProjectionStep 1: translate center to originStep 2: Rotate so that view aligns with –Z axis andup with +Y axisStep 3: Center view volumeStep 4: Scale view volume12RTSTM =oMvM15Window Transformation Convert from [-1,-1],[+1,+1] window region to image space[-1,-1][1,1]xy[0,0][MaxX,MaxY]xyPixel centers offset by 0.5 ( e.g. 0.5, 1.5, 2.5 … MaxX-0.5 )wM= Translate and scaleExampleimage space16Detour: 3D Transformations With the exception of rotations, basically the same as in 2D: =1~00AAyxtt22 is ×A2D17 With the exception of rotations, basically the same as in 2D: =1000~zyxtttAADetour: 3D Transformations33 is ×A3D18Detour: 3D Transformations Axis-aligned scales are still diagonal Rotations still orthonormal w/ Det = +1 Shear is a composition of rotation and scale SVD and polar decomposition have the same propertiesBUT: More than one way to rotate Can rotate about any axis in space 3 DOF for rotation, not just 1419Detour: 3D Rotations 2D implicitly rotating about axis “out of the page” −)Cos()Sin()Sin()Cos(θθθθ20Detour: 3D Rotations In 3D can rotate about one of coordinate axes Or about arbitrary axis (we’ll see shortly…) −=)Cos()Sin(0)Sin()Cos(0001θθθθxRExample: rotation about X axis. (Other axes similar, see text.)21Detour: 3D RotationsRotation Matrix Trivia: AKA direction-cosine matrices Orthonormal Det = +1 One real eigenvalue = 1 Corresponding eigenvector is axis of rotation Unique22Detour: 3D RotationsEuler Angles Any rotation can be composed of one rotations about each of the primary axes Allows tumbling Suffers from gimbal-lock Non-uniquexyzRRRR =23Detour: 3D RotationsAngular Displacement AKA: exponential map, axis-angle Rotate degrees about axis is given by the length of the vector24Detour: 3D RotationsAngular Displacement Method 1 to arrive at rotation matrix1. Rotate axis about X axis into X-Y plane2. Rotate axis about Z axis to align with X axis3. Rotate about X axis4. Undo step 25. Undo step 3– Composite 5.4.3.2.1 together525Detour: 3D RotationsAngular Displacement Method 2 to arrive at rotation matrixxrx⊥x⊥xr26Detour: 3D RotationsAngular Displacement Method 2 to arrive at rotation matrix– does not change– rotates like 2D rotationx⊥x⊥xr⊥xx27Detour: 3D RotationsAngular Displacement Method 2 to arrive at rotation matrix 28Detour: 3D RotationsAngular Displacement Method 2 to arrive at rotation matrix 29Detour: 3D RotationsAngular Displacement Allows tumbling No gimbal lock Orientations are space within radius ball Nearly unique representation Singularities are shells at 2 Nice for interpolation30Detour: 3D RotationsQuaternions631Detour: 3D RotationsQuaternions Multiplication Conjugate Mgnitude 32Detour: 3D RotationsQuaternions Represent vectors with Represent rotation with33Detour: 3D RotationsQuaternions Rotate a point using quaternions Compose rotations34Detour: 3D RotationsQuaternions No tumbling No gimbal lock Orientations are 3D sphere in R4 Double representation No singularities Nice for interpolation35Detour: 3D Rotations Relationship between exponential maps and quaternions…36Detour: 3D Rotations Consider Columns of rotation matrix are axes of coordinate system after rotation Rows are original axes expressed in the rotated coordinate system =100010001zzzyzxyzyyyxxzxyxxrrrrrrrrrRI737Orthographic Projection (back from a long detour)Step 1: translate center to originStep 2: Rotate so that view aligns with –Z axis andup with +Y axisStep 3: Center view volumeStep 4: Scale view volume12RTSTM =oMvM38Orthographic ProjectionStep 2: Rotate so that view aligns with –Z axis andup with +Y axis −−−=zzzyyyxxxViewUpRightViewUpRightViewUpRightR39Perspective Projection Foreshortening: further things get smaller Some parallel lines stay parallel, most don’t Lines still look like lines Z ordering preserved for what we care about40Pinhole Camera41Perspective Projection Foreshortening: distant things are smaller42Perspective Projection Draw “ film” in front or pinhole843Perspective Projection Vanishing points– Depend on scene, not intrinsic to cameraOne point perspective44Perspective Projection Vanishing points– Depend on scene, not intrinsic to cameraTwo point perspective45Perspective Projection Vanishing points– Depend on scene, not intrinsic to cameraThree point perspective46Perspective ProjectionuvnView frustrum47Perspective
View Full Document