180 likes | 198 Views
Computer Graphics (Spring 2003). COMS 4160, Lecture 9: Transformations 2 Ravi Ramamoorthi. http://www.cs.columbia.edu/~cs4160. Motivation. Modeling Objects in convenient coordinate system Transform into world space, eye space Viewing: project world space into 2D rectangle Virtual cameras
E N D
Computer Graphics (Spring 2003) COMS 4160, Lecture 9: Transformations 2 Ravi Ramamoorthi http://www.cs.columbia.edu/~cs4160
Motivation Modeling • Objects in convenient coordinate system • Transform into world space, eye space • Viewing: project world space into 2D rectangle • Virtual cameras • Types of projections (perspective, orthographic) • Window system
Rotations • Very brief overview (not in detail) • For little more detail, some useful websites: • www.cs.berkeley.edu/~ug/slide/pipeline/assignments/as5/rotation.html • www.cs.cmu.edu/afs/cs/academic/class/16741-s02/www/lecture6.pdf
Rotations • 2D (simple) • Matrix representation, commutative • 3D (complicated) • Non-commutative • Counterclockwise • Matrix reps for axis transforms
Euler Angles • Rotate about Z, then new X, then new Z • [Goldstein pp 107] • Product of axis transforms • Efficient, 3 parameters • Bad for numerics, splining
Axis-Angle • Single axis, angle about it • 3 params (axis is normalized) • Somewhat intuitive • Many of same numerical problems as Euler-Angles • Formula (axis-angle to rotation matrix) Dual Matrix of v
Viewing 3D • Pipeline (pp 230 FvDFH) • Projection 3D -> 2D • Clip: near and far planes (viewing volume)
The Whole Viewing Pipeline Eye coordinates Model coordinates Perspective transformation Model transformation Screen coordinates Viewport transformation World coordinates Camera transformation Window coordinates Raster transformation Device coordinates Slide courtesy Greg Humphreys
Projections • To lower dimensional space • Preserve straight lines • Trivial example: Drop one coordinate • We are concerned with 3D -> 2D • Taxonomy [Fig 6.13, pp 237] • Perspective [realistic images, no proportions preserved] • Parallel [preserves proportions] • Orthographic (common in graphics)
Perspective • Center of projection, rays, projection plane • Distance from center of projection to projection plane is finite. If infinite, projection rays parallel • Foreshortening: Key feature • Size inverse proportional to distance • Cameras, visual system are similar
Perspective or Parallel? If the distance between the center of projection and the projection plane is finite, the projection is called a perspective projection. Otherwise, it’s a parallel projection. A A A’ A’ B B B’ B’ C (at infinity) C Parallel Perspective
Perspective • Distortions • Lines remain lines, everything else is distorted… • Vanishing points for parallel lines • Shape distortions • Parallel Projections (parallel lines are parallel) • Not realistic but preserve size (useful in mechanical drawings)
Parallel (Orthographic) • Projection vector (direction of rays) • Perpendicular to projection plane : Orthographic • Otherwise, oblique. • Far off objects in perspective are approx. orthographic • Uniform foreshortening • Parallelism preserved, angles are not • More info in book • We now concentrate on perspective…
Perspective mathematically 1 Intuition: divide by z • Eye as a point (or pinhole camera) • Easy in eye space (homogeneous coordinates) Simple form: equation 6.4 page 255 Full mathematics next week
Overhead View of Our Screen Looks like we’ve got some nice similar triangles here! Next few slides courtesy Greg Humphreys
The Perspective Matrix • This “division by z” can be accomplished by a 4x4 matrix • We’re in homogeneous coordinates, so if we multiply some point by P, we get . • Recall that to get the actual 3D point, you divide by w, giving , which was the point on our screen. Now just drop the third coordinate!
Viewing in OpenGL • OpenGL has multiple matrix stacks - transformation functions right-multiply the top of the stack • Two most important stacks: GL_MODELVIEW and GL_PROJECTION • Points get multiplied by the modelview matrix first, and then the projection matrix • This is only really necessary for convenience -- you could ignore all of this and put your entire viewing matrix into one or the other. However, if one is changing and the other one isn’t, you’ll save time
OpenGL Example void SetUpViewing(){ // The viewport isn’t a matrix, it’s just state... glViewport( 0, 0, window_width, window_height ); // Set up camera transformation first glMatrixMode( GL_PROJECTION ); glLoadIdentity(); gluPerspective( 60, 1, 1, 1000 ); // fov, aspect, near, far gluLookAt( 3, 3, 2, // eye point 0, 0, 0, // look at point 0, 0, 1 ); // up vector // Set up the model transformation glMatrixMode( GL_MODELVIEW ); glRotatef( theta, 0, 0, 1 ); // rotate the model glScalef( zoom, zoom, zoom ); // scale the model }