![]() |
![]() |
![]() |
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() |
![]() |
![]() |
To access the contents, click the chapter and section titles.
Cutting Edge Direct 3D Programming
The MorphWin ClassThe MorphWin class provides its functionality with these functions:
The LoadMorphSequence() takes the name of an MRF or X file and attempts to construct a morph sequence based on the file contents. The GetNumMorphTargets() function returns the number of morph targets present in the current morph sequence. The GetMorphMesh() function returns a pointer to the Direct3DRMMesh interface that represents the morph mesh. The AddMorphKey(), DeleteMorphKey(), and SetMorphTime() functions are inspired by the Direct3DRMAnimation interface. A morph key is a morph target. The AddMorphKey() function allows you to specify which morph target should be in effect at a given time in the morph sequence. The SetMorphTime() function allows you to indicate the point in the morph sequence that should be calculated. The MorphWin class is declared like this: class MorphWin : public RMWin { public: MorphWin(); LPDIRECT3DRMMESH GetMorphMesh() { return morphmesh; } DWORD GetNumMorphTargets() { return nummorphtargets; } BOOL LoadMorphSequence( const CString& filename ); BOOL AddMorphKey( DWORD target, D3DVALUE time ); BOOL DeleteMorphKey( D3DVALUE time ); BOOL SetMorphTime( D3DVALUE time ); private: BOOL LoadMeshes( const CString& filename ); BOOL CreateAnimations(); BOOL PrepareMorphVertices(); BOOL ReleaseAnimations(int count); protected: //{{AFX_MSG(MorphWin) afx_msg void OnDestroy(); //}}AFX_MSG DECLARE_MESSAGE_MAP() private: LPDIRECT3DRMMESH morphmesh; D3DRMVERTEX* morphmeshdata[MAXMORPHTARGETS]; D3DRMVERTEX* morphvertex; DWORD nummorphvertices; DWORD nummorphtargets; LPDIRECT3DRMANIMATION* posanimation; LPDIRECT3DRMFRAME* posframe; LPDIRECT3DRMANIMATION* normanimation; LPDIRECT3DRMFRAME* normframe; BOOL morphing; }; The six functions that we have discussed, along with the class constructor, are declared public. Four private helper functions are also declared. The class declares the OnDestroy() message handler function to perform cleanup tasks. The morphmeshdata array will be used to store the vertex data for each morph target in a morph sequence. The morphvertex array is used to store the vertex data for the mesh that will be used to perform the actual morphing. The nummorphvertices data member will be used to store the number of vertices in the morph targets. We dont have to store a separate vertex count for each morph target because it is required that all morph targets have the same vertex count. The nummorphtargets is used to store the number of targets in the morph sequence. The posanimation and posframe arrays are used to calculate new vertex positions. The posanimation array is an array of pointers to the Direct3DRMAnimation interface. Vertex positions are determined by generating an animation sequence for each vertex in the morph mesh. The posframe array is an array of frames that serve as dummy frames. The frames are used solely to retrieve animation data from the Direct3DRMAnimation objects. The normanimation and normframe arrays are used to calculate normals for each vertex. This is necessary for correct lighting during the sequence. The vertex normals are morphed along with the vertex positions using the same technique. Finally, the boolean morphing data member is used to indicate if a morph sequence has been loaded. The MorphWin::LoadMorphSequence() FunctionThe LoadMorphSequence() function takes the name of a file as an argument. The function attempts to construct a morph sequence given the contents of the file: BOOL MorphWin::LoadMorphSequence( const CString& filename ) { CString windowtext; GetWindowText( windowtext ); CString txt="Loading: " + filename; SetWindowText( txt ); BOOL ret=FALSE; if (LoadMeshes( filename )) if (CreateAnimations()) ret=PrepareMorphVertices(); SetWindowText( windowtext ); return ret; } First, the function retrieves the text that is currently displayed in the windows title bar. The window title text is retrieved with the MFC GetWindowText() function and stored in the windowtext object. The text is then replaced with a string that indicates the name of the file to be loaded. The SetWindowText() function is used to display the string. Notice that before the LoadMorphSequence() function returns, the SetWindowText() function is used againthis time to restore the title bars original text. Next, the LoadMorphSequence() function makes three function calls, each dependent on the last. The LoadMeshes() function is used to extract the meshes from the file. The CreateAnimation() function is used to prepare an animation sequence for each vertex. The PrepareMorphVertices() function is used to initialize the array of vertices that will be used to store the calculated vertex data. If any of these functions fail, the LoadMorphSequence() function returns FALSE.
|
![]() |
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. |