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


Chapter 8
More About Meshes

  Vertex Animation
  Multiple Mesh Groups
  Morphing

At this point, we’ve talked about animation in considerable detail. We’ve animated meshes starting with Chapter 4, using rotation attributes. In Chapter 5, we performed texture animation. In Chapter 7, we discussed frame-based animation and key-framing.

All of the animation techniques that we’ve looked at performed animation either by animating a texture on a mesh, or by moving or rotating the mesh itself. In this chapter, we’ll look at sub-mesh, or vertex, animation.

Vertex animation involves manipulating the location of vertices within a mesh to change the shape of the mesh at runtime. This technique has many applications, the most notable of which is morphing.

We’ll study these demos in this chapter:

  Cube
  Cube2
  MorphPlay

We’ll use the Cube demo to introduce vertex animation. The Cube2 demo illustrates how to create and maintain multiple groups of faces within the same mesh. Finally, we’ll study morphing with the MorphPlay demo.

Vertex Animation

Vertex animation is the animation of one or more vertices within a single mesh, and is relatively simple to implement. The challenging part is not the moving of vertices, but deciding where and when to move the vertices.

Vertex animation can be performed by both the Direct3DRMMeshBuilder and Direct3DRMMesh interfaces. Because of the extra performance and memory overhead associated with the Direct3DRMMeshBuilder interface, however, we will be using the Direct3DRMMesh interface exclusively.

The Cube Demo

The Cube demo uses vertex animation to stretch and skew a cube. The demo is intended to be simple rather than impressive, so only two of the cube’s vertices are animated. The Cube demo appears in Figure 8.1.


Figure 8.1  The Cube demo.

In addition to the vertex animation, a random rotation vector is used to spin the cube. This goes a long way to disguise the simplicity of the vertex animation. The Cube demo also supports the typical Render menu that allows the rendering method of the mesh to be changed at runtime.

The Cube demo demonstrates the following techniques:

  Constructing a mesh from scratch (the mesh is not loaded from disk, but assembled at program startup)
  Using the Direct3DRMMesh to perform vertex animation
  Changing the mesh’s rendering method with menu commands

The CubeWin Class

The Cube demo provides its functionality in the CubeWin class:

class CubeWin : public RMWin
{
public:
    CubeWin();
    BOOL CreateScene();
protected:
    //{{AFX_MSG(CubeWin)
    afx_msg void OnRenderWireframe();
    afx_msg void OnRenderFlat();
    afx_msg void OnRenderGouraud();
    afx_msg void OnUpdateRenderWireframe(CCmdUI* pCmdUI);
    afx_msg void OnUpdateRenderFlat(CCmdUI* pCmdUI);
    afx_msg void OnUpdateRenderGouraud(CCmdUI* pCmdUI);
    //}}AFX_MSG
    DECLARE_MESSAGE_MAP()
private:
    static void UpdateCube(LPDIRECT3DRMFRAME, void*, D3DVALUE);
private:
    LPDIRECT3DRMMESH mesh;
    D3DRMGROUPINDEX group;
};

The class declares two public functions: a constructor and the CreateScene() function. The constructor is used to initialize the class’s data members. The CreateScene() function constructs the demo’s scene. We’ll look at CreateScene() soon.

Six protected member functions are declared. They provide Render menu functionality.

One callback function is declared: UpdateCube(). We’ll use this callback to perform the actual vertex animation.

Finally, two data members are declared. The first is a pointer to the Direct3DRMMesh interface and will be initialized to point to the demo’s single mesh. The second is a mesh group identifier. We’ll use this data member to manipulate the cube mesh once it has been created.


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.