Download presentation
Presentation is loading. Please wait.
Published byJanis Norman Modified over 9 years ago
1
Introduction to Computer Graphics: Viewing Transformations Rama C
Introduction to Computer Graphics: Viewing Transformations Rama C. Hoetzlein, 2011 Cornell University Lecture Notes
2
Topics Covered 1. Vector & Matrix Algebra 2. Affine Transformations 3. Homogeneous Coordinates 4. Perspective Projection 5. Projection Pipeline
16
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
17
Viewing Pipeline What does the world look like through the camera?
18
scene with camera camera image Goal: Create a projected image of the scene from viewpoint of camera.
20
Model Space Local objects coordinates centered on the origin X+ Z+
drawCylinder () p
21
World Space { Objects in their place in the world
How do we look through this camera? camera glTranslatef ( .. ) { M glRotatef ( .. ) drawCylinder () p = M p world
22
Camera Transforms Step 1. Translate everything to camera origin
23
Camera Transforms Step 2. Rotate around Y-axis by camera angle
24
Camera Transforms Step 3. Rotate around X-axis by camera tilt
25
{ 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
26
Normalized Projection 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
27
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
28
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
29
Summary…
30
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
31
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 projection creates a perspective matrix (P) tell OpenGL to setup model-view creates a view matrix (V) assigns rotation as model matrix (M) requests polygons to be drawn The clipping and divide by w happen automatically in hardware.
32
MULTIPLE OBJECTS Whats wrong with this?
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 ); P V M1 M2 Whats wrong with this?
33
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 ( .. ); glRotatef ( 20, 1, 0, 0 ); P V M1 V M2 obj1 = P V M1 obj2 = P V M2 save V
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.