computer graphics: programming, problem solving, and visual communication

33
Computer Graphics: Programming, Problem Solving, and Visual Communication Steve Cunningham California State University Stanislaus and Grinnell College PowerPoint Instructor’s Resource

Upload: oriana

Post on 25-Jan-2016

33 views

Category:

Documents


0 download

DESCRIPTION

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. - PowerPoint PPT Presentation

TRANSCRIPT

Page 1: Computer Graphics: Programming, Problem Solving, and Visual Communication

Computer Graphics:Programming, Problem Solving,

and Visual Communication

Steve CunninghamCalifornia State University Stanislaus and Grinnell College

PowerPoint Instructor’s Resource

Page 2: Computer Graphics: Programming, Problem Solving, and Visual Communication

Viewing and Projection

Making an image from a scene

Page 3: Computer Graphics: Programming, Problem Solving, and Visual Communication

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

Page 4: Computer Graphics: Programming, Problem Solving, and Visual Communication

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

Page 5: Computer Graphics: Programming, Problem Solving, and Visual Communication

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

Page 6: Computer Graphics: Programming, Problem Solving, and Visual Communication

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

Page 7: Computer Graphics: Programming, Problem Solving, and Visual Communication

Two Similar Views

• Half dome from the valley floor

• Half dome from the Glacier Point lookout

Page 8: Computer Graphics: Programming, Problem Solving, and Visual Communication

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)

Page 9: Computer Graphics: Programming, Problem Solving, and Visual Communication

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

Page 10: Computer Graphics: Programming, Problem Solving, and Visual Communication

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

Page 11: Computer Graphics: Programming, Problem Solving, and Visual Communication

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)

Page 12: Computer Graphics: Programming, Problem Solving, and Visual Communication

The Standard Viewing Model

• The eye coordinates are left-handed!

• 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

Page 13: Computer Graphics: Programming, Problem Solving, and Visual Communication

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

Page 14: Computer Graphics: Programming, Problem Solving, and Visual Communication

Perspective or Orthographic?

• Perspective view • Orthographic view

Page 15: Computer Graphics: Programming, Problem Solving, and Visual Communication

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

Page 16: Computer Graphics: Programming, Problem Solving, and Visual Communication

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

Page 17: Computer Graphics: Programming, Problem Solving, and Visual Communication

View Volumes

• The region in world space that is seen with perspective (left) or orthographic (right) projections

Page 18: Computer Graphics: Programming, Problem Solving, and Visual Communication

View Volumes in a Scene

Page 19: Computer Graphics: Programming, Problem Solving, and Visual Communication

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

Page 20: Computer Graphics: Programming, Problem Solving, and Visual Communication

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)

Page 21: Computer Graphics: Programming, Problem Solving, and Visual Communication

Field of View in Perspective Projections

• Acts like defining the focal length of a camera -- wide angle (left) to telephoto (right)

Page 22: Computer Graphics: Programming, Problem Solving, and Visual Communication

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

Page 23: Computer Graphics: Programming, Problem Solving, and Visual Communication

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

Page 24: Computer Graphics: Programming, Problem Solving, and Visual Communication

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

Page 25: Computer Graphics: Programming, Problem Solving, and Visual Communication

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

Page 26: Computer Graphics: Programming, Problem Solving, and Visual Communication

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

Page 27: Computer Graphics: Programming, Problem Solving, and Visual Communication

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

Page 28: Computer Graphics: Programming, Problem Solving, and Visual Communication

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

Page 29: Computer Graphics: Programming, Problem Solving, and Visual Communication

Viewing and Projection in OpenGL

• How you define a view

• How you define a projection

Page 30: Computer Graphics: Programming, Problem Solving, and Visual Communication

Viewing

• Default view has the eye at the origin, looking at the point (0, 0, -1), with the up vector the y-axis

• 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

Page 31: Computer Graphics: Programming, Problem Solving, and Visual Communication

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 );

Page 32: Computer Graphics: Programming, Problem Solving, and Visual Communication

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 )

Page 33: Computer Graphics: Programming, Problem Solving, and Visual Communication

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