Basic graphics. ReviewReview Viewing Process, Window and viewport, World, normalized and device...

33
Basic graphics Basic graphics

Transcript of Basic graphics. ReviewReview Viewing Process, Window and viewport, World, normalized and device...

Page 1: Basic graphics. ReviewReview Viewing Process, Window and viewport, World, normalized and device coordinates Input and output primitives and their attributes.

Basic graphicsBasic graphicsBasic graphicsBasic graphics

Page 2: Basic graphics. ReviewReview Viewing Process, Window and viewport, World, normalized and device coordinates Input and output primitives and their attributes.

ReviewReview ReviewReview

•Viewing Process, Window and viewport, World, normalized and device coordinates

•Input and output primitives and their attributes. Rendering. Vector and raster displays

•Basic graphics in an universal programming system

•Vector Algebra

•Homogeneous Coordinates and Transformation of Space

Page 3: Basic graphics. ReviewReview Viewing Process, Window and viewport, World, normalized and device coordinates Input and output primitives and their attributes.

Preliminaries Preliminaries Preliminaries Preliminaries

What newcomers to Shape Modeling and Computer Graphics have to knowFundamental ideas and vocabulary in

Geometrical Modeling and Computer graphics

Graphics and geometry APIs

Transformations

Curves and surfaces design

Rendering technique

Physics-based approaches for modeling

Page 4: Basic graphics. ReviewReview Viewing Process, Window and viewport, World, normalized and device coordinates Input and output primitives and their attributes.

OverviewOverviewOverviewOverview

Are they shadows that we see?

And can shadows pleasure give?

Pleasures only shadows be

Cast by bodies we conceive

And are made the things we deem

In those figures which they seem

From Are They Shadows by Samuel Daniel

Page 5: Basic graphics. ReviewReview Viewing Process, Window and viewport, World, normalized and device coordinates Input and output primitives and their attributes.

3D Viewing3D Viewing

•Many of the 3D images seen on a screen are really a trick of the eye. The modeling is performed in 3D, but the rendering has to be converted to 2D

Page 6: Basic graphics. ReviewReview Viewing Process, Window and viewport, World, normalized and device coordinates Input and output primitives and their attributes.

3D Viewing3D Viewing

Page 7: Basic graphics. ReviewReview Viewing Process, Window and viewport, World, normalized and device coordinates Input and output primitives and their attributes.

3D Viewing3D Viewing

Page 8: Basic graphics. ReviewReview Viewing Process, Window and viewport, World, normalized and device coordinates Input and output primitives and their attributes.

3D Viewing3D Viewing

•A useful metaphor for creating 3D scenes is the motion of a synthetic camera

• We imagine that we can move our camera to any location, orient it in any way we wish, and, with a snap of the shutter, create a 2D image (“photo”) of a 3D object

• The camera, of course, is really just a computer program that produces an image on a display screen

Page 9: Basic graphics. ReviewReview Viewing Process, Window and viewport, World, normalized and device coordinates Input and output primitives and their attributes.

3D Viewing3D Viewing

Rendering is the process by which a computer creates images from models

• The rendering of 3D pictures is accomplished through projection: draw a line from the eye (P0) with a straight line to the (x,y,z)

Page 10: Basic graphics. ReviewReview Viewing Process, Window and viewport, World, normalized and device coordinates Input and output primitives and their attributes.

3D Viewing3D Viewing

Creation of our “photo” is accomplished as a series of steps:

•Specification of projection type to transform 3D objects onto a 2D projection plane

•Specification of viewing parameters. We must specify the conditions under which we want to view the 3D real world dataset

•Clipping in three dimensions. We must ignore parts of the scene that are not candidates for ultimate display

Page 11: Basic graphics. ReviewReview Viewing Process, Window and viewport, World, normalized and device coordinates Input and output primitives and their attributes.

3D Viewing3D Viewing

•Given that output primitives are specified in world coordinates, the graphics subroutine package must be told how to map world coordinates onto screen coordinates or device coordinates

•So if we have world-coordinate window, and a corresponding rectangular region in screen coordinates, called the viewport, we have to produce the transformation that maps the window into the viewport

Page 12: Basic graphics. ReviewReview Viewing Process, Window and viewport, World, normalized and device coordinates Input and output primitives and their attributes.

3D Viewing3D Viewing

•We may want to ignore parts of the scene that are behind us or too far distant to be clearly visible

•The view volume bounds that portion of the world that is to be clipped out and projected onto the view plane

Page 13: Basic graphics. ReviewReview Viewing Process, Window and viewport, World, normalized and device coordinates Input and output primitives and their attributes.

3D Viewing3D Viewing

•In the output pipeline, the application program takes description of objects in terms of primitives and attributes stored in or derived from an application model or data structure, and specifies them to the graphics package, which in turn clips and converts them to the pixels seen on the screen

•CG packages supports a basic collection of primitives: lines, polygons, circles and ellipses, and text

Page 14: Basic graphics. ReviewReview Viewing Process, Window and viewport, World, normalized and device coordinates Input and output primitives and their attributes.

3D Viewing3D Viewing

•Raster displays store the display primitives in a refresh buffer in terms of the primitive’s component pixel

•Pixels are points of a rectangular array or the smallest visible elements that the display hardware can put on the screen

Page 15: Basic graphics. ReviewReview Viewing Process, Window and viewport, World, normalized and device coordinates Input and output primitives and their attributes.

Basic graphics in an universal programming system (OpenGL)Basic graphics in an universal programming system (OpenGL)•The OpenGL graphics system is a software interface to graphics hardware

•It allows you to create interactive programs that produce color images of moving three-dimensional objects

• With OpenGL, you must build up your desired model from a small set of geometric primitives – points, lines, and polygons

Page 16: Basic graphics. ReviewReview Viewing Process, Window and viewport, World, normalized and device coordinates Input and output primitives and their attributes.

Basic graphics in an universal programming system (OpenGL)Basic graphics in an universal programming system (OpenGL)•The OpenGL Utility Library (GLU) provides many of the modeling features, such as quadric surfaces and NURBS

•OpenGL is a state machine. You put it into various states that then remain in effect until you change them

•Many state variables refer to modes that are enabled or disabled

Page 17: Basic graphics. ReviewReview Viewing Process, Window and viewport, World, normalized and device coordinates Input and output primitives and their attributes.

Basic graphics in an universal programming system (OpenGL)Basic graphics in an universal programming system (OpenGL)

•All data, whether it describes geometry or pixels, can be saved in a display list for current or later use

•All geometric primitives are eventually described by vertices. Parametric curves and surfaces may be initially described by control points. Evaluators provide a method to derive the vertices

•You can handle input events and register callback command that are invoked when specified events occur, for instance when the mouse is moved while a mouse button is also pressed

Page 18: Basic graphics. ReviewReview Viewing Process, Window and viewport, World, normalized and device coordinates Input and output primitives and their attributes.

Basic graphics in an universal programming system (OpenGL)Basic graphics in an universal programming system (OpenGL)•One of the most exciting things you can do on a graphical computer is draw pictures that move, or animate objects

•Most OpenGL implementation provide double-buffering – hardware or software that supplies two complete color buffers. Once is displayed while the other is being drawn. When the drawing of a frame is complete, the two buffers are swapped

Page 19: Basic graphics. ReviewReview Viewing Process, Window and viewport, World, normalized and device coordinates Input and output primitives and their attributes.

Vector AlgebraVector Algebra Vector AlgebraVector Algebra

•A vector is a mathematical entity with two attributes: direction and magnitude. The magnitude of vector P =(x,y,z) is |P| =

•The direction of a vector can be expressed by the cosines of the angles it makes with the coordinate axis x/|P|, y/ |P|, z/|P|.

•The three unit vectors in the directions of the coordinate axes are traditionally denoted

i = (1,0,0), j = (0,1,0) and k = (0,0,1).

Page 20: Basic graphics. ReviewReview Viewing Process, Window and viewport, World, normalized and device coordinates Input and output primitives and their attributes.

Vector AlgebraVector Algebra Vector AlgebraVector Algebra

•Vectors permit two fundamental operations: You can add them and you can multiply them by scalars.

•Let

a1 = a1i, a2 = a2j, a3 = a3k, and

b1 = b1i, b2 = b2j, b3 = b3k. We can write

a + b = (a1 + b1)i + (a2 + b2)j + (a3 + b3)k ,

a = a1 i + a2 j + a3k .

•To form a linear combination of two vectors, a and b, we scale each of them by some scalars, say, and and add the weighted versions to form new vector, a + b.

Page 21: Basic graphics. ReviewReview Viewing Process, Window and viewport, World, normalized and device coordinates Input and output primitives and their attributes.

Vector AlgebraVector Algebra Vector AlgebraVector Algebra

•The dot product of two vectors. To calculate the dot product we multiply corresponding components of the vectors and add the result.

•The cross product (also called the vector product) of two vectors is another vector. Given the 3D vectors

a = (ax,ay,az), and b = (bx,by,bz),

their cross product is denoted as ab or ab. It is defined in terms of the standard unit vector i,j, and k by

ab = (axbz – azby)i + (azbx – axbz)j + (axby – aybx)k.

Page 22: Basic graphics. ReviewReview Viewing Process, Window and viewport, World, normalized and device coordinates Input and output primitives and their attributes.

Vector AlgebraVector Algebra Vector AlgebraVector Algebra

•Vector equation of line. Suppose we are given a point P0 and a unit vector u along the line L. Give the names r0 and r to the vectors OP0 and OP connecting the point O with the point P0 and an arbitrary point P, respectively. Then the vector P0P = r – r0 coincides with the direction of the vector u, so

r – r0 = u. And we have

r = r0 + u.

Page 23: Basic graphics. ReviewReview Viewing Process, Window and viewport, World, normalized and device coordinates Input and output primitives and their attributes.

Vector AlgebraVector Algebra Vector AlgebraVector Algebra

•Vector differentiation. If a vector a is the function of time t, a(t) = a1(t) i + a2(t) j + a3(t) k,

then

= i + j + k.

Page 24: Basic graphics. ReviewReview Viewing Process, Window and viewport, World, normalized and device coordinates Input and output primitives and their attributes.

Homogeneous Coordinates and Homogeneous Coordinates and Transformation of SpaceTransformation of SpaceHomogeneous Coordinates and Homogeneous Coordinates and Transformation of SpaceTransformation of Space•Each primitive has a mathematical representation which can be expressed as a data or type structure fore storage and manipulation by a computer

•Applying transformations to graphical primitives can be done by a process called instancing

Page 25: Basic graphics. ReviewReview Viewing Process, Window and viewport, World, normalized and device coordinates Input and output primitives and their attributes.

ProjectionsProjectionsProjectionsProjections

•3D objects can be projected on 2D view plane

•There are two basic methods:

–parallel projection

–perspective projection

•The parallel projection can be considered as a special case of of perspective projection

Page 26: Basic graphics. ReviewReview Viewing Process, Window and viewport, World, normalized and device coordinates Input and output primitives and their attributes.

ProjectionsProjectionsProjectionsProjections

•Orthographic Parallel Projections

The most common type of orthographic projection is the front-elevation

Page 27: Basic graphics. ReviewReview Viewing Process, Window and viewport, World, normalized and device coordinates Input and output primitives and their attributes.

Homogeneous Coordinates and Homogeneous Coordinates and Transformation of SpaceTransformation of SpaceHomogeneous Coordinates and Homogeneous Coordinates and Transformation of SpaceTransformation of Space

•A point (x, y, z) in three dimensional Cartesian space is represented in R4 by the vector (x, y, z, 1), or by any multiple (rx, ry, rz,r) (with, r 0). When W 0, the homogeneous coordinates (X, Y. Z. W) represent the Cartesian point (x, y, z = (X/W, Y/W, Z/W)

•A point of the form (X, Y, Z,0) does not correspond to a Cartesian point, but represents the point at infinity in the direction of the three-dimensional vector (X, Y, Z). The set of all homogeneous coordinates (X, Y, Z. W) is called (three-dimensional) projective

space and denoted P3

Page 28: Basic graphics. ReviewReview Viewing Process, Window and viewport, World, normalized and device coordinates Input and output primitives and their attributes.

Homogeneous Coordinates and Homogeneous Coordinates and Transformation of SpaceTransformation of SpaceHomogeneous Coordinates and Homogeneous Coordinates and Transformation of SpaceTransformation of Space

A transformation of projective space is a mapping L: P3 P3 of the form

The 44 matrix M is called the homogeneous transformation matrix of L. If M is a non-singular matrix then L is called a non-singular transformation. If m14 = m24 = m34 = 0 and m44 0, then L is said to be an affine transformation. (Affine transformations correspond to translations, scalings, rotations etc. of three-dimensional Cartesian space.)

A point of the form (X, Y, Z,0) does not correspond to a Cartesian point, but represents the point at infiniy

L xyzwxyzw,,, ( )

mmmm

mmmm

mmmm

mmmm

11121314

21222324

31323334

41424344

Page 29: Basic graphics. ReviewReview Viewing Process, Window and viewport, World, normalized and device coordinates Input and output primitives and their attributes.

Homogeneous Coordinates and Homogeneous Coordinates and Transformation of SpaceTransformation of SpaceHomogeneous Coordinates and Homogeneous Coordinates and Transformation of SpaceTransformation of Space•Translations

- The transformation matrix of a translation by x0, y0, and z0

units in the x-, y- and z- directions respectively, is

- Hence, P(x, y, z) is transformed to P'(x + x0, y + y0, z + z0)

T xyz000,,

1000

0100

0010

1000xyz

Page 30: Basic graphics. ReviewReview Viewing Process, Window and viewport, World, normalized and device coordinates Input and output primitives and their attributes.

Homogeneous Coordinates and Homogeneous Coordinates and Transformation of SpaceTransformation of SpaceHomogeneous Coordinates and Homogeneous Coordinates and Transformation of SpaceTransformation of Space•Scalings and Reflections- A scaling about the origin by a factor sx, sy, and sz, in the x-, y-, and z-direction ,is respectively, obtained by the following transformation matrix

- The transformation matrices of the reflections Ryz in the x = 0 plane, Rxz, in the y = 0 plane, and Rxy in the z = 0 plane, are obtained by taking a scaling of -1 in one of the coordinate directions

S(sx,sy,sz,sw) =

s

s

s

s

x

y

z

w

000

000

000

000

Page 31: Basic graphics. ReviewReview Viewing Process, Window and viewport, World, normalized and device coordinates Input and output primitives and their attributes.

Homogeneous Coordinates and Homogeneous Coordinates and Transformation of SpaceTransformation of SpaceHomogeneous Coordinates and Homogeneous Coordinates and Transformation of SpaceTransformation of Space•Rotations about the Coordinate Axes- Rotations in space take place about a line called its rotation axis

- The rotations about the three coordinate axes are called the primary rotations

1. Rotation about the x-axis through an angle x

2. Rotation about the y-axis through an angle y

3. Rotation about the z-axis through an angle z

Rotx(x) =

1000

0 0

0 0

0001

cossin

sincos

x x

x x

Page 32: Basic graphics. ReviewReview Viewing Process, Window and viewport, World, normalized and device coordinates Input and output primitives and their attributes.

Homogeneous Coordinates and Homogeneous Coordinates and Transformation of SpaceTransformation of SpaceHomogeneous Coordinates and Homogeneous Coordinates and Transformation of SpaceTransformation of Space•Rotation about an Arbitrary Line

-Rotation through an angle about an arbitrary rotation axis is obtained by transforming the rotation axis to one of the coordinate axes, applying a primary rotation through an angle about the coordinate axis, and applying the transformation which maps the coordinate axis back to the rotation axis

Page 33: Basic graphics. ReviewReview Viewing Process, Window and viewport, World, normalized and device coordinates Input and output primitives and their attributes.

Homogeneous Coordinates and Homogeneous Coordinates and Transformation of SpaceTransformation of SpaceHomogeneous Coordinates and Homogeneous Coordinates and Transformation of SpaceTransformation of Space• Rotation about an Arbitrary Line

1. Apply the translation T(-pl,-p2 -p3) which maps P to the origin and the rotation axis to the line OR where R(r1,r2,r3)= U

2. Suppose r2 and r3 are not both zero. Apply a rotation through all angle x, about the x-axis so that the line OR is mapped into the xz-plane

3. Apply a rotation about the y-axis so that the line OR' is mapped to the z-axis.

4. Apply a rotation through an angle about the z-axis (Figure 2(c)).

5. Apply the inverses of the transformations 1-3 in reverse order