some basic concepts

34
COMPUTER GRAPHICS SOME BASIC CONCEPTS

Upload: nadda

Post on 22-Mar-2016

25 views

Category:

Documents


3 download

DESCRIPTION

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

TRANSCRIPT

Page 1: Some Basic Concepts

C O M P U T E R G RA P H I C S

SOME BASIC CONCEPTS

Page 2: Some Basic Concepts

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

Page 3: Some Basic Concepts

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.

Page 4: Some Basic Concepts

PERSPECTIVE

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

Page 5: Some Basic Concepts

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.

Page 6: Some Basic Concepts

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.

Page 7: Some Basic Concepts

ORTHOGRAPHIC PROJECTION

• Orthographic projection

Page 8: Some Basic Concepts

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

Page 9: Some Basic Concepts

THE FRUSTUM

Perspective Projection

Page 10: Some Basic Concepts

TRANSFORMATIONS

Page 11: Some Basic Concepts

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

Page 12: Some Basic Concepts

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.

Page 13: Some Basic Concepts

EYE COORDINATES

Page 14: Some Basic Concepts

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.

Page 15: Some Basic Concepts

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

Page 16: Some Basic Concepts

TRANSLATION

Page 17: Some Basic Concepts

ROTATION

Page 18: Some Basic Concepts

SCALING

Page 19: Some Basic Concepts

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.

Page 20: Some Basic Concepts

CASE 1

Page 21: Some Basic Concepts

CASE 2

Page 22: Some Basic Concepts

THE MODELVIEW

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

Page 23: Some Basic Concepts

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.

Page 24: Some Basic Concepts

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.

Page 25: Some Basic Concepts

ORTHOGRAPHIC PROJECTIONS

Page 26: Some Basic Concepts

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.

Page 27: Some Basic Concepts

PERSPECTIVE PROJECTIONS

Page 28: Some Basic Concepts

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.

Page 29: Some Basic Concepts

THE TRANSFORMATION PIPELINE

Page 30: Some Basic Concepts

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.

Page 31: Some Basic Concepts

EXAMPLE

• Suppose that you want to draw two spheres:

Page 32: Some Basic Concepts

EXAMPLE

// Go 10 units up the y-axisglTranslatef(0.0f, 10.0f, 0.0f);// Draw the first sphereglutSolidSphere(1.0f,15,15);// Go 10 units out the x-axisglTranslatef(10.0f, 0.0f, 0.0f);// Draw the second sphereglutSolidSphere(1.0f);

Page 33: Some Basic Concepts

THE ACTUAL RESULT

The actual result for the above code:

Page 34: Some Basic Concepts

SOLUTION: RESET USING THE IDENTITY MATRIX

// Set current matrix to modelview and resetglMatrixMode(GL_MODELVIEW);glLoadIdentity();// Go 10 units up the y-axisglTranslatef(0.0f, 10.0f, 0.0f);// Draw the first sphereglutSolidSphere(1.0f, 15, 15);// Reset modelview matrix againglLoadIdentity();// Go 10 units out the x-axisglTranslatef(10.0f, 0.0f, 0.0f);// Draw the second sphereglutSolidSphere(1.0f, 15, 15);