![]() |
![]() |
![]() |
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() |
![]() |
![]() |
To access the contents, click the chapter and section titles.
Cutting Edge Direct 3D Programming
ScalePerforming a scale operation on a mesh or a face changes its size and location. First, lets 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 cubes 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.
As mentioned previously, performing a scale operation can also change an objects location. In Figure 2.13, the cube is centered on the origin. Had it not been, the cubes location would have been affected as well as its size. A scale operation doesnt scale the object directly: it scales the objects 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.
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 objects center) stays the same. By default, Direct3D scales objects using the objects 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 objects 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 cubes width without affecting the other dimensions. Figure 2.15 shows the result.
RotateThe 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. Lets 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.
Texture MappingTexture mapping gained a lot of attention with the advent of ID softwares smash hit, DOOM. DOOM wasnt 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 objects location in 3D space. We cant just slap a texture on a face without regard for the objects 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 TexturesA 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.
Keep in mind, while you can use any image as a texturenot all images make a good texture. Good textures usually arent 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 dont 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 ScalingTextures can be applied to objects in a number of different ways. One way to vary a texture is to alter a textures 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.
|
![]() |
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. |