330 likes | 342 Views
This lecture introduces the concept of viewing transformations in computer graphics, covering topics such as vector and matrix algebra, affine transformations, and perspective projection. The lecture also discusses the projection pipeline and how to create projected images of a scene from the viewpoint of a camera.
E N D
Introduction to Computer Graphics:Viewing TransformationsRama C. Hoetzlein, 2011Cornell UniversityLecture Notes
Topics Covered 1. Vector & Matrix Algebra2. Affine Transformations3. Homogeneous Coordinates4. Perspective Projection5. Projection Pipeline
Complete Perspective Matrix Lets us specify all characteristics of the projective volume. glMatrixMode ( GL_PROJECTION )glFrustum ( l, r, b, t, near, far); gluPerspective ( fov, asp, near, far);gluOrtho2D ( l, r, b, t ); OpenGL Red Book
Viewing Pipeline What does the world look like through the camera?
scene with camera camera image Goal: Create a projected image of the scene from viewpoint of camera.
Model Space Local objects coordinates centered on the origin X+ Z+ drawCylinder () p
World Space Objects in their place in the world How do we lookthrough this camera? camera glTranslatef ( .. ) { M glRotatef ( .. ) drawCylinder () p = M p world
Camera Transforms Step 1. Translate everything to camera origin
Camera Transforms Step 2. Rotate around Y-axis by camera angle
Camera Transforms Step 3. Rotate around X-axis by camera tilt
View Space Objects oriented with the camera along the Z-axis glMatrixMode ( MODELVIEW ) V { gluLookAt (..) glTranslatef ( .. ) { M glRotatef ( .. ) drawCylinder () V { p = Rcz Rcy Tcam M p p = V M p view view
NormalizedProjection Space Objects multiplied by perspective matrix,to fit in unit cube. glMatrixMode ( PROJECTION ) P { gluPerspective(..) glMatrixMode ( MODELVIEW ) V { gluLookAt (..) glTranslatef ( .. ) { M glRotatef ( .. ) drawCylinder () p = P V M p eye
Clipping Objects clipped to unit cube for rasterization. glMatrixMode ( PROJECTION ) P { gluPerspective(..) glMatrixMode ( MODELVIEW ) V { gluLookAt (..) Look here! glTranslatef ( .. ) { M glRotatef ( .. ) drawCylinder () p = clip ( P V M p ) clip
Screen Space Objects as they appear (flattened) on the screen.Divide by w to get 2D coordinates. glMatrixMode ( PROJECTION ) P { gluPerspective(..) glMatrixMode ( MODELVIEW ) V { gluLookAt (..) glTranslatef ( .. ) { M glRotatef ( .. ) drawCylinder () p = divw ( clip ( P V M p ) ) screen
VIEWING PIPELINE Model Space World Space View Space M V P Screen Space Clipping persp.div clip Normalized Dev.Coordinates Depth Sorting p = divw ( clip ( P V M p ) ) screen Rasterization
VIEWING PIPELINE – in OpenGL OpenGL has two stored matricies, one for the projection, and one for the combined model-view. glMatrixMode ( GL_PROJECTION );gluPerspective ( .. ); glMatrixMode ( GL_MODELVIEW ); gluLookAt ( fx, fy, fz, tx, ty, tz ); glRotatef ( 10, 0, 0, 1 ); drawCylinder ( .. ); tell OpenGL to setup projectioncreates a perspective matrix (P) tell OpenGL to setup model-viewcreates a view matrix (V) assigns rotation as model matrix (M)requests polygons to be drawn The clipping and divide by whappen automatically in hardware.
MULTIPLE OBJECTS The scene has one view matrix (V) for the camera,but.. each object has its own MODELVIEW matrix, VM. glMatrixMode ( GL_PROJECTION );gluPerspective ( .. ); glMatrixMode ( GL_MODELVIEW ); gluLookAt ( fx, fy, fz, tx, ty, tz ); glRotatef ( 10, 0, 0, 1 ); drawCylinder ( .. ); glRotatef ( 20, 1, 0, 0 ); drawCylinder ( .. ); P V M1 M2 Whats wrong with this?
MULTIPLE OBJECTS Right! (I hope).. Each object needs to set up the proper VM matrix. glMatrixMode ( GL_PROJECTION );gluPerspective ( .. ); glMatrixMode ( GL_MODELVIEW ); gluLookAt ( fx, fy, fz, tx, ty, tz ); glGetMatrixfv ( view_matrix ); glLoadMatrixf ( view_matrix ); glRotatef ( 10, 0, 0, 1 ); drawCylinder ( .. ); glLoadMatrixf ( view_matrix ); glRotatef ( 20, 1, 0, 0 ); drawCylinder ( .. ); P V M1 VM2 obj1 = P V M1obj2 = P V M2 save V