D3DXFile.h
上传用户:wymy58
上传日期:2007-01-07
资源大小:2086k
文件大小:4k
源码类别:

DirextX编程

开发平台:

Visual C++

  1. // Copyright (C) 1999 DXGuide.  All Rights Reserved.
  2. // File: D3DXFile.h
  3. #ifndef _D3DXFILE__H
  4. #define _D3DXFILE__H
  5. #include "D3DMatrix.h" // for CD3DMatrix
  6. class CD3DDevice;
  7. class CD3DFileBaseObject;
  8. class CD3DFileFrame;
  9. class CPackFileManager;
  10. class CD3DXFile
  11. {
  12. friend class CD3DFileMesh;
  13. public:
  14. CD3DXFile(void);
  15. ~CD3DXFile();
  16. public:
  17. bool Load(CD3DDevice*  pD3DDevice,
  18. LPCTSTR  lpszFileName,
  19. CPackFileManager*  pPackFileManager = NULL);
  20. public:
  21. bool Render(void);
  22. bool GetBoundingSphere(D3DVECTOR*  pvCenterPt,
  23. D3DVALUE*  pfRadius);
  24. bool GetFrameMatrix(LPCTSTR  lpszName,
  25. CD3DMatrix**  ppmat);
  26. bool GetMeshVertices(LPCTSTR  lpszName,
  27. D3DVERTEX** ppVertices,
  28. DWORD*  pdwNumVertices,
  29. WORD**  ppwIndices,
  30. DWORD*  pdwNumIndices);
  31. protected:
  32. CD3DFileFrame* m_pRootFrame;
  33. CPackFileManager* m_pPackFileManager;
  34. public:
  35. CD3DDevice* m_pD3DDevice;
  36. };
  37. // Internal class used by the CD3DXFile to hold data for a geometry file
  38. class CD3DFileBaseObject
  39. {
  40. protected:
  41. CD3DFileBaseObject(LPCTSTR  lpszName,
  42. CD3DXFile*  pD3DXFile);
  43. virtual ~CD3DFileBaseObject();
  44. public:
  45. virtual void Render(void) = 0;
  46. virtual void ComputeBoundingSphereCenter(CD3DMatrix*  pmat, D3DVECTOR*, DWORD*);
  47. virtual void ComputeBoundingSphereRadius(CD3DMatrix*  pmat, D3DVECTOR*  pvCenter,
  48. D3DVALUE*  pfRadius);
  49. virtual bool GetFrameMatrix(LPCTSTR  lpszName,
  50. CD3DMatrix**  ppMatrix);
  51. virtual bool GetMeshVertices(LPCTSTR  lpszName,
  52. D3DVERTEX**  ppvVertices,
  53. DWORD*  pdwNumVertices,
  54. WORD**  ppwIndices,
  55. DWORD*  pdwNumIndices);
  56. public:
  57. void AddNext(CD3DFileBaseObject*  pChild);
  58. void AddChild(CD3DFileBaseObject*  pNext);
  59. protected:
  60. CD3DFileBaseObject* m_pNext;
  61. CD3DFileBaseObject* m_pChild;
  62. CString m_strName;
  63. CD3DXFile* m_pD3DXFile;
  64. };
  65. class CD3DFileFrame : public CD3DFileBaseObject
  66. {
  67. friend class CD3DXFile;
  68. friend class CDXFileData;
  69. protected:
  70. CD3DFileFrame(LPCTSTR  lpszName, CD3DXFile*  pD3DXFile);
  71. virtual ~CD3DFileFrame();
  72. public:
  73. virtual void Render(void);
  74. virtual void ComputeBoundingSphereCenter(CD3DMatrix*  pmat,
  75. D3DVECTOR*, DWORD*);
  76. virtual void ComputeBoundingSphereRadius(CD3DMatrix*  pmat,
  77. D3DVECTOR*  pvCenter, D3DVALUE*  pfRadius);
  78. virtual bool GetFrameMatrix(LPCTSTR  lpszName,
  79. CD3DMatrix**  ppMatrix);
  80. public:
  81. void SetMatrix(CD3DMatrix*  pmat)
  82. {
  83. m_mat = *pmat;
  84. }
  85. protected:
  86. CD3DMatrix m_mat;
  87. };
  88. class CD3DTexture;
  89. class CD3DFileMesh : public CD3DFileBaseObject
  90. {
  91. friend class CDXFileData;
  92. protected:
  93. CD3DFileMesh(LPCTSTR  lpszName,
  94. CD3DXFile*  pD3DXFile,
  95. DWORD  dwNumVertices, D3DVECTOR*  pVertexData,
  96. DWORD  dwNumFaces, void*  pFaceData);
  97. virtual ~CD3DFileMesh();
  98. public:
  99. virtual void Render(void);
  100. virtual void ComputeBoundingSphereCenter(
  101. CD3DMatrix*  pmat, D3DVECTOR*, DWORD*);
  102. virtual void ComputeBoundingSphereRadius(
  103. CD3DMatrix*  pmat, D3DVECTOR*  pvCenter,
  104. D3DVALUE*  pfRadius);
  105. virtual bool GetMeshVertices(LPCTSTR  lpszName,
  106. D3DVERTEX**  ppvVertices,
  107. DWORD*  pdwNumVertices,
  108. WORD**  ppwIndices, 
  109. DWORD*  pdwNumIndices);
  110. public:
  111. bool SetTexture(LPCTSTR  lpszName);
  112. void SetNormals(D3DVECTOR*  pNormals);
  113. void SetTextureCoords(D3DVALUE*  pTexCoords);
  114. void SetMaterial(D3DMATERIAL7*  pMaterial);
  115. protected:
  116. bool ComputeNormals(void);
  117. protected:
  118. D3DMATERIAL7* m_pMaterial;
  119. CD3DTexture* m_pD3DTexture;
  120. DWORD m_dwNumVertices;
  121. D3DVERTEX* m_pVertices;
  122. DWORD m_dwNumIndices;
  123. WORD* m_pIndices;
  124. };
  125. #endif // _D3DXFILE__H