Computer Graphics: Programming, Problem Solving, and Visual Communication
Computer Graphics: Programming, Problem Solving, and Visual Communication
description
Transcript of Computer Graphics: Programming, Problem Solving, and Visual Communication
![Page 1: Computer Graphics: Programming, Problem Solving, and Visual Communication](https://reader036.fdocuments.in/reader036/viewer/2022070417/568153e0550346895dc1db61/html5/thumbnails/1.jpg)
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](https://reader036.fdocuments.in/reader036/viewer/2022070417/568153e0550346895dc1db61/html5/thumbnails/2.jpg)
Viewing and Projection
Making an image from a scene
![Page 3: Computer Graphics: Programming, Problem Solving, and Visual Communication](https://reader036.fdocuments.in/reader036/viewer/2022070417/568153e0550346895dc1db61/html5/thumbnails/3.jpg)
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](https://reader036.fdocuments.in/reader036/viewer/2022070417/568153e0550346895dc1db61/html5/thumbnails/4.jpg)
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](https://reader036.fdocuments.in/reader036/viewer/2022070417/568153e0550346895dc1db61/html5/thumbnails/5.jpg)
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](https://reader036.fdocuments.in/reader036/viewer/2022070417/568153e0550346895dc1db61/html5/thumbnails/6.jpg)
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](https://reader036.fdocuments.in/reader036/viewer/2022070417/568153e0550346895dc1db61/html5/thumbnails/7.jpg)
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](https://reader036.fdocuments.in/reader036/viewer/2022070417/568153e0550346895dc1db61/html5/thumbnails/8.jpg)
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](https://reader036.fdocuments.in/reader036/viewer/2022070417/568153e0550346895dc1db61/html5/thumbnails/9.jpg)
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](https://reader036.fdocuments.in/reader036/viewer/2022070417/568153e0550346895dc1db61/html5/thumbnails/10.jpg)
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](https://reader036.fdocuments.in/reader036/viewer/2022070417/568153e0550346895dc1db61/html5/thumbnails/11.jpg)
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](https://reader036.fdocuments.in/reader036/viewer/2022070417/568153e0550346895dc1db61/html5/thumbnails/12.jpg)
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](https://reader036.fdocuments.in/reader036/viewer/2022070417/568153e0550346895dc1db61/html5/thumbnails/13.jpg)
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](https://reader036.fdocuments.in/reader036/viewer/2022070417/568153e0550346895dc1db61/html5/thumbnails/14.jpg)
Perspective or Orthographic?
• Perspective view • Orthographic view
![Page 15: Computer Graphics: Programming, Problem Solving, and Visual Communication](https://reader036.fdocuments.in/reader036/viewer/2022070417/568153e0550346895dc1db61/html5/thumbnails/15.jpg)
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](https://reader036.fdocuments.in/reader036/viewer/2022070417/568153e0550346895dc1db61/html5/thumbnails/16.jpg)
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](https://reader036.fdocuments.in/reader036/viewer/2022070417/568153e0550346895dc1db61/html5/thumbnails/17.jpg)
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](https://reader036.fdocuments.in/reader036/viewer/2022070417/568153e0550346895dc1db61/html5/thumbnails/18.jpg)
View Volumes in a Scene
![Page 19: Computer Graphics: Programming, Problem Solving, and Visual Communication](https://reader036.fdocuments.in/reader036/viewer/2022070417/568153e0550346895dc1db61/html5/thumbnails/19.jpg)
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](https://reader036.fdocuments.in/reader036/viewer/2022070417/568153e0550346895dc1db61/html5/thumbnails/20.jpg)
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](https://reader036.fdocuments.in/reader036/viewer/2022070417/568153e0550346895dc1db61/html5/thumbnails/21.jpg)
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](https://reader036.fdocuments.in/reader036/viewer/2022070417/568153e0550346895dc1db61/html5/thumbnails/22.jpg)
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](https://reader036.fdocuments.in/reader036/viewer/2022070417/568153e0550346895dc1db61/html5/thumbnails/23.jpg)
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](https://reader036.fdocuments.in/reader036/viewer/2022070417/568153e0550346895dc1db61/html5/thumbnails/24.jpg)
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](https://reader036.fdocuments.in/reader036/viewer/2022070417/568153e0550346895dc1db61/html5/thumbnails/25.jpg)
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](https://reader036.fdocuments.in/reader036/viewer/2022070417/568153e0550346895dc1db61/html5/thumbnails/26.jpg)
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](https://reader036.fdocuments.in/reader036/viewer/2022070417/568153e0550346895dc1db61/html5/thumbnails/27.jpg)
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](https://reader036.fdocuments.in/reader036/viewer/2022070417/568153e0550346895dc1db61/html5/thumbnails/28.jpg)
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](https://reader036.fdocuments.in/reader036/viewer/2022070417/568153e0550346895dc1db61/html5/thumbnails/29.jpg)
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](https://reader036.fdocuments.in/reader036/viewer/2022070417/568153e0550346895dc1db61/html5/thumbnails/30.jpg)
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](https://reader036.fdocuments.in/reader036/viewer/2022070417/568153e0550346895dc1db61/html5/thumbnails/31.jpg)
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](https://reader036.fdocuments.in/reader036/viewer/2022070417/568153e0550346895dc1db61/html5/thumbnails/32.jpg)
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](https://reader036.fdocuments.in/reader036/viewer/2022070417/568153e0550346895dc1db61/html5/thumbnails/33.jpg)
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