Viewing - California State University Stanislaus

advertisement
Computer Graphics:
Programming, Problem Solving,
and Visual Communication
Steve Cunningham
California State University Stanislaus and Grinnell College
PowerPoint Instructor’s Resource
Viewing and Projection
Making an image from a scene
Creating an Image from a
Scene
• Computer graphics has three main
functions
– Modeling, where you define a scene
– Viewing and projection, where you define
how the scene is to be seen
– Rendering, where the model and view are
translated into an image
• In this chapter, we assume a scene has
been modeled and we discuss how you
define the way it is seen
Two Main Parts
• There are two main parts of defining
how a scene is to be seen
• Viewing, where you place the observer
in the scene
• Projection, where you specify how the
observer’s view is created
• This chapter covers both parts
This is Part of the Geometry
Pipeline
• Modeling creates the scene in world
coordinates, and this chapter covers the
part of the pipeline shown here
Specifying a View
• To specify an image, you place the observer in
the world with specific information
–
–
–
–
–
The location of the observer
The direction the observer is looking
The orientation of the observer
The breadth of field of the observer
The aspect ratio of the observer
• The first three of these are viewing; the last two
are part of projection
– For the projection part, the observer must be looking
through some sort of frame
Two Similar Views
• Half dome from the
valley floor
• Half dome from the
Glacier Point
lookout
These Half Dome Views…
• Are from different viewpoints
• Are looking in slightly different directions
• Have slightly different field of view
– Valley floor is narrower (more zoomed in)
– Glacier Point is wider (more zoomed out)
• Have the same orientation (conventional
up direction) and aspect ratio (1:1)
How Do We Specify a View?
• There are two parts to the specification
• The viewing specification places the
observer
• The projection specifies the frame
• Most graphics systems, including
OpenGL, have you specify them
separately because they operate
independently
A Viewing Example
• A view of world space
that includes a model
and an observer
• The view of the object
in the world as seen by
the observer
For Viewing, You Define…
• The eye point, which is the position of
the observer
• The “look-at” point or view reference
point, which defines the direction the
observer is looking
• The up vector, which defines the
orientation of the observer (in world
space)
The Standard Viewing Model
• The eye coordinates are lefthanded!
• You specify the eyepoint
• You specify the view
reference point, giving you
the z-direction
• You specify the y-direction
with the up vector
• The x-direction is computed
as a cross product
For Projection, You Define…
• The type of projection
– Perspective
– Orthographic
• The width of your viewing space
• The height of your viewing space OR
the aspect ratio of your viewing space
• The front and back of your viewing
volume
Perspective or Orthographic?
• Perspective view
• Orthographic view
Perspective or Orthographic (2)
• Perspective views
are more realistic
(see the figure)
• Orthographic views
are standard in some
engineering areas
and give you
accurate relative
measurements
Types of Perspective
• One-point
– Two coordinate directions
parallel to view plane
• Two-point
– One coordinate direction
parallel to view plane
• Three-point
– No coordinate direction
parallel to view plane
View Volumes
• The region in world space that is seen
with perspective (left) or orthographic
(right) projections
View Volumes in a Scene
Clipping on the View Volume
• Clipping is the process of determining
what lies outside the view volume and
removing that before it is processed
• Six clipping planes to the left, right, top,
bottom, front, and back of the volume
Clipping…
• Removes objects that lie
entirely outside the
volume (e.g. some of the
trees)
• Reworks each object
that lies partly in and
partly outside the volume
• Line segments (left) or
polygon (right)
Field of View in Perspective
Projections
• Acts like defining the focal length of a
camera -- wide angle (left) to telephoto
(right)
Drawing to a Viewport
• A viewport is a rectangular region in the
window to which you can draw
• Default viewport is the entire window
• You can define a smaller viewport so all
drawing is restricted to that region
• You can use separate modeling for
each viewport
Mapping to Screen Space
• The final step in the geometry pipeline
is mapping the image to screen space
• The points in the viewing volume are
projected to the viewplane at the front of
the volume
• This converts them to 2D points in the
space
Mapping to Screen Space (2)
• The points in the 2D real space are then
converted to 2D integer space by a
simple proportional process, followed by
a roundoff
• These 2D integer points are vertex
coordinates in the screen
• Now ready for the rendering process
Managing the View:
Hidden Surfaces
• An understandable 3D image scene
needs to show some things in front of
others
• A graphics program simply draws things
as you define them
• You need a way to keep track of things
in depth order
Managing the View:
Hidden Surfaces (2)
• One way is for you to keep track of the
depth of each object and draw them back
to front (farthest to nearest)
– This is the Painter’s Algorithm
• A graphics system can provide a way to
keep track of things in depth order
• Depth buffering tracks this for each pixel
and only shows those that are in front
Managing the View:
Double Buffering
• Your program draws the objects you
define one by one
– It can take some time for the image of a
complex scene to be drawn
• In order to show only the completed
scene, you can use double buffering
• The image is drawn to the back buffer
and then this is swapped to the front
buffer for display
Managing the View:
Stereo Viewing
• There are a number of ways to get a stereo
view, but one is easy to do at this point
• Divide your window into two viewports
• Draw a scene twice in the separate viewports
with eye points approximating a viewer’s eye
locations
Viewing and Projection in
OpenGL
• How you define a view
• How you define a projection
Viewing
• Default view has the eye at the origin, looking
at the point (0, 0, -1), with the up vector the yaxis
• You can change this with the functions
glMatrixMode( GL_MODELVIEW );
glLoadIdentity();
gluLookAt( eyex, eyey, eyez,
lookatx, lookaty, lookatz,
upx,upy,upz )
• There are times when you will want to use the
default view
The Perspective Projection
• Default OpenGL approach is through the
glFrustum function; this is difficult
• More usual approach is through the functions
glMatrixMode(GL_PROJECTION );
glLoadIdentity();
gluPerspective( view_angle,
aspect_ratio, front, back );
The Orthographic Projection
• The orthgonal projection uses a much
simpler view volume and is defined by
specifying that volume
glMatrixMode( GL_PROJECTION )
glLoadIdentity()
glOrtho( left, right, bottom,
top, near, far )
Other Features
• glutInit(GLUT_DEPTH | GLUT_DOUBLE …)
• Depth testing
– glEnable(GL_DEPTH_TEST)
• Double buffering
– glutSwapBuffers()
• Stereo viewing
– draw into separate viewports that enable
eye conversion
– other techniques discussed later
Download