Introduction to Computer Graphics - CAIG...
Transcript of Introduction to Computer Graphics - CAIG...
Introduction to Computer Graphics5. Viewing in 3D (A)
National Chiao Tung Univ, TaiwanBy: I-Chen Lin, Assistant Professor
Textbook: Hearn and Baker, Computer Graphics, 3rd Ed., Prentice HallRef: E.Angel, Interactive Computer Graphics, 4th Ed., Addison Wesley
OutlineClassical views
Computer viewing
Projection matrices
Classical ViewingViewing requires three basic elements
One or more objectsA viewer with a projection surfaceProjectors 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 ProjectionsStandard projections project onto a plane.
Projectors are lines that eitherconverge at a center of projectionare parallel
Such projections preserve linesbut not necessarily angles
When do we need non-planar projections?
Classical Projections
Perspective vs ParallelClassical 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
parallel perspective
axonometricmultivieworthographic
oblique2 point1 point 3 point
planar geometric projections
isometric dimetric trimetric
Perspective Projection
Parallel Projection
Orthographic ProjectionProjectors are orthogonal to projection surface
Multiview Orthographic ProjectionProjection plane parallel to principal facesUsually form front, top, side views
isometric (not multivieworthographic view) front
side
in CAD and architecture, we often display three multiviews plus isometric
top
Advantages and DisadvantagesPreserves both distances and angles
Shapes preservedCan be used for measurements
Building plansManuals
Cannot see what object really looks like because many surfaces hidden from view
Often we add the isometric
Axonometric ProjectionsAllow projection plane to move relative to object
classify by how many angles ofa corner of a projected cube are the same
none: trimetrictwo: dimetricthree: isometric
θ 1θ 3θ 2
Types of Axonometric Projections
Advantages and DisadvantagesLines are scaled (foreshortened) but can find scaling factors
Lines preserved but angles are notProjection 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 ProjectionArbitrary relationship between projectors and projection plane
Perspective ProjectionProjectors coverage at center of projection
Vanishing PointsParallel 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 PerspectiveNo principal face parallel to projection planeThree vanishing points for cube
Two-Point PerspectiveOn principal direction parallel to projection planeTwo vanishing points for cube
One-Point PerspectiveOne principal face parallel to projection planeOne vanishing point for cube
Advantages and DisadvantagesDiminution:
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
Computer Viewing
Pipeline View
ModelingTransformation
ModelingTransformation
ViewingTransformation
ViewingTransformation
ProjectionTransformation
ProjectionTransformation
Normalizationand
clipping
Normalizationand
clipping
ViewportTransformation
ViewportTransformation
MC WC VC
PC NC DC
Let’s skip the clipping temporarily !
Computer ViewingThree aspects of the viewing process implemented in the pipeline:
Positioning the cameraSetting the model-view matrix
Selecting a lensSetting the projection matrix
ClippingSetting the view volume
The OpenGL CameraIn 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 z 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 FrameIf we want to visualize object with both positive and negative z values we can either
Move the camera in the positive z directionTranslate the camera frame
Move the objects in the negative z directionTranslate the world frame
Both of these views are equivalent and are determined by the model-view matrix
Want a translation (glTranslatef(0.0,0.0,-d);)d > 0
Moving Camera back from Origin
default frames
frames after translation by –dd > 0
Moving the CameraWe can move the camera to any desired position by a sequence of rotations and translations
Example: side viewRotate the cameraMove it away from originModel-view matrix C = TR
gluLookAtglLookAt(eyex, eyey, eyez, atx, aty, atz, upx, upy, upz)
Projections and NormalizationThe default projection in the eye (camera) frame is orthogonal For points within the default view volume
xp = xyp = yzp = 0
Homogeneous Coordinate Representation
default orthographic projectionxp = xyp = yzp = 0wp = 1
pp = Mp
⎥⎥⎥⎥
⎦
⎤
⎢⎢⎢⎢
⎣
⎡
1000000000100001
M =
In practice, we can let M = I and setthe z term to zero later
Simple PerspectiveCenter of projection at the originProjection plane z = d, d < 0
Perspective EquationsTop view Side view
dzx/
dzx/ dz
y/
xp = yp = zp = d
Homogeneous Coordinate Form
M =
⎥⎥⎥⎥
⎦
⎤
⎢⎢⎢⎢
⎣
⎡
0/100010000100001
d
⎥⎥⎥⎥
⎦
⎤
⎢⎢⎢⎢
⎣
⎡
dzzyx
/
consider q = Mp where
⎥⎥⎥⎥
⎦
⎤
⎢⎢⎢⎢
⎣
⎡
1zyx
⇒ q = p =
Perspective DivisionHowever w ≠ 1, so we must divide by w to return from homogeneous coordinatesThis perspective division yields
the desired perspective equations
dzx/ dz
y/
xp = yp = zp = d
Viewport TransformationFrom the working coordinate to the coordinate of display device.
(1,1)
(-1,-1)
(0,0)
(0,0)
(600,600)
By 2D scaling and translation
Next: clipping and normalization !