2 COEN Computer Graphics I Evening’s Goals n Discuss the mathematical transformations that are utilized for computer graphics projection viewing modeling n Describe aspect ratio and its importance n Provide a motivation for homogenous coordinates and their uses
3 COEN Computer Graphics I Mathematical Transformations n Use transformations for moving from one coordinate space to another n The good news only requires multiplication and addition n The bad news its multiplication and addition of matrices
4 COEN Computer Graphics I Mathematical Transformations ( cont. ) n Coordinate spaces we’ll be using model world eye normalized device ( NDC’s ) window screen viewport
5 COEN Computer Graphics I Simplified 2D Transform Pipeline n What if your data is not in viewport coordinates? World Coordinates Date Stock Price Viewport coordinates ???
6 COEN Computer Graphics I Simplified 2D Transform Pipeline ( cont. ) n Need to map world to viewport coordinates n Simple linear transformation linear transformations can be represented by matrices
7 COEN Computer Graphics I Almost, but not quite n The 2x2 matrix isn’t quite enough to do the whole job think about trying to map a point like (10,10) into the (0,0) n Enter … homogenous coordinates add an additional “dimension” to your coordinate vector
8 COEN Computer Graphics I Determining the Matrix Entries n Matrix forms of linear transforms are shorthand for an “line” equation n So what we need is to determine what equations we want to write as matrices
9 COEN Computer Graphics I Mapping World to Viewport Coordinates Viewport coordinates ??? World Coordinates Date Stock Price
10 COEN Computer Graphics I Or as a Matrix n Let then our matrix becomes
11 COEN Computer Graphics I Setting up OpenGL’s 2D world n OpenGL will do this automatically for us gluOrtho2D( xMin, xMax, yMin, yMax ); n However, it doesn’t do it quite as we described first maps world coordinates into normalized device coordinates ( NDC ) then maps from NDC’s to viewport coordinates
12 COEN Computer Graphics I Normalized Device Coordinates n Map each dimension linearly into sometimes mapped to n 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 –very useful when we’re in 3D
13 COEN Computer Graphics I Putting it all together World Coordinates Date Stock Price Date Stock Price NDC Date Stock Price Viewport Coordinates
14 COEN Computer Graphics I Err … something doesn’t look right n Need to match aspect ratio n Aspect ratios of different coordinate spaces need to match
15 COEN Computer Graphics I What’s different for 3D n Add another dimension n Our transformation matrices become 4x4 n More options for our projection transform
16 COEN Computer Graphics I Where we’re at n What our transformation pipeline looks like so far... viewportNDC’sWorld This is really called a projection transform
17 COEN Computer Graphics I Projection Transformations n Map coordinates into NDC’s n Defines our viewing frustum sets the position of our imaging plane n Two types for 3D Orthographic (or parallel) Projection –gluOrtho2D() Perspective Projection
18 COEN Computer Graphics I A Few Definitions First … n 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 n The imaging plane is a plane in space onto which we project our scene viewing frustum controls where the imaging plane is located
19 COEN Computer Graphics I Orthographic Projections n Project objects in viewing frustum without distortion good for computer aided engineering and design –preserves angles and relative sizes
20 COEN Computer Graphics I Orthographic Projections ( cont. )
21 COEN Computer Graphics I Defining an Orthographic Projection n Very similar to mapping 2D to NDC’s n Use OpenGL’s glOrtho( l, r, b, t, n, f );
22 COEN Computer Graphics I Perspective Projections n Model how the eye sees objects farther from the eye are smaller n A few assumptions eye is positioned at the world space origin looking down the world -z axis n Clipping plane restrictions
23 COEN Computer Graphics I Perspective Projections ( cont. ) n Based on similar triangles y z n
24 COEN Computer Graphics I Perspective Projections ( cont. ) n Viewing frustum looks like a truncated Egyptian pyramid
25 COEN Computer Graphics I Defining Perspective Projections n Two OpenGL versions glFrustum( l, r, b, t, n, f ); –frustum not necessarily aligned down line of sight –good for simulating peripheral vision gluPerspective ( fovy, aspect, n, f ); –frustum centered down line of sight –more general form –reasonable values: –aspect should match aspect ratio of viewport
26 COEN Computer Graphics I Defining a Perspective Projection glFrustum( l, r, b, t, n, f );
27 COEN Computer Graphics I Defining a Perspective Projection ( cont. ) gluPerspective ( fovy, aspect, n, f ); then use glFrustum()
28 COEN Computer Graphics I Clipping in 3D n Projections transforms make clipping easy n Use your favorite algorithm n Clipping region well defined
29 COEN Computer Graphics I Normalizing Projected Coordinates n w is a scaling factor n Perspective divide divide each coordinate by w maps into NDC’s What about z?