Upcoming Events
Unite 2010
11/10 - 11/12 @ Montréal, Canada

GDC China
12/5 - 12/7 @ Shanghai, China

Asia Game Show 2010
12/24 - 12/27  

GDC 2011
2/28 - 3/4 @ San Francisco, CA

More events...
Quick Stats
88 people currently visiting GDNet.
2406 articles in the reference section.

Help us fight cancer!
Join SETI Team GDNet!
Link to us Events 4 Gamers
Intel sponsors gamedev.net search:

  Contents

 Preface
 3D File Formats
 The Framework
 X File Class

 Down to the Code

 Source code
 Printable version

 


  The Series

 The Basics
 First Steps to
 Animation

 Multitexturing
 Building Worlds
 With X Files


 

Down to the Code

You know most of the code from the second tutorial First Steps to Animation, so we can concentrate on the new X file code.

OneTimeSceneInit()

Loading an object should happen in the OneTimeSceneInit() method of your main file:

HRESULT CMyD3DApplication::OneTimeSceneInit() { // yellow object m_pObjects[0].vLoc = D3DVECTOR(-1.0f, 0.0f, 0.0f); m_pObjects[0].fYaw = 0.0f; m_pObjects[0].fPitch = 0.0f; m_pObjects[0].fRoll = 0.0f; // red object m_pObjects[1].vLoc = D3DVECTOR(1.0f, 0.0f, 0.0f); m_pObjects[1].fYaw = 0.0f; m_pObjects[1].fPitch = 0.0f; m_pObjects[1].fRoll = 0.0f; HRESULT hr; // yellow object m_pObjects[0].m_pFile = new CD3DFile(); hr = m_pObjects[0].m_pFile->Load ("boidy2.x"); if( FAILED(hr) ) { MessageBox( NULL, TEXT("Error loading boidy.x file"), TEXT("Animation"), MB_OK|MB_ICONERROR); return E_FAIL; } // get the X file matrix CD3DFileObject* pObject = m_pObjects[0].m_pFile->FindObject( "BOID_Root" ); if( pObject ) { m_pObjects[0].matLocal = *pObject->GetMatrix(); } // red object // the same as above return S_OK; }

After allocating the X file class, we could load the X file and search for the BOID_Root Frame template and later for the FrameTransformMatrix template to get the transformation matrix. That's easy ... isn't it? To store the class pointer in the structure of the object, I've expanded the structure used by the objects like this:

struct Object { CD3DFile* m_pFile; D3DVECTOR vLoc; FLOAT fYaw, fPitch, fRoll; D3DMATRIX matLocal; };

You'll find it at the beginning of the objects.cpp file.

Render()

To render the X files, a simple call to CD3DFile::Render() has to be performed:

... if (m_pObjects[0].m_pFile) m_pObjects[0].m_pFile->Render( m_pd3dDevice ); // Apply the object's local matrix m_pd3dDevice->SetTransform(D3DTRANSFORMSTATE_WORLD, &m_pObjects[0].matLocal); ...

Ok, that wasn't difficult.

Finale

Rumours tell us that the X file support in DirectX 8 will be greatly enhanced. There should be a Maya and a 3D Studio Max X file exporter with source. New X file handling routines will be provided with Direct3D's utility library, Direct3DX. So your time has been well-spent learning the ins and outs of the X file format and the simple interface provided by the Direct3D 7 Framework.

I hope you enjoyed our trip to the X file format. This will be a work in progress in the future. If you find any mistakes or if you have any good ideas to improve this tutorial or if you dislike or like it, give me a sign at wolf@direct3d.net.


© 1999-2001 Wolfgang Engel, Mainz, Germany