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

其他书籍

开发平台:

HTML/CSS

  1. // Terrain.h: interface for the CTerrain class.
  2. //
  3. //////////////////////////////////////////////////////////////////////
  4. #if !defined(AFX_TERRAIN_H__605B63BD_B46A_44BF_A2F2_573132F97949__INCLUDED_)
  5. #define AFX_TERRAIN_H__605B63BD_B46A_44BF_A2F2_573132F97949__INCLUDED_
  6. #if _MSC_VER > 1000
  7. #pragma once
  8. #endif // _MSC_VER > 1000
  9. #include <d3dx8.h>
  10. #include "Base.h"
  11. //Define a FVF for our terrain
  12. #define TERRAIN_D3DFVF_CUSTOMVERTEX (D3DFVF_XYZ|D3DFVF_NORMAL|D3DFVF_TEX1)
  13. class CTerrain : public CBase  
  14. {
  15. private:
  16. //Define a custom vertex for our terrain
  17. struct TERRAIN_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. DWORD Render();
  27. CTerrain(LPDIRECT3DDEVICE8 pD3DDevice, WORD wRows = 10, WORD wCols = 10, float rTileSize = 1.0, WORD wMaxHeight = 10);
  28. virtual ~CTerrain();
  29. private:
  30. bool CreateIndexBuffer();
  31. bool UpdateVertices();
  32. bool CreateVertexBuffer();
  33. LPDIRECT3DDEVICE8 m_pD3DDevice;
  34. LPDIRECT3DVERTEXBUFFER8 m_pVertexBuffer;
  35. LPDIRECT3DTEXTURE8 m_pTexture;
  36. D3DMATERIAL8 m_matMaterial;
  37. LPDIRECT3DINDEXBUFFER8 m_pIndexBuffer;
  38. WORD m_wRows;
  39. WORD m_wCols;
  40. WORD m_wMaxHeight;
  41. float m_rTileSize;
  42. DWORD m_dwNumOfVertices;
  43. DWORD m_dwNumOfIndices;
  44. DWORD m_dwNumOfPolygons;
  45. };
  46. #endif // !defined(AFX_TERRAIN_H__605B63BD_B46A_44BF_A2F2_573132F97949__INCLUDED_)