Title: 3D Viewing Cont'
13D Viewing (Cont.)
- Credits Andries van Dam of Brown University,
Angel Book slides.
23D Viewing the Synthetic
Camera
- Programmers reference model for specifying 3D
view projection parameters to the computer - General synthetic camera each package has its
own but they are all (nearly) equivalent.
position of camera - orientation
- field of view (wide angle, normal)
- depth of field (near distance, far distance)
- focal distance
- tilt of view/film plane (if not normal to view
direction, produces oblique projections) - perspective or parallel projection? (camera near
objects or an infinite distance away)
3View Volumes
- A view volume contains everything visible from
the point of view or direction - what does the camera see?
- Conical view volumes
- approximates what eye sees
- expensive math (simultaneous quadratics) when
clipping objects against cones surface - Can approximate with rectangular cone instead
(called a frustum) - works well with a rectangular viewing window
- simultaneous linear equations for easy clipping
of objects against sides
4Graphics (rendering) pipeline
Viewing Geometry Processing World Coordinates
(floating point)
Rendering Pixel Processing Screen Coordinates
(integer)
Conservative VSD Selective traversal of object
database (or traverse scene graph to get CTM)
Transform Vertices To canonical view
volume
Light at Vertices Calculate light intensity at
vertices (lighting model of choice)
Conservative VSD Back-face Culling
Conservative VSD View Volume Clipping
Image- precision VSD Compare pixel
depth (Z-buffer)
Shading Interpolate color values (Gouraud) or
normals (Phong)
per polygon
per pixel of polygon
avd November 9,
2004 VSD 6/48
avd November 5,
2002 VSD 5/45
5View Volume
- We need to know six things about our synthetic
camera model in order to take a picture - Position of the camera (from where its looking)
- The Look vector specifies in what direction the
camera is pointing - The cameras Orientation is determined by the
Look vector and the angle through which the
camera is rotated about that vector, i.e., the
direction of the Up vector
Position
6View Volume
- Aspect ratio of the electronic film ratio of
width to height - Height angle determines how much of the scene we
will fit into our view volume larger height
angles fit more of the scene into the view volume
(width angle determined by height angle and
aspect ratio) - the greater the angle, the greater the amount of
perspective distortion - Front and back clipping planes limit extent of
cameras view by rendering (parts of) objects
lying between them and throwing away everything
outside of them
7Position
- Determining the Position is analogous to a
photographer deciding the vantage point from
which to shoot a photo - Three degrees of freedom x, y, and z coordinates
in 3-space - This x, y, z coordinate system is right-handed
if you open your right hand, align your palm and
fingers with the x axis, and curl your fingers
towards the y axis, your thumb will point along
the z axis
8Orientation
camera Position
- Orientation is specified by a point in 3D space
to look at (or a direction to look in) and an
angle of rotation about this direction - Default (canonical) orientation is looking down
the negative z-axis and up direction pointing
straight up the y-axis - In general the camera is located at the origin
and is looking at an arbitrary point with an
arbitrary up direction - This is a little abstracteasier formulation?
9Look and Up Vectors
- Look Vector
- the direction the camera is pointing
- three degrees of freedom can be any vector in
3-space - Up Vector
- determines how the camera is rotated around the
Look vector - for example, whether youre holding the camera
horizontally or vertically (or in between) - projection of Up vector must be in the plane
perpendicular to the look vector (this allows Up
vector to be specified at an arbitrary angle to
its Look vector)
Up vector
Projection of up vector
10View Angle
- Determines amount of perspective distortion in
picture, from none (parallel projection) to a lot
(wide-angle lens) - In a frustum, two viewing angles width and
height angles - Choosing View angle analogous to photographer
choosing a specific type of lens (e.g., a
wide-angle or telephoto lens)
11View Angle
- Lenses made for distance shots often have a
nearly parallel viewing angle and cause little
perspective distortion, though they foreshorten
depth - Wide-angle lenses cause a lot of perspective
distortion
Resulting picture
12Front and Back Clipping Planes
- Volume of space between Front and Back clipping
planes defines what camera can see - Position of planes defined by distance along Look
vector - Objects appearing outside of view volume dont
get drawn - Objects intersecting view volume get clipped
13Front and Back Clipping Planes
- Reasons for Front (near) clipping plane
- Dont want to draw things too close to the camera
- would block view of rest of scene
- objects would be prone to distortion
- Dont want to draw things behind camera
- wouldnt expect to see things behind the camera
- in the case of the perspective camera, if we were
to draw things behind the camera, they would
appear upside-down and inside-out because of
perspective transformation - Reasons for Back (far) clipping plane
- Dont want to draw objects too far away from
camera - distant objects may appear too small to be
visually significant, but still take long time to
render - by discarding them we lose a small amount of
detail but reclaim a lot of rendering time - alternately, the scene may be filled with many
significant objects for visual clarity, we may
wish to declutter the scene by rendering those
nearest the camera and discarding the rest
14View Volume Specification
- From Position, Look vector, Up vector, Aspect
ratio, Height angle, Clipping planes, and
(optionally) Focal length together specify a
truncated view volume - Truncated view volume is a specification of
bounded space that camera can see - 2D view of 3D scene can be computed from
truncated view volume and projected onto film
plane - Truncated view volumes come in two flavors
parallel and perspective
Truncated view volume means we only need to
render what the camera can see
15Truncated View Volume for
Orthographic Parallel Projection
- Limiting view volume useful for eliminating
extraneous objects - Orthographic parallel projection has width and
height view angles of zero
16Truncated View Volume
(Frustum) for Perspective
Projection
17Wheres My Film?
- Real cameras have a roll of film that captures
pictures - Synthetic camera film is a rectangle on an
infinite film plane that contains image of scene - Why havent we talked about the film in our
synthetic camera, other than mentioning its
aspect ratio? - How is the film plane positioned relative to the
other parts of the camera? Does it lie between
the near and far clipping planes? Behind them? - Turns out that fine positioning of Film plane
doesnt matter. Heres why - for a parallel view volume, as long as the film
plane lies in front of the scene, parallel
projection onto film plane will look the same no
matter how far away film plane is from scene - same is true for perspective view volumes,
because the last step of computing the
perspective projection is a transformation that
stretches the perspective volume into a parallel
volume - In general, it is convenient to think of the film
plane as lying at the far clip plane
18Sources
- Carlbom, Ingrid and Paciorek, Joseph, Planar
Geometric Projections and Viewing
Transformations, Computing Surveys, Vol. 10, No.
4 December 1978 - Kemp, Martin, The Science of Art, Yale University
Press, 1992 - Mitchell, William J., The Reconfigured Eye, MIT
Press, 1992 - Foley, van Dam, et. al., Computer Graphics
Principles and Practice, Addison-Wesley, 1995 - Wernecke, Josie, The Inventor Mentor,
Addison-Wesley, 1994
19The 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 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
20Default Projection
- Default projection is orthogonal
clipped out
2
z0
21Moving the Camera Frame
- If we want to visualize object with both positive
and negative z values we can either - Move the camera in the positive z direction
- Translate the camera frame
- Move the objects in the negative z direction
- Translate 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 gt 0
22Moving Camera back from Origin
frames after translation by d
d gt 0
23Moving 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
24OpenGL code
- Remember that last transformation specified is
first to be applied
glMatrixMode(GL_MODELVIEW) glLoadIdentity() glTra
nslatef(0.0, 0.0, -d) glRotatef(90.0, 0.0, 1.0,
0.0)
25The LookAt Function
- The GLU library contains the function gluLookAt
to form the required modelview matrix through a
simple interface - Note the need for setting an up direction
- Still need to initialize
- Can concatenate with modeling transformations
glMatrixMode(GL_MODELVIEW) glLoadIdentity() gluL
ookAt(1.0, 1.0, 1.0, 0.0, 0.0, 0.0, 0., 1.0. 0.0)
26gluLookAt
- glLookAt(eyex, eyey, eyez, atx, aty, atz, upx,
upy, upz)
27Other Viewing APIs
- The LookAt function is only one possible API for
positioning the camera - Others include
- View reference point, view plane normal, view up
(PHIGS, GKS-3D) - Yaw, pitch, roll
- Elevation, azimuth, twist
- Direction angles
28Projections and Normalization
- The default projection in the eye (camera) frame
is orthogonal - For points within the default view volume
- Most graphics systems use view normalization
- All other views are converted to the default view
by transformations that determine the projection
matrix - Allows use of the same pipeline for all views
xp x yp y zp 0
29Homogeneous Coordinate Representation
default orthographic projection
pp Mp
M
In practice, we can let M I and set the z term
to zero later
30Simple Perspective
- Center of projection at the origin
- Projection plane z d, d lt 0
31Perspective Equations
- Consider top and side views
xp
yp
zp d
32Homogeneous Coordinate Form
M
? p
q
33Perspective Division
- However w ? 1, so we must divide by w to return
from homogeneous coordinates - This perspective division yields
- the desired perspective equations
- We will consider the corresponding clipping
volume with the OpenGL functions
xp
yp
zp d
34- glMatrixMode(GL_PROJECTION)
- glLoadIdentity()
- Above commands affect the projection matrix.
- Purpose is to define a viewing volume (includes
type of projection) - glFrustum()
- gluPerspective()
- glOrtho()
35OpenGL Orthogonal Viewing
- glOrtho(left,right,bottom,top,near,far)
near and far measured from camera
36OpenGL Perspective
- glFrustum(left,right,bottom,top,near,far)
37Using Field of View
- With glFrustum it is often difficult to get the
desired view - gluPerpective(fovy, aspect, near, far) often
provides a better interface
front plane
aspect w/h
38Normalization
- 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
39Pipeline View
modelview transformation
projection transformation
perspective division
4D ? 3D
nonsingular
clipping
projection
3D ? 2D
against default cube
40Notes
- We stay in four-dimensional homogeneous
coordinates through both the modelview and
projection transformations - Both these transformations are nonsingular
- Default to identity matrices (orthogonal view)
- Normalization lets us clip against 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
41Orthogonal Normalization
- glOrtho(left,right,bottom,top,near,far)
normalization ? find transformation to
convert specified clipping volume to default
42Orthogonal Matrix
- Two steps
- Move center to origin
- T(-(leftright)/2, -(bottomtop)/2,(nearfar)/2))
- Scale to have sides of length 2
- S(2/(left-right),2/(top-bottom),2/(near-far))
P ST
43Final Projection
- Set z 0
- Equivalent to the homogeneous coordinate
transformation - Hence, general orthogonal projection in 4D is
Morth
P MorthST
44Simple Perspective
- Consider a simple perspective with the COP at the
origin, the near clipping plane at z -1, and a
90 degree field of view determined by the planes - x ?z, y ?z
45Perspective Matrices
- Simple projection matrix in homogeneous
coordinates - Note that this matrix is independent of the far
clipping plane
M
46Generalization
after perspective division, the point (x, y, z,
1) goes to
x x/z y y/z Z -(ab/z)
which projects orthogonally to the desired point
regardless of a and b
47Picking a and b
If we pick
a
b
the near plane is mapped to z -1 the far plane
is mapped to z 1 and the sides are mapped to x
? 1, y ? 1
Hence the new clipping volume is the default
clipping volume
48Normalization Transformation
distorted object projects correctly
original object
new clipping volume
49Normalization and Hidden-Surface Removal
- Although our selection of the form of the
perspective matrices may appear somewhat
arbitrary, it was chosen so that if z1 gt z2 in
the original clipping volume then the for the
transformed points z1 gt z2 - Thus hidden surface removal works if we first
apply the normalization transformation - However, the formula z -(ab/z) implies that
the distances are distorted by the normalization
which can cause numerical problems especially if
the near distance is small
50OpenGL Perspective
- glFrustum allows for an unsymmetric viewing
frustum (although gluPerspective does not)
51OpenGL Perspective Matrix
- The normalization in glFrustum requires an
initial shear to form a right viewing pyramid,
followed by a scaling to get the normalized
perspective volume. Finally, the perspective
matrix results in needing only a final orthogonal
transformation
P NSH
our previously defined perspective matrix
shear and scale
52Why do we do it this way?
- Normalization allows for a single pipeline for
both perspective and orthogonal viewing - We stay in four dimensional homogeneous
coordinates as long as possible to retain
three-dimensional information needed for
hidden-surface removal and shading - We simplify clipping
53Graphics (rendering) pipeline
Viewing Geometry Processing World Coordinates
(floating point)
Rendering Pixel Processing Screen Coordinates
(integer)
Conservative VSD Selective traversal of object
database (or traverse scene graph to get CTM)
Transform Vertices To canonical view
volume
Light at Vertices Calculate light intensity at
vertices (lighting model of choice)
Conservative VSD Back-face Culling
Conservative VSD View Volume Clipping
Image- precision VSD Compare pixel
depth (Z-buffer)
Shading Interpolate color values (Gouraud) or
normals (Phong)
per polygon
per pixel of polygon
avd November 9,
2004 VSD 6/48
avd November 5,
2002 VSD 5/45