ComputerGraphics 3D Part2
ComputerGraphics 3D Part2
Computer Graphics
Module: 3D Graphics
P. J. Narayanan
Spring 2005
CS3500
1
3D Graphics: Objectives
• Representation and manipulation of 3D objects built using
3D primitives.
2D Graphics
• Draw on a 2D canvas using 2D primitives.
• View it frontally from a certain distance away.
• Only scaling and translation between canvas coordinates
and frame buffer coordinates.
• A window on the canvas is mapped to a window on
screen or frame buffer using the (window-to-)viewport
transformation.
• Translate to origin, scale to new size, translate to new
position.
CS3500 December 09, 2004
3
Perspective Effects
• Perspective distortion is relevant for 3D points.
3D Coordinates
• Cartesian: (x, y, z).
Z
• Polar: (ρ, θ, φ)
z
• z = ρ cos θ,
y = ρ sin θ sin φ P
x = ρ sin θ cos φ θ
ρ
y
Y
φ
• ρ2 = x2 + y 2 + z 2 ,
x
φ = tan−1(y/x),
p
−1
θ = tan ( x2 + y 2/z) X
Homogeneous Representation
• Convert to a 4-vector with a scale factor as fourth.
(x, y, z) ≡ [kx ky kz k]T for any k 6= 0.
Transformation
Matrices: Rotations
1 0 0 0
0 cos θ −sin θ 0
Rx(θ) = ,
0 sin θ cos θ 0
0 0 0 1
cos θ 0 sin θ 0 cos θ −sin θ 0 0
0 1 0 0 sin θ cos θ 0 0
Ry = , Rz =
−sin θ 0 cos θ 0 0 0 1 0
0 0 0 1 0 0 0 1
• RT and TR??
a t · r1
R 0 I b R t · r2
=
0 1 c t · r3
0 1 0 1
Commutativity
• Translations are commutative: T1T2 = T2T1.
• What is Rα(θ)?
• 3-step process:
1
• Net result: Rα(θ) = R−
αx Rx(θ)Rαx
β
α Y
γ
X P
Computing Rα
• First rotate by −β about X axis. Vector α would lie in the
XY plane, with tip at point P.
1
• Overall: Rαx = Rz(−γ)Rx(−β) and R−
αx = Rx (β)Rz (γ).
(0, 1, 1)
(1, 0, 1) (1, 1, 1)
(1, 1, 0) (1, 2 , 0)
(1, 0, 2) (0, 1, 1)
(1, 0, 1) (1, 1, 1)
(1, 1, 0)
• Apply Rα.
End of Class 7
3D Transformations
• Many ways to think about a given transform.
Another Example
Z Z
B
A
C
B’
Y A’ Y
C’
X X
Transforming Lines
• A composite transformation can be seen as changing
points in the coordinate system.
• These transformations preserve collinearity. Thus, points
on a line remain on a (transformed) line.
• Take two points on the line, transform them, and compute
the line between new points.
• Lines are defined as a join of 2 points or intersection of 2
planes in 3D. The same holds for transformed lines using
transformed points or planes!
Transforming Planes
• A plane is defined by a 4-vector n (called the normal
vector) in homogeneous coordinates.
• The plane consists of points p such that nTp = 0.
• Let Q transform n when points are transformed by M.
• Coplanarity is preserved: (Qn)TMp = 0 = nTQTMp.
• True when QTM = I, or Q = M−T.
• Q is the Matrix of cofactors of M in the general case when
M−1 doesn’t exist.
A Model
Building
WC
Floor2
M M
M Room1 Room1
M
Box
M M
Box M M M
End of Class 8
Obj N
Modlng N Projection
NC
Window Coords Viewport
Different Coordinates
• Object Reference: Object is described in an internal
coordinate frame called ORC.
• World: Common reference frame to describe different
objects, called WC.
• Camera/View Reference: Describe with respect to the
current camera position/orientation, called VRC.
• Normalized Projection: A standard space from which
projection is easy, called NPC.
• Screen: Coordinates in the output device space.
CS3500 January 03, 2005
30
Transformations
• Modelling: Convert from object coordinates to world
coordinates (ORC to WC).
• View Orientation or Viewing: From world coordinates to
camera coordinates (WC to VRC).
• Simple coordinate transformations.
• View Mapping or Projection: From VRC to Normalized
Coordinates (NC).
• Viewport: From NC to window coordinates.
• PVRC = V M PORC.
A Single Table
• A table defined in its own coordinate system.
Modelling
• Goal: Transform object coordinates to world coordinates.
aircraft. roll
pitch
• Controllers think in X
Z’
polar coordinates for
ρ θ
position and roll-pitch-
yaw for orientation. Y’
Hierarchy of Transformations
• A hierarchy of transformations needed to setup the world
and the camera.
• A humanoid robot could have a coordinate frame on its
body, another one on the shoulder, a third on the shoulder
that moves with the upper arm, a fourth on the elbow, a
fifth on the elbow that moves with the forearm, etc.
• Remember the wheel with an ant moving on its spoke!
Humanoid Robot
Scene Graph
T T
T T T
T T T T
Building
WC
Floor2
M M
M Room1 Room1
M
Box
M M
Box M M M
Modelling in OpenGL
• OpenGL has a single ModelView matrix M that
transforms points given by glVertex.
End of Class 9
Viewing Specification
• Camera center specified in world coordinates.
n
Z Up
C
Look
u
WC Y
X
Transformation Steps
How do we align WC to VRC?
Rotation
• Let l̄ = L̄/|L̄| and t̄ = Ū/|Ū| be the unit vectors in those
directions.
ρ θ
• What are the viewing
Y’
steps?
φ X’
v
u X
n
Z
CS3500 January 06, 2005
56
Polar View
el
az
• PVRC = V · M · PORC
End of Class 10
End of Class 11
Projections
• Projection involves projectors starting from 3D points and
hitting the 2D projection plane, forming the image of the
point.
Parallel Projections
• Orthographic: Projection plane is perpendicular to the
direction of projection.
? If direction of projection parallel to the axes:
plan, elevation, side elevation.
? If DoP (±1, ±1, ±1): isometric projection.
• Oblique: Otherwise.
? Cabinet when projectors make 45 degrees with the
projection plane.
? Cavalier when they make arctan(2) degrees with the
projection plane.
CS3500 January 20, 2005
67
Oblique Projections
• Projector angle φ and angle
with horizontal α.
• Cabinet: Length along the
depth axis preserved.
φ
• Cavalier: Length along depth α
axis halved. More realistic.
• α is between 30 and 45
degrees.
• Orthographic when φ = 90.
Orthographic Projections
Perspective Projections
• Can be characterized by
the number of vanishing
points. (projections of points
at infinity).
• Depends on the number of
axes the projection plane
intersects.
• 1-point, 2-point, and 3-point
perspective projections.
Another View
• If we shift the origin to lie on the projection plane, with the
CoP at (0, 0, −d), we get the matrix:
x 1 0 0 0 X
y 0 1 0 0 Y
=
z 0 0 0 0 Z
w 0 0 d1 1 1
Projections: Summary
Perspective
x 1 0 0 0 X Orthographic
y 0 1 0 0 Y
x 1 0 0 0 X
= y 0 1 0 0 Y
z 0 0 1 0 Z
=
z 0 0 0 0 Z
w 0 0 d1 0 1
w 0 0 d1 1 1
x 1 0 0 0 X
A special case of
y 0 1 0 0 Y
= perspective projection
z 0 0 0 0 Z
with CoP at infinity.
w 0 0 d1 1 1
Volume of Visibility
• Cameras have finite fields of view in horizontal and
vertical directions.
View Volume
f
b
l
n
r
Orthographic View Volume
CS3500 January 20, 2005
78
f
b
l
r
n
Perspective View Volume
• Needn’t be symmetric!
Alternate Specification
• Symmetric view volumes: horizontal and vertical fields of
view θh, θv
End of Class 12
Projections: Summary
Perspective Orthographic
x 1 0 0 0 X x 1 0 0 0 X
y 0 1 0 0 Y y 0 1 0 0 Y
= =
z 0 0 0 0 Z z 0 0 0 0 Z
w 0 0 d1 1 1 w 0 0 d1 1 1
d<∞ d=∞
• Needn’t be symmetric!
• Why?
? Easier to eliminate objects outside the view volume.
? Orthographic & perspective aren’t different.
? The z-coordinates not thrown away. (Used later!)
• Matrix??
• Matrix:
right+left
2
right−left 0 0 − right−left
0 2
top−bottom 0 − top+bottom
top−bottom
2
far+near
0 0 far−near far−near
0 0 0 1
x = far
z = far
θh / 2
45
x=1
z = −1
z = −1 z = −1
z=k
z=0
near
• The near plane is now at k = far
.
• View volume fits into the canonical view volume, but is
CS3500 January 24, 2005
92
0 0 −1 0
• Where do (x, y, -k) and (x, y,
-1) get transformed to?
• Frustum becomes a cube!
Actual Projection
• We have already performed the perspective division.
3D Module: Recapitulation
• 3D Graphics additionally involves projecting the 3D world
to the 2D image plane of the camera.
End of Class 13