, [eBook] DirectX 3D Graphics Programming Bible 

[ Pobierz całość w formacie PDF ]
.For example, if the use of text is limited to short messages that are part of thegraphics images, the most reasonable approach may be to store the text strings in the image fileitself.On the other hand, if the program uses and reuses extensive text areas it is more efficient tostore the text separately and include in the image file a reference to this location.Image segmentsAn image segment is a portion of the image that can be considered as a graphic unit.Therefore,the image file can contain more than one image segment.The portion of the image contained ineach segment is displayed as a single element.Figure 2-22 shows an image file consisting of twoseparate segments: the mailbox segment and the flag segment.In the right-hand drawing the flagsegment has been rotated to the vertical position.Figure 2-22: Image segmentsMost graphics manipulations take place at the level of the image segment.Image descriptorsThe image descriptors are the basic elements of the encoding.They are also called display filecommands, and less appropriately, graphics primitives.A descriptor contains the instructions,data, and data references necessary for displaying a graphical element.The descriptors in Figure2-20 (move, line, and circle) are used to form the segment (or description) labeled (A).A segmentcan contain one or more descriptors.For example, the segment for the mailbox in Figure 2-22requires descriptors for the straight-line segments that form the top and bottom of the box and forthe arcs that form its ends.The segment for the mailbox flag can contain a single descriptor for apolygon.The components of a descriptor are the operation code and the operands.The operation code,sometimes called opcode, is a mnemonic description of the operations to be performed.The termsmove, line, and circle in Figure 2-20 are opcodes.The operands are the data items required by theopcode.In this example the operands follow the opcodes and are enclosed in parentheses orbrackets. SummaryThis chapter is an overview of the basic concepts and constructs that serve as a foundation tocomputer graphics in general, and to 3D graphics in particular.The chapter's main purpose is toacquaint the reader with types of graphics data and their most common representations, withgraphics modeling systems and techniques, and with the basic ideas of image mapping.In Chapter3 we use this knowledge obtained here to explain the geometrical transformations that are at thecore of 3D graphics manipulations. Chapter 3: 3D Image TransformationsOverviewComputer graphics rely heavily on geometrical transformations for the generation and animation of2D and 3D imagery.In this chapter we introduce the essential transformations of translation,rotation, and scaling.For didactical reasons the geometrical transformations are first presented inthe context of 2D imagery, and then expanded to 3D. Coordinate Systems and Matrix RepresentationsIn computer graphics you often need to manipulate vector images in order to transform them.Forexample, an arrow indicating a northerly direction can be rotated 45 degrees clockwise to indicatea northeasterly direction.If an image is defined as a series of points in the Cartesian plane, thenthe rotation can be performed by a mathematical operation on the coordinates that define eachpoint.Similarly, if an image is defined as a series of straight lines connecting points in the plane,as would be the case in the representation of an arrow, then the transformation applied to theimage points is also a transformation of the image itself.The process is simplified further by storing the coordinates of each image point in a rectangulararray.The mathematical notion of a matrix as a rectangular array of values turns out to be quitesuitable for storing the coordinates of image points.After the coordinate points are stored in amatrix, you can use standard operations of linear algebra to perform geometrical transformationson the images.Figure 3-1 shows the approximate location of seven stars of the constellation UrsaMinor, also known as the Little Dipper.The individual stars are labeled with the letters a through g.The star labeled a corresponds to Polaris (the Pole star).Figure 3-1: Point representation of the stars in the constellation Ursa Minor (Little Dipper)The coordinates of each star of the Little Dipper, shown in Figure 3-1, can be represented intabular form, as follows:Star X YA 0 0B -1 11C 1 8 D 0 12E 2 5F 3 9G 1 2In 2D graphics the coordinate matrix is a set of x, y coordinate pairs, as shown in the precedingexample.3D representations require an additional z-coordinate that stores the depth of each point.3D matrix representations are discussed later in this chapter.In the following sections we explainthe matrix operations that are most useful in graphics programming.Image transformationsAn image can be changed into another one by performing mathematical operations on itscoordinate points.Figure 3-2 shows the translation of a line from coordinates (2,2) and (10,14) tocoordinates (10,2) and (18,14).Figure 3-2: Translation of a straight lineNotice that in Figure 3-2 the translation is performed by adding 8 to the start and end x-coordinatesof the original line.This operation on the x-axis performs a horizontal translation.A verticaltranslation requires manipulating the y-coordinate.To translate the line both horizontally andvertically you must operate on both coordinate axes simultaneously. Matrix ArithmeticMatrices are used in several fields of mathematics.In linear algebra matrices can hold thecoefficients of linear equations.When the equations are represented in this manner, they can bemanipulated (and often solved) by performing operations on the rows and columns of the matrix.At this time we are interested only in matrix operations that are used to perform geometrical imagetransformations.The most primitive of these translation, rotation, and scaling are common ingraphics and animation programming.Other less common transformations are reflection(mirroring) and shearing.We start by defining a matrix as a rectangular array usually containing a set of numeric values.It iscustomary to represent a matrix by means of a capital letter.For example, the following matrix,designated by the letter A, has three rows and two columns.Example 1The size of a matrix is determined by its number of rows and columns [ Pobierz całość w formacie PDF ]
  • zanotowane.pl
  • doc.pisz.pl
  • pdf.pisz.pl
  • anikol.xlx.pl