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


Execution of this portion of the function depends on the depth parameter. If depth is greater than one, the code is executed. The code creates a new child frame with the Direct3DRM CreateFrame() function. The new frame is positioned on a semi-random basis. A static counter variable is used to further discourage predictable results. The newly calculated position is applied using the SetPosition() function.

Finally, the CreateChildren() function calls itself. A loop is used to invoke the function based on the number of child frames that should be attached. Notice that the second CreateChildren() argument is depth–1. Once the depth parameter reaches one, no further child frames are created. Failure to subtract 1 from the depth argument would result in a function that calls itself indefinitely.

The MoleculeWin Depth Functions

The Molecule demo’s Depth menu offers six different depth settings. Each setting is implemented with two functions. The functions for the first depth setting (depth=1) look like this:

void MoleculeWin::OnDepth1()
{
    curdepth=1;
    CreateHierarchy();
}

void MoleculeWin::OnUpdateDepth1(CCmdUI* pCmdUI)
{
    pCmdUI->SetCheck( curdepth==1 );
}

The first function, OnDepth1(), is called when the first Depth menu entry is selected. It assigns 1 to the curdepth data member and rebuilds the frame hierarchy with a call to the CreateHierarchy() function.

The second function, OnUpdateDepth1(), is called by MFC before the Depth menu is displayed. The SetCheck() function is used to indicate if a check mark should appear next to the menu entry.

The remaining 10 Depth menu functions are virtually identical to the these functions. The only difference is the value used to manipulate the curdepth data member.

The MoleculeWin Children Functions

The Children menu offers four settings, ranging from one to four. Like the Depth menu functions, each menu entry is implemented with two functions. The functions for the first Children menu entry (children=1) look like this:

void MoleculeWin::OnChildren1()
{
    numchildren=1;
    CreateHierarchy();
}

void MoleculeWin::OnUpdateChildren1(CCmdUI* pCmdUI)
{
    pCmdUI->SetCheck( numchildren==1 );
}

These functions look similar to the Depth menu functions. The only difference is that the numchildren data member is used instead of the curdepth data member.

Key-Framing

Key-framing is an animation technique where an animation sequence is defined in terms of keys. Each key represents a position and orientation that will be applied to a given object at a specific time within the animation. The position and orientation of the object is determined throughout the animation sequence based on these keys.

It is perhaps unfortunate that Direct3D uses the term frame. Frames in Direct3D refer to the Direct3DRMFrame interface. Key-framing uses the term frame in the traditional sense (as in a “frame” of animation). Bear in mind that these two uses are entirely different. Key-framing theory is discussed in Chapter 2.

Direct3D supports key-framing with the Direct3DRMAnimation interface. The interface allows animation sequences to be defined and controlled using these member functions:

  AddPositionKey()
  AddRotateKey()
  AddScaleKey()
  SetTime()

The AddPositionKey(), AddRotateKey(), and AddScaleKey() functions are used to add key frames to the animation. These three functions all take a time index as the first argument. The time index indicates the time within the animation sequence where the given key will take effect. The SetTime() function is used to specify the current time within the animation sequence.

The Direct3DRMAnimation interface determines an object’s location throughout the animation sequence by interpolating between key frames. This calculation can be performed on a linear or spline basis. Linear animation means that the shortest possible path between two key frames is used. Spline-based animation uses splines, or curves, to calculate animation paths. Spline-based animation is usually more realistic than linear animation.

The Direct3DRMAnimation interface is designed primarily to animate Direct3DRMFrame instances. It is not difficult, however, to use the interface for general purpose animation. In Chapter 8, you will learn how Direct3DRMAnimation can be used to perform vertex animation. In Chapter 9, viewport settings are animated using Direct3DRMAnimation. In this chapter, however, we will be using the animation interface to animate frames.

The Rocket Demo

The Rocket demo uses key-framing to animate a rocket. The animation sequence is defined with just a few key frames, and the remainder of the sequence is calculated by an instance of the Direct3DRMAnimation interface. The demo provides an Animation menu that allows the animation settings to be adjusted at run-time. The menu supports two commands: Linear and Spline. A Speed menu is also provided. The Speed menu allows the speed of the animation sequence to be adjusted.

The Rocket demo appears in Figure 7.4.


Figure 7.4  The Rocket demo.

The Rocket demo demonstrates the following techniques:

  Using the Direct3DRMAnimation interface to create and execute key-framed animation sequences
  Applying a texture to a mesh using the mesh’s texture setting (instead of using a texture wrap)
  Using a callback function to update an animation sequence


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.