Perspective projection Prepared by Cindy Grimm and Ken Goldman for Washington University CSE131 based on slides to accompany Fundamentals of Interactive Computer Graphics by Foley and Van Dam
Properties of perspective projection edges same size, with farther ones smaller Straight lines go to straight lines Closer objects are bigger Parallel lines Stay parallel (lines are perpendicular to viewer) Converge to a vanishing point (lines are not perpendicular to viewer) parallel edges converging Perspective projection
Perspective projection View volume What you can see View point (eye) View direction (projectors) projectors eye, or Center of Projection (COP) projectors picture plane Perspective projection
Perspective projection Specifying a camera Eye position (type: Point) Look direction (type: Vector) Up direction (type: Vector) Near/far (percentage along Look) (0.1, 1,000) Width Up vector Look vector y x Height Position z Near Far Perspective projection
Perspective projection Our camera Eye point is point on sphere. Given d (distance), q (latitude) and f (longitude), eye point is: Eyex = d cos(q) cos(f) Eyey = d sin(q) Eyez = d sin(f) cos(q) Up vector will always be (0,1,0) Note that sphere is oriented with the north/south poles in the y direction Look vector: looks at origin (Eye – (0,0,0)) Perspective projection
Perspective projection Mathematically… Projection is a 4x4 matrix Build from four component matrices, PSRT P: Perspective matrix Responsible for fore-shortening S: Scale matrix Adjusts for aspect ratio R: Rotation matrix Which direction to look at T: Translation matrix Where the camera is Perspective projection
Perspective projection near (0.1) far (1000) k = near/far Scales x,y by z P Flip the z-axis and unhinge Note: not 1! Perspective projection
Perspective projection Scale Pre-adjust for aspect ratio W: width of final image H: height of final image Aspect ratio: W/H Bring the far plane up Note: can put W/H in S(1,1) instead Perspective projection
Perspective projection Rotation Make the camera point at the origin Given: Eye (point) and Up (vector) = (0,1,0) r,u,n are orthogonal, unit length vectors Dot product of any pair is zero Length of each is one Perspective projection
Perspective projection Translation Move camera to position on sphere Why negative? Matrix needs to undo translation to bring camera to origin Perspective projection
Putting it all together Convert point (x,y,z) to 4x1 matrix by adding a one (homogeneous points) Note: Pre-multiply PSRT to make one 4x4 matrix which is applied to all points Perspective projection
Perspective projection To image space Divide by w to get point in camera space Anything with u/w,v/w in [-1,-1]x[1,1] and d/w in [0,1] is visible and in front of the camera If w=0 then point is “smeared” over all of the z=0 plane; one fix is to set u/w and v/w to be zero. Convert to image space by scaling by width and height Camera to image transformation Perspective projection