CS 428: Fall 29 Introduction to Computer Graphics Viewing and projective transformations Andrew Nealen, Rutgers, 29 9/23/29
Modeling and viewing transformations Canonical viewing volume Viewport transformation Window coordinates Andrew Nealen, Rutgers, 29 9/23/29 2
Modeling and viewing OpenGL order glmatrimode(gl_modelview) glloadidentit() glmultmatri(v) glmultmatri(m) draw() transformations Transformation is VM In OpenGL, these transformations are place on the modelview matri stack The projectionmatri stack is onl for storing the projection matri resulting from glortho(), glfrustum(), or gluprojection() Andrew Nealen, Rutgers, 29 9/23/29 3
3D viewing The ee has a view cone Approimated in CG b a rectangular cone = square frustum Good for rectangular viewing window Andrew Nealen, Rutgers, 29 9/23/29 4
3D viewing process Andrew Nealen, Rutgers, 29 9/23/29 5
Truncated view volumes Orthographic Andrew Nealen, Rutgers, 29 9/23/29 6
Truncated view volumes Perspective Andrew Nealen, Rutgers, 29 9/23/29 7
Where s the film? A rectangle with known aspect ratio on the infinite film plane Where doesn t matter, as long as the film plane is parallel to farand near Will be scaled to viewport coordinates Andrew Nealen, Rutgers, 29 9/23/29 8
OpenGL projection matrices How is this implemented in OpenGL? The following matrices assume Camera center at origin Looking down negative z-ais -ais is up near, far> right= -left= top= -bottom= See glortho()etc. manpages for general case Andrew Nealen, Rutgers, 29 9/23/29 9
OpenGL projection matrices Orthographic projection Andrew Nealen, Rutgers, 29 9/23/29
OpenGL projection matrices Perspective projection Andrew Nealen, Rutgers, 29 9/23/29
Perspective projections Perspective projections are not affine transformations Relative lengths are no longer invariant Distant objects (of same size) are made smaller than near ones (= foreshortening) Given a projected point P=(, ) t and ee position A=(-, ) t, then b the theorem of intersecting lines the image B is (, ) t = + Andrew Nealen, Rutgers, 29 9/23/29 2
Perspective projections In general, the mapping is Resulting in the homogeneous 3 3-Matri + a + = 2D-Geometr! = = ' ' + + = 9/23/29 3 Andrew Nealen, Rutgers, 29
Perspective projections The projection is composed of two transformations The perspective transformation The subsequent parallel projection The subsequent parallel projection Perspective projection Parallelprojection Perspective transformation = 9/23/29 4 Andrew Nealen, Rutgers, 29
Perspective transformations Properties of perspective transformations of the form + = = w w w T p 9/23/29 5 Andrew Nealen, Rutgers, 29
Field of view and viewing line All points on the affine Line = - are mapped to infinite points Onl points on one side of this line are transformed These points are in the field of view, and the line = - is the viewing line Ee point Field of view Main vanishing point Viewing line Projection line Vanishing line Andrew Nealen, Rutgers, 29 9/23/29 6
Fied points and lines Points on the projection line = (= -ais) together with the infinite point [,, ] are fied points of this transformation (the -ais is invariant) Lines parallel to the -ais remain parallel Field of view Ee point Main vanishing point Viewing line Andrew Nealen, Rutgers, 29 Projection line Vanishing line Projection line Vanishing line 9/23/29 7
Fied points and lines Points on the projection line = (= -ais) together with the infinite point [,, ] are fied points of this transformation (the -ais is invariant) Lines parallel to the -ais remain parallel Lines are transformed to lines 9/23/29 8 Andrew Nealen, Rutgers, 29 = + + = + = + = = factor image obj obj obj obj obj obj obj obj obj p a T
Parallel lines The affine (ee) point [-,, ] t is transformed to the infinite point [-,, ] t =[-,, ] t The points on the affine -ais are invariant Field of view Ee point Main vanishing point Viewing line Andrew Nealen, Rutgers, 29 Projection line Vanishing line Projection line Vanishing line 9/23/29 9
Parallel lines Lines are mapped to lines A line through ee point [-,, ] t, which intersects the - ais at [,, ] t is mapped to a line parallel to the -ais passing through [,, ] t Field of view Ee point Main vanishing point Viewing line Andrew Nealen, Rutgers, 29 Projection line Vanishing line Projection line Vanishing line 9/23/29 2
Vanishing line The point [,, ] t is mapped to [, /, ] t Note that [,, ] t is a directionand [, /, ] t is a point The mappings of all lines parallel to the affine line with direction [,, ] t contain the point [, /,] t, meaning the all intersect in this point The union of the mappings of all lines with direction [,, ] t lie on the line = (= vanishing line) Andrew Nealen, Rutgers, 29 9/23/29 2
Vanishing line The point [,, ] t is mapped to [, /, ] t Note that [,, ] t is a directionand [, /, ] t is a point Field of view Ee point Main vanishing point Viewing line Projection line Vanishing line Projection line Vanishing line Andrew Nealen, Rutgers, 29 9/23/29 22
Vanishing point The point [,, ] t is mapped to [, /, ] t Note that [,, ] t is a directionand [, /, ] t is a point All lines with direction [,, ] t are mapped to [,, ] t Field of view Ee point Main vanishing point Viewing line Projection line Vanishing line Projection line Vanishing line Andrew Nealen, Rutgers, 29 9/23/29 23
One, two and three vanishing point perspectives General perspective transformation + + + = = w z w z w z T p The directions of lines parallel to the coordinate aes are mapped to the vanishing points[,,, ] t, [,,, ] t, [,, z, ] t z w z w 9/23/29 24 Andrew Nealen, Rutgers, 29
In OpenGL code For eample, in reshape(...) glviewport(,, width, height) glmatrimode(gl_projection) glloadidentit() gluperspective(...) glmatrimode(gl_modelview) In render() glulookat(...) gltranslatef(...) glrotatef(...) draw_scene() Perspective transformation Viewing transformation Modeling transformations Andrew Nealen, Rutgers, 29 9/23/29 25
Geometric construction
Geometric construction This transformation maps points [,,] to [,,/4] The vanishing point of parallel lines AB and DC can be computed from the direction [4,,] as [4,,], which is the 2D point [4,]
Geometric construction Fied points
Geometric construction Points before parallel projection Points after parallel projection Fied points A
Geometric construction Points before parallel projection Points after parallel projection Fied points A B
Geometric construction Points before parallel projection Points after parallel projection Fied points A B D C Lines parallel to the projection line remain parallel
Geometric construction Points before parallel projection Points after parallel projection Fied points A B D C Lines parallel to the projection line remain parallel
Geometric construction A Ee point (-4,, ) = at infinit B D C