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
Chapter 8 More About Meshes
- Vertex Animation
- Multiple Mesh Groups
- Morphing
At this point, weve talked about animation in considerable detail. Weve 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 weve looked at performed animation either by animating a texture on a mesh, or by moving or rotating the mesh itself. In this chapter, well 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.
Well study these demos in this chapter:
- Cube
- Cube2
- MorphPlay
Well 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, well 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 cubes 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 meshs 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 classs data members. The CreateScene() function constructs the demos scene. Well look at CreateScene() soon.
Six protected member functions are declared. They provide Render menu functionality.
One callback function is declared: UpdateCube(). Well 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 demos single mesh. The second is a mesh group identifier. Well use this data member to manipulate the cube mesh once it has been created.
|