Click Here!
home account info subscribe login search My ITKnowledge FAQ/help site map contact us


 
Brief Full
 Advanced
      Search
 Search Tips
To access the contents, click the chapter and section titles.

Cutting Edge Direct 3D Programming
(Publisher: The Coriolis Group)
Author(s): Stan Trujillo
ISBN: 1576100502
Publication Date: 11/01/96

Bookmark It

Search this book:
 
Previous Table of Contents Next


Scale

Performing a scale operation on a mesh or a face changes its size and location. First, let’s look at how a scale operation can change the size of an object. If we take our sample 1 by 1 by 1 cube and scale it by a factor of ½, our cube would be ½ units long in each dimension (or ½ by ½ by ½ units). If we used a scale factor of 2, we would double our cube’s dimensions, producing a cube that is two units long in each dimension (making our sample cube 2 by 2 by 2 units). Figure 2.13 illustrates these scale operations.


Figure 2.13  The result of scaling a 1x1x1 cube with scale factors ½ and 2.

As mentioned previously, performing a scale operation can also change an object’s location. In Figure 2.13, the cube is centered on the origin. Had it not been, the cube’s location would have been affected as well as its size. A scale operation doesn’t scale the object directly: it scales the object’s vertices. With a scale factor greater than 1, vertices move away from the origin. With a scale factor less than 1, vertices move toward the origin. Figure 2.14 uses the same scaling factors as Figure 2.13, but this time the cube is located to the right of the Y axis and the resulting cube is moved away from the origin.


Figure 2.14  A cube that has been sized and moved by a scale operation.

Often, this effect is not desirable because if you want to scale an object without changing its location, you have to move the object to the origin, scale it, and then move it back to its original location. Some graphics systems (including Direct3D) allow for scale operations that enable you to resize an object without changing its location, regardless of whether the object is centered on the origin. This is accomplished by using a local, or object, axis. Scaling objects on a local axis produces the same effect as scaling an object centered on the origin: the size of the object changes, but its location (the object’s center) stays the same. By default, Direct3D scales objects using the object’s local axis.

You can specify a different scale factor for each axis. This allows objects to be stretched and shortened. Scale factors of 1 have no effect on an object’s vertices, so 1 can be used for any axis that should not be modified. If we take our original cube and perform a scale operation using <2, 1, 1>, we will increase the cube’s width without affecting the other dimensions. Figure 2.15 shows the result.


Figure 2.15  Using multiple scale factors <2, 1, 1>.

Rotate

The Rotate operation allows us to assign orientations to objects. Rotating an object requires that we determine the axis of the rotation and how far the object should rotate.

We can use a vector to describe to the axis of the rotation and a value to describe how far the object should rotate.

Let’s go back to our sample cube and rotate it on the Z axis by 45 degrees. Rotating on the Z axis means that the cube will turn as if it had been speared by the Z axis and is now free to turn in only one direction. We can express this with the vector <0, 0, 1> and the number 45. Figure 2.16 shows the result.


Figure 2.16  A cube rotated 45 degrees around the axis <0, 0, 1>.

Texture Mapping

Texture mapping gained a lot of attention with the advent of ID software’s smash hit, DOOM. DOOM wasn’t the first implementation of texture mapping, but it was certainly one of the most popular.

Texture mapping is the application (or mapping) of a texture onto a face or set of faces. This mapping takes place with regard to the object’s location in 3D space. We can’t just slap a texture on a face without regard for the object’s distance and orientation from the viewer. Such a scene would hardly be convincing. We will talk more about texture and perspective later in this chapter. For now, bear in mind that correct texture mapping requires textures on distant objects to be applied differently than textures on nearby objects.

The Nature of Textures

A texture is a two-dimensional grid of color values. Textures are often stored in familiar file formats such as BMP, PCX, or GIF. Just about any 2D image can be used as a texture. Figure 2.17 shows a typical texture.


Figure 2.17  A typical texture.

Keep in mind, while you can use any image as a texture—not all images make a good texture. Good textures usually aren’t much to look at by themselves, but they can bring realism to the objects. Images that are complete scenes usually make poor textures because you don’t expect to see an entire scene when you look at a single object. 3D objects such as mirrors or pictures are exceptions to this rule.

Texture Scaling

Textures can be applied to objects in a number of different ways. One way to vary a texture is to alter a texture’s scale. If a texture is applied with a large scale factor, only a portion of the texture will fit on a given object. If the scale factor is small, the complete texture will appear on the object as a set of repeating tiles. This second effect can be quite useful for situations where you are representing large objects that have a similar overall appearance. Figure 2.18 is an example of the same texture applied using different scale factors.


Figure 2.18  Texture scaling.


Previous Table of Contents Next


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.