viewing in 3d - biuu.cs.biu.ac.il/~kapaho/cg/07_view3d.pdf · distance results with a perspective...
TRANSCRIPT
Viewing in 3D(Chapt. 6 in FVD, Chapt. 12 in Hearn & Baker)
Viewing in 3D vs. 2D
world
3D
2D
world Camera
2D 2D
Transformation Pipe-Line
world
Viewer
System
Body
System
Front-
Wheel
System
Modeling transformation
Viewing
transformation
Projection
Transformation
Transformation
To viewport
Transformation Pipe-Line
Viewing
Transformation
Modeling
Transformation
Workstation
Transformation
Modeling
Coordinates
World Coordinates
Viewing Coordinates
Device Coordinates
Projection
Transformation
Projection Coordinates
Specifying the Viewing
Coordinate System
yw
zw
xw
world
P0
xv
yv
zv
Viewer
System
Viewing Coordinates system,
P0, [xv, yv, zv].
Specifying the Viewing
Coordinate System
world
P0
xv
yv
zv
Viewer
System
A viewing plane (projection plane)
is set up perpendicular to zv and
aligned with (xv,yv).
Specifying the Viewing
Coordinate System
• Camera definition (1 option):
ywxw
zw
L
N
v
P
xv
yv
zv
P=(Px,Py,Pz) camera location.
L - is a point to look-at.
V - is the view-up vector. V
projection onto the view-plane is
directed up.
• How to form Viewing coordinate
system :
• The transformation, M, from world-
coordinate into viewing-coordinates
is:
• Defining the camera in OpenGL
glMatrixMode(GL_MODELVIEW);
glLoadIdentity(); # camera “looking” down
gluLookAt(Px,Py,Pz,Lx,Ly,Lz,Vx,Vy,Vz)
vvv
v
vvv XZY
ZV
ZVX
LP
LPZ
;;
TRP
P
P
zzz
yyy
xxx
Mz
y
x
z
v
y
v
x
v
z
v
y
v
x
v
z
v
y
v
x
v
1000
100
010
001
1000
0
0
0
Projections
• Viewing 3D objects on a 2D display
requires a mapping from 3D to 2D.
• Projectors are lines from the center
of projection through each point in
the object.
• A projection is formed by the
intersection of the projectors with a
viewing plane.
Center of
Projection
Projectors
• Center of projection at infinity
results with a parallel projection.
•A parallel projection preserves
relative proportions of objects, but
does not give realistic appearance
(commonly used in engineering
drawing).
• A center of projection at a finite
distance results with a perspective
projection.
• A perspective projection produces
realistic appearance, but does not
preserve relative proportions.
Parallel Projection
• Projectors are all parallel.
• Orthographic: Projectors are
perpendicular to the projection
plane.
• Oblique: Projectors are not
necessarily perpendicular to the
projection plane.
Orthographic Oblique
• If the viewing plane is aligned
with (xv,yv), orthographic
projection is performed by:
Orthographic Projection
11000
0000
0010
0001
1
0
1
0 v
v
v
v
v
p
p
z
y
x
y
x
y
x
P0
xv
yv
zv
(x,y,z) (x,y)
• Lengths and angles of faces
parallel to the viewing planes are
preserved (Plan View).
• Problem: 3D nature of projected
objects is difficult to deduce.
Oblique Projection
• Projectors are not perpendicular to
the viewing plane.
• Angles and lengths are preserved
for faces parallel to the plane of
projection.
• preserves 3D nature of an object.
yv
(x,y,z)
(x,y)
xv
(xp,yp)
=45o =30o
Cavalinear Projections (=45o) of a cube
for two values of angle (angle to the horizon)
1
1
1
1
1
1
Several Oblique Projections
Cavalinear projection :
– Preserves lengths of lines
perpendicular to the viewing
plane.
– 3D nature can be captured but
shape seems distorted.
– Can display a combination of
front, side, and top views.
=45o =30o
Cabinet Projections (= 63.4o) of a cube
for two values of angle (angle to horizon)
1
1
0.5 1
1
0.5
Several Oblique Projections
• Cabinet projection:
– lines perpendicular to the viewing
plane project at 1/2 of their length.
– A more realistic view than the
Cavalinear projection.
– Can display a combination of
front, side, and top views.
Perspective Projection• In a perspective projection, the center
of projection is at a finite distance from
the viewing plane.
• The size of a projected object is
inversely proportional to its distance
from the viewing plane.
• Parallel lines that are not parallel to the
viewing plane, converge to a vanishing
point.
Perspective Projection
• A vanishing point is the projection of a
point at infinity.
Z-axis vanishing pointy
x
z
Vanishing Points
• There are infinitely many general
vanishing points.
• There can be up to three principal
vanishing points (axis vanishing
points).
• Perspective projections are
categorized by the number of
principal vanishing points, equal
to the number of principal axes
intersected by the viewing plane.
• Most commonly used: one-point
and two-points perspective.
x
y
z
One point (z axis)
perspective projection
Two points
perspective projection
z axis
vanishing point.
x axis
vanishing point.
x
y
z
(x,y,z)
(xp,yp,0)
center of
projection
d
Perspective Projection
d – focal length
• Using similar triangles it follows:
dz
y
d
y
dz
x
d
x pp
;
d
x
-z
(x,y,z)
xp
0;;
ppp z
dz
ydy
dz
xdx
(0,0)
• Thus, a perspective projection
matrix is defined:
11
00
0000
0010
0001
d
M per
d
dz
y
x
z
y
x
d
PM per 0
111
00
0000
0010
0001
0;;
ppp z
dz
ydy
dz
xdx
Observations
• Mper is singular (|Mper|=0), thus Mper is
a many to one mapping.
• Points on the viewing plane (z=0) do
not change.
• The homogeneous coordinates of a
point at infinity directed to (Ux,Uy,Uz)
are (Ux,Uy,Uz,0). Thus, The vanishing
point of parallel lines directed to
(Ux,Uy,Uz) is at [dUx/Uz, dUy/Uz].
• When d, Mperspective Mortho
What is the difference between moving the center of
projection and moving the projection plane?
Center of Projection
zProjectionplane
Center of Projection
zProjectionplane
Center of Projection
zProjectionplane
Original
Moving the Center of Projection
Moving the Projection Plane
Summary
Planar geometric
projections
Parallel Perspective
OrthographicOblique
Cavalinear
Cabinet
Other
TopFront
Side Other
Two
point
One
point
Three
point
Demo
Viewing Window
• After objects were projected onto the
viewing plane, an image is taken from a
Viewing Window.
• A viewing window can be placed
anywhere on the view plane.
• In general the view window is aligned
with the viewing coordinates and is
defined by its extreme points: (l,b) and
(r,t)
yv
xv
zv
Viewing Volume
• Given the specification of the viewing
window, we can set up a Viewing
Volume.
• Only objects inside the viewing volume
will appear in the display, the rest are
clipped.
• In order to limit the infinite viewing volume
we define two additional planes: Near Plane
and Far Plane.
• Only objects in the bounded viewing volume
will appear.
• The near and far planes are parallel to the
viewing plane and specified by znear and zfar.
• A limited viewing volume is defined:
– For orthographic: a rectangular
parallelpiped.
– For oblique: an oblique parallelpiped.
– For perspective: a frustum.
zv
Near
Plane
Far
Plane
zv
Near
Plane
Far
Plane
• The Viewing Plane can be placed
anywhere along the Zv axis, as long it
does not contain the center of
projection.
zv
Near
Plane
Far
Plane
Defining the viewing Volume
zv
far
near
yv
xv
left
righttop
bottom
zv
far
near
yv
xv
left
righttop
bottom
Defining the Viewing Volume
• Definition for Orthographic Projection:
glMatrixMode(GL_PROJECTION) ;
glLoadIdentity(); # camera “looks” down.
glOrtho(l,r,b,t,n,f);
zv
far
near
yv
xv
left
righttop
bottom
• Definition for general Perspective Projection:
Note: near and far values are quantities, e.g. near=50.0 means that the near plane passes at Zv=-50.
zv
far
near
yv
xv
left
righttop
bottom
glMatrixMode(GL_PROJECTION) ;
glLoadIdentity();
glFrustum(l,r,b,t,n,f);
• Definition for standard Perspective Projection:
• Note: aspectRatio=w/h .
glMatrixMode(GL_PROJECTION) ;
glLoadIdentity();
gluPerspective(viewAngle,aspectRatio,n,f);
zv
far
near
yv
xv
h
w
OpenGL Transformation
Pipe-Line
Homogeneous coordinates
in World System
ModelView Matrix
Projection Matrix
Clipping
Viewport
Transformation
Viewing Coordinates
Projection Coordinates
Window Coordinates