Evening s Goals Discuss the mathematical transformations that are utilized for computer graphics projection viewing modeling Describe aspect ratio and its importance Provide a motivation for homogenous coordinates and their uses 2 Mathematical Transformations Use transformations for moving from one coordinate space to another The good news onl requires multiplication and addition The bad news its multiplication and addition of matrices 3
Mathematical Transformations ( cont. ) Coordinate spaces we ll be using model ee normalized device ( NDC s ) window screen viewport 4 Simplified 2D Transform Pipeline What if our data is not in viewport coordinates? Stock Price??? Date World Coordinates Viewport coordinates 5 Simplified 2D Transform Pipeline ( cont. ) Need to map to viewport coordinates Simple linear transformation linear transformations can be represented b matrices x viewport x = a c b d 6 2
Almost, but not quite The 2x2 matrix isn t quite enough to do the whole job think about tring to map a point like (,) into the (,) Enter homogenous coordinates ( x ) add an additional dimension to our coordinate vector 7 Determining the Matrix Entries Matrix forms of linear transforms are shorthand for an line equation = mx + b So what we need is to determine what equations we want to write as matrices = m b x 8 Mapping World to Viewport Coordinates ( xmin Min) Stock Price Date World Coordinates ( xmax Max)??? ( xmax Max) Viewport coordinates ( xmin Min) xmax x = xmax Max = Max xmin xmax Min Max ( x xmin ) + xmin ( Min ) + Min 9 3
Or as a Matrix Let m x = xmax xmin xmax xmin m then our matrix becomes = Max Min Max Min x mx = m xmin Min m xmin x m Min x Setting up OpenGL s 2D OpenGL will do this automaticall for us gluortho2d( xmin, xmax, Min, Max ); However, it doesn t do it quite as we described first maps coordinates into normalized device coordinates ( NDC ) then maps from NDC s to viewport coordinates Normalized Device Coordinates Map each dimension linearl into[-, ] sometimes mapped to [, ] Simplifies several things clipping don t need to know viewport for clipping describes a device independent space no concerns about resolution, etc. more things which we ll get to in a minute verusefulwhenwe rein3d 2 4
Putting it all together Stock Price Date World Coordinates Stock Price Date NDC Stock Price Date Viewport Coordinates 3 Err something doesn t look right Need to match aspect ratio aspect ratio = width height Aspect ratios of different coordinate spaces need to match ar = ar 4 What s different for 3D Add another dimension ( x z w) Our transformation matrices become 4x4 More options for our projection transform 5 5
Where we re at What our transformation pipeline looks like so far... World NDC s viewport This is reall called a projection transform 6 Projection Transformations Map coordinates into NDC s Defines our viewing frustum sets the position of our imaging plane Two tpes for 3D Orthographic (or parallel) Projection gluortho2d() Perspective Projection 7 A Few Definitions First A viewing frustum is the region in space in which objects can be seen All of the visible objects in our scene will be in the viewing frustum The imaging plane is a plane in space onto which we project our scene viewing frustum controls where the imaging plane is located 8 6
Orthographic Projections Project objects in viewing frustum without distortion good for computer aided engineering and design preserves angles and relative sizes 9 Orthographic Projections ( cont. ) 2 Defining an Orthographic Projection Ver similar to mapping 2D to NDC s Use OpenGL s glortho( l, r, b, t, n, f ); 2 r l 2 t b 2 f n r+ l r l t+ b t b + n n f f 2 7
Perspective Projections Model how the ee sees objects farther from the ee are smaller A few assumptions ee is positioned at the space origin looking down the -z axis Clipping plane restrictions < near < far 22 Perspective Projections ( cont. ) Based on similar triangles n ' z 23 Perspective Projections ( cont. ) Viewing frustum looks like a truncated Egptian pramid 24 8
Defining Perspective Projections Two OpenGL versions glfrustum( l, r, b, t, n, f ); frustum not necessaril aligned down line of sight good for simulating peripheral vision gluperspective( fov, aspect, n, f ); frustum centered down line of sight more general form reasonable values: 65. < fov < 4. aspect should match aspect ratio of viewport 25 Defining a Perspective Projection glfrustum( l, r, b, t, n, f ); 2n r l 2n t b r + l r l t+ b t b ( n+ f ) f n 2nf f n 26 Defining a Perspective Projection ( cont. ) gluperspective( fov, aspect, n, f ); fov t = n tan( 2 ) b = t r = t aspect l = r then useglfrustum() 27 9
Clipping in 3D Projections transforms make clipping eas Use our favorite algorithm Clipping region well defined w x w w w w z w 28 Normalizing Projected Coordinates w is a scaling factor Perspective divide divide each coordinate b w maps into NDC s What about z? x w w z w 29