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


Morphing

The 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 aren’t 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:

  The position of the vertices in the starting morph target.
  The position of the vertices in the destination morph target.
  A value indicating the stage in between the two morph targets that should be represented.

Let’s 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 Demo

The 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 file contains at least two meshes.
  The meshes in the file all have the same vertex count.
  The meshes are named with single, lowercase letters, starting with the letter a.

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 targets—one 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 demo’s 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.


Figure 8.4  The MorphPlay demo.

The MorphPlay demo demonstrates the following techniques:

  Creating morph sequences using one or more meshes as morph targets
  Using the Direct3DRMAnimation interface to perform vertex animation
  Using the window title bar to display program information
  Using MFC’s CFileDialog class

Class Design

Unlike 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 demo’s class hierarchy is shown in Figure 8.5.


Figure 8.5  The MorphPlay class hierarchy.

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.


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.