Upload
others
View
4
Download
0
Embed Size (px)
Citation preview
Computer Graphics - Week 3Computer Graphics - Week 3
Bengt-Olaf SchneiderBengt-Olaf SchneiderIBM T.J. Watson Research CenterIBM T.J. Watson Research Center
© Bengt-Olaf Schneider, 1999Computer Graphics – Week 3
Questions about Last Week ?Questions about Last Week ?
© Bengt-Olaf Schneider, 1999Computer Graphics – Week 3
Overview of Week 3Overview of Week 3
Viewing transformationsProjectionsCamera models
© Bengt-Olaf Schneider, 1999Computer Graphics – Week 3
Viewing TransformationViewing Transformation
© Bengt-Olaf Schneider, 1999Computer Graphics – Week 3
Viewing Compared to Taking PicturesViewing Compared to Taking Pictures
Field of View
View Vector & Viewplane: Direct camera towards subjectViewpoint: Position "camera" in sceneUp Vector: Level the cameraField of View: Adjust zoomClipping: Select content Projection: Exposure
© Bengt-Olaf Schneider, 1999Computer Graphics – Week 3
Viewing TransformationViewing Transformation
Position and orient cameraSet viewpoint, viewing direction and upvector
Use geometric transformation to positioncamera with respect to the scene or ...scene with respect to the camera.Both approaches are mathematically equivalent.
© Bengt-Olaf Schneider, 1999Computer Graphics – Week 3
ModelingTransformation
ViewingTransformation
PerspectiveTransformation
PerspectiveDivision
ViewportMapping
World Coordinates (WC)
Eye (Viewing)Coordinates (EC)
PerspectiveCoordinates (PC)
Normalized DeviceCoordinates (NDC)
DeviceCoordinates (DC)
ModelCoordinates (MC)
Viewing Pipeline and Coordinate SystemsViewing Pipeline and Coordinate Systems
Modeling TransformationPosition objects in world coordinates
Viewing TransformationPosition objects in eye/camera coordinates
EC a.k.a. View Reference CoordinatesEC a.k.a. View Reference Coordinates
Perspective TransformationConvert view volume to a canonical view volumeAlso used for clipping
PC a.k.a. clip coordinatesPC a.k.a. clip coordinates
Perspective DivisionPerform mapping from 3D to 2D
Viewport MappingMap normalized device coordinates intowindow/screen coordinates
© Bengt-Olaf Schneider, 1999Computer Graphics – Week 3
Why a special eye coordinate system ?Why a special eye coordinate system ?
In prinicipal it is possible to directly project on an arbitray viewplane. However, this is computationally very involved.
Instead, the scene is transformed into special coordinate system, that makes projection easy.
View down the negative z-axisProjection plane parallel to z=0
This "extra" transformation is free !It can be combined with the modeling transformationTherefore, every point must be transformed only once.This transformation is known in OpenGL as the Model-View Matrix.
© Bengt-Olaf Schneider, 1999Computer Graphics – Week 3
Model, World and Eye CoordinatesModel, World and Eye Coordinates
1 2 3 4 5 6 7 8 x
y
12345678
1 2 3 4 5 6 7 8 x
y
12345678
12
34
56
78
x
y
12345678
WC
MC
EC
P
P = (2.00, 1.00)P = (5.00, 4.00)P = (1.77, 12.90)
MC
WC
EC
© Bengt-Olaf Schneider, 1999Computer Graphics – Week 3
Computing the Viewing TransformationComputing the Viewing Transformation
Changing from WC to EC is simple change of coordinate systems which can be expressed using a 4x4 matrix:
WiEC is unit vector on the WC i-axis expressed in ECWoEC is the WC origin expressed in ECMME is the Model-View Matrix.
Same approach for changing from MC to WC
P M P
M Wx Wy Wz WoEC WE WC
WE EC EC EC EC
= •= b g
© Bengt-Olaf Schneider, 1999Computer Graphics – Week 3
Computing the Viewing Transformation: Computing the Viewing Transformation: ExampleExample1 0 0 21 0 98
0 1 0 98 0 21
0 0 325 17 00
0 21 0 98 3250 98 0 21 17 000 0 1
1 0 30 1 30 0 1
0 21 0 98 0 320 98 0 21 14 690 0 1
0 21 0 98 0 320 98 0 21 14 690 0 1
b g b gb g b gb g b g
WC
T
EC
T
WC
T
EC
T
WC
T
EC
T
= −
=
= −
=−
−FHGG
IKJJ
=FHGG
IKJJ
= • = −FHGG
IKJJ
= • = −F
. .
. .
. .
. . .. . .
. . .. . .
. . .. . .
M
M
M M M
P M P
WE
MW
ME WE MW
E ME M
HGG
IKJJ•
FHGG
IKJJ=
FHGG
IKJJ
2 01010
17212 94
1
...
..
1 2 3 4 5 6 7 8 x
y
12345678
1 2 3 4 5 6 7 8 x
y
12345678
12
34
56
78
x
y
12345678
WC
MC
EC
P
P = (2.00, 1.00)P = (5.00, 4.00)P = (1.77, 12.90)
M
W
E
© Bengt-Olaf Schneider, 1999Computer Graphics – Week 3
ProjectionProjection
© Bengt-Olaf Schneider, 1999Computer Graphics – Week 3
Projection: OverviewProjection: Overview
Now, the scene is transformed to the EC system
Next, the scene must be projected onto the view plane
This is done in several stepsSelecting the projection typeSelecting center/direction of projectionComputing the view volume Transforming the view volume into a canonical representationProjection onto the viewplane
© Bengt-Olaf Schneider, 1999Computer Graphics – Week 3
Projection: IntroductionProjection: IntroductionProjections map points from n dimensions to m dimensions, with m < n.
Here: from 3D to 2DPoints are projected along straight lines, called projectors, onto the projection plane
Perspective projection: projectors go through a single pointParallel projection: projectors are parallel
Center ofProjection
Direction ofProjection
Projector
Projector
ProjectionPlane
ProjectionPlane
© Bengt-Olaf Schneider, 1999Computer Graphics – Week 3
Parallel Projection: PropertiesParallel Projection: Properties
Objects appear at the same size irrespective of distance
Lines map into linesMaintains distances but not angles
Angles only maintained for lines parallel to the viewplaneHowever, parallel lines remain parallel
© Bengt-Olaf Schneider, 1999Computer Graphics – Week 3
Parallel Projection: OrthographicParallel Projection: Orthographic
Projectors are perpendicular to the viewplane
Frequently used orthographic projections have a viewplane perpendicular to a principal axis
front elevationtop elevation (plan view)side elevation
Front-view
Top-view(Plan-view)
Side-view
© Bengt-Olaf Schneider, 1999Computer Graphics – Week 3
Parallel Projection: OrthographicParallel Projection: Orthographic
Axonometric orthographic projections have a viewplane that is not perpendicular to a principal axis
Show more than one sideUniform foreshortening, i.e. unlike perspective projection does not depend on depth of a pointIsometric projection is an axonometric projection where viewplane has same angle with all axes
© Bengt-Olaf Schneider, 1999Computer Graphics – Week 3
Parallel Projection: ObliqueParallel Projection: Oblique
Projectors are not perpendicular to the viewplaneFor viewplane perpendicular to an axisCombination of plan-view projection and axonometric projectionShows faces parallel to viewplane with proper length and anglesUniform foreshortening of faces non-parallel to viewplane
α
© Bengt-Olaf Schneider, 1999Computer Graphics – Week 3
Parallel Projection: ObliqueParallel Projection: Oblique
Angle between viewplane and projectors determines foreshortening
45 degrees: Cavalier projectionAll axis appear at true lengthAll axis appear at true lengthEasy to measure lengths, but looks unrealisticEasy to measure lengths, but looks unrealistic
63.4 degrees: Cabinet projectionLines perpendicular to the viewplane are shortened to half lengthLines perpendicular to the viewplane are shortened to half lengthCloser to perspective displayCloser to perspective display
63.4o 45o1 ½ 1 1
© Bengt-Olaf Schneider, 1999Computer Graphics – Week 3
Perspective Projection: PropertiesPerspective Projection: Properties
Distant objects appear smaller than close onesPerspective foreshortening
Lines map into lines
Distances and angles are not maintainedIn particular parallel line do not remain parallelAngles are maintained only for lines parallel to the view plane
© Bengt-Olaf Schneider, 1999Computer Graphics – Week 3
Perspective Projections: Vanishing PointsPerspective Projections: Vanishing Points
Parallel lines not parallel to the view plane intersect in a single point: the vanishing point for those lines
Vanishing points can be used to construct perspective drawings
VanishingPoint
© Bengt-Olaf Schneider, 1999Computer Graphics – Week 3
Perspective Projection: Vanishing PointsPerspective Projection: Vanishing Points
Lines parallel to one of the axes converge in a principal vanishing point
Number of principal vanishing points equals the number of axes intersected by the view plane.
In 3D there are up to 3 prinicipal vanishing points.Most frequently used are 1 and 2 vanishing pointsThree vanishing points add little realism over two vanishing points
© Bengt-Olaf Schneider, 1999Computer Graphics – Week 3
Perspective Projection:Perspective Projection:One-point PerspectiveOne-point Perspective
X
Y
Z
© Bengt-Olaf Schneider, 1999Computer Graphics – Week 3
Perspective Projection: 1 Vanishing PointPerspective Projection: 1 Vanishing Point
VanishingPoint
© Bengt-Olaf Schneider, 1999Computer Graphics – Week 3
Perspective Projection:Perspective Projection:Two-Point PerspectiveTwo-Point Perspective
X
Y
Z
© Bengt-Olaf Schneider, 1999Computer Graphics – Week 3
Perspective Projection: 2 Vanishing PointsPerspective Projection: 2 Vanishing Points
© Bengt-Olaf Schneider, 1999Computer Graphics – Week 3
Perspective Projection: 3 Vanishing PointsPerspective Projection: 3 Vanishing Points
© Bengt-Olaf Schneider, 1999Computer Graphics – Week 3
Projection Types: SummaryProjection Types: Summary
Planar Geometric Projections
Parallel Projections Perspective Projections
Orthographic Oblique
CavalierCabinet
Axonometric
Top View
Side ViewFront View
Axis-Parallel
DimetricTrimetricIsometric
One-Point PerspectiveTwo-Point PerspectiveThree-Point Perspective
© Bengt-Olaf Schneider, 1999Computer Graphics – Week 3
Projections: Mathematical TreatmentProjections: Mathematical Treatment
How can we describe all these types of projections ?
Overview:Define a suitable coordinate systemCompute the mapping of points from 3-space on the viewplaneDetermine matrix form
© Bengt-Olaf Schneider, 1999Computer Graphics – Week 3
Projection: Eye Coordinate SystemProjection: Eye Coordinate System
Viewplane: z=0Viewing direction down negative z-axis
Up vector: y-axis
Project onto z=0 plane XE
ZE
YE
Viewplane
ViewingDirectionUp-Vector
© Bengt-Olaf Schneider, 1999Computer Graphics – Week 3
Orthographic ProjectionOrthographic Projection
Projection by "dropping" z-coordinate
Projection along other axes can be achieved similarly.
This matrix will be the final part of all other projections.
P P
P M P
S E
S OZ E
=
F
H
GGGG
I
K
JJJJ•
= •
1 0 0 00 1 0 00 0 0 00 0 0 1
© Bengt-Olaf Schneider, 1999Computer Graphics – Week 3
Oblique Projections: 2D ExplanationOblique Projections: 2D Explanation
Two-step processOblique transformationShear along the x-axisOrthographic projection along the z-axis
X X
Z Z
α
αSH( )α
© Bengt-Olaf Schneider, 1999Computer Graphics – Week 3
Oblique Projection: 3D AnalysisOblique Projection: 3D Analysis
Y Y
Z Z1 1
a a
bf
b
X X
SH(a,b)
αβ
P P P
P SH M P M P
s E E
s OZ E ObZ E
=
F
H
GGGG
I
K
JJJJ•
F
H
GGGG
I
K
JJJJ• =
F
H
GGGG
I
K
JJJJ•
= • • = •
1 0 0 00 1 0 00 0 0 00 0 0 1
1 0 00 1 00 0 1 00 0 0 1
1 0 00 1 00 0 0 00 0 0 1
ab
ab
a b( , )
© Bengt-Olaf Schneider, 1999Computer Graphics – Week 3
Oblique Projection: 3D Analysis (cont'd)Oblique Projection: 3D Analysis (cont'd)
f
ab
ff
=
=
−−
F
H
GGGG
I
K
JJJJ=
F
H
GGGG
I
K
JJJJ
cot
cossin
βαα
(Foreshortening factor)
M ObZ
1 0 00 1 00 0 0 00 0 0 1
1 0 00 1 00 0 0 00 0 0 1
Y Y
Z Z1 1
a a
bf
b
X X
SH(a,b)
αβ
© Bengt-Olaf Schneider, 1999Computer Graphics – Week 3
The two-step process is also used with other projections, in particular with perspective projection.
First projection transformation, i.e. distortion of objectsThen, orthographic projection
This a typical divide-and-conquer approachPartition problem into simpler subproblems
Two-Step ProcessTwo-Step Process
© Bengt-Olaf Schneider, 1999Computer Graphics – Week 3
We will look at a simple and common case Viewplane at z = 0Center of projection at z = dThis can always be ensured with the appropriate combination of viewing and projection transformations !
Analysis of a general projectionCenter of projection off the z-axisLine through center of projection and center of window not perpendicular to viewplaneParallel and perspective projections
See Foley et al. or backup charts at the end of this chart set.
Perspective ProjectionPerspective Projection
© Bengt-Olaf Schneider, 1999Computer Graphics – Week 3
Perspective TransformationPerspective Transformationxx
dd z
yy
dd z
xxz d
yyz d
zzz d
d
' '
'/
'/
/
=−
=−
⇔
=−
=−
−
=
−
F
H
GGGG
I
K
JJJJ•
= •
;
;
'=/
1 1
1
1 0 0 00 1 0 00 0 1 00 0 1 1
By analogy we define
P' P
P' M PPER
Z
X
Y
P
P’
d
© Bengt-Olaf Schneider, 1999Computer Graphics – Week 3
Perspective ProjectionPerspective Projection
Perform orthographic projection after perspective transformation
P' M M P P POz PER= • • =
F
H
GGGG
I
K
JJJJ•
−
F
H
GGGG
I
K
JJJJ• =
−
F
H
GGGG
I
K
JJJJ•
1 0 0 00 1 0 00 0 0 00 0 0 1
1 0 0 00 1 0 00 0 1 00 0 1 1
1 0 0 00 1 0 00 0 0 00 0 1 1/ /d d
© Bengt-Olaf Schneider, 1999Computer Graphics – Week 3
Perspective Projection: Vanishing PointsPerspective Projection: Vanishing Points
Mapping of points at infinity
Note that the vanishing point for lines parallel to the direction of projection (z-axis) is reflection of the center of projection at the view plane.
VP M vpPER= •
F
H
GGGG
I
K
JJJJ=
−
F
H
GGGG
I
K
JJJJ•
F
H
GGGG
I
K
JJJJ=
−
F
H
GGGG
I
K
JJJJ⇒ =
−
FHGG
IKJJ
0010
1 0 0 00 1 0 00 0 1 00 0 1 1
0010
001
1
00
/ /d dd
© Bengt-Olaf Schneider, 1999Computer Graphics – Week 3
Perspective Transformation:Perspective Transformation:Space DistortionSpace Distortion
Remember: Perspective projection is a combination of perspective transformation and orthographic projection
Distant objects appear smallerLines along the viewing direction map into parallels to the z-axis.View frustum is transformed into a box
Space is increasingly "squashed" as z grows. Y Y
d -dZ Z
© Bengt-Olaf Schneider, 1999Computer Graphics – Week 3
Perspective Transformation:Perspective Transformation:Coordinate Mapping (1)Coordinate Mapping (1)
The perspective transformation remaps z !
P' M PPER= • ⇔
F
H
GGGG
I
K
JJJJ=
−
F
H
GGGG
I
K
JJJJ•
F
H
GGGG
I
K
JJJJ⇒
FHGG
IKJJ=
FHGG
IKJJ
= = − =−
=−
− ∞ → − →
''''
, ,
': ,
XYZW d
xyz
xyz
X WY WZ W
Z z W z d zzz d z d
z z d z d z
1 0 0 00 1 0 00 0 1 00 0 1 1 1
11
11 1
0 0 0 0
/
'''
'/ ''/ ''/ '
' ' / '/ / /
: , : , ': ,+ ∞ + ∞ → + ∞ − z d z d: , ': ,
© Bengt-Olaf Schneider, 1999Computer Graphics – Week 3
Perspective Transformation:Perspective Transformation:Coordinate Mapping (2)Coordinate Mapping (2)
The perspective transformation remaps z !Points between eye and projection plane (0 < z < d) map to behind the eye (z'>0).Points beyond the projection plane (z<0) map to -d < z' < 0.Points behind the eye (z > d) map to z' < -d.Points behind the eye wrap to in front of the eye !!
z
z’-d 0
0 d
© Bengt-Olaf Schneider, 1999Computer Graphics – Week 3
Perspective Transformation:Perspective Transformation:Coordinate Mapping (3)Coordinate Mapping (3)
The perspective transformation remaps z !Objects extending from behind the eye to in front of the eyeThis requires special attention unless any objects (or parts of objects) behind the eye are eliminated, i.e. clipped.Therefore, we introduce clip planes to reject points behind the eye.
z
z’-d 0
0 d
© Bengt-Olaf Schneider, 1999Computer Graphics – Week 3
Perspective Transformation:Perspective Transformation:Viewpoint at the Origin (1)Viewpoint at the Origin (1)
Transform coordinate system such,that z = d maps to z = 0.
Translate coordinate system by +d along the z-axis.
D
-D
Z Z
Y Y
P PP’ P’T (D)Z
© Bengt-Olaf Schneider, 1999Computer Graphics – Week 3
Perspective Transformation:Perspective Transformation:Viewpoint at the Origin (2)Viewpoint at the Origin (2)
Transform coordinate system such,that z = d maps to z = 0.
Translate coordinate system by +d along the z-axis.
~ ~ ~ ( )
~
/ /
P' M P M T P
M
PER PER Z
PER
= • = • •
=
−
F
H
GGGG
I
K
JJJJ•
F
H
GGGG
I
K
JJJJ=
−
F
H
GGGG
I
K
JJJJ
d
dd d
d
1 0 0 00 1 0 00 0 1 00 0 1 1
1 0 0 00 1 0 00 0 10 0 0 1
1 0 0 00 1 0 00 0 10 0 1 0
© Bengt-Olaf Schneider, 1999Computer Graphics – Week 3
ClippingClipping
Clipping is the process of eliminating parts of the scene outside the view volume.Clipping serves multiple purposes
Elimination of "fake" objects, that are wrapped in front of the eye by the perspective transformation.Reduction of geometry that is processed during rasterization.Prevention of numerical problems for objects outside the view volume.Decrease of visual clutter by removal of close and distant objects.
The view volume is delimited by clipping planes.Reasonable approximation to human view volume, that is described by overlapping view cones.Matches the view volume of a photographic camera.
© Bengt-Olaf Schneider, 1999Computer Graphics – Week 3
Clipping: View VolumeClipping: View Volume
Z
Y
Front Back
Top
Bottom
Z
Y
Front Back
Top
Bottom
Clipping planes define the extent of the view volume.Perspective view volume a.k.a. view frustumFront and back clipping planes a.k.a. hither and yon.Front and back clipping planes are optional.
© Bengt-Olaf Schneider, 1999Computer Graphics – Week 3
Clipping AlgorithmClipping Algorithm
Each object must be intersected with each clip plane.Many objects are delimited by edges or polygons.
Edge-plane intersection:Straight-forward processHowever, intersection of lines with arbitrary planes is compute-intensive.
Therefore, we define a canonical view volume.Intersection calculations are simplifiedTransformation to the canonical view volume is "free". It can be combined with the viewing transformation
© Bengt-Olaf Schneider, 1999Computer Graphics – Week 3
Computing a Canonical View VolumeComputing a Canonical View Volume
Definition of canonical view volumeTransformation of the view volume after viewing transformation into the canonical view volumeProcess is known as normalizing the view volume
Coordinates are called Normalized Device Coordinates (NDC)
Similar procedure for parallel and perspective projection
We will treat them separately
© Bengt-Olaf Schneider, 1999Computer Graphics – Week 3
Normalization: Parallel ProjectionNormalization: Parallel Projection
© Bengt-Olaf Schneider, 1999Computer Graphics – Week 3
Normalization: Parallel Projection (1)Normalization: Parallel Projection (1)
Axis-aligned box
Right, Left x = +/-1Top, Bottom y = +/-1Front, Back z = 0, -1
Much simpler intersection calculations.Cost of computing canonical view volume is amortized over many objects.
Z
Y
1
-1
-1
© Bengt-Olaf Schneider, 1999Computer Graphics – Week 3
Normalization: Parallel Projection (2)Normalization: Parallel Projection (2)View volume after viewing transformation:
Viewing direction along negative z-axisClip planes asymmetric around z-axis and not aligned with z = 0.
X and Y clipping planes define a window.
Center of the window may be displaced from the origin.Width and height determine the window aspect ratio.The window will eventually get mapped to the viewport.
Z
X
Y
Center ofwindow
© Bengt-Olaf Schneider, 1999Computer Graphics – Week 3
Normalization: Parallel Projection (3)Normalization: Parallel Projection (3)
Steps to create the canonical view volume from the view volume after the viewing transformation:
Translate the view volume such that the front clipping plane lies in the plane z = 0.Translate and scale such that the other clip planes become the canonical clip planes.
Z ZZ
Y YY
-1 -1-1
-1 -1-1
1 11
T S
© Bengt-Olaf Schneider, 1999Computer Graphics – Week 3
Normalization: Parallel Projection (4)Normalization: Parallel Projection (4)
N S TPAR = • =
F
H
GGGG
I
K
JJJJ•
−−−
F
H
GGGG
I
K
JJJJ=
−−−
F
H
GGGG
I
K
JJJJ
2 0 0 00 2 0 00 0 1 00 0 0 1
1 0 00 1 00 0 10 0 0 1
2 0 0 20 2 0 20 0 10 0 0 1
//
/
/ // /
/ /
WH
D
CCC
W C WH C H
D C D
X
Y
Z
X
Y
Z
Center of window is at C = (CX, CY, CZ)T
Window has the dimensions W x H x DThen we get for the normalization transformation:
© Bengt-Olaf Schneider, 1999Computer Graphics – Week 3
Normalization: Perspective ProjectionNormalization: Perspective Projection
© Bengt-Olaf Schneider, 1999Computer Graphics – Week 3
Normalization: Perspective Projection (1)Normalization: Perspective Projection (1)
Truncated pyramid with tip at the origin
Right, Left x = +/-zTop, Bottom y = +/-zFront, Back z = zMIN, -1 Z
Y
-1
1
zMIN
-1
© Bengt-Olaf Schneider, 1999Computer Graphics – Week 3
Normalization: Perspective Projection (2)Normalization: Perspective Projection (2)View volume after viewing transformation:
Viewing direction along negative z-axisClip planes asymmetric around z-axis and not aligned with z = 0.
X and Y clipping planes define a window.
Center of the window may be displaced from the origin.Width and height determine the window aspect ratio.The window will eventually get mapped to the viewport.
Z
X
Y
Center ofwindow
© Bengt-Olaf Schneider, 1999Computer Graphics – Week 3
Normalization: Perspective Projection (3)Normalization: Perspective Projection (3)
Steps to create the canonical view volume from the view volume after the viewing transformation:
Translate the view volume such that the center of projection lies at the originTranslate and scale such that the other clip planes become the canonical clip planes.
Z ZZ
Y YY
-1-1
-1 -1-1
1 11
T S
© Bengt-Olaf Schneider, 1999Computer Graphics – Week 3
Normalization: Perspective Projection (4)Normalization: Perspective Projection (4)
N S TPER = • =
F
H
GGGG
I
K
JJJJ•
−
F
H
GGGG
I
K
JJJJ=
−
F
H
GGGG
I
K
JJJJ
2 0 0 00 2 0 00 0 1 00 0 0 1
1 0 0 00 1 0 00 0 10 0 0 1
2 0 0 00 2 0 00 0 10 0 0 1
//
/
//
/ /
WH
D d
WH
D d D
Center of projection is at originWindow has the dimensions W x H x DThen we get for the normalization transformation:
© Bengt-Olaf Schneider, 1999Computer Graphics – Week 3
Perspective Division (1)Perspective Division (1)
After normalization, perspective transformation turns the canonical viewing frustum into a axis-aligned box.We would like to convert that box into the canonical view volume for the parallel projection. First: Compute z'MIN ...
-1 -1Z Z
Y Y
-1 -1
1 1
MPER
z’MIN
© Bengt-Olaf Schneider, 1999Computer Graphics – Week 3
~M PER • =
=
−
F
H
GGGG
I
K
JJJJ•
−−
F
H
GGGG
I
K
JJJJ=
−+ + +− − −
F
H
GGGG
I
K
JJJJ
CP - top, CP - bot, CP - front, CP - back for b g d
x x x xz z y y
z z z
x x x xz z y y
z z zz z z
MIN MIN
MIN
1
1 0 0 00 1 0 00 0 1 10 0 1 0
11 1 1 1
1 1 1 01
Top: y = 1Bottom: y = -1Front: z = -(zN+1)/zN
Back: z = 0
Perspective Division (2)Perspective Division (2)
© Bengt-Olaf Schneider, 1999Computer Graphics – Week 3
Perspective Division (3)Perspective Division (3)
No adjustment of necessary for X and Y dimensions
Z dimension:Near clip plane farther from viewer than far clip planZ orientation reversed
Depth range not 0 ... -1-(z-(zMINMIN+1)/z+1)/zMINMIN = -1 - 1/z= -1 - 1/zMINMIN < -1 for 0 > z< -1 for 0 > zMINMIN > -1 > -1
Steps:Reverse orientation by reflection on z=0 and scale to depth = 1Transform so that near clip plane maps to z=0
© Bengt-Olaf Schneider, 1999Computer Graphics – Week 3
Perspective Division (4)Perspective Division (4)M T S MZ PER= • •
=−
F
H
GGGG
I
K
JJJJ•
+
F
H
GGGG
I
K
JJJJ•
−
F
H
GGGG
I
K
JJJJ=
+−
+−
F
H
GGGG
I
K
JJJJ
~
1 0 0 00 1 0 00 0 1 10 0 0 1
1 0 0 00 1 0 00 0
10
0 0 0 1
1 0 0 00 1 0 00 0 1 10 0 1 0
1 0 0 00 1 0 00 0
11 1
0 0 1 0
zz z
zz
MIN
MIN MIN
MIN
MIN
-1 1 -1Z Z Z
Y Y Y
-1 -1 -1
1 1 1
z’MIN
S TZ
© Bengt-Olaf Schneider, 1999Computer Graphics – Week 3
Viewport Mapping (1)Viewport Mapping (1)
Now both, parallel and perspective transformation have yielded the same normalized view volume.Final step: Map the normalized device coordinates to screen coordinates
Terminology (to be consistent with the textbook)Window: Rectangle in World-coordinates describing (together with the projection) which objects are visible
Do not confuse with on-screen windows, managed by the window manager !!!Do not confuse with on-screen windows, managed by the window manager !!!
Viewport: On-screen rectangle describing where the image will appear on the screen
© Bengt-Olaf Schneider, 1999Computer Graphics – Week 3
Viewport Mapping (2)Viewport Mapping (2)
Window in world coordinates:Width WW and Height HW
Aspect ratio AW = WW / HW
Viewport in screen coordinates:Width WV and Height HV
Aspect ratio AV = WV / HV
Window aspect ratio should be maintainedIf the aspect ratios are not equal, several choices
Fit the window into the viewport, leaving part of the viewport emptyFill the the viewport, clipping off parts of the window
© Bengt-Olaf Schneider, 1999Computer Graphics – Week 3
Viewport Mapping (3)Viewport Mapping (3)
Transformation to the canonical view volume has destroyed the window aspect ratio (now: unit square)Window aspect ratio can be restored by non-uniform scaling of the unit square.
Steps:Restore window aspect ratio (normalized device coordinates)Compare with viewport aspect ratioDetermine appropriate scale factor (device coordinates)Translate adjusted window to viewport
© Bengt-Olaf Schneider, 1999Computer Graphics – Week 3
Viewport Mapping (4)Viewport Mapping (4)
M T S SNV V N= • • =FHGG
IKJJ•
FHGG
IKJJ•
FHGG
IKJJ=
FHGG
IKJJ
1 00 10 0 1
0 00 1 00 0 1
1 0 00 1 00 0 1
00 10 0 1
vv
W WA
W W vA v
X
Y
V W
W
V W X
V Y
//
//
Assuming that AW > 1 and that WV/WW < HV/HW
Center of viewport at (vX, vY)
Sometimes screen coordinates are left-handed coordinate systems, e.g. origin at top-right corner and z-axis pointing out of the screen.
Then the y-axis must be reflected during the viewport mapping.
© Bengt-Olaf Schneider, 1999Computer Graphics – Week 3
That's basically it !That's basically it !
To summarize ...
© Bengt-Olaf Schneider, 1999Computer Graphics – Week 3
Modeling and ViewingModeling and Viewing
ModelingTransforms objects from local model coordinates to world coordinatesTypically done with linear transformations
ViewingPlaces and orients the camera in world coordinatesLook down negative z-axis of ECUp vector along y-axis of EC
© Bengt-Olaf Schneider, 1999Computer Graphics – Week 3
ClippingClipping
Clip planes define a view volumeClipping intersects objects with view frustum
Clipping occurs in normalized device coordinatesCanonical view volume is delimited by planes parallel or at 45O angle to coordinate axes Canonical view volume facilitates clipping
© Bengt-Olaf Schneider, 1999Computer Graphics – Week 3
Projection and Viewport MappingProjection and Viewport Mapping
Perspective TransformationDistort objects such that view volume becomes a rectilinear boxRemap the transformed the perspective canonical view volume into the parallel canonical view volume.
Parallel Projection"Drop" the z-coordinate, i.e. project onto z=0.
Viewport MappingMap the projected scene from normalized device coordinates to screen coordinatesMap the projected scene from normalized device coordinates to screen coordinates
© Bengt-Olaf Schneider, 1999Computer Graphics – Week 3
OpenGLOpenGL
© Bengt-Olaf Schneider, 1999Computer Graphics – Week 3
OpenGL: Rendering PipelineOpenGL: Rendering Pipeline
Model-ViewMatrix
ProjectionMatrix
PerspectiveDivision
ViewportMapping
EyeCoordinates
ObjectCoordinates
ClipCoordinates
Normalized DeviceCoordinates
ScreenCoordinates
Very similar to our discussion of the various transformations
Single step for modeling + viewing transformation
World coordinates are not explicitely specified
Projection Matrix creates canonical view volume
© Bengt-Olaf Schneider, 1999Computer Graphics – Week 3
OpenGL: Viewing TransformationOpenGL: Viewing Transformation
All modeling transformationsglRotate(), glTranslate(), glScale(), glLoadMatrix(), ...
gluLookAt()Specifies in current coordinate system: viewpoint, look-at point and up-vectorViewpoint and Look-at point specify viewing directionCan be re-implemented using standard modeling transformations
© Bengt-Olaf Schneider, 1999Computer Graphics – Week 3
OpenGL: ProjectionsOpenGL: Projections
glOrtho()Specifies orthographic view volume, delimited by 6 clip planes
glFrustum()Specifies perspective view volume as the position and size of the near clip window (and implicitely the viewpoint).
gluPerspective()Wrapper around glFrustum() to more conveniently define a perspective view volume based on ...field of view and aspect ratio of the view volumedistance of the near and far clip planes
© Bengt-Olaf Schneider, 1999Computer Graphics – Week 3
SummarySummary
Mathematical description ofViewing TransformationsClipping VolumeProjections (parallel and perspective)Viewport mapping
© Bengt-Olaf Schneider, 1999Computer Graphics – Week 3
HomeworkHomework
OpenGL rendering primitivesFoley et al. Chapter 16
© Bengt-Olaf Schneider, 1999Computer Graphics – Week 3
Next Week ...Next Week ...
Lighting Models
I k I k I k IA A D i ii
l
S in
i
l
= ⋅ + ⋅ ⋅ ⋅ + ⋅ ⋅= =∑ ∑N L R Eb g b g
0 0
L RN
Eα α β
Object
ViewpointLight-source
N
II
IR
βαI
αR
© Bengt-Olaf Schneider, 1999Computer Graphics – Week 3
Backup ChartsBackup Charts
General Projection
© Bengt-Olaf Schneider, 1999Computer Graphics – Week 3
Projection: General Case (1)Projection: General Case (1)
Z
X
Y
PC
P’
zc
zz’=z
P
Viewplane at z=zP
Center of projection C off the z-axis
© Bengt-Olaf Schneider, 1999Computer Graphics – Week 3
Projection: General Case (2)Projection: General Case (2)P C P C z z
z z z z z
z zz z
z zz z
x x x x
xx x x x
x xz z
z zx z
xz z
x zz z
yy z
yz z
y zz z
P
P C C
P C
C
C
P C
C C
CC C
CP
P C
C
P C
C P
P C
C
P C
C P
P C
' ( ) '
' ( )
/
' ( )( )
'
= + − =⇒
= = + −⇒
= −−
= = −−
⇒= + −
= + − = + −
=+ −
− =+
−− ⋅
−
=+
−− ⋅
−
λ
λ
λ λ
λ
;
; Λ
ΛΛ Λ
ΛΛ
Λ Λ
Λ
1
1
Z
X
Y
PC
P’
zc
zz’=z
P
© Bengt-Olaf Schneider, 1999Computer Graphics – Week 3
x x zx
z zx zz z
y y zy
z zy zz z
z z z zz z
z z
zz
z zz zz z
wz
z zz
z z
C
P C
C P
P C
C
P C
C P
P C
P P PC
P C
P
P C
P C
P C
P C
C
P C
'
'
'
'
= ⋅ +−
− ⋅−
FHG
IKJ
= ⋅ +−
− ⋅−
FHG
IKJ
= = = ⋅ −−
= ⋅−
− ⋅−
FHG
IKJ
= =−
−−
1
1
1
1
Λ
Λ
ΛΛ Λ
Λ
Λ
P' P
P
P' P Pper
=
−−
−
−−
−
−−
−
−−
−
F
H
GGGGGGGGG
I
K
JJJJJJJJJ
•
=
− ⋅− ⋅− ⋅
−
F
H
GGGG
I
K
JJJJ•
= •
1 0
0 1
0 0
0 01
1 00 10 00 0 1
xz z
xz
z zy
z zy
zz z
zz z
zz
z z
z zz
z z
x d x z dy d y z dx d z z d
d z d
C
P CC
P
P C
C
P CC
P
P C
P
P CC
P
P C
P C
C
P C
C C P
C C P
P C P
C
/ // // /
/ /
Projection: General Case (3)Projection: General Case (3)
© Bengt-Olaf Schneider, 1999Computer Graphics – Week 3
Projection: General Case (4)Projection: General Case (4)
P' P P Pper= • =
− ⋅− ⋅− ⋅
−
F
H
GGGG
I
K
JJJJ•
= =
= =
= =
→ ∞
→ ∞
1 00 10 00 0 1
0 0 0
0 0
0 0 0
x d x z dy d y z dx d z z d
d z d
z C z
z C z z
z C d
C C P
C C P
P C P
C
P z
P z
P
/ // // /
/ /
lim
lim
Orthographic Projection:
Cavalier Projection:
Perspective Projection:
,
,
,
b gb g
b g
© Bengt-Olaf Schneider, 1999Computer Graphics – Week 3
Perspective Transformation: Clip PlanesPerspective Transformation: Clip Planes
How are the clip planes transformed by the perspective transformation ?
1 0 0 00 1 0 00 0 1 00 0 1 1 1 1 1 1
1 1 1 1
−
F
H
GGGG
I
K
JJJJ•
− ⋅ − ⋅ −F
H
GGGG
I
K
JJJJ=
− ⋅ − ⋅ −
− − − −
F
H
GGGGG
I
K
JJJJJ
/
( ) ( )
( ) ( )
d
x x x xy y a z d a z d
z z z z
x x x xy y a z d a z d
z z z zzd
zd
zd
zd
F B
F B
F B
Back CPFront CP
Bottom CPTop CP
© Bengt-Olaf Schneider, 1999Computer Graphics – Week 3
x dd z
x dd z
x dd z
x dd z
y dd z
y dd z
a d z dd z
a d z dd z
z dd z
z dd z
z dd z
z dd z
x x x xy y y y
z z z z
F B
F B
F
F
B
B
T B
F B
⋅−
⋅−
⋅−
⋅−
⋅−
⋅−
− ⋅ ⋅ −−
⋅ ⋅ −−
⋅−
⋅−
⋅−
⋅−
F
H
GGGGGG
I
K
JJJJJJ=FHGG
IKJJ
( ) ( )' ' ' '' ' ' '
' ' ' '
Perspective Transformation: Clip PlanesPerspective Transformation: Clip Planes
Plane at y = y'B
Plane at y = y'T
Plane at z = z'B
Plane at z = z'F