If you can't read please download the document
Upload
janis-norman
View
223
Download
1
Embed Size (px)
DESCRIPTION
Topics Covered 1. Vector & Matrix Algebra 2. Affine Transformations 3. Homogeneous Coordinates 4. Perspective Projection 5. Projection Pipeline
Citation preview
Introduction to Computer Graphics: Viewing Transformations Rama
C
Introduction to Computer Graphics: Viewing Transformations Rama C.
Hoetzlein, 2011 Cornell University Lecture 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 looklike
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 look through this camera? camera glTranslatef ( .. ) { M
glRotatef ( .. ) drawCylinder () p = M p world Camera
TransformsStep 1. Translate everything to camera origin Camera
TransformsStep 2. Rotate around Y-axis by camera angle Camera
TransformsStep 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 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 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 Summary 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 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.
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?
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 M1obj2 = P V M2
save V