Introduction to Computer Graphics 4. Viewing in 3D National Chiao Tung Univ, Taiwan By: I-Chen Lin, Assistant Professor Textbook: E.Angel, Interactive Computer Graphics, 5 th Ed., Addison Wesley Ref: Hearn and Baker, Computer Graphics, 3rd Ed., Prentice Hall
Outline Classical views Computer viewing Projection matrices
Classical Viewing Viewing requires three basic elements One or more objects A viewer with a projection surface Projectors that go from the object(s) to the projection surface Each object is assumed to constructed from flat principal faces Buildings, polyhedra, manufactured objects
Planar Geometric Projections Standard projections project onto a plane. Projectors are lines that either converge at a center of projection are parallel Such projections preserve lines but not necessarily angles When do we need non-planar projections?
Classical Projections
Perspective vs Parallel Classical viewing developed different techniques for drawing each type of projection Mathematically parallel viewing is the limit of perspective viewing Computer graphics treats all projections the same and implements them with a single pipeline
Taxonomy of Planar Geometric Projections planar geometric projections parallel perspective multiview orthographic axonometric 1 point 2 point 3 point oblique isometric dimetric trimetric
Perspective Projection
Parallel Projection
Orthographic Projection Projectors are orthogonal to projection surface
Multiview Orthographic Projection Projection plane parallel to principal faces Usually form front, top, side views isometric (not multiview orthographic view) front in CAD and architecture, we often display three multiviews plus isometric top side
Advantages and Disadvantages Preserves both distances and angles Shapes preserved Can be used for measurements Building plans Manuals Cannot see what object really looks like because many surfaces hidden from view Often we add the isometric
Axonometric Projections Allow projection plane to move relative to object classify by how many angles of a corner of a projected cube are the same none: trimetric two: dimetric three: isometric q 2 q 1 q 3
Types of Axonometric Projections
Advantages and Disadvantages Lines are scaled (foreshortened) but can find scaling factors Lines preserved but angles are not Projection of a circle in a plane not parallel to the projection plane is an ellipse Does not look real because far objects are scaled the same as near objects Used in CAD applications
Oblique Projection Arbitrary relationship between projectors and projection plane
Perspective Projection Projectors coverage at center of projection
Vanishing Points Parallel lines (not parallel to the projection plan): converge at a single point in the projection (the vanishing point) Drawing simple perspectives by hand uses these vanishing point(s) vanishing point
Three-Point Perspective No principal face parallel to projection plane Three vanishing points for cube
Two-Point Perspective On principal direction parallel to projection plane Two vanishing points for cube
One-Point Perspective One principal face parallel to projection plane One vanishing point for cube
Advantages and Disadvantages Diminution: Objects further from viewer are projected smaller (Looks realistic) Nonuniform foreshortening: Equal distances along a line are not projected into equal distances Angles preserved only in planes parallel to the projection plane More difficult to construct by hand than parallel projections
Projections and Normaliation The default projection in the eye (camera) frame is orthogonal For points within the default view volume x p = x y p = y p =
Homogeneous Coordinate Representation default orthographic projection x p = x y p = y p = w p = 1 M = p p = Mp 1 1 1 In practice, we can let M = I and set the term to ero later
Simple Perspective Center of projection at the origin Projection plane = d, d <
Perspective Equations Top view Side view x / d x p = x / d y p = y / d p = d
Homogeneous Coordinate Form M = 1/ 1 1 1 d consider q = Mp where 1 y x d y x / p = q =
Perspective Division However w 1, so we must divide by w to return from homogeneous coordinates This perspective division yields x p = x / d y p = y / d p = d the desired perspective equations
Computer Viewing
Pipeline View MC Modeling WC Viewing VC Transformation Transformation Projection Transformation Normaliation and clipping Viewport PC NC Transformation DC Let s skip the clipping details temporarily!
Computer Viewing Three aspects of the viewing process implemented in the pipeline: Positioning the camera Setting the model-view matrix Selecting a lens Setting the projection matrix Clipping Setting the view volume
The OpenGL Camera In OpenGL, initially the object and camera frames are the same Default model-view matrix is an identity The camera is located at origin and points in the negative direction OpenGL also specifies a default view volume that is a cube with sides of length 2 centered at the origin Default projection matrix is an identity
Moving the Camera Frame If we want to visualie object with both positive and negative values we can either Move the camera in the positive direction Translate the camera frame Move the objects in the negative direction Translate the world frame Both of these views are equivalent and are determined by the model-view matrix Want a translation (gltranslatef(.,.,- d);) d >
Moving Camera back from Origin default frames frames after translation by d d >
Moving the Camera We can move the camera to any desired position by a sequence of rotations and translations Example: side view Rotate the camera Move it away from origin Model-view matrix C = TR
glulookat gllookat(eyex, eyey, eye, atx, aty, at, upx, upy, up)
By Coordinate Transformations 1 1 1 vc vc vc y y y x x x wc wc wc y x w v u w v u w v u y x x (1,,) y (, 1, ) (,,1) u v w u (u x, u y, u ) optic axis v (v x, v y, v ) w (w x, w y, w ) c 1 1 1 1 1 1 vc vc vc y x vc vc vc y x c c c y x
Taking Clipping into Account After the view transformation, a simple projection and viewport transformation can generate screen coordinate. However, projecting all vertices are usually unnecessary. Clipping with 3D volume. Associating projection with clipping and normaliation. Why do we use normaliation?
Orthogonal Viewing Volume
Orthogonal Normaliation glortho(left,right,bottom,top,near,far) normaliation find transformation to convert specified clipping volume to default (x wmax, y wmax, far ) Y norm (1, 1, 1) Z norm x norm (x wmin, y wmin, near ) Z view Y view x view (-1, -1, -1)
Orthogonal Matrix Two steps T: Move center to origin S: Scale to have sides of length 2 P = ST = xw max 2 xw min yw max 2 yw min near 2 far xw xw yw yw max max max max near near xw xw yw yw 1 far far min min min min
Clipping for Perspective Views
Perspective Viewing Volume
Normaliation Rather than derive a different projection matrix for each type of projection, we can convert all projections to orthogonal projections with the default view volume This strategy allows us to use standard transformations in the pipeline and makes for efficient clipping
Normaliation
Perspective-Projection Trans. P= (x, y, ) y view (x p, y p, vp ) x view view (x prp, y prp, prp ) x y x y p p p p (1 u) x ux (1 u) y uy x prp y prp prp prp vp vp x y View plane prp prp prp prp vp prp u = ~ 1 vp prp Given x prp =y prp = prp =, vp = near x y p p x near y near
Perspective-Projection Trans. t s t s y y x x p near p near p 1 near near pers t s M After perspective division, the point (x,y,,1) goes to To make -1 p 1 far near far near far near far near t s 2
Perspective-Projection Trans. Distorted object far near xw min xw max xw min original clipping volume xw max original object new clipping volume
1 2 far near far near far near far near near near pers M Further Normaliation 1 2 2 2 min max min max far near far near far near far near near near normpers yw yw xw xw M original object -1 1 far near
Notes Normaliation let us clip against a simple cube regardless of type of projection Delay final projection until end Important for hidden-surface removal to retain depth information as long as possible
Normaliation and Hidden- Surface Removal if 1 > 2 in the original clipping volume then the for the transformed points 1 < 2 Hidden surface removal works if we first apply the normaliation transformation However, the formula = -(s +t /) implies that the distances are distorted by the normaliation which can cause numerical problems especially if the near distance is small
Why do we do it this way? Normaliation allows for a single pipeline for both perspective and orthogonal viewing We stay in four dimensional homogeneous coordinates as long as possible to retain threedimensional information needed for hiddensurface removal and shading Clipping is now easiler.
Viewport Transformation From the working coordinate to the coordinate of display device. (1,1) (,) (,) (-1,-1) By 2D scaling and translation (6,6) Next: clipping and normaliation!
APPENDIX
Using Field of View In addition to directly assigning the viewing frustum, assigning field of view may be more user-friendly. front plane aspect = w/h
Final Projection Set = Equivalent to the homogeneous coordinate transformation Hence, general orthogonal projection in 4D is 1 1 1 M orth = P = M orth ST
Oblique Parallel Projection
Oblique Parallel Projection Oblique Projection = Shear + Orthogonal Projection top view side view
Shear Matrix xy shear ( values unchanged) H(q,f) = 1 cot θ 1 cot φ 1 1 Projection matrix General case: P = M orth H(q,f) P = M orth STH(q,f)
More General Cases x p vp x V V px p y p vp y V V py p
More General Cases p py vp p p px vp p V V y y V V x x ) ( ) ( 1 1 1 1 p py vp p py p px vp p px oblique V V V V V V V V M oblique ortho norm norm oblique M M M,,
Equivalency
Effect on Clipping The projection matrix P = STH transforms the original clipping volume to the default clipping volume object top view = 1 DOP clipping volume near plane far plane x = -1 = -1 DOP x = 1 distorted object (projects correctly)