Cuboid.h
上传用户:whgydz
上传日期:2007-01-12
资源大小:2259k
文件大小:2k
源码类别:

其他书籍

开发平台:

HTML/CSS

  1. // Cuboid.h: interface for the CCuboid class.
  2. //
  3. //////////////////////////////////////////////////////////////////////
  4. #if !defined(AFX_CUBOID_H__AE25AF5F_AE56_48F5_99DC_47CAAA14F245__INCLUDED_)
  5. #define AFX_CUBOID_H__AE25AF5F_AE56_48F5_99DC_47CAAA14F245__INCLUDED_
  6. #if _MSC_VER > 1000
  7. #pragma once
  8. #endif // _MSC_VER > 1000
  9. #include <d3dx8.h>
  10. #include "Helper.h"
  11. //Define a FVF for our cubiods
  12. #define CUBOID_D3DFVF_CUSTOMVERTEX (D3DFVF_XYZ|D3DFVF_NORMAL|D3DFVF_TEX1)
  13. class CCuboid
  14. {
  15. private:
  16. //Define a custom vertex for our cubiods
  17. struct CUBOID_CUSTOMVERTEX
  18. {
  19. FLOAT x, y, z; //Position of vertex in 3D space
  20. FLOAT nx, ny, nz; //Lighting Normal
  21. FLOAT tu, tv; //Texture coordinates
  22. };
  23. public:
  24. bool SetMaterial(D3DCOLORVALUE rgbaDiffuse, D3DCOLORVALUE rgbaAmbient, D3DCOLORVALUE rgbaSpecular, D3DCOLORVALUE rgbaEmissive, float rPower);
  25. bool SetTexture(const char* szTextureFilePath);
  26. bool SetPosition(float x, float y, float z);
  27. bool SetSize(float rWidth, float rHeight, float rDepth);
  28. DWORD Render();
  29. CCuboid(LPDIRECT3DDEVICE8 pD3DDevice, float x = 0.0, float y = 0.0, float z = 0.0);
  30. virtual ~CCuboid();
  31. private:
  32. bool CreateIndexBuffer();
  33. D3DXVECTOR3 GetTriangeNormal(D3DXVECTOR3* vVertex1, D3DXVECTOR3* vVertex2, D3DXVECTOR3* vVertex3);
  34. bool UpdateVertices();
  35. HRESULT CreateVertexBuffer();
  36. LPDIRECT3DDEVICE8 m_pD3DDevice;
  37. LPDIRECT3DVERTEXBUFFER8 m_pVertexBuffer;
  38. LPDIRECT3DTEXTURE8 m_pTexture;
  39. D3DMATERIAL8 m_matMaterial;
  40. LPDIRECT3DINDEXBUFFER8 m_pIndexBuffer;
  41. float m_rWidth;
  42. float m_rHeight;
  43. float m_rDepth;
  44. float m_rX;
  45. float m_rY;
  46. float m_rZ;
  47. DWORD m_dwNumOfVertices;
  48. DWORD m_dwNumOfIndices;
  49. DWORD m_dwNumOfPolygons;
  50. };
  51. #endif // !defined(AFX_CUBOID_H__AE25AF5F_AE56_48F5_99DC_47CAAA14F245__INCLUDED_)