1 / 34

Some Basic Concepts

Some Basic Concepts. Computer graphics. Clipping. A window is measured physically in terms of pixels. Before you can start plotting points , lines , and shapes in a window, you must tell OpenGL how to translate specified coordinate pairs into screen coordinates.

wolford
Download Presentation

Some Basic Concepts

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Some Basic Concepts Computer graphics

  2. Clipping • A window is measured physically in terms of pixels. • Before you can start plotting points, lines, and shapes in a window, you must tell OpenGL how to translate specified coordinate pairs into screen coordinates. • You do this by specifying the region of Cartesian space that occupies the window; this region is known as the clipping region. • In two-dimensional space, the clipping region is the minimum and maximum x and y values that are inside the window. • Another way of looking at this is specifying the origin’s location in relation to the window

  3. Viewport • Rarely will your clipping area width and height exactly match the width and height of the window in pixels. • The coordinate system must therefore be mapped from logical Cartesian coordinates to physical screen pixel coordinates. • This mapping is specified by a setting known as the viewport. • The viewport is the region within the window’s client area that is used for drawing the clipping area. • The viewport simply maps the clipping area to a region of the window. • Usually, the viewport is defined as the entire window, but this is not strictly necessary; for instance, you might want to draw only in the lower half of the window.

  4. Perspective • What makes a shape look three-dimensional is perspective, or the angles between the lines that lend the illusion of depth.

  5. projection • The 3D coordinates you use to create geometry are flattened or projected onto a 2D surface (the window background). It’s like tracing the outlines of some object behind a piece of glass with a black marker. • By specifying the projection, you specify the viewing volume that you want displayed in your window and how it should be transformed.

  6. Orthographic projections • In orthographic, or parallel, projections you specify a square or rectangular viewing volume. Anything outside this volume is not drawn. Furthermore, all objects that have the same dimensions appear the same size, regardless of whether they are far away or nearby.

  7. Orthographic Projection • Orthographic projection

  8. Perspective projection • The perspective projection adds the effect that distant objects appear smaller than nearby objects. The viewing volume is something like a pyramid with the top shaved off. • The remaining shape is called the frustum. Objects nearer to the front of the viewing volume appear close to their original size, but objects near the back of the volume shrink as they are projected to the front of the volume

  9. The Frustum Perspective Projection

  10. Transformations

  11. Transformation Pipeline • Three levels of geometric transformations occur between the time you specify your vertices and the time they appear on the screen: • These are: Viewing transformation Modeling transformation Projection transformation

  12. The EYE Coordinate Systems • An important concept throughout this chapter is that of eye coordinates. • Eye coordinates are from the viewpoint of the observer, regardless of any transformations that may occur; • you can think of them as “absolute” screen coordinates. • Thus, eye coordinates represent a virtual fixed coordinate system that is used as a common frame of reference. • All the transformations are described in terms of their effects relative to the eye coordinate system.

  13. EYE Coordinates

  14. Viewing Transformation • The viewing transformation allows you to place the point of observation anywhere you want and look in any direction. • Determining the viewing transformation is like placing and pointing a camera at the scene. • Generally, you must specify the viewing transformation before any other modeling transformations. • The reason is that it appears to move the current working coordinate system in respect to the eye coordinate system.

  15. Modeling Transformations • Modeling transformations are used to manipulate your model and the particular objects within it. • These transformations move objects (translate) into place, rotate them, and scale them

  16. Translation

  17. Rotation

  18. Scaling

  19. The Order of Modeling Trasnfomations • The final appearance of your scene or object can depend greatly on the order in which the modeling transformations are applied. This is particularly true of translation and rotation.

  20. Case 1

  21. Case 2

  22. The Modelview • Practically, the viewing transformation and the modeling transformation are combined in one transformation: The ModelView Transformation

  23. Projection Transformation • The projection transformation is applied to your vertices after the modelview transformation. • This projection actually defines the viewing volume and establishes clipping planes. • The clipping planes are plane equations in 3D space that OpenGL uses to determine whether geometry can be seen by the viewer.

  24. Orthographic Projections • In an orthographic, or parallel, projection, all the polygons are drawn onscreen with exactly the relative dimensions specified. • Lines and polygons are mapped directly to the 2D screen using parallel lines, which means no matter how far away something is, it is still drawn the same size, just flattened against the screen.

  25. Orthographic Projections

  26. Perspective Projections • A perspective projection shows scenes more as they appear in real life. • The main feature of perspective projections is foreshortening, which makes distant objects appear smaller than nearby objects of the same size. • Lines in 3D space that might be parallel do not always appear parallel to the viewer. • With a railroad track, for instance, the rails are parallel, but using perspective projection, they appear to converge at some distant point.

  27. Perspective Projections

  28. The Viewport Transformation • When all is said and done, you end up with a two-dimensional projection of your scene that will be mapped to a window somewhere on your screen. • This mapping to physical window coordinates is the last transformation that is done, and it is called the viewport transformation.

  29. The Transformation PIPELINE

  30. The effect is cumulative • The effects of transformation functions are cumulative. • Each time you call one, the appropriate matrix is constructed and multiplied by the current modelview matrix. • The new matrix then becomes the current modelview matrix, which is then multiplied by the next transformation, and so on.

  31. Example • Suppose that you want to draw two spheres:

  32. Example // Go 10 units up the y-axis glTranslatef(0.0f, 10.0f, 0.0f); // Draw the first sphere glutSolidSphere(1.0f,15,15); // Go 10 units out the x-axis glTranslatef(10.0f, 0.0f, 0.0f); // Draw the second sphere glutSolidSphere(1.0f);

  33. The Actual Result The actual result for the above code:

  34. Solution: Reset using the identity matrix // Set current matrix to modelview and reset glMatrixMode(GL_MODELVIEW); glLoadIdentity(); // Go 10 units up the y-axis glTranslatef(0.0f, 10.0f, 0.0f); // Draw the first sphere glutSolidSphere(1.0f, 15, 15); // Reset modelview matrix again glLoadIdentity(); // Go 10 units out the x-axis glTranslatef(10.0f, 0.0f, 0.0f); // Draw the second sphere glutSolidSphere(1.0f, 15, 15);

More Related