![]() |
![]() |
![]() |
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() |
![]() |
![]() |
To access the contents, click the chapter and section titles.
Cutting Edge Direct 3D Programming
MorphingThe term morphing has come to be associated with TV ads and movie effects where one shape morphs into another shape. Usually, the starting and destination shapes are quite different. In this section, we discuss morphing on a more general level. For our purposes, we arent too concerned with how different the two morph shapes are, just that it is possible to morph one into the other (and vice versa). In order for two shapes (meshes) to be morphable, they must contain the same number of vertices. Meeting this criteria does not guarantee that the resulting morph sequence will look good. Matching vertex counts just means that a morph sequence will be possible. Practically speaking, the vertex count is only half the story. The faces in the two meshes should be arranged similarly. In fact, most morphable meshes are variations on the same mesh. A mesh that is part of a set of morphable meshes is called a morph target. The design and creation of morph targets, however, is not the focus of this discussion. Here, we will concentrate on how to perform morphing given two or more compatible morph targets. Technically, morphing involves calculating vertex positions for a mesh based on three criteria:
Lets say, for example, that the starting morph mesh is a bird, the destination morph mesh is an airplane, and the betweening value ranges from 1 to 100. If we use a value of 1, then the resulting mesh is a bird. If we use a value of 100, the resulting mesh is a plane. If, however, we use a value of 50, then the result will be a shape that is halfway between a bird and a plane. As the value approaches 1, the mesh looks more like a bird. As the value approaches 100, the mesh looks more like a plane. Morph targets do not have to be entirely different shapes. Visually compelling morph sequences can involve shapes that bend, twist, curl, taper, or stretch. Also, there is no reason that the number of morph targets has to be limited to two. Any number of morph targets can be used. For example, a bird can be morphed into a ball and then into a plane by adding a spherical morph target between the bird and the plane. As long as a set of morph targets has the same number of vertices, a morph sequence can be created. The MorphPlay DemoThe MorphPlay demo is a generic morph sequence player. The demo allows morph files (.MRF) to be loaded and played. The CD-ROM that comes with this book contains MRF files in the meshes directory. The MRF files are X files that meet the following criteria:
The MRF file extension is optional. MorphPlay will load files with either X or MRF file extensions. When a file is loaded, the meshes in the file are used as morph targets. The file can include up to 26 morph targetsone for each letter of the alphabet. The morph targets are used in alphabetical order. The demo provides a Morph menu, which offers three selections: Forward, Reverse, and Both. Forward means the that the morph mesh assumes the shape of the first mesh (mesh a) and then morphs to the second mesh (mesh b). The morphing continues until the morph mesh has conformed to the shape of the last mesh in the file. The sequence then begins over with the first mesh. Playing a morph sequence in reverse causes the morph target sequence to reverse. The default setting, Both, plays the morph sequence forward and backward continuously. The speed of the morph sequence can be adjusted using the demos Speed menu. The demos includes five morph speed settings. Slow speeds are accomplished by incrementing the morph time slowly. This results in very smooth motion. The morph mesh can be rotated and spun using the mouse. Holding the left mouse--button down and moving the mouse will allow you to view the morph sequence from any angle. The MorphPlay demo appears in Figure 8.4.
The MorphPlay demo demonstrates the following techniques:
Class DesignUnlike most of the demos on the CD-ROM, the MorphPlay demo functionality is divided between two classes. General morphing functionality is provided by the MorphWin class, while the demo specific functionality is provided by the MorphPlayWin class. The demos class hierarchy is shown in Figure 8.5.
Isolating the morphing functionality in the MorphWin class means that it will be easy for you to write your own morphing applications. Deriving window classes from MorphWin (instead of RMWin) means that your window class inherits morphing capability.
|
![]() |
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. |