![]() |
![]() |
![]() |
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() |
![]() |
![]() |
To access the contents, click the chapter and section titles.
Cutting Edge Direct 3D Programming
VerticesVertices are points that are used to place objects such as faces and meshes in 3D space (well talk about faces and meshes soon). Vertices, like points, are locations, so they are not visible. Still, Direct3D supports a mode in which vertices are drawn as dots. This mode is of little practical value because its hard to determine whats being drawn based on vertices alone. In fact, scenes rendered in this mode look like 3D connect the dots puzzles. (Greathand me a pencil!) FacesIn Direct3D, a face is a flat graphical element that is defined in terms of vertices. Each vertex defines a corner of the face. All of the vertices in a face must exist in the same plane; they must define a face that is flat. Faces with vertices that do not exist in the same plane are invalid and cannot be drawn. The simplest form of a face is defined with three vertices. The resulting triangular face is easy to work with for several reasons. First, it is impossible to define a set of three vertices that do not exist in the same plane, so the face cannot be invalid. Second, triangular faces are always convex, and convex faces can be rendered more efficiently than concave faces. Figure 2.7 shows some examples of faces.
Faces are usually the only visible objects in a graphics system. Some graphics systems are capable of drawing curved surfaces but most, including Direct3D, use collections of small, flat faces to represent curved surfaces. MeshesA mesh is a collection of connected faces. Typically a mesh represents one object in a scene. A mesh can have one or more faces and can be very complicated. Figure 2.8 shows an example of a mesh. If you look closely at the figure, you can make out the individual faces.
NormalsNormals are vectors used to calculate colors for faces and meshes. There are two types of normals: face normals and vertex normals. A face normal is a vector that is perpendicular to the face. The normal determines the color of a face and which side of the face is visible. Figure 2.9 shows a cube with arrows representing the face normals.
Vertex normals are vectors that are assigned to each vertex in a mesh. The orientation of each vector depends on the orientation and size of the adjoining faces. Figure 2.10 shows the vertex normals for a cube.
The use of face normals versus vertex normals depends on the rendering method. Some rendering methods use face normals, others use vertex normals, and some rendering methods dont use normals at all. Well talk about rendering methods later in this chapter. In most cases, Direct3D calculates and uses normals automatically, so its not necessary that you know they exist. There are situations, however, when normals can be over-ridden to achieve specific rendering effects. Well talk about normals again in Chapter 8. TranslationsNow, we know how to place objects in three-dimensional space. We can specify vertices, define faces using vertices, and define meshes using faces. Now what we need is a way to move the objects around. There are three common operations (or translations) that can be used to move objects: translate, scale, and rotate. Using these three operations, it is possible to place an object in any location and give it any orientation. Before we proceed, lets construct a simple scenario that we can use as we discuss the translate, scale, and rotate operations. Well use a simple mesh: a cube. Our cube is centered on the origin and has dimensions of 1 by 1 by 1. Figure 2.11 shows this cube.
Notice that because the cube is centered on the origin, each side of the cube extends ½ unit away from the origin. Notice also that each face (each side of the cube) is aligned perpendicularly with an axis. TranslateThe dictionary defines translate as: to express in another language. This definition has nothing to do with 3D graphics (that will teach you to look things up!). For our purposes here, translate means move. Lets say that we want to move (or translate) our sample cube up from the origin by two units. We can accomplish this by using a translation of <0, 2, 0>. Figure 2.12 shows the result.
Objects can be moved along several axes simultaneously with a single translation, so it isnt necessary to perform a separate translation for each axis of movement. For example, a translation of <2, 2, 0> would move the cube two units to the right and two units up.
|
![]() |
Products | Contact Us | About Us | Privacy | Ad Info | Home
Use of this site is subject to certain Terms & Conditions, Copyright © 1996-2000 EarthWeb Inc. All rights reserved. Reproduction whole or in part in any form or medium without express written permission of EarthWeb is prohibited. |